@karmaniverous/entity-manager
Advanced tools
Comparing version 2.2.1 to 3.0.0
@@ -16,2 +16,3 @@ "use strict"; | ||
var _sortedUniq2 = _interopRequireDefault(require("lodash/sortedUniq")); | ||
var _has2 = _interopRequireDefault(require("lodash/has")); | ||
var _entries2 = _interopRequireDefault(require("lodash/entries")); | ||
@@ -150,7 +151,7 @@ var _sortBy2 = _interopRequireDefault(require("lodash/sortBy")); | ||
decode | ||
} = _classPrivateFieldGet(this, _entityManager).getKey(entityToken, component); | ||
} = this.getKey(entityToken, component); | ||
if (!(0, _isFunction2.default)(decode)) throw new Error(`no decode function defined on ${entityToken} entity key '${component}'`); | ||
return { | ||
...properties, | ||
...(decode(index[component] ?? '')?.groups ?? []) | ||
...(decode(index[component] ?? '') ?? {}) | ||
}; | ||
@@ -171,2 +172,17 @@ }, {}); | ||
/** | ||
* Return the config for a given entity key token. | ||
* | ||
* @param {string} entityToken - Entity token. | ||
* @param {string} keyToken - Key token. | ||
* @returns {object} Entity key config. | ||
*/ | ||
getKey(entityToken, keyToken) { | ||
const { | ||
keys | ||
} = _classPrivateFieldGet(this, _entityManager).getEntityConfig(entityToken); | ||
if (!(0, _has2.default)(keys, keyToken)) throw new Error(`Key '${keyToken}' does not exist for entity '${entityToken}'.`); | ||
return keys[keyToken]; | ||
} | ||
/** | ||
* Return an array of sharded keys valid for a given entity token & timestamp. | ||
@@ -188,3 +204,3 @@ * | ||
const shardKeySpace = _classPrivateFieldGet(this, _entityManager).getShardKeySpace(entityToken, timestamp); | ||
const result = (0, _sortedUniq2.default)(shardKeySpace.map(shardKey => _classPrivateFieldGet(this, _entityManager).getKey(entityToken, keyToken).encode({ | ||
const result = (0, _sortedUniq2.default)(shardKeySpace.map(shardKey => this.getKey(entityToken, keyToken).encode({ | ||
...item, | ||
@@ -313,3 +329,3 @@ [_classPrivateFieldGet(this, _entityManager).shardKeyToken]: shardKey | ||
encode | ||
} = _classPrivateFieldGet(this, _entityManager).getKey(entityToken, component); | ||
} = this.getKey(entityToken, component); | ||
return [...new Set([...keys, ...(0, _inspectParametersDeclaration.getParametersNames)(encode)]).values()]; | ||
@@ -321,3 +337,3 @@ }, [])); | ||
encode | ||
} = _classPrivateFieldGet(this, _entityManager).getKey(entityToken, component); | ||
} = this.getKey(entityToken, component); | ||
return { | ||
@@ -324,0 +340,0 @@ ...index, |
@@ -305,9 +305,2 @@ "use strict"; | ||
} | ||
getKey(entityToken, keyToken) { | ||
const { | ||
keys | ||
} = this.getEntityConfig(entityToken); | ||
if (!(0, _has2.default)(keys, keyToken)) throw new Error(`Key '${keyToken}' does not exist for entity '${entityToken}'.`); | ||
return keys[keyToken]; | ||
} | ||
@@ -314,0 +307,0 @@ /** |
@@ -113,3 +113,3 @@ /** | ||
const indexProperties = indexComponents.reduce((properties, component) => { | ||
const { decode } = this.#entityManager.getKey(entityToken, component); | ||
const { decode } = this.getKey(entityToken, component); | ||
if (!_.isFunction(decode)) | ||
@@ -122,3 +122,3 @@ throw new Error( | ||
...properties, | ||
...(decode(index[component] ?? '')?.groups ?? []), | ||
...(decode(index[component] ?? '') ?? {}), | ||
}; | ||
@@ -136,2 +136,20 @@ }, {}); | ||
/** | ||
* Return the config for a given entity key token. | ||
* | ||
* @param {string} entityToken - Entity token. | ||
* @param {string} keyToken - Key token. | ||
* @returns {object} Entity key config. | ||
*/ | ||
getKey(entityToken, keyToken) { | ||
const { keys } = this.#entityManager.getEntityConfig(entityToken); | ||
if (!_.has(keys, keyToken)) | ||
throw new Error( | ||
`Key '${keyToken}' does not exist for entity '${entityToken}'.` | ||
); | ||
return keys[keyToken]; | ||
} | ||
/** | ||
* Return an array of sharded keys valid for a given entity token & timestamp. | ||
@@ -162,3 +180,3 @@ * | ||
shardKeySpace.map((shardKey) => | ||
this.#entityManager.getKey(entityToken, keyToken).encode({ | ||
this.getKey(entityToken, keyToken).encode({ | ||
...item, | ||
@@ -288,3 +306,3 @@ [this.#entityManager.shardKeyToken]: shardKey, | ||
indexComponents.reduce((keys, component) => { | ||
const { encode } = this.#entityManager.getKey(entityToken, component); | ||
const { encode } = this.getKey(entityToken, component); | ||
return [...new Set([...keys, ...getParametersNames(encode)]).values()]; | ||
@@ -297,3 +315,3 @@ }, []) | ||
return indexComponents.reduce((index, component) => { | ||
const { encode } = this.#entityManager.getKey(entityToken, component); | ||
const { encode } = this.getKey(entityToken, component); | ||
return { ...index, [component]: encode(indexProperies) }; | ||
@@ -300,0 +318,0 @@ }, {}); |
@@ -284,13 +284,2 @@ import { validate } from 'jsonschema'; | ||
getKey(entityToken, keyToken) { | ||
const { keys } = this.getEntityConfig(entityToken); | ||
if (!_.has(keys, keyToken)) | ||
throw new Error( | ||
`Key '${keyToken}' does not exist for entity '${entityToken}'.` | ||
); | ||
return keys[keyToken]; | ||
} | ||
/** | ||
@@ -297,0 +286,0 @@ * Get the number of nibbles & nibbleBits for a given entityToken at a given timestamp. |
{ | ||
"name": "@karmaniverous/entity-manager", | ||
"version": "2.2.1", | ||
"version": "3.0.0", | ||
"publishConfig": { | ||
@@ -5,0 +5,0 @@ "access": "public" |
@@ -59,3 +59,3 @@ # entity-manager | ||
// Table RANGE key. | ||
entitySK: ({ timestamp, transactionId }) => | ||
transactionSK: ({ timestamp, transactionId }) => | ||
sn2u`timestamp#${timestamp}|transactionId#${transactionId}`, | ||
@@ -166,3 +166,3 @@ | ||
// debug: "entityPK": "transaction!7", | ||
// debug: "entitySK": "timestamp#1676869312851|transactionId#transactionIdValue", | ||
// debug: "transactionSK": "timestamp#1676869312851|transactionId#transactionIdValue", | ||
// debug: "merchantPK": "merchantId#merchantIdValue|transaction!7", | ||
@@ -227,2 +227,3 @@ // debug: "merchantSK": "timestamp#1676869312851|methodId#methodIdValue|transactionId#transactionIdValue", | ||
* [.dehydrateIndex(entityToken, indexToken, index, [delimiter])](#module_entity-manager.EntityManager+dehydrateIndex) ⇒ <code>string</code> | ||
* [.getKey(entityToken, keyToken)](#module_entity-manager.EntityManager+getKey) ⇒ <code>object</code> | ||
* [.getKeySpace(entityToken, keyToken, item, timestamp)](#module_entity-manager.EntityManager+getKeySpace) ⇒ <code>Array.<string></code> | ||
@@ -249,2 +250,3 @@ * [.query(entityToken, keyToken, item, shardQuery, [options])](#module_entity-manager.EntityManager+query) ⇒ <code>Promise.<ShardedQueryResult></code> | ||
* [.dehydrateIndex(entityToken, indexToken, index, [delimiter])](#module_entity-manager.EntityManager+dehydrateIndex) ⇒ <code>string</code> | ||
* [.getKey(entityToken, keyToken)](#module_entity-manager.EntityManager+getKey) ⇒ <code>object</code> | ||
* [.getKeySpace(entityToken, keyToken, item, timestamp)](#module_entity-manager.EntityManager+getKeySpace) ⇒ <code>Array.<string></code> | ||
@@ -326,2 +328,15 @@ * [.query(entityToken, keyToken, item, shardQuery, [options])](#module_entity-manager.EntityManager+query) ⇒ <code>Promise.<ShardedQueryResult></code> | ||
<a name="module_entity-manager.EntityManager+getKey"></a> | ||
#### entityManager.getKey(entityToken, keyToken) ⇒ <code>object</code> | ||
Return the config for a given entity key token. | ||
**Kind**: instance method of [<code>EntityManager</code>](#module_entity-manager.EntityManager) | ||
**Returns**: <code>object</code> - Entity key config. | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| entityToken | <code>string</code> | Entity token. | | ||
| keyToken | <code>string</code> | Key token. | | ||
<a name="module_entity-manager.EntityManager+getKeySpace"></a> | ||
@@ -328,0 +343,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
79360
818
1435
457
101
35
58
73