@adobe/acc-js-sdk 1.1.61 → 1.2.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/.cursor/commands/opsx-apply.md +152 -0
- package/.cursor/commands/opsx-archive.md +157 -0
- package/.cursor/commands/opsx-explore.md +173 -0
- package/.cursor/commands/opsx-propose.md +106 -0
- package/.cursor/skills/openspec-apply-change/SKILL.md +156 -0
- package/.cursor/skills/openspec-archive-change/SKILL.md +114 -0
- package/.cursor/skills/openspec-explore/SKILL.md +288 -0
- package/.cursor/skills/openspec-propose/SKILL.md +110 -0
- package/.eslintrc.js +2 -2
- package/.github/prompts/opsx-apply.prompt.md +149 -0
- package/.github/prompts/opsx-archive.prompt.md +154 -0
- package/.github/prompts/opsx-explore.prompt.md +170 -0
- package/.github/prompts/opsx-propose.prompt.md +103 -0
- package/.github/skills/openspec-apply-change/SKILL.md +156 -0
- package/.github/skills/openspec-archive-change/SKILL.md +114 -0
- package/.github/skills/openspec-explore/SKILL.md +288 -0
- package/.github/skills/openspec-propose/SKILL.md +110 -0
- package/.github/workflows/codeql-analysis.yml +5 -4
- package/.github/workflows/npm-publish.yml +3 -3
- package/AGENTS.md +117 -0
- package/CLAUDE.md +2 -0
- package/MIGRATION.md +10 -0
- package/README.md +6 -2
- package/ai-docs/coding-rules.md +95 -0
- package/ai-docs/tech-stack.md +43 -0
- package/babel.config.js +5 -0
- package/docs/changeLog.html +34 -0
- package/docs/checkList.html +2 -2
- package/docs/connectionParameters.html +5 -0
- package/docs/quickstart.html +2 -1
- package/docs/release.html +1 -1
- package/openspec/config.yaml +20 -0
- package/package-lock.json +7437 -3924
- package/package.json +9 -7
- package/src/AGENTS.md +98 -0
- package/src/CLAUDE.md +2 -0
- package/src/application.js +637 -637
- package/src/cache.js +133 -133
- package/src/cacheRefresher.js +190 -190
- package/src/campaign.js +532 -532
- package/src/client.js +1539 -1532
- package/src/crypto.js +52 -52
- package/src/domUtil.js +346 -346
- package/src/entityAccessor.js +61 -61
- package/src/index.js +83 -83
- package/src/methodCache.js +69 -69
- package/src/optionCache.js +26 -26
- package/src/soap.js +321 -322
- package/src/testUtil.js +13 -13
- package/src/transport.js +70 -70
- package/src/util.js +147 -147
- package/src/web/bundler.js +5 -5
- package/src/xtkCaster.js +258 -258
- package/src/xtkEntityCache.js +34 -34
- package/src/xtkJob.js +185 -185
- package/test/AGENTS.md +37 -0
- package/test/CLAUDE.md +2 -0
- package/test/cacheRefresher.test.js +7 -0
- package/test/client.test.js +123 -81
- package/test/jest.config.js +6 -0
- package/test/observability.test.js +6 -1
- package/test/xtkJob.test.js +2 -2
package/src/xtkCaster.js
CHANGED
|
@@ -10,22 +10,22 @@ OF ANY KIND, either express or implied. See the License for the specific languag
|
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
(function() {
|
|
13
|
-
"use strict";
|
|
13
|
+
"use strict";
|
|
14
14
|
|
|
15
|
-
const { Util } = require('./util.js');
|
|
15
|
+
const { Util } = require('./util.js');
|
|
16
16
|
|
|
17
|
-
/**********************************************************************************
|
|
17
|
+
/**********************************************************************************
|
|
18
18
|
*
|
|
19
19
|
* Helper class to cast values to and from their Xtk versions
|
|
20
20
|
*
|
|
21
21
|
*********************************************************************************/
|
|
22
|
-
|
|
22
|
+
const { CampaignException } = require('./campaign.js');
|
|
23
23
|
|
|
24
|
-
/**
|
|
24
|
+
/**
|
|
25
25
|
* @namespace Campaign
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
-
/**
|
|
28
|
+
/**
|
|
29
29
|
* Campaign XTK types
|
|
30
30
|
*
|
|
31
31
|
*
|
|
@@ -64,12 +64,12 @@ const { Util } = require('./util.js');
|
|
|
64
64
|
* @memberof Campaign
|
|
65
65
|
*/
|
|
66
66
|
|
|
67
|
-
/**
|
|
67
|
+
/**
|
|
68
68
|
* @memberof Campaign
|
|
69
69
|
* @class
|
|
70
70
|
* @constructor
|
|
71
71
|
*/
|
|
72
|
-
class XtkCaster {
|
|
72
|
+
class XtkCaster {
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
75
|
* Helpers to convert between JavaScript data types and Campaign XTK data types
|
|
@@ -86,51 +86,51 @@ class XtkCaster {
|
|
|
86
86
|
*/
|
|
87
87
|
// See "variant" element in xtk:common srcSchema
|
|
88
88
|
static _variantStorageAttribute(type) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
89
|
+
if (type === null || type === undefined) return null;
|
|
90
|
+
switch(type) {
|
|
91
|
+
case 0: // FIELD_NONE
|
|
92
|
+
case "":
|
|
93
|
+
return null;
|
|
94
|
+
case 6: // FIELD_SZ
|
|
95
|
+
case "string":
|
|
96
|
+
case "uuid":
|
|
97
|
+
case "int64":
|
|
98
|
+
case "primarykey":
|
|
99
|
+
return "stringValue";
|
|
100
|
+
case 12: // FIELD_MEMO
|
|
101
|
+
case 13: // FIELD_MEMOSHORT
|
|
102
|
+
case "blob":
|
|
103
|
+
case "html":
|
|
104
|
+
case "memo":
|
|
105
|
+
case "CDATA":
|
|
106
|
+
return "memoValue";
|
|
107
|
+
case 1: // FIELD_BYTE
|
|
108
|
+
case "byte":
|
|
109
|
+
case 2: // FIELD_SHORT
|
|
110
|
+
case "short":
|
|
111
|
+
case 3: // FIELD_LONG
|
|
112
|
+
case "int":
|
|
113
|
+
case "long":
|
|
114
|
+
case "timespan":
|
|
115
|
+
case 15: // FIELD_BOOLEAN
|
|
116
|
+
case "boolean":
|
|
117
|
+
return "longValue";
|
|
118
|
+
case 4: // FIELD_FLOAT
|
|
119
|
+
case 5: // FIELD_DOUBLE
|
|
120
|
+
case "float":
|
|
121
|
+
case "double":
|
|
122
|
+
return "doubleValue";
|
|
123
|
+
case 7: // FIELD_DATETIME
|
|
124
|
+
case "datetime":
|
|
125
|
+
case "datetimetz":
|
|
126
|
+
case "datetimenotz":
|
|
127
|
+
case 10: // FIELD_DATE
|
|
128
|
+
case "date":
|
|
129
|
+
return "timeStampValue";
|
|
130
|
+
default: {
|
|
131
|
+
throw CampaignException.BAD_PARAMETER("type", type, `Cannot get variant storage attribute name for type '${type}'`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
/**
|
|
@@ -141,72 +141,72 @@ class XtkCaster {
|
|
|
141
141
|
* @returns {*} the value casted to the requested type, following XTK rules
|
|
142
142
|
*/
|
|
143
143
|
static as(value, type) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
144
|
+
switch(type) {
|
|
145
|
+
case 0: // FIELD_NONE
|
|
146
|
+
case "": {
|
|
147
|
+
return value;
|
|
148
|
+
}
|
|
149
|
+
case 6: // FIELD_SZ
|
|
150
|
+
case 12: // FIELD_MEMO
|
|
151
|
+
case 13: // FIELD_MEMOSHORT
|
|
152
|
+
case "string":
|
|
153
|
+
case "memo":
|
|
154
|
+
case "uuid":
|
|
155
|
+
case "blob":
|
|
156
|
+
case "html":
|
|
157
|
+
case "CDATA": {
|
|
158
|
+
return this.asString(value);
|
|
159
|
+
}
|
|
160
|
+
case 1: // FIELD_BYTE
|
|
161
|
+
case "byte": {
|
|
162
|
+
return this.asByte(value);
|
|
163
|
+
}
|
|
164
|
+
case 2: // FIELD_SHORT
|
|
165
|
+
case "short": {
|
|
166
|
+
return this.asShort(value);
|
|
167
|
+
}
|
|
168
|
+
case 3: // FIELD_LONG
|
|
169
|
+
case "int":
|
|
170
|
+
case "long": {
|
|
171
|
+
return this.asLong(value);
|
|
172
|
+
}
|
|
173
|
+
case "int64": {
|
|
174
|
+
return this.asInt64(value);
|
|
175
|
+
}
|
|
176
|
+
case 4: // FIELD_FLOAT
|
|
177
|
+
case 5: // FIELD_DOUBLE
|
|
178
|
+
case "float":
|
|
179
|
+
case "double": {
|
|
180
|
+
return this.asNumber(value);
|
|
181
|
+
}
|
|
182
|
+
case 15: // FIELD_BOOLEAN
|
|
183
|
+
case "boolean": {
|
|
184
|
+
return this.asBoolean(value);
|
|
185
|
+
}
|
|
186
|
+
case 7: // FIELD_DATETIME
|
|
187
|
+
case "datetime":
|
|
188
|
+
case "datetimetz":
|
|
189
|
+
case "datetimenotz": {
|
|
190
|
+
return this.asTimestamp(value);
|
|
191
|
+
}
|
|
192
|
+
case 10: // FIELD_DATE
|
|
193
|
+
case "date": {
|
|
194
|
+
return this.asDate(value);
|
|
195
|
+
}
|
|
196
|
+
case "array": {
|
|
197
|
+
return this.asArray(value);
|
|
198
|
+
}
|
|
199
|
+
case 14: // FIELD_TIMESPAN
|
|
200
|
+
case "timespan": {
|
|
201
|
+
return this.asTimespan(value);
|
|
202
|
+
}
|
|
203
|
+
case "primarykey": {
|
|
204
|
+
return this.asPrimaryKey(value);
|
|
205
|
+
}
|
|
206
|
+
default: {
|
|
207
|
+
throw CampaignException.BAD_PARAMETER("type", type, `Cannot convert value type='${type}', value='${value}'`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
/**
|
|
@@ -216,29 +216,29 @@ class XtkCaster {
|
|
|
216
216
|
* @return {string} a string value, guaranteed to be valid
|
|
217
217
|
*/
|
|
218
218
|
static asString(value) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
219
|
+
if (value === null || value === undefined) return "";
|
|
220
|
+
if (value != value || value === Number.POSITIVE_INFINITY || value === Number.NEGATIVE_INFINITY) return "";
|
|
221
|
+
if (value instanceof Date) {
|
|
222
|
+
if (isNaN(value.getTime()))
|
|
223
|
+
return ""; // Invalid JavaScript date
|
|
224
|
+
return value.toISOString();
|
|
225
|
+
}
|
|
226
|
+
if ((typeof value) == "object") {
|
|
227
|
+
if (XtkCaster.isPrimaryKey(value)) {
|
|
228
|
+
let result = value.schemaId;
|
|
229
|
+
for (let i=0; i<value.values.length; i++) {
|
|
230
|
+
result = result + "|";
|
|
231
|
+
let item = value.values[i];
|
|
232
|
+
if (item === null || item === undefined) continue;
|
|
233
|
+
if (typeof item !== "string") item = XtkCaster.asString(item);
|
|
234
|
+
const escaped = item.replace(/\|/g, "\\|").replace(/"/g, "\\\""); // escape | and " chars
|
|
235
|
+
result = result + escaped;
|
|
236
|
+
}
|
|
237
|
+
return result;
|
|
225
238
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
for (let i=0; i<value.values.length; i++) {
|
|
230
|
-
result = result + "|";
|
|
231
|
-
let item = value.values[i];
|
|
232
|
-
if (item === null || item === undefined) continue;
|
|
233
|
-
if (typeof item !== "string") item = XtkCaster.asString(item);
|
|
234
|
-
const escaped = item.replace(/\|/g, "\\|").replace(/\"/g, "\\\""); // escape | and " chars
|
|
235
|
-
result = result + escaped;
|
|
236
|
-
}
|
|
237
|
-
return result;
|
|
238
|
-
}
|
|
239
|
-
return "";
|
|
240
|
-
}
|
|
241
|
-
return value.toString();
|
|
239
|
+
return "";
|
|
240
|
+
}
|
|
241
|
+
return value.toString();
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
/**
|
|
@@ -249,15 +249,15 @@ class XtkCaster {
|
|
|
249
249
|
* @return {boolean} a boolean value, guaranteed to be true or false
|
|
250
250
|
*/
|
|
251
251
|
static asBoolean(value, defaultValue) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
252
|
+
if (defaultValue === undefined) defaultValue = false;
|
|
253
|
+
if (value === null || value === undefined) return defaultValue;
|
|
254
|
+
if (value === true || value === false) return value;
|
|
255
|
+
var stringValue = value.toString().toLowerCase().trim();
|
|
256
|
+
if (stringValue === "false" || stringValue === "") return false;
|
|
257
|
+
if (stringValue === "true") return true;
|
|
258
|
+
var intValue = parseInt(value, 10);
|
|
259
|
+
if (isNaN(intValue)) return false;
|
|
260
|
+
return intValue !== 0;
|
|
261
261
|
}
|
|
262
262
|
|
|
263
263
|
/**
|
|
@@ -266,14 +266,14 @@ class XtkCaster {
|
|
|
266
266
|
* @param {*} value is the raw value to convert
|
|
267
267
|
* @return {number} a numercial value, guaranteed to be valid and in the [-128, 127] range
|
|
268
268
|
*/
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
269
|
+
static asByte(value) {
|
|
270
|
+
var number = this.asNumber(value);
|
|
271
|
+
if( number ) {
|
|
272
|
+
number = Math.round(number);
|
|
273
|
+
if( number < -128) number = -128;
|
|
274
|
+
if( number > 127) number = 127;
|
|
275
|
+
}
|
|
276
|
+
return number;
|
|
277
277
|
}
|
|
278
278
|
|
|
279
279
|
/**
|
|
@@ -283,13 +283,13 @@ class XtkCaster {
|
|
|
283
283
|
* @return {number} a numercial value, guaranteed to be valid and in the [-32768, 32767] range
|
|
284
284
|
*/
|
|
285
285
|
static asShort(value) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
286
|
+
var number = this.asNumber(value);
|
|
287
|
+
if( number ) {
|
|
288
|
+
number = Math.round(number);
|
|
289
|
+
if( number < -32768) number = -32768;
|
|
290
|
+
if( number > 32767) number = 32767;
|
|
291
|
+
}
|
|
292
|
+
return number;
|
|
293
293
|
}
|
|
294
294
|
|
|
295
295
|
/**
|
|
@@ -299,13 +299,13 @@ class XtkCaster {
|
|
|
299
299
|
* @return {number} a numercial value, guaranteed to be valid and in the [-2147483648, 2147483647] range
|
|
300
300
|
*/
|
|
301
301
|
static asLong(value) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
302
|
+
var number = this.asNumber(value);
|
|
303
|
+
if( number ) {
|
|
304
|
+
number = Math.round(number);
|
|
305
|
+
if( number < -2147483648) number = -2147483648;
|
|
306
|
+
if( number > 2147483647) number = 2147483647;
|
|
307
|
+
}
|
|
308
|
+
return number;
|
|
309
309
|
}
|
|
310
310
|
|
|
311
311
|
/**
|
|
@@ -316,14 +316,14 @@ class XtkCaster {
|
|
|
316
316
|
* @return {string} a string value representing the number
|
|
317
317
|
*/
|
|
318
318
|
static asInt64(value) {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
319
|
+
if (value === null || value === undefined || value === "") return "0";
|
|
320
|
+
if (isNaN(value) || value === Number.POSITIVE_INFINITY || value === Number.NEGATIVE_INFINITY) return "0";
|
|
321
|
+
if ((typeof value) == "object") return "0";
|
|
322
|
+
if ((typeof value) == "boolean") return value ? "1" : "0";
|
|
323
|
+
var number = String(value).trim();
|
|
324
|
+
if (number.indexOf(".") != -1) return "0";
|
|
325
|
+
if (number == "") return "0";
|
|
326
|
+
return number;
|
|
327
327
|
}
|
|
328
328
|
|
|
329
329
|
/**
|
|
@@ -333,7 +333,7 @@ class XtkCaster {
|
|
|
333
333
|
* @return {number} a numercial value, guaranteed to be valid
|
|
334
334
|
*/
|
|
335
335
|
static asFloat(value) {
|
|
336
|
-
|
|
336
|
+
return this.asNumber(value);
|
|
337
337
|
}
|
|
338
338
|
|
|
339
339
|
/**
|
|
@@ -343,7 +343,7 @@ class XtkCaster {
|
|
|
343
343
|
* @return {number} a numercial value, guaranteed to be valid
|
|
344
344
|
*/
|
|
345
345
|
static asDouble(value) {
|
|
346
|
-
|
|
346
|
+
return this.asNumber(value);
|
|
347
347
|
}
|
|
348
348
|
|
|
349
349
|
/**
|
|
@@ -353,11 +353,11 @@ class XtkCaster {
|
|
|
353
353
|
* @return {number} a numercial value, guaranteed to be valid
|
|
354
354
|
*/
|
|
355
355
|
static asNumber(value) {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
356
|
+
if (value === null || value === undefined || value === "") return 0;
|
|
357
|
+
if (isNaN(value) || value === Number.POSITIVE_INFINITY || value === Number.NEGATIVE_INFINITY) return 0;
|
|
358
|
+
if ((typeof value) == "object") return 0;
|
|
359
|
+
var number = +value;
|
|
360
|
+
return number;
|
|
361
361
|
}
|
|
362
362
|
|
|
363
363
|
/**
|
|
@@ -366,8 +366,8 @@ class XtkCaster {
|
|
|
366
366
|
* @param {*} value is the raw value to convert
|
|
367
367
|
* @return {Date} the timestamp, possibly null
|
|
368
368
|
*/
|
|
369
|
-
|
|
370
|
-
|
|
369
|
+
static asDatetime(value) {
|
|
370
|
+
return this.asTimestamp(value);
|
|
371
371
|
}
|
|
372
372
|
|
|
373
373
|
/**
|
|
@@ -377,32 +377,32 @@ class XtkCaster {
|
|
|
377
377
|
* @return {Date} the timestamp, possibly null
|
|
378
378
|
*/
|
|
379
379
|
static asTimestamp(value) {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
380
|
+
if (value === null || value === undefined) return null;
|
|
381
|
+
if ((typeof value) == "string") value = value.trim();
|
|
382
|
+
if (value === "" || value === true || value === false) return null;
|
|
383
|
+
if (value !== value || value === Number.POSITIVE_INFINITY || value === Number.NEGATIVE_INFINITY) return null;
|
|
384
|
+
|
|
385
|
+
var timestamp = null;
|
|
386
|
+
if (value instanceof Date)
|
|
387
|
+
timestamp = value;
|
|
388
388
|
// Number to timestamp -> Consider as number of seconds since epoch
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
389
|
+
else if ((typeof value) == "number") {
|
|
390
|
+
timestamp = new Date(0);
|
|
391
|
+
timestamp.setUTCSeconds(value);
|
|
392
|
+
}
|
|
393
|
+
else {
|
|
394
|
+
var number = +value;
|
|
395
|
+
if (number === number){
|
|
396
|
+
timestamp = new Date(0);
|
|
397
|
+
timestamp.setUTCSeconds(value);
|
|
392
398
|
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
timestamp = new Date(0);
|
|
397
|
-
timestamp.setUTCSeconds(value);
|
|
398
|
-
}
|
|
399
|
-
// Parse ISO string. Example: "2018-11-18 01:00:04.690Z"
|
|
400
|
-
else if ((typeof value) == "string") {
|
|
401
|
-
timestamp = new Date(value);
|
|
402
|
-
}
|
|
399
|
+
// Parse ISO string. Example: "2018-11-18 01:00:04.690Z"
|
|
400
|
+
else if ((typeof value) == "string") {
|
|
401
|
+
timestamp = new Date(value);
|
|
403
402
|
}
|
|
404
|
-
|
|
405
|
-
|
|
403
|
+
}
|
|
404
|
+
if (!timestamp || isNaN(timestamp.getTime())) return null;
|
|
405
|
+
return timestamp;
|
|
406
406
|
}
|
|
407
407
|
|
|
408
408
|
/**
|
|
@@ -412,14 +412,14 @@ class XtkCaster {
|
|
|
412
412
|
* @return {Date} a date
|
|
413
413
|
*/
|
|
414
414
|
static asDate(value) {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
415
|
+
var timestamp = this.asTimestamp(value);
|
|
416
|
+
if (timestamp) {
|
|
417
|
+
timestamp.setUTCHours(0);
|
|
418
|
+
timestamp.setUTCMinutes(0);
|
|
419
|
+
timestamp.setUTCSeconds(0);
|
|
420
|
+
timestamp.setUTCMilliseconds(0);
|
|
421
|
+
}
|
|
422
|
+
return timestamp;
|
|
423
423
|
}
|
|
424
424
|
|
|
425
425
|
/**
|
|
@@ -429,10 +429,10 @@ class XtkCaster {
|
|
|
429
429
|
* @param {*} value is the raw value to convert
|
|
430
430
|
* @return {Array} a array
|
|
431
431
|
*/
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
432
|
+
static asArray(value) {
|
|
433
|
+
if (value === null || value === undefined) return [];
|
|
434
|
+
if (Util.isArray(value)) return value;
|
|
435
|
+
return [value];
|
|
436
436
|
}
|
|
437
437
|
|
|
438
438
|
/**
|
|
@@ -441,13 +441,13 @@ class XtkCaster {
|
|
|
441
441
|
* @returns is the time span, in seconds
|
|
442
442
|
*/
|
|
443
443
|
static asTimespan(value) {
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
444
|
+
if (value === null || value === undefined) return 0;
|
|
445
|
+
if ((typeof value) == "string") value = value.trim();
|
|
446
|
+
if (value === "" || value === true || value === false) return 0;
|
|
447
|
+
if (value !== value || value === Number.POSITIVE_INFINITY || value === Number.NEGATIVE_INFINITY) return 0;
|
|
448
|
+
// Number to timespan -> Consider as number of seconds
|
|
449
|
+
var timespan = XtkCaster.asLong(value);
|
|
450
|
+
return timespan;
|
|
451
451
|
}
|
|
452
452
|
|
|
453
453
|
/**
|
|
@@ -456,27 +456,27 @@ class XtkCaster {
|
|
|
456
456
|
* @param {*} value is the raw value to convert
|
|
457
457
|
* @return {PrimaryKey} a primary key
|
|
458
458
|
*/
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
}
|
|
459
|
+
static asPrimaryKey(value) {
|
|
460
|
+
if (value === null || value === undefined) return undefined;
|
|
461
|
+
if (this.isPrimaryKey(value)) return value;
|
|
462
|
+
value = value.toString();
|
|
463
|
+
let index = value.indexOf('|');
|
|
464
|
+
if (index <= 0) return undefined; // no schema id or empty schema id
|
|
465
|
+
const primaryKey = {
|
|
466
|
+
schemaId: value.substring(0, index),
|
|
467
|
+
values: []
|
|
468
|
+
};
|
|
469
|
+
value = value.substring(index+1) + "|";
|
|
470
|
+
let start = 0;
|
|
471
|
+
for(var i=0; i<value.length; i++) {
|
|
472
|
+
const c = value[i];
|
|
473
|
+
if (c === '\\') { i = i + 1; continue; } // escaped char
|
|
474
|
+
if (c === '|') {
|
|
475
|
+
primaryKey.values.push(value.substring(start, i).replace(/\\/g, ""));
|
|
476
|
+
start = i + 1;
|
|
478
477
|
}
|
|
479
|
-
|
|
478
|
+
}
|
|
479
|
+
return primaryKey;
|
|
480
480
|
}
|
|
481
481
|
|
|
482
482
|
/**
|
|
@@ -485,7 +485,7 @@ class XtkCaster {
|
|
|
485
485
|
* @returns {boolean} true if the type is a date and/or time type
|
|
486
486
|
*/
|
|
487
487
|
static isTimeType(type) {
|
|
488
|
-
|
|
488
|
+
return type === "datetime" || type === "datetimetz" || type === "datetimenotz" || type === "timestamp" || type === "date" || type === "time" || type === "timespan" || type === 7 || type === 10 || type === 14;
|
|
489
489
|
}
|
|
490
490
|
|
|
491
491
|
/**
|
|
@@ -494,7 +494,7 @@ class XtkCaster {
|
|
|
494
494
|
* @returns {boolean} true if the type is a string type
|
|
495
495
|
*/
|
|
496
496
|
static isStringType(type) {
|
|
497
|
-
|
|
497
|
+
return type === "string" || type === "memo" || type === 6 || type === 12 || type === 13 || type === "blob" || type === "html" || type === "CDATA";
|
|
498
498
|
}
|
|
499
499
|
|
|
500
500
|
/**
|
|
@@ -503,7 +503,7 @@ class XtkCaster {
|
|
|
503
503
|
* @returns {boolean} true if the type is a numeric type
|
|
504
504
|
*/
|
|
505
505
|
static isNumericType(type) {
|
|
506
|
-
|
|
506
|
+
return type === "byte" || type === 1 || type === "short" || type === 2 || type === "int" || type === "long" || type === 3 || type === "float" || type === 4 || type === "double" || type === 5 || type === "timespan" || type === 14;
|
|
507
507
|
}
|
|
508
508
|
|
|
509
509
|
/**
|
|
@@ -512,12 +512,12 @@ class XtkCaster {
|
|
|
512
512
|
* @returns true or false depending on whether the object is a primary key or not
|
|
513
513
|
*/
|
|
514
514
|
static isPrimaryKey(value) {
|
|
515
|
-
|
|
516
|
-
|
|
515
|
+
if (!value) return false;
|
|
516
|
+
return !!(value.schemaId && value.values && Util.isArray(value.values));
|
|
517
517
|
}
|
|
518
|
-
}
|
|
518
|
+
}
|
|
519
519
|
|
|
520
520
|
|
|
521
|
-
exports.XtkCaster = XtkCaster;
|
|
521
|
+
exports.XtkCaster = XtkCaster;
|
|
522
522
|
|
|
523
523
|
})();
|