Skip to content

Commit

Permalink
Clean up and test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tywalch committed Apr 28, 2024
1 parent 8bb7bac commit d669625
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 28 deletions.
22 changes: 0 additions & 22 deletions src/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -3280,35 +3280,13 @@ class Entity {
const memberAttributeIsImpacted = impactedIndexTypeSources[index] && (impactedIndexTypeSources[index][KeyTypes.pk] === ImpactedIndexTypeSource.provided || impactedIndexTypeSources[index][KeyTypes.sk] === ImpactedIndexTypeSource.provided);
const allMemberAttributesAreIncluded = definition.all.every(({name}) => included[name] !== undefined);

// if any of the indexes were impacted because attributes were provided, then we need to check the condition.
// Indexes that were impacted only because of `included` don't need to be checked. An example of this is would be
// a secondary index that shares composite attributes with the main table index. These cases don't demonstrate an
// intent to recalculate the index. This assumes `included` is really only used by callers to denote values that
// are not changing.
// if (impactedIndexTypeSources[index] && (allMemberAttributesAreIncluded || impactedIndexTypeSources[index][KeyTypes.pk] === ImpactedIndexTypeSource.provided || impactedIndexTypeSources[index][KeyTypes.sk] === ImpactedIndexTypeSource.provided)) {
// there is truth somewhere in the middle between the above and below conditions
if (memberAttributeIsImpacted || allMemberAttributesAreIncluded) {
// We want to make sure that there is actually at least one member attribute is impacted
// const memberAttributeIsBeingMutated = definition.all.find(({name}) => attributes[name] !== undefined);

// 5:38pm I just commented this out because we _should_ reevaluate the condition if all the attributes are in included
// if (memberAttributeIsImpacted || allMemberAttributesAreIncluded) {
// incomplete.push({ index, missing });
// conditions[index] = true;
// continue;
// }

// the `missing` array will contain indexes that are partially provided, but that leaves cases where the pk or
// sk of an index is complete but not both. Both cases are invalid if `indexConditionIsDefined=true`
const missingAttributes = definition.all
.filter(({name}) => !attributes[name] && !included[name] || missing.includes(name))
.map(({name}) => name)
// const missingAreProvidedInAttributesOrIncluded = missing.every((attr) => attributes[attr] !== undefined || included[attr] !== undefined);
// const missingPk = impactedIndexTypeSources[index][KeyTypes.pk] === undefined;
// const hasSkToMiss = !definition.hasSortKeys || (definition.sk && definition.sk.length > 0);
// const missingSk = hasSkToMiss && impactedIndexTypeSources[index][KeyTypes.sk] === undefined;

// if (!missingAreProvidedInAttributesOrIncluded || missingPk || missingSk) {
if (missingAttributes.length) {
// const missingAttributes = missing.length ? missing : definition.all.filter(({name}) => !attributes[name] || !included[name]);
throw new e.ElectroError(e.ErrorCodes.IncompleteIndexCompositesAttributesProvided, `Incomplete composite attributes provided for index ${index}. Write operations that include composite attributes, for indexes with a condition callback defined, must always provide values for every index composite. This is to ensure consistency between index values and attribute values. Missing composite attributes identified: ${u.commaSeparatedString(missingAttributes)}`);
Expand Down
8 changes: 2 additions & 6 deletions test/ts_connected.entity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3831,19 +3831,15 @@ describe("index condition", () => {
it(`${prefix} write index with provided patch attributes`, async () => {
const {params, logger} = createParamsCollector();
const {prop1, prop2, ...props} = createTestEntityData();
const { prop1: _, prop2: __, initialValues } = createTestEntityData();

Check failure on line 3834 in test/ts_connected.entity.spec.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Property 'initialValues' does not exist on type 'Item<string, string, string, { model: { entity: string; service: string; version: string; }; attributes: { prop1: { type: "string"; }; prop2: { type: "string"; }; prop3: { type: "string"; }; prop4: { type: "string"; }; ... 4 more ...; prop9: { ...; }; }; indexes: { ...; }; }, { ...; }>'.

Check failure on line 3834 in test/ts_connected.entity.spec.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Property 'initialValues' does not exist on type 'Item<string, string, string, { model: { entity: string; service: string; version: string; }; attributes: { prop1: { type: "string"; }; prop2: { type: "string"; }; prop3: { type: "string"; }; prop4: { type: "string"; }; ... 4 more ...; prop9: { ...; }; }; indexes: { ...; }; }, { ...; }>'.

Check failure on line 3834 in test/ts_connected.entity.spec.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Property 'initialValues' does not exist on type 'Item<string, string, string, { model: { entity: string; service: string; version: string; }; attributes: { prop1: { type: "string"; }; prop2: { type: "string"; }; prop3: { type: "string"; }; prop4: { type: "string"; }; ... 4 more ...; prop9: { ...; }; }; indexes: { ...; }; }, { ...; }>'.
let invocations: ConditionArguments[] = [];
let allow = false;
const condition = (args: ConditionArguments) => {
invocations.push(args);
return allow;
}


const initialValues = {
prop3: 'val3',
prop4: 'val4',
prop5: 'val5',
};
expect(props).to.not.deep.equal(initialValues);

const entity = createTestEntity(condition);

Expand Down

0 comments on commit d669625

Please sign in to comment.