@oino-ts/common 0.21.1 → 1.0.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.
Files changed (72) hide show
  1. package/README.md +183 -0
  2. package/dist/cjs/OINOApi.js +322 -0
  3. package/dist/cjs/OINOBenchmark.js +3 -4
  4. package/dist/cjs/OINOConfig.js +104 -0
  5. package/dist/cjs/OINOConstants.js +42 -0
  6. package/dist/cjs/OINODataField.js +346 -0
  7. package/dist/cjs/OINODataModel.js +182 -0
  8. package/dist/cjs/OINODataSource.js +165 -0
  9. package/dist/cjs/OINOFormatter.js +6 -5
  10. package/dist/cjs/OINOHtmlTemplate.js +21 -18
  11. package/dist/cjs/OINOModelSet.js +333 -0
  12. package/dist/cjs/OINOParser.js +448 -0
  13. package/dist/cjs/OINOQueryParams.js +434 -0
  14. package/dist/cjs/OINORequest.js +21 -13
  15. package/dist/cjs/OINOResult.js +13 -12
  16. package/dist/cjs/OINOStr.js +11 -11
  17. package/dist/cjs/OINOSwagger.js +205 -0
  18. package/dist/cjs/index.js +57 -39
  19. package/dist/esm/OINOApi.js +315 -0
  20. package/dist/esm/OINOBenchmark.js +3 -4
  21. package/dist/esm/OINOConfig.js +100 -0
  22. package/dist/esm/OINOConstants.js +39 -0
  23. package/dist/esm/OINODataField.js +337 -0
  24. package/dist/esm/OINODataModel.js +178 -0
  25. package/dist/esm/OINODataSource.js +159 -0
  26. package/dist/esm/OINOFormatter.js +2 -1
  27. package/dist/esm/OINOHtmlTemplate.js +4 -1
  28. package/dist/esm/OINOModelSet.js +329 -0
  29. package/dist/esm/OINOParser.js +444 -0
  30. package/dist/esm/OINOQueryParams.js +426 -0
  31. package/dist/esm/OINORequest.js +9 -1
  32. package/dist/esm/OINOResult.js +2 -1
  33. package/dist/esm/OINOStr.js +1 -1
  34. package/dist/esm/OINOSwagger.js +201 -0
  35. package/dist/esm/index.js +14 -32
  36. package/dist/types/OINOApi.d.ts +191 -0
  37. package/dist/types/OINOBenchmark.d.ts +1 -1
  38. package/dist/types/OINOConfig.d.ts +63 -0
  39. package/dist/types/OINOConstants.d.ts +51 -0
  40. package/dist/types/OINODataField.d.ts +209 -0
  41. package/dist/types/OINODataModel.d.ts +78 -0
  42. package/dist/types/OINODataSource.d.ts +184 -0
  43. package/dist/types/OINOHtmlTemplate.d.ts +1 -1
  44. package/dist/types/OINOModelSet.d.ts +64 -0
  45. package/dist/types/OINOParser.d.ts +42 -0
  46. package/dist/types/OINOQueryParams.d.ts +270 -0
  47. package/dist/types/OINORequest.d.ts +4 -1
  48. package/dist/types/OINOResult.d.ts +1 -1
  49. package/dist/types/OINOStr.d.ts +1 -1
  50. package/dist/types/OINOSwagger.d.ts +25 -0
  51. package/dist/types/index.d.ts +14 -31
  52. package/package.json +32 -32
  53. package/src/OINOApi.ts +429 -0
  54. package/src/OINOBenchmark.ts +323 -324
  55. package/src/OINOConfig.ts +113 -0
  56. package/src/OINOConstants.ts +59 -0
  57. package/src/OINODataField.ts +371 -0
  58. package/src/OINODataModel.ts +187 -0
  59. package/src/OINODataSource.ts +280 -0
  60. package/src/OINOFormatter.ts +166 -165
  61. package/src/OINOHeaders.ts +51 -51
  62. package/src/OINOHtmlTemplate.test.ts +114 -114
  63. package/src/OINOHtmlTemplate.ts +225 -222
  64. package/src/OINOLog.ts +292 -292
  65. package/src/OINOModelSet.ts +359 -0
  66. package/src/OINOParser.ts +441 -0
  67. package/src/OINOQueryParams.ts +449 -0
  68. package/src/OINORequest.ts +204 -196
  69. package/src/OINOResult.ts +331 -330
  70. package/src/OINOStr.ts +254 -254
  71. package/src/OINOSwagger.ts +213 -0
  72. package/src/index.ts +18 -38
