@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.
Files changed (62) hide show
  1. package/blob/src/OINOBlob.d.ts +78 -0
  2. package/blob/src/OINOBlobApi.d.ts +49 -0
  3. package/blob/src/OINOBlobConstants.d.ts +37 -0
  4. package/blob/src/OINOBlobDataModel.d.ts +33 -0
  5. package/blob/src/OINOBlobFactory.d.ts +40 -0
  6. package/blob/src/index.d.ts +5 -0
  7. package/blob-aws/src/OINOBlobAwsS3.d.ts +90 -0
  8. package/blob-aws/src/index.d.ts +1 -0
  9. package/blob-azure/src/OINOBlobAzureTable.d.ts +86 -0
  10. package/blob-azure/src/index.d.ts +1 -0
  11. package/common/src/OINOApi.d.ts +191 -0
  12. package/common/src/OINOConfig.d.ts +63 -0
  13. package/common/src/OINOConstants.d.ts +51 -0
  14. package/common/src/OINODataField.d.ts +209 -0
  15. package/common/src/OINODataModel.d.ts +78 -0
  16. package/common/src/OINODataSource.d.ts +184 -0
  17. package/common/src/OINOHtmlTemplate.d.ts +1 -1
  18. package/common/src/OINOModelSet.d.ts +64 -0
  19. package/common/src/OINOParser.d.ts +42 -0
  20. package/common/src/OINOQueryParams.d.ts +270 -0
  21. package/common/src/OINORequest.d.ts +4 -1
  22. package/common/src/OINOResult.d.ts +1 -1
  23. package/common/src/OINOStr.d.ts +1 -1
  24. package/common/src/OINOSwagger.d.ts +25 -0
  25. package/common/src/index.d.ts +14 -31
  26. package/db/src/OINODb.d.ts +55 -0
  27. package/db/src/OINODbApi.d.ts +78 -0
  28. package/db/src/OINODbConfig.d.ts +56 -0
  29. package/db/src/OINODbConstants.d.ts +23 -0
  30. package/db/src/OINODbDataField.d.ts +210 -0
  31. package/db/src/OINODbDataModel.d.ts +55 -0
  32. package/db/src/OINODbDataSet.d.ts +95 -0
  33. package/db/src/OINODbFactory.d.ts +34 -0
  34. package/db/src/OINODbModelSet.d.ts +62 -0
  35. package/db/src/OINODbParser.d.ts +42 -0
  36. package/db/src/OINODbQueryParams.d.ts +72 -0
  37. package/db/src/OINODbRequestParams.d.ts +146 -0
  38. package/db/src/OINODbSqlParams.d.ts +296 -0
  39. package/db/src/OINODbSwagger.d.ts +25 -0
  40. package/db/src/index.d.ts +6 -0
  41. package/db-bunsqlite/src/OINODbBunSqlite.d.ts +99 -0
  42. package/db-bunsqlite/src/index.d.ts +1 -0
  43. package/db-mariadb/src/OINODbMariadb.d.ts +99 -0
  44. package/db-mariadb/src/index.d.ts +1 -0
  45. package/db-mssql/src/OINODbMsSql.d.ts +116 -0
  46. package/db-mssql/src/index.d.ts +1 -0
  47. package/db-postgresql/src/OINODbPostgresql.d.ts +95 -0
  48. package/db-postgresql/src/index.d.ts +1 -0
  49. package/hashid/src/OINOHashid.d.ts +42 -0
  50. package/hashid/src/index.d.ts +1 -0
  51. package/index.d.ts +7 -7
  52. package/nosql/src/OINONoSql.d.ts +81 -0
  53. package/nosql/src/OINONoSqlApi.d.ts +67 -0
  54. package/nosql/src/OINONoSqlConstants.d.ts +34 -0
  55. package/nosql/src/OINONoSqlDataModel.d.ts +29 -0
  56. package/nosql/src/OINONoSqlFactory.d.ts +40 -0
  57. package/nosql/src/index.d.ts +5 -0
  58. package/nosql-aws/src/OINONoSqlAwsDynamo.d.ts +223 -0
  59. package/nosql-aws/src/index.d.ts +1 -0
  60. package/nosql-azure/src/OINONoSqlAzureTable.d.ts +130 -0
  61. package/nosql-azure/src/index.d.ts +1 -0
  62. package/package.json +28 -28
