@degenerate/generic 0.0.9 → 0.0.11

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 (96) hide show
  1. package/dist/crypto/index.d.ts +3 -0
  2. package/dist/crypto/index.d.ts.map +1 -1
  3. package/dist/crypto/index.js +5 -0
  4. package/dist/crypto/signature/create-crypto-signature.d.ts +9 -0
  5. package/dist/crypto/signature/create-crypto-signature.d.ts.map +1 -0
  6. package/dist/crypto/signature/create-crypto-signature.js +13 -0
  7. package/dist/crypto/signature/verify-crypto-signature-by-data.d.ts +13 -0
  8. package/dist/crypto/signature/verify-crypto-signature-by-data.d.ts.map +1 -0
  9. package/dist/crypto/signature/verify-crypto-signature-by-data.js +45 -0
  10. package/dist/crypto/signature/verify-crypto-signature-by-hash.d.ts +13 -0
  11. package/dist/crypto/signature/verify-crypto-signature-by-hash.d.ts.map +1 -0
  12. package/dist/{errors/__tests__/index-test.js → crypto/signature/verify-crypto-signature-by-hash.js} +17 -9
  13. package/dist/errors/generic/generic-errors.d.ts +35 -0
  14. package/dist/errors/generic/generic-errors.d.ts.map +1 -0
  15. package/dist/errors/generic/generic-errors.js +47 -0
  16. package/dist/errors/index.d.ts +4 -0
  17. package/dist/errors/index.d.ts.map +1 -1
  18. package/dist/errors/index.js +4 -0
  19. package/dist/errors/request/request-errors.d.ts +89 -0
  20. package/dist/errors/request/request-errors.d.ts.map +1 -0
  21. package/dist/errors/request/request-errors.js +120 -0
  22. package/dist/errors/safe/safe-rules-errors.d.ts +11 -0
  23. package/dist/errors/safe/safe-rules-errors.d.ts.map +1 -0
  24. package/dist/errors/safe/safe-rules-errors.js +17 -0
  25. package/dist/errors/share-data/share-data-errors.d.ts +49 -0
  26. package/dist/errors/share-data/share-data-errors.d.ts.map +1 -0
  27. package/dist/errors/share-data/share-data-errors.js +66 -0
  28. package/dist/helpers/array/array-helpers.d.ts +8 -0
  29. package/dist/helpers/array/array-helpers.d.ts.map +1 -0
  30. package/dist/helpers/array/array-helpers.js +14 -0
  31. package/dist/helpers/data/data-helpers.d.ts +46 -0
  32. package/dist/helpers/data/data-helpers.d.ts.map +1 -0
  33. package/dist/helpers/data/data-helpers.js +106 -0
  34. package/dist/helpers/file/file-helpers.d.ts +12 -0
  35. package/dist/helpers/file/file-helpers.d.ts.map +1 -0
  36. package/dist/helpers/file/file-helpers.js +39 -0
  37. package/dist/helpers/id-helpers.d.ts +8 -0
  38. package/dist/helpers/id-helpers.d.ts.map +1 -0
  39. package/dist/helpers/id-helpers.js +19 -0
  40. package/dist/helpers/index.d.ts +11 -0
  41. package/dist/helpers/index.d.ts.map +1 -0
  42. package/dist/helpers/index.js +31 -0
  43. package/dist/helpers/lodash/lodash-helpers.d.ts +14 -0
  44. package/dist/helpers/lodash/lodash-helpers.d.ts.map +1 -0
  45. package/dist/helpers/lodash/lodash-helpers.js +28 -0
  46. package/dist/helpers/object-helpers.d.ts +23 -0
  47. package/dist/helpers/object-helpers.d.ts.map +1 -0
  48. package/dist/helpers/object-helpers.js +54 -0
  49. package/dist/helpers/object-validation-helpers.d.ts +59 -0
  50. package/dist/helpers/object-validation-helpers.d.ts.map +1 -0
  51. package/dist/helpers/object-validation-helpers.js +233 -0
  52. package/dist/helpers/request/params-object-helpers.d.ts +38 -0
  53. package/dist/helpers/request/params-object-helpers.d.ts.map +1 -0
  54. package/dist/helpers/request/params-object-helpers.js +54 -0
  55. package/dist/helpers/request/query-object-helpers.d.ts +12 -0
  56. package/dist/helpers/request/query-object-helpers.d.ts.map +1 -0
  57. package/dist/helpers/request/query-object-helpers.js +25 -0
  58. package/dist/helpers/request/request-object-helpers.d.ts +19 -0
  59. package/dist/helpers/request/request-object-helpers.d.ts.map +1 -0
  60. package/dist/helpers/request/request-object-helpers.js +28 -0
  61. package/dist/index.d.ts +2 -0
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +3 -0
  64. package/dist/models/data/data-models.d.ts +24 -0
  65. package/dist/models/data/data-models.d.ts.map +1 -0
  66. package/dist/models/data/data-models.js +3 -0
  67. package/dist/models/dynamic-execution/dynamic-execution-models.d.ts +9 -0
  68. package/dist/models/dynamic-execution/dynamic-execution-models.d.ts.map +1 -0
  69. package/dist/models/dynamic-execution/dynamic-execution-models.js +2 -0
  70. package/dist/models/events/share-event-models.d.ts +65 -0
  71. package/dist/models/events/share-event-models.d.ts.map +1 -0
  72. package/dist/models/events/share-event-models.js +70 -0
  73. package/dist/models/functions/share-data-function-models.d.ts +86 -0
  74. package/dist/models/functions/share-data-function-models.d.ts.map +1 -0
  75. package/dist/models/functions/share-data-function-models.js +17 -0
  76. package/dist/models/generic/__tests__/request-response-models.d.ts +2 -0
  77. package/dist/models/generic/__tests__/request-response-models.d.ts.map +1 -0
  78. package/dist/models/generic/__tests__/request-response-models.js +33 -0
  79. package/dist/models/generic/request-response-models.d.ts +8 -0
  80. package/dist/models/generic/request-response-models.d.ts.map +1 -0
  81. package/dist/models/generic/request-response-models.js +2 -0
  82. package/dist/models/index.d.ts +8 -0
  83. package/dist/models/index.d.ts.map +1 -0
  84. package/dist/models/index.js +24 -0
  85. package/dist/models/rules/share-rule-models.d.ts +277 -0
  86. package/dist/models/rules/share-rule-models.d.ts.map +1 -0
  87. package/dist/models/rules/share-rule-models.js +107 -0
  88. package/dist/models/share-data/share-data.d.ts +55 -0
  89. package/dist/models/share-data/share-data.d.ts.map +1 -0
  90. package/dist/models/share-data/share-data.js +19 -0
  91. package/dist/share-data/share-data.d.ts +1 -0
  92. package/dist/share-data/share-data.d.ts.map +1 -0
  93. package/dist/share-data/share-data.js +166 -0
  94. package/package.json +1 -1
  95. package/dist/errors/__tests__/index-test.d.ts +0 -2
  96. package/dist/errors/__tests__/index-test.d.ts.map +0 -1
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ShareDataFunctionHashNotValid = exports.ShareDataFunctionBeingAppliedDoesNotExistOnShareDataError = exports.ShareDataIntegrityError = exports.ShareDataCurrentAndProposalDataMatchesError = exports.ShareDataIsLockedError = void 0;
4
+ const base_error_1 = require("../base-error");
5
+ /**
6
+ * This error is thrown when a function is tried to be applied to the share data thats state is locked.
7
+ */
8
+ class ShareDataIsLockedError extends base_error_1.BaseError {
9
+ /**
10
+ * This error is thrown when a function is tried to be applied to the share data thats state is locked.
11
+ */
12
+ constructor(shareDataId, shareDataType) {
13
+ super(`Share data with id ${shareDataId} and type ${shareDataType} is locked and cannot be modified.`);
14
+ }
15
+ }
16
+ exports.ShareDataIsLockedError = ShareDataIsLockedError;
17
+ /**
18
+ * This error is thrown when a data proposal matches the current data in the rules evaluation service.
19
+ */
20
+ class ShareDataCurrentAndProposalDataMatchesError extends base_error_1.BaseError {
21
+ /**
22
+ * This error is thrown when a data proposal matches the current data in the rules evaluation service.
23
+ */
24
+ constructor(shareDataId) {
25
+ super(`Share data with id ${shareDataId} current and proposal data matches.`);
26
+ }
27
+ }
28
+ exports.ShareDataCurrentAndProposalDataMatchesError = ShareDataCurrentAndProposalDataMatchesError;
29
+ /**
30
+ * This error is thrown when the share data integrity check fails.
31
+ */
32
+ class ShareDataIntegrityError extends base_error_1.BaseError {
33
+ /**
34
+ * This error is thrown when the share data integrity check fails.
35
+ */
36
+ constructor(shareDataId) {
37
+ super(`Share data with id ${shareDataId} failed the integrity check.`);
38
+ }
39
+ }
40
+ exports.ShareDataIntegrityError = ShareDataIntegrityError;
41
+ /**
42
+ * This error is thrown when the attemping to be applied function does not exist on the share data.
43
+ */
44
+ class ShareDataFunctionBeingAppliedDoesNotExistOnShareDataError extends base_error_1.BaseError {
45
+ /**
46
+ * This error is thrown when the attemping to be applied function does not exist on the share data.
47
+ */
48
+ constructor(shareDataId, functionName, functionId) {
49
+ super(`On share data with id ${shareDataId} the function with id: ${functionId} & name: ${functionName} that is trying to be executed, ` +
50
+ 'but does not exist in the authorized functions for the share data.');
51
+ }
52
+ }
53
+ exports.ShareDataFunctionBeingAppliedDoesNotExistOnShareDataError = ShareDataFunctionBeingAppliedDoesNotExistOnShareDataError;
54
+ /**
55
+ * This error is thrown when the function hash is not valid.
56
+ */
57
+ class ShareDataFunctionHashNotValid extends base_error_1.BaseError {
58
+ /**
59
+ * This error is thrown when the function hash is not valid.
60
+ */
61
+ constructor(shareDataId, shareDataFunction, calculatedHash) {
62
+ super(`On share data with id ${shareDataId} the function with current hash: ${shareDataFunction.currentHash} & previous hase: ${shareDataFunction.previousHash}` +
63
+ ` that is trying to be executed does not meet the generated hash ${calculatedHash}. This makes it an authorized function execution.`);
64
+ }
65
+ }
66
+ exports.ShareDataFunctionHashNotValid = ShareDataFunctionHashNotValid;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * this gets a random item from an array.
3
+ *
4
+ * @param incomingArray the incoming array to get a random item from.
5
+ */
6
+ declare const getRandomItemFromArray: <T>(incomingArray: T[]) => T;
7
+ export { getRandomItemFromArray };
8
+ //# sourceMappingURL=array-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array-helpers.d.ts","sourceRoot":"","sources":["../../../src/helpers/array/array-helpers.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,QAAA,MAAM,sBAAsB,GAAI,CAAC,iBAAiB,CAAC,EAAE,KAAG,CAGvD,CAAC;AAEF,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ // This file contains the helper functions for arrays.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.getRandomItemFromArray = void 0;
5
+ /**
6
+ * this gets a random item from an array.
7
+ *
8
+ * @param incomingArray the incoming array to get a random item from.
9
+ */
10
+ const getRandomItemFromArray = (incomingArray) => {
11
+ const randomIndex = Math.floor(Math.random() * incomingArray.length);
12
+ return incomingArray[randomIndex];
13
+ };
14
+ exports.getRandomItemFromArray = getRandomItemFromArray;
@@ -0,0 +1,46 @@
1
+ import { IGenericData, ISearchableIndex } from '../../models/data/data-models';
2
+ /**
3
+ * This adds the generic data to the object.
4
+ *
5
+ * @param incomingObject the object to add the generic data to.
6
+ * @param userId the user ID to add the generic data to.
7
+ * @param versionNumber the version number to add to the generic data.
8
+ * @returns
9
+ */
10
+ declare const addGenericDataToObject: <T>(incomingObject: any, userId: string, versionNumber?: number) => T;
11
+ /**
12
+ * This creates the generic data record for the database
13
+ *
14
+ * @param userId the user ID to create the generic data for.
15
+ * @param versionNumber the version number to create the generic data for.
16
+ * @returns
17
+ */
18
+ declare const createGenericData: (userId: string, versionNumber?: number) => IGenericData;
19
+ /**
20
+ * This takes an incoming string and creates a searchable index object.
21
+ * @param itemForSearchableIndex the item for a searchable index to be created on
22
+ */
23
+ declare const createSearchableIndex: (itemForSearchableIndex: string) => ISearchableIndex;
24
+ /**
25
+ * This removed all the generic data from an object.
26
+ *
27
+ * @param data
28
+ */
29
+ declare const deleteGenericDataOnObject: (data: any) => any;
30
+ /**
31
+ * This function removes all whitespace from a string
32
+ *
33
+ * @param str the string to remove whitespace from
34
+ * @returns
35
+ */
36
+ declare const removeWhitespaceFromObject: (str: string) => string;
37
+ /**
38
+ * This function updates the generic data on an object.
39
+ * @param data the data to update the generic data on
40
+ * @param userId the user Id to update the object with
41
+ *
42
+ * @returns
43
+ */
44
+ declare const updateGenericDataOnObject: <T>(data: T, userId: string) => any;
45
+ export { addGenericDataToObject, createGenericData, createSearchableIndex, deleteGenericDataOnObject, removeWhitespaceFromObject, updateGenericDataOnObject, };
46
+ //# sourceMappingURL=data-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-helpers.d.ts","sourceRoot":"","sources":["../../../src/helpers/data/data-helpers.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAE/E;;;;;;;GAOG;AACH,QAAA,MAAM,sBAAsB,GAAI,CAAC,kBAAkB,GAAG,UAAU,MAAM,6BAAsB,CAU3F,CAAC;AAGF;;;;;;GAMG;AACH,QAAA,MAAM,iBAAiB,WAAY,MAAM,6BAAsB,YAU9D,CAAC;AAEF;;;GAGG;AACH,QAAA,MAAM,qBAAqB,2BAA4B,MAAM,KAAG,gBAgB/D,CAAC;AAEF;;;;GAIG;AACH,QAAA,MAAM,yBAAyB,SAAU,GAAG,KAAG,GAQ9C,CAAC;AAEF;;;;;GAKG;AACH,QAAA,MAAM,0BAA0B,QAAS,MAAM,KAAG,MAEjD,CAAC;AAEF;;;;;;GAMG;AACH,QAAA,MAAM,yBAAyB,GAAI,CAAC,QAAQ,CAAC,UAAU,MAAM,KAAG,GAO/D,CAAC;AAEF,OAAO,EACH,sBAAsB,EACtB,iBAAiB,EACjB,qBAAqB,EACrB,yBAAyB,EACzB,0BAA0B,EAC1B,yBAAyB,GAC5B,CAAC"}
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ // This contains the interfaces for the data helpers.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.updateGenericDataOnObject = exports.removeWhitespaceFromObject = exports.deleteGenericDataOnObject = exports.createSearchableIndex = exports.createGenericData = exports.addGenericDataToObject = void 0;
6
+ const errors_1 = require("../../errors");
7
+ /**
8
+ * This adds the generic data to the object.
9
+ *
10
+ * @param incomingObject the object to add the generic data to.
11
+ * @param userId the user ID to add the generic data to.
12
+ * @param versionNumber the version number to add to the generic data.
13
+ * @returns
14
+ */
15
+ const addGenericDataToObject = (incomingObject, userId, versionNumber = 1) => {
16
+ const timestamp = Date.now();
17
+ return {
18
+ ...incomingObject,
19
+ versionNumber,
20
+ createdAt: timestamp,
21
+ createdBy: userId,
22
+ updatedAt: timestamp,
23
+ updatedBy: userId,
24
+ };
25
+ };
26
+ exports.addGenericDataToObject = addGenericDataToObject;
27
+ /**
28
+ * This creates the generic data record for the database
29
+ *
30
+ * @param userId the user ID to create the generic data for.
31
+ * @param versionNumber the version number to create the generic data for.
32
+ * @returns
33
+ */
34
+ const createGenericData = (userId, versionNumber = 1) => {
35
+ const timestamp = Date.now();
36
+ return {
37
+ versionNumber,
38
+ createdAt: timestamp,
39
+ createdBy: userId,
40
+ updatedAt: timestamp,
41
+ updatedBy: userId,
42
+ };
43
+ };
44
+ exports.createGenericData = createGenericData;
45
+ /**
46
+ * This takes an incoming string and creates a searchable index object.
47
+ * @param itemForSearchableIndex the item for a searchable index to be created on
48
+ */
49
+ const createSearchableIndex = (itemForSearchableIndex) => {
50
+ if (typeof itemForSearchableIndex !== 'string' || itemForSearchableIndex.length === 0) {
51
+ throw new errors_1.UnableToCreateSearchableIndexError(itemForSearchableIndex);
52
+ }
53
+ const searchableIndex = {}; // the searchable index object.
54
+ const characters = itemForSearchableIndex.toLowerCase().split(''); // the words in the item, lowercase it and split it.
55
+ // this takes the characters and creates a searchable index.
56
+ // it includes all previous characters in the word.
57
+ // Handle the first character separately
58
+ characters.reduce((accumulator, current) => {
59
+ const updatedAccumulator = accumulator + current;
60
+ searchableIndex[updatedAccumulator] = true;
61
+ return updatedAccumulator;
62
+ }, '');
63
+ return searchableIndex;
64
+ };
65
+ exports.createSearchableIndex = createSearchableIndex;
66
+ /**
67
+ * This removed all the generic data from an object.
68
+ *
69
+ * @param data
70
+ */
71
+ const deleteGenericDataOnObject = (data) => {
72
+ if (data) {
73
+ delete data.createdAt; // the timestamp of when the user was created.
74
+ delete data.createdBy; // the user id of the user who created the item.
75
+ delete data.updatedAt; // when the user was last updated.
76
+ delete data.updatedBy; // the user id of the user who updated the item.
77
+ }
78
+ return data;
79
+ };
80
+ exports.deleteGenericDataOnObject = deleteGenericDataOnObject;
81
+ /**
82
+ * This function removes all whitespace from a string
83
+ *
84
+ * @param str the string to remove whitespace from
85
+ * @returns
86
+ */
87
+ const removeWhitespaceFromObject = (str) => {
88
+ return str.replace(/\s/g, '');
89
+ };
90
+ exports.removeWhitespaceFromObject = removeWhitespaceFromObject;
91
+ /**
92
+ * This function updates the generic data on an object.
93
+ * @param data the data to update the generic data on
94
+ * @param userId the user Id to update the object with
95
+ *
96
+ * @returns
97
+ */
98
+ const updateGenericDataOnObject = (data, userId) => {
99
+ const now = Date.now();
100
+ return {
101
+ ...data,
102
+ updatedAt: now,
103
+ updatedBy: userId,
104
+ };
105
+ };
106
+ exports.updateGenericDataOnObject = updateGenericDataOnObject;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * This gets all the files in a directory recursively.
3
+ *
4
+ * @param dirPath the directory path to get the files from.
5
+ * @param arrayOfFiles the array of files to add to.
6
+ * @param ignoreIndexFiles the flag to ignore index files.
7
+ * @param ignoreTestFiles the flag to ignore test files.
8
+ * @returns
9
+ */
10
+ declare const getAllFiles: (dirPath: string, arrayOfFiles?: string[], ignoreIndexFiles?: boolean, ignoreTestFiles?: boolean) => string[];
11
+ export { getAllFiles };
12
+ //# sourceMappingURL=file-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-helpers.d.ts","sourceRoot":"","sources":["../../../src/helpers/file/file-helpers.ts"],"names":[],"mappings":"AAKA;;;;;;;;GAQG;AACH,QAAA,MAAM,WAAW,YAAa,MAAM,iBAAgB,MAAM,EAAE,4DAAyD,MAAM,EAmB1H,CAAA;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -0,0 +1,39 @@
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.getAllFiles = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ // This contains all the functions for helping with files in the degenerate packages.
10
+ /**
11
+ * This gets all the files in a directory recursively.
12
+ *
13
+ * @param dirPath the directory path to get the files from.
14
+ * @param arrayOfFiles the array of files to add to.
15
+ * @param ignoreIndexFiles the flag to ignore index files.
16
+ * @param ignoreTestFiles the flag to ignore test files.
17
+ * @returns
18
+ */
19
+ const getAllFiles = (dirPath, arrayOfFiles = [], ignoreIndexFiles = true, ignoreTestFiles = true) => {
20
+ const files = fs_1.default.readdirSync(dirPath);
21
+ // loop through all the files in the directory.
22
+ files.forEach((file) => {
23
+ const filePath = path_1.default.join(dirPath, file);
24
+ if (fs_1.default.statSync(filePath).isDirectory()) {
25
+ getAllFiles(filePath, arrayOfFiles);
26
+ }
27
+ else {
28
+ if (ignoreTestFiles && file.endsWith('.test.ts')) {
29
+ return;
30
+ }
31
+ if (ignoreIndexFiles && file === 'index.ts') {
32
+ return;
33
+ }
34
+ arrayOfFiles.push(filePath);
35
+ }
36
+ });
37
+ return arrayOfFiles;
38
+ };
39
+ exports.getAllFiles = getAllFiles;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * This creates a random Id.
3
+ * @param length the length of the id to generate.
4
+ * @returns
5
+ */
6
+ declare const createId: (length?: number) => string;
7
+ export { createId };
8
+ //# sourceMappingURL=id-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id-helpers.d.ts","sourceRoot":"","sources":["../../src/helpers/id-helpers.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,QAAA,MAAM,QAAQ,uBAAkB,MAS/B,CAAC;AAEF,OAAO,EAAE,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ // This file contains the helper functions for generating ids.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.createId = void 0;
5
+ /**
6
+ * This creates a random Id.
7
+ * @param length the length of the id to generate.
8
+ * @returns
9
+ */
10
+ const createId = (length = 18) => {
11
+ let result = '';
12
+ const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
13
+ const charactersLength = characters.length;
14
+ for (let i = 0; i < length; i++) {
15
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
16
+ }
17
+ return result;
18
+ };
19
+ exports.createId = createId;
@@ -0,0 +1,11 @@
1
+ export * from './id-helpers';
2
+ export * from './object-helpers';
3
+ export * from './object-validation-helpers';
4
+ export * from './request/params-object-helpers';
5
+ export * from './request/query-object-helpers';
6
+ export * from './request/request-object-helpers';
7
+ export * from './array/array-helpers';
8
+ export * from './data/data-helpers';
9
+ export * from './file/file-helpers';
10
+ export * from './lodash/lodash-helpers';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,6BAA6B,CAAC;AAM5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,kCAAkC,CAAC;AAKjD,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1,31 @@
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
+ //#region main exports
18
+ __exportStar(require("./id-helpers"), exports);
19
+ __exportStar(require("./object-helpers"), exports);
20
+ __exportStar(require("./object-validation-helpers"), exports);
21
+ // #endregion main exports
22
+ // #region request exports
23
+ __exportStar(require("./request/params-object-helpers"), exports);
24
+ __exportStar(require("./request/query-object-helpers"), exports);
25
+ __exportStar(require("./request/request-object-helpers"), exports);
26
+ //#endregion request exports
27
+ // additional
28
+ __exportStar(require("./array/array-helpers"), exports);
29
+ __exportStar(require("./data/data-helpers"), exports);
30
+ __exportStar(require("./file/file-helpers"), exports);
31
+ __exportStar(require("./lodash/lodash-helpers"), exports);
@@ -0,0 +1,14 @@
1
+ /***************************************************
2
+ * This contains a list of the lodash equivalent functions without the lodash bloat and vulnerabilites.
3
+ ****************************************************/
4
+ /**
5
+ * This function is used to break an array into smaller arrays.
6
+ *
7
+ * @param arr the array to be broken into smaller arrays.
8
+ * @param amount the amount of items to be in each array.
9
+ * @param startAt start at a specific index of this array
10
+ * @returns
11
+ */
12
+ declare const chunk: <T>(arr: Array<T>, amount?: number, startAt?: number) => T[][];
13
+ export { chunk };
14
+ //# sourceMappingURL=lodash-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lodash-helpers.d.ts","sourceRoot":"","sources":["../../../src/helpers/lodash/lodash-helpers.ts"],"names":[],"mappings":"AACA;;sDAEsD;AAEtD;;;;;;;GAOG;AACH,QAAA,MAAM,KAAK,GAAI,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,wCAA8B,CAAC,EAAE,EAW/D,CAAC;AAEF,OAAO,EAAE,KAAK,EAAE,CAAC"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ /***************************************************
4
+ * This contains a list of the lodash equivalent functions without the lodash bloat and vulnerabilites.
5
+ ****************************************************/
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.chunk = void 0;
8
+ /**
9
+ * This function is used to break an array into smaller arrays.
10
+ *
11
+ * @param arr the array to be broken into smaller arrays.
12
+ * @param amount the amount of items to be in each array.
13
+ * @param startAt start at a specific index of this array
14
+ * @returns
15
+ */
16
+ const chunk = (arr, amount = 300, startAt = 0) => {
17
+ const result = []; // setup the result.
18
+ const len = arr.length; // get the length
19
+ let startAtInside = startAt;
20
+ while (startAtInside < len) {
21
+ const totalLength = startAtInside + amount;
22
+ const newArray = arr.slice(startAtInside, totalLength);
23
+ result.push(newArray);
24
+ startAtInside += amount;
25
+ }
26
+ return result;
27
+ };
28
+ exports.chunk = chunk;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * This takes a string and converts it to a string with spaces between each word and the first letter of each word capitalized.
3
+ * @param str the string to convert (e.g. "thisIsAString" or "This is a string")
4
+ * @returns the converted string (e.g. "This Is A String")
5
+ */
6
+ declare const toCapitalizedWithSpaces: (str: string) => string;
7
+ /**
8
+ * This takes an object and removes any undefined items off it and then returns a new object.
9
+ * if the type passed in is a primitive type other than the object, it returns the original object.
10
+ *
11
+ * @param item the incoming item.
12
+ * @returns a clean version of the object.
13
+ */
14
+ declare const removeUndefined: <T>(item: T, recurseObject?: boolean) => T;
15
+ /**
16
+ * This function removes all whitespace from a string
17
+ *
18
+ * @param str the string to remove whitespace from
19
+ * @returns
20
+ */
21
+ declare const removeWhitespace: (str: string) => string;
22
+ export { toCapitalizedWithSpaces, removeUndefined, removeWhitespace, };
23
+ //# sourceMappingURL=object-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object-helpers.d.ts","sourceRoot":"","sources":["../../src/helpers/object-helpers.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,QAAA,MAAM,uBAAuB,QAAS,MAAM,KAAG,MAK9C,CAAC;AAEF;;;;;;GAMG;AACH,QAAA,MAAM,eAAe,GAAI,CAAC,QAAQ,CAAC,8BAA0B,CAiB5D,CAAC;AAEF;;;;;GAKG;AACH,QAAA,MAAM,gBAAgB,QAAS,MAAM,KAAG,MAEvC,CAAC;AAEF,OAAO,EACH,uBAAuB,EACvB,eAAe,EACf,gBAAgB,GACnB,CAAC"}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ // This file contains helper functions for working with objects.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.removeWhitespace = exports.removeUndefined = exports.toCapitalizedWithSpaces = void 0;
5
+ /**
6
+ * This takes a string and converts it to a string with spaces between each word and the first letter of each word capitalized.
7
+ * @param str the string to convert (e.g. "thisIsAString" or "This is a string")
8
+ * @returns the converted string (e.g. "This Is A String")
9
+ */
10
+ const toCapitalizedWithSpaces = (str) => {
11
+ // Add a space before all uppercase letters (except the first one), then trim any leading/trailing spaces
12
+ const result = str.replace(/(?!^)([A-Z])/g, ' $1').trim();
13
+ // Capitalize the first letter of each word
14
+ return result.replace(/\b\w/g, (char) => char.toUpperCase());
15
+ };
16
+ exports.toCapitalizedWithSpaces = toCapitalizedWithSpaces;
17
+ /**
18
+ * This takes an object and removes any undefined items off it and then returns a new object.
19
+ * if the type passed in is a primitive type other than the object, it returns the original object.
20
+ *
21
+ * @param item the incoming item.
22
+ * @returns a clean version of the object.
23
+ */
24
+ const removeUndefined = (item, recurseObject = false) => {
25
+ if (Array.isArray(item)) {
26
+ return item
27
+ .filter((element) => element !== undefined)
28
+ .map((element) => (recurseObject && Array.isArray(element) ? removeUndefined(element, true) : element));
29
+ }
30
+ else if (typeof item === 'object' && item !== null) {
31
+ const returnObject = { ...item };
32
+ Object.keys(returnObject).forEach((key) => {
33
+ if (returnObject[key] === undefined) {
34
+ delete returnObject[key];
35
+ }
36
+ else if (recurseObject && (typeof returnObject[key] === 'object' || Array.isArray(returnObject[key]))) {
37
+ returnObject[key] = removeUndefined(returnObject[key], true);
38
+ }
39
+ });
40
+ return returnObject;
41
+ }
42
+ return item;
43
+ };
44
+ exports.removeUndefined = removeUndefined;
45
+ /**
46
+ * This function removes all whitespace from a string
47
+ *
48
+ * @param str the string to remove whitespace from
49
+ * @returns
50
+ */
51
+ const removeWhitespace = (str) => {
52
+ return str.replace(/\s/g, '');
53
+ };
54
+ exports.removeWhitespace = removeWhitespace;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Checks that an object is an array and that it has the minimum number of items.
3
+ *
4
+ * @param incomingObject the object to check
5
+ * @param minimumLength the minimum number of objects to match (zero by default)
6
+ * @param maximumLength the maximum number of objects to match will default to the array length if not provided
7
+ *
8
+ * @returns whether the criteria matches.
9
+ */
10
+ declare const validateArray: (incomingObject: unknown, minimumLength?: number, maximumLength?: number) => boolean;
11
+ /**
12
+ * This validates an incoming shape of a boolean type data.
13
+ *
14
+ * @param incomingObject an object to validate as a boolean.
15
+ * @param undefinedValid whether the item can be undefined or not (false by default)
16
+ *
17
+ * @returns whether the shape is valid.
18
+ */
19
+ declare const validateBoolean: (incomingObject: unknown, undefinedValid?: boolean) => boolean;
20
+ /**
21
+ * This validates a date object or a string that can be converted to a date object.
22
+ * @param dateToValidate the date to validate
23
+ * @param undefinedValid whether the item can be undefined or not (false by default)
24
+ * @param allowFutureDated the date can be in the future (false by default)
25
+ * @param ensureAtLeast18YearsAgo whether the date is at least 18 years ago (true by default)
26
+ *
27
+ * @returns
28
+ */
29
+ declare const validateDate: (dateToValidate: unknown, undefinedValid?: boolean, allowFutureDated?: boolean, ensureAtLeast18YearsAgo?: boolean) => boolean;
30
+ /**
31
+ * This validates that the incoming Object is a number and that it is in the range (if provided)
32
+ *
33
+ * @param incomingObject object to validate to a number
34
+ * @param min (optional) minimum number
35
+ * @param max (optional) maximum number
36
+ * @returns
37
+ */
38
+ declare const validateNumber: (incomingObject: unknown, min?: number, max?: number) => boolean;
39
+ /**
40
+ * This validates an incoming shape of a set of files links to the data.
41
+ *
42
+ * @param incomingObject an object to validate as a string.
43
+ * @param hasNoSpaces whether the item should have no spaces in it (false by default)
44
+ * @param undefinedValid whether the item can be undefined or not (false by default)
45
+ * @param emptyStringValid whether the item can be an empty string or not (false by default)
46
+ *
47
+ * @returns whether the shape is valid.
48
+ */
49
+ declare const validateString: (incomingObject: unknown, hasNoSpaces?: boolean, undefinedValid?: boolean, emptyStringValid?: boolean) => boolean;
50
+ /**
51
+ * This validates that an incoming object is a valid URL.
52
+ *
53
+ * @param incomingUrl the URL to check
54
+ * @param undefinedValid whether the item can be undefined or not (false by default)
55
+ * @returns wether it is a valid URL or not
56
+ */
57
+ declare const validateUrl: (incomingUrl: unknown, undefinedValid?: boolean) => boolean;
58
+ export { validateArray, validateBoolean, validateDate, validateNumber, validateString, validateUrl, };
59
+ //# sourceMappingURL=object-validation-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object-validation-helpers.d.ts","sourceRoot":"","sources":["../../src/helpers/object-validation-helpers.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,QAAA,MAAM,aAAa,mBAAoB,OAAO,0CAAqC,MAAM,KAAG,OAc3F,CAAC;AAEF;;;;;;;GAOG;AACH,QAAA,MAAM,eAAe,mBAAoB,OAAO,+BAA2B,OAS1E,CAAC;AAEF;;;;;;;;GAQG;AACH,QAAA,MAAM,YAAY,mBAAoB,OAAO,8FACP,OAoCrC,CAAC;AAEF;;;;;;;GAOG;AACH,QAAA,MAAM,cAAc,mBAAoB,OAAO,QAAQ,MAAM,QAAQ,MAAM,KAAG,OAU7E,CAAC;AAEF;;;;;;;;;GASG;AACH,QAAA,MAAM,cAAc,mBAAoB,OAAO,kFAA0E,OAiCxH,CAAC;AAEF;;;;;;GAMG;AACH,QAAA,MAAM,WAAW,gBAAiB,OAAO,+BAA2B,OAqBnE,CAAC;AA+CF,OAAO,EACH,aAAa,EACb,eAAe,EACf,YAAY,EACZ,cAAc,EACd,cAAc,EACd,WAAW,GACd,CAAC"}