feat(dynamodb): complete the helper module and add toSubscriptionFilter - #300
Merged
Conversation
The `@aws-appsync/utils/dynamodb` module implemented `get`, `put`, `remove`, `scan`, `update` and `operations`, and those dropped most of their arguments: a `filter` or `projection` handed to `scan` was passed through raw instead of being turned into an expression, and `condition`, `consistentRead`, `projection` and `_version` were silently discarded everywhere else. Adds `query`, `sync`, `batchGet`, `batchPut`, `batchDelete`, `transactGet`, `transactWrite`, the module level set helpers, and `operations.remove` / `operations.updateListItem`, and completes the arguments of the helpers that already existed. The update expression builder was also wrong for anything but a single operation: it joined clauses with a bare comma and repeated the `SET` keyword per clause, where AWS emits one keyword per group, `SET` before `REMOVE`, with the aliases numbered in the order the clauses come out. `util.transform.toSubscriptionFilter` is new, expanding a filter into the disjunctive normal form AppSync delivers subscriptions against, and `util.dynamodb.fromS3ObjectJson` now parses the JSON string form instead of throwing, which un-skips its test. Everything is recorded from `EvaluateCode`. The published types proved wrong in three places along the way: `toNumberSet` does not stringify, a `condition` carries no `returnValuesOnConditionCheckFailure`, and `sync` is accepted despite the stale comment claiming otherwise. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
@aws-appsync/utils/dynamodbmodule implementedget,put,remove,scan,updateandoperations, and those dropped most of their arguments. Afilterorprojectionhanded toscanwas passed through raw rather than turned into an expression, andcondition,consistentRead,projectionand_versionwere discarded everywhere else.The update expression builder was also wrong for anything but a single operation: it joined clauses with a bare comma and repeated the
SETkeyword per clause. AWS emits one keyword per group,SETbeforeREMOVE, with aliases numbered in the order the clauses come out rather than the order they were written. The existing snapshots never caught it because every one of them used a single operation.What this adds
query,sync,batchGet,batchPut,batchDelete,transactGet,transactWrite, the module-level set helpers, andoperations.remove/operations.updateListItem, plus the missing arguments on the helpers that already existed.util.transform.toSubscriptionFilteris new. It expands a filter into the disjunctive normal form subscriptions are delivered against: every operator of a field, every member of anorand every rule is an alternative, so the groups multiply out. Unlike the DynamoDB transforms it answers an object rather than a JSON string.util.dynamodb.fromS3ObjectJsonnow parses the JSON string form instead of throwing, which un-skips its test.The expression builder that already backed
util.transformis reused rather than duplicated: it now also exposes the expression as an object, which is the form a request embeds.Recorded, not inferred
Everything here comes from
EvaluateCode, and the published type definitions turned out wrong in three places:toNumberSet([1,2,3])gives{"NS":[1,2,3]}, not the stringified["1","2","3"]the JSDoc shows.conditioncarries noreturnValuesOnConditionCheckFailure, although the type marks it required.syncis accepted. The comment claiming AWS rejects it, and the test skipped on that basis, were stale.Also recorded: a projection aliases every path segment, so
nested.fieldbecomes#expName_2.#expName_3; an expression that binds no value carries noexpressionValuesat all, while an update expression keeps an empty one; andincrement()with no argument steps by one.Tests
42 new snapshots recorded from
EvaluateCode, covering each helper minimally and fully argued, the update clause grouping and alias numbering, projections that reuse a path segment, and the subscription filter across its operators, nesting,ignoredFields,rulesand the inputs it cannot read.syncandfromS3ObjectJsonare un-skipped.npm test: 412 passed, 1 skipped, 404 snapshots. A probe comparing all 63 recorded inputs against the implementation reports no mismatches, andtest_in_docker.shstill installs and imports.The one remaining skip is
operations.updateListItemreturned on its own: AWS answers an opaque value for that marker alone, with no enumerable keys, serialising to nothing, so it cannot be compared. What it builds is covered by theupdatetests.One divergence worth knowing
Clauses come out in the order the fields were written. AWS orders them by its own object iteration, which for some sets of field names is neither the written order nor sorted, so a condition over several fields can be joined in a different order there.
ANDcommutes, so the two mean the same thing, and it is noted in the code.🤖 Generated with Claude Code