@karmaniverous/entity-manager 6.13.3 → 6.14.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/README.md +330 -16
- package/dist/cjs/{EntityManager.js → EntityManager/EntityManager.js} +18 -44
- package/dist/cjs/{ParsedConfig.js → EntityManager/ParsedConfig.js} +46 -55
- package/dist/cjs/{addKeys.js → EntityManager/addKeys.js} +1 -0
- package/dist/cjs/{decodeElement.js → EntityManager/decodeElement.js} +2 -1
- package/dist/cjs/{dehydratePageKeyMap.js → EntityManager/dehydratePageKeyMap.js} +3 -1
- package/dist/cjs/{encodeElement.js → EntityManager/encodeElement.js} +2 -2
- package/dist/cjs/{encodeGeneratedProperty.js → EntityManager/encodeGeneratedProperty.js} +1 -1
- package/dist/cjs/EntityManager/getPrimaryKey.js +25 -0
- package/dist/cjs/{rehydratePageKeyMap.js → EntityManager/rehydratePageKeyMap.js} +3 -1
- package/dist/cjs/{removeKeys.js → EntityManager/removeKeys.js} +10 -8
- package/dist/cjs/{updateItemHashKey.js → EntityManager/updateItemHashKey.js} +4 -1
- package/dist/cjs/index.js +5 -3
- package/dist/index.d.ts +109 -252
- package/dist/mjs/{EntityManager.js → EntityManager/EntityManager.js} +18 -44
- package/dist/mjs/{ParsedConfig.js → EntityManager/ParsedConfig.js} +46 -55
- package/dist/mjs/{addKeys.js → EntityManager/addKeys.js} +1 -0
- package/dist/mjs/{decodeElement.js → EntityManager/decodeElement.js} +2 -1
- package/dist/mjs/{dehydratePageKeyMap.js → EntityManager/dehydratePageKeyMap.js} +3 -1
- package/dist/mjs/{encodeElement.js → EntityManager/encodeElement.js} +2 -2
- package/dist/mjs/{encodeGeneratedProperty.js → EntityManager/encodeGeneratedProperty.js} +1 -1
- package/dist/mjs/EntityManager/getPrimaryKey.js +23 -0
- package/dist/mjs/{rehydratePageKeyMap.js → EntityManager/rehydratePageKeyMap.js} +3 -1
- package/dist/mjs/{removeKeys.js → EntityManager/removeKeys.js} +10 -8
- package/dist/mjs/{updateItemHashKey.js → EntityManager/updateItemHashKey.js} +4 -1
- package/dist/mjs/index.js +4 -3
- package/package.json +44 -45
- /package/dist/cjs/{BaseEntityClient.js → BaseEntityClient/BaseEntityClient.js} +0 -0
- /package/dist/cjs/{BaseQueryBuilder.js → BaseQueryBuilder/BaseQueryBuilder.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/{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/{unwrapIndex.js → EntityManager/unwrapIndex.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/{decodeGeneratedProperty.js → EntityManager/decodeGeneratedProperty.js} +0 -0
- /package/dist/mjs/{dehydrateIndexItem.js → EntityManager/dehydrateIndexItem.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/{unwrapIndex.js → EntityManager/unwrapIndex.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
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
|
*
|
|
@@ -116,39 +157,15 @@ type EntityRecord<C extends BaseConfigMap> = EntityItem<C> & EntityKey<C>;
|
|
|
116
157
|
*/
|
|
117
158
|
type EntityToken<C extends BaseConfigMap> = keyof Exactify<C['EntityMap']> & string;
|
|
118
159
|
|
|
119
|
-
declare const configSchema: z.
|
|
160
|
+
declare const configSchema: z.ZodObject<{
|
|
120
161
|
entities: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
121
162
|
defaultLimit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
122
163
|
defaultPageSize: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
123
|
-
shardBumps: z.
|
|
164
|
+
shardBumps: z.ZodPipe<z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
124
165
|
timestamp: z.ZodNumber;
|
|
125
166
|
charBits: z.ZodNumber;
|
|
126
167
|
chars: z.ZodNumber;
|
|
127
|
-
},
|
|
128
|
-
timestamp: number;
|
|
129
|
-
charBits: number;
|
|
130
|
-
chars: number;
|
|
131
|
-
}, {
|
|
132
|
-
timestamp: number;
|
|
133
|
-
charBits: number;
|
|
134
|
-
chars: number;
|
|
135
|
-
}>, "many">>>, {
|
|
136
|
-
timestamp: number;
|
|
137
|
-
charBits: number;
|
|
138
|
-
chars: number;
|
|
139
|
-
}[], {
|
|
140
|
-
timestamp: number;
|
|
141
|
-
charBits: number;
|
|
142
|
-
chars: number;
|
|
143
|
-
}[] | undefined>, {
|
|
144
|
-
timestamp: number;
|
|
145
|
-
charBits: number;
|
|
146
|
-
chars: number;
|
|
147
|
-
}[], {
|
|
148
|
-
timestamp: number;
|
|
149
|
-
charBits: number;
|
|
150
|
-
chars: number;
|
|
151
|
-
}[] | undefined>, {
|
|
168
|
+
}, z.core.$strict>>>>, z.ZodTransform<{
|
|
152
169
|
timestamp: number;
|
|
153
170
|
charBits: number;
|
|
154
171
|
chars: number;
|
|
@@ -156,54 +173,20 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
156
173
|
timestamp: number;
|
|
157
174
|
charBits: number;
|
|
158
175
|
chars: number;
|
|
159
|
-
}[]
|
|
176
|
+
}[]>>;
|
|
160
177
|
timestampProperty: z.ZodString;
|
|
161
178
|
uniqueProperty: z.ZodString;
|
|
162
|
-
},
|
|
163
|
-
defaultLimit: number;
|
|
164
|
-
defaultPageSize: number;
|
|
165
|
-
shardBumps: {
|
|
166
|
-
timestamp: number;
|
|
167
|
-
charBits: number;
|
|
168
|
-
chars: number;
|
|
169
|
-
}[];
|
|
170
|
-
timestampProperty: string;
|
|
171
|
-
uniqueProperty: string;
|
|
172
|
-
}, {
|
|
173
|
-
timestampProperty: string;
|
|
174
|
-
uniqueProperty: string;
|
|
175
|
-
defaultLimit?: number | undefined;
|
|
176
|
-
defaultPageSize?: number | undefined;
|
|
177
|
-
shardBumps?: {
|
|
178
|
-
timestamp: number;
|
|
179
|
-
charBits: number;
|
|
180
|
-
chars: number;
|
|
181
|
-
}[] | undefined;
|
|
182
|
-
}>>>>;
|
|
179
|
+
}, z.core.$strict>>>>;
|
|
183
180
|
generatedProperties: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
184
|
-
sharded: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.
|
|
185
|
-
unsharded: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.
|
|
186
|
-
},
|
|
187
|
-
sharded: Record<string, [string, ...string[]]>;
|
|
188
|
-
unsharded: Record<string, [string, ...string[]]>;
|
|
189
|
-
}, {
|
|
190
|
-
sharded?: Record<string, [string, ...string[]]> | undefined;
|
|
191
|
-
unsharded?: Record<string, [string, ...string[]]> | undefined;
|
|
192
|
-
}>>>;
|
|
181
|
+
sharded: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>>;
|
|
182
|
+
unsharded: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>>;
|
|
183
|
+
}, z.core.$strip>>>;
|
|
193
184
|
hashKey: z.ZodString;
|
|
194
185
|
indexes: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
195
186
|
hashKey: z.ZodString;
|
|
196
187
|
rangeKey: z.ZodString;
|
|
197
|
-
projections: z.ZodOptional<z.
|
|
198
|
-
},
|
|
199
|
-
hashKey: string;
|
|
200
|
-
rangeKey: string;
|
|
201
|
-
projections?: string[] | undefined;
|
|
202
|
-
}, {
|
|
203
|
-
hashKey: string;
|
|
204
|
-
rangeKey: string;
|
|
205
|
-
projections?: string[] | undefined;
|
|
206
|
-
}>>>>;
|
|
188
|
+
projections: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
189
|
+
}, z.core.$strip>>>>;
|
|
207
190
|
generatedKeyDelimiter: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
208
191
|
generatedValueDelimiter: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
209
192
|
propertyTranscodes: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
@@ -211,144 +194,10 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
211
194
|
shardKeyDelimiter: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
212
195
|
throttle: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
213
196
|
transcodes: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
214
|
-
encode: z.
|
|
215
|
-
decode: z.
|
|
216
|
-
},
|
|
217
|
-
|
|
218
|
-
decode: (args_0: string, ...args: unknown[]) => any;
|
|
219
|
-
}, {
|
|
220
|
-
encode: (args_0: any, ...args: unknown[]) => string;
|
|
221
|
-
decode: (args_0: string, ...args: unknown[]) => any;
|
|
222
|
-
}>>>>;
|
|
223
|
-
}, "strict", z.ZodTypeAny, {
|
|
224
|
-
hashKey: string;
|
|
225
|
-
rangeKey: string;
|
|
226
|
-
entities: Record<string, {
|
|
227
|
-
defaultLimit: number;
|
|
228
|
-
defaultPageSize: number;
|
|
229
|
-
shardBumps: {
|
|
230
|
-
timestamp: number;
|
|
231
|
-
charBits: number;
|
|
232
|
-
chars: number;
|
|
233
|
-
}[];
|
|
234
|
-
timestampProperty: string;
|
|
235
|
-
uniqueProperty: string;
|
|
236
|
-
}>;
|
|
237
|
-
generatedProperties: {
|
|
238
|
-
sharded: Record<string, [string, ...string[]]>;
|
|
239
|
-
unsharded: Record<string, [string, ...string[]]>;
|
|
240
|
-
};
|
|
241
|
-
indexes: Record<string, {
|
|
242
|
-
hashKey: string;
|
|
243
|
-
rangeKey: string;
|
|
244
|
-
projections?: string[] | undefined;
|
|
245
|
-
}>;
|
|
246
|
-
generatedKeyDelimiter: string;
|
|
247
|
-
generatedValueDelimiter: string;
|
|
248
|
-
propertyTranscodes: Record<string, string>;
|
|
249
|
-
shardKeyDelimiter: string;
|
|
250
|
-
throttle: number;
|
|
251
|
-
transcodes: Record<string, {
|
|
252
|
-
encode: (args_0: any, ...args: unknown[]) => string;
|
|
253
|
-
decode: (args_0: string, ...args: unknown[]) => any;
|
|
254
|
-
}>;
|
|
255
|
-
}, {
|
|
256
|
-
hashKey: string;
|
|
257
|
-
rangeKey: string;
|
|
258
|
-
entities?: Record<string, {
|
|
259
|
-
timestampProperty: string;
|
|
260
|
-
uniqueProperty: string;
|
|
261
|
-
defaultLimit?: number | undefined;
|
|
262
|
-
defaultPageSize?: number | undefined;
|
|
263
|
-
shardBumps?: {
|
|
264
|
-
timestamp: number;
|
|
265
|
-
charBits: number;
|
|
266
|
-
chars: number;
|
|
267
|
-
}[] | undefined;
|
|
268
|
-
}> | undefined;
|
|
269
|
-
generatedProperties?: {
|
|
270
|
-
sharded?: Record<string, [string, ...string[]]> | undefined;
|
|
271
|
-
unsharded?: Record<string, [string, ...string[]]> | undefined;
|
|
272
|
-
} | undefined;
|
|
273
|
-
indexes?: Record<string, {
|
|
274
|
-
hashKey: string;
|
|
275
|
-
rangeKey: string;
|
|
276
|
-
projections?: string[] | undefined;
|
|
277
|
-
}> | undefined;
|
|
278
|
-
generatedKeyDelimiter?: string | undefined;
|
|
279
|
-
generatedValueDelimiter?: string | undefined;
|
|
280
|
-
propertyTranscodes?: Record<string, string> | undefined;
|
|
281
|
-
shardKeyDelimiter?: string | undefined;
|
|
282
|
-
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
|
-
}>, {
|
|
288
|
-
hashKey: string;
|
|
289
|
-
rangeKey: string;
|
|
290
|
-
entities: Record<string, {
|
|
291
|
-
defaultLimit: number;
|
|
292
|
-
defaultPageSize: number;
|
|
293
|
-
shardBumps: {
|
|
294
|
-
timestamp: number;
|
|
295
|
-
charBits: number;
|
|
296
|
-
chars: number;
|
|
297
|
-
}[];
|
|
298
|
-
timestampProperty: string;
|
|
299
|
-
uniqueProperty: string;
|
|
300
|
-
}>;
|
|
301
|
-
generatedProperties: {
|
|
302
|
-
sharded: Record<string, [string, ...string[]]>;
|
|
303
|
-
unsharded: Record<string, [string, ...string[]]>;
|
|
304
|
-
};
|
|
305
|
-
indexes: Record<string, {
|
|
306
|
-
hashKey: string;
|
|
307
|
-
rangeKey: string;
|
|
308
|
-
projections?: string[] | undefined;
|
|
309
|
-
}>;
|
|
310
|
-
generatedKeyDelimiter: string;
|
|
311
|
-
generatedValueDelimiter: string;
|
|
312
|
-
propertyTranscodes: Record<string, string>;
|
|
313
|
-
shardKeyDelimiter: string;
|
|
314
|
-
throttle: number;
|
|
315
|
-
transcodes: Record<string, {
|
|
316
|
-
encode: (args_0: any, ...args: unknown[]) => string;
|
|
317
|
-
decode: (args_0: string, ...args: unknown[]) => any;
|
|
318
|
-
}>;
|
|
319
|
-
}, {
|
|
320
|
-
hashKey: string;
|
|
321
|
-
rangeKey: string;
|
|
322
|
-
entities?: Record<string, {
|
|
323
|
-
timestampProperty: string;
|
|
324
|
-
uniqueProperty: string;
|
|
325
|
-
defaultLimit?: number | undefined;
|
|
326
|
-
defaultPageSize?: number | undefined;
|
|
327
|
-
shardBumps?: {
|
|
328
|
-
timestamp: number;
|
|
329
|
-
charBits: number;
|
|
330
|
-
chars: number;
|
|
331
|
-
}[] | undefined;
|
|
332
|
-
}> | undefined;
|
|
333
|
-
generatedProperties?: {
|
|
334
|
-
sharded?: Record<string, [string, ...string[]]> | undefined;
|
|
335
|
-
unsharded?: Record<string, [string, ...string[]]> | undefined;
|
|
336
|
-
} | undefined;
|
|
337
|
-
indexes?: Record<string, {
|
|
338
|
-
hashKey: string;
|
|
339
|
-
rangeKey: string;
|
|
340
|
-
projections?: string[] | undefined;
|
|
341
|
-
}> | undefined;
|
|
342
|
-
generatedKeyDelimiter?: string | undefined;
|
|
343
|
-
generatedValueDelimiter?: string | undefined;
|
|
344
|
-
propertyTranscodes?: Record<string, string> | undefined;
|
|
345
|
-
shardKeyDelimiter?: string | undefined;
|
|
346
|
-
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
|
-
}>;
|
|
197
|
+
encode: z.ZodCustom<unknown, unknown>;
|
|
198
|
+
decode: z.ZodCustom<unknown, unknown>;
|
|
199
|
+
}, z.core.$strict>>>>;
|
|
200
|
+
}, z.core.$strict>;
|
|
352
201
|
/**
|
|
353
202
|
* Simplified type taken on by a {@link Config | `Config`} object after parsing in the {@link EntityManager | `EntityManager`} constructor.
|
|
354
203
|
*
|
|
@@ -521,6 +370,7 @@ interface QueryResult<C extends BaseConfigMap> {
|
|
|
521
370
|
*/
|
|
522
371
|
declare class EntityManager<C extends BaseConfigMap> {
|
|
523
372
|
#private;
|
|
373
|
+
/** Logger object (defaults to `console`, must support `debug` & `error` methods). */
|
|
524
374
|
readonly logger: Pick<Console, 'debug' | 'error'>;
|
|
525
375
|
/**
|
|
526
376
|
* Create an EntityManager instance.
|
|
@@ -544,12 +394,12 @@ declare class EntityManager<C extends BaseConfigMap> {
|
|
|
544
394
|
/**
|
|
545
395
|
* Encode a generated property value. Returns a string or undefined if atomicity requirement of sharded properties not met.
|
|
546
396
|
*
|
|
547
|
-
* @param property - {@link Config
|
|
397
|
+
* @param property - {@link Config | Config} `generatedProperties` key.
|
|
548
398
|
* @param item - {@link EntityItem | `EntityItem`} object.
|
|
549
399
|
*
|
|
550
400
|
* @returns Encoded generated property value.
|
|
551
401
|
*
|
|
552
|
-
* @throws `Error` if `property` is not a {@link Config
|
|
402
|
+
* @throws `Error` if `property` is not a {@link Config | Config} `generatedProperties` key.
|
|
553
403
|
*/
|
|
554
404
|
encodeGeneratedProperty<C extends BaseConfigMap>(property: C['ShardedKeys'] | C['UnshardedKeys'], item: EntityItem<C>): string | undefined;
|
|
555
405
|
/**
|
|
@@ -562,8 +412,24 @@ declare class EntityManager<C extends BaseConfigMap> {
|
|
|
562
412
|
* @returns {@link EntityRecord | `EntityRecord`} object with updated properties.
|
|
563
413
|
*
|
|
564
414
|
* @throws `Error` if `entityToken` is invalid.
|
|
415
|
+
*
|
|
416
|
+
* @overload
|
|
565
417
|
*/
|
|
566
418
|
addKeys(entityToken: EntityToken<C>, item: EntityItem<C>, overwrite?: boolean): EntityRecord<C>;
|
|
419
|
+
/**
|
|
420
|
+
* Update generated properties, hash key, and range key on an array of {@link EntityItem | `EntityItem`} objects.
|
|
421
|
+
*
|
|
422
|
+
* @param entityToken - {@link Config | `Config`} `entities` key.
|
|
423
|
+
* @param item - Array of {@link EntityItem | `EntityItem`} objects.
|
|
424
|
+
* @param overwrite - Overwrite existing properties (default `false`).
|
|
425
|
+
*
|
|
426
|
+
* @returns An array of {@link EntityRecord | `EntityRecord`} objects with updated properties.
|
|
427
|
+
*
|
|
428
|
+
* @throws `Error` if `entityToken` is invalid.
|
|
429
|
+
*
|
|
430
|
+
* @overload
|
|
431
|
+
*/
|
|
432
|
+
addKeys(entityToken: EntityToken<C>, item: EntityItem<C>[], overwrite?: boolean): EntityRecord<C>[];
|
|
567
433
|
/**
|
|
568
434
|
* Convert an {@link EntityItem | `EntityItem`} into an {@link EntityKey | `EntityKey`}.
|
|
569
435
|
*
|
|
@@ -574,8 +440,24 @@ declare class EntityManager<C extends BaseConfigMap> {
|
|
|
574
440
|
* @returns {@link EntityKey | `EntityKey`} extracted from shallow clone of `item` with updated properties.
|
|
575
441
|
*
|
|
576
442
|
* @throws `Error` if `entityToken` is invalid.
|
|
443
|
+
*
|
|
444
|
+
* @overload
|
|
577
445
|
*/
|
|
578
446
|
getPrimaryKey(entityToken: EntityToken<C>, item: EntityItem<C>, overwrite?: boolean): EntityKey<C>;
|
|
447
|
+
/**
|
|
448
|
+
* Convert an array of {@link EntityItem | `EntityItem`} objects into {@link EntityKey | `EntityKey`} objects.
|
|
449
|
+
*
|
|
450
|
+
* @param entityToken - {@link Config | `Config`} `entities` key.
|
|
451
|
+
* @param items - Array of {@link EntityItem | `EntityItem`} objects.
|
|
452
|
+
* @param overwrite - Overwrite existing properties (default `false`).
|
|
453
|
+
*
|
|
454
|
+
* @returns An array of {@link EntityKey | `EntityKey`} objects extracted from shallow clone of each `item` with updated properties.
|
|
455
|
+
*
|
|
456
|
+
* @throws `Error` if `entityToken` is invalid.
|
|
457
|
+
*
|
|
458
|
+
* @overload
|
|
459
|
+
*/
|
|
460
|
+
getPrimaryKey(entityToken: EntityToken<C>, items: EntityItem<C>[], overwrite?: boolean): EntityKey<C>[];
|
|
579
461
|
/**
|
|
580
462
|
* Strips generated properties, hash key, and range key from an {@link EntityRecord | `EntityRecord`} object.
|
|
581
463
|
*
|
|
@@ -585,8 +467,23 @@ declare class EntityManager<C extends BaseConfigMap> {
|
|
|
585
467
|
* @returns {@link EntityItem | `EntityItem`} with generated properties, hash key & range key removed.
|
|
586
468
|
*
|
|
587
469
|
* @throws `Error` if `entityToken` is invalid.
|
|
470
|
+
*
|
|
471
|
+
* @overload
|
|
588
472
|
*/
|
|
589
473
|
removeKeys(entityToken: EntityToken<C>, item: EntityRecord<C>): EntityItem<C>;
|
|
474
|
+
/**
|
|
475
|
+
* Strips generated properties, hash key, and range key from an array of {@link EntityRecord | `EntityRecord`} objects.
|
|
476
|
+
*
|
|
477
|
+
* @param entityToken - {@link Config | `Config`} `entities` key.
|
|
478
|
+
* @param items - Array of {@link EntityRecord | `EntityRecord`} objects.
|
|
479
|
+
*
|
|
480
|
+
* @returns Array of {@link EntityItem | `EntityItem`} objects with generated properties, hash key & range key removed.
|
|
481
|
+
*
|
|
482
|
+
* @throws `Error` if `entityToken` is invalid.
|
|
483
|
+
*
|
|
484
|
+
* @overload
|
|
485
|
+
*/
|
|
486
|
+
removeKeys(entityToken: EntityToken<C>, items: EntityRecord<C>[]): EntityItem<C>[];
|
|
590
487
|
/**
|
|
591
488
|
* Find an index token in a {@link Config | `Config`} object based on the index `hashKey` and `rangeKey`.
|
|
592
489
|
*
|
|
@@ -728,45 +625,5 @@ declare abstract class BaseQueryBuilder<C extends BaseConfigMap, EntityClient ex
|
|
|
728
625
|
query(options: QueryBuilderQueryOptions<C>): Promise<QueryResult<C>>;
|
|
729
626
|
}
|
|
730
627
|
|
|
731
|
-
|
|
732
|
-
|
|
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 };
|
|
628
|
+
export { BaseEntityClient, BaseQueryBuilder, EntityManager, configSchema };
|
|
629
|
+
export type { BaseConfigMap, BaseEntityClientOptions, BaseQueryBuilderOptions, Config, ConfigMap, EntityItem, EntityKey, EntityRecord, EntityToken, PageKey, ParsedConfig, QueryBuilderQueryOptions, QueryOptions, QueryResult, ShardBump, ShardQueryFunction, ShardQueryMap, ShardQueryResult, ValidateConfigMap };
|
|
@@ -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`.
|