@oino-ts/db 0.16.2 → 0.17.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.
@@ -3,10 +3,65 @@
3
3
  * License, v. 2.0. If a copy of the MPL was not distributed with this
4
4
  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
5
  */
6
- import { OINODbDataModel, OINOStringDataField, OINO_ERROR_PREFIX, OINODbModelSet, OINOBenchmark, OINODbConfig, OINOHtmlTemplate, OINONumberDataField, OINODbParser, OINODatetimeDataField } from "./index.js";
7
- import { OINOLog, OINOResult } from "@oino-ts/common";
6
+ import { OINODbDataModel, OINOStringDataField, OINO_ERROR_PREFIX, OINODbModelSet, OINOBenchmark, OINODbConfig, OINOHtmlTemplate, OINONumberDataField, OINODbParser, OINODatetimeDataField, OINODbSqlAggregate, OINODbSqlSelect, OINODbSqlFilter, OINODbSqlOrder, OINODbSqlLimit } from "./index.js";
7
+ import { OINOLog, OINOResult, OINOHttpRequest } from "@oino-ts/common";
8
8
  import { OINOHashid } from "@oino-ts/hashid";
9
- const API_EMPTY_PARAMS = { sqlParams: {} };
9
+ export class OINODbApiRequest extends OINOHttpRequest {
10
+ rowId;
11
+ data;
12
+ sqlParams;
13
+ constructor(init) {
14
+ super(init);
15
+ this.rowId = init?.rowId || "";
16
+ this.data = init?.data || null;
17
+ this.sqlParams = init?.sqlParams || {};
18
+ if (init?.filter) {
19
+ this.sqlParams.filter = init.filter;
20
+ }
21
+ if (!this.sqlParams.filter) {
22
+ const filter_param = this.url?.searchParams.get(OINODbConfig.OINODB_SQL_FILTER_PARAM);
23
+ if (filter_param) {
24
+ this.sqlParams.filter = OINODbSqlFilter.parse(filter_param);
25
+ }
26
+ }
27
+ if (init?.order) {
28
+ this.sqlParams.order = init.order;
29
+ }
30
+ if (!this.sqlParams.order) {
31
+ const order_param = this.url?.searchParams.get(OINODbConfig.OINODB_SQL_ORDER_PARAM);
32
+ if (order_param) {
33
+ this.sqlParams.order = OINODbSqlOrder.parse(order_param);
34
+ }
35
+ }
36
+ if (init?.limit) {
37
+ this.sqlParams.limit = init.limit;
38
+ }
39
+ if (!this.sqlParams.limit) {
40
+ const limit_param = this.url?.searchParams.get(OINODbConfig.OINODB_SQL_LIMIT_PARAM);
41
+ if (limit_param) {
42
+ this.sqlParams.limit = OINODbSqlLimit.parse(limit_param);
43
+ }
44
+ }
45
+ if (init?.aggregate) {
46
+ this.sqlParams.aggregate = init.aggregate;
47
+ }
48
+ if (!this.sqlParams.aggregate) {
49
+ const aggregate_param = this.url?.searchParams.get(OINODbConfig.OINODB_SQL_AGGREGATE_PARAM);
50
+ if (aggregate_param) {
51
+ this.sqlParams.aggregate = OINODbSqlAggregate.parse(aggregate_param);
52
+ }
53
+ }
54
+ if (init?.select) {
55
+ this.sqlParams.select = init.select;
56
+ }
57
+ if (!this.sqlParams.select) {
58
+ const select_param = this.url?.searchParams.get(OINODbConfig.OINODB_SQL_SELECT_PARAM);
59
+ if (select_param) {
60
+ this.sqlParams.select = OINODbSqlSelect.parse(select_param);
61
+ }
62
+ }
63
+ }
64
+ }
10
65
  /**
11
66
  * OINO API request result object with returned data and/or http status code/message and
12
67
  * error / warning messages.
@@ -14,19 +69,19 @@ const API_EMPTY_PARAMS = { sqlParams: {} };
14
69
  */
