@oino-ts/types 0.3.3 → 0.3.4

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.
@@ -1,108 +0,0 @@
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
- }
@@ -1,95 +0,0 @@
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
- * Attempts to moves dataset to the next row, possibly waiting for more data to become available. Returns !isEof().
34
- *
35
- */
36
- abstract next(): Promise<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
- * Attempts to moves dataset to the next row, possibly waiting for more data to become available. Returns !isEof().
82
- *
83
- */
84
- next(): Promise<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
- }
@@ -1,35 +0,0 @@
1
- import { OINODbApi, OINODbApiParams, OINODbParams, OINODb, OINODbConstructor, OINODbApiRequestParams } 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): OINODbApiRequestParams;
35
- }
@@ -1,51 +0,0 @@
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): Promise<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
- * @param serialize serialize the value
48
- *
49
- */
50
- getValueByFieldName(fieldName: string, serialize?: boolean): OINODataCell;
51
- }
@@ -1,53 +0,0 @@
1
- import { OINODbDataModel, OINODataRow, OINODbApiRequestParams } from "./index.js";
2
- /**
3
- * Static factory class for easily creating things based on data
4
- *
5
- */
6
- export declare class OINODbParser {
7
- /**
8
- * Create data rows from request body based on the datamodel.
9
- *
10
- * @param datamodel datamodel of the api
11
- * @param data data as a string or Buffer or object
12
- * @param requestParams parameters
13
- *
14
- */
15
- static createRows(datamodel: OINODbDataModel, data: string | Buffer | object, requestParams: OINODbApiRequestParams): OINODataRow[];
16
- /**
17
- * Create data rows from request body based on the datamodel.
18
- *
19
- * @param datamodel datamodel of the api
20
- * @param data data as a string
21
- * @param requestParams parameters
22
- *
23
- */
24
- static createRowsFromText(datamodel: OINODbDataModel, data: string, requestParams: OINODbApiRequestParams): OINODataRow[];
25
- /**
26
- * Create data rows from request body based on the datamodel.
27
- *
28
- * @param datamodel datamodel of the api
29
- * @param data data as an Buffer
30
- * @param requestParams parameters
31
- *
32
- */
33
- static createRowsFromBlob(datamodel: OINODbDataModel, data: Buffer, requestParams: OINODbApiRequestParams): OINODataRow[];
34
- /**
35
- * Create one data row from javascript object based on the datamodel.
36
- * NOTE! Data assumed to be unserialized i.e. of the native type (string, number, boolean, Buffer)
37
- *
38
- * @param datamodel datamodel of the api
39
- * @param data data as javascript object
40
- *
41
- */
42
- static createRowFromObject(datamodel: OINODbDataModel, data: any): OINODataRow;
43
- private static _findCsvLineEnd;
44
- private static _parseCsvLine;
45
- private static _createRowFromCsv;
46
- private static _createRowFromJsonObj;
47
- private static _createRowFromJson;
48
- private static _findMultipartBoundary;
49
- private static _parseMultipartLine;
50
- private static _multipartHeaderRegex;
51
- private static _createRowFromFormdata;
52
- private static _createRowFromUrlencoded;
53
- }
@@ -1,146 +0,0 @@
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 _descending;
84
- /**
85
- * Constructor for `OINODbSqlOrder`.
86
- *
87
- * @param column_or_array single or array of columns to order on
88
- * @param descending_or_array single or array of booleans if ordes is descending
89
- *
90
- */
91
- constructor(column_or_array: string[] | string, descending_or_array: boolean[] | boolean);
92
- /**
93
- * Constructor for `OINODbSqlOrder` as parser of http parameter.
94
- *
95
- * @param orderString string representation of ordering from HTTP-request
96
- *
97
- */
98
- static parse(orderString: string): OINODbSqlOrder;
99
- /**
100
- * Does filter contain any valid conditions.
101
- *
102
- */
103
- isEmpty(): boolean;
104
- /**
105
- * Print order as SQL condition based on the datamodel of the API.
106
- *
107
- * @param dataModel data model (and database) to use for formatting of values
108
- *
109
- */
110
- toSql(dataModel: OINODbDataModel): string;
111
- }
112
- /**
113
- * Class for limiting the number of results.
114
- *
115
- */
116
- export declare class OINODbSqlLimit {
117
- private static _limitRegex;
118
- private _limit;
119
- private _page;
120
- /**
121
- * Constructor for `OINODbSqlLimit`.
122
- *
123
- * @param limit maximum number of items to return
124
- *
125
- */
126
- constructor(limit: number, page?: number);
127
- /**
128
- * Constructor for `OINODbSqlLimit` as parser of http parameter.
129
- *
130
- * @param limitString string representation of limit from HTTP-request
131
- *
132
- */
133
- static parse(limitString: string): OINODbSqlLimit;
134
- /**
135
- * Does filter contain any valid conditions.
136
- *
137
- */
138
- isEmpty(): boolean;
139
- /**
140
- * Print order as SQL condition based on the datamodel of the API.
141
- *
142
- * @param dataModel data model (and database) to use for formatting of values
143
- *
144
- */
145
- toSql(dataModel: OINODbDataModel): string;
146
- }
@@ -1,201 +0,0 @@
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 `OINODbSqlFilter` 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 `OINODbSqlFilter` 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 _descending;
84
- /**
85
- * Constructor for `OINODbSqlOrder`.
86
- *
87
- * @param column_or_array single or array of columns to order on
88
- * @param descending_or_array single or array of booleans if ordes is descending
89
- *
90
- */
91
- constructor(column_or_array: string[] | string, descending_or_array: boolean[] | boolean);
92
- /**
93
- * Constructor for `OINODbSqlOrder` as parser of http parameter.
94
- *
95
- * @param orderString string representation of ordering from HTTP-request
96
- *
97
- */
98
- static parse(orderString: string): OINODbSqlOrder;
99
- /**
100
- * Does filter contain any valid conditions.
101
- *
102
- */
103
- isEmpty(): boolean;
104
- /**
105
- * Print order as SQL condition based on the datamodel of the API.
106
- *
107
- * @param dataModel data model (and database) to use for formatting of values
108
- *
109
- */
110
- toSql(dataModel: OINODbDataModel): string;
111
- }
112
- /**
113
- * Class for limiting the number of results.
114
- *
115
- */
116
- export declare class OINODbSqlLimit {
117
- private static _limitRegex;
118
- private _limit;
119
- private _page;
120
- /**
121
- * Constructor for `OINODbSqlLimit`.
122
- *
123
- * @param limit maximum number of items to return
124
- * @param page page number to return starting from 1
125
- *
126
- */
127
- constructor(limit: number, page?: number);
128
- /**
129
- * Constructor for `OINODbSqlLimit` as parser of http parameter.
130
- *
131
- * @param limitString string representation of limit from HTTP-request
132
- *
133
- */
134
- static parse(limitString: string): OINODbSqlLimit;
135
- /**
136
- * Does filter contain any valid conditions.
137
- *
138
- */
139
- isEmpty(): boolean;
140
- /**
141
- * Print order as SQL condition based on the datamodel of the API.
142
- *
143
- * @param dataModel data model (and database) to use for formatting of values
144
- *
145
- */
146
- toSql(dataModel: OINODbDataModel): string;
147
- }
148
- /**
149
- * Supported aggregation functions in OINODbSqlAggregate.
150
- * @enum
151
- */
152
- export declare enum OINODbSqlAggregateFunctions {
153
- count = "count",
154
- sum = "sum",
155
- avg = "avg",
156
- min = "min",
157
- max = "max"
158
- }
159
- /**
160
- * Class for limiting the number of results.
161
- *
162
- */
163
- export declare class OINODbSqlAggregate {
164
- private static _aggregateRegex;
165
- private _functions;
166
- private _fields;
167
- /**
168
- * Constructor for `OINODbSqlAggregate`.
169
- *
170
- * @param function aggregate function to use
171
- * @param fields fields to aggregate
172
- *
173
- */
174
- constructor(func: OINODbSqlAggregateFunctions[], fields: string[]);
175
- /**
176
- * Constructor for `OINODbSqlAggregate` as parser of http parameter.
177
- *
178
- * @param aggregatorString string representation of limit from HTTP-request
179
- *
180
- */
181
- static parse(aggregatorString: string): OINODbSqlAggregate;
182
- /**
183
- * Does filter contain any valid conditions.
184
- *
185
- */
186
- isEmpty(): boolean;
187
- /**
188
- * Print non-aggregated fields as SQL GROUP BY-condition based on the datamodel of the API.
189
- *
190
- * @param dataModel data model (and database) to use for formatting of values
191
- *
192
- */
193
- toSql(dataModel: OINODbDataModel): string;
194
- /**
195
- * Print non-aggregated fields as SQL GROUP BY-condition based on the datamodel of the API.
196
- *
197
- * @param dataModel data model (and database) to use for formatting of values
198
- *
199
- */
200
- printSqlColumnNames(dataModel: OINODbDataModel): string;
201
- }