@oino-ts/types 0.21.2 → 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/blob/src/OINOBlob.d.ts +78 -0
- package/blob/src/OINOBlobApi.d.ts +49 -0
- package/blob/src/OINOBlobConstants.d.ts +37 -0
- package/blob/src/OINOBlobDataModel.d.ts +33 -0
- package/blob/src/OINOBlobFactory.d.ts +40 -0
- package/blob/src/index.d.ts +5 -0
- package/blob-aws/src/OINOBlobAwsS3.d.ts +90 -0
- package/blob-aws/src/index.d.ts +1 -0
- package/blob-azure/src/OINOBlobAzureTable.d.ts +86 -0
- package/blob-azure/src/index.d.ts +1 -0
- package/common/src/OINOApi.d.ts +191 -0
- package/common/src/OINOConfig.d.ts +63 -0
- package/common/src/OINOConstants.d.ts +51 -0
- package/common/src/OINODataField.d.ts +209 -0
- package/common/src/OINODataModel.d.ts +78 -0
- package/common/src/OINODataSource.d.ts +184 -0
- package/common/src/OINOHtmlTemplate.d.ts +1 -1
- package/common/src/OINOModelSet.d.ts +64 -0
- package/common/src/OINOParser.d.ts +42 -0
- package/common/src/OINOQueryParams.d.ts +270 -0
- package/common/src/OINORequest.d.ts +4 -1
- package/common/src/OINOResult.d.ts +1 -1
- package/common/src/OINOStr.d.ts +1 -1
- package/common/src/OINOSwagger.d.ts +25 -0
- package/common/src/index.d.ts +14 -31
- package/db/src/OINODb.d.ts +55 -0
- package/db/src/OINODbApi.d.ts +78 -0
- package/db/src/OINODbConfig.d.ts +56 -0
- package/db/src/OINODbConstants.d.ts +23 -0
- package/db/src/OINODbDataField.d.ts +210 -0
- package/db/src/OINODbDataModel.d.ts +55 -0
- package/db/src/OINODbDataSet.d.ts +95 -0
- package/db/src/OINODbFactory.d.ts +34 -0
- package/db/src/OINODbModelSet.d.ts +62 -0
- package/db/src/OINODbParser.d.ts +42 -0
- package/db/src/OINODbQueryParams.d.ts +72 -0
- package/db/src/OINODbRequestParams.d.ts +146 -0
- package/db/src/OINODbSqlParams.d.ts +296 -0
- package/db/src/OINODbSwagger.d.ts +25 -0
- package/db/src/index.d.ts +6 -0
- package/db-bunsqlite/src/OINODbBunSqlite.d.ts +99 -0
- package/db-bunsqlite/src/index.d.ts +1 -0
- package/db-mariadb/src/OINODbMariadb.d.ts +99 -0
- package/db-mariadb/src/index.d.ts +1 -0
- package/db-mssql/src/OINODbMsSql.d.ts +116 -0
- package/db-mssql/src/index.d.ts +1 -0
- package/db-postgresql/src/OINODbPostgresql.d.ts +95 -0
- package/db-postgresql/src/index.d.ts +1 -0
- package/hashid/src/OINOHashid.d.ts +42 -0
- package/hashid/src/index.d.ts +1 -0
- package/index.d.ts +7 -7
- package/nosql/src/OINONoSql.d.ts +81 -0
- package/nosql/src/OINONoSqlApi.d.ts +67 -0
- package/nosql/src/OINONoSqlConstants.d.ts +34 -0
- package/nosql/src/OINONoSqlDataModel.d.ts +29 -0
- package/nosql/src/OINONoSqlFactory.d.ts +40 -0
- package/nosql/src/index.d.ts +5 -0
- package/nosql-aws/src/OINONoSqlAwsDynamo.d.ts +223 -0
- package/nosql-aws/src/index.d.ts +1 -0
- package/nosql-azure/src/OINONoSqlAzureTable.d.ts +130 -0
- package/nosql-azure/src/index.d.ts +1 -0
- package/package.json +28 -28
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { OINOResult, OINODataSet, OINODataCell } from "@oino-ts/common";
|
|
2
|
+
import { OINODb, OINODbApi, OINODbParams } from "@oino-ts/db";
|
|
3
|
+
/**
|
|
4
|
+
* Implementation of MsSql-database.
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
export declare class OINODbMsSql extends OINODb {
|
|
8
|
+
private _pool;
|
|
9
|
+
/**
|
|
10
|
+
* Constructor of `OINODbMsSql`
|
|
11
|
+
* @param params database parameters
|
|
12
|
+
*/
|
|
13
|
+
constructor(params: OINODbParams);
|
|
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
|
+
printTableName(sqlTable: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Print a column name with correct SQL escaping.
|
|
25
|
+
*
|
|
26
|
+
* @param sqlColumn name of the column
|
|
27
|
+
*
|
|
28
|
+
*/
|
|
29
|
+
printColumnName(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 nativeType native type name for table column
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
38
|
+
printCellAsValue(cellValue: OINODataCell, nativeType: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Print a single string value as valid sql literal
|
|
41
|
+
*
|
|
42
|
+
* @param sqlString string value
|
|
43
|
+
*
|
|
44
|
+
*/
|
|
45
|
+
printStringValue(sqlString: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Parse a single SQL result value for serialization using the context of the native data
|
|
48
|
+
* type.
|
|
49
|
+
*
|
|
50
|
+
* @param sqlValue data from serialization
|
|
51
|
+
* @param nativeType native type name for table column
|
|
52
|
+
*
|
|
53
|
+
*/
|
|
54
|
+
parseValueAsCell(sqlValue: OINODataCell, nativeType: string): OINODataCell;
|
|
55
|
+
/**
|
|
56
|
+
* Print SQL select statement with DB specific formatting.
|
|
57
|
+
*
|
|
58
|
+
* @param tableName - The name of the table to select from.
|
|
59
|
+
* @param columnNames - The columns to be selected.
|
|
60
|
+
* @param whereCondition - The WHERE clause to filter the results.
|
|
61
|
+
* @param orderCondition - The ORDER BY clause to sort the results.
|
|
62
|
+
* @param limitCondition - The LIMIT clause to limit the number of results.
|
|
63
|
+
* @param groupByCondition - The GROUP BY clause to group the results.
|
|
64
|
+
*
|
|
65
|
+
*/
|
|
66
|
+
printSqlSelect(tableName: string, columnNames: string, whereCondition: string, orderCondition: string, limitCondition: string, groupByCondition: string): string;
|
|
67
|
+
/**
|
|
68
|
+
* Print SQL select statement with DB specific formatting.
|
|
69
|
+
*
|
|
70
|
+
* @param tableName - The name of the table to select from.
|
|
71
|
+
* @param columns - The columns to be selected.
|
|
72
|
+
* @param values - The values to be inserted.
|
|
73
|
+
* @param returnIdFields - the id fields to return if returnIds is true (if supported by the database)
|
|
74
|
+
*
|
|
75
|
+
*/
|
|
76
|
+
printSqlInsert(tableName: string, columns: string, values: string, returnIdFields?: string[]): string;
|
|
77
|
+
/**
|
|
78
|
+
* Connect to database.
|
|
79
|
+
*
|
|
80
|
+
*/
|
|
81
|
+
connect(): Promise<OINOResult>;
|
|
82
|
+
/**
|
|
83
|
+
* Validate connection to database is working.
|
|
84
|
+
*
|
|
85
|
+
*/
|
|
86
|
+
validate(): Promise<OINOResult>;
|
|
87
|
+
/**
|
|
88
|
+
* Disconnect from database.
|
|
89
|
+
*
|
|
90
|
+
*/
|
|
91
|
+
disconnect(): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Execute a select operation.
|
|
94
|
+
*
|
|
95
|
+
* @param sql SQL statement.
|
|
96
|
+
*
|
|
97
|
+
*/
|
|
98
|
+
sqlSelect(sql: string): Promise<OINODataSet>;
|
|
99
|
+
/**
|
|
100
|
+
* Execute other sql operations.
|
|
101
|
+
*
|
|
102
|
+
* @param sql SQL statement.
|
|
103
|
+
*
|
|
104
|
+
*/
|
|
105
|
+
sqlExec(sql: string): Promise<OINODataSet>;
|
|
106
|
+
private _getSchemaSql;
|
|
107
|
+
private _getValidateSql;
|
|
108
|
+
/**
|
|
109
|
+
* Initialize a data model by getting the SQL schema and populating OINODataFields of
|
|
110
|
+
* the model.
|
|
111
|
+
*
|
|
112
|
+
* @param api api which data model to initialize.
|
|
113
|
+
*
|
|
114
|
+
*/
|
|
115
|
+
initializeApiDatamodel(api: OINODbApi): Promise<void>;
|
|
116
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { OINODbMsSql } from "./OINODbMsSql.js";
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { OINOResult, OINODataSet, OINODataCell } from "@oino-ts/common";
|
|
2
|
+
import { OINODb, OINODbApi, OINODbParams } from "@oino-ts/db";
|
|
3
|
+
/**
|
|
4
|
+
* Implementation of Postgresql-database.
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
export declare class OINODbPostgresql extends OINODb {
|
|
8
|
+
private _pool;
|
|
9
|
+
/**
|
|
10
|
+
* Constructor of `OINODbPostgresql`
|
|
11
|
+
* @param params database paraneters
|
|
12
|
+
*/
|
|
13
|
+
constructor(params: OINODbParams);
|
|
14
|
+
private _parseFieldLength;
|
|
15
|
+
private _query;
|
|
16
|
+
private _exec;
|
|
17
|
+
/**
|
|
18
|
+
* Print a table name using database specific SQL escaping.
|
|
19
|
+
*
|
|
20
|
+
* @param sqlTable name of the table
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
printTableName(sqlTable: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Print a column name with correct SQL escaping.
|
|
26
|
+
*
|
|
27
|
+
* @param sqlColumn name of the column
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
printColumnName(sqlColumn: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Print a single data value from serialization using the context of the native data
|
|
33
|
+
* type with the correct SQL escaping.
|
|
34
|
+
*
|
|
35
|
+
* @param cellValue data from sql results
|
|
36
|
+
* @param nativeType native type name for table column
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
printCellAsValue(cellValue: OINODataCell, nativeType: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Print a single string value as valid sql literal
|
|
42
|
+
*
|
|
43
|
+
* @param sqlString string value
|
|
44
|
+
*
|
|
45
|
+
*/
|
|
46
|
+
printStringValue(sqlString: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Parse a single SQL result value for serialization using the context of the native data
|
|
49
|
+
* type.
|
|
50
|
+
*
|
|
51
|
+
* @param sqlValue data from serialization
|
|
52
|
+
* @param nativeType native type name for table column
|
|
53
|
+
*
|
|
54
|
+
*/
|
|
55
|
+
parseValueAsCell(sqlValue: OINODataCell, nativeType: string): OINODataCell;
|
|
56
|
+
/**
|
|
57
|
+
* Connect to database.
|
|
58
|
+
*
|
|
59
|
+
*/
|
|
60
|
+
connect(): Promise<OINOResult>;
|
|
61
|
+
/**
|
|
62
|
+
* Validate connection to database is working.
|
|
63
|
+
*
|
|
64
|
+
*/
|
|
65
|
+
validate(): Promise<OINOResult>;
|
|
66
|
+
/**
|
|
67
|
+
* Disconnect from database.
|
|
68
|
+
*
|
|
69
|
+
*/
|
|
70
|
+
disconnect(): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Execute a select operation.
|
|
73
|
+
*
|
|
74
|
+
* @param sql SQL statement.
|
|
75
|
+
*
|
|
76
|
+
*/
|
|
77
|
+
sqlSelect(sql: string): Promise<OINODataSet>;
|
|
78
|
+
/**
|
|
79
|
+
* Execute other sql operations.
|
|
80
|
+
*
|
|
81
|
+
* @param sql SQL statement.
|
|
82
|
+
*
|
|
83
|
+
*/
|
|
84
|
+
sqlExec(sql: string): Promise<OINODataSet>;
|
|
85
|
+
private _getSchemaSql;
|
|
86
|
+
private _getValidateSql;
|
|
87
|
+
/**
|
|
88
|
+
* Initialize a data model by getting the SQL schema and populating OINODataFields of
|
|
89
|
+
* the model.
|
|
90
|
+
*
|
|
91
|
+
* @param api api which data model to initialize.
|
|
92
|
+
*
|
|
93
|
+
*/
|
|
94
|
+
initializeApiDatamodel(api: OINODbApi): Promise<void>;
|
|
95
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { OINODbPostgresql } from "./OINODbPostgresql.js";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export declare const OINOHASHID_MIN_LENGTH: number;
|
|
2
|
+
export declare const OINOHASHID_MAX_LENGTH: number;
|
|
3
|
+
/**
|
|
4
|
+
* Hashid implementation for OINO API:s for the purpose of making it infeasible to scan
|
|
5
|
+
* through numeric autoinc keys. It's not a solution to keeping the id secret in insecure
|
|
6
|
+
* channels, just making it hard enough to not iterate through the entire key space. Half
|
|
7
|
+
* of the the hashid length is nonce and half cryptotext, i.e. 16 char hashid 8 chars of
|
|
8
|
+
* base64 encoded nonce ~ 6 bytes or 48 bits of entropy.
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
export declare class OINOHashid {
|
|
12
|
+
private _key;
|
|
13
|
+
private _iv;
|
|
14
|
+
private _domainId;
|
|
15
|
+
private _minLength;
|
|
16
|
+
private _staticIds;
|
|
17
|
+
/**
|
|
18
|
+
* Hashid constructor
|
|
19
|
+
*
|
|
20
|
+
* @param key AES128 key (32 char hex-string)
|
|
21
|
+
* @param domainId a sufficiently unique domain ID in which row-Id's are unique
|
|
22
|
+
* @param minLength minimum length of nonce and crypto
|
|
23
|
+
* @param staticIds whether hash values should remain static per row or random values
|
|
24
|
+
*
|
|
25
|
+
*/
|
|
26
|
+
constructor(key: string, domainId: string, minLength?: number, staticIds?: boolean);
|
|
27
|
+
/**
|
|
28
|
+
* Encode given id value as a hashid either using random data or given seed value for nonce.
|
|
29
|
+
*
|
|
30
|
+
* @param id numeric value
|
|
31
|
+
* @param cellSeed a sufficiently unique seed for the current cell to keep hashids unique but persistent (e.g. fieldname + primarykey values)
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
34
|
+
encode(id: string, cellSeed?: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Decode given hashid.
|
|
37
|
+
*
|
|
38
|
+
* @param hashid value
|
|
39
|
+
*
|
|
40
|
+
*/
|
|
41
|
+
decode(hashid: string): string;
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { OINOHashid } from "./OINOHashid.js";
|
package/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/// <reference path="db/src/index.d.ts
|
|
2
|
-
/// <reference path="db-bunsqlite/src/index.d.ts
|
|
3
|
-
/// <reference path="db-mariadb/src/index.d.ts
|
|
4
|
-
/// <reference path="db-mssql/src/index.d.ts
|
|
5
|
-
/// <reference path="db-postgresql/src/index.d.ts
|
|
6
|
-
/// <reference path="hashid/src/OINOHashid.d.ts
|
|
7
|
-
/// <reference path="common/src/index.d.ts
|
|
1
|
+
/// <reference path="db/src/index.d.ts
|
|
2
|
+
/// <reference path="db-bunsqlite/src/index.d.ts
|
|
3
|
+
/// <reference path="db-mariadb/src/index.d.ts
|
|
4
|
+
/// <reference path="db-mssql/src/index.d.ts
|
|
5
|
+
/// <reference path="db-postgresql/src/index.d.ts
|
|
6
|
+
/// <reference path="hashid/src/OINOHashid.d.ts
|
|
7
|
+
/// <reference path="common/src/index.d.ts
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { OINODataSource, OINODataCell, OINOQueryFilter } from "@oino-ts/common";
|
|
2
|
+
import { OINONoSqlParams, OINONoSqlEntry } from "./OINONoSqlConstants.js";
|
|
3
|
+
/**
|
|
4
|
+
* Abstract base class for NoSQL storage backends. Subclasses implement
|
|
5
|
+
* the core CRUD operations for a specific provider (e.g. Azure Table Storage).
|
|
6
|
+
*
|
|
7
|
+
* The data model exposed by the API has a fixed set of fields:
|
|
8
|
+
* 1. `partitionKey` – partition key (primary key component, string)
|
|
9
|
+
* 2. `rowKey` – row key (primary key component, string)
|
|
10
|
+
* 3. `timestamp` – last modification timestamp (datetime)
|
|
11
|
+
* 4. `etag` – entity tag (string)
|
|
12
|
+
* 5. `properties` – all custom entity properties as a JSON string
|
|
13
|
+
*
|
|
14
|
+
* The SQL-formatting methods inherited from `OINODataSource` are not used
|
|
15
|
+
* by nosql operations; they are implemented here as passthrough stubs.
|
|
16
|
+
*/
|
|
17
|
+
export declare abstract class OINONoSql extends OINODataSource {
|
|
18
|
+
protected readonly nosqlParams: OINONoSqlParams;
|
|
19
|
+
/** Table name */
|
|
20
|
+
readonly name: string;
|
|
21
|
+
/**
|
|
22
|
+
* Whether this backend can auto-generate primary key values when none are
|
|
23
|
+
* supplied in a POST request. Defaults to `false`; override in subclasses
|
|
24
|
+
* that support server-side key generation (e.g. UUID on insert).
|
|
25
|
+
*/
|
|
26
|
+
readonly supportsAutoKey: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Constructor for `OINONoSql`.
|
|
29
|
+
* @param params nosql storage connection parameters
|
|
30
|
+
*/
|
|
31
|
+
constructor(params: OINONoSqlParams);
|
|
32
|
+
printTableName(name: string): string;
|
|
33
|
+
printColumnName(name: string): string;
|
|
34
|
+
printCellAsValue(cellValue: OINODataCell, nativeType: string): string;
|
|
35
|
+
printStringValue(s: string): string;
|
|
36
|
+
parseValueAsCell(v: OINODataCell, nativeType: string): OINODataCell;
|
|
37
|
+
/**
|
|
38
|
+
* Test whether a NoSQL entry matches an `OINOQueryFilter` predicate.
|
|
39
|
+
* Used for in-memory (result) filtering when the storage backend cannot
|
|
40
|
+
* translate the predicate to a native query.
|
|
41
|
+
*
|
|
42
|
+
* @param entry nosql entry to test
|
|
43
|
+
* @param filter filter predicate to evaluate
|
|
44
|
+
*/
|
|
45
|
+
protected static matchesEntry(entry: OINONoSqlEntry, filter: OINOQueryFilter): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* List all entities in the table, applying storage-level filtering where
|
|
48
|
+
* possible and in-memory result filtering for remaining predicates.
|
|
49
|
+
*
|
|
50
|
+
* @param filter optional query filter to apply
|
|
51
|
+
*/
|
|
52
|
+
abstract listEntries(filter?: OINOQueryFilter): Promise<OINONoSqlEntry[]>;
|
|
53
|
+
/**
|
|
54
|
+
* Fetch a single entity by its primary key values.
|
|
55
|
+
*
|
|
56
|
+
* Returns `null` when no entity with the given primary key exists.
|
|
57
|
+
*
|
|
58
|
+
* @param primaryKey ordered primary key values as defined by the implementation's data model
|
|
59
|
+
*/
|
|
60
|
+
abstract getEntry(primaryKey: string[]): Promise<OINONoSqlEntry | null>;
|
|
61
|
+
/**
|
|
62
|
+
* Upsert (insert or replace) an entity.
|
|
63
|
+
*
|
|
64
|
+
* @param entry entity to upsert
|
|
65
|
+
*/
|
|
66
|
+
abstract upsertEntry(entry: OINONoSqlEntry): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Upsert (insert or replace) multiple entities in the most efficient way
|
|
69
|
+
* the backend supports. The default implementation loops over
|
|
70
|
+
* `upsertEntry`; override in subclasses that support native batch writes.
|
|
71
|
+
*
|
|
72
|
+
* @param entries entities to upsert
|
|
73
|
+
*/
|
|
74
|
+
upsertEntries(entries: OINONoSqlEntry[]): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Delete an entity.
|
|
77
|
+
*
|
|
78
|
+
* @param primaryKey ordered primary key values as defined by the implementation's data model
|
|
79
|
+
*/
|
|
80
|
+
abstract deleteEntry(primaryKey: string[]): Promise<void>;
|
|
81
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { OINOApi, OINOApiParams, OINOApiRequest, OINOApiResult, OINOContentType, OINOQueryParams, OINOHttpRequest, type OINOApiData } from "@oino-ts/common";
|
|
2
|
+
import { OINONoSql } from "./OINONoSql.js";
|
|
3
|
+
import { OINONoSqlDataModel } from "./OINONoSqlDataModel.js";
|
|
4
|
+
/**
|
|
5
|
+
* REST API for NoSQL table storage.
|
|
6
|
+
*
|
|
7
|
+
* Supports the following HTTP methods:
|
|
8
|
+
* - **GET without id** – lists all entities and returns metadata as JSON.
|
|
9
|
+
* - **GET with id** – returns a single entity.
|
|
10
|
+
* - **POST / PUT with id** – upserts an entity; body must be a JSON object
|
|
11
|
+
* with a `properties` key containing the custom entity properties.
|
|
12
|
+
* - **DELETE with id** – deletes the named entity.
|
|
13
|
+
*
|
|
14
|
+
* The URL row ID format uses `OINOConfig.OINO_ID_SEPARATOR` to join the
|
|
15
|
+
* primary key field values, matching the number and order of primary key
|
|
16
|
+
* fields in the data model (same `_OINOID_` convention as `OINODbApi`).
|
|
17
|
+
*/
|
|
18
|
+
export declare class OINONoSqlApi extends OINOApi {
|
|
19
|
+
/** NoSQL storage backend */
|
|
20
|
+
readonly noSql: OINONoSql;
|
|
21
|
+
/** NoSQL-specific data model (populated by `initializeDatamodel`) */
|
|
22
|
+
noSqlDatamodel: OINONoSqlDataModel | null;
|
|
23
|
+
/**
|
|
24
|
+
* Constructor.
|
|
25
|
+
*
|
|
26
|
+
* NOTE: `initializeDatamodel` (or `OINONoSqlFactory.createApi`) must be
|
|
27
|
+
* called before the first request is dispatched.
|
|
28
|
+
*
|
|
29
|
+
* @param noSql nosql storage backend
|
|
30
|
+
* @param params API parameters
|
|
31
|
+
*/
|
|
32
|
+
constructor(noSql: OINONoSql, params: OINOApiParams);
|
|
33
|
+
/**
|
|
34
|
+
* Attach the static nosql data model and mark the API as initialised.
|
|
35
|
+
*
|
|
36
|
+
* @param datamodel `OINONoSqlDataModel` instance for this API
|
|
37
|
+
*/
|
|
38
|
+
initializeDatamodel(datamodel: OINONoSqlDataModel): void;
|
|
39
|
+
/**
|
|
40
|
+
* Parse a `_OINOID_`-formatted row ID into an ordered array of decoded
|
|
41
|
+
* primary key values using `OINOConfig.parseOINOId`. Returns `null` when
|
|
42
|
+
* the number of parts does not match the data model's primary key count.
|
|
43
|
+
*
|
|
44
|
+
* @param rowId `_OINOID_`-formatted row ID
|
|
45
|
+
*/
|
|
46
|
+
private _parseRowId;
|
|
47
|
+
/**
|
|
48
|
+
* Validate a data row against API parameters. Currently checks whether
|
|
49
|
+
* primary key fields are present when `requirePrimaryKey` is `true`.
|
|
50
|
+
*
|
|
51
|
+
* `requirePrimaryKey` is derived at the call-site from:
|
|
52
|
+
* - `this.params.failOnInsertWithoutKey` when explicitly set, or
|
|
53
|
+
* - `!this.noSql.supportsAutoKey` as the implementation-specific default.
|
|
54
|
+
*/
|
|
55
|
+
private _validateRow;
|
|
56
|
+
private _parseData;
|
|
57
|
+
private _rowToEntry;
|
|
58
|
+
private _doGet;
|
|
59
|
+
private _doPut;
|
|
60
|
+
private _doPost;
|
|
61
|
+
private _doDelete;
|
|
62
|
+
doApiRequest(request: OINOApiRequest): Promise<OINOApiResult>;
|
|
63
|
+
doBatchUpdate(method: string, rowId: string, rowData: OINOApiData, queryParams?: OINOQueryParams): Promise<OINOApiResult>;
|
|
64
|
+
doBatchApiRequest(request: OINOApiRequest): Promise<OINOApiResult>;
|
|
65
|
+
doHttpRequest(request: OINOHttpRequest, rowId: string, rowData: OINOApiData, queryParams: OINOQueryParams): Promise<OINOApiResult>;
|
|
66
|
+
doRequest(method: string, rowId: string, rowData: OINOApiData, queryParams: OINOQueryParams, contentType?: OINOContentType): Promise<OINOApiResult>;
|
|
67
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { OINONoSql } from "./OINONoSql.js";
|
|
2
|
+
/**
|
|
3
|
+
* NoSQL class (constructor) type
|
|
4
|
+
* @param params nosql parameters
|
|
5
|
+
*/
|
|
6
|
+
export type OINONoSqlConstructor = new (params: OINONoSqlParams) => OINONoSql;
|
|
7
|
+
/** NoSQL storage connection parameters */
|
|
8
|
+
export type OINONoSqlParams = {
|
|
9
|
+
/** Name of the nosql class (e.g. OINONoSqlAzureTable) */
|
|
10
|
+
type: string;
|
|
11
|
+
/** Service endpoint URL */
|
|
12
|
+
url: string;
|
|
13
|
+
/** Table name */
|
|
14
|
+
table: string;
|
|
15
|
+
/** Provider-specific connection string (e.g. Azure Storage connection string) */
|
|
16
|
+
connectionStr?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Optional static partition key. When set, all read/write operations are
|
|
19
|
+
* automatically scoped to this partition key, allowing multiple logical
|
|
20
|
+
* tables to share a single Azure Table Storage table.
|
|
21
|
+
*/
|
|
22
|
+
staticPartitionKey?: string;
|
|
23
|
+
};
|
|
24
|
+
/** A single NoSQL entity entry */
|
|
25
|
+
export type OINONoSqlEntry = {
|
|
26
|
+
/** Primary key values in the order defined by the implementation's data model */
|
|
27
|
+
primaryKey: string[];
|
|
28
|
+
/** Last modification timestamp */
|
|
29
|
+
timestamp: Date;
|
|
30
|
+
/** Entity tag */
|
|
31
|
+
etag: string;
|
|
32
|
+
/** All custom entity properties as a key-value map */
|
|
33
|
+
properties: Record<string, unknown>;
|
|
34
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { OINODataModel, OINOMemoryDataset } from "@oino-ts/common";
|
|
2
|
+
import { OINONoSqlApi } from "./OINONoSqlApi.js";
|
|
3
|
+
import { OINONoSqlEntry } from "./OINONoSqlConstants.js";
|
|
4
|
+
/**
|
|
5
|
+
* Static data model for NoSQL entity listings.
|
|
6
|
+
*
|
|
7
|
+
* The canonical field order is determined by the implementation's
|
|
8
|
+
* `initializeApiDatamodel` call. Primary key fields are mapped positionally
|
|
9
|
+
* to `OINONoSqlEntry.primaryKey`, while the remaining fields (`timestamp`,
|
|
10
|
+
* `etag`, `properties`) are matched by name.
|
|
11
|
+
*/
|
|
12
|
+
export declare class OINONoSqlDataModel extends OINODataModel {
|
|
13
|
+
/** Reference to the owning NoSQL API */
|
|
14
|
+
readonly noSqlApi: OINONoSqlApi;
|
|
15
|
+
/**
|
|
16
|
+
* Constructor. Fields are added externally by the nosql implementation
|
|
17
|
+
* via `initializeApiDatamodel`.
|
|
18
|
+
*
|
|
19
|
+
* @param api the `OINONoSqlApi` that owns this data model
|
|
20
|
+
*/
|
|
21
|
+
constructor(api: OINONoSqlApi);
|
|
22
|
+
/**
|
|
23
|
+
* Convert an array of NoSQL entries into an in-memory dataset whose
|
|
24
|
+
* columns match the fields present in this model.
|
|
25
|
+
*
|
|
26
|
+
* @param entries nosql entries from the storage backend
|
|
27
|
+
*/
|
|
28
|
+
entriesToDataset(entries: OINONoSqlEntry[]): OINOMemoryDataset;
|
|
29
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { OINOApiParams } from "@oino-ts/common";
|
|
2
|
+
import { OINONoSqlParams, OINONoSqlConstructor } from "./OINONoSqlConstants.js";
|
|
3
|
+
import { OINONoSql } from "./OINONoSql.js";
|
|
4
|
+
import { OINONoSqlApi } from "./OINONoSqlApi.js";
|
|
5
|
+
/**
|
|
6
|
+
* Static factory for creating `OINONoSql` instances and `OINONoSqlApi` instances
|
|
7
|
+
* from registered provider classes.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* ```ts
|
|
11
|
+
* OINONoSqlFactory.registerNoSql("OINONoSqlAzureTable", OINONoSqlAzureTable)
|
|
12
|
+
* const nosql = await OINONoSqlFactory.createNoSql({ type: "OINONoSqlAzureTable", ... })
|
|
13
|
+
* const api = await OINONoSqlFactory.createApi(nosql, { apiName: "entities", tableName: "myTable" })
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare class OINONoSqlFactory {
|
|
17
|
+
private static _registry;
|
|
18
|
+
/**
|
|
19
|
+
* Register a nosql provider class under the given name.
|
|
20
|
+
*
|
|
21
|
+
* @param name name used in `OINONoSqlParams.type`
|
|
22
|
+
* @param noSqlClass constructor of the provider
|
|
23
|
+
*/
|
|
24
|
+
static registerNoSql(name: string, noSqlClass: OINONoSqlConstructor): void;
|
|
25
|
+
/**
|
|
26
|
+
* Create and optionally connect/validate a nosql backend from params.
|
|
27
|
+
*
|
|
28
|
+
* @param params connection parameters
|
|
29
|
+
* @param connect if true, calls `connect()` on the backend
|
|
30
|
+
* @param validate if true, calls `validate()` on the backend
|
|
31
|
+
*/
|
|
32
|
+
static createNoSql(params: OINONoSqlParams, connect?: boolean, validate?: boolean): Promise<OINONoSql>;
|
|
33
|
+
/**
|
|
34
|
+
* Create an `OINONoSqlApi` and initialise its data model.
|
|
35
|
+
*
|
|
36
|
+
* @param noSql nosql backend to use
|
|
37
|
+
* @param params API parameters
|
|
38
|
+
*/
|
|
39
|
+
static createApi(noSql: OINONoSql, params: OINOApiParams): Promise<OINONoSqlApi>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { OINONoSql } from "./OINONoSql.js";
|
|
2
|
+
export { OINONoSqlDataModel } from "./OINONoSqlDataModel.js";
|
|
3
|
+
export { OINONoSqlFactory } from "./OINONoSqlFactory.js";
|
|
4
|
+
export { OINONoSqlApi } from "./OINONoSqlApi.js";
|
|
5
|
+
export { type OINONoSqlConstructor, type OINONoSqlParams, type OINONoSqlEntry } from "./OINONoSqlConstants.js";
|