@karmaniverous/entity-manager 2.1.3 → 2.2.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.
package/README.md
CHANGED
|
@@ -315,7 +315,7 @@ Condense an index object into a delimited string.
|
|
|
315
315
|
| Param | Type | Default | Description |
|
|
316
316
|
| --- | --- | --- | --- |
|
|
317
317
|
| entityToken | <code>string</code> | | Entity token. |
|
|
318
|
-
| indexToken | <code>string</code> | | Index token. |
|
|
318
|
+
| indexToken | <code>string</code> \| <code>Array.<string></code> | | Index token or array of key tokens. |
|
|
319
319
|
| index | <code>object</code> | | Index object. |
|
|
320
320
|
| [delimiter] | <code>string</code> | <code>"~"</code> | Delimiter. |
|
|
321
321
|
|
|
@@ -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
|
|
|
@@ -17,6 +17,7 @@ var _entries2 = _interopRequireDefault(require("lodash/entries"));
|
|
|
17
17
|
var _sortBy2 = _interopRequireDefault(require("lodash/sortBy"));
|
|
18
18
|
var _sortedUniqBy2 = _interopRequireDefault(require("lodash/sortedUniqBy"));
|
|
19
19
|
var _isFunction2 = _interopRequireDefault(require("lodash/isFunction"));
|
|
20
|
+
var _isArray2 = _interopRequireDefault(require("lodash/isArray"));
|
|
20
21
|
var _forEach2 = _interopRequireDefault(require("lodash/forEach"));
|
|
21
22
|
var _isNil2 = _interopRequireDefault(require("lodash/isNil"));
|
|
22
23
|
var _cloneDeep2 = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
@@ -129,7 +130,7 @@ class EntityManager {
|
|
|
129
130
|
* Condense an index object into a delimited string.
|
|
130
131
|
*
|
|
131
132
|
* @param {string} entityToken - Entity token.
|
|
132
|
-
* @param {string} indexToken - Index token.
|
|
133
|
+
* @param {string|string[]} indexToken - Index token or array of key tokens.
|
|
133
134
|
* @param {object} index - Index object.
|
|
134
135
|
* @param {string} [delimiter] - Delimiter.
|
|
135
136
|
* @returns {string} Dehydrated index.
|
|
@@ -141,7 +142,7 @@ class EntityManager {
|
|
|
141
142
|
let delimiter = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '~';
|
|
142
143
|
// Validate item.
|
|
143
144
|
_classPrivateFieldGet(this, _entityManager).validateItem(index);
|
|
144
|
-
const indexComponents = _classPrivateFieldGet(this, _entityManager).getIndexComponents(entityToken, indexToken);
|
|
145
|
+
const indexComponents = (0, _isArray2.default)(indexToken) ? indexToken : _classPrivateFieldGet(this, _entityManager).getIndexComponents(entityToken, indexToken);
|
|
145
146
|
const indexProperties = indexComponents.reduce((properties, component) => {
|
|
146
147
|
const {
|
|
147
148
|
decode
|
|
@@ -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
|
|
@@ -93,7 +93,7 @@ export class EntityManager {
|
|
|
93
93
|
* Condense an index object into a delimited string.
|
|
94
94
|
*
|
|
95
95
|
* @param {string} entityToken - Entity token.
|
|
96
|
-
* @param {string} indexToken - Index token.
|
|
96
|
+
* @param {string|string[]} indexToken - Index token or array of key tokens.
|
|
97
97
|
* @param {object} index - Index object.
|
|
98
98
|
* @param {string} [delimiter] - Delimiter.
|
|
99
99
|
* @returns {string} Dehydrated index.
|
|
@@ -105,10 +105,9 @@ export class EntityManager {
|
|
|
105
105
|
// Validate item.
|
|
106
106
|
this.#entityManager.validateItem(index);
|
|
107
107
|
|
|
108
|
-
const indexComponents =
|
|
109
|
-
|
|
110
|
-
indexToken
|
|
111
|
-
);
|
|
108
|
+
const indexComponents = _.isArray(indexToken)
|
|
109
|
+
? indexToken
|
|
110
|
+
: this.#entityManager.getIndexComponents(entityToken, indexToken);
|
|
112
111
|
|
|
113
112
|
const indexProperties = indexComponents.reduce((properties, component) => {
|
|
114
113
|
const { decode } = this.#entityManager.getKey(entityToken, component);
|
|
@@ -268,7 +267,7 @@ export class EntityManager {
|
|
|
268
267
|
* Convert a delimited string into a named index key.
|
|
269
268
|
*
|
|
270
269
|
* @param {string} entityToken - Entity token.
|
|
271
|
-
* @param {string} indexToken - Index token.
|
|
270
|
+
* @param {string|string[]} indexToken - Index token or array of key tokens.
|
|
272
271
|
* @param {string} value - Dehydrated index value.
|
|
273
272
|
* @param {string} [delimiter] - Delimiter.
|
|
274
273
|
* @returns {object} Rehydrated index key.
|
|
@@ -276,10 +275,9 @@ export class EntityManager {
|
|
|
276
275
|
* @throws {Error} If indexToken is invalid.
|
|
277
276
|
*/
|
|
278
277
|
rehydrateIndex(entityToken, indexToken, value = '', delimiter = '~') {
|
|
279
|
-
const indexComponents =
|
|
280
|
-
|
|
281
|
-
indexToken
|
|
282
|
-
);
|
|
278
|
+
const indexComponents = _.isArray(indexToken)
|
|
279
|
+
? indexToken
|
|
280
|
+
: this.#entityManager.getIndexComponents(entityToken, indexToken);
|
|
283
281
|
|
|
284
282
|
const indexKeys = _.sortBy(
|
|
285
283
|
indexComponents.reduce((keys, component) => {
|