mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-23 20:18:42 +08:00
fix(infra): recover deleted item in orm (#7359)
This commit is contained in:
@@ -122,4 +122,29 @@ describe('ORM entity CRUD', () => {
|
|||||||
const tag2 = client.tags.get(tag.id);
|
const tag2 = client.tags.get(tag.id);
|
||||||
expect(tag2).toBe(null);
|
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',
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -118,6 +118,31 @@ describe('ORM entity CRUD', () => {
|
|||||||
expect(tag2).toBe(null);
|
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 => {
|
test('should be able to list keys', t => {
|
||||||
const { client } = t;
|
const { client } = t;
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ export class YjsTableAdapter implements TableAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.keyBy(record, key);
|
this.keyBy(record, key);
|
||||||
|
record.set(this.deleteFlagKey, false);
|
||||||
}, this.origin);
|
}, this.origin);
|
||||||
|
|
||||||
this.markCacheStaled();
|
this.markCacheStaled();
|
||||||
@@ -148,7 +149,7 @@ export class YjsTableAdapter implements TableAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private isDeleted(record: YMap<any>) {
|
private isDeleted(record: YMap<any>) {
|
||||||
return record.has(this.deleteFlagKey);
|
return record.get(this.deleteFlagKey) === true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private record(key: Key) {
|
private record(key: Key) {
|
||||||
|
|||||||
Reference in New Issue
Block a user