mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 16:33:16 +00:00
fix(ci): repair server and shared gates after the place identities change
Push run 46275645144 on dev (f69a4c1a2) was red in these jobs:
- Server types: UserPlacesRepository.create, UserPlaceMergesRepository.create
and UserPlaceLinksRepository.insert shadowed MikroORM's EntityRepository
methods with other signatures (TS2416), which also broke defineEntity on the
three entities (TS2769). They are createOwn, record and insertUses now.
- Server lint: collections.service.ts had grown to 1411 lines against 1410.
The trip tag lookup of a copy moved into collections.helpers.ts
(tripTagIdsOf, tagKeyOf); the size baseline is lowered to the 1398 it holds.
- ASTCAP-001/002/005b: the trip chat core had taken in PlacesLibraryMcp,
PlaceIdentitiesMcp and TripCollectionsMcp, so core and the tours group
offered 132 tools against 128. They load with the collections group now.
- PLIB-001, PLIB-MCP-001 and the places library e2e: the two entries named
Museum tie on the name and go by their anchor, which the expected order
hard coded the other way. The fixture orders every tie by its anchors.
- ENT-003 and CLASSFIELD-002: the five new entities and their 18 NOT NULL
columns without a default are counted.
- Shared tests: collections.ratingBadge was missing in 26 locales; each has
its translation now.
This commit is contained in:
@@ -54,7 +54,7 @@ export class UserPlaceLinksRepository extends TrekRepository<UserPlaceLinks> {
|
||||
}
|
||||
|
||||
/** Links uses no own place of the user holds (`detach` first) to `userPlaceId`; answers the new ids. */
|
||||
async insert(
|
||||
async insertUses(
|
||||
userId: number,
|
||||
userPlaceId: number,
|
||||
uses: readonly LinkedUse[],
|
||||
|
||||
@@ -18,7 +18,7 @@ export class UserPlaceMergesRepository extends TrekRepository<UserPlaceMerges> {
|
||||
return this.kysely<UserPlaceMergesDB>();
|
||||
}
|
||||
|
||||
async create(userId: number, leadingId: number, mergedId: number, movedLinkIds: string): Promise<number> {
|
||||
async record(userId: number, leadingId: number, mergedId: number, movedLinkIds: string): Promise<number> {
|
||||
const row = await this.db()
|
||||
.insertInto('user_place_merges')
|
||||
.values({ user_id: userId, leading_id: leadingId, merged_id: mergedId, moved_link_ids: movedLinkIds })
|
||||
|
||||
@@ -38,7 +38,7 @@ export class UserPlacesRepository extends TrekRepository<UserPlaces> {
|
||||
return this.kysely<UserPlacesDB>();
|
||||
}
|
||||
|
||||
async create(userId: number, facts: UserPlaceFacts): Promise<number> {
|
||||
async createOwn(userId: number, facts: UserPlaceFacts): Promise<number> {
|
||||
const row = await this.db()
|
||||
.insertInto('user_places')
|
||||
.values({ user_id: userId, ...facts })
|
||||
|
||||
@@ -396,8 +396,11 @@ const CORE_TOOL_GROUPS: ToolGroups = {
|
||||
controllers: ['AtlasMcp', 'AtlasGlobeMcp', 'DawarichAtlasMcp'],
|
||||
},
|
||||
collections: {
|
||||
about: 'Collections: saved places across trips, their labels and ratings.',
|
||||
controllers: ['CollectionsMcp'],
|
||||
about:
|
||||
'Collections and all places: saved places across trips, their labels and ratings, every place of the user ' +
|
||||
'in one library, the places that are one and the same (linking, merging and undoing a merge, duplicates) ' +
|
||||
'and the lists linked to this trip.',
|
||||
controllers: ['CollectionsMcp', 'PlacesLibraryMcp', 'PlaceIdentitiesMcp', 'TripCollectionsMcp'],
|
||||
},
|
||||
collab: {
|
||||
about: 'Trip chat: notes, polls, shared links and messages to the people on the trip.',
|
||||
|
||||
@@ -168,3 +168,29 @@ export function placeOrderOf(current: number[], requested: number[]): number[] |
|
||||
if (named.size !== requested.length || requested.some((id) => !held.has(id))) return null;
|
||||
return [...requested, ...current.filter((id) => !named.has(id))];
|
||||
}
|
||||
|
||||
/** How a trip tag name is compared: trimmed and in lower case. */
|
||||
export function tagKeyOf(name: string): string {
|
||||
return name.trim().toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* The trip's own tag of each name, in the order of `tags`: the one `known`
|
||||
* holds, or one `makeTag` makes now (once per name). `known` keeps the new
|
||||
* ones, so the next place of the same copy reuses them.
|
||||
*/
|
||||
export async function tripTagIdsOf(
|
||||
tags: { name: string; color: string }[],
|
||||
known: Map<string, number>,
|
||||
makeTag: (name: string, color: string) => Promise<number>,
|
||||
): Promise<number[]> {
|
||||
const missing = new Map(tags.filter((t) => !known.has(tagKeyOf(t.name))).map((t) => [tagKeyOf(t.name), t]));
|
||||
const made = await Promise.all(
|
||||
[...missing.entries()].map(async ([key, { name, color }]) => [key, await makeTag(name.trim(), color)] as const),
|
||||
);
|
||||
for (const [key, id] of made) known.set(key, id);
|
||||
return tags.flatMap(({ name }): number[] => {
|
||||
const id = known.get(tagKeyOf(name));
|
||||
return id === undefined ? [] : [id];
|
||||
});
|
||||
}
|
||||
|
||||
@@ -72,7 +72,8 @@ import { NotificationsService } from '../notifications/notifications.service';
|
||||
import { PlaceImportService, type ExportedCollectionFile } from '../place-import/place-import.service';
|
||||
import { UnitOfWork } from '../database/unit-of-work';
|
||||
import {
|
||||
filePlaceOf, groupByPid, listingWriteOf, parseLinks, placeOrderOf, serializeLinks, tripDedupSet, tripPlaceFields,
|
||||
filePlaceOf, groupByPid, listingWriteOf, parseLinks, placeOrderOf, serializeLinks, tagKeyOf, tripDedupSet, tripPlaceFields,
|
||||
tripTagIdsOf,
|
||||
} from './collections.helpers';
|
||||
|
||||
// Errors: a DomainError carrying a status; TrekExceptionFilter maps it to that code with an `{ error }` body.
|
||||
@@ -1075,7 +1076,7 @@ export class CollectionsService {
|
||||
const skipped: { id: number; name: string }[] = [];
|
||||
// The whole copy is one logical write — atomic since the post-fold quirk pass.
|
||||
await this.uow.transactional(async () => {
|
||||
if (carried) for (const t of await this.tags.listByTrip(body.trip_id)) tripTags.set(t.name.trim().toLowerCase(), t.id);
|
||||
if (carried) for (const t of await this.tags.listByTrip(body.trip_id)) tripTags.set(tagKeyOf(t.name), t.id);
|
||||
tagsBefore = tripTags.size;
|
||||
for (const s of sources) {
|
||||
if (!body.force && isPlaceDuplicate({
|
||||
@@ -1093,7 +1094,9 @@ export class CollectionsService {
|
||||
image_url: s.image_url, google_place_id: s.google_place_id, google_ftid: s.google_ftid,
|
||||
website: s.website, phone: s.phone, osm_id: s.osm_id,
|
||||
});
|
||||
await this.tags.insertIgnore(newPlaceId, await this.tripTagIds(body.trip_id, userId, carried?.[s.id] ?? [], tripTags));
|
||||
const tagIds = await tripTagIdsOf(carried?.[s.id] ?? [], tripTags, async (name, color) =>
|
||||
(await this.tags.createTag({ user_id: userId, trip_id: body.trip_id, name, color })).id);
|
||||
await this.tags.insertIgnore(newPlaceId, tagIds);
|
||||
// Ratings of trip members travel along (#1435); nothing is mirrored back.
|
||||
const votes = await this.collectionPlaceRatings.listForPlace(s.id);
|
||||
for (const v of votes) if (tripMemberIds.has(v.user_id)) await this.tripPlaceRatings.insertIgnore(newPlaceId, v.user_id, v.rating);
|
||||
@@ -1110,19 +1113,6 @@ export class CollectionsService {
|
||||
return { copied: created.length, skipped, created };
|
||||
}
|
||||
|
||||
/** The trip's own tag of each name: the one it has, or one made now; `known` keeps the new ones for the next place. */
|
||||
private async tripTagIds(tripId: number, userId: number, tags: { name: string; color: string }[], known: Map<string, number>): Promise<number[]> {
|
||||
const keyOf = (name: string) => name.trim().toLowerCase();
|
||||
const missing = [...new Map(tags.filter(t => !known.has(keyOf(t.name))).map(t => [keyOf(t.name), t])).entries()];
|
||||
const made = await Promise.all(missing.map(async ([key, { name, color }]) =>
|
||||
[key, (await this.tags.createTag({ user_id: userId, trip_id: tripId, name: name.trim(), color })).id] as const));
|
||||
for (const [key, id] of made) known.set(key, id);
|
||||
return tags.flatMap(({ name }): number[] => {
|
||||
const id = known.get(keyOf(name));
|
||||
return id === undefined ? [] : [id];
|
||||
});
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Library-wide membership lookup (inspector indicator)
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@@ -81,7 +81,7 @@ export class PlaceIdentitiesService {
|
||||
const target =
|
||||
request.identity_id === undefined ? { facts: await this.factsOfUse(reach, first) } : { id: request.identity_id };
|
||||
const identityId = await this.uow.transactional(async () => {
|
||||
const id = 'id' in target ? target.id : await this.identities.create(user.id, target.facts);
|
||||
const id = 'id' in target ? target.id : await this.identities.createOwn(user.id, target.facts);
|
||||
await this.attach(user.id, id, uses, 'user');
|
||||
await this.identities.touch(user.id, id);
|
||||
await this.prune(user.id);
|
||||
@@ -130,7 +130,7 @@ export class PlaceIdentitiesService {
|
||||
await this.links.moveTo(user.id, moved, leadId);
|
||||
await this.identities.setMergedInto(user.id, restId, leadId);
|
||||
await this.identities.touch(user.id, leadId);
|
||||
const mergeId = await this.merges.create(
|
||||
const mergeId = await this.merges.record(
|
||||
user.id,
|
||||
leadId,
|
||||
restId,
|
||||
@@ -197,14 +197,14 @@ export class PlaceIdentitiesService {
|
||||
linkedBy: 'user' | 'merge',
|
||||
): Promise<void> {
|
||||
await this.links.detach(userId, uses);
|
||||
await this.links.insert(userId, id, uses, linkedBy);
|
||||
await this.links.insertUses(userId, id, uses, linkedBy);
|
||||
}
|
||||
|
||||
/** The entry's own place, made from its first use when it has none yet. Runs inside the caller's transaction. */
|
||||
private async materialize(userId: number, rows: EntryRows): Promise<number> {
|
||||
if (rows.identity) return rows.identity.id;
|
||||
const first = firstUseOf(rows);
|
||||
const id = await this.identities.create(userId, {
|
||||
const id = await this.identities.createOwn(userId, {
|
||||
name: first.name,
|
||||
lat: first.lat,
|
||||
lng: first.lng,
|
||||
|
||||
Reference in New Issue
Block a user