@oino-ts/types 0.0.17 → 0.1.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/db/src/OINODb.d.ts +180 -0
- package/db/src/OINODbApi.d.ts +82 -0
- package/db/src/OINODbConfig.d.ts +52 -0
- package/db/src/OINODbDataField.d.ts +202 -0
- package/db/src/OINODbDataModel.d.ts +108 -0
- package/db/src/OINODbDataSet.d.ts +95 -0
- package/db/src/OINODbFactory.d.ts +35 -0
- package/db/src/OINODbModelSet.d.ts +51 -0
- package/db/src/OINODbParser.d.ts +53 -0
- package/db/src/OINODbRequestParams.d.ts +146 -0
- package/db/src/OINODbSqlParams.d.ts +147 -0
- package/db/src/OINODbSwagger.d.ts +25 -0
- package/db/src/index.d.ts +111 -0
- package/db-bunsqlite/src/OINODbBunSqlite.d.ts +77 -0
- package/db-bunsqlite/src/index.d.ts +1 -0
- package/db-mariadb/src/OINODbMariadb.d.ts +78 -0
- package/db-mariadb/src/index.d.ts +1 -0
- package/db-mssql/src/OINODbMsSql.d.ts +86 -0
- package/db-mssql/src/index.d.ts +1 -0
- package/db-postgresql/src/OINODbPostgresql.d.ts +76 -0
- package/db-postgresql/src/index.d.ts +1 -0
- package/hashid/src/OINOHashid.d.ts +40 -0
- package/hashid/src/index.d.ts +1 -0
- package/index.d.ts +23 -0
- package/package.json +5 -8
- package/README.md +0 -193
- package/dist/cjs/OINOBenchmark.js +0 -108
- package/dist/cjs/OINOHtmlTemplate.js +0 -177
- package/dist/cjs/OINOLog.js +0 -140
- package/dist/cjs/OINOResult.js +0 -216
- package/dist/cjs/OINOStr.js +0 -265
- package/dist/cjs/index.js +0 -40
- package/dist/esm/OINOBenchmark.js +0 -104
- package/dist/esm/OINOHtmlTemplate.js +0 -173
- package/dist/esm/OINOLog.js +0 -135
- package/dist/esm/OINOResult.js +0 -211
- package/dist/esm/OINOStr.js +0 -261
- package/dist/esm/index.js +0 -29
- package/src/OINOBenchmark.ts +0 -112
- package/src/OINOHtmlTemplate.ts +0 -186
- package/src/OINOLog.ts +0 -160
- package/src/OINOResult.ts +0 -234
- package/src/OINOStr.ts +0 -254
- package/src/index.ts +0 -31
- /package/{dist/types → common/src}/OINOBenchmark.d.ts +0 -0
- /package/{dist/types → common/src}/OINOHtmlTemplate.d.ts +0 -0
- /package/{dist/types → common/src}/OINOLog.d.ts +0 -0
- /package/{dist/types → common/src}/OINOResult.d.ts +0 -0
- /package/{dist/types → common/src}/OINOStr.d.ts +0 -0
- /package/{dist/types → common/src}/index.d.ts +0 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { OINODb, OINODbParams, OINODbDataSet, OINODbApi, OINODataCell } from "@oino-ts/db";
|
|
2
|
+
/**
|
|
3
|
+
* Implementation of BunSqlite-database.
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
export declare class OINODbBunSqlite extends OINODb {
|
|
7
|
+
private static _tableDescriptionRegex;
|
|
8
|
+
private static _tablePrimarykeyRegex;
|
|
9
|
+
private static _tableForeignkeyRegex;
|
|
10
|
+
private static _tableFieldTypeRegex;
|
|
11
|
+
private _db;
|
|
12
|
+
/**
|
|
13
|
+
* OINODbBunSqlite constructor
|
|
14
|
+
* @param params database parameters
|
|
15
|
+
*/
|
|
16
|
+
constructor(params: OINODbParams);
|
|
17
|
+
private _parseDbFieldParams;
|
|
18
|
+
/**
|
|
19
|
+
* Print a table name using database specific SQL escaping.
|
|
20
|
+
*
|
|
21
|
+
* @param sqlTable name of the table
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
printSqlTablename(sqlTable: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Print a column name with correct SQL escaping.
|
|
27
|
+
*
|
|
28
|
+
* @param sqlColumn name of the column
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
printSqlColumnname(sqlColumn: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Print a single data value from serialization using the context of the native data
|
|
34
|
+
* type with the correct SQL escaping.
|
|
35
|
+
*
|
|
36
|
+
* @param cellValue data from sql results
|
|
37
|
+
* @param sqlType native type name for table column
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
40
|
+
printCellAsSqlValue(cellValue: OINODataCell, sqlType: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Parse a single SQL result value for serialization using the context of the native data
|
|
43
|
+
* type.
|
|
44
|
+
*
|
|
45
|
+
* @param sqlValue data from serialization
|
|
46
|
+
* @param sqlType native type name for table column
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
parseSqlValueAsCell(sqlValue: OINODataCell, sqlType: string): OINODataCell;
|
|
50
|
+
/**
|
|
51
|
+
* Connect to database.
|
|
52
|
+
*
|
|
53
|
+
*/
|
|
54
|
+
connect(): Promise<boolean>;
|
|
55
|
+
/**
|
|
56
|
+
* Execute a select operation.
|
|
57
|
+
*
|
|
58
|
+
* @param sql SQL statement.
|
|
59
|
+
*
|
|
60
|
+
*/
|
|
61
|
+
sqlSelect(sql: string): Promise<OINODbDataSet>;
|
|
62
|
+
/**
|
|
63
|
+
* Execute other sql operations.
|
|
64
|
+
*
|
|
65
|
+
* @param sql SQL statement.
|
|
66
|
+
*
|
|
67
|
+
*/
|
|
68
|
+
sqlExec(sql: string): Promise<OINODbDataSet>;
|
|
69
|
+
/**
|
|
70
|
+
* Initialize a data model by getting the SQL schema and populating OINODbDataFields of
|
|
71
|
+
* the model.
|
|
72
|
+
*
|
|
73
|
+
* @param api api which data model to initialize.
|
|
74
|
+
*
|
|
75
|
+
*/
|
|
76
|
+
initializeApiDatamodel(api: OINODbApi): Promise<void>;
|
|
77
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { OINODbBunSqlite } from "./OINODbBunSqlite.js";
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { OINODb, OINODbParams, OINODbDataSet, OINODbApi, OINODataCell } from "@oino-ts/db";
|
|
2
|
+
/**
|
|
3
|
+
* Implementation of MariaDb/MySql-database.
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
export declare class OINODbMariadb extends OINODb {
|
|
7
|
+
private static _fieldLengthRegex;
|
|
8
|
+
private static _exceptionMessageRegex;
|
|
9
|
+
private _pool;
|
|
10
|
+
/**
|
|
11
|
+
* Constructor of `OINODbMariadb`
|
|
12
|
+
* @param params database parameters
|
|
13
|
+
*/
|
|
14
|
+
constructor(params: OINODbParams);
|
|
15
|
+
private _parseFieldLength;
|
|
16
|
+
private _query;
|
|
17
|
+
private _exec;
|
|
18
|
+
/**
|
|
19
|
+
* Print a table name using database specific SQL escaping.
|
|
20
|
+
*
|
|
21
|
+
* @param sqlTable name of the table
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
printSqlTablename(sqlTable: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Print a column name with correct SQL escaping.
|
|
27
|
+
*
|
|
28
|
+
* @param sqlColumn name of the column
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
printSqlColumnname(sqlColumn: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Print a single data value from serialization using the context of the native data
|
|
34
|
+
* type with the correct SQL escaping.
|
|
35
|
+
*
|
|
36
|
+
* @param cellValue data from sql results
|
|
37
|
+
* @param sqlType native type name for table column
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
40
|
+
printCellAsSqlValue(cellValue: OINODataCell, sqlType: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Parse a single SQL result value for serialization using the context of the native data
|
|
43
|
+
* type.
|
|
44
|
+
*
|
|
45
|
+
* @param sqlValue data from serialization
|
|
46
|
+
* @param sqlType native type name for table column
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
parseSqlValueAsCell(sqlValue: OINODataCell, sqlType: string): OINODataCell;
|
|
50
|
+
/**
|
|
51
|
+
* Connect to database.
|
|
52
|
+
*
|
|
53
|
+
*/
|
|
54
|
+
connect(): Promise<boolean>;
|
|
55
|
+
/**
|
|
56
|
+
* Execute a select operation.
|
|
57
|
+
*
|
|
58
|
+
* @param sql SQL statement.
|
|
59
|
+
*
|
|
60
|
+
*/
|
|
61
|
+
sqlSelect(sql: string): Promise<OINODbDataSet>;
|
|
62
|
+
/**
|
|
63
|
+
* Execute other sql operations.
|
|
64
|
+
*
|
|
65
|
+
* @param sql SQL statement.
|
|
66
|
+
*
|
|
67
|
+
*/
|
|
68
|
+
sqlExec(sql: string): Promise<OINODbDataSet>;
|
|
69
|
+
private _getSchemaSql;
|
|
70
|
+
/**
|
|
71
|
+
* Initialize a data model by getting the SQL schema and populating OINODbDataFields of
|
|
72
|
+
* the model.
|
|
73
|
+
*
|
|
74
|
+
* @param api api which data model to initialize.
|
|
75
|
+
*
|
|
76
|
+
*/
|
|
77
|
+
initializeApiDatamodel(api: OINODbApi): Promise<void>;
|
|
78
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { OINODbMariadb } from "./OINODbMariadb.js";
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { OINODb, OINODbParams, OINODbDataSet, OINODbApi, OINODataCell } from "@oino-ts/db";
|
|
2
|
+
/**
|
|
3
|
+
* Implementation of MariaDb/MySql-database.
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
export declare class OINODbMsSql extends OINODb {
|
|
7
|
+
private _pool;
|
|
8
|
+
/**
|
|
9
|
+
* Constructor of `OINODbMsSql`
|
|
10
|
+
* @param params database parameters
|
|
11
|
+
*/
|
|
12
|
+
constructor(params: OINODbParams);
|
|
13
|
+
private _query;
|
|
14
|
+
private _exec;
|
|
15
|
+
/**
|
|
16
|
+
* Print a table name using database specific SQL escaping.
|
|
17
|
+
*
|
|
18
|
+
* @param sqlTable name of the table
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
printSqlTablename(sqlTable: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Print a column name with correct SQL escaping.
|
|
24
|
+
*
|
|
25
|
+
* @param sqlColumn name of the column
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
printSqlColumnname(sqlColumn: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Print a single data value from serialization using the context of the native data
|
|
31
|
+
* type with the correct SQL escaping.
|
|
32
|
+
*
|
|
33
|
+
* @param cellValue data from sql results
|
|
34
|
+
* @param sqlType native type name for table column
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
37
|
+
printCellAsSqlValue(cellValue: OINODataCell, sqlType: string): string;
|
|
38
|
+
/**
|
|
39
|
+
* Parse a single SQL result value for serialization using the context of the native data
|
|
40
|
+
* type.
|
|
41
|
+
*
|
|
42
|
+
* @param sqlValue data from serialization
|
|
43
|
+
* @param sqlType native type name for table column
|
|
44
|
+
*
|
|
45
|
+
*/
|
|
46
|
+
parseSqlValueAsCell(sqlValue: OINODataCell, sqlType: string): OINODataCell;
|
|
47
|
+
/**
|
|
48
|
+
* Print SQL select statement with DB specific formatting.
|
|
49
|
+
*
|
|
50
|
+
* @param tableName - The name of the table to select from.
|
|
51
|
+
* @param columnNames - The columns to be selected.
|
|
52
|
+
* @param whereCondition - The WHERE clause to filter the results.
|
|
53
|
+
* @param orderCondition - The ORDER BY clause to sort the results.
|
|
54
|
+
* @param limitCondition - The LIMIT clause to limit the number of results.
|
|
55
|
+
*
|
|
56
|
+
*/
|
|
57
|
+
printSqlSelect(tableName: string, columnNames: string, whereCondition: string, orderCondition: string, limitCondition: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* Connect to database.
|
|
60
|
+
*
|
|
61
|
+
*/
|
|
62
|
+
connect(): Promise<boolean>;
|
|
63
|
+
/**
|
|
64
|
+
* Execute a select operation.
|
|
65
|
+
*
|
|
66
|
+
* @param sql SQL statement.
|
|
67
|
+
*
|
|
68
|
+
*/
|
|
69
|
+
sqlSelect(sql: string): Promise<OINODbDataSet>;
|
|
70
|
+
/**
|
|
71
|
+
* Execute other sql operations.
|
|
72
|
+
*
|
|
73
|
+
* @param sql SQL statement.
|
|
74
|
+
*
|
|
75
|
+
*/
|
|
76
|
+
sqlExec(sql: string): Promise<OINODbDataSet>;
|
|
77
|
+
private _getSchemaSql;
|
|
78
|
+
/**
|
|
79
|
+
* Initialize a data model by getting the SQL schema and populating OINODbDataFields of
|
|
80
|
+
* the model.
|
|
81
|
+
*
|
|
82
|
+
* @param api api which data model to initialize.
|
|
83
|
+
*
|
|
84
|
+
*/
|
|
85
|
+
initializeApiDatamodel(api: OINODbApi): Promise<void>;
|
|
86
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { OINODbMsSql } from "./OINODbMsSql.js";
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { OINODb, OINODbParams, OINODbDataSet, OINODbApi, OINODataCell } from "@oino-ts/db";
|
|
2
|
+
/**
|
|
3
|
+
* Implementation of Postgresql-database.
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
export declare class OINODbPostgresql extends OINODb {
|
|
7
|
+
private _pool;
|
|
8
|
+
/**
|
|
9
|
+
* Constructor of `OINODbPostgresql`
|
|
10
|
+
* @param params database paraneters
|
|
11
|
+
*/
|
|
12
|
+
constructor(params: OINODbParams);
|
|
13
|
+
private _parseFieldLength;
|
|
14
|
+
private _query;
|
|
15
|
+
private _exec;
|
|
16
|
+
/**
|
|
17
|
+
* Print a table name using database specific SQL escaping.
|
|
18
|
+
*
|
|
19
|
+
* @param sqlTable name of the table
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
printSqlTablename(sqlTable: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Print a column name with correct SQL escaping.
|
|
25
|
+
*
|
|
26
|
+
* @param sqlColumn name of the column
|
|
27
|
+
*
|
|
28
|
+
*/
|
|
29
|
+
printSqlColumnname(sqlColumn: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Print a single data value from serialization using the context of the native data
|
|
32
|
+
* type with the correct SQL escaping.
|
|
33
|
+
*
|
|
34
|
+
* @param cellValue data from sql results
|
|
35
|
+
* @param sqlType native type name for table column
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
38
|
+
printCellAsSqlValue(cellValue: OINODataCell, sqlType: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Parse a single SQL result value for serialization using the context of the native data
|
|
41
|
+
* type.
|
|
42
|
+
*
|
|
43
|
+
* @param sqlValue data from serialization
|
|
44
|
+
* @param sqlType native type name for table column
|
|
45
|
+
*
|
|
46
|
+
*/
|
|
47
|
+
parseSqlValueAsCell(sqlValue: OINODataCell, sqlType: string): OINODataCell;
|
|
48
|
+
/**
|
|
49
|
+
* Connect to database.
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
connect(): Promise<boolean>;
|
|
53
|
+
/**
|
|
54
|
+
* Execute a select operation.
|
|
55
|
+
*
|
|
56
|
+
* @param sql SQL statement.
|
|
57
|
+
*
|
|
58
|
+
*/
|
|
59
|
+
sqlSelect(sql: string): Promise<OINODbDataSet>;
|
|
60
|
+
/**
|
|
61
|
+
* Execute other sql operations.
|
|
62
|
+
*
|
|
63
|
+
* @param sql SQL statement.
|
|
64
|
+
*
|
|
65
|
+
*/
|
|
66
|
+
sqlExec(sql: string): Promise<OINODbDataSet>;
|
|
67
|
+
private _getSchemaSql;
|
|
68
|
+
/**
|
|
69
|
+
* Initialize a data model by getting the SQL schema and populating OINODbDataFields of
|
|
70
|
+
* the model.
|
|
71
|
+
*
|
|
72
|
+
* @param api api which data model to initialize.
|
|
73
|
+
*
|
|
74
|
+
*/
|
|
75
|
+
initializeApiDatamodel(api: OINODbApi): Promise<void>;
|
|
76
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { OINODbPostgresql } from "./OINODbPostgresql.js";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hashid implementation for OINO API:s for the purpose of making it infeasible to scan
|
|
3
|
+
* through numeric autoinc keys. It's not a solution to keeping the id secret in insecure
|
|
4
|
+
* channels, just making it hard enough to not iterate through the entire key space. Half
|
|
5
|
+
* of the the hashid length is nonce and half cryptotext, i.e. 16 char hashid 8 chars of
|
|
6
|
+
* base64 encoded nonce ~ 6 bytes or 48 bits of entropy.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
export declare class OINOHashid {
|
|
10
|
+
private _key;
|
|
11
|
+
private _iv;
|
|
12
|
+
private _domainId;
|
|
13
|
+
private _minLength;
|
|
14
|
+
private _staticIds;
|
|
15
|
+
/**
|
|
16
|
+
* Hashid constructor
|
|
17
|
+
*
|
|
18
|
+
* @param key AES128 key (32 char hex-string)
|
|
19
|
+
* @param domainId a sufficiently unique domain ID in which row-Id's are unique
|
|
20
|
+
* @param minLength minimum length of nonce and crypto
|
|
21
|
+
* @param staticIds whether hash values should remain static per row or random values
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
constructor(key: string, domainId: string, minLength?: number, staticIds?: boolean);
|
|
25
|
+
/**
|
|
26
|
+
* Encode given id value as a hashid either using random data or given seed value for nonce.
|
|
27
|
+
*
|
|
28
|
+
* @param id numeric value
|
|
29
|
+
* @param cellSeed a sufficiently unique seed for the current cell to keep hashids unique but persistent (e.g. fieldname + primarykey values)
|
|
30
|
+
*
|
|
31
|
+
*/
|
|
32
|
+
encode(id: string, cellSeed?: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Decode given hashid.
|
|
35
|
+
*
|
|
36
|
+
* @param hashid value
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
decode(hashid: string): string;
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { OINOHashid } from "./OINOHashid.js";
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference path="db/src/index.d.ts
|
|
2
|
+
/// <reference path="db/src/OINODb.d.ts
|
|
3
|
+
/// <reference path="db/src/OINODbApi.d.ts
|
|
4
|
+
/// <reference path="db/src/OINODbConfig.d.ts
|
|
5
|
+
/// <reference path="db/src/OINODbDataField.d.ts
|
|
6
|
+
/// <reference path="db/src/OINODbDataModel.d.ts
|
|
7
|
+
/// <reference path="db/src/OINODbFactory.d.ts
|
|
8
|
+
/// <reference path="db/src/OINODbModelSet.d.ts
|
|
9
|
+
/// <reference path="db/src/OINODbRequestParams.d.ts
|
|
10
|
+
/// <reference path="db/src/OINODbSqlParams.d.ts
|
|
11
|
+
/// <reference path="db/src/OINODbSwagger.d.ts
|
|
12
|
+
/// <reference path="db/src/OINODbParser.d.ts
|
|
13
|
+
/// <reference path="db-bunsqlite/src/OINODbBunSqlite.d.ts
|
|
14
|
+
/// <reference path="db-mariadb/src/OINODbMariadb.d.ts
|
|
15
|
+
/// <reference path="db-mssql/src/OINODbMsSql.d.ts
|
|
16
|
+
/// <reference path="db-postgresql/src/OINODbPostgresql.d.ts
|
|
17
|
+
/// <reference path="hashid/src/OINOHashid.d.ts
|
|
18
|
+
/// <reference path="common/src/index.d.ts
|
|
19
|
+
/// <reference path="common/src/OINOBenchmark.d.ts
|
|
20
|
+
/// <reference path="common/src/OINOHtmlTemplate.d.ts
|
|
21
|
+
/// <reference path="common/src/OINOLog.d.ts
|
|
22
|
+
/// <reference path="common/src/OINOResult.d.ts
|
|
23
|
+
/// <reference path="common/src/OINOStr.d.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oino-ts/types",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "OINO TS package for types.",
|
|
5
5
|
"author": "Matias Kiviniemi (pragmatta)",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -13,17 +13,14 @@
|
|
|
13
13
|
"typescript",
|
|
14
14
|
"library"
|
|
15
15
|
],
|
|
16
|
-
"main": "
|
|
17
|
-
"
|
|
18
|
-
"types": "./dist/types/index.d.ts",
|
|
16
|
+
"main": "",
|
|
17
|
+
"types": "index.d.ts",
|
|
19
18
|
"dependencies": {
|
|
20
19
|
},
|
|
21
20
|
"devDependencies": {
|
|
22
21
|
},
|
|
23
22
|
"files": [
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"dist/esm/*.js",
|
|
27
|
-
"dist/types/*.d.ts"
|
|
23
|
+
"index.d.ts",
|
|
24
|
+
"**/src/*.d.ts"
|
|
28
25
|
]
|
|
29
26
|
}
|
package/README.md
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
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/db` npm package and necessary database packages and import them in your code.
|
|
14
|
-
```
|
|
15
|
-
bun install @oino-ts/db
|
|
16
|
-
bun install @oino-ts/db-bunsqlite
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
```
|
|
20
|
-
import { OINODb, OINOApi, OINOFactory } from "@oino-ts/db";
|
|
21
|
-
import { OINODbBunSqlite } from "@oino-ts/db-bunsqlite"
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
### Register database and logger
|
|
25
|
-
Register your database implementation and logger (see [`OINOConsoleLog`](https://pragmatta.github.io/oino-ts/classes/types_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/db_src.OINODb.html) is done by passing [`OINODbParams`](https://pragmatta.github.io/oino-ts/types/db_src.OINODbParams.html) to the factory method. For [`OINODbBunSqlite`](https://pragmatta.github.io/oino-ts/classes/db_bunsqlite_src.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/db_src.OINODbApi.html) by passing [`OINOApiParams`](https://pragmatta.github.io/oino-ts/types/db_src.OINODbApiParams.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/db_src.OINODbModelSet.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.data.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
|
-
For example HTTP POST
|
|
64
|
-
```
|
|
65
|
-
Request and response:
|
|
66
|
-
> curl.exe -X POST http://localhost:3001/orderdetails -H "Content-Type: application/json" --data '[{\"OrderID\":11077,\"ProductID\":99,\"UnitPrice\":19,\"Quantity\":1,\"Discount\":0}]'
|
|
67
|
-
{"success":true,"statusCode":200,"statusMessage":"OK","messages":[]}
|
|
68
|
-
|
|
69
|
-
SQL:
|
|
70
|
-
INSERT INTO [OrderDetails] ("OrderID","ProductID","UnitPrice","Quantity","Discount") VALUES (11077,99,19,1,0);
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
## Universal Serialization
|
|
75
|
-
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.
|
|
76
|
-
|
|
77
|
-
### Features
|
|
78
|
-
- Files can be sent to BLOB fields using BASE64 or MIME multipart encoding.
|
|
79
|
-
- Datetimes are (optionally) normalized to ISO 8601 format.
|
|
80
|
-
- Extended JSON-encoding
|
|
81
|
-
- 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).
|
|
82
|
-
- CSV
|
|
83
|
-
- Comma-separated, doublequotes.
|
|
84
|
-
- Unquoted literal `null` represents null values.
|
|
85
|
-
- Unquoted empty string represents undefined values.
|
|
86
|
-
- Form data
|
|
87
|
-
- Multipart-mixed and binary files not supported.
|
|
88
|
-
- Non-existent value line (i.e. nothing after the empty line) treated as a null value.
|
|
89
|
-
- Url-encoded
|
|
90
|
-
- No null values, missing properties treated as undefined.
|
|
91
|
-
- Multiple lines could be used to post multiple rows.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
## Database Abstraction
|
|
95
|
-
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.
|
|
96
|
-
|
|
97
|
-
Currently supported databases:
|
|
98
|
-
- Bun Sqlite through Bun native implementation
|
|
99
|
-
- Postgresql through [pg](https://www.npmjs.com/package/pg)-package
|
|
100
|
-
- Mariadb / Mysql-support through [mariadb](https://www.npmjs.com/package/mariadb)-package
|
|
101
|
-
- Sql Server through [mssql](https://www.npmjs.com/package/mssql)-package
|
|
102
|
-
|
|
103
|
-
## Complex Keys
|
|
104
|
-
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`.
|
|
105
|
-
|
|
106
|
-
## Power Of SQL
|
|
107
|
-
Since OINO is just generating SQL, WHERE-conditions can be defined with [`OINOSqlFilter`](https://pragmatta.github.io/oino-ts/classes/db_src.OINODbSqlFilter.html), order with [`OINOSqlOrder`](https://pragmatta.github.io/oino-ts/classes/db_src.OINODbSqlOrder.html) and limits/paging with [`OINOSqlOrder`](https://pragmatta.github.io/oino-ts/classes/db_src.OINODbSqlLimit.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.
|
|
108
|
-
|
|
109
|
-
## Swagger Support
|
|
110
|
-
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.
|
|
111
|
-
```
|
|
112
|
-
if (url.pathname == "/swagger.json") {
|
|
113
|
-
return new Response(JSON.stringify(OINOSwagger.getApiDefinition(api_array)))
|
|
114
|
-
}
|
|
115
|
-
```
|
|
116
|
-

|
|
117
|
-
|
|
118
|
-
## Node support
|
|
119
|
-
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).
|
|
120
|
-
|
|
121
|
-
## HTMX support
|
|
122
|
-
OINO is [htmx.org](https://htmx.org) friendly, allowing easy translation of [`OINODataRow`](https://pragmatta.github.io/oino-ts/types/db_src.OINODataRow.html) to HTML output using templates (cf. the [htmx sample app](https://github.com/pragmatta/oino-ts/tree/main/samples/htmxApp)).
|
|
123
|
-
|
|
124
|
-
### Hashids
|
|
125
|
-
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.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
# STATUS
|
|
129
|
-
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.
|
|
130
|
-
|
|
131
|
-
## Beta
|
|
132
|
-
For a beta status following milestones are planned:
|
|
133
|
-
|
|
134
|
-
### Realistic app
|
|
135
|
-
There needs to be a realistic app built on top of OINO to get a better grasp of the edge cases.
|
|
136
|
-
|
|
137
|
-
### Security review
|
|
138
|
-
Handling of SQL-injection attacks needs a thorough review, what are the relevant attack vectors are for OINO and what protections are still needed.
|
|
139
|
-
|
|
140
|
-
## Roadmap
|
|
141
|
-
Things that need to happen in some order before beta-status are at least following:
|
|
142
|
-
|
|
143
|
-
### Support for views
|
|
144
|
-
Simple cases of views would work already in some databases but edge cases might get complicated. For example
|
|
145
|
-
- How to handle a view which does not have a complete private key?
|
|
146
|
-
- What edge cases exist in updating views?
|
|
147
|
-
|
|
148
|
-
### Batch updates
|
|
149
|
-
Supporting batch updates similar to batch inserts is slightly bending the RESTfull principles but would still be a useful optional feature.
|
|
150
|
-
|
|
151
|
-
### Aggregation
|
|
152
|
-
Similar to filtering, ordering and limits, aggregation could be implemented as HTTP request parameters telling what column is aggregated or used for ordering or how many results to return.
|
|
153
|
-
|
|
154
|
-
### Streaming
|
|
155
|
-
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.
|
|
156
|
-
|
|
157
|
-
### SQL generation callbacks
|
|
158
|
-
It would be useful to allow developer to validate / override SQL generation to cover cases OINO does not support or even workaround issues.
|
|
159
|
-
|
|
160
|
-
### Transactions
|
|
161
|
-
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.
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
# HELP
|
|
165
|
-
|
|
166
|
-
## Bug reports
|
|
167
|
-
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.
|
|
168
|
-
|
|
169
|
-
## Feedback
|
|
170
|
-
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.
|
|
171
|
-
|
|
172
|
-
## Typescript / Javascript architecture
|
|
173
|
-
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.
|
|
174
|
-
|
|
175
|
-
# LINKS
|
|
176
|
-
- [Github repository](https://github.com/pragmatta/oino-ts)
|
|
177
|
-
- [NPM repository](https://www.npmjs.com/org/oino-ts)
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
# ACKNOWLEDGEMENTS
|
|
181
|
-
|
|
182
|
-
## Libraries
|
|
183
|
-
OINO uses the following open source libraries and npm packages and I would like to thank everyone for their contributions:
|
|
184
|
-
- Postgresql [node-postgres package](https://www.npmjs.com/package/pg)
|
|
185
|
-
- Mariadb / Mysql [mariadb package](https://www.npmjs.com/package/mariadb)
|
|
186
|
-
- Sql Server [mssql package](https://www.npmjs.com/package/mssql)
|
|
187
|
-
- Custom base encoding [base-x package](https://www.npmjs.com/package/base-x)
|
|
188
|
-
|
|
189
|
-
## Bun
|
|
190
|
-
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.
|
|
191
|
-
|
|
192
|
-
## SQL Scripts
|
|
193
|
-
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).
|