@orion-js/helpers 3.11.15 → 4.0.0-alpha.3
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/dist/index.cjs +1018 -0
- package/dist/index.d.ts +362 -0
- package/dist/index.js +992 -0
- package/package.json +21 -15
- package/LICENSE +0 -21
- package/jest.config.js +0 -8
- package/lib/Errors/OrionError.d.ts +0 -39
- package/lib/Errors/OrionError.js +0 -23
- package/lib/Errors/OrionError.test.d.ts +0 -1
- package/lib/Errors/OrionError.test.js +0 -52
- package/lib/Errors/PermissionsError.d.ts +0 -37
- package/lib/Errors/PermissionsError.js +0 -57
- package/lib/Errors/PermissionsError.test.d.ts +0 -1
- package/lib/Errors/PermissionsError.test.js +0 -62
- package/lib/Errors/UserError.d.ts +0 -33
- package/lib/Errors/UserError.js +0 -54
- package/lib/Errors/UserError.test.d.ts +0 -1
- package/lib/Errors/UserError.test.js +0 -49
- package/lib/Errors/index.d.ts +0 -43
- package/lib/Errors/index.js +0 -57
- package/lib/Errors/index.test.d.ts +0 -1
- package/lib/Errors/index.test.js +0 -56
- package/lib/composeMiddlewares.d.ts +0 -6
- package/lib/composeMiddlewares.js +0 -44
- package/lib/createMap.d.ts +0 -17
- package/lib/createMap.js +0 -26
- package/lib/createMap.test.d.ts +0 -1
- package/lib/createMap.test.js +0 -74
- package/lib/createMapArray.d.ts +0 -22
- package/lib/createMapArray.js +0 -32
- package/lib/createMapArray.test.d.ts +0 -1
- package/lib/createMapArray.test.js +0 -101
- package/lib/generateId.d.ts +0 -6
- package/lib/generateId.js +0 -54
- package/lib/generateId.test.d.ts +0 -1
- package/lib/generateId.test.js +0 -11
- package/lib/generateUUID.d.ts +0 -2
- package/lib/generateUUID.js +0 -12
- package/lib/generateUUID.test.d.ts +0 -1
- package/lib/generateUUID.test.js +0 -15
- package/lib/hashObject.d.ts +0 -1
- package/lib/hashObject.js +0 -10
- package/lib/hashObject.test.d.ts +0 -1
- package/lib/hashObject.test.js +0 -30
- package/lib/index.d.ts +0 -13
- package/lib/index.js +0 -40
- package/lib/normalize.d.ts +0 -70
- package/lib/normalize.js +0 -111
- package/lib/normalize.test.d.ts +0 -1
- package/lib/normalize.test.js +0 -101
- package/lib/retries.d.ts +0 -23
- package/lib/retries.js +0 -45
- package/lib/retries.test.d.ts +0 -1
- package/lib/retries.test.js +0 -47
- package/lib/searchTokens.d.ts +0 -61
- package/lib/searchTokens.js +0 -78
- package/lib/searchTokens.test.d.ts +0 -1
- package/lib/searchTokens.test.js +0 -101
- package/lib/shortenMongoId.d.ts +0 -1
- package/lib/shortenMongoId.js +0 -10
- package/lib/sleep.d.ts +0 -5
- package/lib/sleep.js +0 -8
- package/tsconfig.json +0 -16
- package/yarn-error.log +0 -710
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// from https://github.com/koajs/compose/blob/master/index.js
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.composeMiddlewares = void 0;
|
|
5
|
-
/**
|
|
6
|
-
* Compose `middleware` returning
|
|
7
|
-
* a fully valid middleware comprised
|
|
8
|
-
* of all those which are passed.
|
|
9
|
-
*/
|
|
10
|
-
function composeMiddlewares(middleware) {
|
|
11
|
-
if (!Array.isArray(middleware))
|
|
12
|
-
throw new TypeError('Middleware stack must be an array!');
|
|
13
|
-
for (const fn of middleware) {
|
|
14
|
-
if (typeof fn !== 'function')
|
|
15
|
-
throw new TypeError('Middleware must be composed of functions!');
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* @param {Object} context
|
|
19
|
-
* @return {Promise}
|
|
20
|
-
* @api public
|
|
21
|
-
*/
|
|
22
|
-
return function (context, next) {
|
|
23
|
-
// last called middleware #
|
|
24
|
-
let index = -1;
|
|
25
|
-
return dispatch(0);
|
|
26
|
-
function dispatch(i) {
|
|
27
|
-
if (i <= index)
|
|
28
|
-
return Promise.reject(new Error('next() called multiple times'));
|
|
29
|
-
index = i;
|
|
30
|
-
let fn = middleware[i];
|
|
31
|
-
if (i === middleware.length)
|
|
32
|
-
fn = next;
|
|
33
|
-
if (!fn)
|
|
34
|
-
return Promise.resolve();
|
|
35
|
-
try {
|
|
36
|
-
return Promise.resolve(fn(context, dispatch.bind(null, i + 1)));
|
|
37
|
-
}
|
|
38
|
-
catch (err) {
|
|
39
|
-
return Promise.reject(err);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
exports.composeMiddlewares = composeMiddlewares;
|
package/lib/createMap.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates a map (object) from an array of items, using a specified property as the key.
|
|
3
|
-
*
|
|
4
|
-
* This utility transforms an array of objects into a lookup object/dictionary where
|
|
5
|
-
* each item in the array becomes a value in the map, indexed by the specified property.
|
|
6
|
-
* If multiple items have the same key value, only the last one will be preserved.
|
|
7
|
-
*
|
|
8
|
-
* @template T The type of items in the input array
|
|
9
|
-
* @param array - The input array of items to transform into a map
|
|
10
|
-
* @param key - The property name to use as keys in the resulting map (defaults to '_id')
|
|
11
|
-
* @returns A record object where keys are values of the specified property and values are the original items
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* // Returns { '1': { id: 1, name: 'Item 1' }, '2': { id: 2, name: 'Item 2' } }
|
|
15
|
-
* createMap([{ id: 1, name: 'Item 1' }, { id: 2, name: 'Item 2' }], 'id')
|
|
16
|
-
*/
|
|
17
|
-
export default function createMap<T>(array: Array<T>, key?: string): Record<string, T>;
|
package/lib/createMap.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/**
|
|
4
|
-
* Creates a map (object) from an array of items, using a specified property as the key.
|
|
5
|
-
*
|
|
6
|
-
* This utility transforms an array of objects into a lookup object/dictionary where
|
|
7
|
-
* each item in the array becomes a value in the map, indexed by the specified property.
|
|
8
|
-
* If multiple items have the same key value, only the last one will be preserved.
|
|
9
|
-
*
|
|
10
|
-
* @template T The type of items in the input array
|
|
11
|
-
* @param array - The input array of items to transform into a map
|
|
12
|
-
* @param key - The property name to use as keys in the resulting map (defaults to '_id')
|
|
13
|
-
* @returns A record object where keys are values of the specified property and values are the original items
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* // Returns { '1': { id: 1, name: 'Item 1' }, '2': { id: 2, name: 'Item 2' } }
|
|
17
|
-
* createMap([{ id: 1, name: 'Item 1' }, { id: 2, name: 'Item 2' }], 'id')
|
|
18
|
-
*/
|
|
19
|
-
function createMap(array, key = '_id') {
|
|
20
|
-
const map = {};
|
|
21
|
-
for (const item of array) {
|
|
22
|
-
map[item[key]] = item;
|
|
23
|
-
}
|
|
24
|
-
return map;
|
|
25
|
-
}
|
|
26
|
-
exports.default = createMap;
|
package/lib/createMap.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/createMap.test.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
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
|
-
const createMap_1 = __importDefault(require("./createMap"));
|
|
7
|
-
describe('createMap', () => {
|
|
8
|
-
it('should create a map using the default _id key', () => {
|
|
9
|
-
const array = [
|
|
10
|
-
{ _id: '1', name: 'Item 1' },
|
|
11
|
-
{ _id: '2', name: 'Item 2' },
|
|
12
|
-
{ _id: '3', name: 'Item 3' }
|
|
13
|
-
];
|
|
14
|
-
const result = (0, createMap_1.default)(array);
|
|
15
|
-
expect(result).toEqual({
|
|
16
|
-
'1': { _id: '1', name: 'Item 1' },
|
|
17
|
-
'2': { _id: '2', name: 'Item 2' },
|
|
18
|
-
'3': { _id: '3', name: 'Item 3' }
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
it('should create a map using a custom key', () => {
|
|
22
|
-
const array = [
|
|
23
|
-
{ id: 'a', name: 'Item A' },
|
|
24
|
-
{ id: 'b', name: 'Item B' },
|
|
25
|
-
{ id: 'c', name: 'Item C' }
|
|
26
|
-
];
|
|
27
|
-
const result = (0, createMap_1.default)(array, 'id');
|
|
28
|
-
expect(result).toEqual({
|
|
29
|
-
'a': { id: 'a', name: 'Item A' },
|
|
30
|
-
'b': { id: 'b', name: 'Item B' },
|
|
31
|
-
'c': { id: 'c', name: 'Item C' }
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
it('should handle empty arrays', () => {
|
|
35
|
-
const result = (0, createMap_1.default)([]);
|
|
36
|
-
expect(result).toEqual({});
|
|
37
|
-
});
|
|
38
|
-
it('should handle objects with property references', () => {
|
|
39
|
-
const array = [
|
|
40
|
-
{ id: 'u1', message: 'Hello' },
|
|
41
|
-
{ id: 'u2', message: 'World' }
|
|
42
|
-
];
|
|
43
|
-
const result = (0, createMap_1.default)(array, 'id');
|
|
44
|
-
expect(result).toEqual({
|
|
45
|
-
'u1': { id: 'u1', message: 'Hello' },
|
|
46
|
-
'u2': { id: 'u2', message: 'World' }
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
it('should overwrite items with duplicate keys', () => {
|
|
50
|
-
const array = [
|
|
51
|
-
{ id: 'dup', value: 'First' },
|
|
52
|
-
{ id: 'dup', value: 'Second' },
|
|
53
|
-
{ id: 'dup', value: 'Third' }
|
|
54
|
-
];
|
|
55
|
-
const result = (0, createMap_1.default)(array, 'id');
|
|
56
|
-
// Only the last item with a given key should be preserved
|
|
57
|
-
expect(result).toEqual({
|
|
58
|
-
'dup': { id: 'dup', value: 'Third' }
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
it('should handle various key types', () => {
|
|
62
|
-
const array = [
|
|
63
|
-
{ key: 1, value: 'Number key' },
|
|
64
|
-
{ key: 'string', value: 'String key' },
|
|
65
|
-
{ key: true, value: 'Boolean key' }
|
|
66
|
-
];
|
|
67
|
-
const result = (0, createMap_1.default)(array, 'key');
|
|
68
|
-
expect(result).toEqual({
|
|
69
|
-
'1': { key: 1, value: 'Number key' },
|
|
70
|
-
'string': { key: 'string', value: 'String key' },
|
|
71
|
-
'true': { key: true, value: 'Boolean key' }
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
});
|
package/lib/createMapArray.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates a grouped map from an array of items, using a specified property as the key.
|
|
3
|
-
*
|
|
4
|
-
* This utility transforms an array of objects into a lookup object/dictionary where
|
|
5
|
-
* each value is an array of items sharing the same key value. Unlike createMap,
|
|
6
|
-
* this function preserves all items with the same key by grouping them in arrays.
|
|
7
|
-
*
|
|
8
|
-
* @template T The type of items in the input array
|
|
9
|
-
* @param array - The input array of items to transform into a grouped map
|
|
10
|
-
* @param key - The property name to use as keys in the resulting map (defaults to '_id')
|
|
11
|
-
* @returns A record object where keys are values of the specified property and values are arrays of items
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* // Returns { 'category1': [{ id: 1, category: 'category1' }, { id: 3, category: 'category1' }],
|
|
15
|
-
* // 'category2': [{ id: 2, category: 'category2' }] }
|
|
16
|
-
* createMapArray([
|
|
17
|
-
* { id: 1, category: 'category1' },
|
|
18
|
-
* { id: 2, category: 'category2' },
|
|
19
|
-
* { id: 3, category: 'category1' }
|
|
20
|
-
* ], 'category')
|
|
21
|
-
*/
|
|
22
|
-
export default function createMapArray<T>(array: Array<T>, key?: string): Record<string, Array<T>>;
|
package/lib/createMapArray.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/**
|
|
4
|
-
* Creates a grouped map from an array of items, using a specified property as the key.
|
|
5
|
-
*
|
|
6
|
-
* This utility transforms an array of objects into a lookup object/dictionary where
|
|
7
|
-
* each value is an array of items sharing the same key value. Unlike createMap,
|
|
8
|
-
* this function preserves all items with the same key by grouping them in arrays.
|
|
9
|
-
*
|
|
10
|
-
* @template T The type of items in the input array
|
|
11
|
-
* @param array - The input array of items to transform into a grouped map
|
|
12
|
-
* @param key - The property name to use as keys in the resulting map (defaults to '_id')
|
|
13
|
-
* @returns A record object where keys are values of the specified property and values are arrays of items
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* // Returns { 'category1': [{ id: 1, category: 'category1' }, { id: 3, category: 'category1' }],
|
|
17
|
-
* // 'category2': [{ id: 2, category: 'category2' }] }
|
|
18
|
-
* createMapArray([
|
|
19
|
-
* { id: 1, category: 'category1' },
|
|
20
|
-
* { id: 2, category: 'category2' },
|
|
21
|
-
* { id: 3, category: 'category1' }
|
|
22
|
-
* ], 'category')
|
|
23
|
-
*/
|
|
24
|
-
function createMapArray(array, key = '_id') {
|
|
25
|
-
const map = {};
|
|
26
|
-
for (const item of array) {
|
|
27
|
-
map[item[key]] = map[item[key]] || [];
|
|
28
|
-
map[item[key]].push(item);
|
|
29
|
-
}
|
|
30
|
-
return map;
|
|
31
|
-
}
|
|
32
|
-
exports.default = createMapArray;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,101 +0,0 @@
|
|
|
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
|
-
const createMapArray_1 = __importDefault(require("./createMapArray"));
|
|
7
|
-
describe('createMapArray', () => {
|
|
8
|
-
it('should create a map of arrays using the default _id key', () => {
|
|
9
|
-
const array = [
|
|
10
|
-
{ _id: '1', name: 'Item 1' },
|
|
11
|
-
{ _id: '2', name: 'Item 2' },
|
|
12
|
-
{ _id: '1', name: 'Item 1 Duplicate' }
|
|
13
|
-
];
|
|
14
|
-
const result = (0, createMapArray_1.default)(array);
|
|
15
|
-
expect(result).toEqual({
|
|
16
|
-
'1': [
|
|
17
|
-
{ _id: '1', name: 'Item 1' },
|
|
18
|
-
{ _id: '1', name: 'Item 1 Duplicate' }
|
|
19
|
-
],
|
|
20
|
-
'2': [
|
|
21
|
-
{ _id: '2', name: 'Item 2' }
|
|
22
|
-
]
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
it('should create a map of arrays using a custom key', () => {
|
|
26
|
-
const array = [
|
|
27
|
-
{ category: 'A', name: 'Item A1' },
|
|
28
|
-
{ category: 'B', name: 'Item B1' },
|
|
29
|
-
{ category: 'A', name: 'Item A2' },
|
|
30
|
-
{ category: 'C', name: 'Item C1' },
|
|
31
|
-
{ category: 'B', name: 'Item B2' }
|
|
32
|
-
];
|
|
33
|
-
const result = (0, createMapArray_1.default)(array, 'category');
|
|
34
|
-
expect(result).toEqual({
|
|
35
|
-
'A': [
|
|
36
|
-
{ category: 'A', name: 'Item A1' },
|
|
37
|
-
{ category: 'A', name: 'Item A2' }
|
|
38
|
-
],
|
|
39
|
-
'B': [
|
|
40
|
-
{ category: 'B', name: 'Item B1' },
|
|
41
|
-
{ category: 'B', name: 'Item B2' }
|
|
42
|
-
],
|
|
43
|
-
'C': [
|
|
44
|
-
{ category: 'C', name: 'Item C1' }
|
|
45
|
-
]
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
it('should handle empty arrays', () => {
|
|
49
|
-
const result = (0, createMapArray_1.default)([]);
|
|
50
|
-
expect(result).toEqual({});
|
|
51
|
-
});
|
|
52
|
-
it('should preserve the original order of items within each group', () => {
|
|
53
|
-
const array = [
|
|
54
|
-
{ type: 'fruit', name: 'apple', order: 1 },
|
|
55
|
-
{ type: 'vegetable', name: 'carrot', order: 1 },
|
|
56
|
-
{ type: 'fruit', name: 'banana', order: 2 },
|
|
57
|
-
{ type: 'fruit', name: 'cherry', order: 3 },
|
|
58
|
-
{ type: 'vegetable', name: 'broccoli', order: 2 }
|
|
59
|
-
];
|
|
60
|
-
const result = (0, createMapArray_1.default)(array, 'type');
|
|
61
|
-
// Items should be grouped by type and maintain their original order
|
|
62
|
-
expect(result.fruit.map(item => item.order)).toEqual([1, 2, 3]);
|
|
63
|
-
expect(result.vegetable.map(item => item.order)).toEqual([1, 2]);
|
|
64
|
-
});
|
|
65
|
-
it('should handle various key types', () => {
|
|
66
|
-
const array = [
|
|
67
|
-
{ key: 1, value: 'Number key 1' },
|
|
68
|
-
{ key: 1, value: 'Number key 2' },
|
|
69
|
-
{ key: 'string', value: 'String key 1' },
|
|
70
|
-
{ key: 'string', value: 'String key 2' },
|
|
71
|
-
{ key: true, value: 'Boolean key' }
|
|
72
|
-
];
|
|
73
|
-
const result = (0, createMapArray_1.default)(array, 'key');
|
|
74
|
-
expect(result).toEqual({
|
|
75
|
-
'1': [
|
|
76
|
-
{ key: 1, value: 'Number key 1' },
|
|
77
|
-
{ key: 1, value: 'Number key 2' }
|
|
78
|
-
],
|
|
79
|
-
'string': [
|
|
80
|
-
{ key: 'string', value: 'String key 1' },
|
|
81
|
-
{ key: 'string', value: 'String key 2' }
|
|
82
|
-
],
|
|
83
|
-
'true': [
|
|
84
|
-
{ key: true, value: 'Boolean key' }
|
|
85
|
-
]
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
it('should handle items with missing keys by using undefined', () => {
|
|
89
|
-
const array = [
|
|
90
|
-
{ id: '1', name: 'Has ID' },
|
|
91
|
-
{ name: 'No ID' },
|
|
92
|
-
{ id: '2', name: 'Has ID 2' }
|
|
93
|
-
];
|
|
94
|
-
const result = (0, createMapArray_1.default)(array, 'id');
|
|
95
|
-
expect(result).toEqual({
|
|
96
|
-
'1': [{ id: '1', name: 'Has ID' }],
|
|
97
|
-
'2': [{ id: '2', name: 'Has ID 2' }],
|
|
98
|
-
'undefined': [{ name: 'No ID' }]
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
});
|
package/lib/generateId.d.ts
DELETED
package/lib/generateId.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
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
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
7
|
-
const UNMISTAKABLE_CHARS = '23456789ABCDEFGHJKLMNPQRSTWXYZabcdefghjkmnopqrstuvwxyz';
|
|
8
|
-
const hexString = function (digits) {
|
|
9
|
-
var numBytes = Math.ceil(digits / 2);
|
|
10
|
-
var bytes;
|
|
11
|
-
// Try to get cryptographically strong randomness. Fall back to
|
|
12
|
-
// non-cryptographically strong if not available.
|
|
13
|
-
try {
|
|
14
|
-
bytes = crypto_1.default.randomBytes(numBytes);
|
|
15
|
-
}
|
|
16
|
-
catch (e) {
|
|
17
|
-
// XXX should re-throw any error except insufficient entropy
|
|
18
|
-
bytes = crypto_1.default.pseudoRandomBytes(numBytes);
|
|
19
|
-
}
|
|
20
|
-
var result = bytes.toString('hex');
|
|
21
|
-
// If the number of digits is odd, we'll have generated an extra 4 bits
|
|
22
|
-
// of randomness, so we need to trim the last digit.
|
|
23
|
-
return result.substring(0, digits);
|
|
24
|
-
};
|
|
25
|
-
const fraction = function () {
|
|
26
|
-
var numerator = parseInt(hexString(8), 16);
|
|
27
|
-
return numerator * 2.3283064365386963e-10; // 2^-32
|
|
28
|
-
};
|
|
29
|
-
const choice = function (arrayOrString) {
|
|
30
|
-
var index = Math.floor(fraction() * arrayOrString.length);
|
|
31
|
-
if (typeof arrayOrString === 'string')
|
|
32
|
-
return arrayOrString.substr(index, 1);
|
|
33
|
-
else
|
|
34
|
-
return arrayOrString[index];
|
|
35
|
-
};
|
|
36
|
-
const randomString = function (charsCount, alphabet) {
|
|
37
|
-
var digits = [];
|
|
38
|
-
for (var i = 0; i < charsCount; i++) {
|
|
39
|
-
digits[i] = choice(alphabet);
|
|
40
|
-
}
|
|
41
|
-
return digits.join('');
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Returns a random ID
|
|
45
|
-
* @param charsCount length of the ID
|
|
46
|
-
* @param chars characters used to generate the ID
|
|
47
|
-
*/
|
|
48
|
-
function generateId(charsCount, chars = UNMISTAKABLE_CHARS) {
|
|
49
|
-
if (!charsCount) {
|
|
50
|
-
charsCount = 17;
|
|
51
|
-
}
|
|
52
|
-
return randomString(charsCount, chars);
|
|
53
|
-
}
|
|
54
|
-
exports.default = generateId;
|
package/lib/generateId.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/generateId.test.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
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
|
-
const generateId_1 = __importDefault(require("./generateId"));
|
|
7
|
-
const isString_1 = __importDefault(require("lodash/isString"));
|
|
8
|
-
it('should generate random ids', async () => {
|
|
9
|
-
expect((0, generateId_1.default)()).not.toBe((0, generateId_1.default)());
|
|
10
|
-
expect((0, isString_1.default)((0, generateId_1.default)())).toBe(true);
|
|
11
|
-
});
|
package/lib/generateUUID.d.ts
DELETED
package/lib/generateUUID.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateUUIDWithPrefix = exports.generateUUID = void 0;
|
|
4
|
-
const uuid_1 = require("uuid");
|
|
5
|
-
function generateUUID() {
|
|
6
|
-
return (0, uuid_1.v4)();
|
|
7
|
-
}
|
|
8
|
-
exports.generateUUID = generateUUID;
|
|
9
|
-
function generateUUIDWithPrefix(prefix) {
|
|
10
|
-
return `${prefix}-${generateUUID()}`;
|
|
11
|
-
}
|
|
12
|
-
exports.generateUUIDWithPrefix = generateUUIDWithPrefix;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/generateUUID.test.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
const isString_1 = __importDefault(require("lodash/isString"));
|
|
7
|
-
const generateUUID_1 = require("./generateUUID");
|
|
8
|
-
it('should generate random uuid v4', async () => {
|
|
9
|
-
expect((0, generateUUID_1.generateUUID)()).not.toBe((0, generateUUID_1.generateUUID)());
|
|
10
|
-
expect((0, isString_1.default)((0, generateUUID_1.generateUUID)())).toBe(true);
|
|
11
|
-
});
|
|
12
|
-
it('should generate uuid with prefix', async () => {
|
|
13
|
-
expect((0, generateUUID_1.generateUUIDWithPrefix)('test')).not.toBe((0, generateUUID_1.generateUUIDWithPrefix)('test'));
|
|
14
|
-
expect((0, isString_1.default)((0, generateUUID_1.generateUUIDWithPrefix)('test'))).toBe(true);
|
|
15
|
-
});
|
package/lib/hashObject.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function (object: any): string;
|
package/lib/hashObject.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
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
|
-
const object_hash_1 = __importDefault(require("object-hash"));
|
|
7
|
-
function default_1(object) {
|
|
8
|
-
return (0, object_hash_1.default)(object);
|
|
9
|
-
}
|
|
10
|
-
exports.default = default_1;
|
package/lib/hashObject.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/hashObject.test.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
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
|
-
const hashObject_1 = __importDefault(require("./hashObject"));
|
|
7
|
-
it('should create a string hash of an object', async () => {
|
|
8
|
-
const object = {
|
|
9
|
-
hello: 'world',
|
|
10
|
-
date: new Date(),
|
|
11
|
-
subObject: {
|
|
12
|
-
name: 'Nicolás'
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
const hash = (0, hashObject_1.default)(object);
|
|
16
|
-
expect(typeof hash).toBe('string');
|
|
17
|
-
});
|
|
18
|
-
it('object with different key orders should return same hash', async () => {
|
|
19
|
-
const object1 = {
|
|
20
|
-
one: '1',
|
|
21
|
-
two: '2'
|
|
22
|
-
};
|
|
23
|
-
const object2 = {
|
|
24
|
-
two: '2',
|
|
25
|
-
one: '1'
|
|
26
|
-
};
|
|
27
|
-
const hash1 = (0, hashObject_1.default)(object1);
|
|
28
|
-
const hash2 = (0, hashObject_1.default)(object2);
|
|
29
|
-
expect(hash1).toBe(hash2);
|
|
30
|
-
});
|
package/lib/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import sleep from './sleep';
|
|
2
|
-
import hashObject from './hashObject';
|
|
3
|
-
import generateId from './generateId';
|
|
4
|
-
import createMap from './createMap';
|
|
5
|
-
import createMapArray from './createMapArray';
|
|
6
|
-
import { OrionError, OrionErrorInformation, PermissionsError, UserError, isOrionError, isUserError, isPermissionsError } from './Errors';
|
|
7
|
-
export * from './composeMiddlewares';
|
|
8
|
-
export * from './retries';
|
|
9
|
-
export * from './generateUUID';
|
|
10
|
-
export * from './normalize';
|
|
11
|
-
export * from './searchTokens';
|
|
12
|
-
export * from './shortenMongoId';
|
|
13
|
-
export { createMap, createMapArray, generateId, hashObject, sleep, OrionError, PermissionsError, UserError, OrionErrorInformation, isOrionError, isUserError, isPermissionsError };
|
package/lib/index.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
-
};
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.isPermissionsError = exports.isUserError = exports.isOrionError = exports.UserError = exports.PermissionsError = exports.OrionError = exports.sleep = exports.hashObject = exports.generateId = exports.createMapArray = exports.createMap = void 0;
|
|
17
|
-
const sleep_1 = __importDefault(require("./sleep"));
|
|
18
|
-
exports.sleep = sleep_1.default;
|
|
19
|
-
const hashObject_1 = __importDefault(require("./hashObject"));
|
|
20
|
-
exports.hashObject = hashObject_1.default;
|
|
21
|
-
const generateId_1 = __importDefault(require("./generateId"));
|
|
22
|
-
exports.generateId = generateId_1.default;
|
|
23
|
-
const createMap_1 = __importDefault(require("./createMap"));
|
|
24
|
-
exports.createMap = createMap_1.default;
|
|
25
|
-
const createMapArray_1 = __importDefault(require("./createMapArray"));
|
|
26
|
-
exports.createMapArray = createMapArray_1.default;
|
|
27
|
-
// Import all error-related exports from the Errors module
|
|
28
|
-
const Errors_1 = require("./Errors");
|
|
29
|
-
Object.defineProperty(exports, "OrionError", { enumerable: true, get: function () { return Errors_1.OrionError; } });
|
|
30
|
-
Object.defineProperty(exports, "PermissionsError", { enumerable: true, get: function () { return Errors_1.PermissionsError; } });
|
|
31
|
-
Object.defineProperty(exports, "UserError", { enumerable: true, get: function () { return Errors_1.UserError; } });
|
|
32
|
-
Object.defineProperty(exports, "isOrionError", { enumerable: true, get: function () { return Errors_1.isOrionError; } });
|
|
33
|
-
Object.defineProperty(exports, "isUserError", { enumerable: true, get: function () { return Errors_1.isUserError; } });
|
|
34
|
-
Object.defineProperty(exports, "isPermissionsError", { enumerable: true, get: function () { return Errors_1.isPermissionsError; } });
|
|
35
|
-
__exportStar(require("./composeMiddlewares"), exports);
|
|
36
|
-
__exportStar(require("./retries"), exports);
|
|
37
|
-
__exportStar(require("./generateUUID"), exports);
|
|
38
|
-
__exportStar(require("./normalize"), exports);
|
|
39
|
-
__exportStar(require("./searchTokens"), exports);
|
|
40
|
-
__exportStar(require("./shortenMongoId"), exports);
|
package/lib/normalize.d.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Removes diacritical marks (accents) from text without any other modifications.
|
|
3
|
-
* This is the most basic normalization function that others build upon.
|
|
4
|
-
*
|
|
5
|
-
* @param text - The input string to process
|
|
6
|
-
* @returns String with accents removed but otherwise unchanged
|
|
7
|
-
*/
|
|
8
|
-
export declare function removeAccentsOnly(text: string): string;
|
|
9
|
-
/**
|
|
10
|
-
* Normalizes text by removing diacritical marks (accents) and trimming whitespace.
|
|
11
|
-
* Builds on removeAccentsOnly and adds whitespace trimming.
|
|
12
|
-
*
|
|
13
|
-
* @param text - The input string to normalize
|
|
14
|
-
* @returns Normalized string with accents removed and whitespace trimmed
|
|
15
|
-
*/
|
|
16
|
-
export declare function removeAccentsAndTrim(text: string): string;
|
|
17
|
-
/**
|
|
18
|
-
* Normalizes text for search purposes by:
|
|
19
|
-
* - Removing diacritical marks (accents)
|
|
20
|
-
* - Converting to lowercase
|
|
21
|
-
* - Trimming whitespace
|
|
22
|
-
*
|
|
23
|
-
* Builds on removeAccentsAndTrim and adds lowercase conversion.
|
|
24
|
-
* Useful for case-insensitive and accent-insensitive text searching.
|
|
25
|
-
*
|
|
26
|
-
* @param text - The input string to normalize for search
|
|
27
|
-
* @returns Search-optimized string in lowercase with accents removed
|
|
28
|
-
*/
|
|
29
|
-
export declare function normalizeForSearch(text: string): string;
|
|
30
|
-
/**
|
|
31
|
-
* Normalizes text for search purposes by:
|
|
32
|
-
* - Removing diacritical marks (accents)
|
|
33
|
-
* - Converting to lowercase
|
|
34
|
-
* - Trimming whitespace
|
|
35
|
-
* - Removing all spaces
|
|
36
|
-
*
|
|
37
|
-
* Builds on normalizeForSearch and removes all whitespace.
|
|
38
|
-
* Useful for compact search indexes or when spaces should be ignored in searches.
|
|
39
|
-
*
|
|
40
|
-
* @param text - The input string to normalize for compact search
|
|
41
|
-
* @returns Compact search-optimized string with no spaces
|
|
42
|
-
*/
|
|
43
|
-
export declare function normalizeForCompactSearch(text: string): string;
|
|
44
|
-
/**
|
|
45
|
-
* Normalizes text for search token processing by:
|
|
46
|
-
* - Removing diacritical marks (accents)
|
|
47
|
-
* - Converting to lowercase
|
|
48
|
-
* - Trimming whitespace
|
|
49
|
-
* - Replacing all non-alphanumeric characters with spaces
|
|
50
|
-
*
|
|
51
|
-
* Builds on normalizeForSearch and replaces non-alphanumeric characters with spaces.
|
|
52
|
-
* Useful for tokenizing search terms where special characters should be treated as word separators.
|
|
53
|
-
*
|
|
54
|
-
* @param text - The input string to normalize for tokenized search
|
|
55
|
-
* @returns Search token string with only alphanumeric characters and spaces
|
|
56
|
-
*/
|
|
57
|
-
export declare function normalizeForSearchToken(text: string): string;
|
|
58
|
-
/**
|
|
59
|
-
* Normalizes a string specifically for use as a file key (e.g., in S3 or other storage systems).
|
|
60
|
-
* Performs the following transformations:
|
|
61
|
-
* - Removes accents/diacritical marks
|
|
62
|
-
* - Replaces special characters with hyphens
|
|
63
|
-
* - Ensures only alphanumeric characters, hyphens, periods, and underscores remain
|
|
64
|
-
* - Replaces multiple consecutive hyphens with a single hyphen
|
|
65
|
-
* - Removes leading/trailing hyphens
|
|
66
|
-
*
|
|
67
|
-
* @param text - The input string to normalize for file key usage
|
|
68
|
-
* @returns A storage-safe string suitable for use as a file key
|
|
69
|
-
*/
|
|
70
|
-
export declare function normalizeForFileKey(text: string): string;
|