@oino-ts/db 0.7.0 → 0.7.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.
@@ -97,8 +97,12 @@ class OINODbDataModel {
97
97
  if ((f instanceof index_js_1.OINONumberDataField) && (this.api.hashid)) {
98
98
  value = this.api.hashid.decode(value);
99
99
  }
100
+ value = f.printCellAsSqlValue(value);
101
+ if (value == "") { // ids are user input and could be specially crafted to be empty
102
+ throw new Error(index_js_1.OINO_ERROR_PREFIX + ": empty condition for id '" + id_value + "' for table " + this.api.params.tableName);
103
+ }
100
104
  // OINOLog.debug("OINODbDataModel._printSqlPrimaryKeyCondition", {field:f.name, value:value, id_value:id_value})
101
- result += f.printSqlColumnName() + "=" + f.printCellAsSqlValue(value);
105
+ result += f.printSqlColumnName() + "=" + value;
102
106
  i = i + 1;
103
107
  }
104
108
  }
@@ -28,6 +28,8 @@ class OINODbFactory {
28
28
  * Create database from parameters from the registered classes.
29
29
  *
30
30
  * @param params database connection parameters
31
+ * @param connect if true, connects to the database
32
+ * @param validate if true, validates the database connection
31
33
  */
32
34
  static async createDb(params, connect = true, validate = true) {
33
35
  let result;
@@ -94,8 +94,12 @@ export class OINODbDataModel {
94
94
  if ((f instanceof OINONumberDataField) && (this.api.hashid)) {
95
95
  value = this.api.hashid.decode(value);
96
96
  }
97
+ value = f.printCellAsSqlValue(value);
98
+ if (value == "") { // ids are user input and could be specially crafted to be empty
99
+ throw new Error(OINO_ERROR_PREFIX + ": empty condition for id '" + id_value + "' for table " + this.api.params.tableName);
100
+ }
97
101
  // OINOLog.debug("OINODbDataModel._printSqlPrimaryKeyCondition", {field:f.name, value:value, id_value:id_value})
98
- result += f.printSqlColumnName() + "=" + f.printCellAsSqlValue(value);
102
+ result += f.printSqlColumnName() + "=" + value;
99
103
  i = i + 1;
100
104
  }
101
105
  }
@@ -25,6 +25,8 @@ export class OINODbFactory {
25
25
  * Create database from parameters from the registered classes.
26
26
  *
27
27
  * @param params database connection parameters
28
+ * @param connect if true, connects to the database
29
+ * @param validate if true, validates the database connection
28
30
  */
29
31
  static async createDb(params, connect = true, validate = true) {
30
32
  let result;
@@ -1,3 +1,5 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import { OINODbApiParams, OINODb, OINODbDataModel, OINODataRow, OINODbModelSet, OINODbApiRequestParams, OINOHttpResult, OINOHtmlTemplate } from "./index.js";
2
4
  import { OINOResult } from "@oino-ts/common";
3
5
  import { OINOHashid } from "@oino-ts/hashid";
@@ -17,6 +17,8 @@ export declare class OINODbFactory {
17
17
  * Create database from parameters from the registered classes.
18
18
  *
19
19
  * @param params database connection parameters
20
+ * @param connect if true, connects to the database
21
+ * @param validate if true, validates the database connection
20
22
  */
21
23
  static createDb(params: OINODbParams, connect?: boolean, validate?: boolean): Promise<OINODb>;
22
24
  /**
@@ -1,3 +1,5 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import { OINODbDataModel, OINODataRow, OINODbApiRequestParams } from "./index.js";
2
4
  /**
3
5
  * Static factory class for easily creating things based on data
@@ -1,3 +1,5 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import { OINOContentType } from "@oino-ts/common";
2
4
  export { OINOContentType };
3
5
  export { OINO_ERROR_PREFIX, OINO_WARNING_PREFIX, OINO_INFO_PREFIX, OINO_DEBUG_PREFIX, OINOStr, OINOBenchmark, OINOLog, OINOLogLevel, OINOConsoleLog, OINOResult, OINOHttpResult, OINOHtmlTemplate } from "@oino-ts/common";
@@ -48,6 +50,7 @@ export type OINODbApiParams = {
48
50
  /**
49
51
  * Database class (constructor) type
50
52
  * @param dbParams database parameters
53
+ * @return OINODb instance
51
54
  */
52
55
  export type OINODbConstructor = new (dbParams: OINODbParams) => OINODb;
53
56
  /** Database parameters */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oino-ts/db",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
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.7.0"
22
+ "@oino-ts/common": "0.7.1"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/node": "^20.14.10",
26
26
  "@types/bun": "^1.1.14",
27
- "@oino-ts/types": "0.7.0",
27
+ "@oino-ts/types": "0.7.1",
28
28
  "typedoc": "^0.25.13"
29
29
  },
30
30
  "files": [
@@ -103,8 +103,12 @@ export class OINODbDataModel {
103
103
  if ((f instanceof OINONumberDataField) && (this.api.hashid)) {
104
104
  value = this.api.hashid.decode(value)
105
105
  }
106
+ value = f.printCellAsSqlValue(value)
107
+ if (value == "") { // ids are user input and could be specially crafted to be empty
108
+ throw new Error(OINO_ERROR_PREFIX + ": empty condition for id '" + id_value + "' for table " + this.api.params.tableName)
109
+ }
106
110
  // OINOLog.debug("OINODbDataModel._printSqlPrimaryKeyCondition", {field:f.name, value:value, id_value:id_value})
107
- result += f.printSqlColumnName() + "=" + f.printCellAsSqlValue(value);
111
+ result += f.printSqlColumnName() + "=" + value;
108
112
  i = i + 1
109
113
  }
110
114
  }
@@ -30,6 +30,8 @@ export class OINODbFactory {
30
30
  * Create database from parameters from the registered classes.
31
31
  *
32
32
  * @param params database connection parameters
33
+ * @param connect if true, connects to the database
34
+ * @param validate if true, validates the database connection
33
35
  */
34
36
  static async createDb(params:OINODbParams, connect:boolean = true, validate:boolean = true):Promise<OINODb> {
35
37
  let result:OINODb
package/src/index.ts CHANGED
@@ -53,6 +53,7 @@ export type OINODbApiParams = {
53
53
  /**
54
54
  * Database class (constructor) type
55
55
  * @param dbParams database parameters
56
+ * @return OINODb instance
56
57
  */
57
58
  export type OINODbConstructor = new (dbParams:OINODbParams) => OINODb
58
59