Remove type from Api serialisation of ClientMap
All checks were successful
/ build (push) Successful in 1m34s
/ deploy (push) Successful in 16s

Move the logic that converts the EntityClass of a map to a string and
then back into the class to the payload plugin in order to avoid a
circular dependency where the ClientMap needs to know the entity classes
and the entity classes needs to know the ClientMap.

The only place that doesn't know the type of the entities stored in the
client map is the payload reviver, so it makes sense to keep this logic
contained to the payload plugin.
This commit is contained in:
Hornwitser 2025-06-23 18:17:23 +02:00
parent 930d93a95f
commit d48fb035b4
4 changed files with 70 additions and 91 deletions

View file

@ -27,34 +27,31 @@ function fixtureClientMap() {
);
}
function fixtureApiMap(): ApiMap<ApiUser> {
return {
type: "user",
entities: [
{
id: 1,
updatedAt: nowIso,
name: "A",
type: "regular",
},
{
id: 2,
updatedAt: nowIso,
name: "B",
type: "regular",
},
{
id: 5,
updatedAt: nowIso,
deleted: true,
},
],
};
function fixtureApiMap(): ApiUser[] {
return [
{
id: 1,
updatedAt: nowIso,
name: "A",
type: "regular",
},
{
id: 2,
updatedAt: nowIso,
name: "B",
type: "regular",
},
{
id: 5,
updatedAt: nowIso,
deleted: true,
},
];
}
describe("class ClientMap", () => {
test("load from api", () => {
const map = ClientMap.fromApi(fixtureApiMap(), { zone, locale })
const map = ClientMap.fromApi(ClientUser, fixtureApiMap(), { zone, locale })
expect(map).toStrictEqual(fixtureClientMap());
});
@ -202,7 +199,7 @@ describe("class ClientMap", () => {
} else {
throw new Error(`Unknown action pattern ${action}`)
}
map.apiUpdate({ type: "user", entities: [update] }, { zone, locale });
map.apiUpdate([update], { zone, locale });
// Check
const expectedUser = userFromPattern(expectedPattern, useSameTimestamp);
const expectedTomb = tombFromPattern(expectedPattern, useSameTimestamp);
@ -243,7 +240,7 @@ describe("class ClientMap", () => {
} else {
throw new Error(`Unknown action pattern ${action}`)
}
map.apiUpdate({ type: "user", entities: [update] }, { zone, locale });
map.apiUpdate([update], { zone, locale });
// Check
const expectedUser = userFromPattern(startPattern, useSameTimestamp);
const expectedTomb = tombFromPattern(startPattern, useSameTimestamp);