@oino-ts/db 0.4.5 → 0.5.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.
@@ -18,6 +18,10 @@ class OINODbConfig {
18
18
  static OINODB_SQL_AGGREGATE_PARAM = "oinosqlaggregate";
19
19
  /** Name of the OINODbSqlSelect-parameter in request */
20
20
  static OINODB_SQL_SELECT_PARAM = "oinosqlselect";
21
+ /** Name of the OINOContentType-parameter request */
22
+ static OINODB_REQUEST_TYPE = "oinorequesttype";
23
+ /** Name of the OINOContentType-parameter request */
24
+ static OINODB_RESPONSE_TYPE = "oinoresponsetype";
21
25
  /**
22
26
  * Set the name of the OINO ID field
23
27
  * @param idField name of the OINO ID field
@@ -81,23 +81,23 @@ class OINODbFactory {
81
81
  sql_params.select = index_js_1.OINODbSqlSelect.parse(select);
82
82
  }
83
83
  let result = { sqlParams: sql_params };
84
- const content_type = request.headers.get("content-type");
85
- if (content_type == index_js_1.OINOContentType.csv) {
84
+ const request_type = url.searchParams.get(index_js_1.OINODbConfig.OINODB_REQUEST_TYPE) || request.headers.get("content-type"); // content-type header can be overridden by query parameter
85
+ if (request_type == index_js_1.OINOContentType.csv) {
86
86
  result.requestType = index_js_1.OINOContentType.csv;
87
87
  }
88
- else if (content_type == index_js_1.OINOContentType.urlencode) {
88
+ else if (request_type == index_js_1.OINOContentType.urlencode) {
89
89
  result.requestType = index_js_1.OINOContentType.urlencode;
90
90
  }
91
- else if (content_type?.startsWith(index_js_1.OINOContentType.formdata)) {
91
+ else if (request_type?.startsWith(index_js_1.OINOContentType.formdata)) {
92
92
  result.requestType = index_js_1.OINOContentType.formdata;
93
- result.multipartBoundary = content_type.split('boundary=')[1] || "";
93
+ result.multipartBoundary = request_type.split('boundary=')[1] || "";
94
94
  }
95
95
  else {
96
96
  result.requestType = index_js_1.OINOContentType.json;
97
97
  }
98
- const accept = request.headers.get("accept");
98
+ const response_type = url.searchParams.get(index_js_1.OINODbConfig.OINODB_RESPONSE_TYPE) || request.headers.get("accept"); // accept header can be overridden by query parameter
99
99
  // OINOLog.debug("createParamsFromRequest: accept headers", {accept:accept})
100
- const accept_types = accept?.split(', ') || [];
100
+ const accept_types = response_type?.split(', ') || [];
101
101
  for (let i = 0; i < accept_types.length; i++) {
102
102
  if (Object.values(index_js_1.OINOContentType).includes(accept_types[i])) {
103
103
  result.responseType = accept_types[i];
@@ -15,6 +15,10 @@ 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";
18
22
  /**
19
23
  * Set the name of the OINO ID field
20
24
  * @param idField name of the OINO ID field
@@ -78,23 +78,23 @@ export class OINODbFactory {
78
78
  sql_params.select = OINODbSqlSelect.parse(select);
79
79
  }
80
80
  let result = { sqlParams: sql_params };
81
- const content_type = request.headers.get("content-type");
82
- if (content_type == OINOContentType.csv) {
81
+ const request_type = url.searchParams.get(OINODbConfig.OINODB_REQUEST_TYPE) || request.headers.get("content-type"); // content-type header can be overridden by query parameter
82
+ if (request_type == OINOContentType.csv) {
83
83
  result.requestType = OINOContentType.csv;
84
84
  }
85
- else if (content_type == OINOContentType.urlencode) {
85
+ else if (request_type == OINOContentType.urlencode) {
86
86
  result.requestType = OINOContentType.urlencode;
87
87
  }
88
- else if (content_type?.startsWith(OINOContentType.formdata)) {
88
+ else if (request_type?.startsWith(OINOContentType.formdata)) {
89
89
  result.requestType = OINOContentType.formdata;
90
- result.multipartBoundary = content_type.split('boundary=')[1] || "";
90
+ result.multipartBoundary = request_type.split('boundary=')[1] || "";
91
91
  }
92
92
  else {
93
93
  result.requestType = OINOContentType.json;
94
94
  }
95
- const accept = request.headers.get("accept");
95
+ const response_type = url.searchParams.get(OINODbConfig.OINODB_RESPONSE_TYPE) || request.headers.get("accept"); // accept header can be overridden by query parameter
96
96
  // OINOLog.debug("createParamsFromRequest: accept headers", {accept:accept})
97
- const accept_types = accept?.split(', ') || [];
97
+ const accept_types = response_type?.split(', ') || [];
98
98
  for (let i = 0; i < accept_types.length; i++) {
99
99
  if (Object.values(OINOContentType).includes(accept_types[i])) {
100
100
  result.responseType = accept_types[i];
@@ -15,6 +15,10 @@ export declare class OINODbConfig {
15
15
  static OINODB_SQL_AGGREGATE_PARAM: string;
16
16
  /** Name of the OINODbSqlSelect-parameter in request */
17
17
  static OINODB_SQL_SELECT_PARAM: string;
18
+ /** Name of the OINOContentType-parameter request */
19
+ static OINODB_REQUEST_TYPE: string;
20
+ /** Name of the OINOContentType-parameter request */
21
+ static OINODB_RESPONSE_TYPE: string;
18
22
  /**
19
23
  * Set the name of the OINO ID field
20
24
  * @param idField name of the OINO ID field
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oino-ts/db",
3
- "version": "0.4.5",
3
+ "version": "0.5.0",
4
4
  "description": "OINO TS library package for publishing an SQL database tables as a REST API.",
5
5
  "author": "Matias Kiviniemi (pragmatta)",
6
6
  "license": "MPL-2.0",
@@ -19,12 +19,12 @@
19
19
  "module": "./dist/esm/index.js",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "dependencies": {
22
- "@oino-ts/common": "0.4.5"
22
+ "@oino-ts/common": "0.5.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/node": "^20.14.10",
26
26
  "@types/bun": "^1.1.14",
27
- "@oino-ts/types": "0.4.5",
27
+ "@oino-ts/types": "0.5.0",
28
28
  "typedoc": "^0.25.13"
29
29
  },
30
30
  "files": [
@@ -22,6 +22,12 @@ export class OINODbConfig {
22
22
  /** Name of the OINODbSqlSelect-parameter in request */
23
23
  static OINODB_SQL_SELECT_PARAM:string = "oinosqlselect"
24
24
 
25
+ /** Name of the OINOContentType-parameter request */
26
+ static OINODB_REQUEST_TYPE:string = "oinorequesttype"
27
+
28
+ /** Name of the OINOContentType-parameter request */
29
+ static OINODB_RESPONSE_TYPE:string = "oinoresponsetype"
30
+
25
31
  /**
26
32
  * Set the name of the OINO ID field
27
33
  * @param idField name of the OINO ID field
@@ -86,23 +86,23 @@ export class OINODbFactory {
86
86
 
87
87
  let result:OINODbApiRequestParams = { sqlParams: sql_params }
88
88
 
89
- const content_type = request.headers.get("content-type")
90
- if (content_type == OINOContentType.csv) {
89
+ const request_type = url.searchParams.get(OINODbConfig.OINODB_REQUEST_TYPE) || request.headers.get("content-type") // content-type header can be overridden by query parameter
90
+ if (request_type == OINOContentType.csv) {
91
91
  result.requestType = OINOContentType.csv
92
92
 
93
- } else if (content_type == OINOContentType.urlencode) {
93
+ } else if (request_type == OINOContentType.urlencode) {
94
94
  result.requestType = OINOContentType.urlencode
95
95
 
96
- } else if (content_type?.startsWith(OINOContentType.formdata)) {
96
+ } else if (request_type?.startsWith(OINOContentType.formdata)) {
97
97
  result.requestType = OINOContentType.formdata
98
- result.multipartBoundary = content_type.split('boundary=')[1] || ""
98
+ result.multipartBoundary = request_type.split('boundary=')[1] || ""
99
99
 
100
100
  } else {
101
101
  result.requestType = OINOContentType.json
102
102
  }
103
- const accept = request.headers.get("accept")
103
+ const response_type = url.searchParams.get(OINODbConfig.OINODB_RESPONSE_TYPE) || request.headers.get("accept") // accept header can be overridden by query parameter
104
104
  // OINOLog.debug("createParamsFromRequest: accept headers", {accept:accept})
105
- const accept_types = accept?.split(', ') || []
105
+ const accept_types = response_type?.split(', ') || []
106
106
  for (let i=0; i<accept_types.length; i++) {
107
107
  if (Object.values(OINOContentType).includes(accept_types[i] as OINOContentType)) {
108
108
  result.responseType = accept_types[i] as OINOContentType