@oino-ts/types 0.0.17 → 0.1.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.
Files changed (50) hide show
  1. package/db/src/OINODb.d.ts +180 -0
  2. package/db/src/OINODbApi.d.ts +82 -0
  3. package/db/src/OINODbConfig.d.ts +52 -0
  4. package/db/src/OINODbDataField.d.ts +202 -0
  5. package/db/src/OINODbDataModel.d.ts +108 -0
  6. package/db/src/OINODbDataSet.d.ts +95 -0
  7. package/db/src/OINODbFactory.d.ts +35 -0
  8. package/db/src/OINODbModelSet.d.ts +51 -0
  9. package/db/src/OINODbParser.d.ts +53 -0
  10. package/db/src/OINODbRequestParams.d.ts +146 -0
  11. package/db/src/OINODbSqlParams.d.ts +147 -0
  12. package/db/src/OINODbSwagger.d.ts +25 -0
  13. package/db/src/index.d.ts +111 -0
  14. package/db-bunsqlite/src/OINODbBunSqlite.d.ts +77 -0
  15. package/db-bunsqlite/src/index.d.ts +1 -0
  16. package/db-mariadb/src/OINODbMariadb.d.ts +78 -0
  17. package/db-mariadb/src/index.d.ts +1 -0
  18. package/db-mssql/src/OINODbMsSql.d.ts +86 -0
  19. package/db-mssql/src/index.d.ts +1 -0
  20. package/db-postgresql/src/OINODbPostgresql.d.ts +76 -0
  21. package/db-postgresql/src/index.d.ts +1 -0
  22. package/hashid/src/OINOHashid.d.ts +40 -0
  23. package/hashid/src/index.d.ts +1 -0
  24. package/index.d.ts +23 -0
  25. package/package.json +5 -8
  26. package/README.md +0 -193
  27. package/dist/cjs/OINOBenchmark.js +0 -108
  28. package/dist/cjs/OINOHtmlTemplate.js +0 -177
  29. package/dist/cjs/OINOLog.js +0 -140
  30. package/dist/cjs/OINOResult.js +0 -216
  31. package/dist/cjs/OINOStr.js +0 -265
  32. package/dist/cjs/index.js +0 -40
  33. package/dist/esm/OINOBenchmark.js +0 -104
  34. package/dist/esm/OINOHtmlTemplate.js +0 -173
  35. package/dist/esm/OINOLog.js +0 -135
  36. package/dist/esm/OINOResult.js +0 -211
  37. package/dist/esm/OINOStr.js +0 -261
  38. package/dist/esm/index.js +0 -29
  39. package/src/OINOBenchmark.ts +0 -112
  40. package/src/OINOHtmlTemplate.ts +0 -186
  41. package/src/OINOLog.ts +0 -160
  42. package/src/OINOResult.ts +0 -234
  43. package/src/OINOStr.ts +0 -254
  44. package/src/index.ts +0 -31
  45. /package/{dist/types → common/src}/OINOBenchmark.d.ts +0 -0
  46. /package/{dist/types → common/src}/OINOHtmlTemplate.d.ts +0 -0
  47. /package/{dist/types → common/src}/OINOLog.d.ts +0 -0
  48. /package/{dist/types → common/src}/OINOResult.d.ts +0 -0
  49. /package/{dist/types → common/src}/OINOStr.d.ts +0 -0
  50. /package/{dist/types → common/src}/index.d.ts +0 -0
@@ -1,135 +0,0 @@
1
- /*
2
- * This Source Code Form is subject to the terms of the Mozilla Public
3
- * License, v. 2.0. If a copy of the MPL was not distributed with this
4
- * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
- */
6
- /** Logging levels */
7
- export var OINOLogLevel;
8
- (function (OINOLogLevel) {
9
- /** Debug messages */
10
- OINOLogLevel[OINOLogLevel["debug"] = 0] = "debug";
11
- /** Informational messages */
12
- OINOLogLevel[OINOLogLevel["info"] = 1] = "info";
13
- /** Warning messages */
14
- OINOLogLevel[OINOLogLevel["warn"] = 2] = "warn";
15
- /** Error messages */
16
- OINOLogLevel[OINOLogLevel["error"] = 3] = "error";
17
- })(OINOLogLevel || (OINOLogLevel = {}));
18
- /**
19
- * Abstract base class for logging implementations supporting
20
- * - error, warning, info and debug channels
21
- * - setting level of logs outputted
22
- *
23
- */
24
- export class OINOLog {
25
- static _instance;
26
- _logLevel = OINOLogLevel.warn;
27
- /**
28
- * Abstract logging method to implement the actual logging operation.
29
- *
30
- * @param logLevel level of the log events
31
- *
32
- */
33
- constructor(logLevel = OINOLogLevel.warn) {
34
- // console.log("OINOLog.constructor: logLevel=" + logLevel)
35
- this._logLevel = logLevel;
36
- }
37
- /**
38
- * Abstract logging method to implement the actual logging operation.
39
- *
40
- * @param level level of the log event
41
- * @param levelStr level string of the log event
42
- * @param message message of the log event
43
- * @param data structured data associated with the log event
44
- *
45
- */
46
- static _log(level, levelStr, message, data) {
47
- // console.log("_log: level=" + level + ", levelStr=" + levelStr + ", message=" + message + ", data=" + data)
48
- if ((OINOLog._instance) && (OINOLog._instance._logLevel <= level)) {
49
- OINOLog._instance?._writeLog(levelStr, message, data);
50
- }
51
- }
52
- /**
53
- * Set active logger and log level.
54
- *
55
- * @param logger logger instance
56
- *
57
- */
58
- static setLogger(logger) {
59
- // console.log("setLogger: " + log)
60
- if (logger) {
61
- OINOLog._instance = logger;
62
- }
63
- }
64
- /**
65
- * Set log level.
66
- *
67
- * @param logLevel log level to use
68
- *
69
- */
70
- static setLogLevel(logLevel) {
71
- if (OINOLog._instance) {
72
- OINOLog._instance._logLevel = logLevel;
73
- }
74
- }
75
- /**
76
- * Log error event.
77
- *
78
- * @param message message of the log event
79
- * @param data structured data associated with the log event
80
- *
81
- */
82
- static error(message, data) {
83
- OINOLog._log(OINOLogLevel.error, "ERROR", message, data);
84
- }
85
- /**
86
- * Log warning event.
87
- *
88
- * @param message message of the log event
89
- * @param data structured data associated with the log event
90
- *
91
- */
92
- static warning(message, data) {
93
- OINOLog._log(OINOLogLevel.warn, "WARN", message, data);
94
- }
95
- /**
96
- * Log info event.
97
- *
98
- * @param message message of the log event
99
- * @param data structured data associated with the log event
100
- *
101
- */
102
- static info(message, data) {
103
- OINOLog._log(OINOLogLevel.info, "INFO", message, data);
104
- }
105
- /**
106
- * Log debug event.
107
- *
108
- * @param message message of the log event
109
- * @param data structured data associated with the log event
110
- *
111
- */
112
- static debug(message, data) {
113
- OINOLog._log(OINOLogLevel.debug, "DEBUG", message, data);
114
- }
115
- }
116
- /**
117
- * Logging implementation based on console.log.
118
- *
119
- */
120
- export class OINOConsoleLog extends OINOLog {
121
- /**
122
- * Constructor of `OINOConsoleLog`
123
- * @param logLevel logging level
124
- */
125
- constructor(logLevel = OINOLogLevel.warn) {
126
- super(logLevel);
127
- }
128
- _writeLog(level, message, data) {
129
- let log = "OINOLog " + level + ": " + message;
130
- if (data) {
131
- log += " " + JSON.stringify(data);
132
- }
133
- console.log(log);
134
- }
135
- }
@@ -1,211 +0,0 @@
1
- /*
2
- * This Source Code Form is subject to the terms of the Mozilla Public
3
- * License, v. 2.0. If a copy of the MPL was not distributed with this
4
- * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
- */
6
- import { createHash } from "node:crypto";
7
- import { OINO_DEBUG_PREFIX, OINO_ERROR_PREFIX, OINO_INFO_PREFIX, OINO_WARNING_PREFIX } from ".";
8
- /**
9
- * OINO API request result object with returned data and/or http status code/message and
10
- * error / warning messages.
11
- *
12
- */
13
- export class OINOResult {
14
- /** Wheter request was successfully executed */
15
- success;
16
- /** HTTP status code */
17
- statusCode;
18
- /** HTTP status message */
19
- statusMessage;
20
- /** Error / warning messages */
21
- messages;
22
- /**
23
- * Constructor of OINOResult.
24
- *
25
- */
26
- constructor() {
27
- this.success = true;
28
- this.statusCode = 200;
29
- this.statusMessage = "OK";
30
- this.messages = [];
31
- }
32
- /**
33
- * Copy values from different result.
34
- *
35
- * @param result source value
36
- */
37
- copy(result) {
38
- this.success = result.success;
39
- this.statusCode = result.statusCode;
40
- this.statusMessage = result.statusMessage;
41
- this.messages = result.messages.slice();
42
- }
43
- /**
44
- * Set HTTP OK status (does not reset messages).
45
- *
46
- */
47
- setOk() {
48
- this.success = true;
49
- this.statusCode = 200;
50
- this.statusMessage = "OK";
51
- }
52
- /**
53
- * Set HTTP error status using given code and message. Returns self reference for chaining.
54
- *
55
- * @param statusCode HTTP status code
56
- * @param statusMessage HTTP status message
57
- * @param operation operation where error occured
58
- *
59
- */
60
- setError(statusCode, statusMessage, operation) {
61
- this.success = false;
62
- this.statusCode = statusCode;
63
- if (this.statusMessage != "OK") {
64
- this.messages.push(this.statusMessage); // latest error becomes status, but if there was something non-trivial, add it to the messages
65
- }
66
- if (statusMessage.startsWith(OINO_ERROR_PREFIX)) {
67
- this.statusMessage = statusMessage;
68
- }
69
- else {
70
- this.statusMessage = OINO_ERROR_PREFIX + " (" + operation + "): " + statusMessage;
71
- }
72
- return this;
73
- }
74
- /**
75
- * Add warning message. Returns self reference for chaining.
76
- *
77
- * @param message HTTP status message
78
- * @param operation operation where warning occured
79
- *
80
- */
81
- addWarning(message, operation) {
82
- message = message.trim();
83
- if (message) {
84
- this.messages.push(OINO_WARNING_PREFIX + " (" + operation + "): " + message);
85
- }
86
- return this;
87
- }
88
- /**
89
- * Add info message. Returns self reference for chaining.
90
- *
91
- * @param message HTTP status message
92
- * @param operation operation where info occured
93
- *
94
- */
95
- addInfo(message, operation) {
96
- message = message.trim();
97
- if (message) {
98
- this.messages.push(OINO_INFO_PREFIX + " (" + operation + "): " + message);
99
- }
100
- return this;
101
- }
102
- /**
103
- * Add debug message. Returns self reference for chaining.
104
- *
105
- * @param message HTTP status message
106
- * @param operation operation where debug occured
107
- *
108
- */
109
- addDebug(message, operation) {
110
- message = message.trim();
111
- if (message) {
112
- this.messages.push(OINO_DEBUG_PREFIX + " (" + operation + "): " + message);
113
- }
114
- return this;
115
- }
116
- /**
117
- * Copy given messages to HTTP headers.
118
- *
119
- * @param headers HTTP headers
120
- * @param copyErrors wether error messages should be copied (default true)
121
- * @param copyWarnings wether warning messages should be copied (default false)
122
- * @param copyInfos wether info messages should be copied (default false)
123
- * @param copyDebug wether debug messages should be copied (default false)
124
- *
125
- */
126
- copyMessagesToHeaders(headers, copyErrors = true, copyWarnings = false, copyInfos = false, copyDebug = false) {
127
- let j = 1;
128
- for (let i = 0; i < this.messages.length; i++) {
129
- const message = this.messages[i].replaceAll("\r", " ").replaceAll("\n", " ");
130
- if (copyErrors && message.startsWith(OINO_ERROR_PREFIX)) {
131
- headers.append('X-OINO-MESSAGE-' + j, message);
132
- j++;
133
- }
134
- if (copyWarnings && message.startsWith(OINO_WARNING_PREFIX)) {
135
- headers.append('X-OINO-MESSAGE-' + j, message);
136
- j++;
137
- }
138
- if (copyInfos && message.startsWith(OINO_INFO_PREFIX)) {
139
- headers.append('X-OINO-MESSAGE-' + j, message);
140
- j++;
141
- }
142
- if (copyDebug && message.startsWith(OINO_DEBUG_PREFIX)) {
143
- headers.append('X-OINO-MESSAGE-' + j, message);
144
- j++;
145
- }
146
- }
147
- }
148
- /**
149
- * Print result for logging.
150
- *
151
- */
152
- printLog() {
153
- return "OINOResult: statusCode=" + this.statusCode + ", statusMessage=" + this.statusMessage + ", messages=[" + this.messages.join(", ") + "]";
154
- }
155
- }
156
- /**
157
- * Specialized result for HTTP responses.
158
- */
159
- export class OINOHttpResult extends OINOResult {
160
- _etag;
161
- /** HTTP body data */
162
- body;
163
- /** HTTP cache expiration value */
164
- expires;
165
- /** HTTP cache last-modified value */
166
- lastModified;
167
- /**
168
- * Constructor for a `OINOHttpResult`
169
- *
170
- * @param body HTTP body
171
- *
172
- */
173
- constructor(body) {
174
- super();
175
- this.body = body;
176
- this.expires = 0;
177
- this.lastModified = 0;
178
- this._etag = "";
179
- }
180
- /**
181
- * Get the ETag value for the body opportunistically, i.e. don't calculate until requested and reuse value.
182
- *
183
- */
184
- getEtag() {
185
- if (this._etag == "") {
186
- const hash = createHash("sha256");
187
- this._etag = hash.update(this.body).digest("hex");
188
- }
189
- return this._etag;
190
- }
191
- /**
192
- * Get a Response object from the result values.
193
- *
194
- * @param headers HTTP headers (overrides existing values)
195
- */
196
- getResponse(headers) {
197
- const result = new Response(this.body, { status: this.statusCode, statusText: this.statusMessage, headers: headers });
198
- result.headers.set('Content-Length', this.body.length.toString());
199
- if (this.lastModified > 0) {
200
- result.headers.set('Last-Modified', new Date(this.lastModified).toUTCString());
201
- }
202
- if (this.expires >= 0) {
203
- result.headers.set('Expires', Math.round(this.expires).toString());
204
- if (this.expires == 0) {
205
- result.headers.set('Pragma', 'no-cache');
206
- }
207
- }
208
- result.headers.set("ETag", this.getEtag());
209
- return result;
210
- }
211
- }
@@ -1,261 +0,0 @@
1
- import { OINOContentType } from ".";
2
- /**
3
- * Static class string utilities.
4
- *
5
- */
6
- export class OINOStr {
7
- /**
8
- * Split string by the top level of the given type of brackets.
9
- * E.g. splitByBrackets("a(bc(d))ef(gh)kl", true, true, '(', ')') would return ["a", "bc(d)", "ef", "gh", "kl"]
10
- *
11
- * @param str string to split
12
- * @param includePartsBetweenBlocks whether to include strings between top level brackets
13
- * @param includeTrailingUnescapedBlock whether to include final block that is missing necessary end brackets
14
- * @param startBracket starting bracket, e.g. '('
15
- * @param endBracket ending bracket, e.g. ')'
16
- *
17
- */
18
- static splitByBrackets(str, includePartsBetweenBlocks, includeTrailingUnescapedBlock, startBracket, endBracket) {
19
- let result = [];
20
- let parenthesis_count = 0;
21
- let start = 0;
22
- let end = 0;
23
- while (end < str.length) {
24
- if (str[end] == startBracket) {
25
- if (parenthesis_count == 0) {
26
- if ((end > start) && includePartsBetweenBlocks) { // there is some first level string to add to result
27
- result.push(str.substring(start, end));
28
- }
29
- start = end + 1;
30
- }
31
- parenthesis_count++;
32
- }
33
- else if (str[end] == endBracket) {
34
- parenthesis_count--;
35
- if (parenthesis_count == 0) {
36
- if (end >= start) {
37
- result.push(str.substring(start, end));
38
- }
39
- start = end + 1;
40
- }
41
- }
42
- end++;
43
- }
44
- if ((end > start) && ((includePartsBetweenBlocks && (parenthesis_count == 0)) || (includeTrailingUnescapedBlock && (parenthesis_count > 0)))) { // if there is stuff after last block or unfinished block (and those are supported)
45
- result.push(str.substring(start, end)); // i == str.length
46
- }
47
- return result;
48
- }
49
- /**
50
- * Split string by delimeter excluding delimeters inside given brackets.
51
- * E.g. splitExcludingBrackets("a,(bc,d),ef,(g,h),k", ',', '(', ')') would return ["a", "bc,d", "ef", "g,h", "k"]
52
- *
53
- * @param str string to split
54
- * @param delimeter string to use as delimeter
55
- * @param startBracket starting bracket, e.g. '('
56
- * @param endBracket ending bracket, e.g. ')'
57
- */
58
- static splitExcludingBrackets(str, delimeter, startBracket, endBracket) {
59
- let result = [];
60
- let bracket_level = 0;
61
- let start = 0;
62
- let end = 0;
63
- while (end < str.length) {
64
- if (str[end] == startBracket) {
65
- bracket_level++;
66
- }
67
- else if (str[end] == endBracket) {
68
- bracket_level--;
69
- }
70
- else if ((str[end] == delimeter) && (bracket_level == 0)) { // only delimeters at top level will break
71
- result.push(str.substring(start, end));
72
- start = end + 1;
73
- }
74
- end++;
75
- }
76
- if (end > start) {
77
- result.push(str.substring(start, end)); // i == str.length
78
- }
79
- return result;
80
- }
81
- /**
82
- * Encode OINO serialized strings as valid JSON.
83
- *
84
- * @param str string to encode
85
- * @param valueType wether it is a value type
86
- */
87
- static encodeJSON(str, valueType = false) {
88
- if (str === undefined) { // no undefined literal in JSON
89
- return "null";
90
- }
91
- else if (str === null) {
92
- return "null";
93
- }
94
- else {
95
- if (valueType) {
96
- return str;
97
- }
98
- else {
99
- return JSON.stringify(str);
100
- }
101
- }
102
- }
103
- /**
104
- * Decode JSON string as OINO serialization.
105
- *
106
- * @param str string to decode
107
- */
108
- static decodeJSON(str) {
109
- return str; // JSON parsing using JS methods, no need to decode anything
110
- }
111
- /**
112
- * Encode OINO serialized strings as valid CSV.
113
- *
114
- * @param str string to encode
115
- */
116
- static encodeCSV(str) {
117
- if (str === undefined) {
118
- return "";
119
- }
120
- else if (str === null) {
121
- return "null";
122
- }
123
- else {
124
- return "\"" + str.replaceAll("\"", "\"\"") + "\"";
125
- }
126
- }
127
- /**
128
- * Decode CSV string as OINO serialization.
129
- *
130
- * @param str string to decode
131
- */
132
- static decodeCSV(str) {
133
- return str.replaceAll("\"\"", "\"");
134
- }
135
- /**
136
- * Encode OINO serialized strings as valid Formdata.
137
- *
138
- * @param str string to encode
139
- */
140
- static encodeFormdata(str) {
141
- if (str === undefined) {
142
- return "";
143
- }
144
- else if (str === null) {
145
- return "";
146
- }
147
- else {
148
- return str;
149
- }
150
- }
151
- /**
152
- * Decode Formdata string as OINO serialization.
153
- *
154
- * @param str string to decode
155
- */
156
- static decodeFormdata(str) {
157
- return str;
158
- }
159
- /**
160
- * Encode OINO serialized strings as valid Urlencode.
161
- *
162
- * @param str string to encode
163
- */
164
- static encodeUrlencode(str) {
165
- if (str === undefined) {
166
- return "";
167
- }
168
- else if (str === null) {
169
- return "null";
170
- }
171
- else {
172
- return encodeURIComponent(str);
173
- }
174
- }
175
- /**
176
- * Decode Urlencode string as OINO serialization.
177
- *
178
- * @param str string to decode
179
- */
180
- static decodeUrlencode(str) {
181
- return decodeURIComponent(str);
182
- }
183
- /**
184
- * Encode OINO serialized strings as valid HTML content.
185
- *
186
- * @param str string to encode
187
- */
188
- static encodeHtml(str) {
189
- if (str === undefined) {
190
- return "";
191
- }
192
- else if (str === null) {
193
- return "";
194
- }
195
- else {
196
- return str.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('"', '&quot;').replaceAll("'", '&#039;');
197
- }
198
- }
199
- /**
200
- * Decode HTML string as OINO serialization.
201
- *
202
- * @param str string to encode
203
- */
204
- static decodeHtml(str) {
205
- return str.replaceAll('&amp;', '&').replaceAll('&lt;', '<').replaceAll('&gt;', '>').replaceAll('&quot;', '"').replaceAll('&#039;', "'");
206
- }
207
- /**
208
- * Decode content type formatted string as OINO serialization.
209
- *
210
- * @param str string to decode
211
- * @param contentType content type for serialization
212
- *
213
- */
214
- static decode(str, contentType) {
215
- if (contentType == OINOContentType.csv) {
216
- return this.decodeCSV(str);
217
- }
218
- else if (contentType == OINOContentType.json) {
219
- return this.decodeJSON(str);
220
- }
221
- else if (contentType == OINOContentType.formdata) {
222
- return this.decodeFormdata(str);
223
- }
224
- else if (contentType == OINOContentType.urlencode) {
225
- return this.decodeUrlencode(str);
226
- }
227
- else if (contentType == OINOContentType.html) {
228
- return str;
229
- }
230
- else {
231
- return str;
232
- }
233
- }
234
- /**
235
- * Encode OINO serialized string to the content type formatting.
236
- *
237
- * @param str string to encode
238
- * @param contentType content type for serialization
239
- *
240
- */
241
- static encode(str, contentType) {
242
- if (contentType == OINOContentType.csv) {
243
- return this.encodeCSV(str);
244
- }
245
- else if (contentType == OINOContentType.json) {
246
- return this.encodeJSON(str);
247
- }
248
- else if (contentType == OINOContentType.formdata) {
249
- return this.encodeFormdata(str);
250
- }
251
- else if (contentType == OINOContentType.urlencode) {
252
- return this.encodeUrlencode(str);
253
- }
254
- else if (contentType == OINOContentType.html) {
255
- return this.encodeHtml(str);
256
- }
257
- else {
258
- return str || "";
259
- }
260
- }
261
- }
package/dist/esm/index.js DELETED
@@ -1,29 +0,0 @@
1
- export { OINOBenchmark } from "./OINOBenchmark.js";
2
- export { OINOLog, OINOLogLevel, OINOConsoleLog } from "./OINOLog.js";
3
- export { OINOResult, OINOHttpResult } from "./OINOResult.js";
4
- export { OINOStr } from "./OINOStr.js";
5
- export { OINOHtmlTemplate } from "./OINOHtmlTemplate.js";
6
- /** OINO error message prefix */
7
- export const OINO_ERROR_PREFIX = "OINO ERROR";
8
- /** OINO warning message prefix */
9
- export const OINO_WARNING_PREFIX = "OINO WARNING";
10
- /** OINO info message prefix */
11
- export const OINO_INFO_PREFIX = "OINO INFO";
12
- /** OINO debug message prefix */
13
- export const OINO_DEBUG_PREFIX = "OINO DEBUG";
14
- /**
15
- * Supported content format mime-types
16
- */
17
- export var OINOContentType;
18
- (function (OINOContentType) {
19
- /** JSON encoded data */
20
- OINOContentType["json"] = "application/json";
21
- /** CSV encoded data */
22
- OINOContentType["csv"] = "text/csv";
23
- /** Multipart encoded form data */
24
- OINOContentType["formdata"] = "multipart/form-data";
25
- /** URL encoded form data */
26
- OINOContentType["urlencode"] = "application/x-www-form-urlencoded";
27
- /** HTML encoded data (output only) */
28
- OINOContentType["html"] = "text/html";
29
- })(OINOContentType || (OINOContentType = {}));