@@ -0,0 +1,434 @@
1
+ "use strict";
2
+ /*
3
+ * This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.OINOQuerySelect = exports.OINOQueryAggregate = exports.OINOQueryLimit = exports.OINOQueryOrder = exports.OINOQueryFilter = exports.OINOQueryAggregateFunctions = exports.OINOQueryNullCheck = exports.OINOQueryComparison = exports.OINOQueryBooleanOperation = void 0;
9
+ const OINOConstants_js_1 = require("./OINOConstants.js");
10
+ const OINOStr_js_1 = require("./OINOStr.js");
11
+ const OINOLog_js_1 = require("./OINOLog.js");
12
+ const OINO_FIELD_NAME_CHARS = "\\w\\s\\-\\_\\#\\¤";
13
+ /**
14
+ * Supported logical conjunctions in filter predicates.
15
+ * @enum
16
+ */
17
+ var OINOQueryBooleanOperation;
18
+ (function (OINOQueryBooleanOperation) {
19
+ OINOQueryBooleanOperation["and"] = "and";
20
+ OINOQueryBooleanOperation["or"] = "or";
21
+ OINOQueryBooleanOperation["not"] = "not";
22
+ })(OINOQueryBooleanOperation || (exports.OINOQueryBooleanOperation = OINOQueryBooleanOperation = {}));
23
+ /**
24
+ * Supported logical conjunctions in filter predicates.
25
+ * @enum
26
+ */
27
+ var OINOQueryComparison;
28
+ (function (OINOQueryComparison) {
29
+ OINOQueryComparison["lt"] = "lt";
30
+ OINOQueryComparison["le"] = "le";
31
+ OINOQueryComparison["eq"] = "eq";
32
+ OINOQueryComparison["ne"] = "ne";
33
+ OINOQueryComparison["ge"] = "ge";
34
+ OINOQueryComparison["gt"] = "gt";
35
+ OINOQueryComparison["like"] = "like";
36
+ })(OINOQueryComparison || (exports.OINOQueryComparison = OINOQueryComparison = {}));
37
+ /**
38
+ * Supported logical conjunctions in filter predicates.
39
+ * @enum
40
+ */
41
+ var OINOQueryNullCheck;
42
+ (function (OINOQueryNullCheck) {
43
+ OINOQueryNullCheck["isnull"] = "isnull";
44
+ OINOQueryNullCheck["isNotNull"] = "isNotNull";
45
+ })(OINOQueryNullCheck || (exports.OINOQueryNullCheck = OINOQueryNullCheck = {}));
46
+ /**
47
+ * Supported aggregation functions in OINODbQueryAggregate.
48
+ * @enum
49
+ */
50
+ var OINOQueryAggregateFunctions;
51
+ (function (OINOQueryAggregateFunctions) {
52
+ OINOQueryAggregateFunctions["count"] = "count";
53
+ OINOQueryAggregateFunctions["sum"] = "sum";
54
+ OINOQueryAggregateFunctions["avg"] = "avg";
55
+ OINOQueryAggregateFunctions["min"] = "min";
56
+ OINOQueryAggregateFunctions["max"] = "max";
57
+ })(OINOQueryAggregateFunctions || (exports.OINOQueryAggregateFunctions = OINOQueryAggregateFunctions = {}));
58
+ /**
59
+ * Class for recursively parsing of filters and printing them as SQL conditions.
60
+ * Supports three types of statements
61
+ * - comparison: (field)-lt|le|eq|ge|gt|like(value)
62
+ * - negation: -not(filter)
63
+ * - conjunction/disjunction: (filter)-and|or(filter)
64
+ * Supported conditions are comparisons (<, <=, =, >=, >) and substring match (LIKE).
65
+ *
66
+ */
67
+ class OINOQueryFilter {
68
+ static _booleanOperationRegex = /^\s?\-(and|or)\s?$/i;
69
+ static _negationRegex = /^-(not)\((.+)\)$/i;
70
+ static _filterComparisonRegex = /^\(([^'"\(\)]+)\)\s?\-(lt|le|eq|ne|ge|gt|like)\s?\(([^'"\(\)]+)\)$/i;
71
+ static _filterNullCheckRegex = /^-(isnull|isNotNull)\((.+)\)$/i;
72
+ leftSide;
73
+ rightSide;
74
+ operator;
75
+ /**
76
+ * Constructor of `OINOQueryFilter`
77
+ * @param leftSide left side of the filter, either another filter or a column name
78
+ * @param operation operation of the filter, either `OINOQueryComparison` or `OINOQueryBooleanOperation`
79
+ * @param rightSide right side of the filter, either another filter or a value
80
+ */
81
+ constructor(leftSide, operation, rightSide) {
82
+ if (!(((operation === null) && (leftSide == "") && (rightSide == "")) ||
83
+ ((operation !== null) && (Object.values(OINOQueryComparison).includes(operation)) && (typeof (leftSide) == "string") && (leftSide != "") && (typeof (rightSide) == "string") && (rightSide != "")) ||
84
+ ((operation == OINOQueryBooleanOperation.not) && (leftSide == "") && (rightSide instanceof OINOQueryFilter)) ||
85
+ (((operation == OINOQueryNullCheck.isnull) || (operation == OINOQueryNullCheck.isNotNull)) && (typeof (leftSide) == "string") && (rightSide == "")) ||
86
+ (((operation == OINOQueryBooleanOperation.and) || (operation == OINOQueryBooleanOperation.or)) && (leftSide instanceof OINOQueryFilter) && (rightSide instanceof OINOQueryFilter)))) {
87
+ OINOLog_js_1.OINOLog.error("@oino-ts/db", "OINOQueryFilter", "constructor", "Unsupported OINOQueryFilter format", { leftSide: leftSide, operation: operation, rightSide: rightSide });
88
+ throw new Error(OINOConstants_js_1.OINO_ERROR_PREFIX + ": Unsupported OINOQueryFilter format!");
89
+ }
90
+ this.leftSide = leftSide;
91
+ this.operator = operation;
92
+ this.rightSide = rightSide;
93
+ }
94
+ /**
95
+ * Constructor for `OINOQueryFilter` as parser of http parameter.
96
+ *
97
+ * Supports three types of statements:
98
+ * - comparison: (field)-lt|le|eq|ge|gt|like(value)
99
+ * - negation: -not(filter)
100
+ * - conjunction/disjunction: (filter)-and|or(filter)
101
+ * - null check: -isnull(field) or -isNotNull(field)
102
+ *
103
+ * @param filterString string representation of filter from HTTP-request
104
+ *
105
+ */
106
+ static parse(filterString) {
107
+ if (!filterString) {
108
+ return new OINOQueryFilter("", null, "");
109
+ }
110
+ else {
111
+ let match = OINOQueryFilter._filterComparisonRegex.exec(filterString);
112
+ if ((match != null) && (match.length == 4)) {
113
+ return new OINOQueryFilter(match[1], match[2].toLowerCase(), match[3]);
114
+ }
115
+ else {
116
+ let match = OINOQueryFilter._negationRegex.exec(filterString);
117
+ if (match != null) {
118
+ return new OINOQueryFilter("", OINOQueryBooleanOperation.not, OINOQueryFilter.parse(match[3]));
119
+ }
120
+ else {
121
+ let boolean_parts = OINOStr_js_1.OINOStr.splitByBrackets(filterString, true, false, '(', ')');
122
+ if (boolean_parts.length == 3 && (boolean_parts[1].match(OINOQueryFilter._booleanOperationRegex))) {
123
+ return new OINOQueryFilter(OINOQueryFilter.parse(boolean_parts[0]), boolean_parts[1].trim().toLowerCase().substring(1), OINOQueryFilter.parse(boolean_parts[2]));
124
+ }
125
+ else {
126
+ let match = OINOQueryFilter._filterNullCheckRegex.exec(filterString);
127
+ if ((match != null)) {
128
+ return new OINOQueryFilter(match[2], match[1].toLowerCase(), "");
129
+ }
130
+ else {
131
+ OINOLog_js_1.OINOLog.error("@oino-ts/db", "OINOQueryFilter", "constructor", "Invalid filter", { filterString: filterString });
132
+ throw new Error(OINOConstants_js_1.OINO_ERROR_PREFIX + ": Invalid filter '" + filterString + "'"); // invalid filter could be a security risk, stop processing
133
+ }
134
+ }
135
+ }
136
+ }
137
+ }
138
+ }
139
+ /**
140
+ * Construct a new `OINOQueryFilter` as combination of (boolean and/or) of two filters.
141
+ *
142
+ * @param leftSide left side to combine
143
+ * @param operation boolean operation to use in combination
144
+ * @param rightSide right side to combine
145
+ *
146
+ */
147
+ static combine(leftSide, operation, rightSide) {
148
+ if ((leftSide) && (!leftSide.isEmpty()) && (rightSide) && (!rightSide.isEmpty())) {
149
+ return new OINOQueryFilter(leftSide, operation, rightSide);
150
+ }
151
+ else if ((leftSide) && (!leftSide.isEmpty())) {
152
+ return leftSide;
153
+ }
154
+ else if ((rightSide) && (!rightSide.isEmpty())) {
155
+ return rightSide;
156
+ }
157
+ else {
158
+ return undefined;
159
+ }
160
+ }
161
+ /**
162
+ * Combine two filters with an AND operation.
163
+ *
164
+ * @param leftSide left side filter
165
+ * @param rightSide right side filter
166
+ *
167
+ */
168
+ static and(leftSide, rightSide) {
169
+ if ((leftSide) && (!leftSide.isEmpty()) && (rightSide) && (!rightSide.isEmpty())) {
170
+ return new OINOQueryFilter(leftSide, OINOQueryBooleanOperation.and, rightSide);
171
+ }
172
+ else {
173
+ return undefined;
174
+ }
175
+ }
176
+ /**
177
+ * Combine two filters with an OR operation.
178
+ *
179
+ * @param leftSide left side filter
180
+ * @param rightSide right side filter
181
+ *
182
+ */
183
+ static or(leftSide, rightSide) {
184
+ if ((leftSide) && (!leftSide.isEmpty()) && (rightSide) && (!rightSide.isEmpty())) {
185
+ return new OINOQueryFilter(leftSide, OINOQueryBooleanOperation.or, rightSide);
186
+ }
187
+ else {
188
+ return undefined;
189
+ }
190
+ }
191
+ /**
192
+ * Negate a filter with a NOT operation.
193
+ *
194
+ * @param leftSide left side filter
195
+ *
196
+ */
197
+ static not(leftSide) {
198
+ if ((leftSide) && (!leftSide.isEmpty())) {
199
+ return new OINOQueryFilter(leftSide, OINOQueryBooleanOperation.not, "");
200
+ }
201
+ else {
202
+ return undefined;
203
+ }
204
+ }
205
+ /**
206
+ * Does filter contain any valid conditions.
207
+ *
208
+ */
209
+ isEmpty() {
210
+ return (this.leftSide == "") && (this.operator == null) && (this.rightSide == "");
211
+ }
212
+ }
213
+ exports.OINOQueryFilter = OINOQueryFilter;
214
+ /**
215
+ * Class for ordering select results on a number of columns.
216
+ *
217
+ */
218
+ class OINOQueryOrder {
219
+ static _orderColumnRegex = /^\s*(\w+)\s?(ASC|DESC|\+|\-)?\s*?$/i;
220
+ columns;
221
+ descending;
222
+ /**
223
+ * Constructor for `OINOQueryOrder`.
224
+ *
225
+ * @param column_or_array single or array of columns to order on
226
+ * @param descending_or_array single or array of booleans if ordes is descending
227
+ *
228
+ */
229
+ constructor(column_or_array, descending_or_array) {
230
+ if (Array.isArray(column_or_array)) {
231
+ this.columns = column_or_array;
232
+ }
233
+ else {
234
+ this.columns = [column_or_array];
235
+ }
236
+ if (Array.isArray(descending_or_array)) {
237
+ this.descending = descending_or_array;
238
+ }
239
+ else {
240
+ this.descending = [descending_or_array];
241
+ }
242
+ }
243
+ /**
244
+ * Constructor for `OINOQueryOrder` as parser of http parameter.
245
+ *
246
+ * Supports comma separated list of column orders formatted as :
247
+ * - `column` - order by column in ascending order
248
+ * - `column ASC|DESC` - order by single either ascending or descending order
249
+ * - `column+|-` - order by single either ascending or descending order
250
+ *
251
+ * @param orderString string representation of order from HTTP-request
252
+ *
253
+ */
254
+ static parse(orderString) {
255
+ let columns = [];
256
+ let directions = [];
257
+ const column_strings = orderString.split(',');
258
+ for (let i = 0; i < column_strings.length; i++) {
259
+ let match = OINOQueryOrder._orderColumnRegex.exec(column_strings[i]);
260
+ if (match != null) {
261
+ columns.push(match[1]);
262
+ const dir = (match[2] || "ASC").toUpperCase();
263
+ directions.push((dir == "DESC") || (dir == "-"));
264
+ }
265
+ }
266
+ return new OINOQueryOrder(columns, directions);
267
+ }
268
+ /**
269
+ * Does filter contain any valid conditions.
270
+ *
271
+ */
272
+ isEmpty() {
273
+ return (this.columns.length == 0);
274
+ }
275
+ }
276
+ exports.OINOQueryOrder = OINOQueryOrder;
277
+ /**
278
+ * Class for limiting the number of results.
279
+ *
280
+ */
281
+ class OINOQueryLimit {
282
+ static _limitRegex = /^(\d+)(\spage\s|\.)?(\d+)?$/i;
283
+ limit;
284
+ page;
285
+ /**
286
+ * Constructor for `OINOQueryLimit`.
287
+ *
288
+ * @param limit maximum number of items to return
289
+ * @param page page number to return starting from 1
290
+ *
291
+ */
292
+ constructor(limit, page = -1) {
293
+ this.limit = limit;
294
+ this.page = page;
295
+ }
296
+ /**
297
+ * Constructor for `OINOQueryLimit` as parser of http parameter.
298
+ *
299
+ * Supports limit and page formatted as:
300
+ * - `limit` - limit number of items to return
301
+ * - `limit page n` - limit number of items to return and return page n (starting from 1)
302
+ * - `limit.n` - limit number of items to return and return page n (starting from 1)
303
+ *
304
+ * @param limitString string representation of limit from HTTP-request
305
+ *
306
+ */
307
+ static parse(limitString) {
308
+ let match = OINOQueryLimit._limitRegex.exec(limitString);
309
+ if ((match != null) && (match.length == 4)) {
310
+ return new OINOQueryLimit(Number.parseInt(match[1]), Number.parseInt(match[3]));
311
+ }
312
+ else if (match != null) {
313
+ return new OINOQueryLimit(Number.parseInt(match[1]));
314
+ }
315
+ else {
316
+ return new OINOQueryLimit(-1);
317
+ }
318
+ }
319
+ /**
320
+ * Does filter contain any valid conditions.
321
+ *
322
+ */
323
+ isEmpty() {
324
+ return (this.limit <= 0);
325
+ }
326
+ }
327
+ exports.OINOQueryLimit = OINOQueryLimit;
328
+ /**
329
+ * Class for limiting the number of results.
330
+ *
331
+ */
332
+ class OINOQueryAggregate {
333
+ static _aggregateRegex = new RegExp("^(count|sum|avg|min|max)\\(([" + OINO_FIELD_NAME_CHARS + "]+)\\)$", "mi");
334
+ functions;
335
+ fields;
336
+ /**
337
+ * Constructor for `OINOQueryAggregate`.
338
+ *
339
+ * @param functions aggregate function to use
340
+ * @param fields fields to aggregate
341
+ *
342
+ */
343
+ constructor(functions, fields) {
344
+ this.functions = functions;
345
+ this.fields = fields;
346
+ }
347
+ /**
348
+ * Constructor for `OINOQueryAggregate` as parser of http parameter.
349
+ *
350
+ * Supports comma separated list of aggregates formatted as:
351
+ * - `function(field)`
352
+ *
353
+ * Supported functions are count, sum, avg, min, max.
354
+ *
355
+ * @param aggregatorString string representation of limit from HTTP-request
356
+ *
357
+ */
358
+ static parse(aggregatorString) {
359
+ let funtions = [];
360
+ let fields = [];
361
+ const aggregator_parts = aggregatorString.split(',');
362
+ for (let i = 0; i < aggregator_parts.length; i++) {
363
+ let match = OINOQueryAggregate._aggregateRegex.exec(aggregator_parts[i]);
364
+ if ((match != null) && (match.length == 3)) {
365
+ funtions.push(match[1]);
366
+ fields.push(match[2]);
367
+ }
368
+ }
369
+ return new OINOQueryAggregate(funtions, fields);
370
+ }
371
+ /**
372
+ * Does filter contain any valid conditions.
373
+ *
374
+ */
375
+ isEmpty() {
376
+ return (this.functions.length <= 0);
377
+ }
378
+ /**
379
+ * Does filter contain any valid conditions.
380
+ *
381
+ * @param field field to check if it is aggregated
382
+ */
383
+ isAggregated(field) {
384
+ return (this.fields.includes(field));
385
+ }
386
+ }
387
+ exports.OINOQueryAggregate = OINOQueryAggregate;
388
+ /**
389
+ * Class for ordering select results on a number of columns.
390
+ *
391
+ */
392
+ class OINOQuerySelect {
393
+ columns;
394
+ /**
395
+ * Constructor for `OINOQuerySelect`.
396
+ *
397
+ * @param columns array of columns to select
398
+ *
399
+ */
400
+ constructor(columns) {
401
+ this.columns = columns;
402
+ }
403
+ /**
404
+ * Constructor for `OINOQuerySelect` as parser of http parameter.
405
+ *
406
+ * @param columns comma separated string selected columns from HTTP-request
407
+ *
408
+ */
409
+ static parse(columns) {
410
+ if (columns == "") {
411
+ return new OINOQuerySelect([]);
412
+ }
413
+ else {
414
+ return new OINOQuerySelect(columns.split(','));
415
+ }
416
+ }
417
+ /**
418
+ * Does select contain any valid columns.
419
+ *
420
+ */
421
+ isEmpty() {
422
+ return (this.columns.length == 0);
423
+ }
424
+ /**
425
+ * Does select include given column.
426
+ *
427
+ * @param field field to check if it is selected
428
+ *
429
+ */
430
+ isSelected(field) {
431
+ return ((this.columns.length == 0) || (this.columns.includes(field)));
432
+ }
433
+ }
434
+ exports.OINOQuerySelect = OINOQuerySelect;
@@ -7,7 +7,8 @@
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.OINOHttpRequest = exports.OINORequest = void 0;
9
9
  const node_buffer_1 = require("node:buffer");
10
- const _1 = require(".");
10
+ const OINOConstants_js_1 = require("./OINOConstants.js");
11
+ const OINOHeaders_js_1 = require("./OINOHeaders.js");
11
12
  /**
12
13
  * OINO API request result object with returned data and/or http status code/message and
13
14
  * error / warning messages.
@@ -37,6 +38,7 @@ class OINOHttpRequest extends OINORequest {
37
38
  body;
38
39
  requestType;
39
40
  responseType;
41
+ responseDownload;
40
42
  multipartBoundary;
41
43
  lastModified;
42
44
  etags;
@@ -50,7 +52,7 @@ class OINOHttpRequest extends OINORequest {
50
52
  super(init);
51
53
  this.url = typeof init.url === "string" ? new URL(init.url) : init.url;
52
54
  this.method = init.method?.toUpperCase() ?? "GET";
53
- this.headers = new _1.OINOHeaders(init.headers);
55
+ this.headers = new OINOHeaders_js_1.OINOHeaders(init.headers);
54
56
  this.body = init.body ?? null;
55
57
  this.multipartBoundary = "";
56
58
  this.lastModified = init.lastModified;
@@ -61,37 +63,43 @@ class OINOHttpRequest extends OINORequest {
61
63
  this.requestType = init.requestType;
62
64
  }
63
65
  else {
64
- const request_type_param = this.url?.searchParams.get(_1.OINO_REQUEST_TYPE_PARAM) || this.headers.get("content-type"); // content-type header can be overridden by query parameter
65
- if (request_type_param == _1.OINOContentType.csv) {
66
- this.requestType = _1.OINOContentType.csv;
66
+ const request_type_param = this.url?.searchParams.get(OINOConstants_js_1.OINO_REQUEST_TYPE_PARAM) || this.headers.get("content-type"); // content-type header can be overridden by query parameter
67
+ if (request_type_param == OINOConstants_js_1.OINOContentType.csv) {
68
+ this.requestType = OINOConstants_js_1.OINOContentType.csv;
67
69
  }
68
- else if (request_type_param == _1.OINOContentType.urlencode) {
69
- this.requestType = _1.OINOContentType.urlencode;
70
+ else if (request_type_param == OINOConstants_js_1.OINOContentType.urlencode) {
71
+ this.requestType = OINOConstants_js_1.OINOContentType.urlencode;
70
72
  }
71
- else if (request_type_param?.startsWith(_1.OINOContentType.formdata)) {
72
- this.requestType = _1.OINOContentType.formdata;
73
+ else if (request_type_param?.startsWith(OINOConstants_js_1.OINOContentType.formdata)) {
74
+ this.requestType = OINOConstants_js_1.OINOContentType.formdata;
73
75
  if (!this.multipartBoundary) {
74
76
  this.multipartBoundary = request_type_param.split('boundary=')[1] || "";
75
77
  }
76
78
  }
77
79
  else {
78
- this.requestType = _1.OINOContentType.json;
80
+ this.requestType = OINOConstants_js_1.OINOContentType.json;
79
81
  }
80
82
  }
81
83
  if (init.responseType) {
82
84
  this.responseType = init.responseType;
83
85
  }
84
86
  else {
85
- const response_type_param = this.url?.searchParams.get(_1.OINO_RESPONSE_TYPE_PARAM) || this.headers.get("accept"); // accept header can be overridden by query parameter
87
+ const response_type_param = this.url?.searchParams.get(OINOConstants_js_1.OINO_RESPONSE_TYPE_PARAM) || this.headers.get("accept"); // accept header can be overridden by query parameter
86
88
  const accept_types = response_type_param?.split(', ') || [];
87
89
  let response_type = undefined;
88
90
  for (let i = 0; i < accept_types.length; i++) {
89
- if (Object.values(_1.OINOContentType).includes(accept_types[i])) {
91
+ if (Object.values(OINOConstants_js_1.OINOContentType).includes(accept_types[i])) {
90
92
  response_type = accept_types[i];
91
93
  break;
92
94
  }
93
95
  }
94
- this.responseType = response_type ?? _1.OINOContentType.json;
96
+ this.responseType = response_type ?? OINOConstants_js_1.OINOContentType.json;
97
+ }
98
+ if (init.responseDownload) {
99
+ this.responseDownload = init.responseDownload;
100
+ }
101
+ else {
102
+ this.responseDownload = this.url?.searchParams.get(OINOConstants_js_1.OINO_RESPONSE_DOWNLOAD_PARAM) ?? "";
95
103
  }
96
104
  const last_modified = this.headers.get("if-modified-since");
97
105
  if (last_modified) {
@@ -8,7 +8,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.OINOHttpResult = exports.OINOResult = void 0;
9
9
  const node_crypto_1 = require("node:crypto");
10
10
  const node_buffer_1 = require("node:buffer");
11
- const _1 = require(".");
11
+ const OINOConstants_js_1 = require("./OINOConstants.js");
12
+ const OINOHeaders_js_1 = require("./OINOHeaders.js");
12
13
  /**
13
14
  * OINO API request result object with returned data and/or http status code/message and
14
15
  * error / warning messages.
@@ -69,11 +70,11 @@ class OINOResult {
69
70
  if (this.statusText != "OK") {
70
71
  this.messages.push(this.statusText); // latest error becomes status, but if there was something non-trivial, add it to the messages
71
72
  }
72
- if (statusText.startsWith(_1.OINO_ERROR_PREFIX)) {
73
+ if (statusText.startsWith(OINOConstants_js_1.OINO_ERROR_PREFIX)) {
73
74
  this.statusText = statusText;
74
75
  }
75
76
  else {
76
- this.statusText = _1.OINO_ERROR_PREFIX + " (" + operation + "): " + statusText;
77
+ this.statusText = OINOConstants_js_1.OINO_ERROR_PREFIX + " (" + operation + "): " + statusText;
77
78
  }
78
79
  return this;
79
80
  }
@@ -87,7 +88,7 @@ class OINOResult {
87
88
  addWarning(message, operation) {
88
89
  message = message.trim();
89
90
  if (message) {
90
- this.messages.push(_1.OINO_WARNING_PREFIX + " (" + operation + "): " + message);
91
+ this.messages.push(OINOConstants_js_1.OINO_WARNING_PREFIX + " (" + operation + "): " + message);
91
92
  }
92
93
  return this;
93
94
  }
@@ -101,7 +102,7 @@ class OINOResult {
101
102
  addInfo(message, operation) {
102
103
  message = message.trim();
103
104
  if (message) {
104
- this.messages.push(_1.OINO_INFO_PREFIX + " (" + operation + "): " + message);
105
+ this.messages.push(OINOConstants_js_1.OINO_INFO_PREFIX + " (" + operation + "): " + message);
105
106
  }
106
107
  return this;
107
108
  }
@@ -115,7 +116,7 @@ class OINOResult {
115
116
  addDebug(message, operation) {
116
117
  message = message.trim();
117
118
  if (message) {
118
- this.messages.push(_1.OINO_DEBUG_PREFIX + " (" + operation + "): " + message);
119
+ this.messages.push(OINOConstants_js_1.OINO_DEBUG_PREFIX + " (" + operation + "): " + message);
119
120
  }
120
121
  return this;
121
122
  }
@@ -133,19 +134,19 @@ class OINOResult {
133
134
  let j = 1;
134
135
  for (let i = 0; i < this.messages.length; i++) {
135
136
  const message = this.messages[i].replaceAll("\r", " ").replaceAll("\n", " ");
136
- if (copyErrors && message.startsWith(_1.OINO_ERROR_PREFIX)) {
137
+ if (copyErrors && message.startsWith(OINOConstants_js_1.OINO_ERROR_PREFIX)) {
137
138
  headers.set('X-OINO-MESSAGE-' + j, message);
138
139
  j++;
139
140
  }
140
- if (copyWarnings && message.startsWith(_1.OINO_WARNING_PREFIX)) {
141
+ if (copyWarnings && message.startsWith(OINOConstants_js_1.OINO_WARNING_PREFIX)) {
141
142
  headers.set('X-OINO-MESSAGE-' + j, message);
142
143
  j++;
143
144
  }
144
- if (copyInfos && message.startsWith(_1.OINO_INFO_PREFIX)) {
145
+ if (copyInfos && message.startsWith(OINOConstants_js_1.OINO_INFO_PREFIX)) {
145
146
  headers.set('X-OINO-MESSAGE-' + j, message);
146
147
  j++;
147
148
  }
148
- if (copyDebug && message.startsWith(_1.OINO_DEBUG_PREFIX)) {
149
+ if (copyDebug && message.startsWith(OINOConstants_js_1.OINO_DEBUG_PREFIX)) {
149
150
  headers.set('X-OINO-MESSAGE-' + j, message);
150
151
  j++;
151
152
  }
@@ -184,7 +185,7 @@ class OINOHttpResult extends OINOResult {
184
185
  constructor(init) {
185
186
  super(init);
186
187
  this.body = init?.body ?? "";
187
- this.headers = new _1.OINOHeaders(init?.headers);
188
+ this.headers = new OINOHeaders_js_1.OINOHeaders(init?.headers);
188
189
  this.expires = init?.expires ?? 0;
189
190
  this.lastModified = init?.lastModified ?? 0;
190
191
  this._etag = "";
@@ -206,7 +207,7 @@ class OINOHttpResult extends OINOResult {
206
207
  * @param headers HTTP headers (overrides existing values)
207
208
  */
208
209
  getFetchResponse(headers) {
209
- const merged_headers = new _1.OINOHeaders(this.headers);
210
+ const merged_headers = new OINOHeaders_js_1.OINOHeaders(this.headers);
210
211
  if (headers) {
211
212
  merged_headers.setHeaders(headers);
212
213
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OINOStr = void 0;
4
- const _1 = require(".");
4
+ const OINOConstants_js_1 = require("./OINOConstants.js");
5
5
  /**
6
6
  * Static class string utilities.
7
7
  *
@@ -215,19 +215,19 @@ class OINOStr {
215
215
  *
216
216
  */
217
217
  static decode(str, contentType) {
218
- if (contentType == _1.OINOContentType.csv) {
218
+ if (contentType == OINOConstants_js_1.OINOContentType.csv) {
219
219
  return this.decodeCSV(str);
220
220
  }
221
- else if (contentType == _1.OINOContentType.json) {
221
+ else if (contentType == OINOConstants_js_1.OINOContentType.json) {
222
222
  return this.decodeJSON(str);
223
223
  }
224
- else if (contentType == _1.OINOContentType.formdata) {
224
+ else if (contentType == OINOConstants_js_1.OINOContentType.formdata) {
225
225
  return this.decodeFormdata(str);
226
226
  }
227
- else if (contentType == _1.OINOContentType.urlencode) {
227
+ else if (contentType == OINOConstants_js_1.OINOContentType.urlencode) {
228
228
  return this.decodeUrlencode(str);
229
229
  }
230
- else if (contentType == _1.OINOContentType.html) {
230
+ else if (contentType == OINOConstants_js_1.OINOContentType.html) {
231
231
  return str;
232
232
  }
233
233
  else {
@@ -242,19 +242,19 @@ class OINOStr {
242
242
  *
243
243
  */
244
244
  static encode(str, contentType) {
245
- if (contentType == _1.OINOContentType.csv) {
245
+ if (contentType == OINOConstants_js_1.OINOContentType.csv) {
246
246
  return this.encodeCSV(str);
247
247
  }
248
- else if (contentType == _1.OINOContentType.json) {
248
+ else if (contentType == OINOConstants_js_1.OINOContentType.json) {
249
249
  return this.encodeJSON(str);
250
250
  }
251
- else if (contentType == _1.OINOContentType.formdata) {
251
+ else if (contentType == OINOConstants_js_1.OINOContentType.formdata) {
252
252
  return this.encodeFormdata(str);
253
253
  }
254
- else if (contentType == _1.OINOContentType.urlencode) {
254
+ else if (contentType == OINOConstants_js_1.OINOContentType.urlencode) {
255
255
  return this.encodeUrlencode(str);
256
256
  }
257
- else if (contentType == _1.OINOContentType.html) {
257
+ else if (contentType == OINOConstants_js_1.OINOContentType.html) {
258
258
  return this.encodeHtml(str);
259
259
  }
260
260
  else {