@oino-ts/common 0.21.1 → 1.0.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.
- package/README.md +183 -0
- package/dist/cjs/OINOApi.js +322 -0
- package/dist/cjs/OINOBenchmark.js +3 -4
- package/dist/cjs/OINOConfig.js +104 -0
- package/dist/cjs/OINOConstants.js +42 -0
- package/dist/cjs/OINODataField.js +346 -0
- package/dist/cjs/OINODataModel.js +182 -0
- package/dist/cjs/OINODataSource.js +165 -0
- package/dist/cjs/OINOFormatter.js +6 -5
- package/dist/cjs/OINOHtmlTemplate.js +21 -18
- package/dist/cjs/OINOModelSet.js +333 -0
- package/dist/cjs/OINOParser.js +448 -0
- package/dist/cjs/OINOQueryParams.js +434 -0
- package/dist/cjs/OINORequest.js +21 -13
- package/dist/cjs/OINOResult.js +13 -12
- package/dist/cjs/OINOStr.js +11 -11
- package/dist/cjs/OINOSwagger.js +205 -0
- package/dist/cjs/index.js +57 -39
- package/dist/esm/OINOApi.js +315 -0
- package/dist/esm/OINOBenchmark.js +3 -4
- package/dist/esm/OINOConfig.js +100 -0
- package/dist/esm/OINOConstants.js +39 -0
- package/dist/esm/OINODataField.js +337 -0
- package/dist/esm/OINODataModel.js +178 -0
- package/dist/esm/OINODataSource.js +159 -0
- package/dist/esm/OINOFormatter.js +2 -1
- package/dist/esm/OINOHtmlTemplate.js +4 -1
- package/dist/esm/OINOModelSet.js +329 -0
- package/dist/esm/OINOParser.js +444 -0
- package/dist/esm/OINOQueryParams.js +426 -0
- package/dist/esm/OINORequest.js +9 -1
- package/dist/esm/OINOResult.js +2 -1
- package/dist/esm/OINOStr.js +1 -1
- package/dist/esm/OINOSwagger.js +201 -0
- package/dist/esm/index.js +14 -32
- package/dist/types/OINOApi.d.ts +191 -0
- package/dist/types/OINOBenchmark.d.ts +1 -1
- package/dist/types/OINOConfig.d.ts +63 -0
- package/dist/types/OINOConstants.d.ts +51 -0
- package/dist/types/OINODataField.d.ts +209 -0
- package/dist/types/OINODataModel.d.ts +78 -0
- package/dist/types/OINODataSource.d.ts +184 -0
- package/dist/types/OINOHtmlTemplate.d.ts +1 -1
- package/dist/types/OINOModelSet.d.ts +64 -0
- package/dist/types/OINOParser.d.ts +42 -0
- package/dist/types/OINOQueryParams.d.ts +270 -0
- package/dist/types/OINORequest.d.ts +4 -1
- package/dist/types/OINOResult.d.ts +1 -1
- package/dist/types/OINOStr.d.ts +1 -1
- package/dist/types/OINOSwagger.d.ts +25 -0
- package/dist/types/index.d.ts +14 -31
- package/package.json +32 -32
- package/src/OINOApi.ts +429 -0
- package/src/OINOBenchmark.ts +323 -324
- package/src/OINOConfig.ts +113 -0
- package/src/OINOConstants.ts +59 -0
- package/src/OINODataField.ts +371 -0
- package/src/OINODataModel.ts +187 -0
- package/src/OINODataSource.ts +280 -0
- package/src/OINOFormatter.ts +166 -165
- package/src/OINOHeaders.ts +51 -51
- package/src/OINOHtmlTemplate.test.ts +114 -114
- package/src/OINOHtmlTemplate.ts +225 -222
- package/src/OINOLog.ts +292 -292
- package/src/OINOModelSet.ts +359 -0
- package/src/OINOParser.ts +441 -0
- package/src/OINOQueryParams.ts +449 -0
- package/src/OINORequest.ts +204 -196
- package/src/OINOResult.ts +331 -330
- package/src/OINOStr.ts +254 -254
- package/src/OINOSwagger.ts +213 -0
- package/src/index.ts +18 -38
package/dist/esm/index.js
CHANGED
|
@@ -1,36 +1,18 @@
|
|
|
1
|
+
export { OINOApi, OINOApiRequest, OINOApiResult, OINOApiHtmlTemplate } from "./OINOApi.js";
|
|
1
2
|
export { OINOBenchmark, OINOMemoryBenchmark } from "./OINOBenchmark.js";
|
|
3
|
+
export { OINOConfig } from "./OINOConfig.js";
|
|
4
|
+
export { OINO_ERROR_PREFIX, OINO_WARNING_PREFIX, OINO_INFO_PREFIX, OINO_DEBUG_PREFIX, OINO_REQUEST_TYPE_PARAM, OINO_RESPONSE_TYPE_PARAM, OINOContentType, OINO_EMPTY_ROW, OINO_EMPTY_ROWS } from "./OINOConstants.js";
|
|
5
|
+
export { OINODataModel } from "./OINODataModel.js";
|
|
6
|
+
export { OINODataSource, OINODataSet, OINOMemoryDataset } from "./OINODataSource.js";
|
|
7
|
+
export { OINODataField, OINOStringDataField, OINONumberDataField, OINOBooleanDataField, OINODatetimeDataField, OINOBlobDataField } from "./OINODataField.js";
|
|
8
|
+
export { OINOFormatter, OINO_EMPTY_FORMATTER } from "./OINOFormatter.js";
|
|
9
|
+
export { OINOHeaders } from "./OINOHeaders.js";
|
|
10
|
+
export { OINOHtmlTemplate } from "./OINOHtmlTemplate.js";
|
|
2
11
|
export { OINOLog, OINOLogLevel, OINOConsoleLog } from "./OINOLog.js";
|
|
3
|
-
export {
|
|
12
|
+
export { OINOModelSet } from "./OINOModelSet.js";
|
|
13
|
+
export { OINOParser } from "./OINOParser.js";
|
|
14
|
+
export { OINOQueryBooleanOperation, OINOQueryComparison, OINOQueryNullCheck, OINOQueryAggregateFunctions, OINOQuerySelect, OINOQueryFilter, OINOQueryOrder, OINOQueryLimit, OINOQueryAggregate } from "./OINOQueryParams.js";
|
|
4
15
|
export { OINORequest, OINOHttpRequest } from "./OINORequest.js";
|
|
16
|
+
export { OINOResult, OINOHttpResult } from "./OINOResult.js";
|
|
5
17
|
export { OINOStr } from "./OINOStr.js";
|
|
6
|
-
export {
|
|
7
|
-
export { OINOFormatter, OINO_EMPTY_FORMATTER } from "./OINOFormatter.js";
|
|
8
|
-
export { OINOHeaders } from "./OINOHeaders.js";
|
|
9
|
-
/** OINO error message prefix */
|
|
10
|
-
export const OINO_ERROR_PREFIX = "OINO ERROR";
|
|
11
|
-
/** OINO warning message prefix */
|
|
12
|
-
export const OINO_WARNING_PREFIX = "OINO WARNING";
|
|
13
|
-
/** OINO info message prefix */
|
|
14
|
-
export const OINO_INFO_PREFIX = "OINO INFO";
|
|
15
|
-
/** OINO debug message prefix */
|
|
16
|
-
export const OINO_DEBUG_PREFIX = "OINO DEBUG";
|
|
17
|
-
/** Name of the OINOContentType-parameter request */
|
|
18
|
-
export const OINO_REQUEST_TYPE_PARAM = "oinorequesttype";
|
|
19
|
-
/** Name of the OINOContentType-parameter request */
|
|
20
|
-
export const OINO_RESPONSE_TYPE_PARAM = "oinoresponsetype";
|
|
21
|
-
/**
|
|
22
|
-
* Supported content format mime-types
|
|
23
|
-
*/
|
|
24
|
-
export var OINOContentType;
|
|
25
|
-
(function (OINOContentType) {
|
|
26
|
-
/** JSON encoded data */
|
|
27
|
-
OINOContentType["json"] = "application/json";
|
|
28
|
-
/** CSV encoded data */
|
|
29
|
-
OINOContentType["csv"] = "text/csv";
|
|
30
|
-
/** Multipart encoded form data */
|
|
31
|
-
OINOContentType["formdata"] = "multipart/form-data";
|
|
32
|
-
/** URL encoded form data */
|
|
33
|
-
OINOContentType["urlencode"] = "application/x-www-form-urlencoded";
|
|
34
|
-
/** HTML encoded data (output only) */
|
|
35
|
-
OINOContentType["html"] = "text/html";
|
|
36
|
-
})(OINOContentType || (OINOContentType = {}));
|
|
18
|
+
export { OINOSwagger } from "./OINOSwagger.js";
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { Buffer } from "node:buffer";
|
|
4
|
+
import { OINOHashid } from "@oino-ts/hashid";
|
|
5
|
+
import { OINOContentType, OINODataRow } from "./OINOConstants.js";
|
|
6
|
+
import { OINODataSource } from "./OINODataSource.js";
|
|
7
|
+
import { OINODataModel } from "./OINODataModel.js";
|
|
8
|
+
import { OINOModelSet } from "./OINOModelSet.js";
|
|
9
|
+
import { OINOQueryParams, OINOQueryFilter, OINOQueryOrder, OINOQueryAggregate, OINOQueryLimit, OINOQuerySelect } from "./OINOQueryParams.js";
|
|
10
|
+
import { OINOHttpRequest, OINOHttpRequestInit } from "./OINORequest.js";
|
|
11
|
+
import { OINOHttpResult, OINOResult } from "./OINOResult.js";
|
|
12
|
+
import { OINOHtmlTemplate } from "./OINOHtmlTemplate.js";
|
|
13
|
+
/** API parameters */
|
|
14
|
+
export type OINOApiParams = {
|
|
15
|
+
/** Name of the api */
|
|
16
|
+
apiName: string;
|
|
17
|
+
/** Name of the database table */
|
|
18
|
+
tableName: string;
|
|
19
|
+
/** Reject values that exceed field max length (behaviour on such is platform dependent) */
|
|
20
|
+
failOnOversizedValues?: boolean;
|
|
21
|
+
/** Reject PUT-requests that contain values for autoinc-type fields */
|
|
22
|
+
failOnUpdateOnAutoinc?: boolean;
|
|
23
|
+
/** Reject POST-requests without primary key value (can work if DB-side ) */
|
|
24
|
+
failOnInsertWithoutKey?: boolean;
|
|
25
|
+
/** Reject POST-requests without primary key value (can work if DB-side ) */
|
|
26
|
+
failOnAnyInvalidRows?: boolean;
|
|
27
|
+
/** Treat date type fields as just strings and use the native formatting instead of the ISO 8601 format */
|
|
28
|
+
useDatesAsString?: boolean;
|
|
29
|
+
/** Include given fields from the API and exclude rest (if defined) */
|
|
30
|
+
includeFields?: string[];
|
|
31
|
+
/** Exclude all fields with this prefix from the API */
|
|
32
|
+
excludeFieldPrefix?: string;
|
|
33
|
+
/** Exclude given fields from the API and include rest (if defined) */
|
|
34
|
+
excludeFields?: string[];
|
|
35
|
+
/** Enable hashids for numeric primarykeys by adding a 32 char key */
|
|
36
|
+
hashidKey?: string;
|
|
37
|
+
/** Set (minimum) length (12-32 chars) of the hashids */
|
|
38
|
+
hashidLength?: number;
|
|
39
|
+
/** Make hashids static per row/table */
|
|
40
|
+
hashidStaticIds?: boolean;
|
|
41
|
+
/** Name of field that has the modified field */
|
|
42
|
+
cacheModifiedField?: string;
|
|
43
|
+
/** Return inserted id values */
|
|
44
|
+
returnInsertedIds?: boolean;
|
|
45
|
+
};
|
|
46
|
+
export type OINOApiData = string | OINODataRow[] | Buffer | Uint8Array | object | null;
|
|
47
|
+
export interface OINOApiRequestInit extends OINOHttpRequestInit {
|
|
48
|
+
rowId?: string;
|
|
49
|
+
rowData?: OINOApiData;
|
|
50
|
+
queryParams?: OINOQueryParams;
|
|
51
|
+
filter?: OINOQueryFilter | string;
|
|
52
|
+
order?: OINOQueryOrder | string;
|
|
53
|
+
limit?: OINOQueryLimit | string;
|
|
54
|
+
aggregate?: OINOQueryAggregate | string;
|
|
55
|
+
select?: OINOQuerySelect | string;
|
|
56
|
+
}
|
|
57
|
+
export declare class OINOApiRequest extends OINOHttpRequest {
|
|
58
|
+
rowId: string;
|
|
59
|
+
rowData: OINOApiData;
|
|
60
|
+
queryParams: OINOQueryParams;
|
|
61
|
+
constructor(init: OINOApiRequestInit);
|
|
62
|
+
static fromFetchRequest(request: Request, rowId?: string, rowData?: OINOApiData, queryParams?: OINOQueryParams): Promise<OINOApiRequest>;
|
|
63
|
+
static fromHttpRequest(request: OINOHttpRequest, rowId?: string, rowData?: OINOApiData, queryParams?: OINOQueryParams): OINOApiRequest;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* OINO API request result object with returned data and/or http status code/message and
|
|
67
|
+
* error / warning messages.
|
|
68
|
+
*
|
|
69
|
+
*/
|
|
70
|
+
export declare class OINOApiResult extends OINOResult {
|
|
71
|
+
/** DbApi request params */
|
|
72
|
+
request: OINOApiRequest;
|
|
73
|
+
/** Returned data if any */
|
|
74
|
+
data?: OINOModelSet;
|
|
75
|
+
/**
|
|
76
|
+
* Constructor of OINOApiResult.
|
|
77
|
+
*
|
|
78
|
+
* @param request DbApi request parameters
|
|
79
|
+
* @param data result data
|
|
80
|
+
*
|
|
81
|
+
*/
|
|
82
|
+
constructor(request: OINOApiRequest, data?: OINOModelSet);
|
|
83
|
+
/**
|
|
84
|
+
* Creates a HTTP Response from API results.
|
|
85
|
+
*
|
|
86
|
+
* @param headers Headers to include in the response
|
|
87
|
+
*
|
|
88
|
+
*/
|
|
89
|
+
writeApiResponse(headers?: Record<string, string>): Promise<Response>;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Specialized HTML template that can render ´OINOApiResult´.
|
|
93
|
+
*
|
|
94
|
+
*/
|
|
95
|
+
export declare class OINOApiHtmlTemplate extends OINOHtmlTemplate {
|
|
96
|
+
/** Locale validation regex */
|
|
97
|
+
static LOCALE_REGEX: RegExp;
|
|
98
|
+
/** Locale formatter */
|
|
99
|
+
protected _locale: Intl.DateTimeFormat | null;
|
|
100
|
+
protected _numberDecimals: number;
|
|
101
|
+
/**
|
|
102
|
+
* Constructor of OINOApiHtmlTemplate.
|
|
103
|
+
*
|
|
104
|
+
* @param template HTML template string
|
|
105
|
+
* @param numberDecimals Number of decimals to use for numbers, -1 for no formatting
|
|
106
|
+
* @param dateLocaleStr Datetime format string, either "iso" for ISO8601 or "default" for system default or valid locale string
|
|
107
|
+
* @param dateLocaleStyle Datetime format style, either "short/medium/long/full" or Intl.DateTimeFormat options
|
|
108
|
+
*
|
|
109
|
+
*/
|
|
110
|
+
constructor(template: string, numberDecimals?: number, dateLocaleStr?: string, dateLocaleStyle?: string | any);
|
|
111
|
+
/**
|
|
112
|
+
* Creates HTML Response from API modelset.
|
|
113
|
+
*
|
|
114
|
+
* @param modelset OINO API dataset
|
|
115
|
+
* @param overrideValues values to override in the data
|
|
116
|
+
*
|
|
117
|
+
*/
|
|
118
|
+
renderFromDbData(modelset: OINOModelSet, overrideValues?: any): Promise<OINOHttpResult>;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* API class with method to process HTTP REST requests.
|
|
122
|
+
*
|
|
123
|
+
*/
|
|
124
|
+
export declare abstract class OINOApi {
|
|
125
|
+
/** Enable debug output on errors */
|
|
126
|
+
protected _debugOnError: boolean;
|
|
127
|
+
/** API database reference */
|
|
128
|
+
readonly datasource: OINODataSource;
|
|
129
|
+
/** API parameters */
|
|
130
|
+
readonly params: OINOApiParams;
|
|
131
|
+
/** API hashid */
|
|
132
|
+
readonly hashid: OINOHashid | null;
|
|
133
|
+
/** Is API initialized */
|
|
134
|
+
initialized: boolean;
|
|
135
|
+
/** API datamodel */
|
|
136
|
+
datamodel: OINODataModel | null;
|
|
137
|
+
constructor(datasource: OINODataSource, params: OINOApiParams);
|
|
138
|
+
/**
|
|
139
|
+
* Method for handling a HTTP REST request with GET, POST, PUT, DELETE corresponding to
|
|
140
|
+
* SQL select, insert, update and delete.
|
|
141
|
+
*
|
|
142
|
+
* @param request OINO HTTP request object containing all parameters of the REST request
|
|
143
|
+
* @param rowId URL id of the REST request
|
|
144
|
+
* @param rowData HTTP body data as either serialized string or unserialized JS object or OINODataRow-array or Buffer/Uint8Array binary data
|
|
145
|
+
* @param queryParams SQL parameters for the REST request
|
|
146
|
+
*
|
|
147
|
+
*/
|
|
148
|
+
abstract doHttpRequest(request: OINOHttpRequest, rowId: string, rowData: OINOApiData, queryParams: OINOQueryParams): Promise<OINOApiResult>;
|
|
149
|
+
/**
|
|
150
|
+
* Method for handling a HTTP REST request with GET, POST, PUT, DELETE corresponding to
|
|
151
|
+
* SQL select, insert, update and delete.
|
|
152
|
+
*
|
|
153
|
+
* @param method HTTP method of the REST request
|
|
154
|
+
* @param rowId URL id of the REST request
|
|
155
|
+
* @param rowData HTTP body data as either serialized string or unserialized JS object or OINODataRow-array or Buffer/Uint8Array binary data
|
|
156
|
+
* @param queryParams SQL parameters for the REST request
|
|
157
|
+
* @param contentType content type of the HTTP body data, default is JSON
|
|
158
|
+
*
|
|
159
|
+
*/
|
|
160
|
+
abstract doRequest(method: string, rowId: string, rowData: OINOApiData, queryParams: OINOQueryParams, contentType: OINOContentType): Promise<OINOApiResult>;
|
|
161
|
+
abstract doApiRequest(request: OINOApiRequest): Promise<OINOApiResult>;
|
|
162
|
+
/**
|
|
163
|
+
* Method for handling a HTTP REST request with batch update using PUT or DELETE methods.
|
|
164
|
+
*
|
|
165
|
+
* @param method HTTP method of the REST request
|
|
166
|
+
* @param rowId URL id of the REST request
|
|
167
|
+
* @param rowData HTTP body data as either serialized string or unserialized JS object or OINODataRow-array or Buffer/Uint8Array binary data
|
|
168
|
+
*
|
|
169
|
+
*/
|
|
170
|
+
abstract doBatchUpdate(method: string, rowId: string, rowData: OINOApiData, queryParams?: OINOQueryParams): Promise<OINOApiResult>;
|
|
171
|
+
/**
|
|
172
|
+
* Method for handling a HTTP REST request with batch update using PUT or DELETE methods.
|
|
173
|
+
*
|
|
174
|
+
* @param request HTTP URL parameters as key-value-pairs
|
|
175
|
+
*
|
|
176
|
+
*/
|
|
177
|
+
abstract doBatchApiRequest(request: OINOApiRequest): Promise<OINOApiResult>;
|
|
178
|
+
/**
|
|
179
|
+
* Enable or disable debug output on errors.
|
|
180
|
+
*
|
|
181
|
+
* @param debugOnError true to enable debug output on errors, false to disable
|
|
182
|
+
*/
|
|
183
|
+
setDebugOnError(debugOnError: boolean): void;
|
|
184
|
+
/**
|
|
185
|
+
* Method to check if a field is included in the API params.
|
|
186
|
+
*
|
|
187
|
+
* @param fieldName name of the field
|
|
188
|
+
*
|
|
189
|
+
*/
|
|
190
|
+
isFieldIncluded(fieldName: string): boolean;
|
|
191
|
+
}
|
|
@@ -105,7 +105,7 @@ export declare abstract class OINOBenchmark {
|
|
|
105
105
|
static trackMetric(module: string, method: string, value: number, success?: boolean): void;
|
|
106
106
|
protected abstract _trackException(module: string, method: string, name: string, message: string, stack: string): void;
|
|
107
107
|
/**
|
|
108
|
-
* Track an exception
|
|
108
|
+
* Track an exception. Does not consider enabled modules.
|
|
109
109
|
*
|
|
110
110
|
* @param module of the benchmark
|
|
111
111
|
* @param method of the benchmark
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** Set the name of the OINO ID field (default \_OINOID\_) */
|
|
2
|
+
export declare class OINOConfig {
|
|
3
|
+
/** Name of the synthetic OINO ID field */
|
|
4
|
+
static OINO_ID_FIELD: string;
|
|
5
|
+
/** Private key separator of the synthetic OINO ID field */
|
|
6
|
+
static OINO_ID_SEPARATOR: string;
|
|
7
|
+
private static OINO_ID_SEPARATOR_ESCAPED;
|
|
8
|
+
/** Name of the OINODbQueryFilter-parameter in request */
|
|
9
|
+
static OINO_QUERY_FILTER_PARAM: string;
|
|
10
|
+
/** Name of the OINODbQueryOrder-parameter in request */
|
|
11
|
+
static OINO_QUERY_ORDER_PARAM: string;
|
|
12
|
+
/** Name of the OINODbQueryLimit-parameter in request */
|
|
13
|
+
static OINO_QUERY_LIMIT_PARAM: string;
|
|
14
|
+
/** Name of the OINODbQueryAggregate-parameter in request */
|
|
15
|
+
static OINO_QUERY_AGGREGATE_PARAM: string;
|
|
16
|
+
/** Name of the OINODbSqlSelect-parameter in request */
|
|
17
|
+
static OINO_QUERY_SELECT_PARAM: string;
|
|
18
|
+
/**
|
|
19
|
+
* Set the name of the OINO ID field
|
|
20
|
+
* @param idField name of the OINO ID field
|
|
21
|
+
*/
|
|
22
|
+
static setOinoIdField(idField: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* Set the separator character of the OINO ID field
|
|
25
|
+
* @param idSeparator character to use as separator of id parts
|
|
26
|
+
*/
|
|
27
|
+
static setOinoIdSeparator(idSeparator: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Print OINO ID for primary key values.
|
|
30
|
+
*
|
|
31
|
+
* @param primaryKeys an array of primary key values.
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
34
|
+
static printOINOId(primaryKeys: string[]): string;
|
|
35
|
+
/**
|
|
36
|
+
* Print OINO ID for primary key values.
|
|
37
|
+
*
|
|
38
|
+
* @param oinoid the OINO ID string to parse as primary key values.
|
|
39
|
+
*
|
|
40
|
+
*/
|
|
41
|
+
static parseOINOId(oinoid: string): string[];
|
|
42
|
+
/**
|
|
43
|
+
* Set the name of the OINODbQueryFilter-param field
|
|
44
|
+
*
|
|
45
|
+
* @param sqlFilterParam name of the http parameter with `OINODbQueryFilter` definition
|
|
46
|
+
*
|
|
47
|
+
*/
|
|
48
|
+
static setOinoQueryFilterParam(sqlFilterParam: string): void;
|
|
49
|
+
/**
|
|
50
|
+
* Set the name of the OINODbQueryOrder-param field
|
|
51
|
+
*
|
|
52
|
+
* @param sqlOrderParam name of the http parameter with `OINODbQueryOrder` definition
|
|
53
|
+
*
|
|
54
|
+
*/
|
|
55
|
+
static setOinoQueryOrderParam(sqlOrderParam: string): void;
|
|
56
|
+
/**
|
|
57
|
+
* Set the name of the OINODbQueryLimit-param field
|
|
58
|
+
*
|
|
59
|
+
* @param sqlLimitParam name of the http parameter with `OINODbQueryLimit` definition
|
|
60
|
+
*
|
|
61
|
+
*/
|
|
62
|
+
static setOinoQueryLimitParam(sqlLimitParam: string): void;
|
|
63
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { Buffer } from "node:buffer";
|
|
4
|
+
/** OINO error message prefix */
|
|
5
|
+
export declare const OINO_ERROR_PREFIX = "OINO ERROR";
|
|
6
|
+
/** OINO warning message prefix */
|
|
7
|
+
export declare const OINO_WARNING_PREFIX = "OINO WARNING";
|
|
8
|
+
/** OINO info message prefix */
|
|
9
|
+
export declare const OINO_INFO_PREFIX = "OINO INFO";
|
|
10
|
+
/** OINO debug message prefix */
|
|
11
|
+
export declare const OINO_DEBUG_PREFIX = "OINO DEBUG";
|
|
12
|
+
/** Name of the OINOContentType-parameter request */
|
|
13
|
+
export declare const OINO_REQUEST_TYPE_PARAM = "oinorequesttype";
|
|
14
|
+
/** Name of the OINOContentType-parameter request */
|
|
15
|
+
export declare const OINO_RESPONSE_TYPE_PARAM = "oinoresponsetype";
|
|
16
|
+
/** Name of the query parameter that triggers a file download response */
|
|
17
|
+
export declare const OINO_RESPONSE_DOWNLOAD_PARAM = "oinoresponsedownload";
|
|
18
|
+
/**
|
|
19
|
+
* Supported content format mime-types
|
|
20
|
+
*/
|
|
21
|
+
export declare enum OINOContentType {
|
|
22
|
+
/** JSON encoded data */
|
|
23
|
+
json = "application/json",
|
|
24
|
+
/** CSV encoded data */
|
|
25
|
+
csv = "text/csv",
|
|
26
|
+
/** Multipart encoded form data */
|
|
27
|
+
formdata = "multipart/form-data",
|
|
28
|
+
/** URL encoded form data */
|
|
29
|
+
urlencode = "application/x-www-form-urlencoded",
|
|
30
|
+
/** HTML encoded data (output only) */
|
|
31
|
+
html = "text/html"
|
|
32
|
+
}
|
|
33
|
+
/** Field parameters in database */
|
|
34
|
+
export type OINODataFieldParams = {
|
|
35
|
+
/** Is the field a primary key */
|
|
36
|
+
isPrimaryKey: boolean;
|
|
37
|
+
/** Is the field a primary key */
|
|
38
|
+
isForeignKey: boolean;
|
|
39
|
+
/** Is the field an auto inc type */
|
|
40
|
+
isAutoInc: boolean;
|
|
41
|
+
/** Is the field allowed to have null values */
|
|
42
|
+
isNotNull: boolean;
|
|
43
|
+
};
|
|
44
|
+
/** A single column value of a data row */
|
|
45
|
+
export type OINODataCell = string | bigint | number | boolean | Date | Uint8Array | Buffer | null | undefined;
|
|
46
|
+
/** A single data row */
|
|
47
|
+
export type OINODataRow = Array<OINODataCell>;
|
|
48
|
+
/** Empty row instance */
|
|
49
|
+
export declare const OINO_EMPTY_ROW: OINODataRow;
|
|
50
|
+
/** Empty row array instance */
|
|
51
|
+
export declare const OINO_EMPTY_ROWS: OINODataRow[];
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { OINODataFieldParams, OINODataCell } from "./OINOConstants.js";
|
|
2
|
+
import { OINODataSource } from "./OINODataSource.js";
|
|
3
|
+
/**
|
|
4
|
+
* Base class for a column of data responsible for appropriatelly serializing/deserializing the data.
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
export declare class OINODataField {
|
|
8
|
+
/** OINO data source reference*/
|
|
9
|
+
readonly datasource: OINODataSource;
|
|
10
|
+
/** Name of the field */
|
|
11
|
+
readonly name: string;
|
|
12
|
+
/** Internal type of field*/
|
|
13
|
+
readonly type: string;
|
|
14
|
+
/** SQL type of the field */
|
|
15
|
+
readonly nativeType: string;
|
|
16
|
+
/** Maximum length of the field (or 0) */
|
|
17
|
+
readonly maxLength: number;
|
|
18
|
+
/** Parameters for the field */
|
|
19
|
+
readonly fieldParams: OINODataFieldParams;
|
|
20
|
+
/**
|
|
21
|
+
* Constructor for a data field
|
|
22
|
+
*
|
|
23
|
+
* @param datasource OINO data source reference
|
|
24
|
+
* @param name name of the field
|
|
25
|
+
* @param type internal type of the field
|
|
26
|
+
* @param nativeType column type in database
|
|
27
|
+
* @param fieldParams parameters of the field
|
|
28
|
+
* @param maxLength maximum length of the field (or 0)
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
constructor(datasource: OINODataSource, name: string, type: string, nativeType: string, fieldParams: OINODataFieldParams, maxLength?: number);
|
|
32
|
+
/**
|
|
33
|
+
* Serialize cell value in the given content format.
|
|
34
|
+
*
|
|
35
|
+
* @param cellVal cell value
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
38
|
+
serializeCell(cellVal: OINODataCell): string | null | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Parce cell value from string using field type specific formatting rules.
|
|
41
|
+
*
|
|
42
|
+
* @param value string value
|
|
43
|
+
*
|
|
44
|
+
*/
|
|
45
|
+
deserializeCell(value: string | null | undefined): OINODataCell;
|
|
46
|
+
/**
|
|
47
|
+
* Print data cell (from deserialization) as SQL-string.
|
|
48
|
+
*
|
|
49
|
+
* @param cellVal cell value
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
printCellAsValue(cellVal: OINODataCell): string;
|
|
53
|
+
/**
|
|
54
|
+
* Print name of column as SQL.
|
|
55
|
+
*
|
|
56
|
+
*/
|
|
57
|
+
printColumnName(): string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Specialised class for a string column.
|
|
61
|
+
*
|
|
62
|
+
*/
|
|
63
|
+
export declare class OINOStringDataField extends OINODataField {
|
|
64
|
+
/**
|
|
65
|
+
* Constructor for a string data field
|
|
66
|
+
*
|
|
67
|
+
* @param datasource OINO data source reference
|
|
68
|
+
* @param name name of the field
|
|
69
|
+
* @param nativeType column type in database
|
|
70
|
+
* @param fieldParams parameters of the field
|
|
71
|
+
* @param maxLength maximum length of the field (or 0)
|
|
72
|
+
*
|
|
73
|
+
*/
|
|
74
|
+
constructor(datasource: OINODataSource, name: string, nativeType: string, fieldParams: OINODataFieldParams, maxLength: number);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Specialised class for a boolean column.
|
|
78
|
+
*
|
|
79
|
+
*/
|
|
80
|
+
export declare class OINOBooleanDataField extends OINODataField {
|
|
81
|
+
/**
|
|
82
|
+
* Constructor for a boolean data field
|
|
83
|
+
*
|
|
84
|
+
* @param datasource OINO data source reference
|
|
85
|
+
* @param name name of the field
|
|
86
|
+
* @param nativeType column type in database
|
|
87
|
+
* @param fieldParams parameters of the field
|
|
88
|
+
*
|
|
89
|
+
*/
|
|
90
|
+
constructor(datasource: OINODataSource, name: string, nativeType: string, fieldParams: OINODataFieldParams);
|
|
91
|
+
/**
|
|
92
|
+
* Serialize cell value in the given content format.
|
|
93
|
+
*
|
|
94
|
+
* @param cellVal cell value
|
|
95
|
+
*
|
|
96
|
+
*/
|
|
97
|
+
serializeCell(cellVal: OINODataCell): string | null | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* Parce cell value from string using field type specific formatting rules.
|
|
100
|
+
*
|
|
101
|
+
* @param value string value
|
|
102
|
+
*
|
|
103
|
+
*/
|
|
104
|
+
deserializeCell(value: string | null | undefined): OINODataCell;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Specialised class for a number column.
|
|
108
|
+
*
|
|
109
|
+
*/
|
|
110
|
+
export declare class OINONumberDataField extends OINODataField {
|
|
111
|
+
/**
|
|
112
|
+
* Constructor for a string data field
|
|
113
|
+
*
|
|
114
|
+
* @param datasource OINO data source reference
|
|
115
|
+
* @param name name of the field
|
|
116
|
+
* @param nativeType column type in database
|
|
117
|
+
* @param fieldParams parameters of the field
|
|
118
|
+
*
|
|
119
|
+
*/
|
|
120
|
+
constructor(datasource: OINODataSource, name: string, nativeType: string, fieldParams: OINODataFieldParams);
|
|
121
|
+
/**
|
|
122
|
+
* Serialize cell value in the given content format.
|
|
123
|
+
*
|
|
124
|
+
* @param cellVal cell value
|
|
125
|
+
*
|
|
126
|
+
*/
|
|
127
|
+
serializeCell(cellVal: OINODataCell): string | null | undefined;
|
|
128
|
+
/**
|
|
129
|
+
* Parce cell value from string using field type specific formatting rules.
|
|
130
|
+
*
|
|
131
|
+
* @param value string value
|
|
132
|
+
*
|
|
133
|
+
*/
|
|
134
|
+
deserializeCell(value: string | null | undefined): OINODataCell;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Specialised class for a blob column.
|
|
138
|
+
*
|
|
139
|
+
*/
|
|
140
|
+
export declare class OINOBlobDataField extends OINODataField {
|
|
141
|
+
/**
|
|
142
|
+
* Constructor for a blob data field
|
|
143
|
+
*
|
|
144
|
+
* @param datasource OINO data source reference
|
|
145
|
+
* @param name name of the field
|
|
146
|
+
* @param nativeType column type in database
|
|
147
|
+
* @param fieldParams parameters of the field
|
|
148
|
+
* @param maxLength maximum length of the field (or 0)
|
|
149
|
+
*
|
|
150
|
+
*/
|
|
151
|
+
constructor(datasource: OINODataSource, name: string, nativeType: string, fieldParams: OINODataFieldParams, maxLength: number);
|
|
152
|
+
/**
|
|
153
|
+
* Serialize cell value in the given content format.
|
|
154
|
+
*
|
|
155
|
+
* @param cellVal cell value
|
|
156
|
+
*
|
|
157
|
+
*/
|
|
158
|
+
serializeCell(cellVal: OINODataCell): string | null | undefined;
|
|
159
|
+
/**
|
|
160
|
+
* Parce cell value from string using field type specific formatting rules.
|
|
161
|
+
*
|
|
162
|
+
* @param value string value
|
|
163
|
+
*
|
|
164
|
+
*/
|
|
165
|
+
deserializeCell(value: string | null | undefined): OINODataCell;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Specialised class for a datetime column.
|
|
169
|
+
*
|
|
170
|
+
*/
|
|
171
|
+
export declare class OINODatetimeDataField extends OINODataField {
|
|
172
|
+
/**
|
|
173
|
+
* Constructor for a string data field
|
|
174
|
+
*
|
|
175
|
+
* @param datasource OINO data source reference
|
|
176
|
+
* @param name name of the field
|
|
177
|
+
* @param nativeType column type in database
|
|
178
|
+
* @param fieldParams parameters of the field
|
|
179
|
+
*
|
|
180
|
+
*/
|
|
181
|
+
constructor(datasource: OINODataSource, name: string, nativeType: string, fieldParams: OINODataFieldParams);
|
|
182
|
+
/**
|
|
183
|
+
* Serialize cell value in the given content format.
|
|
184
|
+
*
|
|
185
|
+
* @param cellVal cell value
|
|
186
|
+
*
|
|
187
|
+
*/
|
|
188
|
+
serializeCell(cellVal: OINODataCell): string | null | undefined;
|
|
189
|
+
/**
|
|
190
|
+
* Serialize cell value in the given content format.
|
|
191
|
+
*
|
|
192
|
+
* @param cellVal cell value
|
|
193
|
+
* @param locale locale-object to format datetimes with
|
|
194
|
+
*
|
|
195
|
+
*/
|
|
196
|
+
serializeCellWithLocale(cellVal: OINODataCell, locale: Intl.DateTimeFormat): string | null | undefined;
|
|
197
|
+
/**
|
|
198
|
+
* Parce cell value from string using field type specific formatting rules.
|
|
199
|
+
*
|
|
200
|
+
* @param value string value
|
|
201
|
+
*
|
|
202
|
+
*/
|
|
203
|
+
deserializeCell(value: string | null | undefined): OINODataCell;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Callback to filter data fields
|
|
207
|
+
* @param field fields to filter
|
|
208
|
+
*/
|
|
209
|
+
export type OINODataFieldFilter = (field: OINODataField) => Boolean;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { OINODataRow } from "./OINOConstants.js";
|
|
2
|
+
import { OINOApi } from "./OINOApi.js";
|
|
3
|
+
import { OINODataField, OINODataFieldFilter } from "./OINODataField.js";
|
|
4
|
+
/**
|
|
5
|
+
* OINO Datamodel object for representing one database table and it's columns.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
export declare class OINODataModel {
|
|
9
|
+
private _fieldIndexLookup;
|
|
10
|
+
/** Database refererence of the table */
|
|
11
|
+
readonly api: OINOApi;
|
|
12
|
+
/** Field refererences of the API */
|
|
13
|
+
readonly fields: OINODataField[];
|
|
14
|
+
/**
|
|
15
|
+
* Constructor of the data model.
|
|
16
|
+
* NOTE! OINODbDataModel.initialize must be called after constructor to populate fields.
|
|
17
|
+
*
|
|
18
|
+
* @param api api of the data model
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
constructor(api: OINOApi);
|
|
22
|
+
/**
|
|
23
|
+
* Add a field to the datamodel.
|
|
24
|
+
*
|
|
25
|
+
* @param field dataset field
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
addField(field: OINODataField): void;
|
|
29
|
+
/**
|
|
30
|
+
* Find a field of a given name if any.
|
|
31
|
+
*
|
|
32
|
+
* @param name name of the field to find
|
|
33
|
+
*
|
|
34
|
+
*/
|
|
35
|
+
findFieldByName(name: string): OINODataField | null;
|
|
36
|
+
/**
|
|
37
|
+
* Find index of a field of a given name if any.
|
|
38
|
+
*
|
|
39
|
+
* @param name name of the field to find
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
findFieldIndexByName(name: string): number;
|
|
43
|
+
/**
|
|
44
|
+
* Find all fields based of given filter callback criteria (e.g. fields of certain data type, primary keys etc.)
|
|
45
|
+
*
|
|
46
|
+
* @param filter callback called for each field to include or not
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
filterFields(filter: OINODataFieldFilter): OINODataField[];
|
|
50
|
+
/**
|
|
51
|
+
* Return the primary key values of one row in order of the data model
|
|
52
|
+
*
|
|
53
|
+
* @param row data row
|
|
54
|
+
* @param hashidValues apply hashid when applicable
|
|
55
|
+
*
|
|
56
|
+
*/
|
|
57
|
+
getRowPrimarykeyValues(row: OINODataRow, hashidValues?: boolean): string[];
|
|
58
|
+
/**
|
|
59
|
+
* Pring debug information for the field
|
|
60
|
+
*
|
|
61
|
+
* @param length length of the debug output (or 0 for as long as needed)
|
|
62
|
+
*
|
|
63
|
+
*/
|
|
64
|
+
printColumnDebug(field: OINODataField, length?: number): 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
|
+
}
|