@karmaniverous/entity-manager
Advanced tools
Comparing version 6.4.10 to 6.5.0
@@ -26,2 +26,6 @@ 'use strict'; | ||
}; | ||
const componentArray = zod.z | ||
.array(zod.z.string().min(1)) | ||
.nonempty() | ||
.superRefine(validateArrayUnique); | ||
const configSchema = zod.z | ||
@@ -50,6 +54,3 @@ .object({ | ||
atomic: zod.z.boolean().optional().default(false), | ||
elements: zod.z | ||
.array(zod.z.string().min(1)) | ||
.nonempty() | ||
.superRefine(validateArrayUnique), | ||
elements: componentArray, | ||
sharded: zod.z.boolean().optional().default(false), | ||
@@ -62,6 +63,6 @@ }) | ||
indexes: zod.z | ||
.record(zod.z | ||
.array(zod.z.string().min(1)) | ||
.nonempty() | ||
.superRefine(validateArrayUnique)) | ||
.record(zod.z.object({ | ||
components: componentArray, | ||
projections: componentArray.optional(), | ||
})) | ||
.optional() | ||
@@ -215,6 +216,7 @@ .default({}), | ||
}); | ||
// validate all ungenerated entity index components have a corresponding entity element type. | ||
// validate indexes. | ||
const generatedProperties = Object.keys(entity.generated); | ||
for (const [indexKey, index] of Object.entries(entity.indexes)) | ||
for (const component of index) | ||
for (const [indexKey, index] of Object.entries(entity.indexes)) { | ||
// validate all ungenerated entity index components have a corresponding entity element type | ||
for (const component of index.components) | ||
if (![data.hashKey, data.rangeKey, ...generatedProperties].includes(component) && | ||
@@ -225,5 +227,28 @@ !typedElements.includes(component)) | ||
options: typedElements, | ||
path: ['entities', entityToken, 'indexes', indexKey], | ||
path: [ | ||
'entities', | ||
entityToken, | ||
'indexes', | ||
indexKey, | ||
'components', | ||
], | ||
received: component, | ||
}); | ||
// validate no index projections are index components, hashKey, or rangeKey | ||
if (index.projections) | ||
for (const projection of index.projections) { | ||
if ([data.hashKey, data.rangeKey, ...index.components].includes(projection)) | ||
ctx.addIssue({ | ||
code: zod.z.ZodIssueCode.custom, | ||
message: 'index projection is an index component, hash key, or range key', | ||
path: [ | ||
'entities', | ||
entityToken, | ||
'indexes', | ||
indexKey, | ||
'projections', | ||
], | ||
}); | ||
} | ||
} | ||
} | ||
@@ -230,0 +255,0 @@ }); |
@@ -54,3 +54,4 @@ 'use strict'; | ||
item = updateItemRangeKey.updateItemRangeKey(entityManager, item, entityToken); | ||
return radash.zipToObject(entityManager.config.entities[entityToken].indexes[index], (component) => entityManager.config.entities[entityToken].generated[component] | ||
return radash.zipToObject(entityManager.config.entities[entityToken].indexes[index] | ||
.components, (component) => entityManager.config.entities[entityToken].generated[component] | ||
? encodeGeneratedProperty.encodeGeneratedProperty(entityManager, item, entityToken, component) | ||
@@ -57,0 +58,0 @@ : item[component]); |
@@ -24,3 +24,3 @@ 'use strict'; | ||
const generatedKeys = Object.keys(radash.shake(generated)); | ||
return entityManager.config.entities[entityToken].indexes[indexToken] | ||
return entityManager.config.entities[entityToken].indexes[indexToken].components | ||
.map((component) => component === entityManager.config.hashKey | ||
@@ -27,0 +27,0 @@ ? entityManager.config.hashKey |
@@ -84,2 +84,15 @@ import { Entity, Exactify, TranscodeMap, PropertiesOfType, TranscodableProperties, Transcodes, DefaultTranscodeMap, SortOrder } from '@karmaniverous/entity-tools'; | ||
/** | ||
* Returns a Config entity index components type. | ||
* | ||
* @typeParam EntityToken - The {@link Entity | `Entity`} token. | ||
* @typeParam M - The {@link EntityMap | `EntityMap`}. | ||
* @typeParam HashKey - The property used across the configuration to store an {@link Entity | `Entity`}'s sharded hash key. Should be configured as the table hash key. Must not conflict with any {@link Entity | `Entity`} property. | ||
* @typeParam RangeKey - The property used across the configuration to store an {@link Entity | `Entity`}'s range key. Should be configured as the table range key. Must not conflict with any {@link Entity | `Entity`} property. | ||
* @typeParam T - The {@link TranscodeMap | `TranscodeMap`} identifying transcodable property types. Only {@link Entity | `Entity`} properties of these types can be components of an {@link ConfigEntity.indexes | index} or a {@link ConfigEntityGenerated | generated property}. | ||
* @category Config | ||
* @protected | ||
*/ | ||
type ConfigEntityIndexComponents<EntityToken extends keyof Exactify<M>, M extends EntityMap, HashKey extends string, RangeKey extends string, T extends TranscodeMap> = (TranscodableProperties<M[EntityToken], T> | PropertiesOfType<M[EntityToken], never> | HashKey | RangeKey)[]; | ||
/** | ||
* Returns a Config entity type. | ||
@@ -179,3 +192,6 @@ * | ||
*/ | ||
indexes?: Record<string, (TranscodableProperties<M[EntityToken], T> | PropertiesOfType<M[EntityToken], never> | HashKey | RangeKey)[]>; | ||
indexes?: Record<string, { | ||
components: ConfigEntityIndexComponents<EntityToken, M, HashKey, RangeKey, T>; | ||
projections?: (keyof M[EntityToken])[]; | ||
}>; | ||
/** | ||
@@ -382,3 +398,12 @@ * An array of {@link ShardBump | `ShardBump`} objects representing the {@link Entity | `Entity`}'s sharding strategy. | ||
elementTranscodes: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>; | ||
indexes: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodArray<z.ZodString, "atleastone">, [string, ...string[]], [string, ...string[]]>>>>; | ||
indexes: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{ | ||
components: z.ZodEffects<z.ZodArray<z.ZodString, "atleastone">, [string, ...string[]], [string, ...string[]]>; | ||
projections: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodString, "atleastone">, [string, ...string[]], [string, ...string[]]>>; | ||
}, "strip", z.ZodTypeAny, { | ||
components: [string, ...string[]]; | ||
projections?: [string, ...string[]] | undefined; | ||
}, { | ||
components: [string, ...string[]]; | ||
projections?: [string, ...string[]] | undefined; | ||
}>>>>; | ||
shardBumps: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodObject<{ | ||
@@ -427,3 +452,6 @@ timestamp: z.ZodNumber; | ||
elementTranscodes: Record<string, string>; | ||
indexes: Record<string, [string, ...string[]]>; | ||
indexes: Record<string, { | ||
components: [string, ...string[]]; | ||
projections?: [string, ...string[]] | undefined; | ||
}>; | ||
shardBumps: { | ||
@@ -447,3 +475,6 @@ timestamp: number; | ||
elementTranscodes?: Record<string, string> | undefined; | ||
indexes?: Record<string, [string, ...string[]]> | undefined; | ||
indexes?: Record<string, { | ||
components: [string, ...string[]]; | ||
projections?: [string, ...string[]] | undefined; | ||
}> | undefined; | ||
shardBumps?: { | ||
@@ -463,3 +494,6 @@ timestamp: number; | ||
elementTranscodes: Record<string, string>; | ||
indexes: Record<string, [string, ...string[]]>; | ||
indexes: Record<string, { | ||
components: [string, ...string[]]; | ||
projections?: [string, ...string[]] | undefined; | ||
}>; | ||
shardBumps: { | ||
@@ -483,3 +517,6 @@ timestamp: number; | ||
elementTranscodes?: Record<string, string> | undefined; | ||
indexes?: Record<string, [string, ...string[]]> | undefined; | ||
indexes?: Record<string, { | ||
components: [string, ...string[]]; | ||
projections?: [string, ...string[]] | undefined; | ||
}> | undefined; | ||
shardBumps?: { | ||
@@ -519,3 +556,6 @@ timestamp: number; | ||
elementTranscodes: Record<string, string>; | ||
indexes: Record<string, [string, ...string[]]>; | ||
indexes: Record<string, { | ||
components: [string, ...string[]]; | ||
projections?: [string, ...string[]] | undefined; | ||
}>; | ||
shardBumps: { | ||
@@ -551,3 +591,6 @@ timestamp: number; | ||
elementTranscodes?: Record<string, string> | undefined; | ||
indexes?: Record<string, [string, ...string[]]> | undefined; | ||
indexes?: Record<string, { | ||
components: [string, ...string[]]; | ||
projections?: [string, ...string[]] | undefined; | ||
}> | undefined; | ||
shardBumps?: { | ||
@@ -579,3 +622,6 @@ timestamp: number; | ||
elementTranscodes: Record<string, string>; | ||
indexes: Record<string, [string, ...string[]]>; | ||
indexes: Record<string, { | ||
components: [string, ...string[]]; | ||
projections?: [string, ...string[]] | undefined; | ||
}>; | ||
shardBumps: { | ||
@@ -611,3 +657,6 @@ timestamp: number; | ||
elementTranscodes?: Record<string, string> | undefined; | ||
indexes?: Record<string, [string, ...string[]]> | undefined; | ||
indexes?: Record<string, { | ||
components: [string, ...string[]]; | ||
projections?: [string, ...string[]] | undefined; | ||
}> | undefined; | ||
shardBumps?: { | ||
@@ -634,3 +683,3 @@ timestamp: number; | ||
/** | ||
* Foo | ||
* Simplified type taken on by a {@link Config | `Config`} object after parsing in the {@link EntityManager | `EntityManager`} constructor. | ||
* | ||
@@ -843,2 +892,2 @@ * @category Config | ||
export { type Config, type ConfigEntities, type ConfigEntity, type ConfigEntityGenerated, type ConfigKeys, type ConfigTranscodes, EntityManager, type EntityMap, type ExclusiveKey, type ItemMap, type ParsedConfig, type QueryOptions, type QueryResult, type ShardBump, type ShardQueryFunction, type ShardQueryMap, type ShardQueryResult, type Unwrap, conditionalize }; | ||
export { type Config, type ConfigEntities, type ConfigEntity, type ConfigEntityGenerated, type ConfigEntityIndexComponents, type ConfigKeys, type ConfigTranscodes, EntityManager, type EntityMap, type ExclusiveKey, type ItemMap, type ParsedConfig, type QueryOptions, type QueryResult, type ShardBump, type ShardQueryFunction, type ShardQueryMap, type ShardQueryResult, type Unwrap, conditionalize }; |
@@ -24,2 +24,6 @@ import { defaultTranscodes } from '@karmaniverous/entity-tools'; | ||
}; | ||
const componentArray = z | ||
.array(z.string().min(1)) | ||
.nonempty() | ||
.superRefine(validateArrayUnique); | ||
const configSchema = z | ||
@@ -48,6 +52,3 @@ .object({ | ||
atomic: z.boolean().optional().default(false), | ||
elements: z | ||
.array(z.string().min(1)) | ||
.nonempty() | ||
.superRefine(validateArrayUnique), | ||
elements: componentArray, | ||
sharded: z.boolean().optional().default(false), | ||
@@ -60,6 +61,6 @@ }) | ||
indexes: z | ||
.record(z | ||
.array(z.string().min(1)) | ||
.nonempty() | ||
.superRefine(validateArrayUnique)) | ||
.record(z.object({ | ||
components: componentArray, | ||
projections: componentArray.optional(), | ||
})) | ||
.optional() | ||
@@ -213,6 +214,7 @@ .default({}), | ||
}); | ||
// validate all ungenerated entity index components have a corresponding entity element type. | ||
// validate indexes. | ||
const generatedProperties = Object.keys(entity.generated); | ||
for (const [indexKey, index] of Object.entries(entity.indexes)) | ||
for (const component of index) | ||
for (const [indexKey, index] of Object.entries(entity.indexes)) { | ||
// validate all ungenerated entity index components have a corresponding entity element type | ||
for (const component of index.components) | ||
if (![data.hashKey, data.rangeKey, ...generatedProperties].includes(component) && | ||
@@ -223,5 +225,28 @@ !typedElements.includes(component)) | ||
options: typedElements, | ||
path: ['entities', entityToken, 'indexes', indexKey], | ||
path: [ | ||
'entities', | ||
entityToken, | ||
'indexes', | ||
indexKey, | ||
'components', | ||
], | ||
received: component, | ||
}); | ||
// validate no index projections are index components, hashKey, or rangeKey | ||
if (index.projections) | ||
for (const projection of index.projections) { | ||
if ([data.hashKey, data.rangeKey, ...index.components].includes(projection)) | ||
ctx.addIssue({ | ||
code: z.ZodIssueCode.custom, | ||
message: 'index projection is an index component, hash key, or range key', | ||
path: [ | ||
'entities', | ||
entityToken, | ||
'indexes', | ||
indexKey, | ||
'projections', | ||
], | ||
}); | ||
} | ||
} | ||
} | ||
@@ -228,0 +253,0 @@ }); |
@@ -52,3 +52,4 @@ import { range, mapValues, zipToObject, cluster } from 'radash'; | ||
item = updateItemRangeKey(entityManager, item, entityToken); | ||
return zipToObject(entityManager.config.entities[entityToken].indexes[index], (component) => entityManager.config.entities[entityToken].generated[component] | ||
return zipToObject(entityManager.config.entities[entityToken].indexes[index] | ||
.components, (component) => entityManager.config.entities[entityToken].generated[component] | ||
? encodeGeneratedProperty(entityManager, item, entityToken, component) | ||
@@ -55,0 +56,0 @@ : item[component]); |
@@ -22,3 +22,3 @@ import { shake } from 'radash'; | ||
const generatedKeys = Object.keys(shake(generated)); | ||
return entityManager.config.entities[entityToken].indexes[indexToken] | ||
return entityManager.config.entities[entityToken].indexes[indexToken].components | ||
.map((component) => component === entityManager.config.hashKey | ||
@@ -25,0 +25,0 @@ ? entityManager.config.hashKey |
@@ -135,3 +135,3 @@ { | ||
"types": "dist/index.d.ts", | ||
"version": "6.4.10" | ||
"version": "6.5.0" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
164254
3561