@dwtechs/antity-pgsql 0.9.0 → 0.10.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
@@ -62,11 +62,11 @@ const entity = new SQLEntity("consumers", [
62
62
  type: "integer",
63
63
  min: 0,
64
64
  max: 120,
65
- typeCheck: true,
66
- filter: true,
67
- need: ["PUT"],
65
+ isTypeChecked: true,
66
+ isFilterable: true,
67
+ requiredFor: ["PUT"],
68
68
  operations: ["SELECT", "UPDATE"],
69
- send: true,
69
+ isPrivate: false,
70
70
  sanitizer: null,
71
71
  normalizer: null,
72
72
  validator: null,
@@ -76,11 +76,11 @@ const entity = new SQLEntity("consumers", [
76
76
  type: "string",
77
77
  min: 0,
78
78
  max: 255,
79
- typeCheck: true,
80
- filter: false,
81
- need: ["POST", "PUT"],
79
+ isTypeChecked: true,
80
+ isFilterable: false,
81
+ requiredFor: ["POST", "PUT"],
82
82
  operations: ["SELECT", "UPDATE"],
83
- send: true,
83
+ isPrivate: false,
84
84
  sanitizer: null,
85
85
  normalizer: normalizeName,
86
86
  validator: null,
@@ -90,11 +90,11 @@ const entity = new SQLEntity("consumers", [
90
90
  type: "string",
91
91
  min: 0,
92
92
  max: 255,
93
- typeCheck: true,
94
- filter: false,
95
- need: ["POST", "PUT"],
93
+ isTypeChecked: true,
94
+ isFilterable: false,
95
+ requiredFor: ["POST", "PUT"],
96
96
  operations: ["SELECT", "UPDATE"],
97
- send: true,
97
+ isPrivate: false,
98
98
  sanitizer: null,
99
99
  normalizer: normalizeName,
100
100
  validator: null,
@@ -104,11 +104,11 @@ const entity = new SQLEntity("consumers", [
104
104
  type: "string",
105
105
  min: 0,
106
106
  max: 255,
107
- typeCheck: true,
108
- filter: true,
109
- need: ["POST", "PUT"],
107
+ isTypeChecked: true,
108
+ isFilterable: true,
109
+ requiredFor: ["POST", "PUT"],
110
110
  operations: ["SELECT", "UPDATE"],
111
- send: true,
111
+ isPrivate: false,
112
112
  sanitizer: null,
113
113
  normalizer: normalizeNickname,
114
114
  validator: null,
@@ -125,10 +125,10 @@ router.put("/", ...entity.updateArraySubstack);
125
125
  router.post("/manual", entity.normalizeArray, entity.validateArray, ..., entity.add);
126
126
  router.put("/manual", entity.normalizeArray, entity.validateArray, ..., entity.update);
127
127
 
128
- router.put("/archive", ..., entity.archive);
128
+ router.patch("/archive", ..., entity.archive);
129
129
  router.delete("/", ..., entity.delete);
130
130
  router.delete("/archived", ..., entity.deleteArchive);
131
- router.get("/history", ..., entity.getHistory);
131
+ router.get("/:id/history", ..., entity.getHistory);
132
132
 
133
133
  ```
134
134
 
@@ -175,7 +175,7 @@ class SQLEntity {
175
175
  get name(): string;
176
176
  get table(): string;
177
177
  get schema(): string;
178
- get unsafeProps(): string[];
178
+ get privateProps(): string[];
179
179
  get properties(): Property[];
180
180
  set name(name: string);
181
181
  set table(table: string);
@@ -360,10 +360,10 @@ Any of these can be passed into the options object for each function.
360
360
  | type | Type | Type of the property |
361
361
  | min | number \| Date | Minimum value | 0 \| 1900-01-01
362
362
  | max | number \| Date | Maximum value | 999999999 \| 2200-12-31
363
- | need | Method[] | property is validated for the listed methods only | ["PATCH", "PUT", "POST"]
364
- | send | boolean | Property is sent in the response | true
365
- | typeCheck | boolean | Type is checked during validation | false
366
- | filter | boolean | property is filterable in a SELECT operation | true
363
+ | requiredFor | Method[] | property is required for the listed methods only | ["PATCH", "PUT", "POST"]
364
+ | isPrivate | boolean | Property is unsafe to send in the response | true
365
+ | isTypeChecked | boolean | Type is checked during validation | false
366
+ | isFilterable | boolean | property is filterable in a SELECT operation | true
367
367
  | operations | Operation[] | Property is used for the DML operations only | ["SELECT", "INSERT", "UPDATE"]
368
368
  | sanitizer | ((v:any) => any) \| null | Custom sanitizer function if sanitize is true | null
369
369
  | normalizer | ((v:any) => any) \| null | Custom Normalizer function if normalize is true | null
@@ -24,12 +24,12 @@ SOFTWARE.
24
24
  https://github.com/DWTechs/Antity-pgsql.js
25
25
  */
26
26
 
27
- import { Entity } from "@dwtechs/antity";
28
- import { Type } from "@dwtechs/antity";
29
- import { Property } from './property';
27
+ import { Entity, Property as BaseProperty } from "@dwtechs/antity";
28
+ import type { Type, Method } from "@dwtechs/antity";
30
29
  import type { Request, Response, NextFunction } from 'express';
30
+ import type { Pool, PoolClient } from 'pg';
31
31
 
32
- export type Operation = "SELECT" | "INSERT" | "UPDATE" | "DELETE";
32
+ export type Operation = "SELECT" | "INSERT" | "UPDATE";
33
33
  export type Sort = "ASC" | "DESC";
34
34
  export type Filters = {
35
35
  [key: string]: Filter;
@@ -39,7 +39,27 @@ export type Filter = {
39
39
  subProps?: string[];
40
40
  matchMode?: MatchMode;
41
41
  };
42
- export { Type };
42
+ export type { Type };
43
+
44
+ export declare class Property extends BaseProperty {
45
+ filter: boolean;
46
+ operations: Operation[];
47
+ constructor(
48
+ key: string,
49
+ type: Type,
50
+ min: number | Date | null,
51
+ max: number | Date | null,
52
+ requiredFor: Method[],
53
+ isPrivate: boolean,
54
+ isTypeChecked: boolean,
55
+ isFilterable: boolean,
56
+ operations: Operation[] | undefined,
57
+ sanitizer: ((v: unknown) => unknown) | null,
58
+ normalizer: ((v: unknown) => unknown) | null,
59
+ validator: ((v: unknown) => unknown) | null
60
+ );
61
+ }
62
+
43
63
  export type LogicalOperator = "AND" | "OR";
44
64
  export type Comparator = "=" | "<" | ">" | "<=" | ">=" | "<>" | "IS" | "IS NOT" | "IN" | "LIKE" | "NOT LIKE";
45
65
  export type MatchMode = "startsWith" | "endsWith" | "contains" | "notContains" | "equals" | "notEquals" | "between" | "in" | "lt" | "lte" | "gt" | "gte" | "is" | "isNot" | "before" | "after" | "st_contains" | "st_dwithin";
@@ -72,12 +92,12 @@ type ExpressMiddleware = (req: Request, res: Response, next: NextFunction) => vo
72
92
  type ExpressMiddlewareAsync = (req: Request, res: Response, next: NextFunction) => Promise<void>;
73
93
  type SubstackTuple = [ExpressMiddleware, ExpressMiddleware, ExpressMiddlewareAsync];
74
94
 
75
- export class SQLEntity extends Entity {
95
+ export declare class SQLEntity extends Entity {
76
96
  private _table: string;
77
97
  private _schema: string;
78
- private sel: any;
79
- private ins: any;
80
- private upd: any;
98
+ private sel: unknown;
99
+ private ins: unknown;
100
+ private upd: unknown;
81
101
 
82
102
  constructor(name: string, properties: Property[], schema?: string);
83
103
 
@@ -142,7 +162,7 @@ export class SQLEntity extends Entity {
142
162
  getHistory(req: Request, res: Response, next: NextFunction): void;
143
163
  }
144
164
 
145
- declare function filter(
165
+ export declare function filter(
146
166
  first: number,
147
167
  rows: number | null,
148
168
  sortField: string | null,
@@ -150,16 +170,9 @@ declare function filter(
150
170
  filters: Filters | null,
151
171
  ): { filterClause: string, args: (Filter["value"])[] };
152
172
 
153
- declare function execute(
173
+ export declare function execute(
154
174
  query: string,
155
175
  args: (string | number | boolean | Date | number[])[],
156
- client: any
176
+ client: Pool | PoolClient | null
157
177
  ): Promise<PGResponse>;
158
178
 
159
- export {
160
- SQLEntity,
161
- Property,
162
- filter,
163
- execute,
164
- };
165
-
@@ -459,7 +459,7 @@ function cleanFilters(filters, properties) {
459
459
  delete filters[k];
460
460
  continue;
461
461
  }
462
- if (!prop.filter) {
462
+ if (!prop.isFilterable) {
463
463
  log.warn(`${LOGS_PREFIX}Filters: skipping unfilterable property: ${k}`);
464
464
  delete filters[k];
465
465
  continue;
@@ -497,10 +497,10 @@ function generateSummary(name, table, properties) {
497
497
  lines.push(`│ │ ├─ Type: ${p.type}`);
498
498
  lines.push(`│ │ ├─ Min: ${p.min}`);
499
499
  lines.push(`│ │ ├─ Max: ${p.max}`);
500
- lines.push(`│ │ ├─ need: ${p.need}`);
501
- lines.push(`│ │ ├─ Safe: ${p.safe}`);
502
- lines.push(`│ │ ├─ TypeCheck: ${p.typeCheck}`);
503
- lines.push(`│ │ ├─ Filter: ${p.filter}`);
500
+ lines.push(`│ │ ├─ RequiredFor: ${p.requiredFor}`);
501
+ lines.push(`│ │ ├─ IsPrivate: ${p.isPrivate}`);
502
+ lines.push(`│ │ ├─ IsTypeChecked: ${p.isTypeChecked}`);
503
+ lines.push(`│ │ ├─ IsFilterable: ${p.isFilterable}`);
504
504
  lines.push(`│ │ ├─ Operations: [${p.operations.join(', ')}]`);
505
505
  lines.push(`│ │ ├─ Sanitize: ${p.sanitize}`);
506
506
  lines.push(`│ │ ├─ Normalize: ${p.normalize}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dwtechs/antity-pgsql",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Open source library to add PostgreSQL support to @dwtechs/Antity entities.",
5
5
  "keywords": [
6
6
  "entities"
@@ -38,7 +38,7 @@
38
38
  "dependencies": {
39
39
  "@dwtechs/checkard": "3.6.0",
40
40
  "@dwtechs/winstan": "0.5.0",
41
- "@dwtechs/antity": "0.15.0",
41
+ "@dwtechs/antity": "0.16.0",
42
42
  "@dwtechs/sparray": "0.2.1",
43
43
  "pg": "8.13.1"
44
44
  },