@qrvey/data-persistence 0.0.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 (81) hide show
  1. package/README.md +77 -0
  2. package/dist/cjs/helpers/crudHelpers.js +27 -0
  3. package/dist/cjs/helpers/crudHelpers.js.map +1 -0
  4. package/dist/cjs/helpers/queryHelpers.js +10 -0
  5. package/dist/cjs/helpers/queryHelpers.js.map +1 -0
  6. package/dist/cjs/helpers/tableHelper.js +25 -0
  7. package/dist/cjs/helpers/tableHelper.js.map +1 -0
  8. package/dist/cjs/index.js +15 -0
  9. package/dist/cjs/index.js.map +1 -0
  10. package/dist/cjs/interfaces/compoundFilter.interface.js +3 -0
  11. package/dist/cjs/interfaces/compoundFilter.interface.js.map +1 -0
  12. package/dist/cjs/interfaces/crudService.interface.js +3 -0
  13. package/dist/cjs/interfaces/crudService.interface.js.map +1 -0
  14. package/dist/cjs/interfaces/filter.interface.js +3 -0
  15. package/dist/cjs/interfaces/filter.interface.js.map +1 -0
  16. package/dist/cjs/interfaces/findIndex.interface.js +3 -0
  17. package/dist/cjs/interfaces/findIndex.interface.js.map +1 -0
  18. package/dist/cjs/interfaces/findOptions.interface.js +3 -0
  19. package/dist/cjs/interfaces/findOptions.interface.js.map +1 -0
  20. package/dist/cjs/interfaces/findPagination.interface.js +3 -0
  21. package/dist/cjs/interfaces/findPagination.interface.js.map +1 -0
  22. package/dist/cjs/interfaces/findResult.interface.js +3 -0
  23. package/dist/cjs/interfaces/findResult.interface.js.map +1 -0
  24. package/dist/cjs/interfaces/index.js +29 -0
  25. package/dist/cjs/interfaces/index.js.map +1 -0
  26. package/dist/cjs/interfaces/queryBuilder.interface.js +3 -0
  27. package/dist/cjs/interfaces/queryBuilder.interface.js.map +1 -0
  28. package/dist/cjs/interfaces/queryBuilderCondition.interface.js +3 -0
  29. package/dist/cjs/interfaces/queryBuilderCondition.interface.js.map +1 -0
  30. package/dist/cjs/interfaces/queryOptions.interface.js +3 -0
  31. package/dist/cjs/interfaces/queryOptions.interface.js.map +1 -0
  32. package/dist/cjs/interfaces/sorting.interface.js +3 -0
  33. package/dist/cjs/interfaces/sorting.interface.js.map +1 -0
  34. package/dist/cjs/interfaces/tableColumns.interface.js +3 -0
  35. package/dist/cjs/interfaces/tableColumns.interface.js.map +1 -0
  36. package/dist/cjs/interfaces/tableName.interface.js +3 -0
  37. package/dist/cjs/interfaces/tableName.interface.js.map +1 -0
  38. package/dist/cjs/interfaces/updateOptions.interface.js +3 -0
  39. package/dist/cjs/interfaces/updateOptions.interface.js.map +1 -0
  40. package/dist/cjs/schemas/crudSchema.js +9 -0
  41. package/dist/cjs/schemas/crudSchema.js.map +1 -0
  42. package/dist/cjs/schemas/index.js +18 -0
  43. package/dist/cjs/schemas/index.js.map +1 -0
  44. package/dist/cjs/services/crud.service.js +51 -0
  45. package/dist/cjs/services/crud.service.js.map +1 -0
  46. package/dist/cjs/services/crudFactory.service.js +15 -0
  47. package/dist/cjs/services/crudFactory.service.js.map +1 -0
  48. package/dist/cjs/services/cruds/dynamodb/dynamoDbClient.service.js +100 -0
  49. package/dist/cjs/services/cruds/dynamodb/dynamoDbClient.service.js.map +1 -0
  50. package/dist/cjs/services/cruds/dynamodb/dynamoDbCrud.service.js +191 -0
  51. package/dist/cjs/services/cruds/dynamodb/dynamoDbCrud.service.js.map +1 -0
  52. package/dist/cjs/services/cruds/dynamodb/queryBuilder.service.js +71 -0
  53. package/dist/cjs/services/cruds/dynamodb/queryBuilder.service.js.map +1 -0
  54. package/dist/cjs/services/cruds/dynamodb/queryBuilderCondition.service.js +144 -0
  55. package/dist/cjs/services/cruds/dynamodb/queryBuilderCondition.service.js.map +1 -0
  56. package/dist/cjs/services/cruds/index.js +19 -0
  57. package/dist/cjs/services/cruds/index.js.map +1 -0
  58. package/dist/cjs/services/cruds/postgresql/connection.service.js +40 -0
  59. package/dist/cjs/services/cruds/postgresql/connection.service.js.map +1 -0
  60. package/dist/cjs/services/cruds/postgresql/postgreSqlClient.service.js +167 -0
  61. package/dist/cjs/services/cruds/postgresql/postgreSqlClient.service.js.map +1 -0
  62. package/dist/cjs/services/cruds/postgresql/postgreSqlCrud.service.js +77 -0
  63. package/dist/cjs/services/cruds/postgresql/postgreSqlCrud.service.js.map +1 -0
  64. package/dist/cjs/services/cruds/postgresql/query.service.js +31 -0
  65. package/dist/cjs/services/cruds/postgresql/query.service.js.map +1 -0
  66. package/dist/cjs/types/connectionClosingMode.type.js +5 -0
  67. package/dist/cjs/types/connectionClosingMode.type.js.map +1 -0
  68. package/dist/cjs/types/filterInput.type.js +3 -0
  69. package/dist/cjs/types/filterInput.type.js.map +1 -0
  70. package/dist/cjs/types/filterLogicOperator.type.js +5 -0
  71. package/dist/cjs/types/filterLogicOperator.type.js.map +1 -0
  72. package/dist/cjs/types/index.js +21 -0
  73. package/dist/cjs/types/index.js.map +1 -0
  74. package/dist/cjs/types/sortDirection.type.js +5 -0
  75. package/dist/cjs/types/sortDirection.type.js.map +1 -0
  76. package/dist/cjs/utils/constants.js +68 -0
  77. package/dist/cjs/utils/constants.js.map +1 -0
  78. package/dist/esm/index.mjs +13 -0
  79. package/dist/esm/index.mjs.map +1 -0
  80. package/dist/types/index.d.ts +110 -0
  81. package/package.json +59 -0
