@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,108 @@
|
|
|
1
|
+
import { OINODbDataField, OINODbApi, OINODataRow, OINODbDataFieldFilter, OINODbSqlParams } from "./index.js";
|
|
2
|
+
/**
|
|
3
|
+
* OINO Datamodel object for representing one database table and it's columns.
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
export declare class OINODbDataModel {
|
|
7
|
+
private _columnLookup;
|
|
8
|
+
/** Database refererence of the table */
|
|
9
|
+
readonly api: OINODbApi;
|
|
10
|
+
/** Field refererences of the API */
|
|
11
|
+
readonly fields: OINODbDataField[];
|
|
12
|
+
/**
|
|
13
|
+
* Constructor of the data model.
|
|
14
|
+
* NOTE! OINODbDataModel.initialize must be called after constructor to populate fields.
|
|
15
|
+
*
|
|
16
|
+
* @param api api of the data model
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
constructor(api: OINODbApi);
|
|
20
|
+
/**
|
|
21
|
+
* Initialize datamodel from SQL schema.
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
initialize(): Promise<void>;
|
|
25
|
+
private _printSqlColumnNames;
|
|
26
|
+
private _printSqlInsertColumnsAndValues;
|
|
27
|
+
private _printSqlUpdateValues;
|
|
28
|
+
private _printSqlPrimaryKeyCondition;
|
|
29
|
+
/**
|
|
30
|
+
* Add a field to the datamodel.
|
|
31
|
+
*
|
|
32
|
+
* @param field dataset field
|
|
33
|
+
*
|
|
34
|
+
*/
|
|
35
|
+
addField(field: OINODbDataField): void;
|
|
36
|
+
/**
|
|
37
|
+
* Find a field of a given name if any.
|
|
38
|
+
*
|
|
39
|
+
* @param name name of the field to find
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
findFieldByName(name: string): OINODbDataField | null;
|
|
43
|
+
/**
|
|
44
|
+
* Find index of a field of a given name if any.
|
|
45
|
+
*
|
|
46
|
+
* @param name name of the field to find
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
findFieldIndexByName(name: string): number;
|
|
50
|
+
/**
|
|
51
|
+
* Find all fields based of given filter callback criteria (e.g. fields of certain data type, primary keys etc.)
|
|
52
|
+
*
|
|
53
|
+
* @param filter callback called for each field to include or not
|
|
54
|
+
*
|
|
55
|
+
*/
|
|
56
|
+
filterFields(filter: OINODbDataFieldFilter): OINODbDataField[];
|
|
57
|
+
/**
|
|
58
|
+
* Return the primary key values of one row in order of the data model
|
|
59
|
+
*
|
|
60
|
+
* @param row data row
|
|
61
|
+
* @param hashidValues apply hashid when applicable
|
|
62
|
+
*
|
|
63
|
+
*/
|
|
64
|
+
getRowPrimarykeyValues(row: OINODataRow, hashidValues?: boolean): string[];
|
|
65
|
+
/**
|
|
66
|
+
* Print debug information about the fields.
|
|
67
|
+
*
|
|
68
|
+
* @param separator string to separate field prints
|
|
69
|
+
*
|
|
70
|
+
*/
|
|
71
|
+
printDebug(separator?: string): string;
|
|
72
|
+
/**
|
|
73
|
+
* Print all public properties (db, table name, fields) of the datamodel. Used
|
|
74
|
+
* in automated testing validate schema has stayed the same.
|
|
75
|
+
*
|
|
76
|
+
*/
|
|
77
|
+
printFieldPublicPropertiesJson(): string;
|
|
78
|
+
/**
|
|
79
|
+
* Print SQL select statement using optional id and filter.
|
|
80
|
+
*
|
|
81
|
+
* @param id OINO ID (i.e. combined primary key values)
|
|
82
|
+
* @param params OINO reqest params
|
|
83
|
+
*
|
|
84
|
+
*/
|
|
85
|
+
printSqlSelect(id: string, params: OINODbSqlParams): string;
|
|
86
|
+
/**
|
|
87
|
+
* Print SQL insert statement from one data row.
|
|
88
|
+
*
|
|
89
|
+
* @param row one row of data in the data model
|
|
90
|
+
*
|
|
91
|
+
*/
|
|
92
|
+
printSqlInsert(row: OINODataRow): string;
|
|
93
|
+
/**
|
|
94
|
+
* Print SQL insert statement from one data row.
|
|
95
|
+
*
|
|
96
|
+
* @param id OINO ID (i.e. combined primary key values)
|
|
97
|
+
* @param row one row of data in the data model
|
|
98
|
+
*
|
|
99
|
+
*/
|
|
100
|
+
printSqlUpdate(id: string, row: OINODataRow): string;
|
|
101
|
+
/**
|
|
102
|
+
* Print SQL delete statement for id.
|
|
103
|
+
*
|
|
104
|
+
* @param id OINO ID (i.e. combined primary key values)
|
|
105
|
+
*
|
|
106
|
+
*/
|
|
107
|
+
printSqlDelete(id: string): string;
|
|
108
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { OINODataRow } from "./index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Base class for SQL results that can be asynchronously iterated (but
|
|
4
|
+
* not necessarity rewinded). Idea is to handle database specific mechanisms
|
|
5
|
+
* for returning and formatting conventions in the database specific
|
|
6
|
+
* implementation. Data might be in memory or streamed in chunks and
|
|
7
|
+
* `OINODbDataSet` will serve it out consistently.
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
export declare abstract class OINODbDataSet {
|
|
11
|
+
private _data;
|
|
12
|
+
/** Error messages */
|
|
13
|
+
readonly messages: string[];
|
|
14
|
+
/**
|
|
15
|
+
* Constructor for `OINODbDataSet`.
|
|
16
|
+
*
|
|
17
|
+
* @param data internal database specific data type (constructor will throw if invalid)
|
|
18
|
+
* @param messages error messages from SQL-query
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
constructor(data: unknown, messages?: string[]);
|
|
22
|
+
/**
|
|
23
|
+
* Is data set empty.
|
|
24
|
+
*
|
|
25
|
+
*/
|
|
26
|
+
abstract isEmpty(): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Is there no more content, i.e. either dataset is empty or we have moved beyond last line
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
abstract isEof(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Moves dataset to the next row, returns !isEof().
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
abstract next(): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Gets current row of data.
|
|
39
|
+
*
|
|
40
|
+
*/
|
|
41
|
+
abstract getRow(): OINODataRow;
|
|
42
|
+
/**
|
|
43
|
+
* Checks if the messages contain errors.
|
|
44
|
+
*
|
|
45
|
+
*/
|
|
46
|
+
hasErrors(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Checks if the messages contain errors.
|
|
49
|
+
*
|
|
50
|
+
*/
|
|
51
|
+
getFirstError(): string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Generic in memory implementation of a data set where data is an array of rows. Used
|
|
55
|
+
* by BunSqlite and automated testing. Can be rewinded.
|
|
56
|
+
*
|
|
57
|
+
*/
|
|
58
|
+
export declare class OINODbMemoryDataSet extends OINODbDataSet {
|
|
59
|
+
private _rows;
|
|
60
|
+
private _currentRow;
|
|
61
|
+
private _eof;
|
|
62
|
+
/**
|
|
63
|
+
* Constructor of `OINODbMemoryDataSet`.
|
|
64
|
+
*
|
|
65
|
+
* @param data data as OINODataRow[] (constructor will throw if invalid)
|
|
66
|
+
* @param errors error messages from SQL-query
|
|
67
|
+
*
|
|
68
|
+
*/
|
|
69
|
+
constructor(data: unknown, errors?: string[]);
|
|
70
|
+
/**
|
|
71
|
+
* Is data set empty.
|
|
72
|
+
*
|
|
73
|
+
*/
|
|
74
|
+
isEmpty(): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Is there no more content, i.e. either dataset is empty or we have moved beyond last line
|
|
77
|
+
*
|
|
78
|
+
*/
|
|
79
|
+
isEof(): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Moves dataset to the next row, returns !isEof().
|
|
82
|
+
*
|
|
83
|
+
*/
|
|
84
|
+
next(): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Gets current row of data.
|
|
87
|
+
*
|
|
88
|
+
*/
|
|
89
|
+
getRow(): OINODataRow;
|
|
90
|
+
/**
|
|
91
|
+
* Rewinds data set to the first row, returns !isEof().
|
|
92
|
+
*
|
|
93
|
+
*/
|
|
94
|
+
first(): boolean;
|
|
95
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { OINODbApi, OINODbApiParams, OINODbParams, OINODbDataModel, OINODb, OINODataRow, OINODbConstructor, OINORequestParams, OINODbApiResult, OINODbModelSet } from "./index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Static factory class for easily creating things based on data
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
export declare class OINODbFactory {
|
|
7
|
+
private static _dbRegistry;
|
|
8
|
+
/**
|
|
9
|
+
* Register a supported database class. Used to enable those that are installed in the factory
|
|
10
|
+
* instead of forcing everyone to install all database libraries.
|
|
11
|
+
*
|
|
12
|
+
* @param dbName name of the database implementation class
|
|
13
|
+
* @param dbTypeClass constructor for creating a database of that type
|
|
14
|
+
*/
|
|
15
|
+
static registerDb(dbName: string, dbTypeClass: OINODbConstructor): void;
|
|
16
|
+
/**
|
|
17
|
+
* Create database from parameters from the registered classes.
|
|
18
|
+
*
|
|
19
|
+
* @param params database connection parameters
|
|
20
|
+
*/
|
|
21
|
+
static createDb(params: OINODbParams): Promise<OINODb>;
|
|
22
|
+
/**
|
|
23
|
+
* Create API from parameters and calls initDatamodel on the datamodel.
|
|
24
|
+
*
|
|
25
|
+
* @param db databased used in API
|
|
26
|
+
* @param params parameters of the API
|
|
27
|
+
*/
|
|
28
|
+
static createApi(db: OINODb, params: OINODbApiParams): Promise<OINODbApi>;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a key-value-collection from Javascript URL parameters.
|
|
31
|
+
*
|
|
32
|
+
* @param request HTTP Request
|
|
33
|
+
*/
|
|
34
|
+
static createParamsFromRequest(request: Request): OINORequestParams;
|
|
35
|
+
/**
|
|
36
|
+
* Creates a HTTP Response from API results.
|
|
37
|
+
*
|
|
38
|
+
* @param apiResult API results
|
|
39
|
+
* @param requestParams API request parameters
|
|
40
|
+
* @param responseHeaders Headers to include in the response
|
|
41
|
+
*
|
|
42
|
+
*/
|
|
43
|
+
static createResponseFromApiResult(apiResult: OINODbApiResult, requestParams: OINORequestParams, responseHeaders?: Record<string, string>): Response;
|
|
44
|
+
/**
|
|
45
|
+
* Creates HTML Response from API modelset.
|
|
46
|
+
*
|
|
47
|
+
* @param modelset OINO API dataset
|
|
48
|
+
* @param template HTML template
|
|
49
|
+
*
|
|
50
|
+
*/
|
|
51
|
+
static createHtmlFromData(modelset: OINODbModelSet, template: string): string;
|
|
52
|
+
/**
|
|
53
|
+
* Creates HTML Response from a row id.
|
|
54
|
+
*
|
|
55
|
+
* @param oinoId OINO id
|
|
56
|
+
* @param template HTML template
|
|
57
|
+
*
|
|
58
|
+
*/
|
|
59
|
+
static createHtmlFromOinoId(oinoId: string, template: string): string;
|
|
60
|
+
/**
|
|
61
|
+
* Creates HTML Response from object properties.
|
|
62
|
+
*
|
|
63
|
+
* @param object object
|
|
64
|
+
* @param template HTML template
|
|
65
|
+
*
|
|
66
|
+
*/
|
|
67
|
+
static createHtmlFromObject(object: any, template: string): string;
|
|
68
|
+
/**
|
|
69
|
+
* Creates HTML Response from API result.
|
|
70
|
+
*
|
|
71
|
+
* @param apiResult object
|
|
72
|
+
* @param template HTML template
|
|
73
|
+
* @param includeErrorMessages include debug messages in result
|
|
74
|
+
* @param includeWarningMessages include debug messages in result
|
|
75
|
+
* @param includeInfoMessages include debug messages in result
|
|
76
|
+
* @param includeDebugMessages include debug messages in result
|
|
77
|
+
*
|
|
78
|
+
*/
|
|
79
|
+
static createHtmlFromApiResult(apiResult: OINODbApiResult, template: string, includeErrorMessages?: boolean, includeWarningMessages?: boolean, includeInfoMessages?: boolean, includeDebugMessages?: boolean): string;
|
|
80
|
+
private static _findCsvLineEnd;
|
|
81
|
+
private static _parseCsvLine;
|
|
82
|
+
private static createRowFromCsv;
|
|
83
|
+
private static _createRowFromJsonObj;
|
|
84
|
+
private static _createRowFromJson;
|
|
85
|
+
private static _findMultipartBoundary;
|
|
86
|
+
private static _parseMultipartLine;
|
|
87
|
+
private static _multipartHeaderRegex;
|
|
88
|
+
private static createRowFromFormdata;
|
|
89
|
+
private static createRowFromUrlencoded;
|
|
90
|
+
/**
|
|
91
|
+
* Create data rows from request body based on the datamodel.
|
|
92
|
+
*
|
|
93
|
+
* @param datamodel datamodel of the api
|
|
94
|
+
* @param data data as a string
|
|
95
|
+
* @param requestParams parameters
|
|
96
|
+
*
|
|
97
|
+
*/
|
|
98
|
+
static createRows(datamodel: OINODbDataModel, data: string, requestParams: OINORequestParams): OINODataRow[];
|
|
99
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { OINODbDataSet, OINODbDataModel, OINOContentType, OINODataCell } from "./index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Class for dataset based on a data model that can be serialized to
|
|
4
|
+
* a supported format:
|
|
5
|
+
* - JSON (application/json)
|
|
6
|
+
* - CSV (text/csv)
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
export declare class OINODbModelSet {
|
|
10
|
+
/** Reference to datamodel */
|
|
11
|
+
readonly datamodel: OINODbDataModel;
|
|
12
|
+
/** Reference to data set */
|
|
13
|
+
readonly dataset: OINODbDataSet;
|
|
14
|
+
/** Collection of errors */
|
|
15
|
+
errors: string[];
|
|
16
|
+
/**
|
|
17
|
+
* Constructor for `OINODbModelSet`.
|
|
18
|
+
*
|
|
19
|
+
* @param datamodel data model
|
|
20
|
+
* @param dataset data set
|
|
21
|
+
*/
|
|
22
|
+
constructor(datamodel: OINODbDataModel, dataset: OINODbDataSet);
|
|
23
|
+
private _encodeAndHashFieldValue;
|
|
24
|
+
private _writeRowJson;
|
|
25
|
+
private _writeStringJson;
|
|
26
|
+
private _writeHeaderCsv;
|
|
27
|
+
private _writeRowCsv;
|
|
28
|
+
private _writeStringCsv;
|
|
29
|
+
private _writeRowFormdataParameterBlock;
|
|
30
|
+
private _writeRowFormdataFileBlock;
|
|
31
|
+
private _writeRowFormdata;
|
|
32
|
+
private _writeStringFormdata;
|
|
33
|
+
private _writeRowUrlencode;
|
|
34
|
+
private _writeStringUrlencode;
|
|
35
|
+
/**
|
|
36
|
+
* Serialize model set in the given format.
|
|
37
|
+
*
|
|
38
|
+
* @param [contentType=OINOContentType.json] serialization content type
|
|
39
|
+
*
|
|
40
|
+
*/
|
|
41
|
+
writeString(contentType?: OINOContentType): string;
|
|
42
|
+
/**
|
|
43
|
+
* Get value of given field in the current row. Undefined if no rows,
|
|
44
|
+
* field not found or value does not exist.
|
|
45
|
+
*
|
|
46
|
+
* @param fieldName name of the field
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
getValueByFieldName(fieldName: string): OINODataCell;
|
|
50
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { OINODbDataModel } from "./index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Supported logical conjunctions in filter predicates.
|
|
4
|
+
* @enum
|
|
5
|
+
*/
|
|
6
|
+
export declare enum OINODbSqlBooleanOperation {
|
|
7
|
+
and = "and",
|
|
8
|
+
or = "or",
|
|
9
|
+
not = "not"
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Supported logical conjunctions in filter predicates.
|
|
13
|
+
* @enum
|
|
14
|
+
*/
|
|
15
|
+
export declare enum OINODbSqlComparison {
|
|
16
|
+
lt = "lt",
|
|
17
|
+
le = "le",
|
|
18
|
+
eq = "eq",
|
|
19
|
+
ge = "ge",
|
|
20
|
+
gt = "gt",
|
|
21
|
+
like = "like"
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Class for recursively parsing of filters and printing them as SQL conditions.
|
|
25
|
+
* Supports three types of statements
|
|
26
|
+
* - comparison: (field)-lt|le|eq|ge|gt|like(value)
|
|
27
|
+
* - negation: -not(filter)
|
|
28
|
+
* - conjunction/disjunction: (filter)-and|or(filter)
|
|
29
|
+
* Supported conditions are comparisons (<, <=, =, >=, >) and substring match (LIKE).
|
|
30
|
+
*
|
|
31
|
+
*/
|
|
32
|
+
export declare class OINODbSqlFilter {
|
|
33
|
+
private static _booleanOperationRegex;
|
|
34
|
+
private static _negationRegex;
|
|
35
|
+
private static _filterComparisonRegex;
|
|
36
|
+
private _leftSide;
|
|
37
|
+
private _rightSide;
|
|
38
|
+
private _operator;
|
|
39
|
+
/**
|
|
40
|
+
* Constructor of `OINODbSqlFilter`
|
|
41
|
+
* @param leftSide left side of the filter, either another filter or a column name
|
|
42
|
+
* @param operation operation of the filter, either `OINODbSqlComparison` or `OINODbSqlBooleanOperation`
|
|
43
|
+
* @param rightSide right side of the filter, either another filter or a value
|
|
44
|
+
*/
|
|
45
|
+
constructor(leftSide: OINODbSqlFilter | string, operation: OINODbSqlComparison | OINODbSqlBooleanOperation | null, rightSide: OINODbSqlFilter | string);
|
|
46
|
+
/**
|
|
47
|
+
* Constructor for `OINOFilter` as parser of http parameter.
|
|
48
|
+
*
|
|
49
|
+
* @param filterString string representation of filter from HTTP-request
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
static parse(filterString: string): OINODbSqlFilter;
|
|
53
|
+
/**
|
|
54
|
+
* Construct a new `OINOFilter` as combination of (boolean and/or) of two filters.
|
|
55
|
+
*
|
|
56
|
+
* @param leftSide left side to combine
|
|
57
|
+
* @param operation boolean operation to use in combination
|
|
58
|
+
* @param rightSide right side to combine
|
|
59
|
+
*
|
|
60
|
+
*/
|
|
61
|
+
static combine(leftSide: OINODbSqlFilter | undefined, operation: OINODbSqlBooleanOperation, rightSide: OINODbSqlFilter | undefined): OINODbSqlFilter | undefined;
|
|
62
|
+
private _operatorToSql;
|
|
63
|
+
/**
|
|
64
|
+
* Does filter contain any valid conditions.
|
|
65
|
+
*
|
|
66
|
+
*/
|
|
67
|
+
isEmpty(): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Print filter as SQL condition based on the datamodel of the API.
|
|
70
|
+
*
|
|
71
|
+
* @param dataModel data model (and database) to use for formatting of values
|
|
72
|
+
*
|
|
73
|
+
*/
|
|
74
|
+
toSql(dataModel: OINODbDataModel): string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Class for ordering select results on a number of columns.
|
|
78
|
+
*
|
|
79
|
+
*/
|
|
80
|
+
export declare class OINODbSqlOrder {
|
|
81
|
+
private static _orderColumnRegex;
|
|
82
|
+
private _columns;
|
|
83
|
+
private _directions;
|
|
84
|
+
/**
|
|
85
|
+
* Constructor for `OINODbSqlOrder`.
|
|
86
|
+
*
|
|
87
|
+
* @param orderString string representation of filter from HTTP-request
|
|
88
|
+
*
|
|
89
|
+
*/
|
|
90
|
+
constructor(orderString: string);
|
|
91
|
+
/**
|
|
92
|
+
* Does filter contain any valid conditions.
|
|
93
|
+
*
|
|
94
|
+
*/
|
|
95
|
+
isEmpty(): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Print order as SQL condition based on the datamodel of the API.
|
|
98
|
+
*
|
|
99
|
+
* @param dataModel data model (and database) to use for formatting of values
|
|
100
|
+
*
|
|
101
|
+
*/
|
|
102
|
+
toSql(dataModel: OINODbDataModel): string;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Class for limiting the number of results.
|
|
106
|
+
*
|
|
107
|
+
*/
|
|
108
|
+
export declare class OINODbSqlLimit {
|
|
109
|
+
private static _orderColumnRegex;
|
|
110
|
+
private _limit;
|
|
111
|
+
/**
|
|
112
|
+
* Constructor for `OINODbSqlLimit`.
|
|
113
|
+
*
|
|
114
|
+
* @param limitString string representation of filter from HTTP-request
|
|
115
|
+
*
|
|
116
|
+
*/
|
|
117
|
+
constructor(limitString: string);
|
|
118
|
+
/**
|
|
119
|
+
* Does filter contain any valid conditions.
|
|
120
|
+
*
|
|
121
|
+
*/
|
|
122
|
+
isEmpty(): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Print order as SQL condition based on the datamodel of the API.
|
|
125
|
+
*
|
|
126
|
+
* @param dataModel data model (and database) to use for formatting of values
|
|
127
|
+
*
|
|
128
|
+
*/
|
|
129
|
+
toSql(dataModel: OINODbDataModel): string;
|
|
130
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { OINODbApi } from "./index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Static class for Swagger utilities
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
export declare class OINODbSwagger {
|
|
7
|
+
private static _getSchemaApiMethodParamsQueryId;
|
|
8
|
+
private static _getSchemaApiMethodParamsBody;
|
|
9
|
+
private static _getSchemaApiMethodDescription;
|
|
10
|
+
private static _getSchemaApiMethodOperationId;
|
|
11
|
+
private static _getSchemaOinoResponse;
|
|
12
|
+
private static _getSchemaFieldType;
|
|
13
|
+
private static _getSwaggerApiType;
|
|
14
|
+
private static _getSchemaType;
|
|
15
|
+
private static _getSchemaApiMethodParams;
|
|
16
|
+
private static _getSchemaApiMethod;
|
|
17
|
+
private static _getSwaggerApiPath;
|
|
18
|
+
/**
|
|
19
|
+
* Returns swagger.json as object of the given API's.
|
|
20
|
+
*
|
|
21
|
+
* @param apis array of API's use for Swagger definition
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
static getApiDefinition(apis: OINODbApi[]): any;
|
|
25
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { OINOContentType } from "@oino-ts/types";
|
|
2
|
+
export { OINOContentType };
|
|
3
|
+
export { OINO_ERROR_PREFIX, OINO_WARNING_PREFIX, OINO_INFO_PREFIX, OINO_DEBUG_PREFIX, OINOStr, OINOBenchmark, OINOLog, OINOLogLevel, OINOConsoleLog, OINOResult } from "@oino-ts/types";
|
|
4
|
+
import { OINODb } from "./OINODb.js";
|
|
5
|
+
import { OINODbDataField } from "./OINODbDataField.js";
|
|
6
|
+
import { OINODbSqlFilter, OINODbSqlLimit, OINODbSqlOrder } from "./OINODbRequestParams.js";
|
|
7
|
+
export { OINODbApiResult, OINODbApi } from "./OINODbApi.js";
|
|
8
|
+
export { OINODbDataModel } from "./OINODbDataModel.js";
|
|
9
|
+
export { OINODbModelSet } from "./OINODbModelSet.js";
|
|
10
|
+
export { OINODbDataField, OINOBooleanDataField, OINONumberDataField, OINOStringDataField, OINOBlobDataField, OINODatetimeDataField } from "./OINODbDataField.js";
|
|
11
|
+
export { OINODb } from "./OINODb.js";
|
|
12
|
+
export { OINODbDataSet, OINODbMemoryDataSet } from "./OINODbDataSet.js";
|
|
13
|
+
export { OINODbSqlFilter, OINODbSqlOrder, OINODbSqlComparison, OINODbSqlLimit, OINODbSqlBooleanOperation } from "./OINODbRequestParams.js";
|
|
14
|
+
export { OINODbConfig } from "./OINODbConfig.js";
|
|
15
|
+
export { OINODbFactory } from "./OINODbFactory.js";
|
|
16
|
+
export { OINODbSwagger } from "./OINODbSwagger.js";
|
|
17
|
+
/** API parameters */
|
|
18
|
+
export type OINODbApiParams = {
|
|
19
|
+
/** Name of the database table */
|
|
20
|
+
tableName: string;
|
|
21
|
+
/** Reject values that exceed field max length (behaviour on such is platform dependent) */
|
|
22
|
+
failOnOversizedValues?: Boolean;
|
|
23
|
+
/** Reject PUT-requests that contain values for autoinc-type fields */
|
|
24
|
+
failOnUpdateOnAutoinc?: boolean;
|
|
25
|
+
/** Reject POST-requests without primary key value (can work if DB-side ) */
|
|
26
|
+
failOnInsertWithoutKey?: boolean;
|
|
27
|
+
/** Treat date type fields as just strings and use the native formatting instead of the ISO 8601 format */
|
|
28
|
+
useDatesAsString?: Boolean;
|
|
29
|
+
/** Exclude all fields with this prefix from the API */
|
|
30
|
+
excludeFieldPrefix?: string;
|
|
31
|
+
/** Exclude given fields from the API */
|
|
32
|
+
excludeFields?: string[];
|
|
33
|
+
/** Enable hashids for numeric primarykeys by adding a 32 char key */
|
|
34
|
+
hashidKey?: string;
|
|
35
|
+
/** Set (minimum) length (12-32 chars) of the hashids */
|
|
36
|
+
hashidLength?: number;
|
|
37
|
+
/** Make hashids static per row/table */
|
|
38
|
+
hashidRandomIds?: boolean;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Database class (constructor) type
|
|
42
|
+
* @param dbParams database parameters
|
|
43
|
+
*/
|
|
44
|
+
export type OINODbConstructor = new (dbParams: OINODbParams) => OINODb;
|
|
45
|
+
/** Database parameters */
|
|
46
|
+
export type OINODbParams = {
|
|
47
|
+
/** Name of the database class (e.g. OINODbPostgresql) */
|
|
48
|
+
type: string;
|
|
49
|
+
/** Connection URL, either file://-path or an IP-address or an HTTP-url */
|
|
50
|
+
url: string;
|
|
51
|
+
/** Name of the database */
|
|
52
|
+
database: string;
|
|
53
|
+
/** TCP port of the database */
|
|
54
|
+
port?: number;
|
|
55
|
+
/** Username used to authenticate */
|
|
56
|
+
user?: string;
|
|
57
|
+
/** Password used to authenticate */
|
|
58
|
+
password?: string;
|
|
59
|
+
};
|
|
60
|
+
/** Field parameters in database */
|
|
61
|
+
export type OINODbDataFieldParams = {
|
|
62
|
+
/** Is the field a primary key */
|
|
63
|
+
isPrimaryKey: Boolean;
|
|
64
|
+
/** Is the field an auto inc type */
|
|
65
|
+
isAutoInc: Boolean;
|
|
66
|
+
/** Is the field allowed to have null values */
|
|
67
|
+
isNotNull: Boolean;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Callback to filter data fields
|
|
71
|
+
* @param field fields to filter
|
|
72
|
+
*/
|
|
73
|
+
export type OINODbDataFieldFilter = (field: OINODbDataField) => Boolean;
|
|
74
|
+
/** Request options */
|
|
75
|
+
export type OINODbSqlParams = {
|
|
76
|
+
/** Additional SQL select where-conditions */
|
|
77
|
+
filter?: OINODbSqlFilter;
|
|
78
|
+
/** SQL result ordering conditions */
|
|
79
|
+
order?: OINODbSqlOrder;
|
|
80
|
+
/** SQL result limit condition */
|
|
81
|
+
limit?: OINODbSqlLimit;
|
|
82
|
+
};
|
|
83
|
+
/** Request options */
|
|
84
|
+
export type OINORequestParams = {
|
|
85
|
+
/** Content type of the request body */
|
|
86
|
+
requestType?: OINOContentType;
|
|
87
|
+
/** Content type of the response body */
|
|
88
|
+
responseType?: OINOContentType;
|
|
89
|
+
/** Multipart boundary token */
|
|
90
|
+
multipartBoundary?: string;
|
|
91
|
+
/** SQL parameters */
|
|
92
|
+
sqlParams: OINODbSqlParams;
|
|
93
|
+
};
|
|
94
|
+
/** A single column value of a data row */
|
|
95
|
+
export type OINODataCell = string | bigint | number | boolean | Date | Uint8Array | Buffer | null | undefined;
|
|
96
|
+
/** A single data row */
|
|
97
|
+
export type OINODataRow = Array<OINODataCell>;
|
|
98
|
+
/** Empty row instance */
|
|
99
|
+
export declare const OINODB_EMPTY_ROW: OINODataRow;
|
|
100
|
+
/** Empty row array instance */
|
|
101
|
+
export declare const OINODB_EMPTY_ROWS: OINODataRow[];
|
|
102
|
+
/** Key-value collection */
|
|
103
|
+
export type OINOValues = Record<string, string>;
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@oino-ts/db",
|
|
3
|
+
"version": "0.0.11",
|
|
4
|
+
"description": "OINO TS library package for publishing an SQL database tables as a REST API.",
|
|
5
|
+
"author": "Matias Kiviniemi (pragmatta)",
|
|
6
|
+
"license": "MPL-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/pragmatta/oino-ts.git"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"sql",
|
|
13
|
+
"database",
|
|
14
|
+
"rest-api",
|
|
15
|
+
"typescript",
|
|
16
|
+
"library"
|
|
17
|
+
],
|
|
18
|
+
"main": "./dist/cjs/index.js",
|
|
19
|
+
"module": "./dist/esm/index.js",
|
|
20
|
+
"types": "./dist/types/index.d.ts",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@types/node": "^20.14.10",
|
|
23
|
+
"@oino-ts/types": "0.0.11"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/bun": "latest",
|
|
27
|
+
"typedoc": "^0.25.13"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"src/*.ts",
|
|
31
|
+
"dist/cjs/*.js",
|
|
32
|
+
"dist/esm/*.js",
|
|
33
|
+
"dist/types/*.d.ts"
|
|
34
|
+
]
|
|
35
|
+
}
|