@oino-ts/types 0.0.13 → 0.0.14

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.
@@ -26,21 +26,23 @@ class OINOBenchmark {
26
26
  /**
27
27
  * Set benchmark names that are enabled.
28
28
  *
29
- * @param names array of those benchmarks that are enabled
29
+ * @param module array of those benchmarks that are enabled
30
30
  */
31
- static setEnabled(names) {
31
+ static setEnabled(module) {
32
32
  this._benchmarkEnabled = {};
33
- names.forEach(name => {
34
- this._benchmarkEnabled[name] = true;
33
+ module.forEach(module_name => {
34
+ this._benchmarkEnabled[module_name] = true;
35
35
  });
36
36
  }
37
37
  /**
38
38
  * Start benchmark timing.
39
39
  *
40
- * @param name of the benchmark
40
+ * @param module of the benchmark
41
+ * @param method of the benchmark
41
42
  */
42
- static start(name) {
43
- if (this._benchmarkEnabled[name]) {
43
+ static start(module, method) {
44
+ const name = module + "." + method;
45
+ if (this._benchmarkEnabled[module]) {
44
46
  if (this._benchmarkCount[name] == undefined) {
45
47
  this._benchmarkCount[name] = 0;
46
48
  this._benchmarkData[name] = 0;
@@ -51,12 +53,14 @@ class OINOBenchmark {
51
53
  /**
52
54
  * Complete benchmark timing
53
55
  *
54
- * @param name of the benchmark
56
+ * @param module of the benchmark
57
+ * @param method of the benchmark
55
58
  * @param category optional subcategory of the benchmark
56
59
  */
57
- static end(name, category) {
60
+ static end(module, method, category) {
61
+ const name = module + "." + method;
58
62
  let result = 0;
59
- if (this._benchmarkEnabled[name]) {
63
+ if (this._benchmarkEnabled[module]) {
60
64
  const duration = performance.now() - this._benchmarkStart[name];
61
65
  this._benchmarkCount[name] += 1;
62
66
  this._benchmarkData[name] += duration;
@@ -76,11 +80,14 @@ class OINOBenchmark {
76
80
  /**
77
81
  * Get given benchmark data.
78
82
  *
79
- * @param name of the benchmark
83
+ * @param module of the benchmark
84
+ * @param method of the benchmark
85
+ *
80
86
  */
81
- static get(name) {
82
- if (this._benchmarkEnabled[name]) {
83
- return this._benchmarkData[name] / this._benchmarkCount[name];
87
+ static get(module, method) {
88
+ const name = module + "." + method;
89
+ if (this._benchmarkEnabled[module]) {
90
+ return this._benchmarkData[module] / this._benchmarkCount[module];
84
91
  }
85
92
  return -1;
86
93
  }
@@ -37,6 +37,7 @@ class OINOHtmlTemplate {
37
37
  *
38
38
  */
39
39
  renderFromKeyValue(key, value) {
40
+ _1.OINOBenchmark.start("OINOHtmlTemplate", "renderFromKeyValue");
40
41
  const html = this.template.replaceAll('###' + key + '###', _1.OINOStr.encode(value, _1.OINOContentType.html));
41
42
  const result = new _1.OINOHttpResult(html);
42
43
  if (this.expires >= 1) {
@@ -45,6 +46,7 @@ class OINOHtmlTemplate {
45
46
  if (this.modified >= 1) {
46
47
  result.lastModified = this.modified;
47
48
  }
49
+ _1.OINOBenchmark.end("OINOHtmlTemplate", "renderFromKeyValue");
48
50
  return result;
49
51
  }
50
52
  /**
@@ -54,6 +56,7 @@ class OINOHtmlTemplate {
54
56
  *
55
57
  */
56
58
  renderFromObject(object) {
59
+ _1.OINOBenchmark.start("OINOHtmlTemplate", "renderFromObject");
57
60
  let html = this.template;
58
61
  if (object) {
59
62
  for (let key in object) {
@@ -71,6 +74,7 @@ class OINOHtmlTemplate {
71
74
  if (this.modified >= 1) {
72
75
  result.lastModified = this.modified;
73
76
  }
77
+ _1.OINOBenchmark.end("OINOHtmlTemplate", "renderFromObject");
74
78
  return result;
75
79
  }
76
80
  /**
@@ -84,6 +88,7 @@ class OINOHtmlTemplate {
84
88
  *
85
89
  */
86
90
  renderFromResult(result, includeErrorMessages = false, includeWarningMessages = false, includeInfoMessages = false, includeDebugMessages = false) {
91
+ _1.OINOBenchmark.start("OINOHtmlTemplate", "renderFromResult");
87
92
  let html = this.template;
88
93
  html = html.replaceAll('###statusCode###', _1.OINOStr.encode(result.statusCode.toString(), _1.OINOContentType.html));
89
94
  html = html.replaceAll('###statusMessage###', _1.OINOStr.encode(result.statusMessage.toString(), _1.OINOContentType.html));
@@ -113,6 +118,7 @@ class OINOHtmlTemplate {
113
118
  if (this.modified >= 1) {
114
119
  http_result.lastModified = this.modified;
115
120
  }
121
+ _1.OINOBenchmark.end("OINOHtmlTemplate", "renderFromResult");
116
122
  return http_result;
117
123
  }
118
124
  }
package/dist/cjs/index.js CHANGED
@@ -22,7 +22,9 @@ exports.OINO_WARNING_PREFIX = "OINO WARNING";
22
22
  exports.OINO_INFO_PREFIX = "OINO INFO";
23
23
  /** OINO debug message prefix */
24
24
  exports.OINO_DEBUG_PREFIX = "OINO DEBUG";
25
- /** Supported content format mime-types */
25
+ /**
26
+ * Supported content format mime-types
27
+ */
26
28
  var OINOContentType;
27
29
  (function (OINOContentType) {
28
30
  /** JSON encoded data */
@@ -23,21 +23,23 @@ export class OINOBenchmark {
23
23
  /**
24
24
  * Set benchmark names that are enabled.
25
25
  *
26
- * @param names array of those benchmarks that are enabled
26
+ * @param module array of those benchmarks that are enabled
27
27
  */
28
- static setEnabled(names) {
28
+ static setEnabled(module) {
29
29
  this._benchmarkEnabled = {};
30
- names.forEach(name => {
31
- this._benchmarkEnabled[name] = true;
30
+ module.forEach(module_name => {
31
+ this._benchmarkEnabled[module_name] = true;
32
32
  });
33
33
  }
34
34
  /**
35
35
  * Start benchmark timing.
36
36
  *
37
- * @param name of the benchmark
37
+ * @param module of the benchmark
38
+ * @param method of the benchmark
38
39
  */
39
- static start(name) {
40
- if (this._benchmarkEnabled[name]) {
40
+ static start(module, method) {
41
+ const name = module + "." + method;
42
+ if (this._benchmarkEnabled[module]) {
41
43
  if (this._benchmarkCount[name] == undefined) {
42
44
  this._benchmarkCount[name] = 0;
43
45
  this._benchmarkData[name] = 0;
@@ -48,12 +50,14 @@ export class OINOBenchmark {
48
50
  /**
49
51
  * Complete benchmark timing
50
52
  *
51
- * @param name of the benchmark
53
+ * @param module of the benchmark
54
+ * @param method of the benchmark
52
55
  * @param category optional subcategory of the benchmark
53
56
  */
54
- static end(name, category) {
57
+ static end(module, method, category) {
58
+ const name = module + "." + method;
55
59
  let result = 0;
56
- if (this._benchmarkEnabled[name]) {
60
+ if (this._benchmarkEnabled[module]) {
57
61
  const duration = performance.now() - this._benchmarkStart[name];
58
62
  this._benchmarkCount[name] += 1;
59
63
  this._benchmarkData[name] += duration;
@@ -73,11 +77,14 @@ export class OINOBenchmark {
73
77
  /**
74
78
  * Get given benchmark data.
75
79
  *
76
- * @param name of the benchmark
80
+ * @param module of the benchmark
81
+ * @param method of the benchmark
82
+ *
77
83
  */
78
- static get(name) {
79
- if (this._benchmarkEnabled[name]) {
80
- return this._benchmarkData[name] / this._benchmarkCount[name];
84
+ static get(module, method) {
85
+ const name = module + "." + method;
86
+ if (this._benchmarkEnabled[module]) {
87
+ return this._benchmarkData[module] / this._benchmarkCount[module];
81
88
  }
82
89
  return -1;
83
90
  }
@@ -1,4 +1,4 @@
1
- import { OINOStr, OINOContentType, OINOHttpResult, OINO_ERROR_PREFIX, OINO_WARNING_PREFIX, OINO_INFO_PREFIX, OINO_DEBUG_PREFIX } from ".";
1
+ import { OINOStr, OINOContentType, OINOHttpResult, OINO_ERROR_PREFIX, OINO_WARNING_PREFIX, OINO_INFO_PREFIX, OINO_DEBUG_PREFIX, OINOBenchmark } from ".";
2
2
  /**
3
3
  * Class for rendering HTML from data.
4
4
  */
@@ -34,6 +34,7 @@ export class OINOHtmlTemplate {
34
34
  *
35
35
  */
36
36
  renderFromKeyValue(key, value) {
37
+ OINOBenchmark.start("OINOHtmlTemplate", "renderFromKeyValue");
37
38
  const html = this.template.replaceAll('###' + key + '###', OINOStr.encode(value, OINOContentType.html));
38
39
  const result = new OINOHttpResult(html);
39
40
  if (this.expires >= 1) {
@@ -42,6 +43,7 @@ export class OINOHtmlTemplate {
42
43
  if (this.modified >= 1) {
43
44
  result.lastModified = this.modified;
44
45
  }
46
+ OINOBenchmark.end("OINOHtmlTemplate", "renderFromKeyValue");
45
47
  return result;
46
48
  }
47
49
  /**
@@ -51,6 +53,7 @@ export class OINOHtmlTemplate {
51
53
  *
52
54
  */
53
55
  renderFromObject(object) {
56
+ OINOBenchmark.start("OINOHtmlTemplate", "renderFromObject");
54
57
  let html = this.template;
55
58
  if (object) {
56
59
  for (let key in object) {
@@ -68,6 +71,7 @@ export class OINOHtmlTemplate {
68
71
  if (this.modified >= 1) {
69
72
  result.lastModified = this.modified;
70
73
  }
74
+ OINOBenchmark.end("OINOHtmlTemplate", "renderFromObject");
71
75
  return result;
72
76
  }
73
77
  /**
@@ -81,6 +85,7 @@ export class OINOHtmlTemplate {
81
85
  *
82
86
  */
83
87
  renderFromResult(result, includeErrorMessages = false, includeWarningMessages = false, includeInfoMessages = false, includeDebugMessages = false) {
88
+ OINOBenchmark.start("OINOHtmlTemplate", "renderFromResult");
84
89
  let html = this.template;
85
90
  html = html.replaceAll('###statusCode###', OINOStr.encode(result.statusCode.toString(), OINOContentType.html));
86
91
  html = html.replaceAll('###statusMessage###', OINOStr.encode(result.statusMessage.toString(), OINOContentType.html));
@@ -110,6 +115,7 @@ export class OINOHtmlTemplate {
110
115
  if (this.modified >= 1) {
111
116
  http_result.lastModified = this.modified;
112
117
  }
118
+ OINOBenchmark.end("OINOHtmlTemplate", "renderFromResult");
113
119
  return http_result;
114
120
  }
115
121
  }
package/dist/esm/index.js CHANGED
@@ -11,7 +11,9 @@ export const OINO_WARNING_PREFIX = "OINO WARNING";
11
11
  export const OINO_INFO_PREFIX = "OINO INFO";
12
12
  /** OINO debug message prefix */
13
13
  export const OINO_DEBUG_PREFIX = "OINO DEBUG";
14
- /** Supported content format mime-types */
14
+ /**
15
+ * Supported content format mime-types
16
+ */
15
17
  export var OINOContentType;
16
18
  (function (OINOContentType) {
17
19
  /** JSON encoded data */
@@ -15,28 +15,32 @@ export declare class OINOBenchmark {
15
15
  /**
16
16
  * Set benchmark names that are enabled.
17
17
  *
18
- * @param names array of those benchmarks that are enabled
18
+ * @param module array of those benchmarks that are enabled
19
19
  */
20
- static setEnabled(names: string[]): void;
20
+ static setEnabled(module: string[]): void;
21
21
  /**
22
22
  * Start benchmark timing.
23
23
  *
24
- * @param name of the benchmark
24
+ * @param module of the benchmark
25
+ * @param method of the benchmark
25
26
  */
26
- static start(name: string): void;
27
+ static start(module: string, method: string): void;
27
28
  /**
28
29
  * Complete benchmark timing
29
30
  *
30
- * @param name of the benchmark
31
+ * @param module of the benchmark
32
+ * @param method of the benchmark
31
33
  * @param category optional subcategory of the benchmark
32
34
  */
33
- static end(name: string, category?: string): number;
35
+ static end(module: string, method: string, category?: string): number;
34
36
  /**
35
37
  * Get given benchmark data.
36
38
  *
37
- * @param name of the benchmark
39
+ * @param module of the benchmark
40
+ * @param method of the benchmark
41
+ *
38
42
  */
39
- static get(name: string): number;
43
+ static get(module: string, method: string): number;
40
44
  /**
41
45
  * Get all benchmark data.
42
46
  *
@@ -11,7 +11,9 @@ export declare const OINO_WARNING_PREFIX = "OINO WARNING";
11
11
  export declare const OINO_INFO_PREFIX = "OINO INFO";
12
12
  /** OINO debug message prefix */
13
13
  export declare const OINO_DEBUG_PREFIX = "OINO DEBUG";
14
- /** Supported content format mime-types */
14
+ /**
15
+ * Supported content format mime-types
16
+ */
15
17
  export declare enum OINOContentType {
16
18
  /** JSON encoded data */
17
19
  json = "application/json",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oino-ts/types",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "OINO TS package for types.",
5
5
  "author": "Matias Kiviniemi (pragmatta)",
6
6
  "license": "MPL-2.0",
@@ -27,22 +27,24 @@ export class OINOBenchmark {
27
27
  /**
28
28
  * Set benchmark names that are enabled.
29
29
  *
30
- * @param names array of those benchmarks that are enabled
30
+ * @param module array of those benchmarks that are enabled
31
31
  */
32
- static setEnabled(names:string[]):void {
32
+ static setEnabled(module:string[]):void {
33
33
  this._benchmarkEnabled = {}
34
- names.forEach(name => {
35
- this._benchmarkEnabled[name] = true
34
+ module.forEach(module_name => {
35
+ this._benchmarkEnabled[module_name] = true
36
36
  });
37
37
  }
38
38
 
39
39
  /**
40
40
  * Start benchmark timing.
41
41
  *
42
- * @param name of the benchmark
42
+ * @param module of the benchmark
43
+ * @param method of the benchmark
43
44
  */
44
- static start(name:string):void {
45
- if (this._benchmarkEnabled[name]) {
45
+ static start(module:string, method:string):void {
46
+ const name:string = module + "." + method
47
+ if (this._benchmarkEnabled[module]) {
46
48
  if (this._benchmarkCount[name] == undefined) {
47
49
  this._benchmarkCount[name] = 0
48
50
  this._benchmarkData[name] = 0
@@ -54,12 +56,14 @@ export class OINOBenchmark {
54
56
  /**
55
57
  * Complete benchmark timing
56
58
  *
57
- * @param name of the benchmark
59
+ * @param module of the benchmark
60
+ * @param method of the benchmark
58
61
  * @param category optional subcategory of the benchmark
59
62
  */
60
- static end(name:string, category?:string):number {
63
+ static end(module:string, method:string, category?:string):number {
64
+ const name:string = module + "." + method
61
65
  let result:number = 0
62
- if (this._benchmarkEnabled[name]) {
66
+ if (this._benchmarkEnabled[module]) {
63
67
  const duration = performance.now() - this._benchmarkStart[name]
64
68
  this._benchmarkCount[name] += 1
65
69
  this._benchmarkData[name] += duration
@@ -80,11 +84,14 @@ export class OINOBenchmark {
80
84
  /**
81
85
  * Get given benchmark data.
82
86
  *
83
- * @param name of the benchmark
87
+ * @param module of the benchmark
88
+ * @param method of the benchmark
89
+ *
84
90
  */
85
- static get(name:string):number {
86
- if (this._benchmarkEnabled[name]) {
87
- return this._benchmarkData[name] / this._benchmarkCount[name]
91
+ static get(module:string, method:string):number {
92
+ const name:string = module + "." + method
93
+ if (this._benchmarkEnabled[module]) {
94
+ return this._benchmarkData[module] / this._benchmarkCount[module]
88
95
  }
89
96
  return -1
90
97
  }
@@ -1,4 +1,4 @@
1
- import { OINOStr, OINOContentType, OINOResult, OINOHttpResult, OINO_ERROR_PREFIX, OINO_WARNING_PREFIX, OINO_INFO_PREFIX, OINO_DEBUG_PREFIX } from "."
1
+ import { OINOStr, OINOContentType, OINOResult, OINOHttpResult, OINO_ERROR_PREFIX, OINO_WARNING_PREFIX, OINO_INFO_PREFIX, OINO_DEBUG_PREFIX, OINOBenchmark } from "."
2
2
 
3
3
  /**
4
4
  * Class for rendering HTML from data.
@@ -40,6 +40,7 @@ export class OINOHtmlTemplate {
40
40
  *
41
41
  */
42
42
  renderFromKeyValue(key:string, value:string):OINOHttpResult {
43
+ OINOBenchmark.start("OINOHtmlTemplate", "renderFromKeyValue")
43
44
  const html:string = this.template.replaceAll('###' + key + '###', OINOStr.encode(value, OINOContentType.html))
44
45
  const result:OINOHttpResult = new OINOHttpResult(html)
45
46
  if (this.expires >= 1) {
@@ -48,6 +49,7 @@ export class OINOHtmlTemplate {
48
49
  if (this.modified >= 1) {
49
50
  result.lastModified = this.modified
50
51
  }
52
+ OINOBenchmark.end("OINOHtmlTemplate", "renderFromKeyValue")
51
53
  return result
52
54
  }
53
55
 
@@ -58,6 +60,7 @@ export class OINOHtmlTemplate {
58
60
  *
59
61
  */
60
62
  renderFromObject(object:any):OINOHttpResult {
63
+ OINOBenchmark.start("OINOHtmlTemplate", "renderFromObject")
61
64
  let html:string = this.template
62
65
  if (object) {
63
66
  for (let key in object) {
@@ -75,6 +78,7 @@ export class OINOHtmlTemplate {
75
78
  if (this.modified >= 1) {
76
79
  result.lastModified = this.modified
77
80
  }
81
+ OINOBenchmark.end("OINOHtmlTemplate", "renderFromObject")
78
82
  return result
79
83
  }
80
84
 
@@ -89,6 +93,7 @@ export class OINOHtmlTemplate {
89
93
  *
90
94
  */
91
95
  renderFromResult(result:OINOResult, includeErrorMessages:boolean=false, includeWarningMessages:boolean=false, includeInfoMessages:boolean=false, includeDebugMessages:boolean=false):OINOHttpResult {
96
+ OINOBenchmark.start("OINOHtmlTemplate", "renderFromResult")
92
97
  let html:string = this.template
93
98
  html = html.replaceAll('###statusCode###', OINOStr.encode(result.statusCode.toString(), OINOContentType.html))
94
99
  html = html.replaceAll('###statusMessage###', OINOStr.encode(result.statusMessage.toString(), OINOContentType.html))
@@ -119,6 +124,7 @@ export class OINOHtmlTemplate {
119
124
  if (this.modified >= 1) {
120
125
  http_result.lastModified = this.modified
121
126
  }
127
+ OINOBenchmark.end("OINOHtmlTemplate", "renderFromResult")
122
128
  return http_result
123
129
  }
124
130
  };
package/src/index.ts CHANGED
@@ -13,7 +13,9 @@ export const OINO_INFO_PREFIX = "OINO INFO"
13
13
  /** OINO debug message prefix */
14
14
  export const OINO_DEBUG_PREFIX = "OINO DEBUG"
15
15
 
16
- /** Supported content format mime-types */
16
+ /**
17
+ * Supported content format mime-types
18
+ */
17
19
  export enum OINOContentType {
18
20
  /** JSON encoded data */
19
21
  json='application/json',