@oino-ts/db 0.4.3 → 0.4.5

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.
@@ -60,7 +60,7 @@ exports.OINODbApiResult = OINODbApiResult;
60
60
  */
61
61
  class OINODbHtmlTemplate extends index_js_1.OINOHtmlTemplate {
62
62
  /** Locale validation regex */
63
- static LOCALE_REGEX = /^(\w\w)(\-\w\w)?$/g;
63
+ static LOCALE_REGEX = /^(\w\w)(\-\w\w)?$/;
64
64
  /** Locale formatter */
65
65
  _locale;
66
66
  /**
@@ -73,7 +73,6 @@ class OINODbHtmlTemplate extends index_js_1.OINOHtmlTemplate {
73
73
  */
74
74
  constructor(template, dateLocaleStr, dateLocaleStyle) {
75
75
  super(template);
76
- console.log("OINODbHtmlTemplate.constructor", { dateLocaleStr: dateLocaleStr, dateLocaleStyle: dateLocaleStyle });
77
76
  let locale_opts;
78
77
  if ((dateLocaleStyle == null) || (dateLocaleStyle == "")) {
79
78
  locale_opts = { dateStyle: "medium", timeStyle: "medium" };
@@ -236,7 +236,7 @@ class OINODbDataModel {
236
236
  const filter_sql = params.filter?.toSql(this) || "";
237
237
  const groupby_sql = params.aggregate?.toSql(this, params.select) || "";
238
238
  let where_sql = "";
239
- // OINOLog.debug("OINODbDataModel.printSqlSelect", {order_sql:order_sql, limit_sql:limit_sql, filter_sql:filter_sql, aggregate_sql:aggregate_sql})
239
+ // OINOLog.debug("OINODbDataModel.printSqlSelect", {order_sql:order_sql, limit_sql:limit_sql, filter_sql:filter_sql, groupby_sql:groupby_sql})
240
240
  if ((id != null) && (id != "") && (filter_sql != "")) {
241
241
  where_sql = this._printSqlPrimaryKeyCondition(id) + " AND " + filter_sql;
242
242
  }
@@ -247,7 +247,7 @@ class OINODbDataModel {
247
247
  where_sql = filter_sql;
248
248
  }
249
249
  const result = this.api.db.printSqlSelect(this.api.params.tableName, column_names, where_sql, order_sql, limit_sql, groupby_sql);
250
- index_js_1.OINOLog.debug("OINODbDataModel.printSqlSelect", { result: result });
250
+ // OINOLog.debug("OINODbDataModel.printSqlSelect", {result:result})
251
251
  return result;
252
252
  }
253
253
  /**
@@ -412,7 +412,7 @@ class OINODbSqlAggregate {
412
412
  result += f.printSqlColumnName() + ",";
413
413
  }
414
414
  }
415
- // OINOLog.debug("OINODbSqlAggregate.toSql", {result:result})
415
+ index_js_1.OINOLog.debug("OINODbSqlAggregate.toSql", { result: result });
416
416
  return result.substring(0, result.length - 1);
417
417
  }
418
418
  /**
@@ -23,11 +23,14 @@ class OINODbSwagger {
23
23
  }
24
24
  static _getSchemaApiMethodParamsBody(tableName) {
25
25
  return {
26
- "schema": {
27
- "$ref": "#/components/schemas/" + tableName
28
- },
29
- "in": "body",
30
- "required": true
26
+ "required": true,
27
+ "content": {
28
+ "application/json": {
29
+ "schema": {
30
+ "$ref": "#/components/schemas/" + tableName
31
+ }
32
+ }
33
+ }
31
34
  };
32
35
  }
33
36
  static _getSchemaApiMethodDescription(method, tableName, hasQueryIdParam) {
@@ -130,28 +133,26 @@ class OINODbSwagger {
130
133
  return { "$ref": "#/components/schemas/OINOResponse" };
131
134
  }
132
135
  }
133
- static _getSchemaApiMethodParams(tableName, hasQueryIdParam, hasResultData) {
134
- if (hasResultData && hasQueryIdParam) {
136
+ static _getSchemaApiMethodParams(hasQueryIdParam) {
137
+ if (hasQueryIdParam) {
135
138
  return [this._getSchemaApiMethodParamsQueryId()];
136
139
  }
137
- else if (hasResultData) {
138
- return [];
139
- }
140
- else if (hasQueryIdParam) {
141
- return [this._getSchemaApiMethodParamsQueryId(), this._getSchemaApiMethodParamsBody(tableName)];
142
- }
143
140
  else {
144
- return [this._getSchemaApiMethodParamsBody(tableName)];
141
+ return [];
145
142
  }
146
143
  }
147
144
  static _getSchemaApiMethod(method, tableName, hasQueryIdParam, hasBody, hasResultData) {
148
- return {
145
+ const result = {
149
146
  responses: {
150
147
  200: { description: this._getSchemaApiMethodDescription(method, tableName, hasQueryIdParam), content: { "application/json": { schema: this._getSchemaType(tableName, hasQueryIdParam, hasResultData) } } }
151
148
  },
152
149
  "operationId": this._getSchemaApiMethodOperationId(method, tableName, hasQueryIdParam),
153
- "parameters": this._getSchemaApiMethodParams(tableName, hasQueryIdParam, hasResultData)
150
+ "parameters": this._getSchemaApiMethodParams(hasQueryIdParam)
154
151
  };
152
+ if (hasBody) {
153
+ result["requestBody"] = this._getSchemaApiMethodParamsBody(tableName);
154
+ }
155
+ return result;
155
156
  }
156
157
  static _getSwaggerApiPath(tableName, hasQueryIdParam) {
157
158
  if (hasQueryIdParam) {
@@ -56,7 +56,7 @@ export class OINODbApiResult extends OINOResult {
56
56
  */
57
57
  export class OINODbHtmlTemplate extends OINOHtmlTemplate {
58
58
  /** Locale validation regex */
59
- static LOCALE_REGEX = /^(\w\w)(\-\w\w)?$/g;
59
+ static LOCALE_REGEX = /^(\w\w)(\-\w\w)?$/;
60
60
  /** Locale formatter */
61
61
  _locale;
62
62
  /**
@@ -69,7 +69,6 @@ export class OINODbHtmlTemplate extends OINOHtmlTemplate {
69
69
  */
70
70
  constructor(template, dateLocaleStr, dateLocaleStyle) {
71
71
  super(template);
72
- console.log("OINODbHtmlTemplate.constructor", { dateLocaleStr: dateLocaleStr, dateLocaleStyle: dateLocaleStyle });
73
72
  let locale_opts;
74
73
  if ((dateLocaleStyle == null) || (dateLocaleStyle == "")) {
75
74
  locale_opts = { dateStyle: "medium", timeStyle: "medium" };
@@ -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 { OINO_ERROR_PREFIX, OINODbConfig, OINONumberDataField, OINOLog, OINODB_UNDEFINED } from "./index.js";
6
+ import { OINO_ERROR_PREFIX, OINODbConfig, OINONumberDataField, OINODB_UNDEFINED } from "./index.js";
7
7
  /**
8
8
  * OINO Datamodel object for representing one database table and it's columns.
9
9
  *
@@ -233,7 +233,7 @@ export class OINODbDataModel {
233
233
  const filter_sql = params.filter?.toSql(this) || "";
234
234
  const groupby_sql = params.aggregate?.toSql(this, params.select) || "";
235
235
  let where_sql = "";
236
- // OINOLog.debug("OINODbDataModel.printSqlSelect", {order_sql:order_sql, limit_sql:limit_sql, filter_sql:filter_sql, aggregate_sql:aggregate_sql})
236
+ // OINOLog.debug("OINODbDataModel.printSqlSelect", {order_sql:order_sql, limit_sql:limit_sql, filter_sql:filter_sql, groupby_sql:groupby_sql})
237
237
  if ((id != null) && (id != "") && (filter_sql != "")) {
238
238
  where_sql = this._printSqlPrimaryKeyCondition(id) + " AND " + filter_sql;
239
239
  }
@@ -244,7 +244,7 @@ export class OINODbDataModel {
244
244
  where_sql = filter_sql;
245
245
  }
246
246
  const result = this.api.db.printSqlSelect(this.api.params.tableName, column_names, where_sql, order_sql, limit_sql, groupby_sql);
247
- OINOLog.debug("OINODbDataModel.printSqlSelect", { result: result });
247
+ // OINOLog.debug("OINODbDataModel.printSqlSelect", {result:result})
248
248
  return result;
249
249
  }
250
250
  /**
@@ -406,7 +406,7 @@ export class OINODbSqlAggregate {
406
406
  result += f.printSqlColumnName() + ",";
407
407
  }
408
408
  }
409
- // OINOLog.debug("OINODbSqlAggregate.toSql", {result:result})
409
+ OINOLog.debug("OINODbSqlAggregate.toSql", { result: result });
410
410
  return result.substring(0, result.length - 1);
411
411
  }
412
412
  /**
@@ -20,11 +20,14 @@ export class OINODbSwagger {
20
20
  }
21
21
  static _getSchemaApiMethodParamsBody(tableName) {
22
22
  return {
23
- "schema": {
24
- "$ref": "#/components/schemas/" + tableName
25
- },
26
- "in": "body",
27
- "required": true
23
+ "required": true,
24
+ "content": {
25
+ "application/json": {
26
+ "schema": {
27
+ "$ref": "#/components/schemas/" + tableName
28
+ }
29
+ }
30
+ }
28
31
  };
29
32
  }
30
33
  static _getSchemaApiMethodDescription(method, tableName, hasQueryIdParam) {
@@ -127,28 +130,26 @@ export class OINODbSwagger {
127
130
  return { "$ref": "#/components/schemas/OINOResponse" };
128
131
  }
129
132
  }
130
- static _getSchemaApiMethodParams(tableName, hasQueryIdParam, hasResultData) {
131
- if (hasResultData && hasQueryIdParam) {
133
+ static _getSchemaApiMethodParams(hasQueryIdParam) {
134
+ if (hasQueryIdParam) {
132
135
  return [this._getSchemaApiMethodParamsQueryId()];
133
136
  }
134
- else if (hasResultData) {
135
- return [];
136
- }
137
- else if (hasQueryIdParam) {
138
- return [this._getSchemaApiMethodParamsQueryId(), this._getSchemaApiMethodParamsBody(tableName)];
139
- }
140
137
  else {
141
- return [this._getSchemaApiMethodParamsBody(tableName)];
138
+ return [];
142
139
  }
143
140
  }
144
141
  static _getSchemaApiMethod(method, tableName, hasQueryIdParam, hasBody, hasResultData) {
145
- return {
142
+ const result = {
146
143
  responses: {
147
144
  200: { description: this._getSchemaApiMethodDescription(method, tableName, hasQueryIdParam), content: { "application/json": { schema: this._getSchemaType(tableName, hasQueryIdParam, hasResultData) } } }
148
145
  },
149
146
  "operationId": this._getSchemaApiMethodOperationId(method, tableName, hasQueryIdParam),
150
- "parameters": this._getSchemaApiMethodParams(tableName, hasQueryIdParam, hasResultData)
147
+ "parameters": this._getSchemaApiMethodParams(hasQueryIdParam)
151
148
  };
149
+ if (hasBody) {
150
+ result["requestBody"] = this._getSchemaApiMethodParamsBody(tableName);
151
+ }
152
+ return result;
152
153
  }
153
154
  static _getSwaggerApiPath(tableName, hasQueryIdParam) {
154
155
  if (hasQueryIdParam) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oino-ts/db",
3
- "version": "0.4.3",
3
+ "version": "0.4.5",
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.3"
22
+ "@oino-ts/common": "0.4.5"
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.3",
27
+ "@oino-ts/types": "0.4.5",
28
28
  "typedoc": "^0.25.13"
29
29
  },
30
30
  "files": [
package/src/OINODbApi.ts CHANGED
@@ -62,7 +62,7 @@ export class OINODbApiResult extends OINOResult {
62
62
  */
63
63
  export class OINODbHtmlTemplate extends OINOHtmlTemplate {
64
64
  /** Locale validation regex */
65
- static LOCALE_REGEX:RegExp = /^(\w\w)(\-\w\w)?$/g
65
+ static LOCALE_REGEX:RegExp = /^(\w\w)(\-\w\w)?$/
66
66
  /** Locale formatter */
67
67
  protected _locale:Intl.DateTimeFormat|null
68
68
 
@@ -76,7 +76,6 @@ export class OINODbHtmlTemplate extends OINOHtmlTemplate {
76
76
  */
77
77
  constructor (template:string, dateLocaleStr?:string, dateLocaleStyle?:string|any) {
78
78
  super(template)
79
- console.log("OINODbHtmlTemplate.constructor", {dateLocaleStr:dateLocaleStr, dateLocaleStyle:dateLocaleStyle})
80
79
  let locale_opts:any
81
80
  if ((dateLocaleStyle == null) || (dateLocaleStyle == "")) {
82
81
  locale_opts = { dateStyle: "medium", timeStyle: "medium" }
@@ -246,7 +246,7 @@ export class OINODbDataModel {
246
246
  const groupby_sql = params.aggregate?.toSql(this, params.select) || ""
247
247
 
248
248
  let where_sql = ""
249
- // OINOLog.debug("OINODbDataModel.printSqlSelect", {order_sql:order_sql, limit_sql:limit_sql, filter_sql:filter_sql, aggregate_sql:aggregate_sql})
249
+ // OINOLog.debug("OINODbDataModel.printSqlSelect", {order_sql:order_sql, limit_sql:limit_sql, filter_sql:filter_sql, groupby_sql:groupby_sql})
250
250
  if ((id != null) && (id != "") && (filter_sql != "")) {
251
251
  where_sql = this._printSqlPrimaryKeyCondition(id) + " AND " + filter_sql
252
252
  } else if ((id != null) && (id != "")) {
@@ -255,7 +255,7 @@ export class OINODbDataModel {
255
255
  where_sql = filter_sql
256
256
  }
257
257
  const result = this.api.db.printSqlSelect(this.api.params.tableName, column_names, where_sql, order_sql, limit_sql, groupby_sql)
258
- OINOLog.debug("OINODbDataModel.printSqlSelect", {result:result})
258
+ // OINOLog.debug("OINODbDataModel.printSqlSelect", {result:result})
259
259
  return result;
260
260
  }
261
261
 
@@ -411,7 +411,7 @@ export class OINODbSqlAggregate {
411
411
  result += f.printSqlColumnName() + ","
412
412
  }
413
413
  }
414
- // OINOLog.debug("OINODbSqlAggregate.toSql", {result:result})
414
+ OINOLog.debug("OINODbSqlAggregate.toSql", {result:result})
415
415
  return result.substring(0, result.length-1)
416
416
  }
417
417
 
@@ -24,12 +24,15 @@ export class OINODbSwagger {
24
24
  }
25
25
 
26
26
  private static _getSchemaApiMethodParamsBody(tableName:string): any {
27
- return {
28
- "schema": {
29
- "$ref": "#/components/schemas/" + tableName
30
- },
31
- "in": "body",
32
- "required": true
27
+ return {
28
+ "required": true,
29
+ "content": {
30
+ "application/json": {
31
+ "schema": {
32
+ "$ref": "#/components/schemas/" + tableName
33
+ }
34
+ }
35
+ }
33
36
  }
34
37
  }
35
38
 
@@ -134,29 +137,26 @@ export class OINODbSwagger {
134
137
  }
135
138
  }
136
139
 
137
- private static _getSchemaApiMethodParams(tableName:string, hasQueryIdParam:boolean, hasResultData:boolean) {
138
- if (hasResultData && hasQueryIdParam) {
140
+ private static _getSchemaApiMethodParams(hasQueryIdParam:boolean) {
141
+ if (hasQueryIdParam) {
139
142
  return [ this._getSchemaApiMethodParamsQueryId() ]
140
-
141
- } else if (hasResultData) {
142
- return []
143
-
144
- } else if (hasQueryIdParam) {
145
- return [ this._getSchemaApiMethodParamsQueryId(), this._getSchemaApiMethodParamsBody(tableName) ]
146
-
147
143
  } else {
148
- return [ this._getSchemaApiMethodParamsBody(tableName) ]
144
+ return [ ]
149
145
  }
150
146
  }
151
147
 
152
148
  private static _getSchemaApiMethod(method:string, tableName:string, hasQueryIdParam:boolean, hasBody:boolean, hasResultData:boolean) {
153
- return {
149
+ const result:any = {
154
150
  responses: {
155
151
  200: { description: this._getSchemaApiMethodDescription(method, tableName, hasQueryIdParam), content: { "application/json": { schema: this._getSchemaType(tableName, hasQueryIdParam, hasResultData) } } }
156
152
  },
157
153
  "operationId": this._getSchemaApiMethodOperationId(method, tableName, hasQueryIdParam),
158
- "parameters": this._getSchemaApiMethodParams(tableName, hasQueryIdParam, hasResultData)
154
+ "parameters": this._getSchemaApiMethodParams(hasQueryIdParam)
159
155
  }
156
+ if (hasBody) {
157
+ result["requestBody"] = this._getSchemaApiMethodParamsBody(tableName)
158
+ }
159
+ return result
160
160
  }
161
161
 
162
162
  private static _getSwaggerApiPath(tableName:string, hasQueryIdParam:boolean):any {