@dwtechs/antity 0.2.0 → 0.3.0

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/README.md CHANGED
@@ -116,6 +116,8 @@ const entity = new Entity("consumer", "consumers", [
116
116
  req.body = entity.normalize(req.body);
117
117
  const check = entity.validate(req.body, req.method);
118
118
 
119
+
120
+
119
121
  ```
120
122
 
121
123
 
@@ -173,9 +175,12 @@ class Property {
173
175
  class Entity {
174
176
  name: string;
175
177
  table: string;
178
+ cols: Record<Method, string>;
176
179
  properties: Property[];
177
180
  normalize(rows: Record<string, any>[]): Record<string, any>[];
178
181
  validate(rows: Record<string, any>[], method: Method): string | null;
182
+ getTable(): string;
183
+ getCols(method: Method): string;
179
184
  }
180
185
 
181
186
  ```
@@ -457,22 +457,30 @@ class Entity {
457
457
  constructor(name, table, properties) {
458
458
  this.name = name;
459
459
  this.table = table;
460
+ this.cols = {
461
+ GET: "",
462
+ POST: "",
463
+ PUT: "",
464
+ PATCH: "",
465
+ DELETE: "",
466
+ };
460
467
  this.properties = this.init(properties);
461
468
  }
462
469
  init(properties) {
463
470
  const props = [];
464
471
  for (const p of properties) {
465
472
  props.push(new Property(p.key, p.type, p.min, p.max, p.required, p.typeCheck, p.methods, p.sanitize, p.normalize, p.control, p.sanitizer, p.normalizer, p.controller));
473
+ for (const m of p.methods) {
474
+ this.cols[m] += this.cols[m].length ? `, ${p.key}` : `${p.key}`;
475
+ }
466
476
  }
467
477
  return props;
468
478
  }
469
- cols(method) {
470
- const cols = [];
471
- for (const p of this.properties) {
472
- if (isIn(method, p.methods))
473
- cols.push(p.key);
474
- }
475
- return cols;
479
+ getTable() {
480
+ return this.table;
481
+ }
482
+ getCols(method) {
483
+ return this.cols[method];
476
484
  }
477
485
  normalize(rows) {
478
486
  for (const r of rows) {
package/dist/antity.d.ts CHANGED
@@ -25,16 +25,41 @@ https://github.com/DWTechs/Antity.js
25
25
  */
26
26
 
27
27
 
28
- type Type = keyof typeof Types;
29
28
  type Method = typeof Methods[number];
29
+ type Type =
30
+ "boolean" |
31
+ "string" |
32
+ "number" |
33
+ "integer" |
34
+ "float" |
35
+ "even" |
36
+ "odd" |
37
+ "positive" |
38
+ "negative" |
39
+ "powerOfTwo" |
40
+ "ascii" |
41
+ "array" |
42
+ "jwt" |
43
+ "symbol" |
44
+ "email" |
45
+ "regex" |
46
+ "json" |
47
+ "ipAddress" |
48
+ "slug" |
49
+ "hexadecimal" |
50
+ "date" |
51
+ "timestamp" |
52
+ "function" |
53
+ "htmlElement" |
54
+ "htmlEventAttribute" |
55
+ "node" |
56
+ "object";
30
57
 
31
58
  declare const Methods: readonly ["GET", "PATCH", "PUT", "POST", "DELETE"];
32
59
 
33
- declare const Types: {
34
- [key: string]: {
35
- validate: (v: any, min: number | Date, max: number | Date, typeCheck: boolean) => boolean;
36
- };
37
- };
60
+ declare const Types: Record<Type, {
61
+ validate: (v: any, min: number | Date, max: number | Date, typeCheck: boolean) => boolean;
62
+ }>;
38
63
 
39
64
  declare const Required: {
40
65
  validate: (v: any) => boolean;
@@ -43,10 +68,12 @@ declare const Required: {
43
68
  declare class Entity {
44
69
  name: string;
45
70
  table: string;
71
+ cols: Record<Method, string>;
46
72
  properties: Property[];
47
73
  constructor(name: string, table: string, properties: Property[]);
48
74
  private init;
49
- cols(method: Method): string[];
75
+ getTable(): string;
76
+ getCols(method: Method): string;
50
77
  normalize(rows: Record<string, any>[]): Record<string, any>[];
51
78
  validate(rows: Record<string, any>[], method: Method): string | null;
52
79
  private require;
package/dist/antity.js CHANGED
@@ -152,22 +152,30 @@ class Entity {
152
152
  constructor(name, table, properties) {
153
153
  this.name = name;
154
154
  this.table = table;
155
+ this.cols = {
156
+ GET: "",
157
+ POST: "",
158
+ PUT: "",
159
+ PATCH: "",
160
+ DELETE: "",
161
+ };
155
162
  this.properties = this.init(properties);
156
163
  }
157
164
  init(properties) {
158
165
  const props = [];
159
166
  for (const p of properties) {
160
167
  props.push(new Property(p.key, p.type, p.min, p.max, p.required, p.typeCheck, p.methods, p.sanitize, p.normalize, p.control, p.sanitizer, p.normalizer, p.controller));
168
+ for (const m of p.methods) {
169
+ this.cols[m] += this.cols[m].length ? `, ${p.key}` : `${p.key}`;
170
+ }
161
171
  }
162
172
  return props;
163
173
  }
164
- cols(method) {
165
- const cols = [];
166
- for (const p of this.properties) {
167
- if (isIn(method, p.methods))
168
- cols.push(p.key);
169
- }
170
- return cols;
174
+ getTable() {
175
+ return this.table;
176
+ }
177
+ getCols(method) {
178
+ return this.cols[method];
171
179
  }
172
180
  normalize(rows) {
173
181
  for (const r of rows) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dwtechs/antity",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Open source library for easy entity management",
5
5
  "keywords": [
6
6
  "entities"