Skip to content

Commit

Permalink
Cleanup and null cursor fix (#341)
Browse files Browse the repository at this point in the history
* Remove drop table in init.js

* Updates changelog, bumps patch version

* Fixes cursor returned as `undefined`
Collection queries returned an `undefined` cursor (currently typed as `string | null`) when using the `raw:true` execution option. Fixed to return `null` instead of `undefined`.

* Adds null cursor tests
  • Loading branch information
tywalch authored Dec 26, 2023
1 parent 346a15a commit eb6254a
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 7 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ All notable changes to this project will be documented in this file. Breaking ch
- Addresses edge case that filtered valid items when item lacked entity identifiers (created outside ElectroDB) when keys (pk or sk) were numeric.

## [2.10.4] - 2023-10-26
> NOTE: This version is depricated, this version introduced code that significantly increased latency. That code was fixed in `2.10.7`
> NOTE: This version is deprecated, this version introduced code that significantly increased latency. That code was fixed in `2.10.7`
### Added
- Adds `cause` property to `ElectroError`, currently populated when error originates from the AWS Client, to help with error triage. This also adds the ability to provide an error type to ElectroError<Error> to type the error located on `cause`.

Expand All @@ -498,8 +498,13 @@ All notable changes to this project will be documented in this file. Breaking ch

## [2.12.1] - 2023-11-29
### Fixed
- Adds more sophisticated custom attribute type extraction. Patch provided by github user @wentsul with an assist by @adriancooney via [PR #332](https://github.com/tywalch/electrodb/pull/334). Thank you both for this great addition!
- Adds more sophisticated custom attribute type extraction. Patch provided by GitHub user @wentsul with an assist by @adriancooney via [PR #332](https://github.com/tywalch/electrodb/pull/334). Thank you both for this great addition!

## [2.12.2] - 2023-12-18
### Fixed
- Fixes bug where `scan` appended invalid filters if some cases. In cases where [attributes are used as keys](https://electrodb.dev/en/modeling/indexes/#attributes-as-indexes) or [composite templates contain no prefixes](https://electrodb.dev/en/modeling/indexes/#composite-attribute-templates) the `scan` operation would append invalid filters to parameters. This bug was identified by discord user @engi22, thank you!
- Fixes bug where `scan` appended invalid filters if some cases. In cases where [attributes are used as keys](https://electrodb.dev/en/modeling/indexes/#attributes-as-indexes) or [composite templates contain no prefixes](https://electrodb.dev/en/modeling/indexes/#composite-attribute-templates) the `scan` operation would append invalid filters to parameters. This bug was identified by discord user @engi22, thank you!

## [2.12.3] - 2023-12-26
### Fixed
- Collection queries returned an `undefined` cursor (currently typed as `string | null`) when using the `raw:true` execution option. Fixed to return `null` instead of `undefined`.
- Removed superfluous and unused files, `./library-data.json` and `test.csv`, accidentally published in version `2.12.2`.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "electrodb",
"version": "2.12.2",
"version": "2.12.3",
"description": "A library to more easily create and interact with multiple entities and heretical relationships in dynamodb",
"main": "index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ class Entity {
collection(collection = "", clauses = {}, facets = {}, options = {}) {
const chainOptions = {
...options,
_isPagination: true,
_isCollectionQuery: true,
};

Expand Down
87 changes: 87 additions & 0 deletions test/connected.page.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,93 @@ describe("Page", () => {
} while (cursor !== null);
}).timeout(10000);

describe('null cursors', () => {
const entity1 = new Entity({
model: {
entity: uuid(),
version: '1',
service: 'null-cursor',
},
attributes: {
id: {
type: 'string'
}
},
indexes: {
record: {
collection: 'test',
pk: {
field: 'pk',
composite: ['id'],
},
sk: {
field: 'sk',
composite: [],
}
}
}
}, { table, client });
const entity2 = new Entity({
model: {
entity: uuid(),
version: '1',
service: 'null-cursor',
},
attributes: {
id: {
type: 'string'
}
},
indexes: {
record: {
collection: 'test',
pk: {
field: 'pk',
composite: ['id'],
},
sk: {
field: 'sk',
composite: [],
}
}
}
}, { table, client });

const service = new Service({ entity1, entity2 });

const id = uuid();
const queries = [
['query operation using default execution options', () => entity1.query.record({ id }).go()],
['query operation with raw flag', () => entity1.query.record({ id }).go({ raw: true })],
['query operation with includeKeys flag', () => entity1.query.record({ id }).go({ includeKeys: true })],
['query operation with ignoreOwnership flag', () => entity1.query.record({ id }).go({ ignoreOwnership: true })],
// ['scan query using default execution options', () => entity1.scan.go()],
// ['scan query with raw flag', () => entity1.scan.go({ raw: true })],
// ['scan query with includeKeys flag', () => entity1.scan.go({ includeKeys: true })],
// ['scan query with ignoreOwnership flag', () => entity1.scan.go({ ignoreOwnership: true })],
['match query using default execution options', () => entity1.match({ id }).go()],
['match query with raw flag', () => entity1.match({ id }).go({ raw: true })],
['match query with includeKeys flag', () => entity1.match({ id }).go({ includeKeys: true })],
['match query with ignoreOwnership flag', () => entity1.match({ id }).go({ ignoreOwnership: true })],
['find query using default execution options', () => entity1.find({ id }).go()],
['find query with raw flag', () => entity1.find({ id }).go({ raw: true })],
['find query with includeKeys flag', () => entity1.find({ id }).go({ includeKeys: true })],
['find query with ignoreOwnership flag', () => entity1.find({ id }).go({ ignoreOwnership: true })],
['collection query using default execution options', () => service.collections.test({ id }).go()],
['collection query with raw flag', () => service.collections.test({ id }).go({ raw: true })],
['collection query with includeKeys flag', () => service.collections.test({ id }).go({ includeKeys: true })],
['collection query with ignoreOwnership flag', () => service.collections.test({ id }).go({ ignoreOwnership: true })],
];

for (const [variation, query] of queries) {
it(`should return a null cursor when performing ${variation}`, async () => {
const { cursor } = await query();
expect(cursor).to.be.null;
});
}
});


// it("Should not accept incomplete page composite attributes", async () => {
// let tests = [
// {
Expand Down
5 changes: 2 additions & 3 deletions test/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ async function createTable(dynamodb, table, definition) {
if (configuration.endpoint !== undefined) {
let tableManager = createTableManager(dynamodb, table);
let exists = await tableManager.exists();
if (exists) {
await tableManager.drop();
if (!exists) {
await tableManager.create(definition);
}
await tableManager.create(definition);
} else {
// make sure we're hitting dynamodb local
// (this code is only for tests and experimentation)
Expand Down

0 comments on commit eb6254a

Please sign in to comment.