@oino-ts/db 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 +222 -0
- package/dist/cjs/OINODb.js +27 -0
- package/dist/cjs/OINODbApi.js +270 -0
- package/dist/cjs/OINODbConfig.js +86 -0
- package/dist/cjs/OINODbDataField.js +354 -0
- package/dist/cjs/OINODbDataModel.js +279 -0
- package/dist/cjs/OINODbDataSet.js +139 -0
- package/dist/cjs/OINODbFactory.js +563 -0
- package/dist/cjs/OINODbModelSet.js +267 -0
- package/dist/cjs/OINODbParams.js +280 -0
- package/dist/cjs/OINODbRequestParams.js +280 -0
- package/dist/cjs/OINODbSwagger.js +201 -0
- package/dist/cjs/index.js +51 -0
- package/dist/esm/OINODb.js +23 -0
- package/dist/esm/OINODbApi.js +265 -0
- package/dist/esm/OINODbConfig.js +82 -0
- package/dist/esm/OINODbDataField.js +345 -0
- package/dist/esm/OINODbDataModel.js +275 -0
- package/dist/esm/OINODbDataSet.js +134 -0
- package/dist/esm/OINODbFactory.js +559 -0
- package/dist/esm/OINODbModelSet.js +263 -0
- package/dist/esm/OINODbRequestParams.js +274 -0
- package/dist/esm/OINODbSwagger.js +197 -0
- package/dist/esm/index.js +17 -0
- package/dist/types/OINODb.d.ts +75 -0
- package/dist/types/OINODbApi.d.ts +57 -0
- package/dist/types/OINODbConfig.d.ts +52 -0
- package/dist/types/OINODbDataField.d.ts +202 -0
- package/dist/types/OINODbDataModel.d.ts +108 -0
- package/dist/types/OINODbDataSet.d.ts +95 -0
- package/dist/types/OINODbFactory.d.ts +99 -0
- package/dist/types/OINODbModelSet.d.ts +50 -0
- package/dist/types/OINODbRequestParams.d.ts +130 -0
- package/dist/types/OINODbSwagger.d.ts +25 -0
- package/dist/types/index.d.ts +103 -0
- package/package.json +35 -0
- package/src/OINODb.ts +98 -0
- package/src/OINODbApi.test.ts +243 -0
- package/src/OINODbApi.ts +270 -0
- package/src/OINODbConfig.ts +92 -0
- package/src/OINODbDataField.ts +372 -0
- package/src/OINODbDataModel.ts +290 -0
- package/src/OINODbDataSet.ts +170 -0
- package/src/OINODbFactory.ts +570 -0
- package/src/OINODbModelSet.ts +286 -0
- package/src/OINODbRequestParams.ts +281 -0
- package/src/OINODbSwagger.ts +209 -0
- package/src/index.ts +116 -0
|
@@ -0,0 +1,139 @@
|
|
|
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.OINODbMemoryDataSet = exports.OINODbDataSet = void 0;
|
|
9
|
+
const index_js_1 = require("./index.js");
|
|
10
|
+
/**
|
|
11
|
+
* Base class for SQL results that can be asynchronously iterated (but
|
|
12
|
+
* not necessarity rewinded). Idea is to handle database specific mechanisms
|
|
13
|
+
* for returning and formatting conventions in the database specific
|
|
14
|
+
* implementation. Data might be in memory or streamed in chunks and
|
|
15
|
+
* `OINODbDataSet` will serve it out consistently.
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
class OINODbDataSet {
|
|
19
|
+
_data;
|
|
20
|
+
/** Error messages */
|
|
21
|
+
messages;
|
|
22
|
+
/**
|
|
23
|
+
* Constructor for `OINODbDataSet`.
|
|
24
|
+
*
|
|
25
|
+
* @param data internal database specific data type (constructor will throw if invalid)
|
|
26
|
+
* @param messages error messages from SQL-query
|
|
27
|
+
*
|
|
28
|
+
*/
|
|
29
|
+
constructor(data, messages = []) {
|
|
30
|
+
this._data = data;
|
|
31
|
+
this.messages = messages;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Checks if the messages contain errors.
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
37
|
+
hasErrors() {
|
|
38
|
+
for (let i = 0; i < this.messages.length; i++) {
|
|
39
|
+
if (this.messages[i].startsWith(index_js_1.OINO_ERROR_PREFIX)) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Checks if the messages contain errors.
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
getFirstError() {
|
|
50
|
+
for (let i = 0; i < this.messages.length; i++) {
|
|
51
|
+
if (this.messages[i].startsWith(index_js_1.OINO_ERROR_PREFIX)) {
|
|
52
|
+
return this.messages[i];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return "";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.OINODbDataSet = OINODbDataSet;
|
|
59
|
+
/**
|
|
60
|
+
* Generic in memory implementation of a data set where data is an array of rows. Used
|
|
61
|
+
* by BunSqlite and automated testing. Can be rewinded.
|
|
62
|
+
*
|
|
63
|
+
*/
|
|
64
|
+
class OINODbMemoryDataSet extends OINODbDataSet {
|
|
65
|
+
_rows;
|
|
66
|
+
_currentRow;
|
|
67
|
+
_eof;
|
|
68
|
+
/**
|
|
69
|
+
* Constructor of `OINODbMemoryDataSet`.
|
|
70
|
+
*
|
|
71
|
+
* @param data data as OINODataRow[] (constructor will throw if invalid)
|
|
72
|
+
* @param errors error messages from SQL-query
|
|
73
|
+
*
|
|
74
|
+
*/
|
|
75
|
+
constructor(data, errors = []) {
|
|
76
|
+
super(data, errors);
|
|
77
|
+
if ((data == null) || !(Array.isArray(data))) {
|
|
78
|
+
throw new Error(index_js_1.OINO_ERROR_PREFIX + ": Data needs to be compatible with OINORow[]!"); // TODO: maybe check all rows
|
|
79
|
+
}
|
|
80
|
+
this._rows = data;
|
|
81
|
+
if (this.isEmpty()) {
|
|
82
|
+
this._currentRow = -1;
|
|
83
|
+
this._eof = true;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
this._currentRow = 0;
|
|
87
|
+
this._eof = false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Is data set empty.
|
|
92
|
+
*
|
|
93
|
+
*/
|
|
94
|
+
isEmpty() {
|
|
95
|
+
return (this._rows.length == 0);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Is there no more content, i.e. either dataset is empty or we have moved beyond last line
|
|
99
|
+
*
|
|
100
|
+
*/
|
|
101
|
+
isEof() {
|
|
102
|
+
return (this._eof);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Moves dataset to the next row, returns !isEof().
|
|
106
|
+
*
|
|
107
|
+
*/
|
|
108
|
+
next() {
|
|
109
|
+
if (this._currentRow < this._rows.length - 1) {
|
|
110
|
+
this._currentRow = this._currentRow + 1;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
this._eof = true;
|
|
114
|
+
}
|
|
115
|
+
return !this._eof;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Gets current row of data.
|
|
119
|
+
*
|
|
120
|
+
*/
|
|
121
|
+
getRow() {
|
|
122
|
+
if ((this._currentRow >= 0) && (this._currentRow < this._rows.length)) {
|
|
123
|
+
return this._rows[this._currentRow];
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
return index_js_1.OINODB_EMPTY_ROW;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Rewinds data set to the first row, returns !isEof().
|
|
131
|
+
*
|
|
132
|
+
*/
|
|
133
|
+
first() {
|
|
134
|
+
this._currentRow = 0;
|
|
135
|
+
this._eof = this._rows.length == 0;
|
|
136
|
+
return !this._eof;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.OINODbMemoryDataSet = OINODbMemoryDataSet;
|