Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/@cdklabs/tskb/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ export class Database<ES extends object, RS extends object> {
}
if (!!proto && typeof proto === 'object' && !!x && typeof x === 'object') {
for (const [k, v] of Object.entries(proto)) {
hydrate(v, (x as any)[k]);
const dehydratedData = (x as any)[k];
if (dehydratedData !== undefined) {
// May be missing if this is from a database created from an old version of the schema
hydrate(v, dehydratedData);
}
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions packages/@cdklabs/tskb/test/entity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ describe.each([false, true])('database is filled with one item (saveAndLoad: %p)
});
});

test('can dehydrate from a data where the collection is missing without crashing', () => {
db.load({
idCtr: 1,
schema: {},
});
});

describe.each([false, true])('database is filled with multiple items (saveAndLoad: %p)', (saveAndLoad) => {
beforeEach(() => {
db.allocate('thing', {
Expand Down
7 changes: 7 additions & 0 deletions packages/@cdklabs/tskb/test/relationship.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ beforeEach(() => {
db = emptyDatabase();
});

test('can dehydrate from a data where the collections are missing without crashing', () => {
db.load({
idCtr: 1,
schema: {},
});
});

describe.each([false, true])('database with some entities (saveAndLoad: %p)', (saveAndLoad) => {
beforeEach(() => {
const a = db.allocate('thing', {
Expand Down