Rename and refactor the types passed over the API to be based on an entity that's either living or a tombstone. A living entity has a deleted property that's either undefined or false, while a tombstone has a deleted property set to true. All entities have a numeric id and an updatedAt timestamp. To sync entities, an array of replacements are passed around. Living entities are replaced with tombstones when they're deleted. And tombstones are replaced with living entities when restored.
17 lines
502 B
TypeScript
17 lines
502 B
TypeScript
import type { LocationQueryValue } from 'vue-router';
|
|
|
|
export function queryToString(item?: null | LocationQueryValue | LocationQueryValue[]) {
|
|
if (item === null)
|
|
return "";
|
|
if (item instanceof Array)
|
|
return queryToString(item[0])
|
|
return item;
|
|
}
|
|
|
|
export function queryToNumber(item?: null | LocationQueryValue | LocationQueryValue[]) {
|
|
if (item === null || item === undefined)
|
|
return undefined;
|
|
if (item instanceof Array)
|
|
return queryToNumber(item[0])
|
|
return Number.parseInt(item, 10);
|
|
}
|