MCPcopy Create free account
hub / github.com/clientdb/clientdb / assertEntityNotBreakingUniqueIndex

Function assertEntityNotBreakingUniqueIndex

core/store.ts:155–175  ·  view source on GitHub ↗
(entity: StoreEntity)

Source from the content-addressed store, hash-verified

153 });
154
155 function assertEntityNotBreakingUniqueIndex(entity: StoreEntity) {
156 if (!definition.config.uniqueProps) return;
157
158 for (const uniquePropName of definition.config.uniqueProps) {
159 const index = store.getPropIndex(uniquePropName);
160 const propValue = entity[uniquePropName] as unknown as IndexFindInput<
161 Data,
162 View,
163 keyof Data
164 >;
165 const existingEntities = index.find(propValue);
166
167 if (existingEntities.length > 0) {
168 throw new Error(
169 `Entity "${
170 definition.config.name
171 }" with unique property "${uniquePropName.toString()}"="${propValue?.toString()}" already exists`
172 );
173 }
174 }
175 }
176
177 function updateEntityIndexes(
178 entity: StoreEntity,

Callers 1

addFunction · 0.85

Calls 2

getPropIndexMethod · 0.80
findMethod · 0.65

Tested by

no test coverage detected