@oino-ts/types 0.0.11

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/README.md ADDED
@@ -0,0 +1,222 @@
1
+ # OINO TS
2
+ OINO Is Not an ORM but it's trying to solve a similar problem for API development. Instead of mirroring your DB schema in code that needs manual updates, OINO will get the data schema from DBMS using SQL in real time. Every time your app starts, it has an updated data model which enables automatic (de)serialize SQL results to JSON/CSV and back. OINO works on the level below routing where you pass the method, URL ID, body and request parameters to the API-object. OINO will parse and validate the data against the data model and generate proper SQL for your DB. Because OINO knows how data is serialized (e.g. JSON), what column it belongs to (e.g. floating point number) and what the target database is, it knows how to parse, format and escape the value as valid SQL.
3
+
4
+ ```
5
+ const result:OINOApiResult = await api_orderdetails.doRequest("GET", id, body, params)
6
+ return new Response(result.modelset.writeString(OINOContentType.json))
7
+ ```
8
+
9
+
10
+ # GETTING STARTED
11
+
12
+ ### Setup
13
+ Install the `@oino-ts/core` npm package and necessary database packages and import them in your code.
14
+ ```
15
+ bun install @oino-ts/core
16
+ bun install @oino-ts/bunsqlite
17
+ ```
18
+
19
+ ```
20
+ import { OINODb, OINOApi, OINOFactory } from "@oino-ts/core";
21
+ import { OINODbBunSqlite } from "@oino-ts/bunsqlite"
22
+ ```
23
+
24
+ ### Register database and logger
25
+ Register your database implementation and logger (see [`OINOConsoleLog`](https://pragmatta.github.io/oino-ts/classes/core_src.OINOConsoleLog.html) how to implement your own)
26
+
27
+ ```
28
+ OINOLog.setLogger(new OINOConsoleLog())
29
+ OINOFactory.registerDb("OINODbBunSqlite", OINODbBunSqlite)
30
+ ```
31
+
32
+ ### Create a database
33
+ Creating a database connection [`OINODb`](https://pragmatta.github.io/oino-ts/classes/core_src_OINODb.OINODb.html) is done by passing [`OINODbParams`](https://pragmatta.github.io/oino-ts/types/core_src.OINODbParams.html) to the factory method. For [`OINODbBunSqlite`](https://pragmatta.github.io/oino-ts/classes/bunsqlite_OINODbBunSqlite.OINODbBunSqlite.html) that means a file url for the database file, for others network host, port, credentials etc.
34
+ ```
35
+ const db:OINODb = await OINOFactory.createDb( { type: "OINODbBunSqlite", url: "file://../localDb/northwind.sqlite" } )
36
+ ```
37
+
38
+ ### Create an API
39
+ From a database you can create an [`OINOApi`](https://pragmatta.github.io/oino-ts/classes/core_src_OINOApi.OINOApi.html) by passing [`OINOApiParams`](https://pragmatta.github.io/oino-ts/types/core_src.OINOApiParams.html) with table name and preferences to the factory method.
40
+ ```
41
+ const api_employees:OINOApi = await OINOFactory.createApi(db, { tableName: "Employees", excludeFields:["BirthDate"] })
42
+ ```
43
+
44
+ ### Pass HTTP requests to API
45
+ When you receive a HTTP request, just pass the method, URL ID, body and params to the correct API, which will parse and validate input and return results.
46
+
47
+ ```
48
+ const result:OINOApiResult = await api_orderdetails.doRequest("GET", id, body, params)
49
+ ```
50
+
51
+ ### Write results back to HTTP Response
52
+ The results for a GET request will contain [`OINOModelSet`](https://pragmatta.github.io/oino-ts/classes/core_src_OINOModelSet.OINOModelSet.html) data that can be written out as JSON or CSV as needed. For other requests result is just success or error with messages.
53
+ ```
54
+ return new Response(result.modelset.writeString(OINOContentType.json))
55
+ ```
56
+
57
+
58
+ # FEATURES
59
+
60
+ ## RESTfull
61
+ OINO maps HTTP methods GET/POST/PUT/DELETE to SQL operations SELECT/INSERT/UPDATE/DELETE. The GET/POST requests can be made without URL ID to get all rows or insert new ones and others target a single row using URL ID.
62
+
63
+ ### HTTP GET
64
+ ```
65
+ Request and response:
66
+ > curl.exe -X GET http://localhost:3001/orderdetails/11077:77
67
+ [
68
+ {"_OINOID_":"11077:77","OrderID":11077,"ProductID":77,"UnitPrice":13,"Quantity":2,"Discount":0}
69
+ ]
70
+
71
+ SQL:
72
+ SELECT "OrderID","ProductID","UnitPrice","Quantity","Discount" FROM [OrderDetails] WHERE ("OrderID"=11077 AND "ProductID"=77);
73
+ ```
74
+
75
+ ### HTTP POST
76
+ ```
77
+ Request and response:
78
+ > curl.exe -X POST http://localhost:3001/orderdetails -H "Content-Type: application/json" --data '[{\"OrderID\":11077,\"ProductID\":99,\"UnitPrice\":19,\"Quantity\":1,\"Discount\":0}]'
79
+ {"success":true,"statusCode":200,"statusMessage":"OK","messages":[]}
80
+
81
+ SQL:
82
+ INSERT INTO [OrderDetails] ("OrderID","ProductID","UnitPrice","Quantity","Discount") VALUES (11077,99,19,1,0);
83
+ ```
84
+
85
+ ### HTTP PUT
86
+ ```
87
+ Request and response:
88
+ > curl.exe -X PUT http://localhost:3001/orderdetails/11077:99 -H "Content-Type: application/json" --data '[{\"UnitPrice\":20}]'
89
+ {"success":true,"statusCode":200,"statusMessage":"OK","messages":[]}
90
+
91
+ SQL:
92
+ UPDATE [OrderDetails] SET "UnitPrice"=20 WHERE ("OrderID"=11077 AND "ProductID"=99);
93
+ ```
94
+
95
+ ### HTTP DELETE
96
+ ```
97
+ Request and response:
98
+ > curl.exe -X DELETE http://localhost:3001/orderdetails/11077:99
99
+ {"success":true,"statusCode":200,"statusMessage":"OK","messages":[]}
100
+
101
+ SQL:
102
+ DELETE FROM [OrderDetails] WHERE ("OrderID"=11077 AND "ProductID"=99);
103
+ ```
104
+
105
+ ## Universal Serialization
106
+ OINO handles serialization of data to JSON/CSV/etc. and back based on the data model. It knows what columns exist, what is their data type and how to convert each to JSON/CSV and back. This allows also partial data to be sent, i.e. you can send only columns that need updating or even send extra columns and have them ignored.
107
+
108
+ ### Features
109
+ - Files can be sent to BLOB fields using BASE64 encoding.
110
+ - Datetimes are (optionally) normalized to ISO 8601 format.
111
+ - Extended JSON-encoding
112
+ - Unquoted literal `undefined` can be used to represent non-existent values (leaving property out works too but preserving structure might be easier e.g. when translating data).
113
+ - CSV
114
+ - Comma-separated, doublequotes.
115
+ - Unquoted literal `null` represents null values.
116
+ - Unquoted empty string represents undefined values.
117
+ - Form data
118
+ - Multipart-mixed and binary files not supported.
119
+ - Non-existent value line (i.e. nothing after the empty line) treated as a null value.
120
+ - Url-encoded
121
+ - No null values, missing properties treated as undefined.
122
+ - Multiple lines could be used to post multiple rows.
123
+
124
+
125
+ ## Database Abstraction
126
+ OINO functions as a database abstraction, providing a consistent interface for working with different databases. It abstracts out different conventions in connecting, making queries and formatting data.
127
+
128
+ Currently supported databases:
129
+ - Bun Sqlite through Bun native implementation
130
+ - Postgresql through [pg](https://www.npmjs.com/package/pg)-package
131
+ - Mariadb / Mysql-support through [mariadb](https://www.npmjs.com/package/mariadb)-package
132
+
133
+ ## Complex Keys
134
+ To support tables with multipart primary keys OINO generates a composite key `_OINOID_` that is included in the result and can be used as the REST ID. For example in the example above table `OrderDetails` has two primary keys `OrderID` and `ProductID` making the `_OINOID_` of form `11077:99`.
135
+
136
+ ## Power Of SQL
137
+ Since OINO controls the SQL, WHERE-conditions can be defined with [`OINOSqlFilter`](https://pragmatta.github.io/oino-ts/classes/core_src.OINOSqlFilter.html) and order with [`OINOSqlOrder`](https://pragmatta.github.io/oino-ts/classes/core_src.OINOSqlOrder.html) that are passed as HTTP request parameters. No more API development where you make unique API endpoints for each filter that fetch all data with original API and filter in backend code. Every API can be filtered when and as needed without unnessecary data tranfer and utilizing SQL indexing when available.
138
+
139
+ ## Swagger Support
140
+ Swagger is great as long as the definitions are updated and with OINO you can automatically get a Swagger definition including a data model schema.
141
+ ```
142
+ if (url.pathname == "/swagger.json") {
143
+ return new Response(JSON.stringify(OINOSwagger.getApiDefinition(api_array)))
144
+ }
145
+ ```
146
+ ![Swagger definition with a data model schema](img/readme-swagger.png)
147
+
148
+ ## Node support
149
+ OINO is developped Typescript first but compiles to standard CommonJS and the NPM packages should work on either ESM / CommonJS. Checkout sample apps `readmeApp` (ESM) and `nodeApp` (CommonJS).
150
+
151
+ ## HTMX support
152
+ OINO is [htmx.org](https://htmx.org) friendly, allowing easy translation of [`OINODataRow`](https://pragmatta.github.io/oino-ts/types/core_src.OINODataRow.html) to HTML output using templates (cf. the [htmx sample app](https://github.com/pragmatta/oino-ts/tree/main/samples/htmxApp)).
153
+
154
+ ### Hashids
155
+ Autoinc numeric id's are very pragmatic and fit well with OINO (e.g. using a form without primary key fields to insert new rows with database assigned ids). However it's not always sensible to share information about the sequence. Hashids solve this by masking the original values by encrypting the ids using AES-128 and some randomness. Length of the hashid can be chosen from 12-32 characters where longer ids provide more security. However this should not be considereded a cryptographic solution for keeping ids secret but rather making it infeasible to iterate all ids.
156
+
157
+
158
+ # STATUS
159
+ OINO is currently a hobby project which should and should considered in alpha status. That also means compatibility breaking changes can be made without prior notice when architectual issues are discovered.
160
+
161
+ ## Beta
162
+ For a beta status following milestones are planned:
163
+
164
+ ### Realistic app
165
+ There needs to be a realistic app built on top of OINO to get a better grasp of the edge cases.
166
+
167
+ ### Security review
168
+ Handling of SQL-injection attacks needs a thorough review, what are the relevant attack vectors are for OINO and what protections are still needed.
169
+
170
+ ## Roadmap
171
+ Things that need to happen in some order before beta-status are at least following:
172
+
173
+ ### Support for views
174
+ Simple cases of views would work already in some databases but edge cases might get complicated. For example
175
+ - How to handle a view which does not have a complete private key?
176
+ - What edge cases exist in updating views?
177
+
178
+ ### Batch updates
179
+ Supporting batch updates similar to batch inserts is slightly bending the RESTfull principles but would still be a useful optional feature.
180
+
181
+ ### Aggregation and limits
182
+ Similar to filtering and ordering, aggregation and limits can be implemented as HTTP request parameters telling what column is aggregated or used for ordering or how many results to return.
183
+
184
+ ### Streaming
185
+ One core idea is to be efficient in not making unnecessary copies of the data and minimizing garbage collection debt. This can be taken further by implementing streaming, allowing large dataset to be written to HTTP response as SQL result rows are received.
186
+
187
+ ### SQL generation callbacks
188
+ It would be useful to allow developer to validate / override SQL generation to cover cases OINO does not support or even workaround issues.
189
+
190
+ ### Transactions
191
+ Even though the basic case for OINO is executing SQL operations on individual rows, having an option to use SQL transactions could make sense at least for batch operations.
192
+
193
+
194
+ # HELP
195
+
196
+ ## Bug reports
197
+ Fixing bugs is a priority and getting good quality bug reports helps. It's recommended to use the sample Northwind database included with project to replicate issues or make an SQL script export of the relevant table.
198
+
199
+ ## Feedback
200
+ Understanding and prioritizing the use cases for OINO is also important and feedback about how you'd use OINO is interesting. Feel free to raise issues and feature requests in Github, but understand that short term most of the effort goes towards reaching the beta stage.
201
+
202
+ ## Typescript / Javascript architecture
203
+ Typescript building with different targets and module-systemts and a ton of configuration is a complex domain and something I have little experience un so help in fixing problems and how thing ought to be done is appreciated.
204
+
205
+ # LINKS
206
+ - [Github repository](https://github.com/pragmatta/oino-ts)
207
+ - [NPM repository](https://www.npmjs.com/org/oino-ts)
208
+
209
+
210
+ # ACKNOWLEDGEMENTS
211
+
212
+ ## Libraries
213
+ OINO uses the following open source libraries and npm packages and I would like to thank everyone for their contributions:
214
+ - Postgresql support by [node-postgres package](https://www.npmjs.com/package/pg)
215
+ - Mariadb / Mysql-support by [mariadb package](https://www.npmjs.com/package/mariadb)
216
+
217
+ ## Bun
218
+ OINO has been developed using the Bun runtime, not because of the speed improvements but for the first class Typescript support and integrated developper experience. Kudos on the bun team for making Typescript work more exiting again.
219
+
220
+ ## SQL Scripts
221
+ The SQL scripts for creating the sample Northwind database are based on [Google Code archive](https://code.google.com/archive/p/northwindextended/downloads) and have been further customized to ensure they would have identical data (in the scope of the automated testing).
222
+
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ /*
3
+ * This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.OINOBenchmark = void 0;
9
+ /**
10
+ * Static class for benchmarking functions.
11
+ *
12
+ */
13
+ class OINOBenchmark {
14
+ static _benchmarkCount = {};
15
+ static _benchmarkData = {};
16
+ static _benchmarkEnabled = {};
17
+ static _benchmarkStart = {};
18
+ /**
19
+ * Reset benchmark data (but not what is enabled).
20
+ *
21
+ */
22
+ static reset() {
23
+ this._benchmarkData = {};
24
+ this._benchmarkCount = {};
25
+ }
26
+ /**
27
+ * Set benchmark names that are enabled.
28
+ *
29
+ * @param names array of those benchmarks that are enabled
30
+ */
31
+ static setEnabled(names) {
32
+ this._benchmarkEnabled = {};
33
+ names.forEach(name => {
34
+ this._benchmarkEnabled[name] = true;
35
+ });
36
+ }
37
+ /**
38
+ * Start benchmark timing.
39
+ *
40
+ * @param name of the benchmark
41
+ */
42
+ static start(name) {
43
+ if (this._benchmarkEnabled[name]) {
44
+ if (this._benchmarkCount[name] == undefined) {
45
+ this._benchmarkCount[name] = 0;
46
+ this._benchmarkData[name] = 0;
47
+ }
48
+ this._benchmarkStart[name] = performance.now();
49
+ }
50
+ }
51
+ /**
52
+ * Complete benchmark timing
53
+ *
54
+ * @param name of the benchmark
55
+ */
56
+ static end(name) {
57
+ let result = 0;
58
+ if (this._benchmarkEnabled[name]) {
59
+ this._benchmarkCount[name] += 1;
60
+ this._benchmarkData[name] += performance.now() - this._benchmarkStart[name];
61
+ result = this._benchmarkData[name] / this._benchmarkCount[name];
62
+ }
63
+ return result;
64
+ }
65
+ }
66
+ exports.OINOBenchmark = OINOBenchmark;
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ /*
3
+ * This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.OINOConsoleLog = exports.OINOLog = exports.OINOLogLevel = void 0;
9
+ /** Logging levels */
10
+ var OINOLogLevel;
11
+ (function (OINOLogLevel) {
12
+ /** Debug messages */
13
+ OINOLogLevel[OINOLogLevel["debug"] = 0] = "debug";
14
+ /** Informational messages */
15
+ OINOLogLevel[OINOLogLevel["info"] = 1] = "info";
16
+ /** Warning messages */
17
+ OINOLogLevel[OINOLogLevel["warn"] = 2] = "warn";
18
+ /** Error messages */
19
+ OINOLogLevel[OINOLogLevel["error"] = 3] = "error";
20
+ })(OINOLogLevel || (exports.OINOLogLevel = OINOLogLevel = {}));
21
+ /**
22
+ * Abstract base class for logging implementations supporting
23
+ * - error, warning, info and debug channels
24
+ * - setting level of logs outputted
25
+ *
26
+ */
27
+ class OINOLog {
28
+ static _instance;
29
+ _logLevel = OINOLogLevel.warn;
30
+ /**
31
+ * Abstract logging method to implement the actual logging operation.
32
+ *
33
+ * @param logLevel level of the log events
34
+ *
35
+ */
36
+ constructor(logLevel = OINOLogLevel.warn) {
37
+ // console.log("OINOLog.constructor: logLevel=" + logLevel)
38
+ this._logLevel = logLevel;
39
+ }
40
+ /**
41
+ * Abstract logging method to implement the actual logging operation.
42
+ *
43
+ * @param level level of the log event
44
+ * @param levelStr level string of the log event
45
+ * @param message message of the log event
46
+ * @param data structured data associated with the log event
47
+ *
48
+ */
49
+ static _log(level, levelStr, message, data) {
50
+ // console.log("_log: level=" + level + ", levelStr=" + levelStr + ", message=" + message + ", data=" + data)
51
+ if ((OINOLog._instance) && (OINOLog._instance._logLevel <= level)) {
52
+ OINOLog._instance?._writeLog(levelStr, message, data);
53
+ }
54
+ }
55
+ /**
56
+ * Set active logger and log level.
57
+ *
58
+ * @param logger logger instance
59
+ *
60
+ */
61
+ static setLogger(logger) {
62
+ // console.log("setLogger: " + log)
63
+ if (logger) {
64
+ OINOLog._instance = logger;
65
+ }
66
+ }
67
+ /**
68
+ * Set log level.
69
+ *
70
+ * @param logLevel log level to use
71
+ *
72
+ */
73
+ static setLogLevel(logLevel) {
74
+ if (OINOLog._instance) {
75
+ OINOLog._instance._logLevel = logLevel;
76
+ }
77
+ }
78
+ /**
79
+ * Log error event.
80
+ *
81
+ * @param message message of the log event
82
+ * @param data structured data associated with the log event
83
+ *
84
+ */
85
+ static error(message, data) {
86
+ OINOLog._log(OINOLogLevel.error, "ERROR", message, data);
87
+ }
88
+ /**
89
+ * Log warning event.
90
+ *
91
+ * @param message message of the log event
92
+ * @param data structured data associated with the log event
93
+ *
94
+ */
95
+ static warning(message, data) {
96
+ OINOLog._log(OINOLogLevel.warn, "WARN", message, data);
97
+ }
98
+ /**
99
+ * Log info event.
100
+ *
101
+ * @param message message of the log event
102
+ * @param data structured data associated with the log event
103
+ *
104
+ */
105
+ static info(message, data) {
106
+ OINOLog._log(OINOLogLevel.info, "INFO", message, data);
107
+ }
108
+ /**
109
+ * Log debug event.
110
+ *
111
+ * @param message message of the log event
112
+ * @param data structured data associated with the log event
113
+ *
114
+ */
115
+ static debug(message, data) {
116
+ OINOLog._log(OINOLogLevel.debug, "DEBUG", message, data);
117
+ }
118
+ }
119
+ exports.OINOLog = OINOLog;
120
+ /**
121
+ * Logging implementation based on console.log.
122
+ *
123
+ */
124
+ class OINOConsoleLog extends OINOLog {
125
+ /**
126
+ * Constructor of `OINOConsoleLog`
127
+ * @param logLevel logging level
128
+ */
129
+ constructor(logLevel = OINOLogLevel.warn) {
130
+ super(logLevel);
131
+ }
132
+ _writeLog(level, message, data) {
133
+ let log = "OINOLog " + level + ": " + message;
134
+ if (data) {
135
+ log += " " + JSON.stringify(data);
136
+ }
137
+ console.log(log);
138
+ }
139
+ }
140
+ exports.OINOConsoleLog = OINOConsoleLog;
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ /*
3
+ * This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.OINOResult = void 0;
9
+ const _1 = require(".");
10
+ /**
11
+ * OINO API request result object with returned data and/or http status code/message and
12
+ * error / warning messages.
13
+ *
14
+ */
15
+ class OINOResult {
16
+ /** Wheter request was successfully executed */
17
+ success;
18
+ /** HTTP status code */
19
+ statusCode;
20
+ /** HTTP status message */
21
+ statusMessage;
22
+ /** Error / warning messages */
23
+ messages;
24
+ /**
25
+ * Constructor of OINOResult.
26
+ *
27
+ */
28
+ constructor() {
29
+ this.success = true;
30
+ this.statusCode = 200;
31
+ this.statusMessage = "OK";
32
+ this.messages = [];
33
+ }
34
+ /**
35
+ * Set HTTP OK status (does not reset messages).
36
+ *
37
+ */
38
+ setOk() {
39
+ this.success = true;
40
+ this.statusCode = 200;
41
+ this.statusMessage = "OK";
42
+ }
43
+ /**
44
+ * Set HTTP error status using given code and message.
45
+ *
46
+ * @param statusCode HTTP status code
47
+ * @param statusMessage HTTP status message
48
+ * @param operation operation where error occured
49
+ *
50
+ */
51
+ setError(statusCode, statusMessage, operation) {
52
+ this.success = false;
53
+ this.statusCode = statusCode;
54
+ if (this.statusMessage != "OK") {
55
+ this.messages.push(this.statusMessage); // latest error becomes status, but if there was something non-trivial, add it to the messages
56
+ }
57
+ if (statusMessage.startsWith(_1.OINO_ERROR_PREFIX)) {
58
+ this.statusMessage = statusMessage;
59
+ }
60
+ else {
61
+ this.statusMessage = _1.OINO_ERROR_PREFIX + " (" + operation + "): " + statusMessage;
62
+ }
63
+ }
64
+ /**
65
+ * Add warning message.
66
+ *
67
+ * @param message HTTP status message
68
+ * @param operation operation where warning occured
69
+ *
70
+ */
71
+ addWarning(message, operation) {
72
+ message = message.trim();
73
+ if (message) {
74
+ this.messages.push(_1.OINO_WARNING_PREFIX + " (" + operation + "): " + message);
75
+ }
76
+ }
77
+ /**
78
+ * Add info message.
79
+ *
80
+ * @param message HTTP status message
81
+ * @param operation operation where info occured
82
+ *
83
+ */
84
+ addInfo(message, operation) {
85
+ message = message.trim();
86
+ if (message) {
87
+ this.messages.push(_1.OINO_INFO_PREFIX + " (" + operation + "): " + message);
88
+ }
89
+ }
90
+ /**
91
+ * Add debug message.
92
+ *
93
+ * @param message HTTP status message
94
+ * @param operation operation where debug occured
95
+ *
96
+ */
97
+ addDebug(message, operation) {
98
+ message = message.trim();
99
+ if (message) {
100
+ this.messages.push(_1.OINO_DEBUG_PREFIX + " (" + operation + "): " + message);
101
+ }
102
+ }
103
+ /**
104
+ * Copy given messages to HTTP headers.
105
+ *
106
+ * @param headers HTTP headers
107
+ * @param copyErrors wether error messages should be copied (default true)
108
+ * @param copyWarnings wether warning messages should be copied (default false)
109
+ * @param copyInfos wether info messages should be copied (default false)
110
+ * @param copyDebug wether debug messages should be copied (default false)
111
+ *
112
+ */
113
+ copyMessagesToHeaders(headers, copyErrors = true, copyWarnings = false, copyInfos = false, copyDebug = false) {
114
+ let j = 1;
115
+ for (let i = 0; i < this.messages.length; i++) {
116
+ const message = this.messages[i].replaceAll("\r", " ").replaceAll("\n", " ");
117
+ if (copyErrors && message.startsWith(_1.OINO_ERROR_PREFIX)) {
118
+ headers.append('X-OINO-MESSAGE-' + j, message);
119
+ j++;
120
+ }
121
+ if (copyWarnings && message.startsWith(_1.OINO_WARNING_PREFIX)) {
122
+ headers.append('X-OINO-MESSAGE-' + j, message);
123
+ j++;
124
+ }
125
+ if (copyInfos && message.startsWith(_1.OINO_INFO_PREFIX)) {
126
+ headers.append('X-OINO-MESSAGE-' + j, message);
127
+ j++;
128
+ }
129
+ if (copyDebug && message.startsWith(_1.OINO_DEBUG_PREFIX)) {
130
+ headers.append('X-OINO-MESSAGE-' + j, message);
131
+ j++;
132
+ }
133
+ }
134
+ }
135
+ }
136
+ exports.OINOResult = OINOResult;