@oino-ts/db 0.10.2 → 0.10.3
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.
- package/dist/cjs/OINODbApi.js +8 -2
- package/dist/esm/OINODbApi.js +8 -2
- package/dist/types/OINODbApi.d.ts +3 -1
- package/package.json +3 -3
- package/src/OINODbApi.test.ts +1 -1
- package/src/OINODbApi.ts +10 -3
package/dist/cjs/OINODbApi.js
CHANGED
|
@@ -63,15 +63,17 @@ class OINODbHtmlTemplate extends index_js_1.OINOHtmlTemplate {
|
|
|
63
63
|
static LOCALE_REGEX = /^(\w\w)(\-\w\w)?$/;
|
|
64
64
|
/** Locale formatter */
|
|
65
65
|
_locale;
|
|
66
|
+
_numberOfDecimals = -1;
|
|
66
67
|
/**
|
|
67
68
|
* Constructor of OINODbHtmlTemplate.
|
|
68
69
|
*
|
|
69
70
|
* @param template HTML template string
|
|
71
|
+
* @param numberOfDecimals Number of decimals to use for numbers, -1 for no formatting
|
|
70
72
|
* @param dateLocaleStr Datetime format string, either "iso" for ISO8601 or "default" for system default or valid locale string
|
|
71
73
|
* @param dateLocaleStyle Datetime format style, either "short/medium/long/full" or Intl.DateTimeFormat options
|
|
72
74
|
*
|
|
73
75
|
*/
|
|
74
|
-
constructor(template, dateLocaleStr, dateLocaleStyle) {
|
|
76
|
+
constructor(template, numberOfDecimals = -1, dateLocaleStr = "", dateLocaleStyle = "") {
|
|
75
77
|
super(template);
|
|
76
78
|
let locale_opts;
|
|
77
79
|
if ((dateLocaleStyle == null) || (dateLocaleStyle == "")) {
|
|
@@ -84,6 +86,7 @@ class OINODbHtmlTemplate extends index_js_1.OINOHtmlTemplate {
|
|
|
84
86
|
locale_opts = dateLocaleStyle;
|
|
85
87
|
}
|
|
86
88
|
this._locale = null;
|
|
89
|
+
this._numberOfDecimals = numberOfDecimals;
|
|
87
90
|
if ((dateLocaleStr != null) && (dateLocaleStr != "") && OINODbHtmlTemplate.LOCALE_REGEX.test(dateLocaleStr)) {
|
|
88
91
|
try {
|
|
89
92
|
this._locale = new Intl.DateTimeFormat(dateLocaleStr, locale_opts);
|
|
@@ -118,9 +121,12 @@ class OINODbHtmlTemplate extends index_js_1.OINOHtmlTemplate {
|
|
|
118
121
|
for (let i = 0; i < datamodel.fields.length; i++) {
|
|
119
122
|
const f = datamodel.fields[i];
|
|
120
123
|
let value;
|
|
121
|
-
if ((
|
|
124
|
+
if ((f instanceof index_js_1.OINODatetimeDataField) && (this._locale != null)) {
|
|
122
125
|
value = f.serializeCellWithLocale(row[i], this._locale);
|
|
123
126
|
}
|
|
127
|
+
else if ((f instanceof index_js_1.OINONumberDataField) && (this._numberOfDecimals >= 0) && (typeof row[i] === "number")) {
|
|
128
|
+
value = row[i].toFixed(this._numberOfDecimals);
|
|
129
|
+
}
|
|
124
130
|
else {
|
|
125
131
|
value = f.serializeCell(row[i]);
|
|
126
132
|
}
|
package/dist/esm/OINODbApi.js
CHANGED
|
@@ -59,15 +59,17 @@ export class OINODbHtmlTemplate extends OINOHtmlTemplate {
|
|
|
59
59
|
static LOCALE_REGEX = /^(\w\w)(\-\w\w)?$/;
|
|
60
60
|
/** Locale formatter */
|
|
61
61
|
_locale;
|
|
62
|
+
_numberOfDecimals = -1;
|
|
62
63
|
/**
|
|
63
64
|
* Constructor of OINODbHtmlTemplate.
|
|
64
65
|
*
|
|
65
66
|
* @param template HTML template string
|
|
67
|
+
* @param numberOfDecimals Number of decimals to use for numbers, -1 for no formatting
|
|
66
68
|
* @param dateLocaleStr Datetime format string, either "iso" for ISO8601 or "default" for system default or valid locale string
|
|
67
69
|
* @param dateLocaleStyle Datetime format style, either "short/medium/long/full" or Intl.DateTimeFormat options
|
|
68
70
|
*
|
|
69
71
|
*/
|
|
70
|
-
constructor(template, dateLocaleStr, dateLocaleStyle) {
|
|
72
|
+
constructor(template, numberOfDecimals = -1, dateLocaleStr = "", dateLocaleStyle = "") {
|
|
71
73
|
super(template);
|
|
72
74
|
let locale_opts;
|
|
73
75
|
if ((dateLocaleStyle == null) || (dateLocaleStyle == "")) {
|
|
@@ -80,6 +82,7 @@ export class OINODbHtmlTemplate extends OINOHtmlTemplate {
|
|
|
80
82
|
locale_opts = dateLocaleStyle;
|
|
81
83
|
}
|
|
82
84
|
this._locale = null;
|
|
85
|
+
this._numberOfDecimals = numberOfDecimals;
|
|
83
86
|
if ((dateLocaleStr != null) && (dateLocaleStr != "") && OINODbHtmlTemplate.LOCALE_REGEX.test(dateLocaleStr)) {
|
|
84
87
|
try {
|
|
85
88
|
this._locale = new Intl.DateTimeFormat(dateLocaleStr, locale_opts);
|
|
@@ -114,9 +117,12 @@ export class OINODbHtmlTemplate extends OINOHtmlTemplate {
|
|
|
114
117
|
for (let i = 0; i < datamodel.fields.length; i++) {
|
|
115
118
|
const f = datamodel.fields[i];
|
|
116
119
|
let value;
|
|
117
|
-
if ((
|
|
120
|
+
if ((f instanceof OINODatetimeDataField) && (this._locale != null)) {
|
|
118
121
|
value = f.serializeCellWithLocale(row[i], this._locale);
|
|
119
122
|
}
|
|
123
|
+
else if ((f instanceof OINONumberDataField) && (this._numberOfDecimals >= 0) && (typeof row[i] === "number")) {
|
|
124
|
+
value = row[i].toFixed(this._numberOfDecimals);
|
|
125
|
+
}
|
|
120
126
|
else {
|
|
121
127
|
value = f.serializeCell(row[i]);
|
|
122
128
|
}
|
|
@@ -38,15 +38,17 @@ export declare class OINODbHtmlTemplate extends OINOHtmlTemplate {
|
|
|
38
38
|
static LOCALE_REGEX: RegExp;
|
|
39
39
|
/** Locale formatter */
|
|
40
40
|
protected _locale: Intl.DateTimeFormat | null;
|
|
41
|
+
protected _numberOfDecimals: number;
|
|
41
42
|
/**
|
|
42
43
|
* Constructor of OINODbHtmlTemplate.
|
|
43
44
|
*
|
|
44
45
|
* @param template HTML template string
|
|
46
|
+
* @param numberOfDecimals Number of decimals to use for numbers, -1 for no formatting
|
|
45
47
|
* @param dateLocaleStr Datetime format string, either "iso" for ISO8601 or "default" for system default or valid locale string
|
|
46
48
|
* @param dateLocaleStyle Datetime format style, either "short/medium/long/full" or Intl.DateTimeFormat options
|
|
47
49
|
*
|
|
48
50
|
*/
|
|
49
|
-
constructor(template: string, dateLocaleStr?: string, dateLocaleStyle?: string | any);
|
|
51
|
+
constructor(template: string, numberOfDecimals?: number, dateLocaleStr?: string, dateLocaleStyle?: string | any);
|
|
50
52
|
/**
|
|
51
53
|
* Creates HTML Response from API modelset.
|
|
52
54
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oino-ts/db",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.3",
|
|
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.10.
|
|
22
|
+
"@oino-ts/common": "0.10.3"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/node": "^20.14.10",
|
|
26
26
|
"@types/bun": "^1.1.14",
|
|
27
|
-
"@oino-ts/types": "0.10.
|
|
27
|
+
"@oino-ts/types": "0.10.3",
|
|
28
28
|
"typedoc": "^0.25.13"
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
package/src/OINODbApi.test.ts
CHANGED
|
@@ -153,7 +153,7 @@ function createApiTemplate(api:OINODbApi):OINODbHtmlTemplate {
|
|
|
153
153
|
for (let i=0; i<api.datamodel.fields.length; i++) {
|
|
154
154
|
template_str += "<input type='text' name='" + api.datamodel.fields[i].name + "' value='###" + api.datamodel.fields[i].name + "###'></input>"
|
|
155
155
|
}
|
|
156
|
-
return new OINODbHtmlTemplate(template_str, "fi", "medium")
|
|
156
|
+
return new OINODbHtmlTemplate(template_str, -1, "fi", "medium")
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
export async function OINOTestApi(dbParams:OINODbParams, testParams: OINOTestParams) {
|
package/src/OINODbApi.ts
CHANGED
|
@@ -65,16 +65,18 @@ export class OINODbHtmlTemplate extends OINOHtmlTemplate {
|
|
|
65
65
|
static LOCALE_REGEX:RegExp = /^(\w\w)(\-\w\w)?$/
|
|
66
66
|
/** Locale formatter */
|
|
67
67
|
protected _locale:Intl.DateTimeFormat|null
|
|
68
|
+
protected _numberOfDecimals:number = -1
|
|
68
69
|
|
|
69
70
|
/**
|
|
70
71
|
* Constructor of OINODbHtmlTemplate.
|
|
71
72
|
*
|
|
72
73
|
* @param template HTML template string
|
|
74
|
+
* @param numberOfDecimals Number of decimals to use for numbers, -1 for no formatting
|
|
73
75
|
* @param dateLocaleStr Datetime format string, either "iso" for ISO8601 or "default" for system default or valid locale string
|
|
74
76
|
* @param dateLocaleStyle Datetime format style, either "short/medium/long/full" or Intl.DateTimeFormat options
|
|
75
77
|
*
|
|
76
78
|
*/
|
|
77
|
-
constructor (template:string, dateLocaleStr
|
|
79
|
+
constructor (template:string, numberOfDecimals:number=-1, dateLocaleStr:string="", dateLocaleStyle:string|any="") {
|
|
78
80
|
super(template)
|
|
79
81
|
let locale_opts:any
|
|
80
82
|
if ((dateLocaleStyle == null) || (dateLocaleStyle == "")) {
|
|
@@ -85,6 +87,7 @@ export class OINODbHtmlTemplate extends OINOHtmlTemplate {
|
|
|
85
87
|
locale_opts = dateLocaleStyle
|
|
86
88
|
}
|
|
87
89
|
this._locale = null
|
|
90
|
+
this._numberOfDecimals = numberOfDecimals
|
|
88
91
|
|
|
89
92
|
if ((dateLocaleStr != null) && (dateLocaleStr != "") && OINODbHtmlTemplate.LOCALE_REGEX.test(dateLocaleStr)) {
|
|
90
93
|
try {
|
|
@@ -120,9 +123,13 @@ export class OINODbHtmlTemplate extends OINOHtmlTemplate {
|
|
|
120
123
|
this.setVariableFromValue(OINODbConfig.OINODB_ID_FIELD, "")
|
|
121
124
|
for (let i=0; i<datamodel.fields.length; i++) {
|
|
122
125
|
const f:OINODbDataField = datamodel.fields[i]
|
|
123
|
-
let value:string|null|undefined
|
|
124
|
-
if ((
|
|
126
|
+
let value:string|null|undefined
|
|
127
|
+
if ((f instanceof OINODatetimeDataField) && (this._locale != null)) {
|
|
125
128
|
value = f.serializeCellWithLocale(row[i], this._locale)
|
|
129
|
+
|
|
130
|
+
} else if ((f instanceof OINONumberDataField) && (this._numberOfDecimals >= 0) && (typeof row[i] === "number")) {
|
|
131
|
+
value = (row[i]! as number).toFixed(this._numberOfDecimals)
|
|
132
|
+
|
|
126
133
|
} else {
|
|
127
134
|
value = f.serializeCell(row[i])
|
|
128
135
|
}
|