@karmaniverous/entity-manager 3.0.0 → 4.0.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
@@ -224,7 +224,7 @@ This change can be accomplished with no breaking changes to existing implementat
224
224
  * [.dehydrateIndex(entityToken, indexToken, index, [delimiter])](#module_entity-manager.EntityManager+dehydrateIndex) ⇒ <code>string</code>
225
225
  * [.getKey(entityToken, keyToken)](#module_entity-manager.EntityManager+getKey) ⇒ <code>object</code>
226
226
  * [.getKeySpace(entityToken, keyToken, item, timestamp)](#module_entity-manager.EntityManager+getKeySpace) ⇒ <code>Array.&lt;string&gt;</code>
227
- * [.query(entityToken, keyToken, item, shardQuery, [options])](#module_entity-manager.EntityManager+query) ⇒ <code>Promise.&lt;ShardedQueryResult&gt;</code>
227
+ * [.query(options)](#module_entity-manager.EntityManager+query) ⇒ <code>Promise.&lt;ShardedQueryResult&gt;</code>
228
228
  * [.rehydrateIndex(entityToken, indexToken, value, [delimiter])](#module_entity-manager.EntityManager+rehydrateIndex) ⇒ <code>object</code>
229
229
  * [.removeKeys(entityToken, item)](#module_entity-manager.EntityManager+removeKeys) ⇒ <code>object</code>
230
230
  * _inner_
@@ -246,7 +246,7 @@ Manage DynamoDb entities.
246
246
  * [.dehydrateIndex(entityToken, indexToken, index, [delimiter])](#module_entity-manager.EntityManager+dehydrateIndex) ⇒ <code>string</code>
247
247
  * [.getKey(entityToken, keyToken)](#module_entity-manager.EntityManager+getKey) ⇒ <code>object</code>
248
248
  * [.getKeySpace(entityToken, keyToken, item, timestamp)](#module_entity-manager.EntityManager+getKeySpace) ⇒ <code>Array.&lt;string&gt;</code>
249
- * [.query(entityToken, keyToken, item, shardQuery, [options])](#module_entity-manager.EntityManager+query) ⇒ <code>Promise.&lt;ShardedQueryResult&gt;</code>
249
+ * [.query(options)](#module_entity-manager.EntityManager+query) ⇒ <code>Promise.&lt;ShardedQueryResult&gt;</code>
250
250
  * [.rehydrateIndex(entityToken, indexToken, value, [delimiter])](#module_entity-manager.EntityManager+rehydrateIndex) ⇒ <code>object</code>
251
251
  * [.removeKeys(entityToken, item)](#module_entity-manager.EntityManager+removeKeys) ⇒ <code>object</code>
252
252
 
@@ -358,21 +358,21 @@ Return an array of sharded keys valid for a given entity token & timestamp.
358
358
 
359
359
  <a name="module_entity-manager.EntityManager+query"></a>
360
360
 
361
- #### entityManager.query(entityToken, keyToken, item, shardQuery, [options]) ⇒ <code>Promise.&lt;ShardedQueryResult&gt;</code>
361
+ #### entityManager.query(options) ⇒ <code>Promise.&lt;ShardedQueryResult&gt;</code>
362
362
  Query an entity across shards.
363
363
 
364
364
  **Kind**: instance method of [<code>EntityManager</code>](#module_entity-manager.EntityManager)
365
365
  **Returns**: <code>Promise.&lt;ShardedQueryResult&gt;</code> - Sharded query result.
366
366
 
367
- | Param | Type | Description |
368
- | --- | --- | --- |
369
- | entityToken | <code>string</code> | Entity token. |
370
- | keyToken | <code>string</code> | Key token. |
371
- | item | <code>object</code> | Entity item sufficiently populated to generate property keyToken. |
372
- | shardQuery | <code>ShardQueryFunction</code> | Sharded query function. |
373
- | [options] | <code>object</code> | Options object. |
374
- | [options.limit] | <code>number</code> | Request limit. |
375
- | [options.pageKeys] | <code>object</code> | Map of shard page keys. |
367
+ | Param | Type | Default | Description |
368
+ | --- | --- | --- | --- |
369
+ | options | <code>object</code> | | Query options. |
370
+ | options.entityToken | <code>string</code> | | Entity token. |
371
+ | [options.keyToken] | <code>string</code> | <code>&quot;entityPK&quot;</code> | Key token. |
372
+ | [options.item] | <code>object</code> | <code>{}</code> | Entity item sufficiently populated to generate property keyToken. |
373
+ | options.shardQuery | <code>ShardQueryFunction</code> | | Sharded query function. |
374
+ | [options.limit] | <code>number</code> | | Request limit. |
375
+ | [options.pageKeys] | <code>object</code> | | Map of shard page keys. |
376
376
 
377
377
  <a name="module_entity-manager.EntityManager+rehydrateIndex"></a>
378
378
 
@@ -434,9 +434,8 @@ Shard query function
434
434
  | Param | Type | Description |
435
435
  | --- | --- | --- |
436
436
  | shardedKey | <code>string</code> | Sharded key. |
437
- | [options] | <code>object</code> | Options object. |
438
- | [options.limit] | <code>number</code> | Request limit. |
439
- | [options.pageKey] | <code>\*</code> | Page key. |
437
+ | [limit] | <code>number</code> | Request limit. |
438
+ | [pageKey] | <code>\*</code> | Page key. |
440
439
 
441
440
  <a name="module_entity-manager..ShardedQueryResult"></a>
442
441
 
@@ -217,9 +217,8 @@ class EntityManager {
217
217
  *
218
218
  * @callback ShardQueryFunction
219
219
  * @param {string} shardedKey - Sharded key.
220
- * @param {object} [options] - Options object.
221
- * @param {number} [options.limit] - Request limit.
222
- * @param {*} [options.pageKey] - Page key.
220
+ * @param {number} [limit] - Request limit.
221
+ * @param {*} [pageKey] - Page key.
223
222
  * @returns {Promise<ShardQueryResult>} Sharded query result.
224
223
  */
225
224
 
@@ -232,20 +231,24 @@ class EntityManager {
232
231
  /**
233
232
  * Query an entity across shards.
234
233
  *
235
- * @param {string} entityToken - Entity token.
236
- * @param {string} keyToken - Key token.
237
- * @param {object} item - Entity item sufficiently populated to generate property keyToken.
238
- * @param {ShardQueryFunction} shardQuery - Sharded query function.
239
- * @param {object} [options] - Options object.
234
+ * @param {object} options - Query options.
235
+ * @param {string} options.entityToken - Entity token.
236
+ * @param {string} [options.keyToken=entityPK] - Key token.
237
+ * @param {object} [options.item={}] - Entity item sufficiently populated to generate property keyToken.
238
+ * @param {ShardQueryFunction} options.shardQuery - Sharded query function.
240
239
  * @param {number} [options.limit] - Request limit.
241
240
  * @param {object} [options.pageKeys] - Map of shard page keys.
242
241
  * @returns {Promise<ShardedQueryResult>} Sharded query result.
243
242
  */
244
- async query(entityToken, keyToken, item, shardQuery) {
243
+ async query() {
245
244
  let {
245
+ entityToken,
246
+ keyToken = 'entityPK',
247
+ item = {},
248
+ shardQuery,
246
249
  limit,
247
250
  pageKeys
248
- } = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
251
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
249
252
  // Validate params.
250
253
  _classPrivateFieldGet(this, _entityManager).validateKeyToken(entityToken, keyToken);
251
254
  _classPrivateFieldGet(this, _entityManager).validateItem(item);
@@ -266,10 +269,7 @@ class EntityManager {
266
269
  const shardLimit = (0, _isUndefined2.default)(limit) ? undefined : Math.ceil(limit / (0, _size2.default)(pageKeys));
267
270
 
268
271
  // Query every shard in pageKeys.
269
- const shardQueryResults = await Promise.all((0, _map2.default)(pageKeys, (pageKey, shardedKey) => new Promise(resolve => shardQuery(shardedKey, {
270
- pageKey,
271
- limit: shardLimit
272
- }).then(_ref6 => {
272
+ const shardQueryResults = await Promise.all((0, _map2.default)(pageKeys, (pageKey, shardedKey) => new Promise(resolve => shardQuery(shardedKey, pageKey, shardLimit).then(_ref6 => {
273
273
  let {
274
274
  items,
275
275
  pageKey
@@ -196,9 +196,8 @@ export class EntityManager {
196
196
  *
197
197
  * @callback ShardQueryFunction
198
198
  * @param {string} shardedKey - Sharded key.
199
- * @param {object} [options] - Options object.
200
- * @param {number} [options.limit] - Request limit.
201
- * @param {*} [options.pageKey] - Page key.
199
+ * @param {number} [limit] - Request limit.
200
+ * @param {*} [pageKey] - Page key.
202
201
  * @returns {Promise<ShardQueryResult>} Sharded query result.
203
202
  */
204
203
 
@@ -211,22 +210,23 @@ export class EntityManager {
211
210
  /**
212
211
  * Query an entity across shards.
213
212
  *
214
- * @param {string} entityToken - Entity token.
215
- * @param {string} keyToken - Key token.
216
- * @param {object} item - Entity item sufficiently populated to generate property keyToken.
217
- * @param {ShardQueryFunction} shardQuery - Sharded query function.
218
- * @param {object} [options] - Options object.
213
+ * @param {object} options - Query options.
214
+ * @param {string} options.entityToken - Entity token.
215
+ * @param {string} [options.keyToken=entityPK] - Key token.
216
+ * @param {object} [options.item={}] - Entity item sufficiently populated to generate property keyToken.
217
+ * @param {ShardQueryFunction} options.shardQuery - Sharded query function.
219
218
  * @param {number} [options.limit] - Request limit.
220
219
  * @param {object} [options.pageKeys] - Map of shard page keys.
221
220
  * @returns {Promise<ShardedQueryResult>} Sharded query result.
222
221
  */
223
- async query(
222
+ async query({
224
223
  entityToken,
225
- keyToken,
226
- item,
224
+ keyToken = 'entityPK',
225
+ item = {},
227
226
  shardQuery,
228
- { limit, pageKeys } = {}
229
- ) {
227
+ limit,
228
+ pageKeys,
229
+ } = {}) {
230
230
  // Validate params.
231
231
  this.#entityManager.validateKeyToken(entityToken, keyToken);
232
232
  this.#entityManager.validateItem(item);
@@ -259,7 +259,7 @@ export class EntityManager {
259
259
  pageKeys,
260
260
  (pageKey, shardedKey) =>
261
261
  new Promise((resolve) =>
262
- shardQuery(shardedKey, { pageKey, limit: shardLimit }).then(
262
+ shardQuery(shardedKey, pageKey, shardLimit).then(
263
263
  ({ items, pageKey }) => resolve({ shardedKey, items, pageKey })
264
264
  )
265
265
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@karmaniverous/entity-manager",
3
- "version": "3.0.0",
3
+ "version": "4.0.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },