Skip to content

Commit

Permalink
Merge pull request #45 from ardeearam/main
Browse files Browse the repository at this point in the history
Release - 1.7.0
  • Loading branch information
ardeearam authored May 1, 2023
2 parents 72e6d4d + 4d5a3b5 commit 155cc23
Show file tree
Hide file tree
Showing 10 changed files with 335 additions and 70 deletions.
5 changes: 5 additions & 0 deletions RELEASE.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# v1.7.0
* Added Session#create() and Session#cleanupExpired
* Added @klaudsol/commons/lib/Crypto for cryptography-related functions
* Crypto#sha256 has can now be encoded as 'hex' or 'base64' (used to be 'base64' only)

# v1.6.1
* Fix: Removed trailing commas on migration script

Expand Down
39 changes: 39 additions & 0 deletions dist/lib/Crypto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.sha256 = void 0;
var _crypto = _interopRequireDefault(require("crypto"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
/**
* MIT License
Copyright (c) 2022 KlaudSol Philippines, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
**/

//defaults to base64 to preserve backwards-compability
var sha256 = function sha256(text) {
var encoding = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'base64';
return _crypto["default"].createHash('sha256').update(text).digest(encoding);
};
exports.sha256 = sha256;
28 changes: 27 additions & 1 deletion dist/lib/DB.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,14 @@ var DB = /*#__PURE__*/function () {
}]);
return DB;
}();
var _default = DB;
var _default = DB; //DEPRECATE on v2.0.0
exports["default"] = _default;
var sha256 = function sha256(text) {
console.log('DB.sha256 is deprecated. Please use sha256 from @klaudsol/commons/lib/Crypto instead.');
return _crypto["default"].createHash('sha256').update(text).digest('base64');
};

//DEPRECATE on v2.0.0
exports.sha256 = sha256;
var fieldsForSelect = function fieldsForSelect(table, fieldsHash) {
return Object.entries(fieldsHash).map(function (_ref8) {
Expand All @@ -147,6 +150,8 @@ var fieldsForSelect = function fieldsForSelect(table, fieldsHash) {
return "".concat(table, ".").concat(name);
}).join(',');
};

//DEPRECATE on v2.0.0
exports.fieldsForSelect = fieldsForSelect;
var allowedFieldsOnCreate = function allowedFieldsOnCreate(fieldsHash) {
return Object.entries(fieldsHash).filter(function (_ref10) {
Expand All @@ -156,13 +161,17 @@ var allowedFieldsOnCreate = function allowedFieldsOnCreate(fieldsHash) {
return allowOnCreate;
});
};

//DEPRECATE on v2.0.0
var fieldsForInsert = function fieldsForInsert(fieldsHash) {
return allowedFieldsOnCreate(fieldsHash).map(function (_ref12) {
var _ref13 = _slicedToArray(_ref12, 1),
name = _ref13[0];
return "".concat(name);
}).join(',');
};

//DEPRECATE on v2.0.0
exports.fieldsForInsert = fieldsForInsert;
var fieldParametersForInsert = function fieldParametersForInsert(fieldsHash) {
return allowedFieldsOnCreate(fieldsHash).map(function (_ref14) {
Expand All @@ -171,6 +180,8 @@ var fieldParametersForInsert = function fieldParametersForInsert(fieldsHash) {
return ":".concat(name);
}).join(',');
};

//DEPRECATE on v2.0.0
exports.fieldParametersForInsert = fieldParametersForInsert;
var executeStatementParamsForInsert = function executeStatementParamsForInsert(fieldsHash, model, transform) {
return allowedFieldsOnCreate(fieldsHash).map(function (_ref16) {
Expand All @@ -185,6 +196,8 @@ var executeStatementParamsForInsert = function executeStatementParamsForInsert(f
};
});
};

//DEPRECATE on v2.0.0
exports.executeStatementParamsForInsert = executeStatementParamsForInsert;
var allowedFieldsOnUpdate = function allowedFieldsOnUpdate(fieldsHash) {
return Object.entries(fieldsHash).filter(function (_ref18) {
Expand All @@ -194,13 +207,17 @@ var allowedFieldsOnUpdate = function allowedFieldsOnUpdate(fieldsHash) {
return allowOnUpdate;
});
};

//DEPRECATE on v2.0.0
var fieldsForUpdate = function fieldsForUpdate(fieldsHash) {
return allowedFieldsOnUpdate(fieldsHash).map(function (_ref20) {
var _ref21 = _slicedToArray(_ref20, 1),
name = _ref21[0];
return "".concat(name, " = :").concat(name);
}).join(',');
};

//DEPRECATE on v2.0.0
exports.fieldsForUpdate = fieldsForUpdate;
var executeStatementParamsForUpdate = function executeStatementParamsForUpdate(fieldsHash, model, transform) {
return allowedFieldsOnUpdate(fieldsHash).map(function (_ref22) {
Expand All @@ -215,6 +232,7 @@ var executeStatementParamsForUpdate = function executeStatementParamsForUpdate(f
});
};

//DEPRECATE on v2.0.0
//Allowed datatypes in Aurora Data API
exports.executeStatementParamsForUpdate = executeStatementParamsForUpdate;
var AURORA_TYPE = {
Expand Down Expand Up @@ -255,6 +273,8 @@ A single Aurora record looks something like this:
It is rather unwieldy, and has reliance on the order of the fields in the query, so we need a layer that shields the app from this
format, and just return a sane key-value Object.
*/

//DEPRECATE on v2.0.0
exports.AURORA_TYPE = AURORA_TYPE;
var fromAurora = function fromAurora(record, fields) {
return Object.fromEntries(Object.entries(fields).map(function (_ref24, index) {
Expand All @@ -264,6 +284,8 @@ var fromAurora = function fromAurora(record, fields) {
return [key, record[index]["".concat(auroraType, "Value")]];
}));
};

//DEPRECATE on v2.0.0
exports.fromAurora = fromAurora;
var sanitizeData = function sanitizeData(rawData, fields) {
var allowedFields = Object.entries(fields).map(function (_ref26) {
Expand All @@ -284,12 +306,16 @@ var sanitizeData = function sanitizeData(rawData, fields) {
numberOfRecordsUpdated: 1 }
*/

//DEPRECATE on v2.0.0
exports.sanitizeData = sanitizeData;
var fromInsertAurora = function fromInsertAurora(record) {
return {
id: record.generatedFields[0].longValue
};
};

//DEPRECATE on v2.0.0
exports.fromInsertAurora = fromInsertAurora;
var fromDeleteAurora = function fromDeleteAurora(record) {
return record.numberOfRecordsUpdated > 0;
Expand Down
Loading

0 comments on commit 155cc23

Please sign in to comment.