@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 +23 -23
- package/dist/antity-pgsql.d.ts +32 -19
- package/dist/antity-pgsql.js +5 -5
- package/package.json +2 -2
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
isTypeChecked: true,
|
|
66
|
+
isFilterable: true,
|
|
67
|
+
requiredFor: ["PUT"],
|
|
68
68
|
operations: ["SELECT", "UPDATE"],
|
|
69
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
isTypeChecked: true,
|
|
80
|
+
isFilterable: false,
|
|
81
|
+
requiredFor: ["POST", "PUT"],
|
|
82
82
|
operations: ["SELECT", "UPDATE"],
|
|
83
|
-
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
isTypeChecked: true,
|
|
94
|
+
isFilterable: false,
|
|
95
|
+
requiredFor: ["POST", "PUT"],
|
|
96
96
|
operations: ["SELECT", "UPDATE"],
|
|
97
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
isTypeChecked: true,
|
|
108
|
+
isFilterable: true,
|
|
109
|
+
requiredFor: ["POST", "PUT"],
|
|
110
110
|
operations: ["SELECT", "UPDATE"],
|
|
111
|
-
|
|
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.
|
|
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
|
|
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
|
-
|
|
|
364
|
-
|
|
|
365
|
-
|
|
|
366
|
-
|
|
|
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
|
package/dist/antity-pgsql.d.ts
CHANGED
|
@@ -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"
|
|
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:
|
|
79
|
-
private ins:
|
|
80
|
-
private upd:
|
|
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:
|
|
176
|
+
client: Pool | PoolClient | null
|
|
157
177
|
): Promise<PGResponse>;
|
|
158
178
|
|
|
159
|
-
export {
|
|
160
|
-
SQLEntity,
|
|
161
|
-
Property,
|
|
162
|
-
filter,
|
|
163
|
-
execute,
|
|
164
|
-
};
|
|
165
|
-
|
package/dist/antity-pgsql.js
CHANGED
|
@@ -459,7 +459,7 @@ function cleanFilters(filters, properties) {
|
|
|
459
459
|
delete filters[k];
|
|
460
460
|
continue;
|
|
461
461
|
}
|
|
462
|
-
if (!prop.
|
|
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(`│ │ ├─
|
|
501
|
-
lines.push(`│ │ ├─
|
|
502
|
-
lines.push(`│ │ ├─
|
|
503
|
-
lines.push(`│ │ ├─
|
|
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.
|
|
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.
|
|
41
|
+
"@dwtechs/antity": "0.16.0",
|
|
42
42
|
"@dwtechs/sparray": "0.2.1",
|
|
43
43
|
"pg": "8.13.1"
|
|
44
44
|
},
|