@karmaniverous/entity-manager 6.13.0 → 6.13.2

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.
@@ -111,11 +111,14 @@ class EntityManager {
111
111
  *
112
112
  * @param hashKeyToken - Index hash key.
113
113
  * @param rangeKeyToken - Index range key.
114
+ * @param suppressError - Suppress error if no match found.
114
115
  *
115
116
  * @returns Index token if found.
117
+ *
118
+ * @throws `Error` if no match found and `suppressError` is not `true`.
116
119
  */
117
- findIndexToken(hashKeyToken, rangeKeyToken) {
118
- return findIndexToken.findIndexToken(this, hashKeyToken, rangeKeyToken);
120
+ findIndexToken(hashKeyToken, rangeKeyToken, suppressError) {
121
+ return findIndexToken.findIndexToken(this, hashKeyToken, rangeKeyToken, suppressError);
119
122
  }
120
123
  /**
121
124
  * Query a database entity across shards in a provider-generic fashion.
@@ -103,7 +103,10 @@ const configSchema = zod.z
103
103
  .record(zod.z.object({
104
104
  hashKey: zod.z.string().min(1),
105
105
  rangeKey: zod.z.string().min(1),
106
- projections: componentArray.optional(),
106
+ projections: zod.z
107
+ .array(zod.z.string().min(1))
108
+ .superRefine(validateArrayUnique)
109
+ .optional(),
107
110
  }))
108
111
  .optional()
109
112
  .default({}),
@@ -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
- return Object.entries(entityManager.config.indexes).find(([, index]) => index.hashKey === hashKeyToken && index.rangeKey === rangeKeyToken)?.[0];
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
@@ -194,15 +194,15 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
194
194
  indexes: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
195
195
  hashKey: z.ZodString;
196
196
  rangeKey: z.ZodString;
197
- projections: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodString, "atleastone">, [string, ...string[]], [string, ...string[]]>>;
197
+ projections: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodString, "many">, string[], string[]>>;
198
198
  }, "strip", z.ZodTypeAny, {
199
199
  hashKey: string;
200
200
  rangeKey: string;
201
- projections?: [string, ...string[]] | undefined;
201
+ projections?: string[] | undefined;
202
202
  }, {
203
203
  hashKey: string;
204
204
  rangeKey: string;
205
- projections?: [string, ...string[]] | undefined;
205
+ projections?: string[] | undefined;
206
206
  }>>>>;
207
207
  generatedKeyDelimiter: z.ZodDefault<z.ZodOptional<z.ZodString>>;
208
208
  generatedValueDelimiter: z.ZodDefault<z.ZodOptional<z.ZodString>>;
@@ -241,7 +241,7 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
241
241
  indexes: Record<string, {
242
242
  hashKey: string;
243
243
  rangeKey: string;
244
- projections?: [string, ...string[]] | undefined;
244
+ projections?: string[] | undefined;
245
245
  }>;
246
246
  generatedKeyDelimiter: string;
247
247
  generatedValueDelimiter: string;
@@ -273,7 +273,7 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
273
273
  indexes?: Record<string, {
274
274
  hashKey: string;
275
275
  rangeKey: string;
276
- projections?: [string, ...string[]] | undefined;
276
+ projections?: string[] | undefined;
277
277
  }> | undefined;
278
278
  generatedKeyDelimiter?: string | undefined;
279
279
  generatedValueDelimiter?: string | undefined;
@@ -305,7 +305,7 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
305
305
  indexes: Record<string, {
306
306
  hashKey: string;
307
307
  rangeKey: string;
308
- projections?: [string, ...string[]] | undefined;
308
+ projections?: string[] | undefined;
309
309
  }>;
310
310
  generatedKeyDelimiter: string;
311
311
  generatedValueDelimiter: string;
@@ -337,7 +337,7 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
337
337
  indexes?: Record<string, {
338
338
  hashKey: string;
339
339
  rangeKey: string;
340
- projections?: [string, ...string[]] | undefined;
340
+ projections?: string[] | undefined;
341
341
  }> | undefined;
342
342
  generatedKeyDelimiter?: string | undefined;
343
343
  generatedValueDelimiter?: string | undefined;
@@ -592,10 +592,13 @@ declare class EntityManager<C extends BaseConfigMap> {
592
592
  *
593
593
  * @param hashKeyToken - Index hash key.
594
594
  * @param rangeKeyToken - Index range key.
595
+ * @param suppressError - Suppress error if no match found.
595
596
  *
596
597
  * @returns Index token if found.
598
+ *
599
+ * @throws `Error` if no match found and `suppressError` is not `true`.
597
600
  */
598
- findIndexToken(hashKeyToken: string, rangeKeyToken: string): string | undefined;
601
+ findIndexToken(hashKeyToken: string, rangeKeyToken: string, suppressError?: boolean): string | undefined;
599
602
  /**
600
603
  * Query a database entity across shards in a provider-generic fashion.
601
604
  *
@@ -109,11 +109,14 @@ class EntityManager {
109
109
  *
110
110
  * @param hashKeyToken - Index hash key.
111
111
  * @param rangeKeyToken - Index range key.
112
+ * @param suppressError - Suppress error if no match found.
112
113
  *
113
114
  * @returns Index token if found.
115
+ *
116
+ * @throws `Error` if no match found and `suppressError` is not `true`.
114
117
  */
115
- findIndexToken(hashKeyToken, rangeKeyToken) {
116
- return findIndexToken(this, hashKeyToken, rangeKeyToken);
118
+ findIndexToken(hashKeyToken, rangeKeyToken, suppressError) {
119
+ return findIndexToken(this, hashKeyToken, rangeKeyToken, suppressError);
117
120
  }
118
121
  /**
119
122
  * Query a database entity across shards in a provider-generic fashion.
@@ -101,7 +101,10 @@ const configSchema = z
101
101
  .record(z.object({
102
102
  hashKey: z.string().min(1),
103
103
  rangeKey: z.string().min(1),
104
- projections: componentArray.optional(),
104
+ projections: z
105
+ .array(z.string().min(1))
106
+ .superRefine(validateArrayUnique)
107
+ .optional(),
105
108
  }))
106
109
  .optional()
107
110
  .default({}),
@@ -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
- return Object.entries(entityManager.config.indexes).find(([, index]) => index.hashKey === hashKeyToken && index.rangeKey === rangeKeyToken)?.[0];
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
@@ -132,5 +132,5 @@
132
132
  },
133
133
  "type": "module",
134
134
  "types": "dist/index.d.ts",
135
- "version": "6.13.0"
135
+ "version": "6.13.2"
136
136
  }