@oino-ts/types 0.0.18 → 0.1.1

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.
Files changed (53) hide show
  1. package/{dist/types → common/src}/index.d.ts +0 -1
  2. package/db/src/OINODb.d.ts +180 -0
  3. package/db/src/OINODbApi.d.ts +82 -0
  4. package/db/src/OINODbConfig.d.ts +52 -0
  5. package/db/src/OINODbDataField.d.ts +202 -0
  6. package/db/src/OINODbDataModel.d.ts +108 -0
  7. package/db/src/OINODbDataSet.d.ts +95 -0
  8. package/db/src/OINODbFactory.d.ts +35 -0
  9. package/db/src/OINODbModelSet.d.ts +51 -0
  10. package/{dist/types/OINOParser.d.ts → db/src/OINODbParser.d.ts} +3 -3
  11. package/db/src/OINODbRequestParams.d.ts +146 -0
  12. package/db/src/OINODbSqlParams.d.ts +147 -0
  13. package/db/src/OINODbSwagger.d.ts +25 -0
  14. package/db/src/index.d.ts +111 -0
  15. package/db-bunsqlite/src/OINODbBunSqlite.d.ts +77 -0
  16. package/db-bunsqlite/src/index.d.ts +1 -0
  17. package/db-mariadb/src/OINODbMariadb.d.ts +78 -0
  18. package/db-mariadb/src/index.d.ts +1 -0
  19. package/db-mssql/src/OINODbMsSql.d.ts +86 -0
  20. package/db-mssql/src/index.d.ts +1 -0
  21. package/db-postgresql/src/OINODbPostgresql.d.ts +76 -0
  22. package/db-postgresql/src/index.d.ts +1 -0
  23. package/hashid/src/OINOHashid.d.ts +40 -0
  24. package/hashid/src/index.d.ts +1 -0
  25. package/index.d.ts +23 -0
  26. package/package.json +5 -8
  27. package/README.md +0 -190
  28. package/dist/cjs/OINOBenchmark.js +0 -108
  29. package/dist/cjs/OINOHtmlTemplate.js +0 -177
  30. package/dist/cjs/OINOLog.js +0 -151
  31. package/dist/cjs/OINOParser.js +0 -466
  32. package/dist/cjs/OINOResult.js +0 -216
  33. package/dist/cjs/OINOStr.js +0 -265
  34. package/dist/cjs/index.js +0 -42
  35. package/dist/esm/OINOBenchmark.js +0 -104
  36. package/dist/esm/OINOHtmlTemplate.js +0 -173
  37. package/dist/esm/OINOLog.js +0 -146
  38. package/dist/esm/OINOParser.js +0 -462
  39. package/dist/esm/OINOResult.js +0 -211
  40. package/dist/esm/OINOStr.js +0 -261
  41. package/dist/esm/index.js +0 -30
  42. package/src/OINOBenchmark.ts +0 -112
  43. package/src/OINOHtmlTemplate.ts +0 -186
  44. package/src/OINOLog.ts +0 -168
  45. package/src/OINOParser.ts +0 -458
  46. package/src/OINOResult.ts +0 -234
  47. package/src/OINOStr.ts +0 -254
  48. package/src/index.ts +0 -32
  49. /package/{dist/types → common/src}/OINOBenchmark.d.ts +0 -0
  50. /package/{dist/types → common/src}/OINOHtmlTemplate.d.ts +0 -0
  51. /package/{dist/types → common/src}/OINOLog.d.ts +0 -0
  52. /package/{dist/types → common/src}/OINOResult.d.ts +0 -0
  53. /package/{dist/types → common/src}/OINOStr.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.18",
3
+ "version": "0.1.1",
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": "./dist/cjs/index.js",
17
- "module": "./dist/esm/index.js",
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
- "src/*.ts",
25
- "dist/cjs/*.js",
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,190 +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. Also supports standard HTML form file submission to blob fields and returning them data url images.
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
- ## Composite 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 [`OINOSqlLimit`](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
- ![Swagger definition with a data model schema](img/readme-swagger.png)
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
- ## Roadmap
138
- Things that need to happen in some order before beta-status are at least following:
139
-
140
- ### Support for views
141
- Simple cases of views would work already in some databases but edge cases might get complicated. For example
142
- - How to handle a view which does not have a complete private key?
143
- - What edge cases exist in updating views?
144
-
145
- ### Batch updates
146
- Supporting batch updates similar to batch inserts is slightly bending the RESTfull principles but would still be a useful optional feature.
147
-
148
- ### Aggregation
149
- 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.
150
-
151
- ### Streaming
152
- 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.
153
-
154
- ### SQL generation callbacks
155
- It would be useful to allow developer to validate / override SQL generation to cover cases OINO does not support or even workaround issues.
156
-
157
- ### Transactions
158
- 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.
159
-
160
-
161
- # HELP
162
-
163
- ## Bug reports
164
- 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.
165
-
166
- ## Feedback
167
- 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.
168
-
169
- ## Typescript / Javascript architecture
170
- 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.
171
-
172
- # LINKS
173
- - [Github repository](https://github.com/pragmatta/oino-ts)
174
- - [NPM repository](https://www.npmjs.com/org/oino-ts)
175
-
176
-
177
- # ACKNOWLEDGEMENTS
178
-
179
- ## Libraries
180
- OINO uses the following open source libraries and npm packages and I would like to thank everyone for their contributions:
181
- - Postgresql [node-postgres package](https://www.npmjs.com/package/pg)
182
- - Mariadb / Mysql [mariadb package](https://www.npmjs.com/package/mariadb)
183
- - Sql Server [mssql package](https://www.npmjs.com/package/mssql)
184
- - Custom base encoding [base-x package](https://www.npmjs.com/package/base-x)
185
-
186
- ## Bun
187
- 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.
188
-
189
- ## SQL Scripts
190
- 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).