15
70
  export class OINODbApiResult extends OINOResult {
16
71
  /** DbApi request params */
17
- params;
72
+ request;
18
73
  /** Returned data if any */
19
74
  data;
20
75
  /**
21
76
  * Constructor of OINODbApiResult.
22
77
  *
23
- * @param params DbApi request parameters
78
+ * @param request DbApi request parameters
24
79
  * @param data result data
25
80
  *
26
81
  */
27
- constructor(params, data) {
82
+ constructor(request, data) {
28
83
  super();
29
- this.params = params;
84
+ this.request = request;
30
85
  this.data = data;
31
86
  }
32
87
  /**
@@ -38,11 +93,11 @@ export class OINODbApiResult extends OINOResult {
38
93
  async writeApiResponse(headers = {}) {
39
94
  let response = null;
40
95
  if (this.success && this.data) {
41
- const body = await this.data.writeString(this.params.responseType);
42
- response = new Response(body, { status: this.statusCode, statusText: this.statusMessage, headers: headers });
96
+ const body = await this.data.writeString(this.request.responseType);
97
+ response = new Response(body, { status: this.status, statusText: this.statusText, headers: headers });
43
98
  }
44
99
  else {
45
- response = new Response(JSON.stringify(this, null, 3), { status: this.statusCode, statusText: this.statusMessage, headers: headers });
100
+ response = new Response(JSON.stringify(this, null, 3), { status: this.status, statusText: this.statusText, headers: headers });
46
101
  }
47
102
  for (let i = 0; i < this.messages.length; i++) {
48
103
  response.headers.set('X-OINO-MESSAGE-' + i, this.messages[i]);
@@ -215,14 +270,14 @@ export class OINODbApi {
215
270
  }
216
271
  //logDebug("OINODbApi.validateHttpValues", {result:result})
217
272
  }
218
- _parseData(httpResult, body, params) {
273
+ _parseData(httpResult, request) {
219
274
  let rows = [];
220
275
  try {
221
- if (Array.isArray(body)) {
222
- rows = body;
276
+ if (Array.isArray(request.data)) {
277
+ rows = request.data;
223
278
  }
224
- else {
225
- rows = OINODbParser.createRows(this.datamodel, body, params);
279
+ else if (request.data != null) {
280
+ rows = OINODbParser.createRows(this.datamodel, request.data, request);
226
281
  }
227
282
  }
228
283
  catch (e) {
@@ -230,10 +285,10 @@ export class OINODbApi {
230
285
  }
231
286
  return rows;
232
287
  }
233
- async _doGet(result, id, params) {
288
+ async _doGet(result, rowId, request) {
234
289
  let sql = "";
235
290
  try {
236
- sql = this.datamodel.printSqlSelect(id, params.sqlParams || {});
291
+ sql = this.datamodel.printSqlSelect(rowId, request.sqlParams || {});
237
292
  OINOLog.debug("@oino-ts/db", "OINODbApi", "_doGet", "Print SQL", { sql: sql });
238
293
  const sql_res = await this.db.sqlSelect(sql);
239
294
  if (sql_res.hasErrors()) {
@@ -243,7 +298,7 @@ export class OINODbApi {
243
298
  }
244
299
  }
245
300
  else {
246
- result.data = new OINODbModelSet(this.datamodel, sql_res, params.sqlParams);
301
+ result.data = new OINODbModelSet(this.datamodel, sql_res, request.sqlParams);
247
302
  }
248
303
  }
249
304
  catch (e) {
@@ -375,28 +430,38 @@ export class OINODbApi {
375
430
  this._debugOnError = debugOnError;
376
431
  }
377
432
  /**
378
- * Method for handlind a HTTP REST request with GET, POST, PUT, DELETE corresponding to
433
+ * Method for handling a HTTP REST request with GET, POST, PUT, DELETE corresponding to
379
434
  * SQL select, insert, update and delete.
380
435
  *
381
- * @param method HTTP verb (uppercase)
382
- * @param id URL id of the REST request
383
- * @param data HTTP body data as either serialized string or unserialized JS object / OINODataRow-array
384
- * @param params HTTP URL parameters as key-value-pairs
436
+ * @param method HTTP method of the REST request
437
+ * @param rowId URL id of the REST request
438
+ * @param data HTTP body data as either serialized string or unserialized JS object or OINODataRow-array or Buffer/Uint8Array binary data
439
+ * @param sqlParams SQL parameters for the REST request
385
440
  *
386
441
  */
387
- async doRequest(method, id, data, params = API_EMPTY_PARAMS) {
388
- OINOBenchmark.startMetric("OINODbApi", "doRequest." + method);
389
- OINOLog.debug("@oino-ts/db", "OINODbApi", "doRequest", "Request", { method: method, id: id, data: data });
390
- let result = new OINODbApiResult(params);
442
+ async doRequest(method, rowId, data, sqlParams) {
443
+ return this.runRequest(new OINODbApiRequest({ method: method, rowId: rowId, data: data, sqlParams: sqlParams }));
444
+ }
445
+ /**
446
+ * Method for handling a HTTP REST request with GET, POST, PUT, DELETE corresponding to
447
+ * SQL select, insert, update and delete.
448
+ *
449
+ * @param request OINO DB API request
450
+ *
451
+ */
452
+ async runRequest(request) {
453
+ OINOBenchmark.startMetric("OINODbApi", "doRequest." + request.method);
454
+ OINOLog.debug("@oino-ts/db", "OINODbApi", "doRequest", "Request", { method: request.method, id: request.rowId, data: request.data });
455
+ let result = new OINODbApiResult(request);
391
456
  let rows = [];
392
- if ((method == "POST") || (method == "PUT")) {
393
- rows = this._parseData(result, data, params);
457
+ if ((request.method == "POST") || (request.method == "PUT")) {
458
+ rows = this._parseData(result, request);
394
459
  }
395
- if (method == "GET") {
396
- await this._doGet(result, id, params);
460
+ if (request.method == "GET") {
461
+ await this._doGet(result, request.rowId, request);
397
462
  }
398
- else if (method == "PUT") {
399
- if (!id) {
463
+ else if (request.method == "PUT") {
464
+ if (!request.rowId) {
400
465
  result.setError(400, "HTTP PUT method requires an URL ID for the row that is updated!", "DoRequest");
401
466
  }
402
467
  else if (rows.length != 1) {
@@ -404,15 +469,15 @@ export class OINODbApi {
404
469
  }
405
470
  else {
406
471
  try {
407
- await this._doPut(result, id, rows);
472
+ await this._doPut(result, request.rowId, rows);
408
473
  }
409
474
  catch (e) {
410
475
  result.setError(500, "Unhandled exception in HTTP PUT doRequest: " + e.message, "DoRequest");
411
476
  }
412
477
  }
413
478
  }
414
- else if (method == "POST") {
415
- if (id) {
479
+ else if (request.method == "POST") {
480
+ if (request.rowId) {
416
481
  result.setError(400, "HTTP POST method must not have an URL ID as it does not target an existing row but creates a new one!", "DoRequest");
417
482
  }
418
483
  else if (rows.length == 0) {
@@ -427,13 +492,13 @@ export class OINODbApi {
427
492
  }
428
493
  }
429
494
  }
430
- else if (method == "DELETE") {
431
- if (!id) {
495
+ else if (request.method == "DELETE") {
496
+ if (!request.rowId) {
432
497
  result.setError(400, "HTTP DELETE method requires an id!", "DoRequest");
433
498
  }
434
499
  else {
435
500
  try {
436
- await this._doDelete(result, id, null);
501
+ await this._doDelete(result, request.rowId, null);
437
502
  }
438
503
  catch (e) {
439
504
  result.setError(500, "Unhandled exception in HTTP DELETE doRequest: " + e.message, "DoRequest");
@@ -441,29 +506,38 @@ export class OINODbApi {
441
506
  }
442
507
  }
443
508
  else {
444
- result.setError(405, "Unsupported HTTP method '" + method + "' for REST request", "DoRequest");
509
+ result.setError(405, "Unsupported HTTP method '" + request.method + "' for REST request", "DoRequest");
445
510
  }
446
- OINOBenchmark.endMetric("OINODbApi", "doRequest." + method);
511
+ OINOBenchmark.endMetric("OINODbApi", "doRequest." + request.method);
447
512
  return Promise.resolve(result);
448
513
  }
449
514
  /**
450
- * Method for handlind a HTTP REST request with GET, POST, PUT, DELETE corresponding to
451
- * SQL select, insert, update and delete.
515
+ * Method for handling a HTTP REST request with batch update using PUT or DELETE methods.
452
516
  *
453
- * @param method HTTP verb (uppercase)
454
- * @param data HTTP body data as either serialized string or unserialized JS object / OINODataRow-array
455
- * @param params HTTP URL parameters as key-value-pairs
517
+ * @param method HTTP method of the REST request
518
+ * @param rowId URL id of the REST request
519
+ * @param data HTTP body data as either serialized string or unserialized JS object or OINODataRow-array or Buffer/Uint8Array binary data
456
520
  *
457
521
  */
458
- async doBatchUpdate(method, data, params = API_EMPTY_PARAMS) {
459
- OINOBenchmark.startMetric("OINODbApi", "doBatchUpdate." + method);
460
- OINOLog.debug("@oino-ts/db", "OINODbApi", "doBatchUpdate", "Request", { method: method, data: data, params: params });
461
- let result = new OINODbApiResult(params);
462
- let rows = [];
463
- if ((method == "PUT")) {
464
- rows = this._parseData(result, data, params);
465
- }
466
- if (method == "PUT") {
522
+ async doBatchUpdate(method, rowId, data, sqlParams) {
523
+ return this.runRequest(new OINODbApiRequest({ method: method, rowId: rowId, data: data, sqlParams: sqlParams }));
524
+ }
525
+ /**
526
+ * Method for handling a HTTP REST request with batch update using PUT or DELETE methods.
527
+ *
528
+ * @param request HTTP URL parameters as key-value-pairs
529
+ *
530
+ */
531
+ async runBatchUpdate(request) {
532
+ OINOLog.debug("@oino-ts/db", "OINODbApi", "doBatchUpdate", "Request", { request: request, data: request.data });
533
+ let result = new OINODbApiResult(request);
534
+ if ((request.method != "PUT") && (request.method != "DELETE")) {
535
+ result.setError(500, "Batch update only supports PUT and DELETE methods!", "DoBatchUpdate");
536
+ return Promise.resolve(result);
537
+ }
538
+ OINOBenchmark.startMetric("OINODbApi", "doBatchUpdate." + request.method);
539
+ const rows = [] = this._parseData(result, request);
540
+ if (request.method == "PUT") {
467
541
  try {
468
542
  await this._doPut(result, null, rows);
469
543
  }
@@ -471,7 +545,7 @@ export class OINODbApi {
471
545
  result.setError(500, "Unhandled exception in HTTP PUT doRequest: " + e.message, "DoBatchUpdate");
472
546
  }
473
547
  }
474
- else if (method == "DELETE") {
548
+ else if (request.method == "DELETE") {
475
549
  try {
476
550
  await this._doDelete(result, null, rows);
477
551
  }
@@ -479,10 +553,7 @@ export class OINODbApi {
479
553
  result.setError(500, "Unhandled exception in HTTP DELETE doRequest: " + e.message, "DoBatchUpdate");
480
554
  }
481
555
  }
482
- else {
483
- result.setError(405, "Unsupported HTTP method '" + method + "' for batch update", "DoBatchUpdate");
484
- }
485
- OINOBenchmark.endMetric("OINODbApi", "doBatchUpdate." + method);
556
+ OINOBenchmark.endMetric("OINODbApi", "doBatchUpdate." + request.method);
486
557
  return Promise.resolve(result);
487
558
  }
488
559
  /**
@@ -15,10 +15,6 @@ export class OINODbConfig {
15
15
  static OINODB_SQL_AGGREGATE_PARAM = "oinosqlaggregate";
16
16
  /** Name of the OINODbSqlSelect-parameter in request */
17
17
  static OINODB_SQL_SELECT_PARAM = "oinosqlselect";
18
- /** Name of the OINOContentType-parameter request */
19
- static OINODB_REQUEST_TYPE = "oinorequesttype";
20
- /** Name of the OINOContentType-parameter request */
21
- static OINODB_RESPONSE_TYPE = "oinoresponsetype";
22
18
  /**
23
19
  * Set the name of the OINO ID field
24
20
  * @param idField name of the OINO ID field
@@ -3,7 +3,7 @@
3
3
  * License, v. 2.0. If a copy of the MPL was not distributed with this
4
4
  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
5
  */
6
- import { OINODbApi, OINOContentType, OINODbSqlFilter, OINODbConfig, OINODbSqlOrder, OINODbSqlLimit, OINODbSqlAggregate, OINODbSqlSelect, OINOLog } from "./index.js";
6
+ import { OINODbApi } from "./index.js";
7
7
  /**
8
8
  * Static factory class for easily creating things based on data
9
9
  *
@@ -39,13 +39,13 @@ export class OINODbFactory {
39
39
  if (connect) {
40
40
  const connect_res = await result.connect();
41
41
  if (connect_res.success == false) {
42
- throw new Error("Database connection failed: " + connect_res.statusMessage);
42
+ throw new Error("Database connection failed: " + connect_res.statusText);
43
43
  }
44
44
  }
45
45
  if (validate) {
46
46
  const validate_res = await result.validate();
47
47
  if (validate_res.success == false) {
48
- throw new Error("Database validation failed: " + validate_res.statusMessage);
48
+ throw new Error("Database validation failed: " + validate_res.statusText);
49
49
  }
50
50
  }
51
51
  return result;
@@ -61,69 +61,4 @@ export class OINODbFactory {
61
61
  await db.initializeApiDatamodel(result);
62
62
  return result;
63
63
  }
64
- /**
65
- * Creates a key-value-collection from Javascript URL parameters.
66
- *
67
- * @param request HTTP Request
68
- */
69
- static createParamsFromRequest(request) {
70
- const url = new URL(request.url);
71
- let sql_params = {};
72
- const filter = url.searchParams.get(OINODbConfig.OINODB_SQL_FILTER_PARAM);
73
- if (filter) {
74
- sql_params.filter = OINODbSqlFilter.parse(filter);
75
- }
76
- const order = url.searchParams.get(OINODbConfig.OINODB_SQL_ORDER_PARAM);
77
- if (order) {
78
- sql_params.order = OINODbSqlOrder.parse(order);
79
- }
80
- const limit = url.searchParams.get(OINODbConfig.OINODB_SQL_LIMIT_PARAM);
81
- if (limit) {
82
- sql_params.limit = OINODbSqlLimit.parse(limit);
83
- }
84
- const aggregate = url.searchParams.get(OINODbConfig.OINODB_SQL_AGGREGATE_PARAM);
85
- if (aggregate) {
86
- sql_params.aggregate = OINODbSqlAggregate.parse(aggregate);
87
- }
88
- const select = url.searchParams.get(OINODbConfig.OINODB_SQL_SELECT_PARAM);
89
- if (select) {
90
- sql_params.select = OINODbSqlSelect.parse(select);
91
- }
92
- let result = { sqlParams: sql_params };
93
- const request_type = url.searchParams.get(OINODbConfig.OINODB_REQUEST_TYPE) || request.headers.get("content-type"); // content-type header can be overridden by query parameter
94
- if (request_type == OINOContentType.csv) {
95
- result.requestType = OINOContentType.csv;
96
- }
97
- else if (request_type == OINOContentType.urlencode) {
98
- result.requestType = OINOContentType.urlencode;
99
- }
100
- else if (request_type?.startsWith(OINOContentType.formdata)) {
101
- result.requestType = OINOContentType.formdata;
102
- result.multipartBoundary = request_type.split('boundary=')[1] || "";
103
- }
104
- else {
105
- result.requestType = OINOContentType.json;
106
- }
107
- const response_type = url.searchParams.get(OINODbConfig.OINODB_RESPONSE_TYPE) || request.headers.get("accept"); // accept header can be overridden by query parameter
108
- const accept_types = response_type?.split(', ') || [];
109
- for (let i = 0; i < accept_types.length; i++) {
110
- if (Object.values(OINOContentType).includes(accept_types[i])) {
111
- result.responseType = accept_types[i];
112
- break;
113
- }
114
- }
115
- if (result.responseType === undefined) {
116
- result.responseType = OINOContentType.json;
117
- }
118
- const last_modified = request.headers.get("if-modified-since");
119
- if (last_modified) {
120
- result.lastModified = new Date(last_modified).getTime();
121
- }
122
- const etags = request.headers.get("if-none-match")?.split(',').map(e => e.trim());
123
- if (etags) {
124
- result.etags = etags;
125
- }
126
- OINOLog.debug("@oino-ts/db", "OINODbFactory", "createParamsFromRequest", "Result", { params: result });
127
- return result;
128
- }
129
64
  }
@@ -13,20 +13,20 @@ export class OINODbParser {
13
13
  * Create data rows from request body based on the datamodel.
14
14
  *
15
15
  * @param datamodel datamodel of the api
16
- * @param data data as a string or Buffer or object
17
- * @param requestParams parameters
16
+ * @param data data as either serialized string or unserialized JS object or OINODataRow-array or Buffer/Uint8Array binary data
17
+ * @param request parameters
18
18
  *
19
19
  */
20
- static createRows(datamodel, data, requestParams) {
20
+ static createRows(datamodel, data, request) {
21
21
  let result = [];
22
22
  if (typeof data == "string") {
23
- result = this.createRowsFromText(datamodel, data, requestParams);
23
+ result = this._createRowsFromText(datamodel, data, request);
24
24
  }
25
- else if (data instanceof Buffer) {
26
- result = this.createRowsFromBlob(datamodel, data, requestParams);
25
+ else if ((data instanceof Buffer) || (data instanceof Uint8Array)) {
26
+ result = this._createRowsFromBlob(datamodel, data, request);
27
27
  }
28
28
  else if (typeof data == "object") {
29
- result = [this.createRowFromObject(datamodel, data)];
29
+ result = [this._createRowFromObject(datamodel, data)];
30
30
  }
31
31
  return result;
32
32
  }
@@ -35,28 +35,28 @@ export class OINODbParser {
35
35
  *
36
36
  * @param datamodel datamodel of the api
37
37
  * @param data data as a string
38
- * @param requestParams parameters
38
+ * @param request request parameters
39
39
  *
40
40
  */
41
- static createRowsFromText(datamodel, data, requestParams) {
42
- if ((requestParams.requestType == OINOContentType.json) || (requestParams.requestType == undefined)) {
41
+ static _createRowsFromText(datamodel, data, request) {
42
+ if ((request.requestType == OINOContentType.json) || (request.requestType == undefined)) {
43
43
  return this._createRowFromJson(datamodel, data);
44
44
  }
45
- else if (requestParams.requestType == OINOContentType.csv) {
45
+ else if (request.requestType == OINOContentType.csv) {
46
46
  return this._createRowFromCsv(datamodel, data);
47
47
  }
48
- else if (requestParams.requestType == OINOContentType.formdata) {
49
- return this._createRowFromFormdata(datamodel, Buffer.from(data, "utf8"), requestParams.multipartBoundary || "");
48
+ else if (request.requestType == OINOContentType.formdata) {
49
+ return this._createRowFromFormdata(datamodel, Buffer.from(data, "utf8"), request.multipartBoundary || "");
50
50
  }
51
- else if (requestParams.requestType == OINOContentType.urlencode) {
51
+ else if (request.requestType == OINOContentType.urlencode) {
52
52
  return this._createRowFromUrlencoded(datamodel, data);
53
53
  }
54
- else if (requestParams.requestType == OINOContentType.html) {
54
+ else if (request.requestType == OINOContentType.html) {
55
55
  OINOLog.error("@oino-ts/db", "OINODbParser", "createRowsFromText", "HTML can't be used as an input content type!", { contentType: OINOContentType.html });
56
56
  return [];
57
57
  }
58
58
  else {
59
- OINOLog.error("@oino-ts/db", "OINODbParser", "createRowsFromText", "Unrecognized input content type!", { contentType: requestParams.requestType });
59
+ OINOLog.error("@oino-ts/db", "OINODbParser", "createRowsFromText", "Unrecognized input content type!", { contentType: request.requestType });
60
60
  return [];
61
61
  }
62
62
  }
@@ -64,29 +64,32 @@ export class OINODbParser {
64
64
  * Create data rows from request body based on the datamodel.
65
65
  *
66
66
  * @param datamodel datamodel of the api
67
- * @param data data as an Buffer
68
- * @param requestParams parameters
67
+ * @param data data as an Buffer or Uint8Array
68
+ * @param request parameters
69
69
  *
70
70
  */
71
- static createRowsFromBlob(datamodel, data, requestParams) {
72
- if ((requestParams.requestType == OINOContentType.json) || (requestParams.requestType == undefined)) {
71
+ static _createRowsFromBlob(datamodel, data, request) {
72
+ if (data instanceof Uint8Array && !(data instanceof Buffer)) {
73
+ data = Buffer.from(data);
74
+ }
75
+ if ((request.requestType == OINOContentType.json) || (request.requestType == undefined)) {
73
76
  return this._createRowFromJson(datamodel, data.toString()); // JSON is always a string
74
77
  }
75
- else if (requestParams.requestType == OINOContentType.csv) {
78
+ else if (request.requestType == OINOContentType.csv) {
76
79
  return this._createRowFromCsv(datamodel, data.toString()); // binary data has to be base64 encoded so it's a string
77
80
  }
78
- else if (requestParams.requestType == OINOContentType.formdata) {
79
- return this._createRowFromFormdata(datamodel, data, requestParams.multipartBoundary || "");
81
+ else if (request.requestType == OINOContentType.formdata) {
82
+ return this._createRowFromFormdata(datamodel, data, request.multipartBoundary || "");
80
83
  }
81
- else if (requestParams.requestType == OINOContentType.urlencode) {
84
+ else if (request.requestType == OINOContentType.urlencode) {
82
85
  return this._createRowFromUrlencoded(datamodel, data.toString()); // data is urlencoded so it's a string
83
86
  }
84
- else if (requestParams.requestType == OINOContentType.html) {
87
+ else if (request.requestType == OINOContentType.html) {
85
88
  OINOLog.error("@oino-ts/db", "OINODbParser", "createRowsFromBlob", "HTML can't be used as an input content type!", { contentType: OINOContentType.html });
86
89
  return [];
87
90
  }
88
91
  else {
89
- OINOLog.error("@oino-ts/db", "OINODbParser", "createRowsFromBlob", "Unrecognized input content type!", { contentType: requestParams.requestType });
92
+ OINOLog.error("@oino-ts/db", "OINODbParser", "createRowsFromBlob", "Unrecognized input content type!", { contentType: request.requestType });
90
93
  return [];
91
94
  }
92
95
  }
@@ -98,7 +101,7 @@ export class OINODbParser {
98
101
  * @param data data as javascript object
99
102
  *
100
103
  */
101
- static createRowFromObject(datamodel, data) {
104
+ static _createRowFromObject(datamodel, data) {
102
105
  const fields = datamodel.fields;
103
106
  let result = new Array(fields.length);
104
107
  for (let i = 0; i < fields.length; i++) {
@@ -53,10 +53,10 @@ export class OINODbSwagger {
53
53
  "success": {
54
54
  "type": "boolean"
55
55
  },
56
- "statusCode": {
56
+ "status": {
57
57
  "type": "number"
58
58
  },
59
- "statusMessage": {
59
+ "statusText": {
60
60
  "type": "string"
61
61
  },
62
62
  "messages": {
@@ -68,8 +68,8 @@ export class OINODbSwagger {
68
68
  },
69
69
  "required": [
70
70
  "success",
71
- "statusCode",
72
- "statusMessage",
71
+ "status",
72
+ "statusText",
73
73
  "messages"
74
74
  ]
75
75
  };
package/dist/esm/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { OINOContentType } from "@oino-ts/common";
2
2
  export { OINOContentType };
3
3
  export { OINO_ERROR_PREFIX, OINO_WARNING_PREFIX, OINO_INFO_PREFIX, OINO_DEBUG_PREFIX, OINOStr, OINOBenchmark, OINOMemoryBenchmark, OINOLog, OINOLogLevel, OINOConsoleLog, OINOResult, OINOHttpResult, OINOHtmlTemplate } from "@oino-ts/common";
4
- export { OINODbApiResult, OINODbHtmlTemplate, OINODbApi } from "./OINODbApi.js";
4
+ export { OINODbApiResult, OINODbHtmlTemplate, OINODbApi, OINODbApiRequest } from "./OINODbApi.js";
5
5
  export { OINODbDataModel } from "./OINODbDataModel.js";
6
6
  export { OINODbModelSet } from "./OINODbModelSet.js";
7
7
  export { OINODbDataField, OINOBooleanDataField, OINONumberDataField, OINOStringDataField, OINOBlobDataField, OINODatetimeDataField } from "./OINODbDataField.js";
@@ -8,8 +8,8 @@ export declare abstract class OINODb {
8
8
  protected _params: OINODbParams;
9
9
  /** Name of the database */
10
10
  readonly name: string;
11
- protected isConnected: boolean;
12
- protected isValidated: boolean;
11
+ isConnected: boolean;
12
+ isValidated: boolean;
13
13
  /**
14
14
  * Constructor for `OINODb`.
15
15
  * @param params database parameters