package/README.md ADDED
@@ -0,0 +1,77 @@
1
+
2
+ # @qrvey/data-persistence
3
+
4
+ ![install size](https://packagephobia.com/badge?p=%40qrvey%2Fdata-persistence)
5
+
6
+
7
+ ## Installation
8
+
9
+ You can install the package using npm or yarn:
10
+
11
+ ```bash
12
+ npm install @qrvey/data-persistence
13
+ ```
14
+
15
+ Or with yarn:
16
+
17
+ ```bash
18
+ yarn add @qrvey/data-persistence
19
+ ```
20
+
21
+ ## Peer Dependencies
22
+
23
+ This package has the following peer dependencies:
24
+
25
+ - `@aws-sdk/client-dynamodb` (v3.x) and `@aws-sdk/lib-dynamodb` (v3.x) for interacting with **DynamoDB**.
26
+ - `pg` (v8.x) and `pg-format` (v1.x) for interacting with **PostgreSQL** databases.
27
+
28
+ ## Concepts
29
+ ### CrudService:
30
+ This class serves as the foundation for interacting with your database. It exposes methods for performing CRUD operations on entities (data objects).
31
+
32
+ #### Basic Functions
33
+
34
+ - `create(entity: T)`: Creates a new entity in the database.
35
+ - find(options: IFindOptions): Retrieves entities based on specified options (filters, sorting, pagination).
36
+ - `findAll(options: IFindOptions)`: Retrieves all entities based on specified options, this function make an internal pagination to load all data.
37
+ - `findItem (options: IFindOptions)`: Fetches a single entity by a specified filter.
38
+ - `update(filters: IFilter[], data: Partial<T>)`: Updates entities matching the provided filters with the given data.
39
+ - `remove(filters: IFilter[])`: Deletes entities that satisfy the specified filters.
40
+
41
+ #### Helper Functions:
42
+ These methods assist in constructing filters, query indexes, and sorting criteria for use within your CRUD operations.
43
+
44
+ - `buildFilter(attribute: string, value: string, operator = 'EQUAL')`: Creates a filter object for a specific attribute.
45
+ - `buildQueryIndex(indexName: string, columns: string[])`: Constructs a query index for efficient data retrieval.
46
+ - `buildSort(column: string, direction: SortDirection)`: Generates a sorting object for ordering results.
47
+
48
+
49
+ ### CrudSchema:
50
+ This interface defines the structure of a database table. It allows you to specify the table name, columns, and optional schema and pool usage.
51
+
52
+ #### Properties:
53
+
54
+ - `static table: string | ITableName`: This property defines the name of the database table that the CrudService will interact with. It can be a simple string (e.g., "users") or an object implementing the ITableName interface (discussed later).
55
+
56
+ - `static columns: ITableColumns`: This property represents an array of column definitions for the table. It should conform to the ITableColumns interface (discussed later). Each column definition likely specifies details like column name, data type, and potentially constraints.
57
+
58
+ - `static usePool?: boolean = false`: This optional boolean property (defaulting to false) indicates whether to use a connection pool for database interactions. Setting it to true can improve performance for frequent queries.
59
+
60
+ - `static schema: string | null = null`: This optional string property allows specifying the schema name (if applicable) where the table resides. It can be a string (e.g., "public") or null if the default schema is used.
61
+
62
+ ### Supported Filter Operators
63
+ This library provides a set of filter operators for performing comparisons on entity attributes within your database. These operators allow you to construct filters for your CRUD operations.
64
+
65
+ #### Available Operators
66
+ The FilterOperator enum defines the following operators:
67
+
68
+ - EQUAL.
69
+ - NOT_EQUAL.
70
+ - CONTAINS: This operator checks if the attribute value contains the specified string as a substring.
71
+ -NOT_CONTAINS: This operator checks if the attribute value does not contain the specified string as a substring.
72
+ - GREATER_THAN.
73
+ - GREATER_THAN_EQUAL.
74
+ - LESS_THAN.
75
+ - LESS_THAN_EQUAL.
76
+ - IN: This operator checks if the attribute value is present within a specified list of values.
77
+ - STARTS_WITH: This operator checks if the attribute value starts with the provided string. It uses parameterized query syntax for security.
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildSort = exports.buildQueryIndex = exports.buildFilter = void 0;
4
+ const constants_1 = require("../utils/constants");
5
+ function buildFilter(attribute, value, operator = 'EQUAL') {
6
+ return {
7
+ attribute,
8
+ operator,
9
+ value,
10
+ };
11
+ }
12
+ exports.buildFilter = buildFilter;
13
+ function buildQueryIndex(indexName, columns) {
14
+ return {
15
+ indexName,
16
+ columns,
17
+ };
18
+ }
19
+ exports.buildQueryIndex = buildQueryIndex;
20
+ function buildSort(column, direction = constants_1.SORT_DIRECTIONS.ASC) {
21
+ return {
22
+ column,
23
+ direction,
24
+ };
25
+ }
26
+ exports.buildSort = buildSort;
27
+ //# sourceMappingURL=crudHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crudHelpers.js","sourceRoot":"","sources":["../../../src/helpers/crudHelpers.ts"],"names":[],"mappings":";;;AAEA,kDAAqD;AAErD,SAAgB,WAAW,CACvB,SAAiB,EACjB,KAAa,EACb,QAAQ,GAAG,OAAO;IAElB,OAAO;QACH,SAAS;QACT,QAAQ;QACR,KAAK;KACR,CAAC;AACN,CAAC;AAVD,kCAUC;AAED,SAAgB,eAAe,CAAC,SAAiB,EAAE,OAAiB;IAChE,OAAO;QACH,SAAS;QACT,OAAO;KACV,CAAC;AACN,CAAC;AALD,0CAKC;AAED,SAAgB,SAAS,CACrB,MAAc,EACd,YAA2B,2BAAe,CAAC,GAAG;IAE9C,OAAO;QACH,MAAM;QACN,SAAS;KACZ,CAAC;AACN,CAAC;AARD,8BAQC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.METHOD_TO_QUERY = void 0;
4
+ var METHOD_TO_QUERY;
5
+ (function (METHOD_TO_QUERY) {
6
+ METHOD_TO_QUERY["where"] = "where";
7
+ METHOD_TO_QUERY["filter"] = "filter";
8
+ METHOD_TO_QUERY["update"] = "update";
9
+ })(METHOD_TO_QUERY || (exports.METHOD_TO_QUERY = METHOD_TO_QUERY = {}));
10
+ //# sourceMappingURL=queryHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queryHelpers.js","sourceRoot":"","sources":["../../../src/helpers/queryHelpers.ts"],"names":[],"mappings":";;;AAAA,IAAY,eAIX;AAJD,WAAY,eAAe;IACvB,kCAAe,CAAA;IACf,oCAAiB,CAAA;IACjB,oCAAiB,CAAA;AACrB,CAAC,EAJW,eAAe,+BAAf,eAAe,QAI1B"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPrimaryKeyColumns = exports.getTableName = exports.findIdColumnName = exports.getTableColumnNames = void 0;
4
+ function getTableColumnNames(columns) {
5
+ return Object.keys(columns);
6
+ }
7
+ exports.getTableColumnNames = getTableColumnNames;
8
+ function findIdColumnName(columns) {
9
+ return getTableColumnNames(columns).find((columnName) => columns[columnName].columnId === true);
10
+ }
11
+ exports.findIdColumnName = findIdColumnName;
12
+ function getTableName(table, property = 'name') {
13
+ if (!table)
14
+ throw new Error('missing table property');
15
+ if (typeof table === 'string')
16
+ return table;
17
+ const { name, alias } = table;
18
+ return property === 'alias' && alias ? alias : name;
19
+ }
20
+ exports.getTableName = getTableName;
21
+ function getPrimaryKeyColumns(columns) {
22
+ return getTableColumnNames(columns).filter((columnName) => columns[columnName].primary === true);
23
+ }
24
+ exports.getPrimaryKeyColumns = getPrimaryKeyColumns;
25
+ //# sourceMappingURL=tableHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tableHelper.js","sourceRoot":"","sources":["../../../src/helpers/tableHelper.ts"],"names":[],"mappings":";;;AAEA,SAAgB,mBAAmB,CAAC,OAAsB;IACtD,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC;AAFD,kDAEC;AAED,SAAgB,gBAAgB,CAAC,OAAsB;IACnD,OAAO,mBAAmB,CAAC,OAAO,CAAC,CAAC,IAAI,CACpC,CAAC,UAAU,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,QAAQ,KAAK,IAAI,CACxD,CAAC;AACN,CAAC;AAJD,4CAIC;AAED,SAAgB,YAAY,CACxB,KAA0B,EAC1B,QAAQ,GAAG,MAAM;IAEjB,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAEtD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAE5C,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;IAC9B,OAAO,QAAQ,KAAK,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACxD,CAAC;AAVD,oCAUC;AAED,SAAgB,oBAAoB,CAAC,OAAsB;IACvD,OAAO,mBAAmB,CAAC,OAAO,CAAC,CAAC,MAAM,CACtC,CAAC,UAAU,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,OAAO,KAAK,IAAI,CACvD,CAAC;AACN,CAAC;AAJD,oDAIC"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.buildSort = exports.buildQueryIndex = exports.buildFilter = exports.CrudSchema = exports.CrudService = void 0;
7
+ var crud_service_1 = require("./services/crud.service");
8
+ Object.defineProperty(exports, "CrudService", { enumerable: true, get: function () { return __importDefault(crud_service_1).default; } });
9
+ var crudSchema_1 = require("./schemas/crudSchema");
10
+ Object.defineProperty(exports, "CrudSchema", { enumerable: true, get: function () { return crudSchema_1.CrudSchema; } });
11
+ var crudHelpers_1 = require("./helpers/crudHelpers");
12
+ Object.defineProperty(exports, "buildFilter", { enumerable: true, get: function () { return crudHelpers_1.buildFilter; } });
13
+ Object.defineProperty(exports, "buildQueryIndex", { enumerable: true, get: function () { return crudHelpers_1.buildQueryIndex; } });
14
+ Object.defineProperty(exports, "buildSort", { enumerable: true, get: function () { return crudHelpers_1.buildSort; } });
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAiE;AAAxD,4HAAA,OAAO,OAAe;AAC/B,mDAAkD;AAAzC,wGAAA,UAAU,OAAA;AAGnB,qDAAgF;AAAvE,0GAAA,WAAW,OAAA;AAAE,8GAAA,eAAe,OAAA;AAAE,wGAAA,SAAS,OAAA"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=compoundFilter.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compoundFilter.interface.js","sourceRoot":"","sources":["../../../src/interfaces/compoundFilter.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=crudService.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crudService.interface.js","sourceRoot":"","sources":["../../../src/interfaces/crudService.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=filter.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filter.interface.js","sourceRoot":"","sources":["../../../src/interfaces/filter.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=findIndex.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findIndex.interface.js","sourceRoot":"","sources":["../../../src/interfaces/findIndex.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=findOptions.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findOptions.interface.js","sourceRoot":"","sources":["../../../src/interfaces/findOptions.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=findPagination.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findPagination.interface.js","sourceRoot":"","sources":["../../../src/interfaces/findPagination.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=findResult.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findResult.interface.js","sourceRoot":"","sources":["../../../src/interfaces/findResult.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./compoundFilter.interface"), exports);
18
+ __exportStar(require("./crudService.interface"), exports);
19
+ __exportStar(require("./filter.interface"), exports);
20
+ __exportStar(require("./findOptions.interface"), exports);
21
+ __exportStar(require("./findPagination.interface"), exports);
22
+ __exportStar(require("./queryOptions.interface"), exports);
23
+ __exportStar(require("./findResult.interface"), exports);
24
+ __exportStar(require("./findIndex.interface"), exports);
25
+ __exportStar(require("./sorting.interface"), exports);
26
+ __exportStar(require("./tableName.interface"), exports);
27
+ __exportStar(require("./tableColumns.interface"), exports);
28
+ __exportStar(require("./updateOptions.interface"), exports);
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6DAA2C;AAC3C,0DAAwC;AACxC,qDAAmC;AACnC,0DAAwC;AACxC,6DAA2C;AAC3C,2DAAyC;AACzC,yDAAuC;AACvC,wDAAsC;AACtC,sDAAoC;AACpC,wDAAsC;AACtC,2DAAyC;AACzC,4DAA0C"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=queryBuilder.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queryBuilder.interface.js","sourceRoot":"","sources":["../../../src/interfaces/queryBuilder.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=queryBuilderCondition.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queryBuilderCondition.interface.js","sourceRoot":"","sources":["../../../src/interfaces/queryBuilderCondition.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=queryOptions.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queryOptions.interface.js","sourceRoot":"","sources":["../../../src/interfaces/queryOptions.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=sorting.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sorting.interface.js","sourceRoot":"","sources":["../../../src/interfaces/sorting.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=tableColumns.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tableColumns.interface.js","sourceRoot":"","sources":["../../../src/interfaces/tableColumns.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=tableName.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tableName.interface.js","sourceRoot":"","sources":["../../../src/interfaces/tableName.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=updateOptions.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateOptions.interface.js","sourceRoot":"","sources":["../../../src/interfaces/updateOptions.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CrudSchema = void 0;
4
+ class CrudSchema {
5
+ }
6
+ exports.CrudSchema = CrudSchema;
7
+ CrudSchema.usePool = false;
8
+ CrudSchema.schema = null;
9
+ //# sourceMappingURL=crudSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crudSchema.js","sourceRoot":"","sources":["../../../src/schemas/crudSchema.ts"],"names":[],"mappings":";;;AAEA,MAAa,UAAU;;AAAvB,gCAKC;AAFU,kBAAO,GAAa,KAAK,CAAC;AAC1B,iBAAM,GAAkB,IAAI,CAAC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./crudSchema"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/schemas/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ const crudHelpers_1 = require("../helpers/crudHelpers");
15
+ const crudFactory_service_1 = require("./crudFactory.service");
16
+ class CrudService {
17
+ constructor(crudSchema) {
18
+ this.crudService = crudFactory_service_1.CrudFactory.databaseClientService(crudSchema);
19
+ }
20
+ create(entity) {
21
+ return this.crudService.create(entity);
22
+ }
23
+ find(options) {
24
+ return this.crudService.find(options);
25
+ }
26
+ findItem(options) {
27
+ return this.crudService.findItem(options);
28
+ }
29
+ update(filters, data) {
30
+ return this.crudService.update(filters, data);
31
+ }
32
+ remove(filters) {
33
+ return this.crudService.remove(filters);
34
+ }
35
+ findAll(options) {
36
+ // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
37
+ const { pagination } = options, findAllOptions = __rest(options, ["pagination"]);
38
+ return this.crudService.findAll(findAllOptions);
39
+ }
40
+ buildFilter(attribute, value, operator = 'EQUAL') {
41
+ return (0, crudHelpers_1.buildFilter)(attribute, value, operator);
42
+ }
43
+ buildQueryIndex(indexName, columns) {
44
+ return (0, crudHelpers_1.buildQueryIndex)(indexName, columns);
45
+ }
46
+ buildSort(column, direction) {
47
+ return (0, crudHelpers_1.buildSort)(column, direction);
48
+ }
49
+ }
50
+ exports.default = CrudService;
51
+ //# sourceMappingURL=crud.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crud.service.js","sourceRoot":"","sources":["../../../src/services/crud.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,wDAIgC;AAUhC,+DAAoD;AAEpD,MAAM,WAAW;IAGb,YAAY,UAA6B;QACrC,IAAI,CAAC,WAAW,GAAG,iCAAW,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC;IACrE,CAAC;IAED,MAAM,CAAC,MAAS;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IAED,IAAI,CAAC,OAAqB;QACtB,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED,QAAQ,CAAC,OAAqB;QAC1B,OAAO,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,MAAM,CACF,OAAoC,EACpC,IAAgB;QAEhB,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC;IAED,MAAM,CAAC,OAAoC;QACvC,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED,OAAO,CAAC,OAAqB;QACzB,6EAA6E;QAC7E,MAAM,EAAE,UAAU,KAAwB,OAAO,EAA1B,cAAc,UAAK,OAAO,EAA3C,cAAiC,CAAU,CAAC;QAClD,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IACpD,CAAC;IAED,WAAW,CAAC,SAAiB,EAAE,KAAa,EAAE,QAAQ,GAAG,OAAO;QAC5D,OAAO,IAAA,yBAAW,EAAC,SAAS,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;IACnD,CAAC;IAED,eAAe,CAAC,SAAiB,EAAE,OAAiB;QAChD,OAAO,IAAA,6BAAe,EAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED,SAAS,CAAC,MAAc,EAAE,SAAwB;QAC9C,OAAO,IAAA,uBAAS,EAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACxC,CAAC;CACJ;AAED,kBAAe,WAAW,CAAC"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CrudFactory = void 0;
4
+ const cruds_1 = require("./cruds");
5
+ class CrudFactory {
6
+ static databaseClientService(crudSchema) {
7
+ var _a;
8
+ const isMultiPlatformMode = ((_a = process.env.PLATFORM_TYPE) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'container';
9
+ if (isMultiPlatformMode)
10
+ return new cruds_1.PostgreSqlCrudService(crudSchema);
11
+ return new cruds_1.DynamoDbCrudService(crudSchema);
12
+ }
13
+ }
14
+ exports.CrudFactory = CrudFactory;
15
+ //# sourceMappingURL=crudFactory.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crudFactory.service.js","sourceRoot":"","sources":["../../../src/services/crudFactory.service.ts"],"names":[],"mappings":";;;AAEA,mCAAqE;AACrE,MAAa,WAAW;IACpB,MAAM,CAAC,qBAAqB,CACxB,UAA6B;;QAE7B,MAAM,mBAAmB,GACrB,CAAA,MAAA,OAAO,CAAC,GAAG,CAAC,aAAa,0CAAE,WAAW,EAAE,MAAK,WAAW,CAAC;QAE7D,IAAI,mBAAmB;YACnB,OAAO,IAAI,6BAAqB,CAAI,UAAU,CAAC,CAAC;QACpD,OAAO,IAAI,2BAAmB,CAAI,UAAU,CAAC,CAAC;IAClD,CAAC;CACJ;AAXD,kCAWC"}
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
4
+ const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
5
+ const AWS_REGION = process.env.AWS_DEFAULT_REGION;
6
+ /**
7
+ * Ref:
8
+ * - https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html
9
+ * - https://www.fernandomc.com/posts/eight-examples-of-fetching-data-from-dynamodb-with-node/
10
+ */
11
+ class DynamoDbClientService {
12
+ constructor(tableName) {
13
+ if (!tableName)
14
+ throw new Error('The "tableName" is required to use a DynamoDbClientService.');
15
+ this.tableName = tableName;
16
+ const client = new client_dynamodb_1.DynamoDBClient({ region: AWS_REGION });
17
+ this.dynamoDBClient = lib_dynamodb_1.DynamoDBDocumentClient.from(client, {
18
+ marshallOptions: {
19
+ removeUndefinedValues: true,
20
+ },
21
+ });
22
+ }
23
+ /**
24
+ * Get an item by key
25
+ * @param {Object} keyObject - Ex: { jobId: 1234 }
26
+ * @param {GetCommandInput} options
27
+ */
28
+ async getByKey(
29
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
+ keyObject, options = {}) {
31
+ const params = Object.assign({ TableName: this.tableName, Key: keyObject }, options);
32
+ const result = await this.dynamoDBClient.send(new lib_dynamodb_1.GetCommand(params));
33
+ return result.Item;
34
+ }
35
+ /**
36
+ * Query a table
37
+ * @param {QueryCommandInput} options
38
+ */
39
+ async query(options = {}) {
40
+ const params = Object.assign({ TableName: this.tableName }, options);
41
+ const result = await this.dynamoDBClient.send(new lib_dynamodb_1.QueryCommand(params));
42
+ if (result.$metadata)
43
+ delete result.$metadata;
44
+ return result;
45
+ }
46
+ /**
47
+ * Scan a table
48
+ * @param {ScanInput} options
49
+ */
50
+ async scan(input) {
51
+ const params = Object.assign(Object.assign({}, input), { TableName: this.tableName });
52
+ const command = new lib_dynamodb_1.ScanCommand(params);
53
+ const response = await this.dynamoDBClient.send(command);
54
+ if (response.$metadata)
55
+ delete response.$metadata;
56
+ return response;
57
+ }
58
+ /**
59
+ * Create/Replace a item object
60
+ * To take care:
61
+ * - https://stackoverflow.com/questions/43667229/difference-between-dynamodb-putitem-vs-updateitem
62
+ * @param {Object} input
63
+ */
64
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
65
+ async put(input) {
66
+ const params = {
67
+ TableName: this.tableName,
68
+ Item: input,
69
+ ReturnValues: 'NONE',
70
+ };
71
+ return await this.dynamoDBClient.send(new lib_dynamodb_1.PutCommand(params));
72
+ }
73
+ /**
74
+ * Update a item object
75
+ * To take care:
76
+ * - https://stackoverflow.com/questions/43667229/difference-between-dynamodb-putitem-vs-updateitem
77
+ * @param {Object} keyObject - Ex: { jobId: 1234 }
78
+ * @param {UpdateCommandInput} updateObject
79
+ */
80
+ async update(
81
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
82
+ keyObject, options = {}) {
83
+ const params = Object.assign({ TableName: this.tableName, Key: keyObject, ReturnValues: 'NONE' }, options);
84
+ return await this.dynamoDBClient.send(new lib_dynamodb_1.UpdateCommand(params));
85
+ }
86
+ /**
87
+ * Delete/Remove an item object
88
+ */
89
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
90
+ async remove(keyObject) {
91
+ const params = {
92
+ TableName: this.tableName,
93
+ Key: keyObject,
94
+ ReturnValues: 'NONE',
95
+ };
96
+ return await this.dynamoDBClient.send(new lib_dynamodb_1.DeleteCommand(params));
97
+ }
98
+ }
99
+ exports.default = DynamoDbClientService;
100
+ //# sourceMappingURL=dynamoDbClient.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dynamoDbClient.service.js","sourceRoot":"","sources":["../../../../../src/services/cruds/dynamodb/dynamoDbClient.service.ts"],"names":[],"mappings":"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"}