@karmaniverous/entity-manager 6.12.0 → 6.13.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.
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var tslib = require('tslib');
|
|
4
4
|
var radash = require('radash');
|
|
5
5
|
var addKeys = require('./addKeys.js');
|
|
6
|
+
var encodeGeneratedProperty = require('./encodeGeneratedProperty.js');
|
|
6
7
|
var findIndexToken = require('./findIndexToken.js');
|
|
7
8
|
var ParsedConfig = require('./ParsedConfig.js');
|
|
8
9
|
var query = require('./query.js');
|
|
@@ -48,6 +49,19 @@ class EntityManager {
|
|
|
48
49
|
set config(value) {
|
|
49
50
|
tslib.__classPrivateFieldSet(this, _EntityManager_config, ParsedConfig.configSchema.parse(value), "f");
|
|
50
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Encode a generated property value. Returns a string or undefined if atomicity requirement of sharded properties not met.
|
|
54
|
+
*
|
|
55
|
+
* @param property - {@link Config.generatedProperties | Generated property} key.
|
|
56
|
+
* @param item - Partial {@link ItemMap | `ItemMap`} object.
|
|
57
|
+
*
|
|
58
|
+
* @returns Encoded generated property value.
|
|
59
|
+
*
|
|
60
|
+
* @throws `Error` if `property` is not a {@link Config.generatedProperties | generated property}.
|
|
61
|
+
*/
|
|
62
|
+
encodeGeneratedProperty(property, item) {
|
|
63
|
+
return encodeGeneratedProperty.encodeGeneratedProperty(this, property, item);
|
|
64
|
+
}
|
|
51
65
|
/**
|
|
52
66
|
* Update generated properties, hash key, and range key on an {@link EntityItem | `EntityItem`} object.
|
|
53
67
|
*
|
|
@@ -97,11 +111,14 @@ class EntityManager {
|
|
|
97
111
|
*
|
|
98
112
|
* @param hashKeyToken - Index hash key.
|
|
99
113
|
* @param rangeKeyToken - Index range key.
|
|
114
|
+
* @param suppressError - Suppress error if no match found.
|
|
100
115
|
*
|
|
101
116
|
* @returns Index token if found.
|
|
117
|
+
*
|
|
118
|
+
* @throws `Error` if no match found and `suppressError` is not `true`.
|
|
102
119
|
*/
|
|
103
|
-
findIndexToken(hashKeyToken, rangeKeyToken) {
|
|
104
|
-
return findIndexToken.findIndexToken(this, hashKeyToken, rangeKeyToken);
|
|
120
|
+
findIndexToken(hashKeyToken, rangeKeyToken, suppressError) {
|
|
121
|
+
return findIndexToken.findIndexToken(this, hashKeyToken, rangeKeyToken, suppressError);
|
|
105
122
|
}
|
|
106
123
|
/**
|
|
107
124
|
* Query a database entity across shards in a provider-generic fashion.
|
|
@@ -6,11 +6,17 @@
|
|
|
6
6
|
* @param entityManager - {@link EntityManager | `EntityManager`} instance.
|
|
7
7
|
* @param hashKeyToken - Index hash key.
|
|
8
8
|
* @param rangeKeyToken - Index range key.
|
|
9
|
+
* @param suppressError - Suppress error if no match found.
|
|
9
10
|
*
|
|
10
11
|
* @returns Index token if found.
|
|
12
|
+
*
|
|
13
|
+
* @throws `Error` if no match found and `suppressError` is not `true`.
|
|
11
14
|
*/
|
|
12
|
-
function findIndexToken(entityManager, hashKeyToken, rangeKeyToken) {
|
|
13
|
-
|
|
15
|
+
function findIndexToken(entityManager, hashKeyToken, rangeKeyToken, suppressError) {
|
|
16
|
+
const indexToken = Object.entries(entityManager.config.indexes).find(([, index]) => index.hashKey === hashKeyToken && index.rangeKey === rangeKeyToken)?.[0];
|
|
17
|
+
if (!indexToken && !suppressError)
|
|
18
|
+
throw new Error(`No index token found for hashKey '${hashKeyToken}' & rangeKey '${rangeKeyToken}'.`);
|
|
19
|
+
return indexToken;
|
|
14
20
|
}
|
|
15
21
|
|
|
16
22
|
exports.findIndexToken = findIndexToken;
|
package/dist/index.d.ts
CHANGED
|
@@ -541,6 +541,17 @@ declare class EntityManager<C extends BaseConfigMap> {
|
|
|
541
541
|
* @param value - {@link Config | `Config`} object.
|
|
542
542
|
*/
|
|
543
543
|
set config(value: ParsedConfig);
|
|
544
|
+
/**
|
|
545
|
+
* Encode a generated property value. Returns a string or undefined if atomicity requirement of sharded properties not met.
|
|
546
|
+
*
|
|
547
|
+
* @param property - {@link Config.generatedProperties | Generated property} key.
|
|
548
|
+
* @param item - Partial {@link ItemMap | `ItemMap`} object.
|
|
549
|
+
*
|
|
550
|
+
* @returns Encoded generated property value.
|
|
551
|
+
*
|
|
552
|
+
* @throws `Error` if `property` is not a {@link Config.generatedProperties | generated property}.
|
|
553
|
+
*/
|
|
554
|
+
encodeGeneratedProperty<C extends BaseConfigMap>(property: C['ShardedKeys'] | C['UnshardedKeys'], item: EntityItem<C>): string | undefined;
|
|
544
555
|
/**
|
|
545
556
|
* Update generated properties, hash key, and range key on an {@link EntityItem | `EntityItem`} object.
|
|
546
557
|
*
|
|
@@ -581,10 +592,13 @@ declare class EntityManager<C extends BaseConfigMap> {
|
|
|
581
592
|
*
|
|
582
593
|
* @param hashKeyToken - Index hash key.
|
|
583
594
|
* @param rangeKeyToken - Index range key.
|
|
595
|
+
* @param suppressError - Suppress error if no match found.
|
|
584
596
|
*
|
|
585
597
|
* @returns Index token if found.
|
|
598
|
+
*
|
|
599
|
+
* @throws `Error` if no match found and `suppressError` is not `true`.
|
|
586
600
|
*/
|
|
587
|
-
findIndexToken(hashKeyToken:
|
|
601
|
+
findIndexToken(hashKeyToken: string, rangeKeyToken: string, suppressError?: boolean): string | undefined;
|
|
588
602
|
/**
|
|
589
603
|
* Query a database entity across shards in a provider-generic fashion.
|
|
590
604
|
*
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { __classPrivateFieldSet, __classPrivateFieldGet } from 'tslib';
|
|
2
2
|
import { pick } from 'radash';
|
|
3
3
|
import { addKeys } from './addKeys.js';
|
|
4
|
+
import { encodeGeneratedProperty } from './encodeGeneratedProperty.js';
|
|
4
5
|
import { findIndexToken } from './findIndexToken.js';
|
|
5
6
|
import { configSchema } from './ParsedConfig.js';
|
|
6
7
|
import { query } from './query.js';
|
|
@@ -46,6 +47,19 @@ class EntityManager {
|
|
|
46
47
|
set config(value) {
|
|
47
48
|
__classPrivateFieldSet(this, _EntityManager_config, configSchema.parse(value), "f");
|
|
48
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Encode a generated property value. Returns a string or undefined if atomicity requirement of sharded properties not met.
|
|
52
|
+
*
|
|
53
|
+
* @param property - {@link Config.generatedProperties | Generated property} key.
|
|
54
|
+
* @param item - Partial {@link ItemMap | `ItemMap`} object.
|
|
55
|
+
*
|
|
56
|
+
* @returns Encoded generated property value.
|
|
57
|
+
*
|
|
58
|
+
* @throws `Error` if `property` is not a {@link Config.generatedProperties | generated property}.
|
|
59
|
+
*/
|
|
60
|
+
encodeGeneratedProperty(property, item) {
|
|
61
|
+
return encodeGeneratedProperty(this, property, item);
|
|
62
|
+
}
|
|
49
63
|
/**
|
|
50
64
|
* Update generated properties, hash key, and range key on an {@link EntityItem | `EntityItem`} object.
|
|
51
65
|
*
|
|
@@ -95,11 +109,14 @@ class EntityManager {
|
|
|
95
109
|
*
|
|
96
110
|
* @param hashKeyToken - Index hash key.
|
|
97
111
|
* @param rangeKeyToken - Index range key.
|
|
112
|
+
* @param suppressError - Suppress error if no match found.
|
|
98
113
|
*
|
|
99
114
|
* @returns Index token if found.
|
|
115
|
+
*
|
|
116
|
+
* @throws `Error` if no match found and `suppressError` is not `true`.
|
|
100
117
|
*/
|
|
101
|
-
findIndexToken(hashKeyToken, rangeKeyToken) {
|
|
102
|
-
return findIndexToken(this, hashKeyToken, rangeKeyToken);
|
|
118
|
+
findIndexToken(hashKeyToken, rangeKeyToken, suppressError) {
|
|
119
|
+
return findIndexToken(this, hashKeyToken, rangeKeyToken, suppressError);
|
|
103
120
|
}
|
|
104
121
|
/**
|
|
105
122
|
* Query a database entity across shards in a provider-generic fashion.
|
|
@@ -4,11 +4,17 @@
|
|
|
4
4
|
* @param entityManager - {@link EntityManager | `EntityManager`} instance.
|
|
5
5
|
* @param hashKeyToken - Index hash key.
|
|
6
6
|
* @param rangeKeyToken - Index range key.
|
|
7
|
+
* @param suppressError - Suppress error if no match found.
|
|
7
8
|
*
|
|
8
9
|
* @returns Index token if found.
|
|
10
|
+
*
|
|
11
|
+
* @throws `Error` if no match found and `suppressError` is not `true`.
|
|
9
12
|
*/
|
|
10
|
-
function findIndexToken(entityManager, hashKeyToken, rangeKeyToken) {
|
|
11
|
-
|
|
13
|
+
function findIndexToken(entityManager, hashKeyToken, rangeKeyToken, suppressError) {
|
|
14
|
+
const indexToken = Object.entries(entityManager.config.indexes).find(([, index]) => index.hashKey === hashKeyToken && index.rangeKey === rangeKeyToken)?.[0];
|
|
15
|
+
if (!indexToken && !suppressError)
|
|
16
|
+
throw new Error(`No index token found for hashKey '${hashKeyToken}' & rangeKey '${rangeKeyToken}'.`);
|
|
17
|
+
return indexToken;
|
|
12
18
|
}
|
|
13
19
|
|
|
14
20
|
export { findIndexToken };
|
package/package.json
CHANGED