electrodb
Advanced tools
Comparing version 0.10.2 to 0.10.3
{ | ||
"name": "electrodb", | ||
"version": "0.10.2", | ||
"version": "0.10.3", | ||
"description": "A library to more easily create and interact with multiple entities and heretical relationships in dynamodb", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1603,3 +1603,3 @@ "use strict"; | ||
if (indexName === "") { | ||
throw new e.ElectroError(e.ErrorCodes.DuplicateIndexes, `Duplicate index defined in model found in Access Pattern '${accessPattern}': '${indexName || "(PRIMARY INDEX)"}'. This could be because you forgot to specify the index name of a secondary index defined in your model.`); | ||
throw new e.ElectroError(e.ErrorCodes.DuplicateIndexes, `Duplicate index defined in model found in Access Pattern '${accessPattern}': '${indexName || "(Primary Index)"}'. This could be because you forgot to specify the index name of a secondary index defined in your model.`); | ||
} else { | ||
@@ -1613,3 +1613,3 @@ throw new e.ElectroError(e.ErrorCodes.DuplicateIndexes, `Duplicate index defined in model found in Access Pattern '${accessPattern}': '${indexName}'`); | ||
if (!hasSk && inCollection) { | ||
throw new e.ElectroError(e.ErrorCodes.CollectionNoSK, `Invalid Access pattern definition for '${accessPattern}': '${indexName || "(PRIMARY INDEX)"}', contains a collection definition without a defined SK. Collections can only be defined on indexes with a defined SK.`); | ||
throw new e.ElectroError(e.ErrorCodes.CollectionNoSK, `Invalid Access pattern definition for '${accessPattern}': '${indexName || "(Primary Index)"}', contains a collection definition without a defined SK. Collections can only be defined on indexes with a defined SK.`); | ||
} | ||
@@ -1644,3 +1644,3 @@ let collection = index.collection || ""; | ||
customFacets.sk = parsedSKFacets.isCustom; | ||
facets.labels[indexName] = Object.assign({}, facets.labels[indexName] || {}, facetLabels); | ||
facets.labels[indexName] = Object.assign({}, facets.labels[indexName] || {}, facetLabels); | ||
sk = { | ||
@@ -1837,2 +1837,3 @@ facetLabels, | ||
facets.labels[indexName] = Object.assign({}, modelLabels, facets.labels[indexName]); | ||
indexes[indexAccessPattern.fromIndexToAccessPattern[indexName]].labels = facets.labels[indexName]; | ||
} | ||
@@ -1839,0 +1840,0 @@ |
@@ -267,8 +267,32 @@ const { Entity } = require("./entity"); | ||
let pkFacetLengthMatch = definition.pk.facets.length === providedIndex.pk.facets.length; | ||
let pkFacetContentMatch; | ||
let mismatchedFacetLabels = []; | ||
let collectionDifferences = []; | ||
let definitionIndexName = definition.index || "(Primary Index)"; | ||
let providedIndexName = providedIndex.index || "(Primary Index)"; | ||
for (let i = 0; i < definition.pk.facets.length; i++) { | ||
pkFacetContentMatch = definition.pk.facets[i] === providedIndex.pk.facets[i]; | ||
if (!pkFacetContentMatch) { | ||
break; | ||
let definitionFacet = definition.pk.facets[i]; | ||
let definitionLabel = definition.labels[definitionFacet] !== undefined | ||
? definition.labels[definitionFacet] | ||
: definitionFacet; | ||
let providedFacet = providedIndex.pk.facets[i]; | ||
let providedLabel = providedIndex.labels[providedFacet] !== undefined | ||
? providedIndex.labels[providedFacet] | ||
: providedFacet; | ||
let noLabels = definition.labels[definitionFacet] === undefined && providedIndex.labels[providedFacet] === undefined; | ||
if (definitionLabel !== providedLabel) { | ||
mismatchedFacetLabels.push({ | ||
definitionFacet, | ||
definitionLabel, | ||
providedFacet, | ||
providedLabel, | ||
type: noLabels ? "facet" : "label" | ||
}); | ||
} else if (definitionFacet !== providedFacet) { | ||
mismatchedFacetLabels.push({ | ||
definitionFacet, | ||
definitionLabel, | ||
providedFacet, | ||
providedLabel, | ||
type: "facet" | ||
}); | ||
} | ||
@@ -278,14 +302,29 @@ } | ||
collectionDifferences.push( | ||
`Index provided "${providedIndex.index}" does not match established index: ${definition.index || "[Main Table Index]"}`, | ||
`Collection defined on provided index "${providedIndexName}" does not match collection established index "${definitionIndexName}". Collections must be defined on the same index across all entities within a service.`, | ||
); | ||
} | ||
if (!pkFieldMatch) { | ||
} else if (!pkFieldMatch) { | ||
collectionDifferences.push( | ||
`Partition Key Field provided "${providedIndex.pk.field}" for index "${providedIndex.index}" does not match established field "${definition.pk.field}"`, | ||
`Partition Key facets provided "${providedIndex.pk.field}" for index "${providedIndexName}" do not match established field "${definition.pk.field}" on established index "${definitionIndexName}"`, | ||
); | ||
} | ||
if (!pkFacetLengthMatch || !pkFacetContentMatch) { | ||
if (!pkFacetLengthMatch) { | ||
collectionDifferences.push( | ||
`Partition Key Facets provided "${providedIndex.pk.facets.join(", ")}" do not match established facets "${definition.pk.facets.join(", ")}"`, | ||
`Partition Key Facets provided [${providedIndex.pk.facets.map(val => `"${val}"`).join(", ")}] for index "${providedIndexName}" do not match established facets [${definition.pk.facets.map(val => `"${val}"`).join(", ")}] on established index "${definitionIndexName}"`, | ||
); | ||
// Else if used here because if they don't even have the same facet length then the data collected for the mismatched facets would include undefined values | ||
// which would make the error messages even more confusing. | ||
} else if (mismatchedFacetLabels.length > 0) { | ||
for (let mismatch of mismatchedFacetLabels) { | ||
if (mismatch.type === "facet") { | ||
collectionDifferences.push( | ||
`Partition Key facets provided for index "${providedIndexName}" do not match established facet "${mismatch.definitionFacet}" on established index "${definitionIndexName}": "${mismatch.definitionLabel}" != "${mismatch.providedLabel}"; Facet definitions must match between all members of a collection to ensure key structures will resolve to identical Partition Keys. Please ensure these facet definitions are identical for all entities associated with this service.` | ||
); | ||
} else { | ||
collectionDifferences.push( | ||
`Partition Key facets provided for index "${providedIndexName}" contain conflicting facet labels for established facet "${mismatch.definitionFacet}" on established index "${definitionIndexName}". Established facet "${mismatch.definitionFacet}" on established index "${definitionIndexName}" was defined with label "${mismatch.definitionLabel}" while provided facet "${mismatch.providedFacet}" on provided index "${providedIndexName}" is defined with label "${mismatch.providedLabel}". Facet labels definitions must match between all members of a collection to ensure key structures will resolve to identical Partition Keys. Please ensure these labels definitions are identical for all entities associated with this service.` | ||
); | ||
} | ||
} | ||
} | ||
@@ -329,2 +368,3 @@ return [!!collectionDifferences.length, collectionDifferences]; | ||
index: providedIndex.index || "", | ||
labels: providedIndex.labels || {}, | ||
pk: { | ||
@@ -340,6 +380,6 @@ field: providedIndex.pk.field, | ||
} | ||
let [invalidDefinition, invalidIndexMessages] = this._validateCollectionDefinition(definition, providedIndex); | ||
if (invalidDefinition) { | ||
throw new e.ElectroError(e.ErrorCodes.InvalidJoin, `Invalid entity index definitions. The following index definitions have already been defined on this model but with incompatible or conflicting properties: ${invalidIndexMessages.join(", ")}`); | ||
} | ||
let [invalidDefinition, invalidIndexMessages] = this._validateCollectionDefinition(definition, providedIndex); | ||
if (invalidDefinition) { | ||
throw new e.ElectroError(e.ErrorCodes.InvalidJoin, invalidIndexMessages.join(", ")); | ||
} | ||
return definition; | ||
@@ -346,0 +386,0 @@ } |
Sorry, the diff of this file is too big to display
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
356537
6097
3172