@karmaniverous/entity-manager 4.0.0 → 4.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.
@@ -271,24 +271,28 @@ class EntityManager {
271
271
  // Query every shard in pageKeys.
272
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
+ count,
274
275
  items,
275
276
  pageKey
276
277
  } = _ref6;
277
278
  return resolve({
278
- shardedKey,
279
+ count,
279
280
  items,
280
- pageKey
281
+ pageKey,
282
+ shardedKey
281
283
  });
282
284
  }))));
283
285
 
284
286
  // Reduce shardQueryResults into a single result.
285
287
  const result = shardQueryResults.reduce((shardedQueryResult, _ref7) => {
286
288
  let {
287
- shardedKey,
289
+ count,
288
290
  items,
289
- pageKey
291
+ pageKey,
292
+ shardedKey
290
293
  } = _ref7;
291
294
  return {
295
+ count: shardedQueryResult.count + count,
292
296
  items: [...shardedQueryResult.items, ...items],
293
297
  pageKeys: {
294
298
  ...shardedQueryResult.pageKeys,
@@ -298,6 +302,7 @@ class EntityManager {
298
302
  }
299
303
  };
300
304
  }, {
305
+ count: 0,
301
306
  items: [],
302
307
  pageKeys: {}
303
308
  });
@@ -367,8 +372,8 @@ class EntityManager {
367
372
  delete newItem[shardKeyToken];
368
373
 
369
374
  // Remove keys.
370
- (0, _forEach2.default)(keys, (getValue, key) => {
371
- delete newItem[key];
375
+ (0, _forEach2.default)(keys, (value, key) => {
376
+ if (!value.retain) delete newItem[key];
372
377
  });
373
378
  _classPrivateFieldGet(this, _entityManager).logger.debug('done', newItem);
374
379
  return newItem;
@@ -108,7 +108,10 @@ const keySchema = {
108
108
  type: 'object',
109
109
  properties: {
110
110
  encode: {},
111
- decode: {}
111
+ decode: {},
112
+ retain: {
113
+ type: 'boolean'
114
+ }
112
115
  },
113
116
  additionalProperties: false,
114
117
  required: ['encode']
@@ -260,7 +260,8 @@ export class EntityManager {
260
260
  (pageKey, shardedKey) =>
261
261
  new Promise((resolve) =>
262
262
  shardQuery(shardedKey, pageKey, shardLimit).then(
263
- ({ items, pageKey }) => resolve({ shardedKey, items, pageKey })
263
+ ({ count, items, pageKey }) =>
264
+ resolve({ count, items, pageKey, shardedKey })
264
265
  )
265
266
  )
266
267
  )
@@ -268,14 +269,15 @@ export class EntityManager {
268
269
 
269
270
  // Reduce shardQueryResults into a single result.
270
271
  const result = shardQueryResults.reduce(
271
- (shardedQueryResult, { shardedKey, items, pageKey }) => ({
272
+ (shardedQueryResult, { count, items, pageKey, shardedKey }) => ({
273
+ count: shardedQueryResult.count + count,
272
274
  items: [...shardedQueryResult.items, ...items],
273
275
  pageKeys: {
274
276
  ...shardedQueryResult.pageKeys,
275
277
  ...(_.isUndefined(pageKey) ? {} : { [shardedKey]: pageKey }),
276
278
  },
277
279
  }),
278
- { items: [], pageKeys: {} }
280
+ { count: 0, items: [], pageKeys: {} }
279
281
  );
280
282
 
281
283
  return result;
@@ -341,8 +343,8 @@ export class EntityManager {
341
343
  delete newItem[shardKeyToken];
342
344
 
343
345
  // Remove keys.
344
- _.forEach(keys, (getValue, key) => {
345
- delete newItem[key];
346
+ _.forEach(keys, (value, key) => {
347
+ if (!value.retain) delete newItem[key];
346
348
  });
347
349
  this.#entityManager.logger.debug('done', newItem);
348
350
 
@@ -72,6 +72,9 @@ const keySchema = {
72
72
  properties: {
73
73
  encode: {},
74
74
  decode: {},
75
+ retain: {
76
+ type: 'boolean',
77
+ },
75
78
  },
76
79
  additionalProperties: false,
77
80
  required: ['encode'],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@karmaniverous/entity-manager",
3
- "version": "4.0.0",
3
+ "version": "4.2.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },