@sap/xsodata 8.2.1 → 8.3.1
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/CHANGELOG.md +10 -0
- package/index.js +2 -2
- package/lib/configuration.js +1 -1
- package/lib/db/connect.js +1 -1
- package/lib/db/dbSegment.js +68 -123
- package/lib/db/dbVersionChecks.js +2 -8
- package/lib/handlerConfiguration.js +2 -2
- package/lib/http/conditionalHttpHandler.js +27 -34
- package/lib/http/simpleHttpRequest.js +14 -18
- package/lib/http/simpleHttpResponse.js +9 -6
- package/lib/http/uriParser.js +9 -9
- package/lib/http/validator/httpRequestValidator.js +9 -9
- package/lib/model/annotationFactory.js +11 -11
- package/lib/model/association.js +3 -3
- package/lib/model/entityType.js +33 -67
- package/lib/model/metadataReader.js +31 -52
- package/lib/model/model.js +0 -1
- package/lib/model/validator/xsoDataConcurrencyTokenValidator.js +6 -6
- package/lib/model/xsodataReader.js +36 -28
- package/lib/processor/authorizationProcessor.js +22 -33
- package/lib/processor/batchProcessor.js +22 -33
- package/lib/processor/errorProcessor.js +4 -4
- package/lib/processor/exitProcessor.js +19 -19
- package/lib/processor/processor.js +9 -9
- package/lib/processor/resourceProcessor.js +31 -61
- package/lib/processor/resourceProcessorDelete.js +16 -16
- package/lib/processor/resourceProcessorDeleteLinks.js +25 -25
- package/lib/processor/resourceProcessorGet.js +5 -5
- package/lib/processor/resourceProcessorPost.js +43 -45
- package/lib/processor/resourceProcessorPut.js +35 -39
- package/lib/processor/resourceProcessorPutPostLinks.js +38 -39
- package/lib/security/securityContext.js +5 -5
- package/lib/serializer/atomSerializer.js +54 -55
- package/lib/serializer/atomXmlToJsonSerializer.js +32 -44
- package/lib/serializer/content.js +5 -5
- package/lib/serializer/json.js +31 -33
- package/lib/serializer/jsonSerializer.js +4 -4
- package/lib/serializer/metadataSerializer.js +32 -35
- package/lib/serializer/serializer.js +29 -43
- package/lib/serializer/serviceSerializer.js +19 -24
- package/lib/serializer/value.js +1 -2
- package/lib/serializer/xmlToJsonSerializer.js +18 -18
- package/lib/sql/createDeleteLinksStatements.js +10 -10
- package/lib/sql/createDeleteStatements.js +12 -12
- package/lib/sql/createGetStatements.js +49 -107
- package/lib/sql/createLinksSQLStatements_1_n.js +27 -27
- package/lib/sql/createPutPostLinksStatements.js +9 -9
- package/lib/sql/createPutStatements.js +0 -1
- package/lib/sql/dataCollectorDelete.js +9 -9
- package/lib/sql/dataCollectorDeleteLinks.js +3 -3
- package/lib/sql/dataCollectorGet.js +9 -17
- package/lib/sql/dataCollectorLinks.js +23 -27
- package/lib/sql/dataCollectorPost.js +20 -20
- package/lib/sql/dataCollectorPut.js +36 -36
- package/lib/sql/dataCollectorPutPostLinks.js +3 -3
- package/lib/sql/sqlStatement.js +81 -128
- package/lib/sql/sqlTools.js +3 -7
- package/lib/sql/statementProcessor.js +7 -14
- package/lib/uri/applyChecks.js +3 -3
- package/lib/uri/checks/checkAllowedMethod.js +3 -3
- package/lib/uri/checks/checkAllowedMethodForBatch.js +2 -2
- package/lib/uri/checks/checkAllowedMethodsForResourcePath.js +3 -3
- package/lib/uri/checks/checkFilterOnAggregatedColumn.js +5 -5
- package/lib/uri/checks/checkFilterOrderByOnGenKeyColumn.js +6 -6
- package/lib/uri/checks/checkGenKeyRestrictions.js +2 -2
- package/lib/uri/checks/checkModificationForbidden.js +3 -3
- package/lib/uri/checks/checkPostPutDeleteChecks.js +5 -5
- package/lib/uri/checks/checkSystemQueryOptions.js +10 -10
- package/lib/uri/checks.js +15 -15
- package/lib/uri/expandSelectTreeBuilder.js +12 -16
- package/lib/uri/oDataUriParser.js +20 -20
- package/lib/uri/queryParameterParser.js +25 -33
- package/lib/uri/resourcePathParser.js +47 -62
- package/lib/uri/uriType.js +4 -4
- package/lib/utils/associations.js +4 -4
- package/lib/utils/batch/batchExecutor.js +49 -51
- package/lib/utils/batch/batchObjects.js +10 -10
- package/lib/utils/batch/batchParser.js +27 -28
- package/lib/utils/batch/batchWriter.js +1 -1
- package/lib/utils/checkContentType.js +34 -39
- package/lib/utils/debugView.js +35 -36
- package/lib/utils/errors/applicationError.js +2 -2
- package/lib/utils/errors/debugInfo.js +2 -2
- package/lib/utils/errors/http/badRequest.js +2 -2
- package/lib/utils/errors/http/forbidden.js +2 -2
- package/lib/utils/errors/http/methodNotAllowed.js +2 -2
- package/lib/utils/errors/http/notAcceptable.js +2 -2
- package/lib/utils/errors/http/notFound.js +2 -2
- package/lib/utils/errors/http/notImplemented.js +2 -2
- package/lib/utils/errors/http/notModified.js +2 -2
- package/lib/utils/errors/http/notSupported.js +2 -2
- package/lib/utils/errors/http/preconditionFailed.js +2 -2
- package/lib/utils/errors/http/preconditionRequired.js +2 -2
- package/lib/utils/errors/http/unauthorized.js +2 -2
- package/lib/utils/errors/http/unsupportedMediaType.js +2 -2
- package/lib/utils/errors/httpError.js +2 -2
- package/lib/utils/errors/internalError.js +2 -2
- package/lib/utils/errors/modelFileError.js +2 -2
- package/lib/utils/errors/sqlError.js +2 -2
- package/lib/utils/errors/testError.js +2 -2
- package/lib/utils/errors/typeError.js +5 -5
- package/lib/utils/errors/xsODataError.js +1 -1
- package/lib/utils/logger.js +21 -32
- package/lib/utils/measurement.js +14 -13
- package/lib/utils/requestContext.js +2 -2
- package/lib/utils/stateMaschine.js +6 -6
- package/lib/utils/tableCleanup.js +3 -3
- package/lib/utils/typeConverter.js +21 -21
- package/lib/utils/typeConverters/converterTools.js +25 -331
- package/lib/utils/typeConverters/dbToJson.js +3 -3
- package/lib/utils/typeConverters/dbToUri.js +7 -7
- package/lib/utils/typeConverters/dbToXml.js +9 -9
- package/lib/utils/typeConverters/jsonToDb.js +20 -27
- package/lib/utils/typeConverters/uriToDb.js +45 -92
- package/lib/utils/typeConverters/xmlValueToJson.js +9 -13
- package/lib/utils/typedObjects.js +11 -79
- package/lib/utils/utils.js +20 -23
- package/lib/xsodata.js +37 -47
- package/package.json +9 -11
- package/.npmignore +0 -40
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const jsonToDb = exports.jsonToDb = {};
|
|
4
|
+
const XsODataTypeError = require('./../errors/typeError');
|
|
5
|
+
const converterTool = require('./converterTools');
|
|
6
6
|
|
|
7
7
|
jsonToDb['Edm.DateTime'] = function jsonToDbEdmDateTime(jsonValue, dbDataType) {
|
|
8
8
|
if (jsonValue === null) {
|
|
9
9
|
return null;
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
let date;
|
|
12
12
|
if (dbDataType === 'DATE' || dbDataType === 'DAYDATE') {
|
|
13
13
|
/* in "/Date(-6847804800000)/" */
|
|
14
14
|
/* out "1753-01-01" */
|
|
15
15
|
/* in "/Date(253402214400000)/" */
|
|
16
16
|
/* out "9999-12-31" */
|
|
17
|
-
|
|
18
|
-
// throw new Type_Error('Type SECONDDATE must start with "Date("');
|
|
19
|
-
//}
|
|
17
|
+
|
|
20
18
|
date = new Date(parseInt(jsonValue.substring(6, jsonValue.length - 2)));
|
|
21
19
|
return date.toISOString().substring(0, 10);
|
|
22
20
|
|
|
@@ -25,9 +23,7 @@ jsonToDb['Edm.DateTime'] = function jsonToDbEdmDateTime(jsonValue, dbDataType) {
|
|
|
25
23
|
/* out "1753-01-01T00:00:00" */
|
|
26
24
|
/* in "/Date(253402263296000)/" */
|
|
27
25
|
/* out "9999-12-31T13:34:56" */
|
|
28
|
-
|
|
29
|
-
// throw new Type_Error('Type SECONDDATE must start with "Date("');
|
|
30
|
-
//}
|
|
26
|
+
|
|
31
27
|
date = new Date(parseInt(jsonValue.substring(6, jsonValue.length - 2)));
|
|
32
28
|
return date.toISOString().substring(0, 19);
|
|
33
29
|
|
|
@@ -36,15 +32,13 @@ jsonToDb['Edm.DateTime'] = function jsonToDbEdmDateTime(jsonValue, dbDataType) {
|
|
|
36
32
|
/* out "1753-01-01T00:00:00" */
|
|
37
33
|
/* in "/Date(253402300799999)/" */
|
|
38
34
|
/* out "9999-12-31T23:59:59.999" */
|
|
39
|
-
|
|
40
|
-
// throw new Type_Error('Type SECONDDATE must start with "Date("');
|
|
41
|
-
//}
|
|
35
|
+
|
|
42
36
|
date = new Date(parseInt(jsonValue.substring(6, jsonValue.length - 2)));
|
|
43
37
|
return date.toISOString().substring(0, 23);
|
|
44
38
|
} else if (dbDataType === 'LONGDATE') {
|
|
45
|
-
throw new
|
|
39
|
+
throw new XsODataTypeError('db type LONGDATE is not supported');
|
|
46
40
|
} else {
|
|
47
|
-
throw new
|
|
41
|
+
throw new XsODataTypeError('db type must be DATE, SECONDDATE or TIMESTAMP');
|
|
48
42
|
}
|
|
49
43
|
};
|
|
50
44
|
|
|
@@ -55,14 +49,13 @@ jsonToDb['Edm.Time'] = function jsonToDbEdmTime(jsonValue, dbDataType, YMDmustZe
|
|
|
55
49
|
/* out "23:59:59" */
|
|
56
50
|
/*--->'Edm.Time' */
|
|
57
51
|
if (dbDataType !== 'TIME' && dbDataType !== 'SECONDTIME') {
|
|
58
|
-
throw new
|
|
52
|
+
throw new XsODataTypeError('db type must be compatible to TIME');
|
|
59
53
|
}
|
|
60
54
|
|
|
61
55
|
if (jsonValue === null) {
|
|
62
56
|
return null;
|
|
63
57
|
}
|
|
64
58
|
|
|
65
|
-
//old reged var match = /PT([0-9]+)H([0-9]+)M([0-9]+)S/i.exec(jsonValue);
|
|
66
59
|
return converterTool.checkEdmTime(jsonValue, dbDataType,false,
|
|
67
60
|
dbDataType === 'TIME' && YMDmustZero, // YMDmustZero
|
|
68
61
|
false,// no fractions
|
|
@@ -71,7 +64,7 @@ jsonToDb['Edm.Time'] = function jsonToDbEdmTime(jsonValue, dbDataType, YMDmustZe
|
|
|
71
64
|
|
|
72
65
|
jsonToDb['Edm.Byte'] = function jsonToDbEdmByte(jsonValue, dbDataType) {
|
|
73
66
|
if (dbDataType !== 'TINYINT') {
|
|
74
|
-
throw new
|
|
67
|
+
throw new XsODataTypeError('db type must be TINYINT');
|
|
75
68
|
}
|
|
76
69
|
/* in 0 */
|
|
77
70
|
/* out 0 */
|
|
@@ -82,7 +75,7 @@ jsonToDb['Edm.Byte'] = function jsonToDbEdmByte(jsonValue, dbDataType) {
|
|
|
82
75
|
|
|
83
76
|
jsonToDb['Edm.Int16'] = function jsonToDbEdmInt16(jsonValue, dbDataType) {
|
|
84
77
|
if (dbDataType !== 'SMALLINT') {
|
|
85
|
-
throw new
|
|
78
|
+
throw new XsODataTypeError('db type must be SMALLINT');
|
|
86
79
|
}
|
|
87
80
|
/* in -32767 */
|
|
88
81
|
/* out -32767 */
|
|
@@ -93,7 +86,7 @@ jsonToDb['Edm.Int16'] = function jsonToDbEdmInt16(jsonValue, dbDataType) {
|
|
|
93
86
|
|
|
94
87
|
jsonToDb['Edm.Int32'] = function jsonToDbEdmInt32(jsonValue, dbDataType) {
|
|
95
88
|
if (dbDataType !== 'INTEGER') {
|
|
96
|
-
throw new
|
|
89
|
+
throw new XsODataTypeError('db type must be INTEGER');
|
|
97
90
|
}
|
|
98
91
|
/* in -2147483648 */
|
|
99
92
|
/* out -2147483648 */
|
|
@@ -104,7 +97,7 @@ jsonToDb['Edm.Int32'] = function jsonToDbEdmInt32(jsonValue, dbDataType) {
|
|
|
104
97
|
|
|
105
98
|
jsonToDb['Edm.Int64'] = function jsonToDbEdmInt64(jsonValue, dbDataType) {
|
|
106
99
|
if (dbDataType !== 'BIGINT') {
|
|
107
|
-
throw new
|
|
100
|
+
throw new XsODataTypeError('db type must be BIGINT');
|
|
108
101
|
}
|
|
109
102
|
/* in "-9223372036854775808" */
|
|
110
103
|
/* out "-9223372036854775808" */
|
|
@@ -127,7 +120,7 @@ jsonToDb['Edm.Decimal'] = function jsonToDbEdmDecimal(jsonValue, dbDataType) {
|
|
|
127
120
|
/* out "1234567890.012345678901234567890123" */
|
|
128
121
|
return jsonValue;
|
|
129
122
|
} else {
|
|
130
|
-
throw new
|
|
123
|
+
throw new XsODataTypeError("db type must be SMALLDECIMAL or DECIMAL");
|
|
131
124
|
}
|
|
132
125
|
};
|
|
133
126
|
|
|
@@ -148,7 +141,7 @@ jsonToDb['Edm.Single'] = function jsonToDbEdmSingle(jsonValue, dbDataType) {
|
|
|
148
141
|
/* out 3.402823466e+38 */
|
|
149
142
|
return parseFloat(jsonValue);
|
|
150
143
|
} else {
|
|
151
|
-
throw new
|
|
144
|
+
throw new XsODataTypeError("db type must be REAL or DECIMAL");
|
|
152
145
|
}
|
|
153
146
|
};
|
|
154
147
|
|
|
@@ -163,7 +156,7 @@ jsonToDb['Edm.Double'] = function jsonToDbEdmDouble(jsonValue, dbDataType) {
|
|
|
163
156
|
/* out 1.7976931348623157e+308 */
|
|
164
157
|
return parseFloat(jsonValue);
|
|
165
158
|
} else {
|
|
166
|
-
throw new
|
|
159
|
+
throw new XsODataTypeError("db type must be DOUBLE");
|
|
167
160
|
}
|
|
168
161
|
|
|
169
162
|
};
|
|
@@ -194,7 +187,7 @@ jsonToDb['Edm.String'] = function jsonToDbEdmString(jsonValue, dbDataType) {
|
|
|
194
187
|
/* out buffer */
|
|
195
188
|
return Buffer.from(jsonValue, 'utf8');
|
|
196
189
|
} else {
|
|
197
|
-
throw new
|
|
190
|
+
throw new XsODataTypeError('db type must be VARCHAR, NVARCHAR, ALPHANUM, SHORTTEXT, CHAR, NCHAR, CLOB, NCLOB');
|
|
198
191
|
}
|
|
199
192
|
};
|
|
200
193
|
|
|
@@ -207,7 +200,7 @@ jsonToDb['Edm.Binary'] = function jsonToDbEdmBinary(jsonValue, dbDataType) {
|
|
|
207
200
|
/* out buffer */
|
|
208
201
|
return Buffer.from(jsonValue, 'base64');
|
|
209
202
|
} else if (dbDataType === 'BINARY') {
|
|
210
|
-
throw new
|
|
203
|
+
throw new XsODataTypeError("db type BINARY is not supported");
|
|
211
204
|
} else if (dbDataType === 'VARBINARY') {
|
|
212
205
|
/* in iVBONA==" */
|
|
213
206
|
/* out buffer */
|
|
@@ -217,5 +210,5 @@ jsonToDb['Edm.Binary'] = function jsonToDbEdmBinary(jsonValue, dbDataType) {
|
|
|
217
210
|
};
|
|
218
211
|
|
|
219
212
|
jsonToDb['Edm.Guid'] = function jsonToDbEdmGuiD(/*jsonValue, dbDataType*/) {
|
|
220
|
-
throw new
|
|
213
|
+
throw new XsODataTypeError('edm type Edm.Guid is not supported');
|
|
221
214
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const uriToDb = exports.uriToDb = {};
|
|
5
|
+
const XsODataTypeError = require('./../errors/typeError');
|
|
6
|
+
const converterTool = require('./converterTools');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
function padZero(string, len) {
|
|
@@ -34,27 +34,26 @@ uriToDb['Edm.DateTime'] = function uriToDbEdmDateTime(value, dbDataType) {
|
|
|
34
34
|
// /* out "9999-12-31T23:59:59.999" */
|
|
35
35
|
//}
|
|
36
36
|
//else if (dbDataType === 'LONGDATE') {
|
|
37
|
-
/// throw new
|
|
37
|
+
/// throw new XsODataTypeError('db type LONGDATE is not supported');
|
|
38
38
|
//} else {
|
|
39
|
-
// throw new
|
|
39
|
+
// throw new XsODataTypeError('db type must be DATE, SECONDDATE or TIMESTAMP');
|
|
40
40
|
//}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
const raw = value.substring(9, value.length - 1);
|
|
42
|
+
const datetime = raw.split('T');
|
|
43
|
+
const dateParts = datetime[0].split('-');
|
|
44
44
|
dateParts[0] = padZero(dateParts[0], 4);
|
|
45
45
|
dateParts[1] = padZero(dateParts[1], 2);
|
|
46
46
|
dateParts[2] = padZero(dateParts[2], 2);
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
const timeParts = datetime[1].split(':');
|
|
49
49
|
timeParts[0] = (timeParts[0]) ? padZero(timeParts[0], 2) : '00';
|
|
50
50
|
timeParts[1] = (timeParts[1]) ? padZero(timeParts[1], 2) : '00';
|
|
51
51
|
if (timeParts.length > 2) {
|
|
52
|
-
|
|
52
|
+
const x = timeParts[2].split('.');
|
|
53
53
|
timeParts[2] = padZero(x[0], 2);
|
|
54
54
|
if (x[1]) {
|
|
55
55
|
if (x[1].length > 7) {
|
|
56
|
-
throw new
|
|
57
|
-
//timeParts[3] = x[1].substr(0, 7);
|
|
56
|
+
throw new XsODataTypeError('To many fractional seconds in ' + value);
|
|
58
57
|
} else {
|
|
59
58
|
timeParts[3] = x[1];
|
|
60
59
|
}
|
|
@@ -72,12 +71,10 @@ uriToDb['Edm.DateTime'] = function uriToDbEdmDateTime(value, dbDataType) {
|
|
|
72
71
|
(timeParts[3] ? '.' + timeParts[3] : '');
|
|
73
72
|
|
|
74
73
|
}
|
|
75
|
-
throw new
|
|
74
|
+
throw new XsODataTypeError('db type must be DATE, SECONDDATE or TIMESTAMP');
|
|
76
75
|
|
|
77
76
|
};
|
|
78
77
|
|
|
79
|
-
// old
|
|
80
|
-
// var timeRegexObj = /^time'PT(?:(\d{1,2})H)?(?:(\d{1,2})M)?(?:(\d{1,2})(?:\.(\d*))?S)?'$/;
|
|
81
78
|
uriToDb['Edm.Time'] = function uriToDbEdmTime(value, dbDataType, yMDmustZero = true) {
|
|
82
79
|
/* in "time'PT0H0M0S'" */
|
|
83
80
|
/* out "00:00:00" */
|
|
@@ -86,7 +83,7 @@ uriToDb['Edm.Time'] = function uriToDbEdmTime(value, dbDataType, yMDmustZero = t
|
|
|
86
83
|
|
|
87
84
|
/*--->'Edm.Time' */
|
|
88
85
|
if (dbDataType !== 'TIME' && dbDataType !== 'SECONDTIME') {
|
|
89
|
-
throw new
|
|
86
|
+
throw new XsODataTypeError('db type must be TIME');
|
|
90
87
|
}
|
|
91
88
|
|
|
92
89
|
return converterTool.checkEdmTime(value, dbDataType,true,
|
|
@@ -97,7 +94,7 @@ uriToDb['Edm.Time'] = function uriToDbEdmTime(value, dbDataType, yMDmustZero = t
|
|
|
97
94
|
|
|
98
95
|
uriToDb['Edm.Byte'] = function uriToDbEdmByte(value, dbDataType) {
|
|
99
96
|
if (dbDataType !== 'TINYINT') {
|
|
100
|
-
throw new
|
|
97
|
+
throw new XsODataTypeError('db type must be TINYINT');
|
|
101
98
|
}
|
|
102
99
|
/* in "0" */
|
|
103
100
|
/* out 0 */
|
|
@@ -108,7 +105,7 @@ uriToDb['Edm.Byte'] = function uriToDbEdmByte(value, dbDataType) {
|
|
|
108
105
|
|
|
109
106
|
uriToDb['Edm.Int16'] = function uriToDbEdmInt16(value, dbDataType) {
|
|
110
107
|
if (dbDataType !== 'SMALLINT') {
|
|
111
|
-
throw new
|
|
108
|
+
throw new XsODataTypeError('db type must be SMALLINT');
|
|
112
109
|
}
|
|
113
110
|
/* in "-32767" */
|
|
114
111
|
/* out -32767 */
|
|
@@ -119,7 +116,7 @@ uriToDb['Edm.Int16'] = function uriToDbEdmInt16(value, dbDataType) {
|
|
|
119
116
|
|
|
120
117
|
uriToDb['Edm.Int32'] = function uriToDbEdmInt32(value, dbDataType) {
|
|
121
118
|
if (dbDataType !== 'INTEGER') {
|
|
122
|
-
throw new
|
|
119
|
+
throw new XsODataTypeError('db type must be INTEGER');
|
|
123
120
|
}
|
|
124
121
|
/* in "-2147483648" */
|
|
125
122
|
/* out -2147483648 */
|
|
@@ -135,67 +132,39 @@ uriToDb['Edm.Int64'] = function uriToDbEdmInt64(value, dbDataType) {
|
|
|
135
132
|
/* out "9223372036854775807" */
|
|
136
133
|
|
|
137
134
|
if (dbDataType !== 'BIGINT') {
|
|
138
|
-
throw new
|
|
135
|
+
throw new XsODataTypeError('db type must be BIGINT');
|
|
139
136
|
}
|
|
140
137
|
|
|
141
|
-
|
|
138
|
+
const last = value.substr(value.length - 1).toUpperCase();
|
|
142
139
|
if (last !== 'L') {
|
|
143
|
-
throw new
|
|
140
|
+
throw new XsODataTypeError('uri type indicator must be (l|L)');
|
|
144
141
|
}
|
|
145
142
|
return value.substring(0, value.length - 1);
|
|
146
143
|
};
|
|
147
144
|
|
|
148
145
|
uriToDb['Edm.Decimal'] = function uriToDbEdmDecimal(value, dbDataType) {
|
|
149
|
-
|
|
150
|
-
if (dbDataType === 'SMALLDECIMAL') {
|
|
151
|
-
/* in "-1.4e-45m" */
|
|
152
|
-
/* out "-1.4e-45" */
|
|
153
|
-
/* in "1.4e-45m" */
|
|
154
|
-
/* out "1.4e-45" */
|
|
146
|
+
let last;
|
|
147
|
+
if (dbDataType === 'SMALLDECIMAL' || dbDataType === 'DECIMAL') {
|
|
155
148
|
last = value.substr(value.length - 1).toUpperCase();
|
|
156
149
|
if (last !== 'M') {
|
|
157
|
-
throw new
|
|
158
|
-
}
|
|
159
|
-
return value.substring(0, value.length - 1);
|
|
160
|
-
} else if (dbDataType === 'DECIMAL') {
|
|
161
|
-
/* in "1234567890.012345678901234567890123m" */
|
|
162
|
-
/* out "1234567890.012345678901234567890123" */
|
|
163
|
-
/* in "1234567890.012345678901234567890123m" */
|
|
164
|
-
/* out "1234567890.012345678901234567890123" */
|
|
165
|
-
last = value.substr(value.length - 1).toUpperCase();
|
|
166
|
-
if (last !== 'M') {
|
|
167
|
-
throw new Type_Error('uri type indicator must be (m|M)');
|
|
150
|
+
throw new XsODataTypeError('uri type indicator must be (m|M)');
|
|
168
151
|
}
|
|
169
152
|
return value.substring(0, value.length - 1);
|
|
170
153
|
} else {
|
|
171
|
-
throw new
|
|
154
|
+
throw new XsODataTypeError("db type must be SMALLDECIMAL or DECIMAL");
|
|
172
155
|
}
|
|
173
156
|
};
|
|
174
157
|
|
|
175
158
|
uriToDb['Edm.Single'] = function uriToDbEdmSingle(value, dbDataType) {
|
|
176
|
-
|
|
177
|
-
if (dbDataType === 'REAL') {
|
|
178
|
-
/* in "-3.40282346e+38f" */
|
|
179
|
-
/* out -3.4028234663852886e+38 */
|
|
180
|
-
/* in "3.40282346e+38f" */
|
|
181
|
-
/* out 3.3028234797236365e+38 */
|
|
182
|
-
last = value.substr(value.length - 1).toUpperCase();
|
|
183
|
-
if (last !== 'F') {
|
|
184
|
-
throw new Type_Error('uri type indicator must be (f|F)');
|
|
185
|
-
}
|
|
186
|
-
return value.substring(0, value.length - 1);
|
|
187
|
-
} else if (dbDataType === 'FLOAT') {
|
|
188
|
-
/* in "-3.4028234e+38d" */
|
|
189
|
-
/* out -3.4028234e+38 */
|
|
190
|
-
/* in "3.402823466e+38d" */
|
|
191
|
-
/* out 3.402823466e+38 */
|
|
159
|
+
let last;
|
|
160
|
+
if (dbDataType === 'REAL' || dbDataType === 'FLOAT') {
|
|
192
161
|
last = value.substr(value.length - 1).toUpperCase();
|
|
193
162
|
if (last !== 'F') {
|
|
194
|
-
throw new
|
|
163
|
+
throw new XsODataTypeError('uri type indicator must be (f|F)');
|
|
195
164
|
}
|
|
196
165
|
return value.substring(0, value.length - 1);
|
|
197
166
|
} else {
|
|
198
|
-
throw new
|
|
167
|
+
throw new XsODataTypeError("db type must be REAL or DECIMAL");
|
|
199
168
|
}
|
|
200
169
|
};
|
|
201
170
|
|
|
@@ -205,18 +174,18 @@ uriToDb['Edm.Double'] = function uriToDbEdmDouble(value, dbDataType) {
|
|
|
205
174
|
/* out -1.7976931348623157e+308 */
|
|
206
175
|
/* in "1.7976931348623158e+308d" */
|
|
207
176
|
/* out 1.7976931348623157e+308 */
|
|
208
|
-
|
|
177
|
+
const last = value.substr(value.length - 1).toUpperCase();
|
|
209
178
|
if (last !== 'F') {
|
|
210
|
-
throw new
|
|
179
|
+
throw new XsODataTypeError('uri type indicator must be (d|D)');
|
|
211
180
|
}
|
|
212
181
|
return value.substring(0, value.length - 1);
|
|
213
182
|
} else {
|
|
214
|
-
throw new
|
|
183
|
+
throw new XsODataTypeError("db type must be DOUBLE");
|
|
215
184
|
}
|
|
216
185
|
};
|
|
217
186
|
|
|
218
187
|
uriToDb['_Generic.Number'] = function uriToDbEdmString(number) {
|
|
219
|
-
|
|
188
|
+
let type = number.substr(number.length - 1).toUpperCase();
|
|
220
189
|
if (type === 'F' ||
|
|
221
190
|
type === 'f' ||
|
|
222
191
|
type === 'D' ||
|
|
@@ -230,14 +199,14 @@ uriToDb['_Generic.Number'] = function uriToDbEdmString(number) {
|
|
|
230
199
|
type = '';
|
|
231
200
|
}
|
|
232
201
|
|
|
233
|
-
|
|
202
|
+
let sign = number.substring(0, 1);
|
|
234
203
|
if ((sign === '+') || (sign === '-')) {
|
|
235
204
|
number = number.substring(1);
|
|
236
205
|
} else {
|
|
237
206
|
sign = '';
|
|
238
207
|
}
|
|
239
208
|
|
|
240
|
-
|
|
209
|
+
let exponent;
|
|
241
210
|
if (number.indexOf('E') !== -1) {
|
|
242
211
|
exponent = number.split('E');
|
|
243
212
|
} else if (number.indexOf('e') !== -1) {
|
|
@@ -246,13 +215,13 @@ uriToDb['_Generic.Number'] = function uriToDbEdmString(number) {
|
|
|
246
215
|
exponent = [number];
|
|
247
216
|
}
|
|
248
217
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
218
|
+
const intFloat = exponent[0].split('.');
|
|
219
|
+
const i = intFloat[0] || null;
|
|
220
|
+
const f = intFloat[1] || null;
|
|
221
|
+
const e = exponent[1] || null;
|
|
253
222
|
|
|
254
223
|
|
|
255
|
-
|
|
224
|
+
let ret = '';
|
|
256
225
|
ret += sign;
|
|
257
226
|
if (i) {
|
|
258
227
|
ret += i;
|
|
@@ -280,13 +249,13 @@ uriToDb['_Generic.Number'] = function uriToDbEdmString(number) {
|
|
|
280
249
|
} else if (type === 'L') {
|
|
281
250
|
return (ret);
|
|
282
251
|
} else {
|
|
283
|
-
throw new
|
|
252
|
+
throw new XsODataTypeError('edm type Edm.Guid is not supported');
|
|
284
253
|
}
|
|
285
254
|
};
|
|
286
255
|
|
|
287
256
|
|
|
288
257
|
function deDoubleQuote(valueString) {
|
|
289
|
-
|
|
258
|
+
const s1 = valueString.substr(1, valueString.length - 2).replace(/''/g, "'");
|
|
290
259
|
return s1;
|
|
291
260
|
}
|
|
292
261
|
|
|
@@ -315,40 +284,24 @@ uriToDb['Edm.String'] = function uriToDbEdmString(jsonValue, dbDataType) {
|
|
|
315
284
|
/* out buffer */
|
|
316
285
|
return Buffer.from(jsonValue, 'utf8');
|
|
317
286
|
} else {
|
|
318
|
-
throw new
|
|
287
|
+
throw new XsODataTypeError('db type must be VARCHAR, NVARCHAR, ALPHANUM, SHORTTEXT, CHAR, NCHAR, CLOB, NCLOB');
|
|
319
288
|
}
|
|
320
289
|
};
|
|
321
290
|
|
|
322
291
|
uriToDb['Edm.Binary'] = function uriToDbEdmBinary(value, dbDataType) {
|
|
323
|
-
|
|
324
|
-
if (dbDataType === 'BLOB') {
|
|
325
|
-
/* in "x'1234ABCD'" */
|
|
326
|
-
/* out buffer */
|
|
327
|
-
|
|
292
|
+
let tmp;
|
|
293
|
+
if (dbDataType === 'BLOB' || dbDataType === 'VARBINARY') {
|
|
328
294
|
if (value[0] === 'X') {
|
|
329
295
|
tmp = value.substring(2, value.length - 1);
|
|
330
296
|
} else {
|
|
331
297
|
tmp = value.substring(7, value.length - 1);
|
|
332
298
|
}
|
|
333
|
-
//return 'x\'' + tmp + '\'';
|
|
334
299
|
return Buffer.from(tmp, 'hex');
|
|
335
300
|
} else if (dbDataType === 'BINARY') {
|
|
336
|
-
throw new
|
|
337
|
-
} else if (dbDataType === 'VARBINARY') {
|
|
338
|
-
|
|
339
|
-
/* in "x'1234ABCD'" */
|
|
340
|
-
/* out buffer */
|
|
341
|
-
if (value[0] === 'X') {
|
|
342
|
-
tmp = value.substring(2, value.length - 1);
|
|
343
|
-
} else {
|
|
344
|
-
tmp = value.substring(7, value.length - 1);
|
|
345
|
-
}
|
|
346
|
-
//return 'x\'' + tmp + '\'';
|
|
347
|
-
return Buffer.from(tmp, 'hex');
|
|
301
|
+
throw new XsODataTypeError("db type BINARY is not supported");
|
|
348
302
|
}
|
|
349
|
-
|
|
350
303
|
};
|
|
351
304
|
|
|
352
305
|
uriToDb['Edm.Guid'] = function uriToDbEdmGuiD(/*jsonValue, dbDataType*/) {
|
|
353
|
-
throw new
|
|
306
|
+
throw new XsODataTypeError('edm type Edm.Guid is not supported');
|
|
354
307
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const xmlValueToODataJson = exports.xmlValueToODataJson = {};
|
|
5
|
+
const XsODataTypeError = require('./../errors/typeError');
|
|
6
|
+
const dateTimeParser = require('./../../parsers/dateTimeParser');
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
*
|
|
@@ -30,11 +30,7 @@ xmlValueToODataJson['Edm.Boolean'] = function xmlEdmBooleanToODataJson(jsonValue
|
|
|
30
30
|
* out: true / false
|
|
31
31
|
*/
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
return true;
|
|
35
|
-
} else {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
33
|
+
return jsonValue === 'true' || jsonValue === true || jsonValue === '1' || jsonValue === 1;
|
|
38
34
|
};
|
|
39
35
|
|
|
40
36
|
/**
|
|
@@ -66,13 +62,13 @@ xmlValueToODataJson['Edm.DateTime'] = function xmlEdmDateTimeToODataJson(jsonVal
|
|
|
66
62
|
* out: /Date(<millis since 1970-01-01T00:00:00.0000000>)/
|
|
67
63
|
*/
|
|
68
64
|
try {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
65
|
+
const result = dateTimeParser.parse(jsonValue);
|
|
66
|
+
const month = result.month-1;
|
|
67
|
+
const date = new Date(Date.UTC(result.year, month, result.day, result.hour, result.minute, result.second, result.millisecond));
|
|
72
68
|
return "/Date(" + date.getTime() + ")/";
|
|
73
69
|
}
|
|
74
70
|
catch (err) {
|
|
75
|
-
throw new
|
|
71
|
+
throw new XsODataTypeError('Provided Edm.DateTime property is not valid');
|
|
76
72
|
}
|
|
77
73
|
|
|
78
74
|
};
|
|
@@ -147,7 +143,7 @@ xmlValueToODataJson['Edm.String'] = noop;
|
|
|
147
143
|
* @param jsonValue
|
|
148
144
|
* @returns {*}
|
|
149
145
|
*/
|
|
150
|
-
xmlValueToODataJson['Edm.Byte'] = function
|
|
146
|
+
xmlValueToODataJson['Edm.Byte'] = function xmlEdmByteToDbJson(jsonValue){
|
|
151
147
|
return parseInt(jsonValue);
|
|
152
148
|
};
|
|
153
149
|
|