@karmaniverous/entity-manager 6.13.3 → 6.14.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 → EntityManager/EntityManager.js} +18 -44
- package/dist/cjs/EntityManager/getPrimaryKey.js +25 -0
- package/dist/cjs/index.js +5 -3
- package/dist/index.d.ts +114 -66
- package/dist/mjs/{EntityManager.js → EntityManager/EntityManager.js} +18 -44
- package/dist/mjs/EntityManager/getPrimaryKey.js +23 -0
- package/dist/mjs/index.js +4 -3
- package/package.json +2 -2
- /package/dist/cjs/{BaseEntityClient.js → BaseEntityClient/BaseEntityClient.js} +0 -0
- /package/dist/cjs/{BaseQueryBuilder.js → BaseQueryBuilder/BaseQueryBuilder.js} +0 -0
- /package/dist/cjs/{ParsedConfig.js → EntityManager/ParsedConfig.js} +0 -0
- /package/dist/cjs/{addKeys.js → EntityManager/addKeys.js} +0 -0
- /package/dist/cjs/{decodeElement.js → EntityManager/decodeElement.js} +0 -0
- /package/dist/cjs/{decodeGeneratedProperty.js → EntityManager/decodeGeneratedProperty.js} +0 -0
- /package/dist/cjs/{dehydrateIndexItem.js → EntityManager/dehydrateIndexItem.js} +0 -0
- /package/dist/cjs/{dehydratePageKeyMap.js → EntityManager/dehydratePageKeyMap.js} +0 -0
- /package/dist/cjs/{encodeElement.js → EntityManager/encodeElement.js} +0 -0
- /package/dist/cjs/{encodeGeneratedProperty.js → EntityManager/encodeGeneratedProperty.js} +0 -0
- /package/dist/cjs/{findIndexToken.js → EntityManager/findIndexToken.js} +0 -0
- /package/dist/cjs/{getHashKeySpace.js → EntityManager/getHashKeySpace.js} +0 -0
- /package/dist/cjs/{getIndexComponents.js → EntityManager/getIndexComponents.js} +0 -0
- /package/dist/cjs/{getShardBump.js → EntityManager/getShardBump.js} +0 -0
- /package/dist/cjs/{query.js → EntityManager/query.js} +0 -0
- /package/dist/cjs/{rehydrateIndexItem.js → EntityManager/rehydrateIndexItem.js} +0 -0
- /package/dist/cjs/{rehydratePageKeyMap.js → EntityManager/rehydratePageKeyMap.js} +0 -0
- /package/dist/cjs/{removeKeys.js → EntityManager/removeKeys.js} +0 -0
- /package/dist/cjs/{unwrapIndex.js → EntityManager/unwrapIndex.js} +0 -0
- /package/dist/cjs/{updateItemHashKey.js → EntityManager/updateItemHashKey.js} +0 -0
- /package/dist/cjs/{updateItemRangeKey.js → EntityManager/updateItemRangeKey.js} +0 -0
- /package/dist/cjs/{validateEntityToken.js → EntityManager/validateEntityToken.js} +0 -0
- /package/dist/cjs/{validateGeneratedProperty.js → EntityManager/validateGeneratedProperty.js} +0 -0
- /package/dist/cjs/{validateIndexToken.js → EntityManager/validateIndexToken.js} +0 -0
- /package/dist/cjs/{validateTranscodedProperty.js → EntityManager/validateTranscodedProperty.js} +0 -0
- /package/dist/mjs/{BaseEntityClient.js → BaseEntityClient/BaseEntityClient.js} +0 -0
- /package/dist/mjs/{BaseQueryBuilder.js → BaseQueryBuilder/BaseQueryBuilder.js} +0 -0
- /package/dist/mjs/{ParsedConfig.js → EntityManager/ParsedConfig.js} +0 -0
- /package/dist/mjs/{addKeys.js → EntityManager/addKeys.js} +0 -0
- /package/dist/mjs/{decodeElement.js → EntityManager/decodeElement.js} +0 -0
- /package/dist/mjs/{decodeGeneratedProperty.js → EntityManager/decodeGeneratedProperty.js} +0 -0
- /package/dist/mjs/{dehydrateIndexItem.js → EntityManager/dehydrateIndexItem.js} +0 -0
- /package/dist/mjs/{dehydratePageKeyMap.js → EntityManager/dehydratePageKeyMap.js} +0 -0
- /package/dist/mjs/{encodeElement.js → EntityManager/encodeElement.js} +0 -0
- /package/dist/mjs/{encodeGeneratedProperty.js → EntityManager/encodeGeneratedProperty.js} +0 -0
- /package/dist/mjs/{findIndexToken.js → EntityManager/findIndexToken.js} +0 -0
- /package/dist/mjs/{getHashKeySpace.js → EntityManager/getHashKeySpace.js} +0 -0
- /package/dist/mjs/{getIndexComponents.js → EntityManager/getIndexComponents.js} +0 -0
- /package/dist/mjs/{getShardBump.js → EntityManager/getShardBump.js} +0 -0
- /package/dist/mjs/{query.js → EntityManager/query.js} +0 -0
- /package/dist/mjs/{rehydrateIndexItem.js → EntityManager/rehydrateIndexItem.js} +0 -0
- /package/dist/mjs/{rehydratePageKeyMap.js → EntityManager/rehydratePageKeyMap.js} +0 -0
- /package/dist/mjs/{removeKeys.js → EntityManager/removeKeys.js} +0 -0
- /package/dist/mjs/{unwrapIndex.js → EntityManager/unwrapIndex.js} +0 -0
- /package/dist/mjs/{updateItemHashKey.js → EntityManager/updateItemHashKey.js} +0 -0
- /package/dist/mjs/{updateItemRangeKey.js → EntityManager/updateItemRangeKey.js} +0 -0
- /package/dist/mjs/{validateEntityToken.js → EntityManager/validateEntityToken.js} +0 -0
- /package/dist/mjs/{validateGeneratedProperty.js → EntityManager/validateGeneratedProperty.js} +0 -0
- /package/dist/mjs/{validateIndexToken.js → EntityManager/validateIndexToken.js} +0 -0
- /package/dist/mjs/{validateTranscodedProperty.js → EntityManager/validateTranscodedProperty.js} +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var tslib = require('tslib');
|
|
4
|
-
var radash = require('radash');
|
|
5
4
|
var addKeys = require('./addKeys.js');
|
|
6
5
|
var encodeGeneratedProperty = require('./encodeGeneratedProperty.js');
|
|
7
6
|
var findIndexToken = require('./findIndexToken.js');
|
|
7
|
+
var getPrimaryKey = require('./getPrimaryKey.js');
|
|
8
8
|
var ParsedConfig = require('./ParsedConfig.js');
|
|
9
9
|
var query = require('./query.js');
|
|
10
10
|
var removeKeys = require('./removeKeys.js');
|
|
@@ -52,59 +52,33 @@ class EntityManager {
|
|
|
52
52
|
/**
|
|
53
53
|
* Encode a generated property value. Returns a string or undefined if atomicity requirement of sharded properties not met.
|
|
54
54
|
*
|
|
55
|
-
* @param property - {@link Config
|
|
55
|
+
* @param property - {@link Config | Config} `generatedProperties` key.
|
|
56
56
|
* @param item - {@link EntityItem | `EntityItem`} object.
|
|
57
57
|
*
|
|
58
58
|
* @returns Encoded generated property value.
|
|
59
59
|
*
|
|
60
|
-
* @throws `Error` if `property` is not a {@link Config
|
|
60
|
+
* @throws `Error` if `property` is not a {@link Config | Config} `generatedProperties` key.
|
|
61
61
|
*/
|
|
62
62
|
encodeGeneratedProperty(property, item) {
|
|
63
63
|
return encodeGeneratedProperty.encodeGeneratedProperty(this, property, item);
|
|
64
64
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
* @param overwrite - Overwrite existing properties (default `false`).
|
|
71
|
-
*
|
|
72
|
-
* @returns {@link EntityRecord | `EntityRecord`} object with updated properties.
|
|
73
|
-
*
|
|
74
|
-
* @throws `Error` if `entityToken` is invalid.
|
|
75
|
-
*/
|
|
76
|
-
addKeys(entityToken, item, overwrite = false) {
|
|
77
|
-
return addKeys.addKeys(this, entityToken, item, overwrite);
|
|
65
|
+
addKeys(entityToken, i, overwrite = false) {
|
|
66
|
+
if (Array.isArray(i)) {
|
|
67
|
+
return i.map((item) => addKeys.addKeys(this, entityToken, item, overwrite));
|
|
68
|
+
}
|
|
69
|
+
return addKeys.addKeys(this, entityToken, i, overwrite);
|
|
78
70
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
* @param overwrite - Overwrite existing properties (default `false`).
|
|
85
|
-
*
|
|
86
|
-
* @returns {@link EntityKey | `EntityKey`} extracted from shallow clone of `item` with updated properties.
|
|
87
|
-
*
|
|
88
|
-
* @throws `Error` if `entityToken` is invalid.
|
|
89
|
-
*/
|
|
90
|
-
getPrimaryKey(entityToken, item, overwrite = false) {
|
|
91
|
-
const { hashKey, rangeKey } = this.config;
|
|
92
|
-
return radash.pick(!overwrite && item[hashKey] && item[rangeKey]
|
|
93
|
-
? item
|
|
94
|
-
: addKeys.addKeys(this, entityToken, item, overwrite), [this.config.hashKey, this.config.rangeKey]);
|
|
71
|
+
getPrimaryKey(entityToken, i, overwrite = false) {
|
|
72
|
+
if (Array.isArray(i)) {
|
|
73
|
+
return i.map((item) => getPrimaryKey.getPrimaryKey(this, entityToken, item, overwrite));
|
|
74
|
+
}
|
|
75
|
+
return getPrimaryKey.getPrimaryKey(this, entityToken, i, overwrite);
|
|
95
76
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
*
|
|
102
|
-
* @returns {@link EntityItem | `EntityItem`} with generated properties, hash key & range key removed.
|
|
103
|
-
*
|
|
104
|
-
* @throws `Error` if `entityToken` is invalid.
|
|
105
|
-
*/
|
|
106
|
-
removeKeys(entityToken, item) {
|
|
107
|
-
return removeKeys.removeKeys(this, entityToken, item);
|
|
77
|
+
removeKeys(entityToken, i) {
|
|
78
|
+
if (Array.isArray(i)) {
|
|
79
|
+
return i.map((item) => removeKeys.removeKeys(this, entityToken, item));
|
|
80
|
+
}
|
|
81
|
+
return removeKeys.removeKeys(this, entityToken, i);
|
|
108
82
|
}
|
|
109
83
|
/**
|
|
110
84
|
* Find an index token in a {@link Config | `Config`} object based on the index `hashKey` and `rangeKey`.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var radash = require('radash');
|
|
4
|
+
var addKeys = require('./addKeys.js');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Convert an {@link EntityItem | `EntityItem`} into an {@link EntityKey | `EntityKey`}.
|
|
8
|
+
*
|
|
9
|
+
* @param entityManager - {@link EntityManager | `EntityManager`} instance.
|
|
10
|
+
* @param entityToken - {@link Config | `Config`} `entities` key.
|
|
11
|
+
* @param item - {@link EntityItem | `EntityItem`} object.
|
|
12
|
+
* @param overwrite - Overwrite existing properties (default `false`).
|
|
13
|
+
*
|
|
14
|
+
* @returns {@link EntityKey | `EntityKey`} extracted from shallow clone of `item` with updated properties.
|
|
15
|
+
*
|
|
16
|
+
* @throws `Error` if `entityToken` is invalid.
|
|
17
|
+
*/
|
|
18
|
+
function getPrimaryKey(entityManager, entityToken, item, overwrite = false) {
|
|
19
|
+
const { hashKey, rangeKey } = entityManager.config;
|
|
20
|
+
return radash.pick(!overwrite && item[hashKey] && item[rangeKey]
|
|
21
|
+
? item
|
|
22
|
+
: addKeys.addKeys(entityManager, entityToken, item, overwrite), [entityManager.config.hashKey, entityManager.config.rangeKey]);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
exports.getPrimaryKey = getPrimaryKey;
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var BaseEntityClient = require('./BaseEntityClient.js');
|
|
4
|
-
var BaseQueryBuilder = require('./BaseQueryBuilder.js');
|
|
5
|
-
var EntityManager = require('./EntityManager.js');
|
|
3
|
+
var BaseEntityClient = require('./BaseEntityClient/BaseEntityClient.js');
|
|
4
|
+
var BaseQueryBuilder = require('./BaseQueryBuilder/BaseQueryBuilder.js');
|
|
5
|
+
var EntityManager = require('./EntityManager/EntityManager.js');
|
|
6
|
+
var ParsedConfig = require('./EntityManager/ParsedConfig.js');
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
exports.BaseEntityClient = BaseEntityClient.BaseEntityClient;
|
|
10
11
|
exports.BaseQueryBuilder = BaseQueryBuilder.BaseQueryBuilder;
|
|
11
12
|
exports.EntityManager = EntityManager.EntityManager;
|
|
13
|
+
exports.configSchema = ParsedConfig.configSchema;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { EntityMap, TranscodeMap, ConditionalProperty, Exactify, PropertiesOfType, TranscodableProperties, FlattenEntityMap, Transcodes,
|
|
2
|
-
import { BatchProcessOptions } from '@karmaniverous/batch-process';
|
|
1
|
+
import { EntityMap, TranscodeMap, ConditionalProperty, Exactify, PropertiesOfType, TranscodableProperties, FlattenEntityMap, Transcodes, MutuallyExclusive, NotNever, DefaultTranscodeMap, SortOrder } from '@karmaniverous/entity-tools';
|
|
3
2
|
import { z } from 'zod';
|
|
3
|
+
import { BatchProcessOptions } from '@karmaniverous/batch-process';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Default type parameter for {@link ConfigMap | `ConfigMap`}.
|
|
@@ -76,6 +76,47 @@ type Config<C extends BaseConfigMap = BaseConfigMap> = ConditionalProperty<'enti
|
|
|
76
76
|
throttle?: number;
|
|
77
77
|
};
|
|
78
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Validates a type derived from {@link BaseConfigMap | `BaseConfigMap`} to ensure HashKey and RangeKey are both defined and that all sets of special keys are mutually exclusive.
|
|
81
|
+
*
|
|
82
|
+
* @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`}.
|
|
83
|
+
*
|
|
84
|
+
* @category EntityManager
|
|
85
|
+
* @protected
|
|
86
|
+
*/
|
|
87
|
+
type ValidateConfigMap<C extends BaseConfigMap> = MutuallyExclusive<[
|
|
88
|
+
C['HashKey'],
|
|
89
|
+
C['RangeKey'],
|
|
90
|
+
C['ShardedKeys'],
|
|
91
|
+
C['UnshardedKeys'],
|
|
92
|
+
keyof FlattenEntityMap<C['EntityMap']>
|
|
93
|
+
]> extends true ? NotNever<C, ['HashKey' | 'RangeKey']> extends true ? C : Exclude<NotNever<C, ['HashKey' | 'RangeKey']>, true> : Exclude<MutuallyExclusive<[
|
|
94
|
+
C['HashKey'],
|
|
95
|
+
C['RangeKey'],
|
|
96
|
+
C['ShardedKeys'],
|
|
97
|
+
C['UnshardedKeys'],
|
|
98
|
+
keyof FlattenEntityMap<C['EntityMap']>
|
|
99
|
+
]>, true>;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Generates & validates the map defining defines an {@link EntityManager | `EntityManager`} configuration's {@link EntityMap | `EntityMap`}, key properties, and {@link TranscodeMap | `TranscodeMap`}.
|
|
103
|
+
*
|
|
104
|
+
* Unspecified properties will default to those defined in {@link BaseConfigMap | `BaseConfigMap`}.
|
|
105
|
+
*
|
|
106
|
+
* @typeParam M - {@link BaseConfigMap | `BaseConfigMap`} extension. If omitted, defaults to {@link BaseConfigMap | `BaseConfigMap`}.
|
|
107
|
+
*
|
|
108
|
+
* @category EntityManager
|
|
109
|
+
*/
|
|
110
|
+
type ConfigMap<M extends Partial<BaseConfigMap> = Partial<BaseConfigMap>> = ValidateConfigMap<{
|
|
111
|
+
EntityMap: 'EntityMap' extends keyof M ? NonNullable<M['EntityMap']> : Record<string, never>;
|
|
112
|
+
HashKey: 'HashKey' extends keyof M ? NonNullable<M['HashKey']> : 'hashKey';
|
|
113
|
+
RangeKey: 'RangeKey' extends keyof M ? NonNullable<M['RangeKey']> : 'rangeKey';
|
|
114
|
+
ShardedKeys: 'ShardedKeys' extends keyof M ? NonNullable<M['ShardedKeys']> : never;
|
|
115
|
+
UnshardedKeys: 'UnshardedKeys' extends keyof M ? NonNullable<M['UnshardedKeys']> : never;
|
|
116
|
+
TranscodedProperties: 'TranscodedProperties' extends keyof M ? NonNullable<M['TranscodedProperties']> : never;
|
|
117
|
+
TranscodeMap: 'TranscodeMap' extends keyof M ? NonNullable<M['TranscodeMap']> : DefaultTranscodeMap;
|
|
118
|
+
}>;
|
|
119
|
+
|
|
79
120
|
/**
|
|
80
121
|
* Extracts a database-facing partial item type from a {@link BaseConfigMap | `ConfigMap`}.
|
|
81
122
|
*
|
|
@@ -238,6 +279,11 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
238
279
|
sharded: Record<string, [string, ...string[]]>;
|
|
239
280
|
unsharded: Record<string, [string, ...string[]]>;
|
|
240
281
|
};
|
|
282
|
+
propertyTranscodes: Record<string, string>;
|
|
283
|
+
transcodes: Record<string, {
|
|
284
|
+
encode: (args_0: any, ...args: unknown[]) => string;
|
|
285
|
+
decode: (args_0: string, ...args: unknown[]) => any;
|
|
286
|
+
}>;
|
|
241
287
|
indexes: Record<string, {
|
|
242
288
|
hashKey: string;
|
|
243
289
|
rangeKey: string;
|
|
@@ -245,13 +291,8 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
245
291
|
}>;
|
|
246
292
|
generatedKeyDelimiter: string;
|
|
247
293
|
generatedValueDelimiter: string;
|
|
248
|
-
propertyTranscodes: Record<string, string>;
|
|
249
294
|
shardKeyDelimiter: string;
|
|
250
295
|
throttle: number;
|
|
251
|
-
transcodes: Record<string, {
|
|
252
|
-
encode: (args_0: any, ...args: unknown[]) => string;
|
|
253
|
-
decode: (args_0: string, ...args: unknown[]) => any;
|
|
254
|
-
}>;
|
|
255
296
|
}, {
|
|
256
297
|
hashKey: string;
|
|
257
298
|
rangeKey: string;
|
|
@@ -270,6 +311,11 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
270
311
|
sharded?: Record<string, [string, ...string[]]> | undefined;
|
|
271
312
|
unsharded?: Record<string, [string, ...string[]]> | undefined;
|
|
272
313
|
} | undefined;
|
|
314
|
+
propertyTranscodes?: Record<string, string> | undefined;
|
|
315
|
+
transcodes?: Record<string, {
|
|
316
|
+
encode: (args_0: any, ...args: unknown[]) => string;
|
|
317
|
+
decode: (args_0: string, ...args: unknown[]) => any;
|
|
318
|
+
}> | undefined;
|
|
273
319
|
indexes?: Record<string, {
|
|
274
320
|
hashKey: string;
|
|
275
321
|
rangeKey: string;
|
|
@@ -277,13 +323,8 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
277
323
|
}> | undefined;
|
|
278
324
|
generatedKeyDelimiter?: string | undefined;
|
|
279
325
|
generatedValueDelimiter?: string | undefined;
|
|
280
|
-
propertyTranscodes?: Record<string, string> | undefined;
|
|
281
326
|
shardKeyDelimiter?: string | undefined;
|
|
282
327
|
throttle?: number | undefined;
|
|
283
|
-
transcodes?: Record<string, {
|
|
284
|
-
encode: (args_0: any, ...args: unknown[]) => string;
|
|
285
|
-
decode: (args_0: string, ...args: unknown[]) => any;
|
|
286
|
-
}> | undefined;
|
|
287
328
|
}>, {
|
|
288
329
|
hashKey: string;
|
|
289
330
|
rangeKey: string;
|
|
@@ -302,6 +343,11 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
302
343
|
sharded: Record<string, [string, ...string[]]>;
|
|
303
344
|
unsharded: Record<string, [string, ...string[]]>;
|
|
304
345
|
};
|
|
346
|
+
propertyTranscodes: Record<string, string>;
|
|
347
|
+
transcodes: Record<string, {
|
|
348
|
+
encode: (args_0: any, ...args: unknown[]) => string;
|
|
349
|
+
decode: (args_0: string, ...args: unknown[]) => any;
|
|
350
|
+
}>;
|
|
305
351
|
indexes: Record<string, {
|
|
306
352
|
hashKey: string;
|
|
307
353
|
rangeKey: string;
|
|
@@ -309,13 +355,8 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
309
355
|
}>;
|
|
310
356
|
generatedKeyDelimiter: string;
|
|
311
357
|
generatedValueDelimiter: string;
|
|
312
|
-
propertyTranscodes: Record<string, string>;
|
|
313
358
|
shardKeyDelimiter: string;
|
|
314
359
|
throttle: number;
|
|
315
|
-
transcodes: Record<string, {
|
|
316
|
-
encode: (args_0: any, ...args: unknown[]) => string;
|
|
317
|
-
decode: (args_0: string, ...args: unknown[]) => any;
|
|
318
|
-
}>;
|
|
319
360
|
}, {
|
|
320
361
|
hashKey: string;
|
|
321
362
|
rangeKey: string;
|
|
@@ -334,6 +375,11 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
334
375
|
sharded?: Record<string, [string, ...string[]]> | undefined;
|
|
335
376
|
unsharded?: Record<string, [string, ...string[]]> | undefined;
|
|
336
377
|
} | undefined;
|
|
378
|
+
propertyTranscodes?: Record<string, string> | undefined;
|
|
379
|
+
transcodes?: Record<string, {
|
|
380
|
+
encode: (args_0: any, ...args: unknown[]) => string;
|
|
381
|
+
decode: (args_0: string, ...args: unknown[]) => any;
|
|
382
|
+
}> | undefined;
|
|
337
383
|
indexes?: Record<string, {
|
|
338
384
|
hashKey: string;
|
|
339
385
|
rangeKey: string;
|
|
@@ -341,13 +387,8 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
341
387
|
}> | undefined;
|
|
342
388
|
generatedKeyDelimiter?: string | undefined;
|
|
343
389
|
generatedValueDelimiter?: string | undefined;
|
|
344
|
-
propertyTranscodes?: Record<string, string> | undefined;
|
|
345
390
|
shardKeyDelimiter?: string | undefined;
|
|
346
391
|
throttle?: number | undefined;
|
|
347
|
-
transcodes?: Record<string, {
|
|
348
|
-
encode: (args_0: any, ...args: unknown[]) => string;
|
|
349
|
-
decode: (args_0: string, ...args: unknown[]) => any;
|
|
350
|
-
}> | undefined;
|
|
351
392
|
}>;
|
|
352
393
|
/**
|
|
353
394
|
* Simplified type taken on by a {@link Config | `Config`} object after parsing in the {@link EntityManager | `EntityManager`} constructor.
|
|
@@ -521,6 +562,7 @@ interface QueryResult<C extends BaseConfigMap> {
|
|
|
521
562
|
*/
|
|
522
563
|
declare class EntityManager<C extends BaseConfigMap> {
|
|
523
564
|
#private;
|
|
565
|
+
/** Logger object (defaults to `console`, must support `debug` & `error` methods). */
|
|
524
566
|
readonly logger: Pick<Console, 'debug' | 'error'>;
|
|
525
567
|
/**
|
|
526
568
|
* Create an EntityManager instance.
|
|
@@ -544,12 +586,12 @@ declare class EntityManager<C extends BaseConfigMap> {
|
|
|
544
586
|
/**
|
|
545
587
|
* Encode a generated property value. Returns a string or undefined if atomicity requirement of sharded properties not met.
|
|
546
588
|
*
|
|
547
|
-
* @param property - {@link Config
|
|
589
|
+
* @param property - {@link Config | Config} `generatedProperties` key.
|
|
548
590
|
* @param item - {@link EntityItem | `EntityItem`} object.
|
|
549
591
|
*
|
|
550
592
|
* @returns Encoded generated property value.
|
|
551
593
|
*
|
|
552
|
-
* @throws `Error` if `property` is not a {@link Config
|
|
594
|
+
* @throws `Error` if `property` is not a {@link Config | Config} `generatedProperties` key.
|
|
553
595
|
*/
|
|
554
596
|
encodeGeneratedProperty<C extends BaseConfigMap>(property: C['ShardedKeys'] | C['UnshardedKeys'], item: EntityItem<C>): string | undefined;
|
|
555
597
|
/**
|
|
@@ -562,8 +604,24 @@ declare class EntityManager<C extends BaseConfigMap> {
|
|
|
562
604
|
* @returns {@link EntityRecord | `EntityRecord`} object with updated properties.
|
|
563
605
|
*
|
|
564
606
|
* @throws `Error` if `entityToken` is invalid.
|
|
607
|
+
*
|
|
608
|
+
* @overload
|
|
565
609
|
*/
|
|
566
610
|
addKeys(entityToken: EntityToken<C>, item: EntityItem<C>, overwrite?: boolean): EntityRecord<C>;
|
|
611
|
+
/**
|
|
612
|
+
* Update generated properties, hash key, and range key on an array of {@link EntityItem | `EntityItem`} objects.
|
|
613
|
+
*
|
|
614
|
+
* @param entityToken - {@link Config | `Config`} `entities` key.
|
|
615
|
+
* @param items - Array of {@link EntityItem | `EntityItem`} objects.
|
|
616
|
+
* @param overwrite - Overwrite existing properties (default `false`).
|
|
617
|
+
*
|
|
618
|
+
* @returns An array of {@link EntityRecord | `EntityRecord`} objects with updated properties.
|
|
619
|
+
*
|
|
620
|
+
* @throws `Error` if `entityToken` is invalid.
|
|
621
|
+
*
|
|
622
|
+
* @overload
|
|
623
|
+
*/
|
|
624
|
+
addKeys(entityToken: EntityToken<C>, item: EntityItem<C>[], overwrite?: boolean): EntityRecord<C>[];
|
|
567
625
|
/**
|
|
568
626
|
* Convert an {@link EntityItem | `EntityItem`} into an {@link EntityKey | `EntityKey`}.
|
|
569
627
|
*
|
|
@@ -574,8 +632,24 @@ declare class EntityManager<C extends BaseConfigMap> {
|
|
|
574
632
|
* @returns {@link EntityKey | `EntityKey`} extracted from shallow clone of `item` with updated properties.
|
|
575
633
|
*
|
|
576
634
|
* @throws `Error` if `entityToken` is invalid.
|
|
635
|
+
*
|
|
636
|
+
* @overload
|
|
577
637
|
*/
|
|
578
638
|
getPrimaryKey(entityToken: EntityToken<C>, item: EntityItem<C>, overwrite?: boolean): EntityKey<C>;
|
|
639
|
+
/**
|
|
640
|
+
* Convert an array of {@link EntityItem | `EntityItem`} objects into {@link EntityKey | `EntityKey`} objects.
|
|
641
|
+
*
|
|
642
|
+
* @param entityToken - {@link Config | `Config`} `entities` key.
|
|
643
|
+
* @param items - Array of {@link EntityItem | `EntityItem`} objects.
|
|
644
|
+
* @param overwrite - Overwrite existing properties (default `false`).
|
|
645
|
+
*
|
|
646
|
+
* @returns An array of {@link EntityKey | `EntityKey`} objects extracted from shallow clone of each `item` with updated properties.
|
|
647
|
+
*
|
|
648
|
+
* @throws `Error` if `entityToken` is invalid.
|
|
649
|
+
*
|
|
650
|
+
* @overload
|
|
651
|
+
*/
|
|
652
|
+
getPrimaryKey(entityToken: EntityToken<C>, items: EntityItem<C>[], overwrite?: boolean): EntityKey<C>[];
|
|
579
653
|
/**
|
|
580
654
|
* Strips generated properties, hash key, and range key from an {@link EntityRecord | `EntityRecord`} object.
|
|
581
655
|
*
|
|
@@ -585,8 +659,23 @@ declare class EntityManager<C extends BaseConfigMap> {
|
|
|
585
659
|
* @returns {@link EntityItem | `EntityItem`} with generated properties, hash key & range key removed.
|
|
586
660
|
*
|
|
587
661
|
* @throws `Error` if `entityToken` is invalid.
|
|
662
|
+
*
|
|
663
|
+
* @overload
|
|
588
664
|
*/
|
|
589
665
|
removeKeys(entityToken: EntityToken<C>, item: EntityRecord<C>): EntityItem<C>;
|
|
666
|
+
/**
|
|
667
|
+
* Strips generated properties, hash key, and range key from an array of {@link EntityRecord | `EntityRecord`} objects.
|
|
668
|
+
*
|
|
669
|
+
* @param entityToken - {@link Config | `Config`} `entities` key.
|
|
670
|
+
* @param items - Array of {@link EntityRecord | `EntityRecord`} objects.
|
|
671
|
+
*
|
|
672
|
+
* @returns Array of {@link EntityItem | `EntityItem`} objects with generated properties, hash key & range key removed.
|
|
673
|
+
*
|
|
674
|
+
* @throws `Error` if `entityToken` is invalid.
|
|
675
|
+
*
|
|
676
|
+
* @overload
|
|
677
|
+
*/
|
|
678
|
+
removeKeys(entityToken: EntityToken<C>, items: EntityRecord<C>[]): EntityItem<C>[];
|
|
590
679
|
/**
|
|
591
680
|
* Find an index token in a {@link Config | `Config`} object based on the index `hashKey` and `rangeKey`.
|
|
592
681
|
*
|
|
@@ -728,45 +817,4 @@ declare abstract class BaseQueryBuilder<C extends BaseConfigMap, EntityClient ex
|
|
|
728
817
|
query(options: QueryBuilderQueryOptions<C>): Promise<QueryResult<C>>;
|
|
729
818
|
}
|
|
730
819
|
|
|
731
|
-
|
|
732
|
-
* Validates a type derived from {@link BaseConfigMap | `BaseConfigMap`} to ensure HashKey and RangeKey are both defined and that all sets of special keys are mutually exclusive.
|
|
733
|
-
*
|
|
734
|
-
* @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`}.
|
|
735
|
-
*
|
|
736
|
-
* @category EntityManager
|
|
737
|
-
* @protected
|
|
738
|
-
*/
|
|
739
|
-
type ValidateConfigMap<C extends BaseConfigMap> = MutuallyExclusive<[
|
|
740
|
-
C['HashKey'],
|
|
741
|
-
C['RangeKey'],
|
|
742
|
-
C['ShardedKeys'],
|
|
743
|
-
C['UnshardedKeys'],
|
|
744
|
-
keyof FlattenEntityMap<C['EntityMap']>
|
|
745
|
-
]> extends true ? NotNever<C, ['HashKey' | 'RangeKey']> extends true ? C : Exclude<NotNever<C, ['HashKey' | 'RangeKey']>, true> : Exclude<MutuallyExclusive<[
|
|
746
|
-
C['HashKey'],
|
|
747
|
-
C['RangeKey'],
|
|
748
|
-
C['ShardedKeys'],
|
|
749
|
-
C['UnshardedKeys'],
|
|
750
|
-
keyof FlattenEntityMap<C['EntityMap']>
|
|
751
|
-
]>, true>;
|
|
752
|
-
|
|
753
|
-
/**
|
|
754
|
-
* Generates & validates the map defining defines an {@link EntityManager | `EntityManager`} configuration's {@link EntityMap | `EntityMap`}, key properties, and {@link TranscodeMap | `TranscodeMap`}.
|
|
755
|
-
*
|
|
756
|
-
* Unspecified properties will default to those defined in {@link BaseConfigMap | `BaseConfigMap`}.
|
|
757
|
-
*
|
|
758
|
-
* @typeParam M - {@link BaseConfigMap | `BaseConfigMap`} extension. If omitted, defaults to {@link BaseConfigMap | `BaseConfigMap`}.
|
|
759
|
-
*
|
|
760
|
-
* @category EntityManager
|
|
761
|
-
*/
|
|
762
|
-
type ConfigMap<M extends Partial<BaseConfigMap> = Partial<BaseConfigMap>> = ValidateConfigMap<{
|
|
763
|
-
EntityMap: 'EntityMap' extends keyof M ? NonNullable<M['EntityMap']> : Record<string, never>;
|
|
764
|
-
HashKey: 'HashKey' extends keyof M ? NonNullable<M['HashKey']> : 'hashKey';
|
|
765
|
-
RangeKey: 'RangeKey' extends keyof M ? NonNullable<M['RangeKey']> : 'rangeKey';
|
|
766
|
-
ShardedKeys: 'ShardedKeys' extends keyof M ? NonNullable<M['ShardedKeys']> : never;
|
|
767
|
-
UnshardedKeys: 'UnshardedKeys' extends keyof M ? NonNullable<M['UnshardedKeys']> : never;
|
|
768
|
-
TranscodedProperties: 'TranscodedProperties' extends keyof M ? NonNullable<M['TranscodedProperties']> : never;
|
|
769
|
-
TranscodeMap: 'TranscodeMap' extends keyof M ? NonNullable<M['TranscodeMap']> : DefaultTranscodeMap;
|
|
770
|
-
}>;
|
|
771
|
-
|
|
772
|
-
export { type BaseConfigMap, BaseEntityClient, type BaseEntityClientOptions, BaseQueryBuilder, type BaseQueryBuilderOptions, type Config, type ConfigMap, type EntityItem, type EntityKey, EntityManager, type EntityRecord, type EntityToken, type PageKey, type ParsedConfig, type QueryBuilderQueryOptions, type QueryOptions, type QueryResult, type ShardBump, type ShardQueryFunction, type ShardQueryMap, type ShardQueryResult, type ValidateConfigMap };
|
|
820
|
+
export { type BaseConfigMap, BaseEntityClient, type BaseEntityClientOptions, BaseQueryBuilder, type BaseQueryBuilderOptions, type Config, type ConfigMap, type EntityItem, type EntityKey, EntityManager, type EntityRecord, type EntityToken, type PageKey, type ParsedConfig, type QueryBuilderQueryOptions, type QueryOptions, type QueryResult, type ShardBump, type ShardQueryFunction, type ShardQueryMap, type ShardQueryResult, type ValidateConfigMap, configSchema };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { __classPrivateFieldSet, __classPrivateFieldGet } from 'tslib';
|
|
2
|
-
import { pick } from 'radash';
|
|
3
2
|
import { addKeys } from './addKeys.js';
|
|
4
3
|
import { encodeGeneratedProperty } from './encodeGeneratedProperty.js';
|
|
5
4
|
import { findIndexToken } from './findIndexToken.js';
|
|
5
|
+
import { getPrimaryKey } from './getPrimaryKey.js';
|
|
6
6
|
import { configSchema } from './ParsedConfig.js';
|
|
7
7
|
import { query } from './query.js';
|
|
8
8
|
import { removeKeys } from './removeKeys.js';
|
|
@@ -50,59 +50,33 @@ class EntityManager {
|
|
|
50
50
|
/**
|
|
51
51
|
* Encode a generated property value. Returns a string or undefined if atomicity requirement of sharded properties not met.
|
|
52
52
|
*
|
|
53
|
-
* @param property - {@link Config
|
|
53
|
+
* @param property - {@link Config | Config} `generatedProperties` key.
|
|
54
54
|
* @param item - {@link EntityItem | `EntityItem`} object.
|
|
55
55
|
*
|
|
56
56
|
* @returns Encoded generated property value.
|
|
57
57
|
*
|
|
58
|
-
* @throws `Error` if `property` is not a {@link Config
|
|
58
|
+
* @throws `Error` if `property` is not a {@link Config | Config} `generatedProperties` key.
|
|
59
59
|
*/
|
|
60
60
|
encodeGeneratedProperty(property, item) {
|
|
61
61
|
return encodeGeneratedProperty(this, property, item);
|
|
62
62
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
* @param overwrite - Overwrite existing properties (default `false`).
|
|
69
|
-
*
|
|
70
|
-
* @returns {@link EntityRecord | `EntityRecord`} object with updated properties.
|
|
71
|
-
*
|
|
72
|
-
* @throws `Error` if `entityToken` is invalid.
|
|
73
|
-
*/
|
|
74
|
-
addKeys(entityToken, item, overwrite = false) {
|
|
75
|
-
return addKeys(this, entityToken, item, overwrite);
|
|
63
|
+
addKeys(entityToken, i, overwrite = false) {
|
|
64
|
+
if (Array.isArray(i)) {
|
|
65
|
+
return i.map((item) => addKeys(this, entityToken, item, overwrite));
|
|
66
|
+
}
|
|
67
|
+
return addKeys(this, entityToken, i, overwrite);
|
|
76
68
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
* @param overwrite - Overwrite existing properties (default `false`).
|
|
83
|
-
*
|
|
84
|
-
* @returns {@link EntityKey | `EntityKey`} extracted from shallow clone of `item` with updated properties.
|
|
85
|
-
*
|
|
86
|
-
* @throws `Error` if `entityToken` is invalid.
|
|
87
|
-
*/
|
|
88
|
-
getPrimaryKey(entityToken, item, overwrite = false) {
|
|
89
|
-
const { hashKey, rangeKey } = this.config;
|
|
90
|
-
return pick(!overwrite && item[hashKey] && item[rangeKey]
|
|
91
|
-
? item
|
|
92
|
-
: addKeys(this, entityToken, item, overwrite), [this.config.hashKey, this.config.rangeKey]);
|
|
69
|
+
getPrimaryKey(entityToken, i, overwrite = false) {
|
|
70
|
+
if (Array.isArray(i)) {
|
|
71
|
+
return i.map((item) => getPrimaryKey(this, entityToken, item, overwrite));
|
|
72
|
+
}
|
|
73
|
+
return getPrimaryKey(this, entityToken, i, overwrite);
|
|
93
74
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
*
|
|
100
|
-
* @returns {@link EntityItem | `EntityItem`} with generated properties, hash key & range key removed.
|
|
101
|
-
*
|
|
102
|
-
* @throws `Error` if `entityToken` is invalid.
|
|
103
|
-
*/
|
|
104
|
-
removeKeys(entityToken, item) {
|
|
105
|
-
return removeKeys(this, entityToken, item);
|
|
75
|
+
removeKeys(entityToken, i) {
|
|
76
|
+
if (Array.isArray(i)) {
|
|
77
|
+
return i.map((item) => removeKeys(this, entityToken, item));
|
|
78
|
+
}
|
|
79
|
+
return removeKeys(this, entityToken, i);
|
|
106
80
|
}
|
|
107
81
|
/**
|
|
108
82
|
* Find an index token in a {@link Config | `Config`} object based on the index `hashKey` and `rangeKey`.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { pick } from 'radash';
|
|
2
|
+
import { addKeys } from './addKeys.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Convert an {@link EntityItem | `EntityItem`} into an {@link EntityKey | `EntityKey`}.
|
|
6
|
+
*
|
|
7
|
+
* @param entityManager - {@link EntityManager | `EntityManager`} instance.
|
|
8
|
+
* @param entityToken - {@link Config | `Config`} `entities` key.
|
|
9
|
+
* @param item - {@link EntityItem | `EntityItem`} object.
|
|
10
|
+
* @param overwrite - Overwrite existing properties (default `false`).
|
|
11
|
+
*
|
|
12
|
+
* @returns {@link EntityKey | `EntityKey`} extracted from shallow clone of `item` with updated properties.
|
|
13
|
+
*
|
|
14
|
+
* @throws `Error` if `entityToken` is invalid.
|
|
15
|
+
*/
|
|
16
|
+
function getPrimaryKey(entityManager, entityToken, item, overwrite = false) {
|
|
17
|
+
const { hashKey, rangeKey } = entityManager.config;
|
|
18
|
+
return pick(!overwrite && item[hashKey] && item[rangeKey]
|
|
19
|
+
? item
|
|
20
|
+
: addKeys(entityManager, entityToken, item, overwrite), [entityManager.config.hashKey, entityManager.config.rangeKey]);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { getPrimaryKey };
|
package/dist/mjs/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { BaseEntityClient } from './BaseEntityClient.js';
|
|
2
|
-
export { BaseQueryBuilder } from './BaseQueryBuilder.js';
|
|
3
|
-
export { EntityManager } from './EntityManager.js';
|
|
1
|
+
export { BaseEntityClient } from './BaseEntityClient/BaseEntityClient.js';
|
|
2
|
+
export { BaseQueryBuilder } from './BaseQueryBuilder/BaseQueryBuilder.js';
|
|
3
|
+
export { EntityManager } from './EntityManager/EntityManager.js';
|
|
4
|
+
export { configSchema } from './EntityManager/ParsedConfig.js';
|
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.8",
|
|
9
9
|
"@karmaniverous/string-utilities": "^0.2.1",
|
|
10
10
|
"lz-string": "^1.5.0",
|
|
11
11
|
"radash": "^12.1.0",
|
|
@@ -132,5 +132,5 @@
|
|
|
132
132
|
},
|
|
133
133
|
"type": "module",
|
|
134
134
|
"types": "dist/index.d.ts",
|
|
135
|
-
"version": "6.
|
|
135
|
+
"version": "6.14.0"
|
|
136
136
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/cjs/{validateGeneratedProperty.js → EntityManager/validateGeneratedProperty.js}
RENAMED
|
File without changes
|
|
File without changes
|
/package/dist/cjs/{validateTranscodedProperty.js → EntityManager/validateTranscodedProperty.js}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/mjs/{validateGeneratedProperty.js → EntityManager/validateGeneratedProperty.js}
RENAMED
|
File without changes
|
|
File without changes
|
/package/dist/mjs/{validateTranscodedProperty.js → EntityManager/validateTranscodedProperty.js}
RENAMED
|
File without changes
|