fix(infra): recover deleted item in orm (#7359)

This commit is contained in:
EYHN
2024-06-27 17:58:47 +08:00
committed by GitHub
parent 2c92e97c48
commit c6c4ed9711
3 changed files with 52 additions and 1 deletions

View File

@@ -122,4 +122,29 @@ describe('ORM entity CRUD', () => {
const tag2 = client.tags.get(tag.id);
expect(tag2).toBe(null);
});
test('should be able to recover entity', t => {
const { client } = t;
client.tags.create({
id: '1',
name: 'test',
color: 'red',
});
client.tags.delete('1');
client.tags.create({
id: '1',
name: 'test',
color: 'red',
});
const tag = client.tags.get('1');
expect(tag).toEqual({
id: '1',
name: 'test',
color: 'red',
});
});
});

View File

@@ -118,6 +118,31 @@ describe('ORM entity CRUD', () => {
expect(tag2).toBe(null);
});
test('should be able to recover entity', t => {
const { client } = t;
client.tags.create({
id: '1',
name: 'test',
color: 'red',
});
client.tags.delete('1');
client.tags.create({
id: '1',
name: 'test',
color: 'red',
});
const tag = client.tags.get('1');
expect(tag).toEqual({
id: '1',
name: 'test',
color: 'red',
});
});
test('should be able to list keys', t => {
const { client } = t;

View File

@@ -57,6 +57,7 @@ export class YjsTableAdapter implements TableAdapter {
}
this.keyBy(record, key);
record.set(this.deleteFlagKey, false);
}, this.origin);
this.markCacheStaled();
@@ -148,7 +149,7 @@ export class YjsTableAdapter implements TableAdapter {
}
private isDeleted(record: YMap<any>) {
return record.has(this.deleteFlagKey);
return record.get(this.deleteFlagKey) === true;
}
private record(key: Key) {