@karmaniverous/entity-manager 6.10.3 → 6.11.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/dist/cjs/EntityManager.js +18 -0
- package/dist/index.d.ts +22 -10
- package/dist/mjs/EntityManager.js +18 -0
- package/package.json +3 -3
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var tslib = require('tslib');
|
|
4
|
+
var radash = require('radash');
|
|
4
5
|
var addKeys = require('./addKeys.js');
|
|
5
6
|
var ParsedConfig = require('./ParsedConfig.js');
|
|
6
7
|
var query = require('./query.js');
|
|
@@ -60,6 +61,23 @@ class EntityManager {
|
|
|
60
61
|
addKeys(entityToken, item, overwrite = false) {
|
|
61
62
|
return addKeys.addKeys(this, entityToken, item, overwrite);
|
|
62
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Convert an {@link EntityItem | `EntityItem`} into an {@link EntityKey | `EntityKey`}.
|
|
66
|
+
*
|
|
67
|
+
* @param entityToken - {@link Config | `Config`} `entities` key.
|
|
68
|
+
* @param item - {@link EntityItem | `EntityItem`} object.
|
|
69
|
+
* @param overwrite - Overwrite existing properties (default `false`).
|
|
70
|
+
*
|
|
71
|
+
* @returns {@link EntityKey | `EntityKey`} extracted from shallow clone of `item` with updated properties.
|
|
72
|
+
*
|
|
73
|
+
* @throws `Error` if `entityToken` is invalid.
|
|
74
|
+
*/
|
|
75
|
+
getPrimaryKey(entityToken, item, overwrite = false) {
|
|
76
|
+
const { hashKey, rangeKey } = this.config;
|
|
77
|
+
return radash.pick(!overwrite && item[hashKey] && item[rangeKey]
|
|
78
|
+
? item
|
|
79
|
+
: addKeys.addKeys(this, entityToken, item, overwrite), [this.config.hashKey, this.config.rangeKey]);
|
|
80
|
+
}
|
|
63
81
|
/**
|
|
64
82
|
* Strips generated properties, hash key, and range key from an {@link EntityItem | `EntityItem`} object.
|
|
65
83
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -86,6 +86,16 @@ type Config<C extends BaseConfigMap = BaseConfigMap> = ConditionalProperty<'enti
|
|
|
86
86
|
*/
|
|
87
87
|
type EntityItem<C extends BaseConfigMap> = Partial<FlattenEntityMap<C['EntityMap']> & Record<C['HashKey'] | C['RangeKey'] | C['ShardedKeys'] | C['UnshardedKeys'], string>> & Record<string, unknown>;
|
|
88
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Database-facing record key type from a {@link BaseConfigMap | `ConfigMap`} with required hash & range keys.
|
|
91
|
+
*
|
|
92
|
+
* @typeParam C - {@link ConfigMap | `ConfigMap`} that defines an {@link Config | `EntityManager configuration`}'s {@link EntityMap | `EntityMap`}, key properties, and {@link TranscodeMap | `TranscodeMap`}. If omitted, defaults to {@link BaseConfigMap | `BaseConfigMap`}.
|
|
93
|
+
*
|
|
94
|
+
* @category EntityClient
|
|
95
|
+
* @protected
|
|
96
|
+
*/
|
|
97
|
+
type EntityKey<C extends BaseConfigMap> = Record<C['HashKey'] | C['RangeKey'], string>;
|
|
98
|
+
|
|
89
99
|
/**
|
|
90
100
|
* Extracts entity tokens from a {@link ConfigMap | `ConfigMap`}.
|
|
91
101
|
*
|
|
@@ -533,6 +543,18 @@ declare class EntityManager<C extends BaseConfigMap> {
|
|
|
533
543
|
* @throws `Error` if `entityToken` is invalid.
|
|
534
544
|
*/
|
|
535
545
|
addKeys(entityToken: EntityToken<C>, item: EntityItem<C>, overwrite?: boolean): EntityItem<C>;
|
|
546
|
+
/**
|
|
547
|
+
* Convert an {@link EntityItem | `EntityItem`} into an {@link EntityKey | `EntityKey`}.
|
|
548
|
+
*
|
|
549
|
+
* @param entityToken - {@link Config | `Config`} `entities` key.
|
|
550
|
+
* @param item - {@link EntityItem | `EntityItem`} object.
|
|
551
|
+
* @param overwrite - Overwrite existing properties (default `false`).
|
|
552
|
+
*
|
|
553
|
+
* @returns {@link EntityKey | `EntityKey`} extracted from shallow clone of `item` with updated properties.
|
|
554
|
+
*
|
|
555
|
+
* @throws `Error` if `entityToken` is invalid.
|
|
556
|
+
*/
|
|
557
|
+
getPrimaryKey(entityToken: EntityToken<C>, item: EntityItem<C>, overwrite?: boolean): EntityKey<C>;
|
|
536
558
|
/**
|
|
537
559
|
* Strips generated properties, hash key, and range key from an {@link EntityItem | `EntityItem`} object.
|
|
538
560
|
*
|
|
@@ -714,16 +736,6 @@ type ConfigMap<M extends Partial<BaseConfigMap> = Partial<BaseConfigMap>> = Vali
|
|
|
714
736
|
TranscodeMap: 'TranscodeMap' extends keyof M ? NonNullable<M['TranscodeMap']> : DefaultTranscodeMap;
|
|
715
737
|
}>;
|
|
716
738
|
|
|
717
|
-
/**
|
|
718
|
-
* Database-facing record key type from a {@link BaseConfigMap | `ConfigMap`} with required hash & range keys.
|
|
719
|
-
*
|
|
720
|
-
* @typeParam C - {@link ConfigMap | `ConfigMap`} that defines an {@link Config | `EntityManager configuration`}'s {@link EntityMap | `EntityMap`}, key properties, and {@link TranscodeMap | `TranscodeMap`}. If omitted, defaults to {@link BaseConfigMap | `BaseConfigMap`}.
|
|
721
|
-
*
|
|
722
|
-
* @category EntityClient
|
|
723
|
-
* @protected
|
|
724
|
-
*/
|
|
725
|
-
type EntityKey<C extends BaseConfigMap> = Record<C['HashKey'] | C['RangeKey'], string>;
|
|
726
|
-
|
|
727
739
|
/**
|
|
728
740
|
* Database-facing record type from a {@link BaseConfigMap | `ConfigMap`} with required hash & range keys.
|
|
729
741
|
*
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { __classPrivateFieldSet, __classPrivateFieldGet } from 'tslib';
|
|
2
|
+
import { pick } from 'radash';
|
|
2
3
|
import { addKeys } from './addKeys.js';
|
|
3
4
|
import { configSchema } from './ParsedConfig.js';
|
|
4
5
|
import { query } from './query.js';
|
|
@@ -58,6 +59,23 @@ class EntityManager {
|
|
|
58
59
|
addKeys(entityToken, item, overwrite = false) {
|
|
59
60
|
return addKeys(this, entityToken, item, overwrite);
|
|
60
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Convert an {@link EntityItem | `EntityItem`} into an {@link EntityKey | `EntityKey`}.
|
|
64
|
+
*
|
|
65
|
+
* @param entityToken - {@link Config | `Config`} `entities` key.
|
|
66
|
+
* @param item - {@link EntityItem | `EntityItem`} object.
|
|
67
|
+
* @param overwrite - Overwrite existing properties (default `false`).
|
|
68
|
+
*
|
|
69
|
+
* @returns {@link EntityKey | `EntityKey`} extracted from shallow clone of `item` with updated properties.
|
|
70
|
+
*
|
|
71
|
+
* @throws `Error` if `entityToken` is invalid.
|
|
72
|
+
*/
|
|
73
|
+
getPrimaryKey(entityToken, item, overwrite = false) {
|
|
74
|
+
const { hashKey, rangeKey } = this.config;
|
|
75
|
+
return pick(!overwrite && item[hashKey] && item[rangeKey]
|
|
76
|
+
? item
|
|
77
|
+
: addKeys(this, entityToken, item, overwrite), [this.config.hashKey, this.config.rangeKey]);
|
|
78
|
+
}
|
|
61
79
|
/**
|
|
62
80
|
* Strips generated properties, hash key, and range key from an {@link EntityItem | `EntityItem`} object.
|
|
63
81
|
*
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
},
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@karmaniverous/batch-process": "^0.1.0",
|
|
8
|
-
"@karmaniverous/entity-tools": "^0.6.
|
|
8
|
+
"@karmaniverous/entity-tools": "^0.6.4",
|
|
9
9
|
"@karmaniverous/string-utilities": "^0.2.1",
|
|
10
10
|
"lz-string": "^1.5.0",
|
|
11
11
|
"radash": "^12.1.0",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"description": "Rational indexing & cross-shard querying at scale in your NoSQL database so you can focus on your application logic.",
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@dotenvx/dotenvx": "^1.22.
|
|
17
|
+
"@dotenvx/dotenvx": "^1.22.1",
|
|
18
18
|
"@eslint/js": "^9.14.0",
|
|
19
19
|
"@faker-js/faker": "^9.2.0",
|
|
20
20
|
"@karmaniverous/mock-db": "^0.3.4",
|
|
@@ -132,5 +132,5 @@
|
|
|
132
132
|
},
|
|
133
133
|
"type": "module",
|
|
134
134
|
"types": "dist/index.d.ts",
|
|
135
|
-
"version": "6.
|
|
135
|
+
"version": "6.11.1"
|
|
136
136
|
}
|