kopia lustrzana https://github.com/FacilMap/facilmap
Rename pad to map in socket methods
rodzic
24b4c3bf96
commit
fe74eab306
|
@ -395,15 +395,15 @@ class Client {
|
|||
}
|
||||
|
||||
async getMap(data: GetMapQuery): Promise<FindMapsResult | null> {
|
||||
return await this._emit("getPad", data);
|
||||
return await this._emit("getMap", data);
|
||||
}
|
||||
|
||||
async findMaps(data: FindMapsQuery): Promise<PagedResults<FindMapsResult>> {
|
||||
return await this._emit("findPads", data);
|
||||
return await this._emit("findMaps", data);
|
||||
}
|
||||
|
||||
async createMap(data: MapData<CRU.CREATE>): Promise<MultipleEvents<SocketEvents<SocketVersion.V3>>> {
|
||||
const obj = await this._emit("createPad", data);
|
||||
const obj = await this._emit("createMap", data);
|
||||
this._set(this.state, 'serverError', undefined);
|
||||
this._set(this.state, 'readonly', false);
|
||||
this._set(this.state, 'writable', 2);
|
||||
|
@ -412,11 +412,11 @@ class Client {
|
|||
}
|
||||
|
||||
async editMap(data: MapData<CRU.UPDATE>): Promise<MapData> {
|
||||
return await this._emit("editPad", data);
|
||||
return await this._emit("editMap", data);
|
||||
}
|
||||
|
||||
async deleteMap(): Promise<void> {
|
||||
await this._emit("deletePad");
|
||||
await this._emit("deleteMap");
|
||||
}
|
||||
|
||||
async listenToHistory(): Promise<MultipleEvents<SocketEvents<SocketVersion.V3>>> {
|
||||
|
@ -586,7 +586,7 @@ class Client {
|
|||
this._set(this.state, 'serverError', undefined);
|
||||
this._set(this.state, 'mapId', mapId);
|
||||
try {
|
||||
const obj = await this._emit("setPadId", mapId);
|
||||
const obj = await this._emit("setMapId", mapId);
|
||||
this._receiveMultiple(obj);
|
||||
return obj;
|
||||
} catch(err: any) {
|
||||
|
|
|
@ -5,6 +5,7 @@ The websocket on the FacilMap server provides different API versions (implemente
|
|||
## v5.0.0 (API v3)
|
||||
|
||||
* “symbol” was renamed to “icon” everywhere. This applies to `Marker.symbol`, `Type.defaultSymbol`, `Type.symbolFixed`, `Type.fields[].controlSymbol` and `Type.fields[].options[].symbol`.
|
||||
* “pad” was renamed “map” everywhere. This applies to the `padData` and `deletePad` socket events and `getPad` (including its `padId` request property), `findPads`, `createPad`, `editPad`, `deletePad`, `setPadId` client/socket methods.
|
||||
|
||||
## v4.0.0 (API v2)
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@
|
|||
const parsed = parseMapId(mapId, context);
|
||||
|
||||
if (parsed) {
|
||||
const mapInfo = await client.value.getMap({ padId: parsed.mapId });
|
||||
const mapInfo = await client.value.getMap({ mapId: parsed.mapId });
|
||||
if (!mapInfo) {
|
||||
return i18n.t("open-map-dialog.map-not-found-error");
|
||||
}
|
||||
|
|
|
@ -33,18 +33,18 @@ test("Create map (using default values)", async () => {
|
|||
expect(client.mapData).toEqual(expectedMapData);
|
||||
expect(onMapData).toBeCalledTimes(1);
|
||||
expect(onMapData).toHaveBeenCalledWith(expectedMapData);
|
||||
expect(await client.getMap({ padId: createMapData.id })).toEqual(pick(expectedMapData, ["id", "name", "description"]));
|
||||
expect(await client.getMap({ mapId: createMapData.id })).toEqual(pick(expectedMapData, ["id", "name", "description"]));
|
||||
});
|
||||
});
|
||||
|
||||
test("Create pad (using custom values)", async () => {
|
||||
test("Create map (using custom values)", async () => {
|
||||
const client = await openClient();
|
||||
|
||||
const onMapData = vi.fn();
|
||||
client.on("mapData", onMapData);
|
||||
|
||||
await createTemporaryMap(client, {
|
||||
name: "Test pad",
|
||||
name: "Test map",
|
||||
searchEngines: true,
|
||||
description: "Test description",
|
||||
clusterMarkers: true,
|
||||
|
@ -67,11 +67,11 @@ test("Create pad (using custom values)", async () => {
|
|||
expect(client.mapData).toEqual(expectedMapData);
|
||||
expect(onMapData).toBeCalledTimes(1);
|
||||
expect(onMapData).toHaveBeenCalledWith(expectedMapData);
|
||||
expect(await client.getMap({ padId: createMapData.id })).toEqual(pick(expectedMapData, ["id", "name", "description"]));
|
||||
expect(await client.getMap({ mapId: createMapData.id })).toEqual(pick(expectedMapData, ["id", "name", "description"]));
|
||||
});
|
||||
});
|
||||
|
||||
test("Create pad (ID already taken)", async () => {
|
||||
test("Create map (ID already taken)", async () => {
|
||||
const client1 = await openClient();
|
||||
const client2 = await openClient();
|
||||
|
||||
|
@ -96,7 +96,7 @@ test("Create pad (ID already taken)", async () => {
|
|||
});
|
||||
});
|
||||
|
||||
test("Create pad (duplicate IDs)", async () => {
|
||||
test("Create map (duplicate IDs)", async () => {
|
||||
const client = await openClient();
|
||||
|
||||
const newId = generateTestMapId();
|
||||
|
@ -123,7 +123,7 @@ test("Create pad (duplicate IDs)", async () => {
|
|||
}).rejects.toThrowError("have to be different");
|
||||
});
|
||||
|
||||
test("Edit pad", async () => {
|
||||
test("Edit map", async () => {
|
||||
const client = await openClient();
|
||||
|
||||
const onMapData = vi.fn();
|
||||
|
@ -131,7 +131,7 @@ test("Edit pad", async () => {
|
|||
|
||||
await createTemporaryMap(client, {}, async (createMapData, mapData) => {
|
||||
const update = {
|
||||
name: "Test pad",
|
||||
name: "Test map",
|
||||
searchEngines: true,
|
||||
description: "Test description",
|
||||
clusterMarkers: true,
|
||||
|
@ -152,11 +152,11 @@ test("Edit pad", async () => {
|
|||
expect(updatedMapData).toEqual(expectedMapData);
|
||||
expect(client.mapData).toEqual(expectedMapData);
|
||||
expect(onMapData).toHaveBeenLastCalledWith(expectedMapData);
|
||||
expect(await client.getMap({ padId: createMapData.id })).toEqual(pick(expectedMapData, ["id", "name", "description"]));
|
||||
expect(await client.getMap({ mapId: createMapData.id })).toEqual(pick(expectedMapData, ["id", "name", "description"]));
|
||||
});
|
||||
});
|
||||
|
||||
test("Rename pad", async () => {
|
||||
test("Rename map", async () => {
|
||||
const client = await openClient();
|
||||
|
||||
const onMapData = vi.fn();
|
||||
|
@ -180,17 +180,17 @@ test("Rename pad", async () => {
|
|||
expect(client.mapData).toEqual(expectedMapData);
|
||||
expect(onMapData).toHaveBeenLastCalledWith(expectedMapData);
|
||||
|
||||
expect(await client.getMap({ padId: createMapData.id })).toBeNull();
|
||||
expect(await client.getMap({ padId: createMapData.writeId })).toBeNull();
|
||||
expect(await client.getMap({ padId: createMapData.adminId })).toBeNull();
|
||||
expect(await client.getMap({ mapId: createMapData.id })).toBeNull();
|
||||
expect(await client.getMap({ mapId: createMapData.writeId })).toBeNull();
|
||||
expect(await client.getMap({ mapId: createMapData.adminId })).toBeNull();
|
||||
|
||||
expect(await client.getMap({ padId: update.id })).toEqual(pick(expectedMapData, ["id", "name", "description"]));
|
||||
expect(await client.getMap({ padId: update.writeId })).toEqual(pick(expectedMapData, ["id", "name", "description"]));
|
||||
expect(await client.getMap({ padId: update.adminId })).toEqual(pick(expectedMapData, ["id", "name", "description"]));
|
||||
expect(await client.getMap({ mapId: update.id })).toEqual(pick(expectedMapData, ["id", "name", "description"]));
|
||||
expect(await client.getMap({ mapId: update.writeId })).toEqual(pick(expectedMapData, ["id", "name", "description"]));
|
||||
expect(await client.getMap({ mapId: update.adminId })).toEqual(pick(expectedMapData, ["id", "name", "description"]));
|
||||
});
|
||||
});
|
||||
|
||||
test("Rename pad (ID already taken)", async () => {
|
||||
test("Rename map (ID already taken)", async () => {
|
||||
const client1 = await openClient();
|
||||
const client2 = await openClient();
|
||||
|
||||
|
@ -217,7 +217,7 @@ test("Rename pad (ID already taken)", async () => {
|
|||
});
|
||||
});
|
||||
|
||||
test("Rename pad (duplicate IDs)", async () => {
|
||||
test("Rename map (duplicate IDs)", async () => {
|
||||
const client = await openClient();
|
||||
|
||||
await createTemporaryMap(client, {}, async () => {
|
||||
|
@ -246,24 +246,24 @@ test("Rename pad (duplicate IDs)", async () => {
|
|||
});
|
||||
});
|
||||
|
||||
test("Delete pad", async () => {
|
||||
test("Delete map", async () => {
|
||||
const client = await openClient();
|
||||
|
||||
const mapData = getTemporaryMapData(SocketVersion.V3, {});
|
||||
await createTemporaryMap(client, mapData, async () => {
|
||||
expect(client.deleted).toBe(false);
|
||||
|
||||
const result = await client.getMap({ padId: mapData.id });
|
||||
const result = await client.getMap({ mapId: mapData.id });
|
||||
expect(result).toBeTruthy();
|
||||
});
|
||||
|
||||
expect(client.deleted).toBe(true);
|
||||
|
||||
const result = await client.getMap({ padId: mapData.id });
|
||||
const result = await client.getMap({ mapId: mapData.id });
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
test("Open existing pad", async () => {
|
||||
test("Open existing map", async () => {
|
||||
const client1 = await openClient();
|
||||
|
||||
await createTemporaryMap(client1, {}, async (createMapData, mapData) => {
|
||||
|
@ -305,7 +305,7 @@ test("Open existing pad", async () => {
|
|||
});
|
||||
});
|
||||
|
||||
test("Open non-existing pad", async () => {
|
||||
test("Open non-existing map", async () => {
|
||||
const id = generateTestMapId();
|
||||
|
||||
const client1 = new Client(getFacilMapUrl(), id, { reconnection: false });
|
||||
|
@ -323,16 +323,16 @@ test("Open non-existing pad", async () => {
|
|||
expect(client2.serverError?.message).toMatch("does not exist");
|
||||
});
|
||||
|
||||
test("Find pads", async () => {
|
||||
test("Find maps", async () => {
|
||||
const uniqueId = generateTestMapId();
|
||||
|
||||
const client = await openClient();
|
||||
await createTemporaryMap(client, {
|
||||
name: `Test ${uniqueId} pad`,
|
||||
name: `Test ${uniqueId} map`,
|
||||
searchEngines: true
|
||||
}, async (createMapData) => {
|
||||
const expectedFound: PagedResults<FindMapsResult> = {
|
||||
results: [{ id: createMapData.id, name: `Test ${uniqueId} pad`, description: "" }],
|
||||
results: [{ id: createMapData.id, name: `Test ${uniqueId} map`, description: "" }],
|
||||
totalLength: 1
|
||||
};
|
||||
|
||||
|
@ -341,18 +341,18 @@ test("Find pads", async () => {
|
|||
totalLength: 0
|
||||
};
|
||||
|
||||
expect(await client.findMaps({ query: `Test ${uniqueId} pad` })).toEqual(expectedFound);
|
||||
expect(await client.findMaps({ query: `test ${uniqueId} pad` })).toEqual(expectedFound);
|
||||
expect(await client.findMaps({ query: `Te?t ${uniqueId} pad` })).toEqual(expectedFound);
|
||||
expect(await client.findMaps({ query: `Te* ${uniqueId} pad` })).toEqual(expectedFound);
|
||||
expect(await client.findMaps({ query: `Test ${uniqueId} map` })).toEqual(expectedFound);
|
||||
expect(await client.findMaps({ query: `test ${uniqueId} map` })).toEqual(expectedFound);
|
||||
expect(await client.findMaps({ query: `Te?t ${uniqueId} map` })).toEqual(expectedFound);
|
||||
expect(await client.findMaps({ query: `Te* ${uniqueId} map` })).toEqual(expectedFound);
|
||||
expect(await client.findMaps({ query: uniqueId })).toEqual(expectedFound);
|
||||
|
||||
expect(await client.findMaps({ query: `Te ${uniqueId} pad` })).toEqual(expectedNotFound);
|
||||
expect(await client.findMaps({ query: `Te? ${uniqueId} pad` })).toEqual(expectedNotFound);
|
||||
expect(await client.findMaps({ query: `Te% ${uniqueId} pad` })).toEqual(expectedNotFound);
|
||||
expect(await client.findMaps({ query: `Te ${uniqueId} map` })).toEqual(expectedNotFound);
|
||||
expect(await client.findMaps({ query: `Te? ${uniqueId} map` })).toEqual(expectedNotFound);
|
||||
expect(await client.findMaps({ query: `Te% ${uniqueId} map` })).toEqual(expectedNotFound);
|
||||
|
||||
await client.editMap({ searchEngines: false });
|
||||
|
||||
expect(await client.findMaps({ query: `Test ${uniqueId} pad` })).toEqual(expectedNotFound);
|
||||
expect(await client.findMaps({ query: `Test ${uniqueId} map` })).toEqual(expectedNotFound);
|
||||
});
|
||||
});
|
|
@ -36,7 +36,7 @@ test("Default types are added", async () => {
|
|||
defaultMode: '',
|
||||
modeFixed: false,
|
||||
showInLegend: false,
|
||||
mapId: mapData.id
|
||||
padId: mapData.id
|
||||
},
|
||||
{
|
||||
fields: [
|
||||
|
@ -61,7 +61,7 @@ test("Default types are added", async () => {
|
|||
defaultMode: '',
|
||||
modeFixed: false,
|
||||
showInLegend: false,
|
||||
mapId: mapData.id
|
||||
padId: mapData.id
|
||||
}
|
||||
] satisfies Array<Type>;
|
||||
|
||||
|
@ -107,7 +107,7 @@ test("Create type (marker, default settings)", async () => {
|
|||
const expectedType: Type = {
|
||||
...type,
|
||||
id: typeResult.id,
|
||||
mapId: mapData.id,
|
||||
padId: mapData.id,
|
||||
idx: 0,
|
||||
defaultColour: "ff0000",
|
||||
colourFixed: false,
|
||||
|
@ -178,7 +178,7 @@ test("Create type (line, default settings)", async () => {
|
|||
const expectedType: Type = {
|
||||
...type,
|
||||
id: typeResult.id,
|
||||
mapId: mapData.id,
|
||||
padId: mapData.id,
|
||||
idx: 0,
|
||||
defaultColour: "0000ff",
|
||||
colourFixed: false,
|
||||
|
@ -263,7 +263,7 @@ test("Create type (custom settings)", async () => {
|
|||
const expectedType: Type = {
|
||||
...type,
|
||||
id: typeResult.id,
|
||||
mapId: mapData.id
|
||||
padId: mapData.id
|
||||
};
|
||||
|
||||
expect(typeResult).toEqual(expectedType);
|
||||
|
@ -327,7 +327,7 @@ test("Update type", async () => {
|
|||
|
||||
const expectedType: Type = {
|
||||
...update,
|
||||
mapId: mapData.id,
|
||||
padId: mapData.id,
|
||||
type: "marker"
|
||||
};
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ export default class DatabaseTypes {
|
|||
for (const obj of newIndexes) {
|
||||
if ((typeId == null || obj.id !== typeId) && obj.oldIdx !== obj.newIdx) {
|
||||
const result = await this._db.helpers._updateMapObject<Type>("Type", mapId, obj.id, { idx: obj.newIdx }, true);
|
||||
this._db.emit("type", result.mapId, result);
|
||||
this._db.emit("type", result.padId, result);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,7 @@ export default class DatabaseTypes {
|
|||
...data,
|
||||
idx
|
||||
});
|
||||
this._db.emit("type", createdType.mapId, createdType);
|
||||
this._db.emit("type", createdType.padId, createdType);
|
||||
return createdType;
|
||||
}
|
||||
|
||||
|
@ -154,12 +154,12 @@ export default class DatabaseTypes {
|
|||
}
|
||||
|
||||
const result = await this._db.helpers._updateMapObject<Type>("Type", mapId, typeId, data);
|
||||
this._db.emit("type", result.mapId, result);
|
||||
this._db.emit("type", result.padId, result);
|
||||
|
||||
if(Object.keys(rename).length > 0)
|
||||
await this._db.helpers.renameObjectDataField(mapId, result.id, rename, result.type == "line");
|
||||
|
||||
await this.recalculateObjectStylesForType(result.mapId, typeId, result.type == "line");
|
||||
await this.recalculateObjectStylesForType(result.padId, typeId, result.type == "line");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ import { SocketVersion, type SocketEvents, type MultipleEvents, type FindOnMapRe
|
|||
import { mapMultipleEvents, type SocketConnection, type SocketHandlers } from "./socket-common";
|
||||
import { SocketConnectionV3 } from "./socket-v3";
|
||||
import type Database from "../database/database";
|
||||
import { omit } from "lodash-es";
|
||||
|
||||
function prepareEvent(...args: SocketServerToClientEmitArgs<SocketVersion.V3>): Array<SocketServerToClientEmitArgs<SocketVersion.V2>> {
|
||||
if (args[0] === "marker") {
|
||||
|
@ -55,25 +56,30 @@ export class SocketConnectionV2 implements SocketConnection<SocketVersion.V2> {
|
|||
}
|
||||
|
||||
getSocketHandlers(): SocketHandlers<SocketVersion.V2> {
|
||||
const socketHandlers = this.socketV3.getSocketHandlers();
|
||||
const socketHandlersV3 = this.socketV3.getSocketHandlers();
|
||||
|
||||
return {
|
||||
...socketHandlers,
|
||||
...omit(socketHandlersV3, ["getMap", "findMaps", "createMap", "editMap", "deleteMap", "setMapId"]),
|
||||
|
||||
addMarker: async (marker) => currentMarkerToLegacyV2(await socketHandlers.addMarker(legacyV2MarkerToCurrent(marker))),
|
||||
editMarker: async (marker) => currentMarkerToLegacyV2(await socketHandlers.editMarker(legacyV2MarkerToCurrent(marker))),
|
||||
addType: async (type) => currentTypeToLegacyV2(await socketHandlers.addType(legacyV2TypeToCurrent(type))),
|
||||
editType: async (type) => currentTypeToLegacyV2(await socketHandlers.editType(legacyV2TypeToCurrent(type))),
|
||||
addMarker: async (marker) => currentMarkerToLegacyV2(await socketHandlersV3.addMarker(legacyV2MarkerToCurrent(marker))),
|
||||
editMarker: async (marker) => currentMarkerToLegacyV2(await socketHandlersV3.editMarker(legacyV2MarkerToCurrent(marker))),
|
||||
addType: async (type) => currentTypeToLegacyV2(await socketHandlersV3.addType(legacyV2TypeToCurrent(type))),
|
||||
editType: async (type) => currentTypeToLegacyV2(await socketHandlersV3.editType(legacyV2TypeToCurrent(type))),
|
||||
|
||||
updateBbox: async (bbox) => prepareMultiple(await socketHandlers.updateBbox(bbox)),
|
||||
createPad: async (mapData) => prepareMultiple(await socketHandlers.createPad(mapData)),
|
||||
listenToHistory: async (data) => prepareMultiple(await socketHandlers.listenToHistory(data)),
|
||||
revertHistoryEntry: async (entry) => prepareMultiple(await socketHandlers.revertHistoryEntry(entry)),
|
||||
getMarker: async (data) => currentMarkerToLegacyV2(await socketHandlers.getMarker(data)),
|
||||
deleteMarker: async (data) => currentMarkerToLegacyV2(await socketHandlers.deleteMarker(data)),
|
||||
findOnMap: async (data) => (await socketHandlers.findOnMap(data)).map((result) => prepareMapResultOutput(result)),
|
||||
deleteType: async (data) => currentTypeToLegacyV2(await socketHandlers.deleteType(data)),
|
||||
setPadId: async (mapId) => prepareMultiple(await socketHandlers.setPadId(mapId))
|
||||
getPad: async (data) => await socketHandlersV3.getMap({ mapId: data.padId }),
|
||||
findPads: async (data) => await socketHandlersV3.findMaps(data),
|
||||
createPad: async (mapData) => prepareMultiple(await socketHandlersV3.createMap(mapData)),
|
||||
editPad: async (mapData) => await socketHandlersV3.editMap(mapData),
|
||||
deletePad: async (data) => await socketHandlersV3.deleteMap(data),
|
||||
setPadId: async (mapId) => prepareMultiple(await socketHandlersV3.setMapId(mapId)),
|
||||
|
||||
updateBbox: async (bbox) => prepareMultiple(await socketHandlersV3.updateBbox(bbox)),
|
||||
listenToHistory: async (data) => prepareMultiple(await socketHandlersV3.listenToHistory(data)),
|
||||
revertHistoryEntry: async (entry) => prepareMultiple(await socketHandlersV3.revertHistoryEntry(entry)),
|
||||
getMarker: async (data) => currentMarkerToLegacyV2(await socketHandlersV3.getMarker(data)),
|
||||
deleteMarker: async (data) => currentMarkerToLegacyV2(await socketHandlersV3.deleteMarker(data)),
|
||||
findOnMap: async (data) => (await socketHandlersV3.findOnMap(data)).map((result) => prepareMapResultOutput(result)),
|
||||
deleteType: async (data) => currentTypeToLegacyV2(await socketHandlersV3.deleteType(data))
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ export class SocketConnectionV3 implements SocketConnection<SocketVersion.V3> {
|
|||
|
||||
getSocketHandlers(): SocketHandlers<SocketVersion.V3> {
|
||||
return {
|
||||
setPadId: async (mapId) => {
|
||||
setMapId: async (mapId) => {
|
||||
if(this.mapId != null)
|
||||
throw new Error(getI18n().t("socket.map-id-set-error"));
|
||||
|
||||
|
@ -159,10 +159,10 @@ export class SocketConnectionV3 implements SocketConnection<SocketVersion.V3> {
|
|||
return await promiseProps(ret);
|
||||
},
|
||||
|
||||
getPad: async (data) => {
|
||||
getMap: async (data) => {
|
||||
this.validatePermissions(Writable.READ);
|
||||
|
||||
const mapData = await this.database.maps.getMapDataByAnyId(data.padId);
|
||||
const mapData = await this.database.maps.getMapDataByAnyId(data.mapId);
|
||||
return mapData && {
|
||||
id: mapData.id,
|
||||
name: mapData.name,
|
||||
|
@ -170,13 +170,13 @@ export class SocketConnectionV3 implements SocketConnection<SocketVersion.V3> {
|
|||
};
|
||||
},
|
||||
|
||||
findPads: async (data) => {
|
||||
findMaps: async (data) => {
|
||||
this.validatePermissions(Writable.READ);
|
||||
|
||||
return this.database.maps.findMaps(data);
|
||||
},
|
||||
|
||||
createPad: async (data) => {
|
||||
createMap: async (data) => {
|
||||
this.validatePermissions(Writable.READ);
|
||||
|
||||
if(this.mapId)
|
||||
|
@ -192,7 +192,7 @@ export class SocketConnectionV3 implements SocketConnection<SocketVersion.V3> {
|
|||
return await this.getMapObjects({ ...mapData, writable: Writable.ADMIN });
|
||||
},
|
||||
|
||||
editPad: async (data) => {
|
||||
editMap: async (data) => {
|
||||
this.validatePermissions(Writable.ADMIN);
|
||||
|
||||
if (!isMapId(this.mapId))
|
||||
|
@ -204,7 +204,7 @@ export class SocketConnectionV3 implements SocketConnection<SocketVersion.V3> {
|
|||
};
|
||||
},
|
||||
|
||||
deletePad: async () => {
|
||||
deleteMap: async () => {
|
||||
this.validatePermissions(Writable.ADMIN);
|
||||
|
||||
if (!isMapId(this.mapId))
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
],
|
||||
"dependencies": {
|
||||
"@types/geojson": "^7946.0.14",
|
||||
"lodash-es": "^4.17.21",
|
||||
"zod": "^3.22.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -5,7 +5,7 @@ import { type Line, type TrackPoint } from "../line.js";
|
|||
import * as z from "zod";
|
||||
|
||||
export const getMapQueryValidator = z.object({
|
||||
padId: z.string()
|
||||
mapId: z.string()
|
||||
});
|
||||
export type GetMapQuery = z.infer<typeof getMapQueryValidator>;
|
||||
|
||||
|
|
|
@ -7,10 +7,12 @@ import { requestDataValidatorsV3, type MapEventsV3, type ResponseDataMapV3 } fro
|
|||
import type { CRU, CRUType } from "../cru.js";
|
||||
import * as z from "zod";
|
||||
import type { GenericHistoryEntry, HistoryEntryObjectTypes } from "../historyEntry.js";
|
||||
import { omit } from "lodash-es";
|
||||
|
||||
// Socket v2:
|
||||
// - “icon” is called “symbol” in `Marker.symbol`, `Type.defaultSymbol`, `Type.symbolFixed`, `Type.fields[].controlSymbol` and
|
||||
// `Type.fields[].options[].symbol`.
|
||||
// - “map” is called “pad” in events, types, methods
|
||||
|
||||
export const legacyV2MarkerValidator = {
|
||||
read: markerValidator.read.omit({ icon: true }).extend({ symbol: markerValidator.read.shape.icon }),
|
||||
|
@ -67,15 +69,29 @@ export type LegacyV2HistoryEntry = GenericHistoryEntry<ReplaceProperties<History
|
|||
Type: Omit<LegacyV2Type, "id">;
|
||||
}>>;
|
||||
|
||||
export const legacyV2GetMapQueryValidator = z.object({
|
||||
padId: z.string()
|
||||
});
|
||||
|
||||
export const requestDataValidatorsV2 = {
|
||||
...requestDataValidatorsV3,
|
||||
...omit(requestDataValidatorsV3, ["getMap", "findMaps", "createMap", "editMap", "deleteMap", "setMapId"]),
|
||||
getPad: legacyV2GetMapQueryValidator,
|
||||
findPads: requestDataValidatorsV3.findMaps,
|
||||
createPad: requestDataValidatorsV3.createMap,
|
||||
editPad: requestDataValidatorsV3.editMap,
|
||||
deletePad: requestDataValidatorsV3.deleteMap,
|
||||
setPadId: requestDataValidatorsV3.setMapId,
|
||||
addMarker: legacyV2MarkerValidator.create,
|
||||
editMarker: legacyV2MarkerValidator.update.extend({ id: idValidator }),
|
||||
addType: legacyV2TypeValidator.create,
|
||||
editType: legacyV2TypeValidator.update.extend({ id: idValidator })
|
||||
};
|
||||
|
||||
export type ResponseDataMapV2 = ReplaceProperties<ResponseDataMapV3, {
|
||||
export type ResponseDataMapV2 = ReplaceProperties<Omit<ResponseDataMapV3, "getMap" | "findMaps" | "createMap" | "editMap" | "deleteMap" | "setMapId">, {
|
||||
getPad: ResponseDataMapV3["getMap"];
|
||||
findPads: ResponseDataMapV3["findMaps"];
|
||||
editPad: ResponseDataMapV3["editMap"];
|
||||
deletePad: ResponseDataMapV3["deleteMap"];
|
||||
updateBbox: MultipleEvents<MapEventsV2>;
|
||||
createPad: MultipleEvents<MapEventsV2>;
|
||||
listenToHistory: MultipleEvents<MapEventsV2>;
|
||||
|
|
|
@ -13,11 +13,11 @@ import type { HistoryEntry } from "../historyEntry.js";
|
|||
|
||||
export const requestDataValidatorsV3 = {
|
||||
updateBbox: bboxWithZoomValidator,
|
||||
getPad: getMapQueryValidator,
|
||||
findPads: findMapsQueryValidator,
|
||||
createPad: mapDataValidator.create,
|
||||
editPad: mapDataValidator.update,
|
||||
deletePad: nullOrUndefinedValidator,
|
||||
getMap: getMapQueryValidator,
|
||||
findMaps: findMapsQueryValidator,
|
||||
createMap: mapDataValidator.create,
|
||||
editMap: mapDataValidator.update,
|
||||
deleteMap: nullOrUndefinedValidator,
|
||||
listenToHistory: nullOrUndefinedValidator,
|
||||
stopListeningToHistory: nullOrUndefinedValidator,
|
||||
revertHistoryEntry: objectWithIdValidator,
|
||||
|
@ -44,17 +44,17 @@ export const requestDataValidatorsV3 = {
|
|||
editView: viewValidator.update.extend({ id: idValidator }),
|
||||
deleteView: objectWithIdValidator,
|
||||
geoip: nullOrUndefinedValidator,
|
||||
setPadId: z.string(),
|
||||
setMapId: z.string(),
|
||||
setLanguage: setLanguageRequestValidator
|
||||
};
|
||||
|
||||
export interface ResponseDataMapV3 {
|
||||
updateBbox: MultipleEvents<MapEventsV3>;
|
||||
getPad: FindMapsResult | null;
|
||||
findPads: PagedResults<FindMapsResult>;
|
||||
createPad: MultipleEvents<MapEventsV3>;
|
||||
editPad: MapData & { writable: Writable };
|
||||
deletePad: null;
|
||||
getMap: FindMapsResult | null;
|
||||
findMaps: PagedResults<FindMapsResult>;
|
||||
createMap: MultipleEvents<MapEventsV3>;
|
||||
editMap: MapData & { writable: Writable };
|
||||
deleteMap: null;
|
||||
listenToHistory: MultipleEvents<MapEventsV3>;
|
||||
stopListeningToHistory: null;
|
||||
revertHistoryEntry: MultipleEvents<MapEventsV3>;
|
||||
|
@ -81,7 +81,7 @@ export interface ResponseDataMapV3 {
|
|||
editView: View;
|
||||
deleteView: View;
|
||||
geoip: Bbox | null;
|
||||
setPadId: MultipleEvents<MapEventsV3>;
|
||||
setMapId: MultipleEvents<MapEventsV3>;
|
||||
setLanguage: void;
|
||||
}
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ export const defaultFields = (): Field[] => [ { name: "Description", type: "text
|
|||
export const rawTypeValidator = cruValidator({
|
||||
id: onlyRead(idValidator),
|
||||
type: exceptUpdate(objectTypeValidator),
|
||||
mapId: onlyRead(mapIdValidator),
|
||||
padId: onlyRead(mapIdValidator),
|
||||
|
||||
name: optionalUpdate(z.string().trim().min(1).max(100)),
|
||||
idx: optionalCreate(z.number().int().min(0)),
|
||||
|
|
|
@ -4196,6 +4196,7 @@ __metadata:
|
|||
resolution: "facilmap-types@workspace:types"
|
||||
dependencies:
|
||||
"@types/geojson": ^7946.0.14
|
||||
lodash-es: ^4.17.21
|
||||
rimraf: ^5.0.5
|
||||
typescript: ^5.4.4
|
||||
vite: ^5.2.8
|
||||
|
|
Ładowanie…
Reference in New Issue