@oino-ts/hashid 0.0.16 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -37
- package/dist/cjs/OINOHashid.js +2 -2
- package/dist/esm/OINOHashid.js +2 -2
- package/package.json +2 -2
- package/src/OINOHashid.ts +2 -2
package/README.md
CHANGED
|
@@ -59,20 +59,8 @@
|
|
|
59
59
|
|
|
60
60
|
## RESTfull
|
|
61
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
|
-
### HTTP GET
|
|
64
|
-
```
|
|
65
|
-
Request and response:
|
|
66
|
-
> curl.exe -X GET http://localhost:3001/orderdetails/11077:77
|
|
67
|
-
[
|
|
68
|
-
{"_OINOID_":"11077:77","OrderID":11077,"ProductID":77,"UnitPrice":13,"Quantity":2,"Discount":0}
|
|
69
|
-
]
|
|
70
|
-
|
|
71
|
-
SQL:
|
|
72
|
-
SELECT "OrderID","ProductID","UnitPrice","Quantity","Discount" FROM [OrderDetails] WHERE ("OrderID"=11077 AND "ProductID"=77);
|
|
73
|
-
```
|
|
74
62
|
|
|
75
|
-
|
|
63
|
+
For example HTTP POST
|
|
76
64
|
```
|
|
77
65
|
Request and response:
|
|
78
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}]'
|
|
@@ -82,31 +70,12 @@
|
|
|
82
70
|
INSERT INTO [OrderDetails] ("OrderID","ProductID","UnitPrice","Quantity","Discount") VALUES (11077,99,19,1,0);
|
|
83
71
|
```
|
|
84
72
|
|
|
85
|
-
### HTTP PUT
|
|
86
|
-
```
|
|
87
|
-
Request and response:
|
|
88
|
-
> curl.exe -X PUT http://localhost:3001/orderdetails/11077:99 -H "Content-Type: application/json" --data '[{\"UnitPrice\":20}]'
|
|
89
|
-
{"success":true,"statusCode":200,"statusMessage":"OK","messages":[]}
|
|
90
|
-
|
|
91
|
-
SQL:
|
|
92
|
-
UPDATE [OrderDetails] SET "UnitPrice"=20 WHERE ("OrderID"=11077 AND "ProductID"=99);
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
### HTTP DELETE
|
|
96
|
-
```
|
|
97
|
-
Request and response:
|
|
98
|
-
> curl.exe -X DELETE http://localhost:3001/orderdetails/11077:99
|
|
99
|
-
{"success":true,"statusCode":200,"statusMessage":"OK","messages":[]}
|
|
100
73
|
|
|
101
|
-
SQL:
|
|
102
|
-
DELETE FROM [OrderDetails] WHERE ("OrderID"=11077 AND "ProductID"=99);
|
|
103
|
-
```
|
|
104
|
-
|
|
105
74
|
## Universal Serialization
|
|
106
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.
|
|
107
76
|
|
|
108
77
|
### Features
|
|
109
|
-
- Files can be sent to BLOB fields using BASE64 encoding.
|
|
78
|
+
- Files can be sent to BLOB fields using BASE64 or MIME multipart encoding.
|
|
110
79
|
- Datetimes are (optionally) normalized to ISO 8601 format.
|
|
111
80
|
- Extended JSON-encoding
|
|
112
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).
|
|
@@ -135,7 +104,7 @@
|
|
|
135
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`.
|
|
136
105
|
|
|
137
106
|
## Power Of SQL
|
|
138
|
-
Since OINO is just generating SQL, WHERE-conditions can be defined with [`OINOSqlFilter`](https://pragmatta.github.io/oino-ts/classes/db_src.OINODbSqlFilter.html)
|
|
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.
|
|
139
108
|
|
|
140
109
|
## Swagger Support
|
|
141
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.
|
|
@@ -179,8 +148,8 @@
|
|
|
179
148
|
### Batch updates
|
|
180
149
|
Supporting batch updates similar to batch inserts is slightly bending the RESTfull principles but would still be a useful optional feature.
|
|
181
150
|
|
|
182
|
-
### Aggregation
|
|
183
|
-
Similar to filtering and
|
|
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.
|
|
184
153
|
|
|
185
154
|
### Streaming
|
|
186
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.
|
|
@@ -222,4 +191,3 @@
|
|
|
222
191
|
|
|
223
192
|
## SQL Scripts
|
|
224
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).
|
|
225
|
-
|
package/dist/cjs/OINOHashid.js
CHANGED
|
@@ -46,7 +46,7 @@ class OINOHashid {
|
|
|
46
46
|
}
|
|
47
47
|
this._staticIds = staticIds;
|
|
48
48
|
this._key = Buffer.from(key, 'hex');
|
|
49
|
-
this._iv =
|
|
49
|
+
this._iv = Buffer.alloc(16);
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* Encode given id value as a hashid either using random data or given seed value for nonce.
|
|
@@ -94,7 +94,7 @@ class OINOHashid {
|
|
|
94
94
|
const hash = hmac.digest();
|
|
95
95
|
hash.copy(this._iv, 0, 0, 16);
|
|
96
96
|
const cryptotext = hashid.substring(this._minLength);
|
|
97
|
-
const cryptobytes =
|
|
97
|
+
const cryptobytes = Buffer.from(hashidEncoder.decode(cryptotext));
|
|
98
98
|
const decipher = (0, node_crypto_1.createDecipheriv)('aes-128-gcm', this._key, this._iv);
|
|
99
99
|
const plaintext = decipher.update(cryptobytes, undefined, 'utf8'); //, cryptotext, 'base64url', 'utf8')
|
|
100
100
|
return plaintext.split(" ")[0];
|
package/dist/esm/OINOHashid.js
CHANGED
|
@@ -43,7 +43,7 @@ export class OINOHashid {
|
|
|
43
43
|
}
|
|
44
44
|
this._staticIds = staticIds;
|
|
45
45
|
this._key = Buffer.from(key, 'hex');
|
|
46
|
-
this._iv =
|
|
46
|
+
this._iv = Buffer.alloc(16);
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
49
|
* Encode given id value as a hashid either using random data or given seed value for nonce.
|
|
@@ -91,7 +91,7 @@ export class OINOHashid {
|
|
|
91
91
|
const hash = hmac.digest();
|
|
92
92
|
hash.copy(this._iv, 0, 0, 16);
|
|
93
93
|
const cryptotext = hashid.substring(this._minLength);
|
|
94
|
-
const cryptobytes =
|
|
94
|
+
const cryptobytes = Buffer.from(hashidEncoder.decode(cryptotext));
|
|
95
95
|
const decipher = createDecipheriv('aes-128-gcm', this._key, this._iv);
|
|
96
96
|
const plaintext = decipher.update(cryptobytes, undefined, 'utf8'); //, cryptotext, 'base64url', 'utf8')
|
|
97
97
|
return plaintext.split(" ")[0];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oino-ts/hashid",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"description": "OINO TS package for hashid's.",
|
|
5
5
|
"author": "Matias Kiviniemi (pragmatta)",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"types": "./dist/types/index.d.ts",
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@types/node": "^20.12.7",
|
|
21
|
-
"@oino-ts/types": "^0.0.
|
|
21
|
+
"@oino-ts/types": "^0.0.17",
|
|
22
22
|
"base-x": "5.0.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
package/src/OINOHashid.ts
CHANGED
|
@@ -48,7 +48,7 @@ export class OINOHashid {
|
|
|
48
48
|
}
|
|
49
49
|
this._staticIds = staticIds
|
|
50
50
|
this._key = Buffer.from(key, 'hex')
|
|
51
|
-
this._iv =
|
|
51
|
+
this._iv = Buffer.alloc(16)
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/**
|
|
@@ -102,7 +102,7 @@ export class OINOHashid {
|
|
|
102
102
|
hash.copy(this._iv, 0, 0, 16)
|
|
103
103
|
|
|
104
104
|
const cryptotext:string = hashid.substring(this._minLength)
|
|
105
|
-
const cryptobytes:Buffer =
|
|
105
|
+
const cryptobytes:Buffer = Buffer.from(hashidEncoder.decode(cryptotext))
|
|
106
106
|
const decipher = createDecipheriv('aes-128-gcm', this._key, this._iv)
|
|
107
107
|
const plaintext = decipher.update(cryptobytes, undefined, 'utf8') //, cryptotext, 'base64url', 'utf8')
|
|
108
108
|
|