mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 17:41:51 +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',
|
||||
};
|
||||
|
||||
+35
-4
@@ -6,15 +6,25 @@
|
||||
* dependency-free.
|
||||
*/
|
||||
|
||||
import type { PLUGIN_ENTITY_FIELDS } from './generated/host-facts.js';
|
||||
|
||||
/** Bumped on any breaking change to the plugin API surface. Embed as `apiVersion` in your manifest. */
|
||||
export const PLUGIN_API_VERSION = 1 as const;
|
||||
|
||||
// Core entity shapes returned by ctx reads/writes. Only `id` is guaranteed; the rest
|
||||
// are the fields plugins most commonly use (typed for autocomplete), left optional
|
||||
// because they mirror raw DB rows — and every shape keeps an index signature, so no
|
||||
// column is ever hidden from you.
|
||||
// are the fields plugins most commonly use (typed for autocomplete), left optional.
|
||||
// What a row actually carries is the published field list in PLUGIN_ENTITY_FIELDS
|
||||
// (generated from TREK's output contract): a row holds those fields and no others, so
|
||||
// a column TREK adds later is not delivered until TREK publishes it there. The index
|
||||
// signature types the published fields these interfaces do not name.
|
||||
export interface Trip { id: number; user_id?: number; title?: string; start_date?: string | null; end_date?: string | null; currency?: string | null; [k: string]: unknown }
|
||||
export interface Place { id: number; trip_id?: number; name?: string; lat?: number | null; lng?: number | null; day_id?: number | null; category_id?: number | null; notes?: string | null; [k: string]: unknown }
|
||||
export interface Place {
|
||||
id: number; trip_id?: number; name?: string; lat?: number | null; lng?: number | null;
|
||||
/** @deprecated Never delivered: a place has no day of its own. Its days are the
|
||||
* `assignments` of `trips.getDays()`, each carrying `day_id` and `place_id`. */
|
||||
day_id?: number | null;
|
||||
category_id?: number | null; notes?: string | null; [k: string]: unknown;
|
||||
}
|
||||
export interface Day { id: number; trip_id?: number; date?: string | null; title?: string | null; [k: string]: unknown }
|
||||
export interface Reservation { id: number; trip_id?: number; type?: string; [k: string]: unknown }
|
||||
export interface PackingItem { id: number; trip_id?: number; name?: string; [k: string]: unknown }
|
||||
@@ -23,6 +33,25 @@ export interface BudgetItem { id: number; trip_id?: number; name?: string; total
|
||||
export interface Assignment { id: number; day_id?: number; place_id?: number; notes?: string | null; [k: string]: unknown }
|
||||
export interface User { id: number; username?: string; display_name?: string | null; avatar?: string | null; [k: string]: unknown }
|
||||
|
||||
// Every field an entity interface above names has to be one TREK delivers. A field
|
||||
// that is not in PLUGIN_ENTITY_FIELDS fails this check at compile time, so the
|
||||
// interfaces cannot promise a field the host drops. `Place.day_id` predates the
|
||||
// contract and is the one deprecated exception.
|
||||
type NamedKeys<T> = keyof { [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K] };
|
||||
type Undelivered<T, E extends keyof typeof PLUGIN_ENTITY_FIELDS> = Exclude<NamedKeys<T>, (typeof PLUGIN_ENTITY_FIELDS)[E][number]>;
|
||||
type NoneUndelivered<T extends never> = T;
|
||||
type EntityFieldsAreDelivered = [
|
||||
NoneUndelivered<Undelivered<Trip, 'trip'>>,
|
||||
NoneUndelivered<Exclude<Undelivered<Place, 'place'>, 'day_id'>>,
|
||||
NoneUndelivered<Undelivered<Day, 'day'>>,
|
||||
NoneUndelivered<Undelivered<Reservation, 'reservation'>>,
|
||||
NoneUndelivered<Undelivered<PackingItem, 'packingItem'>>,
|
||||
NoneUndelivered<Undelivered<TripFile, 'tripFile'>>,
|
||||
NoneUndelivered<Undelivered<BudgetItem, 'budgetItem'>>,
|
||||
NoneUndelivered<Undelivered<Assignment, 'assignment'>>,
|
||||
NoneUndelivered<Undelivered<User, 'user'>>,
|
||||
];
|
||||
|
||||
/** Every ctx.* call is rate-limited per plugin at the host RPC dispatch boundary:
|
||||
* burst 60, sustained 20/s, 16 in-flight. A throttled call is refused (retryable)
|
||||
* rather than executed, with:
|
||||
@@ -976,6 +1005,8 @@ export {
|
||||
export {
|
||||
EVENT_FAMILIES, EVENT_SNAPSHOT_GRANT, KNOWN_PERMISSIONS,
|
||||
} from './generated/host-facts.js';
|
||||
// What ctx results carry: the published fields of each entity, and what each method returns.
|
||||
export { PLUGIN_ENTITY_FIELDS, PLUGIN_METHOD_RESULT } from './generated/host-facts.js';
|
||||
// The lucide icons a `capabilities.poiCategories` entry may use, and the per-plugin cap.
|
||||
export { POI_CATEGORY_ICONS, POI_CATEGORY_MAX } from './generated/host-facts.js';
|
||||
|
||||
|
||||
@@ -136,12 +136,11 @@ const RESERVED_IDS = new Set(['registry', 'install', 'rescan']);
|
||||
const SEMVER_RE = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
|
||||
// Addon-id format (lowercase slug, underscores allowed e.g. `llm_parsing`).
|
||||
const ADDON_ID_RE = /^[a-z][a-z0-9_]{1,39}$/;
|
||||
// Mirror of the server's ADDON_IDS (server/src/addons.ts). Kept in sync so
|
||||
// `trek-plugin validate` can WARN on an addon id TREK doesn't know — never a hard
|
||||
// The server's ADDON_IDS (server/src/addons.ts), generated into host-facts.ts by
|
||||
// gen:plugin-facts so it cannot drift again (dawarich, roadtrip and tours had). Used
|
||||
// so `trek-plugin validate` can WARN on an addon id TREK doesn't know, never a hard
|
||||
// error (a plugin built for a newer TREK may reference an addon this SDK predates).
|
||||
export const KNOWN_ADDONS = [
|
||||
'mcp', 'packing', 'budget', 'documents', 'vacay', 'atlas', 'collab', 'journey', 'airtrail', 'llm_parsing', 'collections',
|
||||
];
|
||||
export { KNOWN_ADDONS } from './generated/host-facts.js';
|
||||
// An outbound host: exact hostname (single-label sibling or dotted FQDN) or a
|
||||
// `*.`-wildcard with a multi-label suffix. No `*`, no `*.`, no whole-TLD `*.com`,
|
||||
// no spaces (mirrors the server manifest validator).
|
||||
|
||||
Reference in New Issue
Block a user