Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@karmaniverous/entity-manager

Package Overview
Dependencies
Maintainers
0
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@karmaniverous/entity-manager - npm Package Compare versions

Comparing version 6.5.0 to 6.5.1

dist/cjs/getIndexComponents.js

27

dist/cjs/ParsedConfig.js

@@ -62,3 +62,4 @@ 'use strict';

.record(zod.z.object({
components: componentArray,
hashKey: zod.z.string().min(1),
rangeKey: zod.z.string().min(1),
projections: componentArray.optional(),

@@ -216,5 +217,19 @@ }))

const generatedProperties = Object.keys(entity.generated);
for (const [indexKey, index] of Object.entries(entity.indexes)) {
for (const [indexKey, { hashKey, rangeKey, projections },] of Object.entries(entity.indexes)) {
// validate index hash key is sharded
if (hashKey !== data.hashKey && !entity.generated[hashKey]?.sharded)
ctx.addIssue({
code: zod.z.ZodIssueCode.custom,
message: 'index hash key is not sharded',
path: ['entities', entityToken, 'indexes', indexKey, 'hashKey'],
});
// validate index range key is unsharded
if (rangeKey !== data.rangeKey && entity.generated[rangeKey]?.sharded)
ctx.addIssue({
code: zod.z.ZodIssueCode.custom,
message: 'index range key is sharded',
path: ['entities', entityToken, 'indexes', indexKey, 'rangeKey'],
});
// validate all ungenerated entity index components have a corresponding entity element type
for (const component of index.components)
for (const component of [hashKey, rangeKey])
if (![data.hashKey, data.rangeKey, ...generatedProperties].includes(component) &&

@@ -235,5 +250,5 @@ !typedElements.includes(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))
if (projections)
for (const projection of projections) {
if ([data.hashKey, data.rangeKey, hashKey, rangeKey].includes(projection))
ctx.addIssue({

@@ -240,0 +255,0 @@ code: zod.z.ZodIssueCode.custom,

@@ -6,2 +6,3 @@ 'use strict';

var getHashKeySpace = require('./getHashKeySpace.js');
var getIndexComponents = require('./getIndexComponents.js');
var rehydrateIndexItem = require('./rehydrateIndexItem.js');

@@ -55,4 +56,3 @@ var updateItemRangeKey = require('./updateItemRangeKey.js');

item = updateItemRangeKey.updateItemRangeKey(entityManager, item, entityToken);
return radash.zipToObject(entityManager.config.entities[entityToken].indexes[index]
.components, (component) => entityManager.config.entities[entityToken].generated[component]
return radash.zipToObject(getIndexComponents.getIndexComponents(entityManager, entityToken, index), (component) => entityManager.config.entities[entityToken].generated[component]
? encodeGeneratedProperty.encodeGeneratedProperty(entityManager, item, entityToken, component)

@@ -59,0 +59,0 @@ : item[component]);

'use strict';
var radash = require('radash');
var getIndexComponents = require('./getIndexComponents.js');
var validateEntityIndexToken = require('./validateEntityIndexToken.js');

@@ -24,3 +25,3 @@

const generatedKeys = Object.keys(radash.shake(generated));
return entityManager.config.entities[entityToken].indexes[indexToken].components
return getIndexComponents.getIndexComponents(entityManager, entityToken, indexToken)
.map((component) => component === entityManager.config.hashKey

@@ -27,0 +28,0 @@ ? entityManager.config.hashKey

@@ -95,3 +95,3 @@ import { Entity, Exactify, TranscodeMap, PropertiesOfType, TranscodableProperties, Transcodes, DefaultTranscodeMap, SortOrder } from '@karmaniverous/entity-tools';

*/
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)[];
type ConfigEntityIndexComponent<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;
/**

@@ -188,8 +188,9 @@ * Returns a Config entity type.

*
* Each key is the name of an index, and each value is a non-empty array of {@link Entity | `Entity`} property names that define the index.
* Each key is the name of an index, and each value defines the hash key, range key, and projected properties of the index.
*
* Related property types must be align with the {@link Config | `Config`} `T` type parameter. Note tha all {@link ConfigEntityGenerated | generated property} types are transcodable by definition.
* hashKey and rangeKey types must align with the {@link Config | `Config`} `T` type parameter. Note that all {@link ConfigEntityGenerated | generated property} types are transcodable by definition.
*/
indexes?: Record<string, {
components: ConfigEntityIndexComponents<EntityToken, M, HashKey, RangeKey, T>;
hashKey: ConfigEntityIndexComponent<EntityToken, M, HashKey, RangeKey, T>;
rangeKey: ConfigEntityIndexComponent<EntityToken, M, HashKey, RangeKey, T>;
projections?: (keyof M[EntityToken])[];

@@ -399,9 +400,12 @@ }>;

indexes: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
components: z.ZodEffects<z.ZodArray<z.ZodString, "atleastone">, [string, ...string[]], [string, ...string[]]>;
hashKey: z.ZodString;
rangeKey: z.ZodString;
projections: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodString, "atleastone">, [string, ...string[]], [string, ...string[]]>>;
}, "strip", z.ZodTypeAny, {
components: [string, ...string[]];
hashKey: string;
rangeKey: string;
projections?: [string, ...string[]] | undefined;
}, {
components: [string, ...string[]];
hashKey: string;
rangeKey: string;
projections?: [string, ...string[]] | undefined;

@@ -453,3 +457,4 @@ }>>>>;

indexes: Record<string, {
components: [string, ...string[]];
hashKey: string;
rangeKey: string;
projections?: [string, ...string[]] | undefined;

@@ -476,3 +481,4 @@ }>;

indexes?: Record<string, {
components: [string, ...string[]];
hashKey: string;
rangeKey: string;
projections?: [string, ...string[]] | undefined;

@@ -495,3 +501,4 @@ }> | undefined;

indexes: Record<string, {
components: [string, ...string[]];
hashKey: string;
rangeKey: string;
projections?: [string, ...string[]] | undefined;

@@ -518,3 +525,4 @@ }>;

indexes?: Record<string, {
components: [string, ...string[]];
hashKey: string;
rangeKey: string;
projections?: [string, ...string[]] | undefined;

@@ -557,3 +565,4 @@ }> | undefined;

indexes: Record<string, {
components: [string, ...string[]];
hashKey: string;
rangeKey: string;
projections?: [string, ...string[]] | undefined;

@@ -592,3 +601,4 @@ }>;

indexes?: Record<string, {
components: [string, ...string[]];
hashKey: string;
rangeKey: string;
projections?: [string, ...string[]] | undefined;

@@ -623,3 +633,4 @@ }> | undefined;

indexes: Record<string, {
components: [string, ...string[]];
hashKey: string;
rangeKey: string;
projections?: [string, ...string[]] | undefined;

@@ -658,3 +669,4 @@ }>;

indexes?: Record<string, {
components: [string, ...string[]];
hashKey: string;
rangeKey: string;
projections?: [string, ...string[]] | undefined;

@@ -891,2 +903,2 @@ }> | undefined;

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 };
export { type Config, type ConfigEntities, type ConfigEntity, type ConfigEntityGenerated, type ConfigEntityIndexComponent, 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 };

@@ -60,3 +60,4 @@ import { defaultTranscodes } from '@karmaniverous/entity-tools';

.record(z.object({
components: componentArray,
hashKey: z.string().min(1),
rangeKey: z.string().min(1),
projections: componentArray.optional(),

@@ -214,5 +215,19 @@ }))

const generatedProperties = Object.keys(entity.generated);
for (const [indexKey, index] of Object.entries(entity.indexes)) {
for (const [indexKey, { hashKey, rangeKey, projections },] of Object.entries(entity.indexes)) {
// validate index hash key is sharded
if (hashKey !== data.hashKey && !entity.generated[hashKey]?.sharded)
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'index hash key is not sharded',
path: ['entities', entityToken, 'indexes', indexKey, 'hashKey'],
});
// validate index range key is unsharded
if (rangeKey !== data.rangeKey && entity.generated[rangeKey]?.sharded)
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'index range key is sharded',
path: ['entities', entityToken, 'indexes', indexKey, 'rangeKey'],
});
// validate all ungenerated entity index components have a corresponding entity element type
for (const component of index.components)
for (const component of [hashKey, rangeKey])
if (![data.hashKey, data.rangeKey, ...generatedProperties].includes(component) &&

@@ -233,5 +248,5 @@ !typedElements.includes(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))
if (projections)
for (const projection of projections) {
if ([data.hashKey, data.rangeKey, hashKey, rangeKey].includes(projection))
ctx.addIssue({

@@ -238,0 +253,0 @@ code: z.ZodIssueCode.custom,

import { range, mapValues, zipToObject, cluster } from 'radash';
import { encodeGeneratedProperty } from './encodeGeneratedProperty.js';
import { getHashKeySpace } from './getHashKeySpace.js';
import { getIndexComponents } from './getIndexComponents.js';
import { rehydrateIndexItem } from './rehydrateIndexItem.js';

@@ -52,4 +53,3 @@ import { updateItemRangeKey } from './updateItemRangeKey.js';

item = updateItemRangeKey(entityManager, item, entityToken);
return zipToObject(entityManager.config.entities[entityToken].indexes[index]
.components, (component) => entityManager.config.entities[entityToken].generated[component]
return zipToObject(getIndexComponents(entityManager, entityToken, index), (component) => entityManager.config.entities[entityToken].generated[component]
? encodeGeneratedProperty(entityManager, item, entityToken, component)

@@ -56,0 +56,0 @@ : item[component]);

import { shake } from 'radash';
import { getIndexComponents } from './getIndexComponents.js';
import { validateEntityIndexToken } from './validateEntityIndexToken.js';

@@ -22,3 +23,3 @@

const generatedKeys = Object.keys(shake(generated));
return entityManager.config.entities[entityToken].indexes[indexToken].components
return getIndexComponents(entityManager, entityToken, indexToken)
.map((component) => component === entityManager.config.hashKey

@@ -25,0 +26,0 @@ ? entityManager.config.hashKey

@@ -135,3 +135,3 @@ {

"types": "dist/index.d.ts",
"version": "6.5.0"
"version": "6.5.1"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc