mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 15:17:30 +00:00
feat(plugins): cut entity results down to a published field list
The entity reads of the plugin RPC surface handed plugins whatever their query produced, mostly SELECT t.*, with credentials stripped by a denylist (withoutFeedToken). Every column a migration added reached every plugin holding the read grant, and renaming one was an unversioned break of a published API. protocol/output-contract.ts now states, for every wire method, what its result is: rows of one of the nine entities the SDK types (trip, place, day, reservation, packingItem, tripFile, budgetItem, assignment, user), a value the host builds itself, or a read model passed on as the REST route returns it. The router applies it to each result on the way out, so an entity row keeps exactly the fields plugins received when the list was drawn, in the same order and with the same values, minus the trip's feed_token (listMine, create and update used to carry it as null). The table is keyed by every method, so a new one does not compile without an entry. output-contract.schema.test.ts holds the lists to the migrated schema: a new column on a whole-row table fails until it is published or withheld, and each entity method is called on the real services to prove the contract drops nothing but the withheld fields. gen:plugin-facts publishes the lists to the SDK as PLUGIN_ENTITY_FIELDS and PLUGIN_METHOD_RESULT, and the SDK's entity interfaces are type-checked against them. Place.day_id, which no read ever delivered, is deprecated rather than removed. KNOWN_ADDONS is generated from ADDON_IDS as well, which adds the dawarich, roadtrip and tours ids the hand-kept copy lacked. The SDK goes to 1.9.0, and its README and the plugin wiki pages describe what a ctx call returns.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// GENERATED — do not edit by hand.
|
||||
// Source: server/src/nest/plugins/protocol/envelope.ts + server/src/plugin-event-sink.ts
|
||||
// + server/src/nest/plugins/protocol/output-contract.ts + server/src/addons.ts
|
||||
// + shared/src/plugins/plugin-poi-facts.ts
|
||||
// Regenerate: node --import tsx server/scripts/gen-plugin-facts.ts
|
||||
|
||||
@@ -388,3 +389,360 @@ export const POI_CATEGORY_ICONS: string[] = [
|
||||
|
||||
export const POI_CATEGORY_MAX = 4;
|
||||
export const POI_CATEGORY_LABEL_MAX = 40;
|
||||
|
||||
/**
|
||||
* The addon ids a manifest's `requiredAddons` may name: TREK's ADDON_IDS.
|
||||
*/
|
||||
export const KNOWN_ADDONS: string[] = [
|
||||
'mcp',
|
||||
'packing',
|
||||
'budget',
|
||||
'documents',
|
||||
'vacay',
|
||||
'atlas',
|
||||
'collab',
|
||||
'journey',
|
||||
'airtrail',
|
||||
'dawarich',
|
||||
'llm_parsing',
|
||||
'collections',
|
||||
'roadtrip',
|
||||
'tours',
|
||||
];
|
||||
|
||||
/**
|
||||
* The fields each entity result carries, and nothing else: the row's published
|
||||
* columns, then the keys the host adds (joined names, counts, hydrated children).
|
||||
* A column TREK adds later is not delivered until it is listed here. A literal,
|
||||
* unlike the wide tables above, because it is new (nothing published depends on a
|
||||
* wider type) and the SDK's entity interfaces are type-checked against it.
|
||||
*/
|
||||
export const PLUGIN_ENTITY_FIELDS = {
|
||||
trip: [
|
||||
'id',
|
||||
'user_id',
|
||||
'title',
|
||||
'description',
|
||||
'start_date',
|
||||
'end_date',
|
||||
'currency',
|
||||
'cover_image',
|
||||
'is_archived',
|
||||
'reminder_days',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'reminder_sent_for',
|
||||
'day_count',
|
||||
'place_count',
|
||||
'is_owner',
|
||||
'owner_username',
|
||||
'shared_count',
|
||||
],
|
||||
place: [
|
||||
'id',
|
||||
'trip_id',
|
||||
'name',
|
||||
'description',
|
||||
'lat',
|
||||
'lng',
|
||||
'address',
|
||||
'category_id',
|
||||
'price',
|
||||
'currency',
|
||||
'reservation_status',
|
||||
'reservation_notes',
|
||||
'reservation_datetime',
|
||||
'place_time',
|
||||
'end_time',
|
||||
'duration_minutes',
|
||||
'notes',
|
||||
'image_url',
|
||||
'google_place_id',
|
||||
'google_ftid',
|
||||
'website',
|
||||
'phone',
|
||||
'transport_mode',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'osm_id',
|
||||
'route_geometry',
|
||||
'route_color',
|
||||
'stop_type',
|
||||
'fill_percent',
|
||||
'amap_poi_id',
|
||||
'source',
|
||||
'email',
|
||||
'opening_hours',
|
||||
'category_name',
|
||||
'category_color',
|
||||
'category_icon',
|
||||
'tour_place_id',
|
||||
'category',
|
||||
'tags',
|
||||
'ratings',
|
||||
'rating_avg',
|
||||
'rating_count',
|
||||
],
|
||||
day: [
|
||||
'id',
|
||||
'trip_id',
|
||||
'day_number',
|
||||
'date',
|
||||
'notes',
|
||||
'title',
|
||||
'default_transport_mode',
|
||||
'assignments',
|
||||
'notes_items',
|
||||
],
|
||||
reservation: [
|
||||
'id',
|
||||
'trip_id',
|
||||
'day_id',
|
||||
'end_day_id',
|
||||
'place_id',
|
||||
'assignment_id',
|
||||
'title',
|
||||
'accommodation_id',
|
||||
'reservation_time',
|
||||
'reservation_end_time',
|
||||
'location',
|
||||
'confirmation_number',
|
||||
'notes',
|
||||
'status',
|
||||
'type',
|
||||
'created_at',
|
||||
'metadata',
|
||||
'day_plan_position',
|
||||
'needs_review',
|
||||
'external_source',
|
||||
'external_id',
|
||||
'external_owner_user_id',
|
||||
'external_synced_at',
|
||||
'sync_enabled',
|
||||
'external_hash',
|
||||
'url',
|
||||
'ingest_state',
|
||||
'day_number',
|
||||
'place_name',
|
||||
'accommodation_place_id',
|
||||
'accommodation_name',
|
||||
'accommodation_start_day_id',
|
||||
'accommodation_end_day_id',
|
||||
'day_positions',
|
||||
'endpoints',
|
||||
'travelers',
|
||||
],
|
||||
packingItem: [
|
||||
'id',
|
||||
'trip_id',
|
||||
'name',
|
||||
'checked',
|
||||
'category',
|
||||
'sort_order',
|
||||
'created_at',
|
||||
'weight_grams',
|
||||
'bag_id',
|
||||
'quantity',
|
||||
'updated_at',
|
||||
'is_private',
|
||||
'owner_id',
|
||||
'packed_quantity',
|
||||
'owner_username',
|
||||
'recipients',
|
||||
'contributors',
|
||||
],
|
||||
tripFile: [
|
||||
'id',
|
||||
'trip_id',
|
||||
'place_id',
|
||||
'reservation_id',
|
||||
'filename',
|
||||
'original_name',
|
||||
'file_size',
|
||||
'mime_type',
|
||||
'description',
|
||||
'created_at',
|
||||
'note_id',
|
||||
'uploaded_by',
|
||||
'starred',
|
||||
'deleted_at',
|
||||
'message_id',
|
||||
'reservation_title',
|
||||
'uploaded_by_name',
|
||||
'uploaded_by_avatar',
|
||||
'url',
|
||||
'linked_reservation_ids',
|
||||
'linked_place_ids',
|
||||
'linked_budget_item_ids',
|
||||
],
|
||||
budgetItem: [
|
||||
'id',
|
||||
'trip_id',
|
||||
'category',
|
||||
'name',
|
||||
'total_price',
|
||||
'persons',
|
||||
'days',
|
||||
'note',
|
||||
'sort_order',
|
||||
'created_at',
|
||||
'paid_by_user_id',
|
||||
'expense_date',
|
||||
'reservation_id',
|
||||
'currency',
|
||||
'exchange_rate',
|
||||
'ticket_json',
|
||||
'place_id',
|
||||
'members',
|
||||
'payers',
|
||||
'receipts',
|
||||
],
|
||||
assignment: [
|
||||
'id',
|
||||
'day_id',
|
||||
'place_id',
|
||||
'order_index',
|
||||
'notes',
|
||||
'assignment_time',
|
||||
'assignment_end_time',
|
||||
'end_day',
|
||||
'leg_transport_mode',
|
||||
'incoming_leg_transport_mode',
|
||||
'route_excluded',
|
||||
'accommodation_id',
|
||||
'created_at',
|
||||
'participants',
|
||||
'tour_place_id',
|
||||
'tour_route_geometry',
|
||||
'place',
|
||||
],
|
||||
user: [
|
||||
'id',
|
||||
'username',
|
||||
'display_name',
|
||||
'avatar',
|
||||
],
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* What each ctx method returns: an entity from PLUGIN_ENTITY_FIELDS (`trip`, or
|
||||
* `trip[]` for a list), `host` for a value the host builds itself or data the
|
||||
* plugin owns, or `readModel` for a domain read model passed on as the app's own
|
||||
* REST route returns it.
|
||||
*/
|
||||
export const PLUGIN_METHOD_RESULT: Readonly<Record<string, string>> = {
|
||||
'db.exec': 'host',
|
||||
'db.query': 'host',
|
||||
'db.migrate': 'host',
|
||||
'db.tx': 'host',
|
||||
'trips.getById': 'trip',
|
||||
'trips.getPlaces': 'place[]',
|
||||
'trips.getReservations': 'reservation[]',
|
||||
'trips.getDays': 'day[]',
|
||||
'trips.getAccommodations': 'readModel',
|
||||
'trips.listMine': 'trip[]',
|
||||
'reservations.listMine': 'reservation[]',
|
||||
'reservations.create': 'reservation',
|
||||
'reservations.update': 'reservation',
|
||||
'reservations.delete': 'host',
|
||||
'accommodations.create': 'readModel',
|
||||
'accommodations.update': 'readModel',
|
||||
'accommodations.delete': 'host',
|
||||
'packing.list': 'packingItem[]',
|
||||
'packing.create': 'packingItem',
|
||||
'packing.update': 'packingItem',
|
||||
'packing.delete': 'host',
|
||||
'packing.listBags': 'readModel',
|
||||
'packing.createBag': 'readModel',
|
||||
'packing.updateBag': 'readModel',
|
||||
'packing.deleteBag': 'host',
|
||||
'packing.setBagMembers': 'readModel',
|
||||
'files.list': 'tripFile[]',
|
||||
'files.getContent': 'host',
|
||||
'files.create': 'tripFile',
|
||||
'files.createLink': 'readModel',
|
||||
'files.update': 'tripFile',
|
||||
'files.softDelete': 'host',
|
||||
'collab.listNotes': 'readModel',
|
||||
'collab.listPolls': 'readModel',
|
||||
'collab.listMessages': 'readModel',
|
||||
'collab.createNote': 'readModel',
|
||||
'collab.createPoll': 'readModel',
|
||||
'collab.votePoll': 'readModel',
|
||||
'collab.createMessage': 'readModel',
|
||||
'trips.addMember': 'host',
|
||||
'trips.removeMember': 'host',
|
||||
'trips.create': 'trip',
|
||||
'journal.listMine': 'readModel',
|
||||
'journal.getEntries': 'readModel',
|
||||
'atlas.visited': 'readModel',
|
||||
'atlas.bucketList': 'readModel',
|
||||
'rates.get': 'host',
|
||||
'vacay.mine': 'readModel',
|
||||
'daynotes.list': 'readModel',
|
||||
'daynotes.create': 'readModel',
|
||||
'daynotes.update': 'readModel',
|
||||
'daynotes.delete': 'host',
|
||||
'collections.listMine': 'readModel',
|
||||
'collections.get': 'readModel',
|
||||
'collections.create': 'readModel',
|
||||
'collections.update': 'readModel',
|
||||
'collections.savePlace': 'readModel',
|
||||
'collections.copyToTrip': 'readModel',
|
||||
'collections.deletePlace': 'host',
|
||||
'atlas.markCountry': 'host',
|
||||
'atlas.unmarkCountry': 'host',
|
||||
'atlas.markRegion': 'host',
|
||||
'atlas.unmarkRegion': 'host',
|
||||
'atlas.createBucketItem': 'readModel',
|
||||
'atlas.deleteBucketItem': 'host',
|
||||
'vacay.toggleEntry': 'readModel',
|
||||
'vacay.toggleCompanyHoliday': 'readModel',
|
||||
'journal.createEntry': 'readModel',
|
||||
'journal.addEntryPhoto': 'readModel',
|
||||
'journal.updateEntry': 'readModel',
|
||||
'journal.deleteEntry': 'host',
|
||||
'journal.createJourney': 'readModel',
|
||||
'journal.deleteJourney': 'host',
|
||||
'weather.get': 'host',
|
||||
'categories.list': 'readModel',
|
||||
'tags.list': 'readModel',
|
||||
'tags.create': 'readModel',
|
||||
'tags.update': 'readModel',
|
||||
'tags.delete': 'host',
|
||||
'trips.members': 'user[]',
|
||||
'todos.list': 'readModel',
|
||||
'todos.create': 'readModel',
|
||||
'todos.update': 'readModel',
|
||||
'todos.delete': 'host',
|
||||
'costs.getByTrip': 'budgetItem[]',
|
||||
'costs.listMine': 'budgetItem[]',
|
||||
'costs.create': 'budgetItem',
|
||||
'costs.update': 'budgetItem',
|
||||
'costs.delete': 'host',
|
||||
'places.create': 'place',
|
||||
'places.update': 'place',
|
||||
'places.delete': 'host',
|
||||
'days.create': 'day',
|
||||
'days.update': 'day',
|
||||
'days.delete': 'host',
|
||||
'itinerary.assign': 'assignment',
|
||||
'itinerary.unassign': 'host',
|
||||
'trips.update': 'trip',
|
||||
'meta.get': 'host',
|
||||
'meta.set': 'host',
|
||||
'meta.list': 'host',
|
||||
'meta.delete': 'host',
|
||||
'users.getById': 'user',
|
||||
'ws.broadcastToTrip': 'host',
|
||||
'ws.broadcastToUser': 'host',
|
||||
'notify.send': 'host',
|
||||
'ai.complete': 'host',
|
||||
'ai.extract': 'host',
|
||||
'oauth.getToken': 'host',
|
||||
'scheduler.set': 'host',
|
||||
'scheduler.cancel': 'host',
|
||||
'plugins.call': 'host',
|
||||
'events.emit': 'host',
|
||||
'settings.get': 'host',
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user