1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | Object.defineProperty(exports, "__esModule", { value: true });
|
7 | exports.getOAIPrimitiveType = exports.matchDateFormat = exports.isValidDateTime = exports.isFalse = exports.isTrue = exports.isEmpty = void 0;
|
8 | const tslib_1 = require("tslib");
|
9 | const debug_1 = tslib_1.__importDefault(require("debug"));
|
10 | const debug = (0, debug_1.default)('loopback:rest:coercion');
|
11 | function isEmpty(data) {
|
12 | const result = data === '';
|
13 | debug('isEmpty(%j) -> %s', data, result);
|
14 | return result;
|
15 | }
|
16 | exports.isEmpty = isEmpty;
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | function isTrue(data) {
|
24 | return ['TRUE', '1'].includes(data.toUpperCase());
|
25 | }
|
26 | exports.isTrue = isTrue;
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | function isFalse(data) {
|
33 | return ['FALSE', '0'].includes(data.toUpperCase());
|
34 | }
|
35 | exports.isFalse = isFalse;
|
36 |
|
37 |
|
38 |
|
39 | function isValidDateTime(data) {
|
40 | return isNaN(data.getTime()) ? false : true;
|
41 | }
|
42 | exports.isValidDateTime = isValidDateTime;
|
43 | const REGEX_RFC3339_DATE = /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])$/;
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | function matchDateFormat(date) {
|
50 | const pattern = new RegExp(REGEX_RFC3339_DATE);
|
51 | const result = pattern.test(date);
|
52 | debug('matchDateFormat(%j) -> %s', date, result);
|
53 | return result;
|
54 | }
|
55 | exports.matchDateFormat = matchDateFormat;
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | function getOAIPrimitiveType(type, format) {
|
63 | if (type === 'object' || type === 'array')
|
64 | return type;
|
65 | if (type === 'string') {
|
66 | switch (format) {
|
67 | case 'byte':
|
68 | return 'byte';
|
69 | case 'binary':
|
70 | return 'binary';
|
71 | case 'date':
|
72 | return 'date';
|
73 | case 'date-time':
|
74 | return 'date-time';
|
75 | case 'password':
|
76 | return 'password';
|
77 | default:
|
78 | return 'string';
|
79 | }
|
80 | }
|
81 | if (type === 'boolean')
|
82 | return 'boolean';
|
83 | if (type === 'number')
|
84 | switch (format) {
|
85 | case 'float':
|
86 | return 'float';
|
87 | case 'double':
|
88 | return 'double';
|
89 | default:
|
90 | return 'number';
|
91 | }
|
92 | if (type === 'integer')
|
93 | return format === 'int64' ? 'long' : 'integer';
|
94 | }
|
95 | exports.getOAIPrimitiveType = getOAIPrimitiveType;
|
96 |
|
\ | No newline at end of file |