nodester 0.7.17 → 0.7.18

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.
@@ -8,27 +8,59 @@
8
8
 
9
9
  module.exports = {
10
10
  UUID: _UUID,
11
+ UUIDV1: _UUID,
12
+ UUIDV4: _UUID,
11
13
 
12
14
  CHAR: _STRING,
13
15
  VARCHAR: _STRING,
14
16
  STRING: _STRING,
15
17
  TEXT: _TEXT,
18
+ CITEXT: _STRING,
19
+ TSVECTOR: _STRING,
20
+
21
+ // Network address types are stored as strings.
22
+ CIDR: _STRING,
23
+ INET: _STRING,
24
+ MACADDR: _STRING,
16
25
 
17
26
  ENUM: _ENUM,
18
27
 
19
28
  NUMBER: _NUMBER,
29
+ DECIMAL: _NUMBER,
20
30
 
21
31
  INT: _INTEGER,
22
32
  INTEGER: _INTEGER,
23
33
  BIGINT: _INTEGER,
34
+ TINYINT: _INTEGER,
35
+ SMALLINT: _INTEGER,
36
+ MEDIUMINT: _INTEGER,
37
+
38
+ FLOAT: _FLOAT,
39
+ REAL: _FLOAT,
40
+ DOUBLE: _FLOAT,
24
41
 
25
42
  BOOLEAN: _BOOLEAN,
26
43
 
27
44
  DATE: _DATE,
28
45
  DATETIME: _DATE,
46
+ NOW: _DATE,
47
+ DATEONLY: _DATEONLY,
48
+ TIME: _TIME,
29
49
 
30
50
  JSON: _JSON,
31
- JSONTYPE: _JSON
51
+ JSONTYPE: _JSON,
52
+ JSONB: _JSON,
53
+ // Geometry/Geography accept GeoJSON objects, HSTORE accepts key/value objects.
54
+ GEOMETRY: _JSON,
55
+ GEOGRAPHY: _JSON,
56
+ HSTORE: _JSON,
57
+
58
+ ARRAY: _ARRAY,
59
+ RANGE: _ARRAY,
60
+
61
+ BLOB: _BLOB,
62
+
63
+ VIRTUAL: _VIRTUAL
32
64
  }
33
65
 
34
66
  function _UUID(value=undefined, options={ fallback:undefined }) {
@@ -104,6 +136,11 @@ function _INTEGER(value=undefined, options={ fallback:undefined, min:undefined,
104
136
  return num === undefined ? options?.fallback : parseInt(num);
105
137
  }
106
138
 
139
+ function _FLOAT(value=undefined, options={ fallback:undefined, min:undefined, max:undefined }) {
140
+ const num = _NUMBER(value, { fallback:undefined, min:options?.min, max:options?.max });
141
+ return num === undefined ? options?.fallback : parseFloat(num);
142
+ }
143
+
107
144
  function _BOOLEAN(value=undefined, options={ fallback:undefined }) {
108
145
  try {
109
146
  // If clear boolean.
@@ -152,6 +189,89 @@ function _DATE(value=undefined, options={ fallback:undefined }) {
152
189
  }
153
190
 
154
191
 
192
+ function _DATEONLY(value=undefined, options={ fallback:undefined }) {
193
+ try {
194
+ const type = Object.prototype.toString.call(value);
195
+
196
+ switch(type) {
197
+ case('[object Date]'): {
198
+ if (isNaN(value.valueOf()))
199
+ throw new Error('Not a date');
200
+
201
+ // Normalize to a date-only string (YYYY-MM-DD).
202
+ return value.toISOString().slice(0, 10);
203
+ }
204
+ case('[object String]'): {
205
+ const check = new Date(value);
206
+ if (isNaN(check.valueOf()))
207
+ throw new Error('Not a date');
208
+
209
+ // Normalize to a date-only string (YYYY-MM-DD).
210
+ return check.toISOString().slice(0, 10);
211
+ }
212
+ default:
213
+ break;
214
+ }
215
+
216
+ throw new Error('Not a date');
217
+ }
218
+ catch(ex) {
219
+ return options?.fallback;
220
+ }
221
+ }
222
+
223
+
224
+ function _TIME(value=undefined, options={ fallback:undefined }) {
225
+ try {
226
+ if (typeof value !== 'string')
227
+ throw new Error(`Not a time string`);
228
+
229
+ return value;
230
+ }
231
+ catch(ex) {
232
+ return options?.fallback;
233
+ }
234
+ }
235
+
236
+
237
+ function _ARRAY(value=undefined, options={ fallback:undefined }) {
238
+ try {
239
+ if (Array.isArray(value))
240
+ return value;
241
+
242
+ // Allow a JSON-encoded array string.
243
+ if (typeof value === 'string') {
244
+ const parsed = JSON.parse(value);
245
+ if (Array.isArray(parsed))
246
+ return parsed;
247
+ }
248
+
249
+ throw new Error(`Not an Array`);
250
+ }
251
+ catch(ex) {
252
+ return options?.fallback;
253
+ }
254
+ }
255
+
256
+
257
+ function _BLOB(value=undefined, options={ fallback:undefined }) {
258
+ try {
259
+ if (Buffer.isBuffer(value) || typeof value === 'string')
260
+ return value;
261
+
262
+ throw new Error(`Not a Buffer or String`);
263
+ }
264
+ catch(ex) {
265
+ return options?.fallback;
266
+ }
267
+ }
268
+
269
+
270
+ function _VIRTUAL(value=undefined, options={ fallback:undefined }) {
271
+ return value === undefined ? options?.fallback : value;
272
+ }
273
+
274
+
155
275
  function _JSON(value=undefined, options={ fallback:undefined }) {
156
276
  try {
157
277
  if (typeof value === 'string')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodester",
3
- "version": "0.7.17",
3
+ "version": "0.7.18",
4
4
  "description": "A versatile REST framework for Node.js",
5
5
  "directories": {
6
6
  "docs": "docs",