@@ -0,0 +1,223 @@
1
+ import { OINOApi, OINOResult, OINOQueryFilter } from "@oino-ts/common";
2
+ import { OINONoSql } from "@oino-ts/nosql";
3
+ import { type OINONoSqlEntry } from "@oino-ts/nosql";
4
+ /**
5
+ * Mutable accumulator used while building a DynamoDB expression string.
6
+ * Attribute names and values are collected here and later merged into
7
+ * `ExpressionAttributeNames` / `ExpressionAttributeValues` on the command.
8
+ */
9
+ type ExprBuilder = {
10
+ names: Record<string, string>;
11
+ values: Record<string, unknown>;
12
+ counter: number;
13
+ };
14
+ /**
15
+ * AWS DynamoDB implementation of `OINONoSql`.
16
+ *
17
+ * Authenticates using static IAM credentials supplied as a JSON-encoded
18
+ * connection string. Connection parameters map as:
19
+ * - `params.url` → optional custom endpoint URL (e.g. for DynamoDB Local:
20
+ * `http://localhost:8000`)
21
+ * - `params.table` → DynamoDB table name
22
+ * - `params.connectionStr` → JSON string:
23
+ * `{"region":"…","accessKeyId":"…","secretAccessKey":"…"}`
24
+ * - `params.staticPartitionKey` → scope all operations to a fixed partition key
25
+ *
26
+ * Register and use via the factory:
27
+ * ```ts
28
+ * import { OINONoSqlFactory } from "@oino-ts/nosql"
29
+ * import { OINONoSqlAwsDynamoDB } from "@oino-ts/nosql-aws"
30
+ *
31
+ * OINONoSqlFactory.registerNoSql("OINONoSqlAwsDynamoDB", OINONoSqlAwsDynamoDB)
32
+ *
33
+ * const nosql = await OINONoSqlFactory.createNoSql({
34
+ * type: "OINONoSqlAwsDynamoDB",
35
+ * url: "",
36
+ * table: "myTable",
37
+ * connectionStr: JSON.stringify({
38
+ * region: "us-east-1",
39
+ * accessKeyId: process.env.AWS_ACCESS_KEY_ID,
40
+ * secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
41
+ * })
42
+ * })
43
+ * const api = await OINONoSqlFactory.createApi(nosql, {
44
+ * apiName: "entities",
45
+ * tableName: "myTable"
46
+ * })
47
+ * ```
48
+ *
49
+ * ## DynamoDB table schema
50
+ *
51
+ * The target table must have:
52
+ * - A HASH key of type **String** (any attribute name is accepted)
53
+ * - A RANGE key of type **String** (any attribute name is accepted)
54
+ *
55
+ * The actual attribute names are read from the table during `validate()` and
56
+ * stored on the instance. The OINO API field names (`partitionKey`, `rowKey`)
57
+ * will reflect the real DynamoDB attribute names once the backend is validated.
58
+ *
59
+ * Two additional system attributes are managed automatically:
60
+ * - `_timestamp` – ISO-8601 timestamp, set on every upsert
61
+ * - `_etag` – UUID v4, regenerated on every upsert
62
+ *
63
+ * All custom entity data is stored as top-level item attributes and
64
+ * serialised into `OINONoSqlEntry.properties` on read.
65
+ *
66
+ * ## Static partition key
67
+ *
68
+ * Set `staticPartitionKey` to scope all operations to a fixed partition key,
69
+ * allowing multiple logical tables to share one physical DynamoDB table:
70
+ * ```ts
71
+ * const nosql = await OINONoSqlFactory.createNoSql({
72
+ * type: "OINONoSqlAwsDynamoDB",
73
+ * url: "",
74
+ * table: "sharedTable",
75
+ * connectionStr: process.env.DYNAMO_CONNECTION_STR,
76
+ * staticPartitionKey: "myLogicalTable"
77
+ * })
78
+ * ```
79
+ *
80
+ * ## Filter support
81
+ *
82
+ * Filters on `partitionKey` are used to choose between `Query` (cheap, when
83
+ * an equality predicate on `partitionKey` is detected) and `Scan` (full-table).
84
+ *
85
+ * All predicates except `like` are translated to DynamoDB `FilterExpression`
86
+ * (evaluated server-side, but billed at scan cost). `like` predicates are
87
+ * evaluated in-memory after the DynamoDB response is received.
88
+ *
89
+ * DynamoDB operators supported: `=`, `<>`, `<`, `<=`, `>`, `>=`,
90
+ * `attribute_exists`, `attribute_not_exists`, `AND`, `OR`, `NOT`.
91
+ */
92
+ export declare class OINONoSqlAwsDynamo extends OINONoSql {
93
+ private _rawClient;
94
+ private _docClient;
95
+ /** Actual DynamoDB HASH key attribute name, discovered during validate(). */
96
+ private _hashKeyAttr;
97
+ /** Actual DynamoDB RANGE key attribute name, discovered during validate(). */
98
+ private _rangeKeyAttr;
99
+ /**
100
+ * Walk the `OINOQueryFilter` tree and attempt to build a DynamoDB
101
+ * `FilterExpression` string, accumulating placeholder names and values
102
+ * into `builder`.
103
+ *
104
+ * Returns `undefined` for sub-trees that contain untranslatable predicates
105
+ * (currently only the `like` operator). For `OR` nodes, if either child
106
+ * cannot be expressed, the entire `OR` returns `undefined` because omitting
107
+ * one branch would change the semantics.
108
+ *
109
+ * @param filter filter node to translate
110
+ * @param builder mutable accumulator for placeholder names / values
111
+ */
112
+ static buildFilterExpression(filter: OINOQueryFilter, builder: ExprBuilder): string | undefined;
113
+ /**
114
+ * Recursively search an AND-branch filter tree for a top-level
115
+ * hash-key `eq <value>` leaf. Returns the value string when found,
116
+ * or `undefined` if no such leaf exists at the AND level.
117
+ *
118
+ * The search deliberately does not descend into OR or NOT branches because
119
+ * extracting a partition key equality from inside an OR would change the
120
+ * scan semantics.
121
+ *
122
+ * @param filter filter tree to search
123
+ */
124
+ private extractPartitionKeyEq;
125
+ /**
126
+ * Recursively rebuild the filter tree, removing any top-level (AND-branch)
127
+ * hash-key `eq <value>` leaf. Used to avoid passing the partition key
128
+ * predicate in both `KeyConditionExpression` and `FilterExpression`.
129
+ *
130
+ * Returns `undefined` when the entire tree reduces to nothing after removal.
131
+ *
132
+ * @param filter filter tree to process
133
+ */
134
+ private stripPartitionKeyEq;
135
+ /**
136
+ * Initialise the AWS SDK DynamoDB Document Client from the JSON-encoded
137
+ * `connectionStr`. Does not perform any network call.
138
+ */
139
+ connect(): Promise<OINOResult>;
140
+ /**
141
+ * Verify that the target table exists, read its key schema, and store the
142
+ * HASH and RANGE attribute names for use by all subsequent operations.
143
+ * Both key attributes must be of type String (`S`).
144
+ */
145
+ validate(): Promise<OINOResult>;
146
+ /**
147
+ * Release the client reference.
148
+ */
149
+ disconnect(): Promise<void>;
150
+ /**
151
+ * List entities from the table.
152
+ *
153
+ * Uses `Query` when an equality predicate on `partitionKey` can be
154
+ * extracted from the filter (or when `staticPartitionKey` is set);
155
+ * otherwise falls back to `Scan`.
156
+ *
157
+ * All predicates except `like` are translated to a DynamoDB
158
+ * `FilterExpression` and evaluated server-side. `like` predicates are
159
+ * evaluated in-memory after the response is received.
160
+ *
161
+ * @param filter optional query filter to apply
162
+ */
163
+ listEntries(filter?: OINOQueryFilter): Promise<OINONoSqlEntry[]>;
164
+ /**
165
+ * Fetch a single entity by its primary key values.
166
+ *
167
+ * @param primaryKey [partitionKey, rowKey]
168
+ */
169
+ getEntry(primaryKey: string[]): Promise<OINONoSqlEntry | null>;
170
+ /**
171
+ * Upsert (insert or replace) an entity.
172
+ *
173
+ * `_timestamp` is set to the current UTC time on every upsert.
174
+ * `_etag` is set to a new UUID v4 on every upsert.
175
+ *
176
+ * All fields in `entry.properties` are written as top-level DynamoDB item
177
+ * attributes alongside the key and system fields.
178
+ *
179
+ * @param entry entity to upsert
180
+ */
181
+ upsertEntry(entry: OINONoSqlEntry): Promise<void>;
182
+ /**
183
+ * Batch-upsert using DynamoDB `BatchWriteCommand`. DynamoDB limits each
184
+ * call to 25 items; entries are chunked accordingly. Any items returned
185
+ * in `UnprocessedItems` (capacity exceeded) are retried once before
186
+ * throwing.
187
+ */
188
+ upsertEntries(entries: OINONoSqlEntry[]): Promise<void>;
189
+ /**
190
+ * Delete an entity by its primary key values.
191
+ *
192
+ * @param primaryKey [partitionKey, rowKey]
193
+ */
194
+ deleteEntry(primaryKey: string[]): Promise<void>;
195
+ /**
196
+ * Attach a static `OINONoSqlDataModel` to the given API, adding the five
197
+ * standard fields that mirror the `OINONoSqlEntry` structure.
198
+ *
199
+ * Field mapping to DynamoDB item attributes:
200
+ * | OINO field | DynamoDB attribute | Key role |
201
+ * |-------------------|-------------------------|----------------|
202
+ * | `_hashKeyAttr` | discovered HASH attr | Partition key |
203
+ * | `_rangeKeyAttr` | discovered RANGE attr | Sort key |
204
+ * | `timestamp` | `_timestamp` | Managed, string|
205
+ * | `etag` | `_etag` | Managed, string|
206
+ * | `properties` | (all other attrs) | JSON-serialised|
207
+ *
208
+ * @param api the `OINONoSqlApi` whose data model is to be initialised
209
+ */
210
+ initializeApiDatamodel(api: OINOApi): Promise<void>;
211
+ /**
212
+ * Convert a raw DynamoDB item (as returned by `DynamoDBDocumentClient`)
213
+ * to an `OINONoSqlEntry`.
214
+ *
215
+ * The four system attributes (the HASH key, the RANGE key, `_timestamp`,
216
+ * `_etag`) are extracted using the attribute names discovered during
217
+ * `validate()`; every other attribute is collected into `properties`.
218
+ *
219
+ * @param item raw item from DynamoDB
220
+ */
221
+ private itemToEntry;
222
+ }
223
+ export {};
@@ -0,0 +1 @@
1
+ export { OINONoSqlAwsDynamo } from "./OINONoSqlAwsDynamo.js";
@@ -0,0 +1,130 @@
1
+ import { OINOApi, OINOResult, OINOQueryFilter } from "@oino-ts/common";
2
+ import { OINONoSql } from "@oino-ts/nosql";
3
+ import { type OINONoSqlEntry } from "@oino-ts/nosql";
4
+ /**
5
+ * Azure Table Storage implementation of `OINONoSql`.
6
+ *
7
+ * Authenticates using an Azure Storage connection string. Connection parameters map as:
8
+ * - `params.url` → table service endpoint, e.g. `https://<account>.table.core.windows.net`
9
+ * - `params.table` → table name
10
+ * - `params.connectionStr` → Azure Storage connection string (e.g. `DefaultEndpointsProtocol=https;AccountName=...`)
11
+ *
12
+ * Register and use via the factory:
13
+ * ```ts
14
+ * import { OINONoSqlFactory } from "@oino-ts/nosql"
15
+ * import { OINONoSqlAzureTable } from "@oino-ts/nosql-azure"
16
+ *
17
+ * OINONoSqlFactory.registerNoSql("OINONoSqlAzureTable", OINONoSqlAzureTable)
18
+ *
19
+ * const nosql = await OINONoSqlFactory.createNoSql({
20
+ * type: "OINONoSqlAzureTable",
21
+ * url: "https://myaccount.table.core.windows.net",
22
+ * table: "myTable",
23
+ * connectionStr: process.env.AZURE_STORAGE_CONNECTION_STRING
24
+ * })
25
+ * const api = await OINONoSqlFactory.createApi(nosql, {
26
+ * apiName: "entities",
27
+ * tableName: "myTable"
28
+ * })
29
+ * ```
30
+ *
31
+ * ## Static partition key
32
+ *
33
+ * Set `staticPartitionKey` in the params to scope all operations to a fixed
34
+ * partition key. This lets multiple logical tables share one physical Azure
35
+ * Table Storage table:
36
+ * ```ts
37
+ * const nosql = await OINONoSqlFactory.createNoSql({
38
+ * type: "OINONoSqlAzureTable",
39
+ * url: "https://myaccount.table.core.windows.net",
40
+ * table: "sharedTable",
41
+ * connectionStr: process.env.AZURE_STORAGE_CONNECTION_STRING,
42
+ * staticPartitionKey: "myLogicalTable"
43
+ * })
44
+ * ```
45
+ *
46
+ * ## Filter support
47
+ *
48
+ * Filters on `partitionKey`, `rowKey`, and `timestamp` are translated to native
49
+ * Azure Table Storage OData query filter expressions and evaluated server-side.
50
+ * Filters on `etag` are evaluated in-memory after the listing.
51
+ *
52
+ * OData operators supported: `eq`, `ne`, `lt`, `le`, `gt`, `ge`, `and`, `or`, `not`.
53
+ * The `like` operator is not supported by OData and is evaluated in-memory.
54
+ */
55
+ export declare class OINONoSqlAzureTable extends OINONoSql {
56
+ private _tableClient;
57
+ /**
58
+ * Attempt to translate an `OINOQueryFilter` tree to an Azure Table Storage
59
+ * OData v3 filter expression string.
60
+ *
61
+ * Returns `undefined` for sub-trees that contain untranslatable predicates
62
+ * (e.g. filter on `etag`, or a `like` comparison). The caller falls back
63
+ * to in-memory evaluation for those cases.
64
+ *
65
+ * @param filter filter to translate
66
+ */
67
+ static filterToOData(filter: OINOQueryFilter): string | undefined;
68
+ /**
69
+ * Initialise the Azure SDK table client. Does not perform any network call.
70
+ */
71
+ connect(): Promise<OINOResult>;
72
+ /**
73
+ * Verify that the target table exists and is accessible.
74
+ */
75
+ validate(): Promise<OINOResult>;
76
+ /**
77
+ * Release the client reference.
78
+ */
79
+ disconnect(): Promise<void>;
80
+ /**
81
+ * List entities from the table, applying native OData filtering for
82
+ * `partitionKey`, `rowKey`, and `timestamp` predicates server-side, and
83
+ * performing in-memory evaluation for the remaining predicates.
84
+ *
85
+ * @param filter optional query filter to apply
86
+ */
87
+ listEntries(filter?: OINOQueryFilter): Promise<OINONoSqlEntry[]>;
88
+ /**
89
+ * Fetch a single entity by its primary key values.
90
+ *
91
+ * @param primaryKey [partitionKey, rowKey]
92
+ */
93
+ getEntry(primaryKey: string[]): Promise<OINONoSqlEntry | null>;
94
+ /**
95
+ * Upsert (insert or replace) an entity.
96
+ *
97
+ * All fields in `entry.properties` are written as top-level entity
98
+ * properties in Azure Table Storage.
99
+ *
100
+ * @param entry entity to upsert
101
+ */
102
+ upsertEntry(entry: OINONoSqlEntry): Promise<void>;
103
+ /**
104
+ * Batch-upsert using Azure Table Storage transactions. Each transaction
105
+ * is limited to 100 entities that share the same partition key. Entries
106
+ * are grouped by partition key first, then chunked to satisfy the limit.
107
+ */
108
+ upsertEntries(entries: OINONoSqlEntry[]): Promise<void>;
109
+ /**
110
+ * Delete an entity.
111
+ *
112
+ * @param primaryKey [partitionKey, rowKey]
113
+ */
114
+ deleteEntry(primaryKey: string[]): Promise<void>;
115
+ /**
116
+ * Attach a static `OINONoSqlDataModel` to the given API, adding all five
117
+ * standard fields.
118
+ *
119
+ * @param api the `OINONoSqlApi` whose data model is to be initialised
120
+ */
121
+ initializeApiDatamodel(api: OINOApi): Promise<void>;
122
+ /**
123
+ * Convert an Azure Table Storage entity to an `OINONoSqlEntry`.
124
+ * System fields (`partitionKey`, `rowKey`, `timestamp`, `etag`) are
125
+ * extracted; all remaining properties are collected into `properties`.
126
+ *
127
+ * @param entity raw entity from the Azure SDK
128
+ */
129
+ private static entityToEntry;
130
+ }
@@ -0,0 +1 @@
1
+ export { OINONoSqlAzureTable } from "./OINONoSqlAzureTable.js";
package/package.json CHANGED
@@ -1,28 +1,28 @@
1
- {
2
- "name": "@oino-ts/types",
3
- "version": "0.21.2",
4
- "description": "OINO TS package for types.",
5
- "author": "Matias Kiviniemi (pragmatta)",
6
- "license": "MPL-2.0",
7
- "repository": {
8
- "type": "git",
9
- "url": "https://github.com/pragmatta/oino-ts.git"
10
- },
11
- "keywords": [
12
- "types",
13
- "typescript",
14
- "library"
15
- ],
16
- "main": "",
17
- "types": "index.d.ts",
18
- "dependencies": {
19
- },
20
- "devDependencies": {
21
- "typescript": "~5.9.0",
22
- "@types/node": "^22.0.0"
23
- },
24
- "files": [
25
- "index.d.ts",
26
- "**/src/*.d.ts"
27
- ]
28
- }
1
+ {
2
+ "name": "@oino-ts/types",
3
+ "version": "1.0.0",
4
+ "description": "OINO TS package for types.",
5
+ "author": "Matias Kiviniemi (pragmatta)",
6
+ "license": "MPL-2.0",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/pragmatta/oino-ts.git"
10
+ },
11
+ "keywords": [
12
+ "types",
13
+ "typescript",
14
+ "library"
15
+ ],
16
+ "main": "",
17
+ "types": "index.d.ts",
18
+ "dependencies": {
19
+ },
20
+ "devDependencies": {
21
+ "typescript": "~5.9.0",
22
+ "@types/node": "^22.0.0"
23
+ },
24
+ "files": [
25
+ "index.d.ts",
26
+ "**/src/*.d.ts"
27
+ ]
28
+ }