electrodb
Advanced tools
Comparing version 0.9.2 to 0.9.3
{ | ||
"name": "electrodb", | ||
"version": "0.9.2", | ||
"version": "0.9.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", |
@@ -205,3 +205,3 @@ | ||
team: { | ||
type: ["development", "marketing", "finance", "product"], | ||
type: ["development", "marketing", "finance", "product", "cool cats and kittens"], | ||
required: true, | ||
@@ -1405,3 +1405,3 @@ }, | ||
const OfficesModel = new Entity({ | ||
const OfficesModel = { | ||
entity: "offices", | ||
@@ -1455,3 +1455,3 @@ version: "1", | ||
}, | ||
}); | ||
}; | ||
``` | ||
@@ -1458,0 +1458,0 @@ Join models on a new `Service` called `EmployeeApp` |
@@ -1124,2 +1124,6 @@ "use strict"; | ||
} | ||
if (facets.byIndex[""] === undefined) { | ||
throw new Error("Schema is missing an index definition for the table's main index. Please update the schema to include an index without a specified name to define the table's natural index"); | ||
} | ||
@@ -1126,0 +1130,0 @@ return { |
@@ -101,3 +101,3 @@ const { Entity } = require("./entity"); | ||
collectionDifferences.push( | ||
`Index provided "${providedIndex.index}" does not match established index ${definition.index}`, | ||
`Index provided "${providedIndex.index}" does not match established index: ${definition.index || "[Main Table Index]"}`, | ||
); | ||
@@ -107,3 +107,3 @@ } | ||
collectionDifferences.push( | ||
`Partition Key Field provided "${providedIndex.pk.field}" for index "${providedIndex.index}" does not match established field ${definition.field}`, | ||
`Partition Key Field provided "${providedIndex.pk.field}" for index "${providedIndex.index}" does not match established field "${definition.pk.field}"`, | ||
); | ||
@@ -134,3 +134,3 @@ } | ||
results.invalid.push( | ||
`Attribute provided "${name}" with Table Field "${detail.field}" does not match established Table Field ${provided.field}`, | ||
`Attribute provided "${name}" with Table Field "${detail.field}" does not match established Table Field "${defined.field}"`, | ||
); | ||
@@ -137,0 +137,0 @@ } |
@@ -166,2 +166,35 @@ const { Entity, clauses } = require("../src/entity"); | ||
}); | ||
it("Should identify a missing definiton for the table's main index", () => { | ||
expect(() => new Entity({ | ||
service: "test", | ||
entity: "entityOne", | ||
table: "test", | ||
version: "1", | ||
attributes: { | ||
prop1: { | ||
type: "string", | ||
}, | ||
prop4: { | ||
type: "string" | ||
}, | ||
prop5: { | ||
type: "string" | ||
} | ||
}, | ||
indexes: { | ||
index1: { | ||
pk: { | ||
field: "pk", | ||
facets: ["prop1"], | ||
}, | ||
sk: { | ||
field: "sk", | ||
facets: ["prop4", "prop5"], | ||
}, | ||
collection: "collectionA", | ||
index: "different-index-than-entity-one", | ||
} | ||
} | ||
})).to.throw("Schema is missing an index definition for the table's main index. Please update the schema to include an index without a specified name to define the table's natural index") | ||
}); | ||
it("should recognize when an attribute's field property is duplicated", () => { | ||
@@ -168,0 +201,0 @@ let schema = { |
@@ -370,2 +370,271 @@ const { Service } = require("../src/service"); | ||
describe("Misconfiguration exceptions", () => { | ||
it("Should require collections to be set on the same index", () => { | ||
let entityOne = { | ||
entity: "entityOne", | ||
attributes: { | ||
prop1: { | ||
type: "string", | ||
}, | ||
prop2: { | ||
type: "string" | ||
}, | ||
prop3: { | ||
type: "string" | ||
} | ||
}, | ||
indexes: { | ||
index1: { | ||
pk: { | ||
field: "pk", | ||
facets: ["prop1"], | ||
}, | ||
sk: { | ||
field: "sk", | ||
facets: ["prop2", "prop3"], | ||
}, | ||
collection: "collectionA", | ||
} | ||
} | ||
} | ||
let entityTwo = { | ||
entity: "entityOne", | ||
attributes: { | ||
prop1: { | ||
type: "string", | ||
}, | ||
prop4: { | ||
type: "string" | ||
}, | ||
prop5: { | ||
type: "string" | ||
} | ||
}, | ||
indexes: { | ||
index1: { | ||
pk: { | ||
field: "pk", | ||
facets: ["prop1"], | ||
}, | ||
sk: { | ||
field: "sk", | ||
facets: ["prop4", "prop5"], | ||
}, | ||
collection: "collectionB", | ||
}, | ||
index2: { | ||
pk: { | ||
field: "pk", | ||
facets: ["prop1"], | ||
}, | ||
sk: { | ||
field: "sk", | ||
facets: ["prop4", "prop5"], | ||
}, | ||
collection: "collectionA", | ||
index: "different-index-than-entity-one", | ||
} | ||
} | ||
} | ||
let database = new Service({ | ||
version: "1", | ||
table: "electro", | ||
service: "electrotest", | ||
}); | ||
database.join(entityOne); | ||
expect(() => database.join(entityTwo)).to.throw(`Index provided "different-index-than-entity-one" does not match established index: [Main Table Index]`); | ||
// expect(() => database.join(entityTwo)).to.throw("You cant do that"); | ||
}); | ||
it("Should validate the PK facets match on all added schemas", () => { | ||
let entityOne = { | ||
entity: "entityOne", | ||
attributes: { | ||
prop1: { | ||
type: "string", | ||
}, | ||
prop2: { | ||
type: "string" | ||
}, | ||
prop3: { | ||
type: "string" | ||
} | ||
}, | ||
indexes: { | ||
index1: { | ||
pk: { | ||
field: "pk", | ||
facets: ["prop1"], | ||
}, | ||
sk: { | ||
field: "sk", | ||
facets: ["prop2", "prop3"], | ||
}, | ||
collection: "collectionA", | ||
} | ||
} | ||
} | ||
let entityTwo = { | ||
entity: "entityOne", | ||
attributes: { | ||
prop1: { | ||
type: "string", | ||
}, | ||
prop4: { | ||
type: "string" | ||
}, | ||
prop5: { | ||
type: "string" | ||
} | ||
}, | ||
indexes: { | ||
index1: { | ||
pk: { | ||
field: "pk", | ||
facets: ["prop4"], | ||
}, | ||
sk: { | ||
field: "sk", | ||
facets: ["prop1", "prop5"], | ||
}, | ||
collection: "collectionA", | ||
}, | ||
} | ||
} | ||
let database = new Service({ | ||
version: "1", | ||
table: "electro", | ||
service: "electrotest", | ||
}); | ||
database.join(entityOne); | ||
expect(() => database.join(entityTwo)).to.throw(`Partition Key Facets provided "prop4" do not match established facets "prop1"`); | ||
}); | ||
it("Should validate the PK field matches on all added schemas", () => { | ||
let entityOne = { | ||
entity: "entityOne", | ||
attributes: { | ||
prop1: { | ||
type: "string", | ||
}, | ||
prop2: { | ||
type: "string" | ||
}, | ||
prop3: { | ||
type: "string" | ||
} | ||
}, | ||
indexes: { | ||
index1: { | ||
pk: { | ||
field: "pk", | ||
facets: ["prop1"], | ||
}, | ||
sk: { | ||
field: "sk", | ||
facets: ["prop2", "prop3"], | ||
}, | ||
collection: "collectionA", | ||
} | ||
} | ||
} | ||
let entityTwo = { | ||
entity: "entityOne", | ||
attributes: { | ||
prop1: { | ||
type: "string", | ||
}, | ||
prop4: { | ||
type: "string" | ||
}, | ||
prop5: { | ||
type: "string" | ||
} | ||
}, | ||
indexes: { | ||
index1: { | ||
pk: { | ||
field: "pkz", | ||
facets: ["prop1"], | ||
}, | ||
sk: { | ||
field: "sk", | ||
facets: ["prop4", "prop5"], | ||
}, | ||
collection: "collectionA", | ||
}, | ||
} | ||
} | ||
let database = new Service({ | ||
version: "1", | ||
table: "electro", | ||
service: "electrotest", | ||
}); | ||
database.join(entityOne); | ||
expect(() => database.join(entityTwo)).to.throw(`Partition Key Field provided "pkz" for index "" does not match established field "pk"`); | ||
}); | ||
it("Should validate the attributes with matching names have matching fields on all added schemas", () => { | ||
let entityOne = { | ||
entity: "entityOne", | ||
attributes: { | ||
prop1: { | ||
type: "string", | ||
}, | ||
prop2: { | ||
type: "string" | ||
}, | ||
prop3: { | ||
type: "string" | ||
} | ||
}, | ||
indexes: { | ||
index1: { | ||
pk: { | ||
field: "pk", | ||
facets: ["prop1"], | ||
}, | ||
sk: { | ||
field: "sk", | ||
facets: ["prop2", "prop3"], | ||
}, | ||
collection: "collectionA", | ||
} | ||
} | ||
} | ||
let entityTwo = { | ||
entity: "entityOne", | ||
attributes: { | ||
prop1: { | ||
type: "string", | ||
field: "notProp1" | ||
}, | ||
prop4: { | ||
type: "string" | ||
}, | ||
prop5: { | ||
type: "string" | ||
} | ||
}, | ||
indexes: { | ||
index1: { | ||
pk: { | ||
field: "pk", | ||
facets: ["prop1"], | ||
}, | ||
sk: { | ||
field: "sk", | ||
facets: ["prop4", "prop5"], | ||
}, | ||
collection: "collectionA", | ||
}, | ||
} | ||
} | ||
let database = new Service({ | ||
version: "1", | ||
table: "electro", | ||
service: "electrotest", | ||
}); | ||
database.join(entityOne); | ||
expect(() => database.join(entityTwo)).to.throw(`Attribute provided "prop1" with Table Field "notProp1" does not match established Table Field "prop1"`); | ||
}); | ||
}) | ||
// database.find.collectionA({}).go(); |
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
290023
6033