@karmaniverous/entity-manager 2.1.2 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -375,7 +375,7 @@ Convert a delimited string into a named index key.
|
|
|
375
375
|
| Param | Type | Default | Description |
|
|
376
376
|
| --- | --- | --- | --- |
|
|
377
377
|
| entityToken | <code>string</code> | | Entity token. |
|
|
378
|
-
| indexToken | <code>string</code> | | Index token. |
|
|
378
|
+
| indexToken | <code>string</code> \| <code>Array.<string></code> | | Index token or array of key tokens. |
|
|
379
379
|
| value | <code>string</code> | | Dehydrated index value. |
|
|
380
380
|
| [delimiter] | <code>string</code> | <code>"~"</code> | Delimiter. |
|
|
381
381
|
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.EntityManager = void 0;
|
|
7
7
|
var _zipObject2 = _interopRequireDefault(require("lodash/zipObject"));
|
|
8
|
+
var _isArray2 = _interopRequireDefault(require("lodash/isArray"));
|
|
8
9
|
var _map2 = _interopRequireDefault(require("lodash/map"));
|
|
9
10
|
var _size2 = _interopRequireDefault(require("lodash/size"));
|
|
10
11
|
var _isEmpty2 = _interopRequireDefault(require("lodash/isEmpty"));
|
|
@@ -149,7 +150,7 @@ class EntityManager {
|
|
|
149
150
|
if (!(0, _isFunction2.default)(decode)) throw new Error(`no decode function defined on ${entityToken} entity key '${component}'`);
|
|
150
151
|
return {
|
|
151
152
|
...properties,
|
|
152
|
-
...(decode(index[component])?.groups ?? [])
|
|
153
|
+
...(decode(index[component] ?? '')?.groups ?? [])
|
|
153
154
|
};
|
|
154
155
|
}, {});
|
|
155
156
|
return (0, _sortedUniqBy2.default)((0, _sortBy2.default)((0, _entries2.default)(indexProperties), _ref3 => {
|
|
@@ -291,7 +292,7 @@ class EntityManager {
|
|
|
291
292
|
* Convert a delimited string into a named index key.
|
|
292
293
|
*
|
|
293
294
|
* @param {string} entityToken - Entity token.
|
|
294
|
-
* @param {string} indexToken - Index token.
|
|
295
|
+
* @param {string|string[]} indexToken - Index token or array of key tokens.
|
|
295
296
|
* @param {string} value - Dehydrated index value.
|
|
296
297
|
* @param {string} [delimiter] - Delimiter.
|
|
297
298
|
* @returns {object} Rehydrated index key.
|
|
@@ -301,7 +302,7 @@ class EntityManager {
|
|
|
301
302
|
rehydrateIndex(entityToken, indexToken) {
|
|
302
303
|
let value = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
303
304
|
let delimiter = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '~';
|
|
304
|
-
const indexComponents = _classPrivateFieldGet(this, _entityManager).getIndexComponents(entityToken, indexToken);
|
|
305
|
+
const indexComponents = (0, _isArray2.default)(indexToken) ? indexToken : _classPrivateFieldGet(this, _entityManager).getIndexComponents(entityToken, indexToken);
|
|
305
306
|
const indexKeys = (0, _sortBy2.default)(indexComponents.reduce((keys, component) => {
|
|
306
307
|
const {
|
|
307
308
|
encode
|
|
@@ -117,7 +117,10 @@ export class EntityManager {
|
|
|
117
117
|
`no decode function defined on ${entityToken} entity key '${component}'`
|
|
118
118
|
);
|
|
119
119
|
|
|
120
|
-
return {
|
|
120
|
+
return {
|
|
121
|
+
...properties,
|
|
122
|
+
...(decode(index[component] ?? '')?.groups ?? []),
|
|
123
|
+
};
|
|
121
124
|
}, {});
|
|
122
125
|
|
|
123
126
|
return _.sortedUniqBy(
|
|
@@ -265,7 +268,7 @@ export class EntityManager {
|
|
|
265
268
|
* Convert a delimited string into a named index key.
|
|
266
269
|
*
|
|
267
270
|
* @param {string} entityToken - Entity token.
|
|
268
|
-
* @param {string} indexToken - Index token.
|
|
271
|
+
* @param {string|string[]} indexToken - Index token or array of key tokens.
|
|
269
272
|
* @param {string} value - Dehydrated index value.
|
|
270
273
|
* @param {string} [delimiter] - Delimiter.
|
|
271
274
|
* @returns {object} Rehydrated index key.
|
|
@@ -273,10 +276,9 @@ export class EntityManager {
|
|
|
273
276
|
* @throws {Error} If indexToken is invalid.
|
|
274
277
|
*/
|
|
275
278
|
rehydrateIndex(entityToken, indexToken, value = '', delimiter = '~') {
|
|
276
|
-
const indexComponents =
|
|
277
|
-
|
|
278
|
-
indexToken
|
|
279
|
-
);
|
|
279
|
+
const indexComponents = _.isArray(indexToken)
|
|
280
|
+
? indexToken
|
|
281
|
+
: this.#entityManager.getIndexComponents(entityToken, indexToken);
|
|
280
282
|
|
|
281
283
|
const indexKeys = _.sortBy(
|
|
282
284
|
indexComponents.reduce((keys, component) => {
|