@karmaniverous/entity-manager 6.11.4 → 6.12.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/dist/cjs/EntityManager.js +12 -0
- package/dist/cjs/ParsedConfig.js +1 -0
- package/dist/cjs/findIndexToken.js +16 -0
- package/dist/index.d.ts +9 -0
- package/dist/mjs/EntityManager.js +12 -0
- package/dist/mjs/ParsedConfig.js +1 -0
- package/dist/mjs/findIndexToken.js +14 -0
- package/package.json +1 -1
|
@@ -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 findIndexToken = require('./findIndexToken.js');
|
|
6
7
|
var ParsedConfig = require('./ParsedConfig.js');
|
|
7
8
|
var query = require('./query.js');
|
|
8
9
|
var removeKeys = require('./removeKeys.js');
|
|
@@ -91,6 +92,17 @@ class EntityManager {
|
|
|
91
92
|
removeKeys(entityToken, item) {
|
|
92
93
|
return removeKeys.removeKeys(this, entityToken, item);
|
|
93
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Find an index token in a {@link Config | `Config`} object based on the index `hashKey` and `rangeKey`.
|
|
97
|
+
*
|
|
98
|
+
* @param hashKeyToken - Index hash key.
|
|
99
|
+
* @param rangeKeyToken - Index range key.
|
|
100
|
+
*
|
|
101
|
+
* @returns Index token if found.
|
|
102
|
+
*/
|
|
103
|
+
findIndexToken(hashKeyToken, rangeKeyToken) {
|
|
104
|
+
return findIndexToken.findIndexToken(this, hashKeyToken, rangeKeyToken);
|
|
105
|
+
}
|
|
94
106
|
/**
|
|
95
107
|
* Query a database entity across shards in a provider-generic fashion.
|
|
96
108
|
*
|
package/dist/cjs/ParsedConfig.js
CHANGED
|
@@ -236,6 +236,7 @@ const configSchema = zod.z
|
|
|
236
236
|
path: ['generatedProperties', 'unsharded', property],
|
|
237
237
|
});
|
|
238
238
|
// Validate indexes.
|
|
239
|
+
// TODO: Vaidate no two indexes have the same hashKey & rangeKey.
|
|
239
240
|
for (const [indexKey, { hashKey, rangeKey, projections }] of Object.entries(data.indexes)) {
|
|
240
241
|
// Validate hash key is sharded.
|
|
241
242
|
if (![data.hashKey, ...shardedKeys].includes(hashKey)) {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Find an index token in a {@link Config | `Config`} object based on the index `hashKey` and `rangeKey`.
|
|
5
|
+
*
|
|
6
|
+
* @param entityManager - {@link EntityManager | `EntityManager`} instance.
|
|
7
|
+
* @param hashKeyToken - Index hash key.
|
|
8
|
+
* @param rangeKeyToken - Index range key.
|
|
9
|
+
*
|
|
10
|
+
* @returns Index token if found.
|
|
11
|
+
*/
|
|
12
|
+
function findIndexToken(entityManager, hashKeyToken, rangeKeyToken) {
|
|
13
|
+
return Object.entries(entityManager.config.indexes).find(([, index]) => index.hashKey === hashKeyToken && index.rangeKey === rangeKeyToken)?.[0];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.findIndexToken = findIndexToken;
|
package/dist/index.d.ts
CHANGED
|
@@ -576,6 +576,15 @@ declare class EntityManager<C extends BaseConfigMap> {
|
|
|
576
576
|
* @throws `Error` if `entityToken` is invalid.
|
|
577
577
|
*/
|
|
578
578
|
removeKeys(entityToken: EntityToken<C>, item: EntityRecord<C>): EntityItem<C>;
|
|
579
|
+
/**
|
|
580
|
+
* Find an index token in a {@link Config | `Config`} object based on the index `hashKey` and `rangeKey`.
|
|
581
|
+
*
|
|
582
|
+
* @param hashKeyToken - Index hash key.
|
|
583
|
+
* @param rangeKeyToken - Index range key.
|
|
584
|
+
*
|
|
585
|
+
* @returns Index token if found.
|
|
586
|
+
*/
|
|
587
|
+
findIndexToken(hashKeyToken: C['HashKey'] | C['ShardedKeys'], rangeKeyToken: C['RangeKey'] | C['UnshardedKeys'] | C['TranscodedProperties']): string | undefined;
|
|
579
588
|
/**
|
|
580
589
|
* Query a database entity across shards in a provider-generic fashion.
|
|
581
590
|
*
|
|
@@ -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 { findIndexToken } from './findIndexToken.js';
|
|
4
5
|
import { configSchema } from './ParsedConfig.js';
|
|
5
6
|
import { query } from './query.js';
|
|
6
7
|
import { removeKeys } from './removeKeys.js';
|
|
@@ -89,6 +90,17 @@ class EntityManager {
|
|
|
89
90
|
removeKeys(entityToken, item) {
|
|
90
91
|
return removeKeys(this, entityToken, item);
|
|
91
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Find an index token in a {@link Config | `Config`} object based on the index `hashKey` and `rangeKey`.
|
|
95
|
+
*
|
|
96
|
+
* @param hashKeyToken - Index hash key.
|
|
97
|
+
* @param rangeKeyToken - Index range key.
|
|
98
|
+
*
|
|
99
|
+
* @returns Index token if found.
|
|
100
|
+
*/
|
|
101
|
+
findIndexToken(hashKeyToken, rangeKeyToken) {
|
|
102
|
+
return findIndexToken(this, hashKeyToken, rangeKeyToken);
|
|
103
|
+
}
|
|
92
104
|
/**
|
|
93
105
|
* Query a database entity across shards in a provider-generic fashion.
|
|
94
106
|
*
|
package/dist/mjs/ParsedConfig.js
CHANGED
|
@@ -234,6 +234,7 @@ const configSchema = z
|
|
|
234
234
|
path: ['generatedProperties', 'unsharded', property],
|
|
235
235
|
});
|
|
236
236
|
// Validate indexes.
|
|
237
|
+
// TODO: Vaidate no two indexes have the same hashKey & rangeKey.
|
|
237
238
|
for (const [indexKey, { hashKey, rangeKey, projections }] of Object.entries(data.indexes)) {
|
|
238
239
|
// Validate hash key is sharded.
|
|
239
240
|
if (![data.hashKey, ...shardedKeys].includes(hashKey)) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Find an index token in a {@link Config | `Config`} object based on the index `hashKey` and `rangeKey`.
|
|
3
|
+
*
|
|
4
|
+
* @param entityManager - {@link EntityManager | `EntityManager`} instance.
|
|
5
|
+
* @param hashKeyToken - Index hash key.
|
|
6
|
+
* @param rangeKeyToken - Index range key.
|
|
7
|
+
*
|
|
8
|
+
* @returns Index token if found.
|
|
9
|
+
*/
|
|
10
|
+
function findIndexToken(entityManager, hashKeyToken, rangeKeyToken) {
|
|
11
|
+
return Object.entries(entityManager.config.indexes).find(([, index]) => index.hashKey === hashKeyToken && index.rangeKey === rangeKeyToken)?.[0];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { findIndexToken };
|
package/package.json
CHANGED