@happyvertical/smrt-places 0.34.0 → 0.34.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -431,13 +431,20 @@ export declare class PlaceCollection extends SmrtCollection<Place> {
431
431
  */
432
432
  findByTenant(tenantId: string): Promise<Place[]>;
433
433
  /**
434
- * Find all global places (not associated with any tenant)
434
+ * Find all global places (not associated with any tenant).
435
+ *
436
+ * Routes through the shared tenant-global helper so it does not throw under
437
+ * an active tenant context (an explicit `tenant_id IS NULL` filter would be
438
+ * flagged as an isolation violation). (#1600)
435
439
  *
436
440
  * @returns Array of global places
437
441
  */
438
442
  findGlobal(): Promise<Place[]>;
439
443
  /**
440
- * Find places for a tenant including global places
444
+ * Find places for a tenant including global places.
445
+ *
446
+ * Fails closed if an active tenant context requests a different tenant's
447
+ * rows; the admin/system path keeps the cross-tenant capability. (#1600)
441
448
  *
442
449
  * @param tenantId - The tenant ID to include
443
450
  * @returns Array of tenant-specific and global places
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ObjectRegistry, foreignKey, crossPackageRef, field, smrt, SmrtObject, SmrtJunction, SmrtHierarchical, SmrtCollection } from "@happyvertical/smrt-core";
2
2
  import { getOwnedAssetsFromCollection, addOwnedAssetFromCollection, removeOwnedAssetFromCollection, resolveOwnedAssetsById, assertValidOwnedAssetRelationship, assertValidOwnedAssetSortOrder } from "@happyvertical/smrt-assets";
3
- import { tenantId, TenantScoped } from "@happyvertical/smrt-tenancy";
3
+ import { tenantId, TenantScoped, queryGlobal, queryWithGlobals } from "@happyvertical/smrt-tenancy";
4
4
  import { getGeoAdapter } from "@happyvertical/geo";
5
5
  import { areCoordinatesNear, calculateDistance, formatCoordinates, generateDisplayName, locationToGeoData, mapLocationTypeToPlaceType, normalizeAddressComponents, parseCoordinates, validateCoordinates } from "./utils.js";
6
6
  ObjectRegistry.registerPackageManifest(
@@ -922,24 +922,28 @@ class PlaceCollection extends SmrtCollection {
922
922
  return this.list({ where: { tenantId: tenantId2 } });
923
923
  }
924
924
  /**
925
- * Find all global places (not associated with any tenant)
925
+ * Find all global places (not associated with any tenant).
926
+ *
927
+ * Routes through the shared tenant-global helper so it does not throw under
928
+ * an active tenant context (an explicit `tenant_id IS NULL` filter would be
929
+ * flagged as an isolation violation). (#1600)
926
930
  *
927
931
  * @returns Array of global places
928
932
  */
929
933
  async findGlobal() {
930
- return this.list({ where: { tenantId: null } });
934
+ return queryGlobal(this);
931
935
  }
932
936
  /**
933
- * Find places for a tenant including global places
937
+ * Find places for a tenant including global places.
938
+ *
939
+ * Fails closed if an active tenant context requests a different tenant's
940
+ * rows; the admin/system path keeps the cross-tenant capability. (#1600)
934
941
  *
935
942
  * @param tenantId - The tenant ID to include
936
943
  * @returns Array of tenant-specific and global places
937
944
  */
938
945
  async findWithGlobals(tenantId2) {
939
- return this.query(
940
- `SELECT * FROM ${this.tableName} WHERE tenant_id = ? OR tenant_id IS NULL`,
941
- [tenantId2]
942
- );
946
+ return queryWithGlobals(this, tenantId2, "Place.findWithGlobals");
943
947
  }
944
948
  }
945
949
  const PlaceCollection$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/__smrt-register__.ts","../src/models/PlaceAsset.ts","../src/collections/PlaceAssetCollection.ts","../src/models/Place.ts","../src/models/PlaceType.ts","../src/collections/PlaceTypeCollection.ts","../src/collections/PlaceCollection.ts"],"sourcesContent":["/**\n * Self-registers this package's build-time manifest before any @smrt() decorator\n * in the package fires. Fixes issue #1132: in consumer runtimes (tsx, SvelteKit\n * SSR, plain `vite dev`) the decorator's synchronous manifest lookup previously\n * missed because no step populated the global manifest cache — classes got\n * registered with zero fields and `save()` / `toJSON()` silently dropped every\n * declared property.\n *\n * Import this module as the first statement in `src/index.ts` so its top-level\n * side effect runs ahead of any class module's @smrt() decorator.\n *\n * Silent no-op in dev/test, where the vitest plugin already populates manifests\n * via a different path. Only needs to succeed in the published dist output.\n *\n * @see https://github.com/happyvertical/smrt/issues/1132\n */\nimport { ObjectRegistry } from '@happyvertical/smrt-core';\n\n// `new URL('./manifest.json', import.meta.url)` resolves at runtime to the\n// manifest sitting next to this module's compiled output. Vite warns at build\n// time that it cannot pre-resolve the URL; that is the intended behavior —\n// the URL must resolve to dist/manifest.json at runtime, not be inlined.\nObjectRegistry.registerPackageManifest(\n new URL('./manifest.json', import.meta.url),\n);\n","import type { SmrtObjectOptions } from '@happyvertical/smrt-core';\nimport {\n crossPackageRef,\n field,\n foreignKey,\n SmrtObject,\n smrt,\n} from '@happyvertical/smrt-core';\nimport { TenantScoped, tenantId } from '@happyvertical/smrt-tenancy';\n\nexport interface PlaceAssetOptions extends SmrtObjectOptions {\n placeId?: string;\n assetId?: string;\n relationship?: string;\n sortOrder?: number;\n tenantId?: string | null;\n}\n\n@TenantScoped({ mode: 'optional' })\n@smrt({\n tableName: 'place_assets',\n conflictColumns: ['place_id', 'asset_id', 'relationship'],\n api: false,\n mcp: false,\n cli: false,\n})\nexport class PlaceAsset extends SmrtObject {\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n @foreignKey('Place', { required: true })\n placeId = '';\n\n @crossPackageRef('@happyvertical/smrt-assets:Asset', { required: true })\n assetId = '';\n\n @field({ required: true })\n relationship = 'attachment';\n\n @field()\n sortOrder = 0;\n\n constructor(options: PlaceAssetOptions = {}) {\n super(options);\n if (options.placeId) this.placeId = options.placeId;\n if (options.assetId) this.assetId = options.assetId;\n if (options.relationship) this.relationship = options.relationship;\n if (options.sortOrder !== undefined) this.sortOrder = options.sortOrder;\n if (options.tenantId !== undefined) this.tenantId = options.tenantId;\n }\n}\n","import type { Asset } from '@happyvertical/smrt-assets';\nimport {\n addOwnedAssetFromCollection,\n getOwnedAssetsFromCollection,\n removeOwnedAssetFromCollection,\n} from '@happyvertical/smrt-assets';\nimport type { SmrtCollectionOptions } from '@happyvertical/smrt-core';\nimport { SmrtJunction, smrt } from '@happyvertical/smrt-core';\nimport { PlaceAsset } from '../models/PlaceAsset';\nimport type { PlaceCollection } from './PlaceCollection';\n\nexport interface PlaceAssetCollectionOptions extends SmrtCollectionOptions {}\n\n@smrt({\n api: false,\n mcp: false,\n cli: false,\n})\nexport class PlaceAssetCollection extends SmrtJunction<PlaceAsset> {\n static readonly _itemClass = PlaceAsset;\n protected leftField = 'placeId';\n protected rightField = 'assetId';\n\n private placeCollectionPromise: Promise<PlaceCollection> | null = null;\n\n private async getPlaceCollection(): Promise<PlaceCollection> {\n if (!this.placeCollectionPromise) {\n const { PlaceCollection } = await import('./PlaceCollection');\n this.placeCollectionPromise = PlaceCollection.create({ db: this.db });\n }\n\n return this.placeCollectionPromise;\n }\n\n async getAssets(placeId: string, relationship?: string): Promise<Asset[]> {\n return getOwnedAssetsFromCollection(\n await this.getPlaceCollection(),\n placeId,\n relationship,\n );\n }\n\n async addAsset(\n placeId: string,\n asset: Asset,\n relationship = 'attachment',\n sortOrder = 0,\n ): Promise<void> {\n await addOwnedAssetFromCollection(\n await this.getPlaceCollection(),\n 'Place',\n placeId,\n asset,\n relationship,\n sortOrder,\n );\n }\n\n async removeAsset(\n placeId: string,\n assetId: string,\n relationship?: string,\n ): Promise<void> {\n await removeOwnedAssetFromCollection(\n await this.getPlaceCollection(),\n 'Place',\n placeId,\n assetId,\n relationship,\n );\n }\n}\n","/**\n * Place model - Core entity for hierarchical place management\n *\n * Supports both real-world places with geo data and abstract places\n * (virtual worlds, game zones) by making all geo fields optional.\n *\n * Tenancy: Places are tenant-scoped with optional mode, allowing:\n * - Tenant-specific places (tenantId set)\n * - Global/shared places (tenantId null)\n */\n\nimport type { Asset } from '@happyvertical/smrt-assets';\nimport {\n assertValidOwnedAssetRelationship,\n assertValidOwnedAssetSortOrder,\n resolveOwnedAssetsById,\n} from '@happyvertical/smrt-assets';\nimport {\n field,\n foreignKey,\n SmrtHierarchical,\n smrt,\n} from '@happyvertical/smrt-core';\nimport { TenantScoped, tenantId } from '@happyvertical/smrt-tenancy';\nimport type { GeoData, PlaceOptions } from '../types';\n\n@TenantScoped({ mode: 'optional' })\n@smrt({\n tableStrategy: 'sti',\n api: { include: ['list', 'get', 'create', 'update', 'delete'] },\n mcp: { include: ['list', 'get', 'create', 'update'] },\n cli: true,\n})\nexport class Place extends SmrtHierarchical {\n // id: UUID (auto-generated by SmrtObject)\n\n // Tenancy field - nullable for global/shared places\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n // Core fields\n @foreignKey('PlaceType')\n typeId = ''; // FK to PlaceType\n // parentId inherited from SmrtHierarchical (nullable, self-reference)\n name = ''; // Place name/title\n description = ''; // Optional description\n\n // Optional geo fields (all nullable for abstract places)\n @field({ type: 'decimal' })\n latitude: number | null = null;\n @field({ type: 'decimal' })\n longitude: number | null = null;\n streetNumber = '';\n streetName = '';\n city = '';\n region = '';\n country = '';\n postalCode = '';\n countryCode = '';\n timezone = '';\n\n // Metadata\n externalId = ''; // External system identifier\n source = ''; // Where this place came from (e.g., 'google', 'osm')\n metadata = ''; // JSON metadata stored as text\n\n // Timestamps\n createdAt = new Date();\n updatedAt = new Date();\n\n constructor(options: PlaceOptions = {}) {\n super(options);\n\n // Tenancy field\n if (options.tenantId !== undefined) this.tenantId = options.tenantId as any;\n\n // Core fields\n if (options.typeId) this.typeId = options.typeId;\n if (options.parentId !== undefined)\n this.parentId = options.parentId ?? null;\n if (options.name) this.name = options.name;\n if (options.description !== undefined)\n this.description = options.description;\n\n // Geo fields\n if (options.latitude !== undefined) this.latitude = options.latitude;\n if (options.longitude !== undefined) this.longitude = options.longitude;\n if (options.streetNumber !== undefined)\n this.streetNumber = options.streetNumber;\n if (options.streetName !== undefined) this.streetName = options.streetName;\n if (options.city !== undefined) this.city = options.city;\n if (options.region !== undefined) this.region = options.region;\n if (options.country !== undefined) this.country = options.country;\n if (options.postalCode !== undefined) this.postalCode = options.postalCode;\n if (options.countryCode !== undefined)\n this.countryCode = options.countryCode;\n if (options.timezone !== undefined) this.timezone = options.timezone;\n\n // Metadata\n if (options.externalId !== undefined) this.externalId = options.externalId;\n if (options.source !== undefined) this.source = options.source;\n\n // Handle metadata - can be object or JSON string\n if (options.metadata !== undefined) {\n if (typeof options.metadata === 'string') {\n this.metadata = options.metadata;\n } else {\n this.metadata = JSON.stringify(options.metadata);\n }\n }\n\n // Timestamps\n if (options.createdAt) this.createdAt = options.createdAt;\n if (options.updatedAt) this.updatedAt = options.updatedAt;\n }\n\n /**\n * Get geographic data for this place\n *\n * @returns GeoData object with all geo fields\n */\n getGeoData(): GeoData {\n return {\n latitude: this.latitude,\n longitude: this.longitude,\n streetNumber: this.streetNumber || undefined,\n streetName: this.streetName || undefined,\n city: this.city || undefined,\n region: this.region || undefined,\n country: this.country || undefined,\n postalCode: this.postalCode || undefined,\n countryCode: this.countryCode || undefined,\n timezone: this.timezone || undefined,\n };\n }\n\n /**\n * Check if this place has geographic coordinates\n *\n * @returns True if latitude and longitude are set\n */\n hasCoordinates(): boolean {\n return this.latitude !== null && this.longitude !== null;\n }\n\n /**\n * Get metadata as parsed object\n *\n * @returns Parsed metadata object or empty object if no metadata\n */\n getMetadata(): Record<string, any> {\n if (!this.metadata) return {};\n try {\n return JSON.parse(this.metadata);\n } catch {\n return {};\n }\n }\n\n /**\n * Set metadata from object\n *\n * @param data - Metadata object to store\n */\n setMetadata(data: Record<string, any>): void {\n this.metadata = JSON.stringify(data);\n }\n\n /**\n * Update metadata by merging with existing values\n *\n * @param updates - Partial metadata to merge\n */\n updateMetadata(updates: Record<string, any>): void {\n const current = this.getMetadata();\n this.setMetadata({ ...current, ...updates });\n }\n\n /**\n * Get the place type\n *\n * @returns PlaceType instance or null if not found\n */\n async getType() {\n if (!this.typeId) return null;\n\n const { PlaceTypeCollection } = await import(\n '../collections/PlaceTypeCollection'\n );\n const collection = await (PlaceTypeCollection as any).create(this.options);\n\n return await collection.get({ id: this.typeId });\n }\n\n // Hierarchy traversal (getParent / getChildren / getAncestors /\n // getDescendants / getHierarchy / moveTo) provided by SmrtHierarchical.\n\n private async getPlaceAssetCollection() {\n const { PlaceAssetCollection } = await import(\n '../collections/PlaceAssetCollection'\n );\n return PlaceAssetCollection.create({ db: this.db });\n }\n async getAssets(relationship?: string): Promise<Asset[]> {\n if (!this.id) {\n return [];\n }\n\n const placeAssets = await this.getPlaceAssetCollection();\n const linkedAssets = await placeAssets.byLeft(\n this.id,\n relationship ? { relationship } : {},\n );\n\n return resolveOwnedAssetsById(\n this.db,\n linkedAssets.map((link) => link.assetId),\n this.tenantId,\n );\n }\n\n async addAsset(\n asset: Asset,\n relationship = 'attachment',\n sortOrder = 0,\n ): Promise<void> {\n if (!this.id || !asset.id) {\n throw new Error('Cannot associate unsaved place or asset');\n }\n\n assertValidOwnedAssetRelationship(relationship);\n assertValidOwnedAssetSortOrder(sortOrder);\n\n const placeAssets = await this.getPlaceAssetCollection();\n await placeAssets.attach(this.id, asset.id, {\n relationship,\n sortOrder,\n tenantId: this.tenantId,\n });\n }\n\n async removeAsset(assetId: string, relationship?: string): Promise<void> {\n if (!this.id) {\n return;\n }\n\n const placeAssets = await this.getPlaceAssetCollection();\n await placeAssets.detach(\n this.id,\n assetId,\n relationship ? { relationship } : {},\n );\n }\n}\n","/**\n * PlaceType model - Defines types/categories of places\n *\n * Examples: 'country', 'city', 'building', 'zone', 'room', 'region'\n */\n\nimport { field, SmrtObject, smrt } from '@happyvertical/smrt-core';\nimport type { PlaceTypeOptions } from '../types';\n\n@smrt({\n tableStrategy: 'sti',\n api: { include: ['list', 'get', 'create', 'update', 'delete'] },\n mcp: { include: ['list', 'get', 'create'] },\n cli: true,\n})\nexport class PlaceType extends SmrtObject {\n // id and slug are inherited from SmrtObject\n @field({ required: true })\n name: string = ''; // Type name (e.g., 'Town', 'City', 'Country')\n\n description?: string; // Optional description\n\n // Timestamps\n createdAt = new Date();\n updatedAt = new Date();\n\n constructor(options: PlaceTypeOptions = {}) {\n super(options);\n if (options.name) this.name = options.name;\n if (options.description !== undefined)\n this.description = options.description;\n if (options.createdAt) this.createdAt = options.createdAt;\n if (options.updatedAt) this.updatedAt = options.updatedAt;\n }\n\n /**\n * Convenience method for slug-based lookup\n *\n * @param slug - The slug to search for\n * @returns PlaceType instance or null if not found\n */\n static async getBySlug(_slug: string): Promise<PlaceType | null> {\n // Will be auto-implemented by SMRT\n return null;\n }\n}\n","/**\n * PlaceTypeCollection - Collection manager for PlaceType objects\n *\n * Provides simple lookup and creation for place types.\n */\n\nimport { SmrtCollection } from '@happyvertical/smrt-core';\nimport { PlaceType } from '../models/PlaceType';\n\nexport class PlaceTypeCollection extends SmrtCollection<PlaceType> {\n static readonly _itemClass = PlaceType;\n\n /**\n * Get or create a place type by slug\n *\n * @param slug - PlaceType slug (e.g., 'city', 'building')\n * @param name - Optional display name (defaults to capitalized slug)\n * @returns PlaceType instance\n */\n async getOrCreate(slug: string, name?: string): Promise<PlaceType> {\n // First try to find existing type with this slug\n const existing = await this.get({ slug });\n\n if (existing) {\n return existing;\n }\n\n // Create new type with auto-generated name if not provided\n const displayName =\n name || slug.replace(/-/g, ' ').replace(/\\b\\w/g, (l) => l.toUpperCase());\n\n return await this.create({\n slug,\n name: displayName,\n });\n }\n\n /**\n * Get a place type by slug\n *\n * @param slug - PlaceType slug to search for\n * @returns PlaceType instance or null if not found\n */\n async getBySlug(slug: string): Promise<PlaceType | null> {\n return await this.get({ slug });\n }\n\n /**\n * Initialize default place types\n *\n * Creates standard types if they don't exist:\n * - country\n * - region (state/province)\n * - city\n * - address\n * - building\n * - room\n * - zone (for abstract/virtual places)\n *\n * @returns Array of created/existing place types\n */\n async initializeDefaults(): Promise<PlaceType[]> {\n const defaults = [\n { slug: 'country', name: 'Country' },\n { slug: 'region', name: 'Region' },\n { slug: 'city', name: 'City' },\n { slug: 'address', name: 'Address' },\n { slug: 'building', name: 'Building' },\n { slug: 'room', name: 'Room' },\n { slug: 'zone', name: 'Zone' },\n { slug: 'point_of_interest', name: 'Point of Interest' },\n ];\n\n const types: PlaceType[] = [];\n for (const def of defaults) {\n const type = await this.getOrCreate(def.slug, def.name);\n types.push(type);\n }\n\n return types;\n }\n}\n","/**\n * PlaceCollection - Collection manager for Place objects\n *\n * Provides hierarchy traversal and organic place database growth via\n * lookupOrCreate method that integrates with @happyvertical/geo.\n */\n\nimport type { GeoAdapter, Location } from '@happyvertical/geo';\nimport { getGeoAdapter } from '@happyvertical/geo';\nimport type { Asset } from '@happyvertical/smrt-assets';\nimport {\n addOwnedAssetFromCollection,\n getOwnedAssetsFromCollection,\n removeOwnedAssetFromCollection,\n} from '@happyvertical/smrt-assets';\nimport { SmrtCollection } from '@happyvertical/smrt-core';\nimport { Place } from '../models/Place';\nimport type {\n DiscoverNearbyOptions,\n LookupOrCreateOptions,\n ResolveTrackPlacesOptions,\n TrackPlacesResult,\n TrackPoint,\n} from '../types';\nimport { PlaceTypeCollection } from './PlaceTypeCollection';\n\ntype PoiSearchOptions = Pick<\n DiscoverNearbyOptions,\n 'types' | 'keyword' | 'limit' | 'language'\n>;\n\ntype GeoAdapterWithPoiSearch = GeoAdapter & {\n findPoisNear?: (\n latitude: number,\n longitude: number,\n radiusMeters: number,\n options?: PoiSearchOptions,\n ) => Promise<Location[]>;\n};\n\nexport class PlaceCollection extends SmrtCollection<Place> {\n static readonly _itemClass = Place;\n\n /**\n * Look up a place by query or coordinates, creating it if not found\n *\n * This is the key method for organic database growth:\n * 1. Search local database first\n * 2. If not found, query @happyvertical/geo\n * 3. Create place from geocoding result\n * 4. Return place\n *\n * @param query - Address or location query string\n * @param options - Lookup options (provider, type, parent, etc.)\n * @returns Place instance\n */\n async lookupOrCreate(\n query: string,\n options: LookupOrCreateOptions = {},\n ): Promise<Place | null> {\n const {\n geoProvider = 'openstreetmap',\n typeSlug,\n parentId,\n createIfNotFound = true,\n coords,\n } = options;\n\n // Step 1: Try to find existing place\n let existingPlace: Place | null = null;\n\n // Search by coordinates if provided\n if (coords) {\n existingPlace = await this.findByCoordinates(coords.lat, coords.lng);\n }\n\n // Search by query text if coordinates didn't match\n if (!existingPlace) {\n existingPlace = await this.findByQuery(query);\n }\n\n if (existingPlace) {\n return existingPlace;\n }\n\n // Step 2: If not found and createIfNotFound is false, return null\n if (!createIfNotFound) {\n return null;\n }\n\n // Step 3: Query @happyvertical/geo for location data\n const locations = await this.geocode(\n query,\n coords,\n geoProvider as 'google' | 'openstreetmap',\n );\n\n if (locations.length === 0) {\n return null;\n }\n\n // Use first result (most relevant)\n const location = locations[0];\n\n // Step 4: Create place from location data\n return await this.createFromLocation(location, typeSlug, parentId);\n }\n\n /**\n * Find place by coordinates (within small threshold)\n *\n * @param latitude - Latitude to search\n * @param longitude - Longitude to search\n * @param threshold - Max distance in degrees (default: 0.0001 ~11m)\n * @returns Place instance or null\n */\n private async findByCoordinates(\n latitude: number,\n longitude: number,\n threshold: number = 0.0001,\n ): Promise<Place | null> {\n // Get all places with coordinates\n const places = await this.list({\n where: {\n latitude: { $ne: null },\n longitude: { $ne: null },\n },\n });\n\n // Find closest match within threshold\n for (const place of places) {\n // Cast to access Place-specific properties\n const placeObj = place as Place;\n if (placeObj.latitude === null || placeObj.longitude === null) continue;\n\n const latDiff = Math.abs(placeObj.latitude - latitude);\n const lngDiff = Math.abs(placeObj.longitude - longitude);\n\n if (latDiff < threshold && lngDiff < threshold) {\n return place;\n }\n }\n\n return null;\n }\n\n /**\n * Find place by query text (matches name, city, region, country)\n *\n * @param query - Search query\n * @returns Place instance or null\n */\n private async findByQuery(query: string): Promise<Place | null> {\n const normalizedQuery = query.toLowerCase().trim();\n\n // Try exact match on name first\n const places = await this.list({});\n\n for (const place of places) {\n // Match on name\n if (place.name.toLowerCase().includes(normalizedQuery)) {\n return place;\n }\n\n // Match on full address components\n const addressParts = [\n place.streetNumber,\n place.streetName,\n place.city,\n place.region,\n place.country,\n ]\n .filter((p) => p)\n .join(' ')\n .toLowerCase();\n\n if (addressParts.includes(normalizedQuery)) {\n return place;\n }\n }\n\n return null;\n }\n\n /**\n * Geocode query or coordinates using @happyvertical/geo\n *\n * @param query - Address query\n * @param coords - Optional coordinates for reverse geocoding\n * @param provider - Geo provider to use\n * @returns Array of Location results\n */\n private async geocode(\n query: string,\n coords?: { lat: number; lng: number },\n provider: 'google' | 'openstreetmap' = 'openstreetmap',\n ): Promise<Location[]> {\n const geo = await this.getGeoAdapter(provider);\n\n // Use reverse geocode if coords provided, otherwise forward geocode\n if (coords) {\n return await geo.reverseGeocode(coords.lat, coords.lng);\n }\n\n return await geo.lookup(query);\n }\n\n /**\n * Find a place by the provider's native id (Google place_id, OSM\n * osm-node-N, etc.). Used as the primary idempotency key by\n * `discoverNearby` so repeat POI searches don't create duplicate rows.\n */\n private async findByExternalId(externalId: string): Promise<Place | null> {\n if (!externalId) return null;\n const matches = await this.list({\n where: { externalId },\n limit: 1,\n });\n return matches[0] ?? null;\n }\n\n /**\n * Idempotent \"find or create\" for a geo Location. Keyed purely on the\n * provider's externalId (Google place_id, osm-node-*, etc.), which is\n * stable per POI across repeat searches. The older `lookupOrCreate`\n * keeps its own fallback chain (name/address/coordinate matching) for\n * address-style workflows where externalId isn't reliable.\n *\n * Returns `{ place, created }` so callers can distinguish fresh rows\n * from reused ones without re-querying the table — this is how\n * `resolveTrackPlaces` derives its `cacheHitCount` without a full\n * scan per bucket.\n */\n private async ensureFromLocation(\n location: Location,\n typeSlug?: string,\n parentId?: string | null,\n ): Promise<{ place: Place; created: boolean }> {\n if (location.id) {\n const existing = await this.findByExternalId(location.id);\n if (existing) return { place: existing, created: false };\n }\n const place = await this.createFromLocation(location, typeSlug, parentId);\n return { place, created: true };\n }\n\n /**\n * Create place from @happyvertical/geo Location data\n *\n * @param location - Location from geocoding\n * @param typeSlug - Optional type slug override\n * @param parentId - Optional parent place ID\n * @returns Created Place instance\n */\n private async createFromLocation(\n location: Location,\n typeSlug?: string,\n parentId?: string | null,\n ): Promise<Place> {\n // Get or create place type\n const typeCollection = await (PlaceTypeCollection as any).create(\n this.options,\n );\n\n const slug = typeSlug || location.type || 'address';\n const placeType = await typeCollection.getOrCreate(slug);\n\n // Extract address components\n const components = location.addressComponents || {};\n\n // Create place\n return await this.create({\n typeId: placeType.id,\n parentId: parentId ?? null,\n name: location.name,\n description: '',\n\n // Geo fields from location\n latitude: location.latitude,\n longitude: location.longitude,\n streetNumber: components.streetNumber || '',\n streetName: components.streetName || '',\n city: components.city || '',\n region: components.region || '',\n country: components.country || '',\n postalCode: components.postalCode || '',\n countryCode: location.countryCode || '',\n timezone: location.timezone || '',\n\n // Metadata\n externalId: location.id,\n source: location.raw?.provider || 'unknown',\n metadata: JSON.stringify({ raw: location.raw ?? null }),\n });\n }\n\n /**\n * Discover POIs near a coordinate and persist them as Place rows.\n *\n * Composes `@happyvertical/geo`'s `findPoisNear` with `ensureFromLocation`\n * so every returned POI is either reused from the local DB (when the\n * provider returns an id matching an existing Place `externalId`) or\n * created fresh otherwise. The cache is effectively automatic because\n * the provider's own place_id becomes the Place row's `externalId`, so\n * calling `discoverNearby` twice for the same area on the same provider\n * is a no-op after the first run when the provider returns stable ids.\n *\n * Requires a geo provider that implements `findPoisNear`. Throws a clear\n * error otherwise so consumers can fall back to `lookupOrCreate` or\n * switch providers.\n */\n async discoverNearby(\n latitude: number,\n longitude: number,\n radiusMeters: number,\n options: DiscoverNearbyOptions = {},\n ): Promise<Place[]> {\n if (!(radiusMeters > 0)) {\n throw new Error(\n `discoverNearby: radiusMeters must be > 0 (got ${radiusMeters})`,\n );\n }\n const detailed = await this.discoverNearbyDetailed(\n latitude,\n longitude,\n radiusMeters,\n options,\n );\n return detailed.map((d) => d.place);\n }\n\n /**\n * Internal variant of `discoverNearby` that exposes whether each\n * returned Place was created during this call (`true`) or reused from\n * an earlier call (`false`). Used by `resolveTrackPlaces` to classify\n * buckets as cache hits without having to re-scan the Place table.\n */\n private async discoverNearbyDetailed(\n latitude: number,\n longitude: number,\n radiusMeters: number,\n options: DiscoverNearbyOptions = {},\n ): Promise<Array<{ place: Place; created: boolean }>> {\n const {\n geoProvider = 'openstreetmap',\n types,\n keyword,\n limit,\n language,\n typeSlug,\n parentId,\n } = options;\n\n const geo = await this.getGeoAdapter(geoProvider);\n if (typeof geo.findPoisNear !== 'function') {\n throw new Error(\n `Geo provider '${geoProvider}' does not implement findPoisNear`,\n );\n }\n\n const results = await geo.findPoisNear(latitude, longitude, radiusMeters, {\n types,\n keyword,\n limit,\n language,\n });\n\n const detailed: Array<{ place: Place; created: boolean }> = [];\n for (const result of results) {\n detailed.push(await this.ensureFromLocation(result, typeSlug, parentId));\n }\n return detailed;\n }\n\n /**\n * Resolve POIs along a GPS track (e.g. a video's per-frame path).\n *\n * Naively walking every point would hammer the provider with redundant\n * requests — consecutive samples are usually within a few meters. This\n * method buckets points into a `bucketMeters`-wide grid, calls\n * `discoverNearby` once per distinct bucket, and throttles requests per\n * `throttleMs` so free tiers (Overpass, Nominatim) stay inside their\n * community rate limits without the caller having to manage a queue.\n *\n * The returned `places` are deduped across buckets by Place id, so a\n * POI that falls within several overlapping search radii appears once.\n */\n async resolveTrackPlaces(\n points: ReadonlyArray<TrackPoint>,\n options: ResolveTrackPlacesOptions = {},\n ): Promise<TrackPlacesResult> {\n const radiusMeters = options.radiusMeters ?? 50;\n const bucketMeters = options.bucketMeters ?? 50;\n const throttleMs = options.throttleMs ?? 1100;\n\n if (!(radiusMeters > 0)) {\n throw new Error(\n `resolveTrackPlaces: radiusMeters must be > 0 (got ${radiusMeters})`,\n );\n }\n if (!(bucketMeters > 0)) {\n // Grid/greedy bucketing both divide by bucketMeters; a non-positive\n // value would either NaN the math or produce \"everything in one\n // bucket\", neither of which the caller likely meant.\n throw new Error(\n `resolveTrackPlaces: bucketMeters must be > 0 (got ${bucketMeters})`,\n );\n }\n if (throttleMs < 0 || !Number.isFinite(throttleMs)) {\n throw new Error(\n `resolveTrackPlaces: throttleMs must be a finite non-negative number (got ${throttleMs})`,\n );\n }\n\n // Greedy proximity-based bucketing: each new point joins the nearest\n // existing bucket within `bucketMeters` (Haversine), otherwise seeds a\n // new bucket with itself as the center. This matches the documented\n // semantic (\"points within bucketMeters of each other collapse into\n // one request\") more faithfully than a `Math.round`-on-grid scheme,\n // which can split two points ~0.2m apart if they straddle a cell\n // boundary and inflate requestCount exactly when the user was trying\n // to rate-limit.\n const bucketMetersKm = bucketMeters / 1000;\n const bucketCenters: TrackPoint[] = [];\n for (const point of points) {\n if (!Number.isFinite(point.lat) || !Number.isFinite(point.lng)) continue;\n let bestIdx = -1;\n let bestKm = Number.POSITIVE_INFINITY;\n for (let i = 0; i < bucketCenters.length; i += 1) {\n const c = bucketCenters[i];\n const km = this.calculateDistance(c.lat, c.lng, point.lat, point.lng);\n if (km <= bucketMetersKm && km < bestKm) {\n bestKm = km;\n bestIdx = i;\n }\n }\n if (bestIdx < 0) bucketCenters.push(point);\n }\n\n const result: TrackPlacesResult = {\n places: [],\n requestCount: 0,\n cacheHitCount: 0,\n bucketCount: bucketCenters.length,\n };\n const seen = new Map<string, Place>();\n\n let lastCallAt = 0;\n for (const center of bucketCenters) {\n const wait = lastCallAt + throttleMs - Date.now();\n if (wait > 0) {\n await new Promise((resolve) => setTimeout(resolve, wait));\n }\n\n const detailed = await this.discoverNearbyDetailed(\n center.lat,\n center.lng,\n radiusMeters,\n options,\n );\n lastCallAt = Date.now();\n result.requestCount += 1;\n\n // Cache hit = the provider returned results and every one of them\n // matched a Place that already existed (explicit `created === false`\n // from ensureFromLocation). No timestamp heuristics, no re-scan.\n if (detailed.length > 0 && detailed.every((d) => !d.created)) {\n result.cacheHitCount += 1;\n }\n\n for (const { place } of detailed) {\n if (place.id && !seen.has(place.id)) seen.set(place.id, place);\n }\n }\n\n result.places = [...seen.values()];\n return result;\n }\n\n /**\n * Provider wiring (env keys, user-agent string, etc.) that `geocode`\n * and `discoverNearby` share so the two code paths can't drift. Kept\n * separate from the adapter call itself so tests and future providers\n * can inspect or override the options before construction.\n */\n private getGeoAdapterOptions(\n provider: 'google' | 'openstreetmap',\n ):\n | { provider: 'google'; apiKey: string }\n | { provider: 'openstreetmap'; userAgent: string } {\n if (provider === 'google') {\n return {\n provider: 'google',\n apiKey: process.env.GOOGLE_MAPS_API_KEY || '',\n };\n }\n return { provider: 'openstreetmap', userAgent: '@have/places' };\n }\n\n /**\n * Build a geo adapter configured for this call. Single source of truth\n * for provider wiring — `geocode` and `discoverNearby` both come through\n * here.\n */\n private async getGeoAdapter(\n provider: 'google' | 'openstreetmap',\n ): Promise<GeoAdapterWithPoiSearch> {\n return getGeoAdapter(this.getGeoAdapterOptions(provider));\n }\n\n /**\n * Get immediate children of a parent place\n *\n * @param parentId - The parent place ID\n * @returns Array of child places\n */\n async getChildren(parentId: string): Promise<Place[]> {\n return await this.list({\n where: { parentId },\n });\n }\n\n /**\n * Get root places (no parent)\n *\n * @returns Array of root places\n */\n async getRootPlaces(): Promise<Place[]> {\n return await this.list({\n where: { parentId: null },\n });\n }\n\n /**\n * Get places by type\n *\n * @param typeSlug - PlaceType slug\n * @returns Array of places of that type\n */\n async getByType(typeSlug: string): Promise<Place[]> {\n // Get type ID\n const typeCollection = await (PlaceTypeCollection as any).create(\n this.options,\n );\n\n const placeType = await typeCollection.getBySlug(typeSlug);\n if (!placeType) return [];\n\n return await this.list({\n where: { typeId: placeType.id },\n });\n }\n\n /**\n * Get place hierarchy (all ancestors and descendants)\n *\n * @param placeId - The place ID\n * @returns Object with ancestors, current place, and descendants\n */\n async getHierarchy(placeId: string) {\n const place = await this.get({ id: placeId });\n if (!place) throw new Error(`Place '${placeId}' not found`);\n\n return await place.getHierarchy();\n }\n\n async getAssets(placeId: string, relationship?: string): Promise<Asset[]> {\n return getOwnedAssetsFromCollection(this, placeId, relationship);\n }\n\n async addAsset(\n placeId: string,\n asset: Asset,\n relationship = 'attachment',\n sortOrder = 0,\n ): Promise<void> {\n await addOwnedAssetFromCollection(\n this,\n 'Place',\n placeId,\n asset,\n relationship,\n sortOrder,\n );\n }\n\n async removeAsset(\n placeId: string,\n assetId: string,\n relationship?: string,\n ): Promise<void> {\n await removeOwnedAssetFromCollection(\n this,\n 'Place',\n placeId,\n assetId,\n relationship,\n );\n }\n\n /**\n * Search places by proximity to coordinates\n *\n * @param latitude - Center latitude\n * @param longitude - Center longitude\n * @param radiusKm - Search radius in kilometers\n * @returns Array of places within radius, sorted by distance\n */\n async searchByProximity(\n latitude: number,\n longitude: number,\n radiusKm: number = 10,\n ): Promise<Place[]> {\n // Get all places with coordinates\n const places = await this.list({\n where: {\n latitude: { $ne: null },\n longitude: { $ne: null },\n },\n });\n\n // Calculate distances and filter by radius\n const placesWithDistance = places\n .map((place) => {\n if (place.latitude === null || place.longitude === null) return null;\n\n const distance = this.calculateDistance(\n latitude,\n longitude,\n place.latitude,\n place.longitude,\n );\n\n return { place, distance };\n })\n .filter(\n (p): p is { place: Place; distance: number } =>\n p !== null && p.distance <= radiusKm,\n )\n .sort((a, b) => a.distance - b.distance);\n\n return placesWithDistance.map((p) => p.place);\n }\n\n /**\n * Calculate distance between two coordinates using Haversine formula\n *\n * @param lat1 - First latitude\n * @param lng1 - First longitude\n * @param lat2 - Second latitude\n * @param lng2 - Second longitude\n * @returns Distance in kilometers\n */\n private calculateDistance(\n lat1: number,\n lng1: number,\n lat2: number,\n lng2: number,\n ): number {\n const R = 6371; // Earth radius in km\n const dLat = this.toRad(lat2 - lat1);\n const dLng = this.toRad(lng2 - lng1);\n\n const a =\n Math.sin(dLat / 2) * Math.sin(dLat / 2) +\n Math.cos(this.toRad(lat1)) *\n Math.cos(this.toRad(lat2)) *\n Math.sin(dLng / 2) *\n Math.sin(dLng / 2);\n\n const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));\n return R * c;\n }\n\n /**\n * Convert degrees to radians\n */\n private toRad(degrees: number): number {\n return degrees * (Math.PI / 180);\n }\n\n // ─────────────────────────────────────────────────────────────────────────────\n // Tenant Helper Methods\n // ─────────────────────────────────────────────────────────────────────────────\n\n /**\n * Find all places belonging to a specific tenant\n *\n * @param tenantId - The tenant ID to filter by\n * @returns Array of places for the tenant\n */\n async findByTenant(tenantId: string): Promise<Place[]> {\n return this.list({ where: { tenantId } });\n }\n\n /**\n * Find all global places (not associated with any tenant)\n *\n * @returns Array of global places\n */\n async findGlobal(): Promise<Place[]> {\n return this.list({ where: { tenantId: null } });\n }\n\n /**\n * Find places for a tenant including global places\n *\n * @param tenantId - The tenant ID to include\n * @returns Array of tenant-specific and global places\n */\n async findWithGlobals(tenantId: string): Promise<Place[]> {\n return this.query(\n `SELECT * FROM ${this.tableName} WHERE tenant_id = ? OR tenant_id IS NULL`,\n [tenantId],\n );\n }\n}\n"],"names":["__decorateClass","PlaceCollection","PlaceTypeCollection","PlaceAssetCollection","tenantId"],"mappings":";;;;;AAsBA,eAAe;AAAA,EACb,IAAA,IAAA,mBAAA,YAAA,GAAA;AACF;;;;;;;;;;;ACEO,IAAM,aAAN,cAAyB,WAAW;AAAA,EAEzC,WAA0B;AAAA,EAG1B,UAAU;AAAA,EAGV,UAAU;AAAA,EAGV,eAAe;AAAA,EAGf,YAAY;AAAA,EAEZ,YAAY,UAA6B,IAAI;AAC3C,UAAM,OAAO;AACb,QAAI,QAAQ,QAAS,MAAK,UAAU,QAAQ;AAC5C,QAAI,QAAQ,QAAS,MAAK,UAAU,QAAQ;AAC5C,QAAI,QAAQ,aAAc,MAAK,eAAe,QAAQ;AACtD,QAAI,QAAQ,cAAc,OAAW,MAAK,YAAY,QAAQ;AAC9D,QAAI,QAAQ,aAAa,OAAW,MAAK,WAAW,QAAQ;AAAA,EAC9D;AACF;AAtBEA,kBAAA;AAAA,EADC,SAAS,EAAE,UAAU,KAAA,CAAM;AAAA,GADjB,WAEX,WAAA,YAAA,CAAA;AAGAA,kBAAA;AAAA,EADC,WAAW,SAAS,EAAE,UAAU,MAAM;AAAA,GAJ5B,WAKX,WAAA,WAAA,CAAA;AAGAA,kBAAA;AAAA,EADC,gBAAgB,oCAAoC,EAAE,UAAU,MAAM;AAAA,GAP5D,WAQX,WAAA,WAAA,CAAA;AAG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AA,EACb;AAAA;AAAA;AAAA;AAAA,EAKQ,MAAM,SAAyB;AACrC,WAAO,WAAW,KAAK,KAAK;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,MAAM,aAAaI,WAAoC;AACrD,WAAO,KAAK,KAAK,EAAE,OAAO,EAAE,UAAAA,UAAA,GAAY;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,aAA+B;AACnC,WAAO,KAAK,KAAK,EAAE,OAAO,EAAE,UAAU,KAAA,GAAQ;AAAA,EAChD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,gBAAgBA,WAAoC;AACxD,WAAO,KAAK;AAAA,MACV,iBAAiB,KAAK,SAAS;AAAA,MAC/B,CAACA,SAAQ;AAAA,IAAA;AAAA,EAEb;AACF;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/__smrt-register__.ts","../src/models/PlaceAsset.ts","../src/collections/PlaceAssetCollection.ts","../src/models/Place.ts","../src/models/PlaceType.ts","../src/collections/PlaceTypeCollection.ts","../src/collections/PlaceCollection.ts"],"sourcesContent":["/**\n * Self-registers this package's build-time manifest before any @smrt() decorator\n * in the package fires. Fixes issue #1132: in consumer runtimes (tsx, SvelteKit\n * SSR, plain `vite dev`) the decorator's synchronous manifest lookup previously\n * missed because no step populated the global manifest cache — classes got\n * registered with zero fields and `save()` / `toJSON()` silently dropped every\n * declared property.\n *\n * Import this module as the first statement in `src/index.ts` so its top-level\n * side effect runs ahead of any class module's @smrt() decorator.\n *\n * Silent no-op in dev/test, where the vitest plugin already populates manifests\n * via a different path. Only needs to succeed in the published dist output.\n *\n * @see https://github.com/happyvertical/smrt/issues/1132\n */\nimport { ObjectRegistry } from '@happyvertical/smrt-core';\n\n// `new URL('./manifest.json', import.meta.url)` resolves at runtime to the\n// manifest sitting next to this module's compiled output. Vite warns at build\n// time that it cannot pre-resolve the URL; that is the intended behavior —\n// the URL must resolve to dist/manifest.json at runtime, not be inlined.\nObjectRegistry.registerPackageManifest(\n new URL('./manifest.json', import.meta.url),\n);\n","import type { SmrtObjectOptions } from '@happyvertical/smrt-core';\nimport {\n crossPackageRef,\n field,\n foreignKey,\n SmrtObject,\n smrt,\n} from '@happyvertical/smrt-core';\nimport { TenantScoped, tenantId } from '@happyvertical/smrt-tenancy';\n\nexport interface PlaceAssetOptions extends SmrtObjectOptions {\n placeId?: string;\n assetId?: string;\n relationship?: string;\n sortOrder?: number;\n tenantId?: string | null;\n}\n\n@TenantScoped({ mode: 'optional' })\n@smrt({\n tableName: 'place_assets',\n conflictColumns: ['place_id', 'asset_id', 'relationship'],\n api: false,\n mcp: false,\n cli: false,\n})\nexport class PlaceAsset extends SmrtObject {\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n @foreignKey('Place', { required: true })\n placeId = '';\n\n @crossPackageRef('@happyvertical/smrt-assets:Asset', { required: true })\n assetId = '';\n\n @field({ required: true })\n relationship = 'attachment';\n\n @field()\n sortOrder = 0;\n\n constructor(options: PlaceAssetOptions = {}) {\n super(options);\n if (options.placeId) this.placeId = options.placeId;\n if (options.assetId) this.assetId = options.assetId;\n if (options.relationship) this.relationship = options.relationship;\n if (options.sortOrder !== undefined) this.sortOrder = options.sortOrder;\n if (options.tenantId !== undefined) this.tenantId = options.tenantId;\n }\n}\n","import type { Asset } from '@happyvertical/smrt-assets';\nimport {\n addOwnedAssetFromCollection,\n getOwnedAssetsFromCollection,\n removeOwnedAssetFromCollection,\n} from '@happyvertical/smrt-assets';\nimport type { SmrtCollectionOptions } from '@happyvertical/smrt-core';\nimport { SmrtJunction, smrt } from '@happyvertical/smrt-core';\nimport { PlaceAsset } from '../models/PlaceAsset';\nimport type { PlaceCollection } from './PlaceCollection';\n\nexport interface PlaceAssetCollectionOptions extends SmrtCollectionOptions {}\n\n@smrt({\n api: false,\n mcp: false,\n cli: false,\n})\nexport class PlaceAssetCollection extends SmrtJunction<PlaceAsset> {\n static readonly _itemClass = PlaceAsset;\n protected leftField = 'placeId';\n protected rightField = 'assetId';\n\n private placeCollectionPromise: Promise<PlaceCollection> | null = null;\n\n private async getPlaceCollection(): Promise<PlaceCollection> {\n if (!this.placeCollectionPromise) {\n const { PlaceCollection } = await import('./PlaceCollection');\n this.placeCollectionPromise = PlaceCollection.create({ db: this.db });\n }\n\n return this.placeCollectionPromise;\n }\n\n async getAssets(placeId: string, relationship?: string): Promise<Asset[]> {\n return getOwnedAssetsFromCollection(\n await this.getPlaceCollection(),\n placeId,\n relationship,\n );\n }\n\n async addAsset(\n placeId: string,\n asset: Asset,\n relationship = 'attachment',\n sortOrder = 0,\n ): Promise<void> {\n await addOwnedAssetFromCollection(\n await this.getPlaceCollection(),\n 'Place',\n placeId,\n asset,\n relationship,\n sortOrder,\n );\n }\n\n async removeAsset(\n placeId: string,\n assetId: string,\n relationship?: string,\n ): Promise<void> {\n await removeOwnedAssetFromCollection(\n await this.getPlaceCollection(),\n 'Place',\n placeId,\n assetId,\n relationship,\n );\n }\n}\n","/**\n * Place model - Core entity for hierarchical place management\n *\n * Supports both real-world places with geo data and abstract places\n * (virtual worlds, game zones) by making all geo fields optional.\n *\n * Tenancy: Places are tenant-scoped with optional mode, allowing:\n * - Tenant-specific places (tenantId set)\n * - Global/shared places (tenantId null)\n */\n\nimport type { Asset } from '@happyvertical/smrt-assets';\nimport {\n assertValidOwnedAssetRelationship,\n assertValidOwnedAssetSortOrder,\n resolveOwnedAssetsById,\n} from '@happyvertical/smrt-assets';\nimport {\n field,\n foreignKey,\n SmrtHierarchical,\n smrt,\n} from '@happyvertical/smrt-core';\nimport { TenantScoped, tenantId } from '@happyvertical/smrt-tenancy';\nimport type { GeoData, PlaceOptions } from '../types';\n\n@TenantScoped({ mode: 'optional' })\n@smrt({\n tableStrategy: 'sti',\n api: { include: ['list', 'get', 'create', 'update', 'delete'] },\n mcp: { include: ['list', 'get', 'create', 'update'] },\n cli: true,\n})\nexport class Place extends SmrtHierarchical {\n // id: UUID (auto-generated by SmrtObject)\n\n // Tenancy field - nullable for global/shared places\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n // Core fields\n @foreignKey('PlaceType')\n typeId = ''; // FK to PlaceType\n // parentId inherited from SmrtHierarchical (nullable, self-reference)\n name = ''; // Place name/title\n description = ''; // Optional description\n\n // Optional geo fields (all nullable for abstract places)\n @field({ type: 'decimal' })\n latitude: number | null = null;\n @field({ type: 'decimal' })\n longitude: number | null = null;\n streetNumber = '';\n streetName = '';\n city = '';\n region = '';\n country = '';\n postalCode = '';\n countryCode = '';\n timezone = '';\n\n // Metadata\n externalId = ''; // External system identifier\n source = ''; // Where this place came from (e.g., 'google', 'osm')\n metadata = ''; // JSON metadata stored as text\n\n // Timestamps\n createdAt = new Date();\n updatedAt = new Date();\n\n constructor(options: PlaceOptions = {}) {\n super(options);\n\n // Tenancy field\n if (options.tenantId !== undefined) this.tenantId = options.tenantId as any;\n\n // Core fields\n if (options.typeId) this.typeId = options.typeId;\n if (options.parentId !== undefined)\n this.parentId = options.parentId ?? null;\n if (options.name) this.name = options.name;\n if (options.description !== undefined)\n this.description = options.description;\n\n // Geo fields\n if (options.latitude !== undefined) this.latitude = options.latitude;\n if (options.longitude !== undefined) this.longitude = options.longitude;\n if (options.streetNumber !== undefined)\n this.streetNumber = options.streetNumber;\n if (options.streetName !== undefined) this.streetName = options.streetName;\n if (options.city !== undefined) this.city = options.city;\n if (options.region !== undefined) this.region = options.region;\n if (options.country !== undefined) this.country = options.country;\n if (options.postalCode !== undefined) this.postalCode = options.postalCode;\n if (options.countryCode !== undefined)\n this.countryCode = options.countryCode;\n if (options.timezone !== undefined) this.timezone = options.timezone;\n\n // Metadata\n if (options.externalId !== undefined) this.externalId = options.externalId;\n if (options.source !== undefined) this.source = options.source;\n\n // Handle metadata - can be object or JSON string\n if (options.metadata !== undefined) {\n if (typeof options.metadata === 'string') {\n this.metadata = options.metadata;\n } else {\n this.metadata = JSON.stringify(options.metadata);\n }\n }\n\n // Timestamps\n if (options.createdAt) this.createdAt = options.createdAt;\n if (options.updatedAt) this.updatedAt = options.updatedAt;\n }\n\n /**\n * Get geographic data for this place\n *\n * @returns GeoData object with all geo fields\n */\n getGeoData(): GeoData {\n return {\n latitude: this.latitude,\n longitude: this.longitude,\n streetNumber: this.streetNumber || undefined,\n streetName: this.streetName || undefined,\n city: this.city || undefined,\n region: this.region || undefined,\n country: this.country || undefined,\n postalCode: this.postalCode || undefined,\n countryCode: this.countryCode || undefined,\n timezone: this.timezone || undefined,\n };\n }\n\n /**\n * Check if this place has geographic coordinates\n *\n * @returns True if latitude and longitude are set\n */\n hasCoordinates(): boolean {\n return this.latitude !== null && this.longitude !== null;\n }\n\n /**\n * Get metadata as parsed object\n *\n * @returns Parsed metadata object or empty object if no metadata\n */\n getMetadata(): Record<string, any> {\n if (!this.metadata) return {};\n try {\n return JSON.parse(this.metadata);\n } catch {\n return {};\n }\n }\n\n /**\n * Set metadata from object\n *\n * @param data - Metadata object to store\n */\n setMetadata(data: Record<string, any>): void {\n this.metadata = JSON.stringify(data);\n }\n\n /**\n * Update metadata by merging with existing values\n *\n * @param updates - Partial metadata to merge\n */\n updateMetadata(updates: Record<string, any>): void {\n const current = this.getMetadata();\n this.setMetadata({ ...current, ...updates });\n }\n\n /**\n * Get the place type\n *\n * @returns PlaceType instance or null if not found\n */\n async getType() {\n if (!this.typeId) return null;\n\n const { PlaceTypeCollection } = await import(\n '../collections/PlaceTypeCollection'\n );\n const collection = await (PlaceTypeCollection as any).create(this.options);\n\n return await collection.get({ id: this.typeId });\n }\n\n // Hierarchy traversal (getParent / getChildren / getAncestors /\n // getDescendants / getHierarchy / moveTo) provided by SmrtHierarchical.\n\n private async getPlaceAssetCollection() {\n const { PlaceAssetCollection } = await import(\n '../collections/PlaceAssetCollection'\n );\n return PlaceAssetCollection.create({ db: this.db });\n }\n async getAssets(relationship?: string): Promise<Asset[]> {\n if (!this.id) {\n return [];\n }\n\n const placeAssets = await this.getPlaceAssetCollection();\n const linkedAssets = await placeAssets.byLeft(\n this.id,\n relationship ? { relationship } : {},\n );\n\n return resolveOwnedAssetsById(\n this.db,\n linkedAssets.map((link) => link.assetId),\n this.tenantId,\n );\n }\n\n async addAsset(\n asset: Asset,\n relationship = 'attachment',\n sortOrder = 0,\n ): Promise<void> {\n if (!this.id || !asset.id) {\n throw new Error('Cannot associate unsaved place or asset');\n }\n\n assertValidOwnedAssetRelationship(relationship);\n assertValidOwnedAssetSortOrder(sortOrder);\n\n const placeAssets = await this.getPlaceAssetCollection();\n await placeAssets.attach(this.id, asset.id, {\n relationship,\n sortOrder,\n tenantId: this.tenantId,\n });\n }\n\n async removeAsset(assetId: string, relationship?: string): Promise<void> {\n if (!this.id) {\n return;\n }\n\n const placeAssets = await this.getPlaceAssetCollection();\n await placeAssets.detach(\n this.id,\n assetId,\n relationship ? { relationship } : {},\n );\n }\n}\n","/**\n * PlaceType model - Defines types/categories of places\n *\n * Examples: 'country', 'city', 'building', 'zone', 'room', 'region'\n */\n\nimport { field, SmrtObject, smrt } from '@happyvertical/smrt-core';\nimport type { PlaceTypeOptions } from '../types';\n\n@smrt({\n tableStrategy: 'sti',\n api: { include: ['list', 'get', 'create', 'update', 'delete'] },\n mcp: { include: ['list', 'get', 'create'] },\n cli: true,\n})\nexport class PlaceType extends SmrtObject {\n // id and slug are inherited from SmrtObject\n @field({ required: true })\n name: string = ''; // Type name (e.g., 'Town', 'City', 'Country')\n\n description?: string; // Optional description\n\n // Timestamps\n createdAt = new Date();\n updatedAt = new Date();\n\n constructor(options: PlaceTypeOptions = {}) {\n super(options);\n if (options.name) this.name = options.name;\n if (options.description !== undefined)\n this.description = options.description;\n if (options.createdAt) this.createdAt = options.createdAt;\n if (options.updatedAt) this.updatedAt = options.updatedAt;\n }\n\n /**\n * Convenience method for slug-based lookup\n *\n * @param slug - The slug to search for\n * @returns PlaceType instance or null if not found\n */\n static async getBySlug(_slug: string): Promise<PlaceType | null> {\n // Will be auto-implemented by SMRT\n return null;\n }\n}\n","/**\n * PlaceTypeCollection - Collection manager for PlaceType objects\n *\n * Provides simple lookup and creation for place types.\n */\n\nimport { SmrtCollection } from '@happyvertical/smrt-core';\nimport { PlaceType } from '../models/PlaceType';\n\nexport class PlaceTypeCollection extends SmrtCollection<PlaceType> {\n static readonly _itemClass = PlaceType;\n\n /**\n * Get or create a place type by slug\n *\n * @param slug - PlaceType slug (e.g., 'city', 'building')\n * @param name - Optional display name (defaults to capitalized slug)\n * @returns PlaceType instance\n */\n async getOrCreate(slug: string, name?: string): Promise<PlaceType> {\n // First try to find existing type with this slug\n const existing = await this.get({ slug });\n\n if (existing) {\n return existing;\n }\n\n // Create new type with auto-generated name if not provided\n const displayName =\n name || slug.replace(/-/g, ' ').replace(/\\b\\w/g, (l) => l.toUpperCase());\n\n return await this.create({\n slug,\n name: displayName,\n });\n }\n\n /**\n * Get a place type by slug\n *\n * @param slug - PlaceType slug to search for\n * @returns PlaceType instance or null if not found\n */\n async getBySlug(slug: string): Promise<PlaceType | null> {\n return await this.get({ slug });\n }\n\n /**\n * Initialize default place types\n *\n * Creates standard types if they don't exist:\n * - country\n * - region (state/province)\n * - city\n * - address\n * - building\n * - room\n * - zone (for abstract/virtual places)\n *\n * @returns Array of created/existing place types\n */\n async initializeDefaults(): Promise<PlaceType[]> {\n const defaults = [\n { slug: 'country', name: 'Country' },\n { slug: 'region', name: 'Region' },\n { slug: 'city', name: 'City' },\n { slug: 'address', name: 'Address' },\n { slug: 'building', name: 'Building' },\n { slug: 'room', name: 'Room' },\n { slug: 'zone', name: 'Zone' },\n { slug: 'point_of_interest', name: 'Point of Interest' },\n ];\n\n const types: PlaceType[] = [];\n for (const def of defaults) {\n const type = await this.getOrCreate(def.slug, def.name);\n types.push(type);\n }\n\n return types;\n }\n}\n","/**\n * PlaceCollection - Collection manager for Place objects\n *\n * Provides hierarchy traversal and organic place database growth via\n * lookupOrCreate method that integrates with @happyvertical/geo.\n */\n\nimport type { GeoAdapter, Location } from '@happyvertical/geo';\nimport { getGeoAdapter } from '@happyvertical/geo';\nimport type { Asset } from '@happyvertical/smrt-assets';\nimport {\n addOwnedAssetFromCollection,\n getOwnedAssetsFromCollection,\n removeOwnedAssetFromCollection,\n} from '@happyvertical/smrt-assets';\nimport { SmrtCollection } from '@happyvertical/smrt-core';\nimport { queryGlobal, queryWithGlobals } from '@happyvertical/smrt-tenancy';\nimport { Place } from '../models/Place';\nimport type {\n DiscoverNearbyOptions,\n LookupOrCreateOptions,\n ResolveTrackPlacesOptions,\n TrackPlacesResult,\n TrackPoint,\n} from '../types';\nimport { PlaceTypeCollection } from './PlaceTypeCollection';\n\ntype PoiSearchOptions = Pick<\n DiscoverNearbyOptions,\n 'types' | 'keyword' | 'limit' | 'language'\n>;\n\ntype GeoAdapterWithPoiSearch = GeoAdapter & {\n findPoisNear?: (\n latitude: number,\n longitude: number,\n radiusMeters: number,\n options?: PoiSearchOptions,\n ) => Promise<Location[]>;\n};\n\nexport class PlaceCollection extends SmrtCollection<Place> {\n static readonly _itemClass = Place;\n\n /**\n * Look up a place by query or coordinates, creating it if not found\n *\n * This is the key method for organic database growth:\n * 1. Search local database first\n * 2. If not found, query @happyvertical/geo\n * 3. Create place from geocoding result\n * 4. Return place\n *\n * @param query - Address or location query string\n * @param options - Lookup options (provider, type, parent, etc.)\n * @returns Place instance\n */\n async lookupOrCreate(\n query: string,\n options: LookupOrCreateOptions = {},\n ): Promise<Place | null> {\n const {\n geoProvider = 'openstreetmap',\n typeSlug,\n parentId,\n createIfNotFound = true,\n coords,\n } = options;\n\n // Step 1: Try to find existing place\n let existingPlace: Place | null = null;\n\n // Search by coordinates if provided\n if (coords) {\n existingPlace = await this.findByCoordinates(coords.lat, coords.lng);\n }\n\n // Search by query text if coordinates didn't match\n if (!existingPlace) {\n existingPlace = await this.findByQuery(query);\n }\n\n if (existingPlace) {\n return existingPlace;\n }\n\n // Step 2: If not found and createIfNotFound is false, return null\n if (!createIfNotFound) {\n return null;\n }\n\n // Step 3: Query @happyvertical/geo for location data\n const locations = await this.geocode(\n query,\n coords,\n geoProvider as 'google' | 'openstreetmap',\n );\n\n if (locations.length === 0) {\n return null;\n }\n\n // Use first result (most relevant)\n const location = locations[0];\n\n // Step 4: Create place from location data\n return await this.createFromLocation(location, typeSlug, parentId);\n }\n\n /**\n * Find place by coordinates (within small threshold)\n *\n * @param latitude - Latitude to search\n * @param longitude - Longitude to search\n * @param threshold - Max distance in degrees (default: 0.0001 ~11m)\n * @returns Place instance or null\n */\n private async findByCoordinates(\n latitude: number,\n longitude: number,\n threshold: number = 0.0001,\n ): Promise<Place | null> {\n // Get all places with coordinates\n const places = await this.list({\n where: {\n latitude: { $ne: null },\n longitude: { $ne: null },\n },\n });\n\n // Find closest match within threshold\n for (const place of places) {\n // Cast to access Place-specific properties\n const placeObj = place as Place;\n if (placeObj.latitude === null || placeObj.longitude === null) continue;\n\n const latDiff = Math.abs(placeObj.latitude - latitude);\n const lngDiff = Math.abs(placeObj.longitude - longitude);\n\n if (latDiff < threshold && lngDiff < threshold) {\n return place;\n }\n }\n\n return null;\n }\n\n /**\n * Find place by query text (matches name, city, region, country)\n *\n * @param query - Search query\n * @returns Place instance or null\n */\n private async findByQuery(query: string): Promise<Place | null> {\n const normalizedQuery = query.toLowerCase().trim();\n\n // Try exact match on name first\n const places = await this.list({});\n\n for (const place of places) {\n // Match on name\n if (place.name.toLowerCase().includes(normalizedQuery)) {\n return place;\n }\n\n // Match on full address components\n const addressParts = [\n place.streetNumber,\n place.streetName,\n place.city,\n place.region,\n place.country,\n ]\n .filter((p) => p)\n .join(' ')\n .toLowerCase();\n\n if (addressParts.includes(normalizedQuery)) {\n return place;\n }\n }\n\n return null;\n }\n\n /**\n * Geocode query or coordinates using @happyvertical/geo\n *\n * @param query - Address query\n * @param coords - Optional coordinates for reverse geocoding\n * @param provider - Geo provider to use\n * @returns Array of Location results\n */\n private async geocode(\n query: string,\n coords?: { lat: number; lng: number },\n provider: 'google' | 'openstreetmap' = 'openstreetmap',\n ): Promise<Location[]> {\n const geo = await this.getGeoAdapter(provider);\n\n // Use reverse geocode if coords provided, otherwise forward geocode\n if (coords) {\n return await geo.reverseGeocode(coords.lat, coords.lng);\n }\n\n return await geo.lookup(query);\n }\n\n /**\n * Find a place by the provider's native id (Google place_id, OSM\n * osm-node-N, etc.). Used as the primary idempotency key by\n * `discoverNearby` so repeat POI searches don't create duplicate rows.\n */\n private async findByExternalId(externalId: string): Promise<Place | null> {\n if (!externalId) return null;\n const matches = await this.list({\n where: { externalId },\n limit: 1,\n });\n return matches[0] ?? null;\n }\n\n /**\n * Idempotent \"find or create\" for a geo Location. Keyed purely on the\n * provider's externalId (Google place_id, osm-node-*, etc.), which is\n * stable per POI across repeat searches. The older `lookupOrCreate`\n * keeps its own fallback chain (name/address/coordinate matching) for\n * address-style workflows where externalId isn't reliable.\n *\n * Returns `{ place, created }` so callers can distinguish fresh rows\n * from reused ones without re-querying the table — this is how\n * `resolveTrackPlaces` derives its `cacheHitCount` without a full\n * scan per bucket.\n */\n private async ensureFromLocation(\n location: Location,\n typeSlug?: string,\n parentId?: string | null,\n ): Promise<{ place: Place; created: boolean }> {\n if (location.id) {\n const existing = await this.findByExternalId(location.id);\n if (existing) return { place: existing, created: false };\n }\n const place = await this.createFromLocation(location, typeSlug, parentId);\n return { place, created: true };\n }\n\n /**\n * Create place from @happyvertical/geo Location data\n *\n * @param location - Location from geocoding\n * @param typeSlug - Optional type slug override\n * @param parentId - Optional parent place ID\n * @returns Created Place instance\n */\n private async createFromLocation(\n location: Location,\n typeSlug?: string,\n parentId?: string | null,\n ): Promise<Place> {\n // Get or create place type\n const typeCollection = await (PlaceTypeCollection as any).create(\n this.options,\n );\n\n const slug = typeSlug || location.type || 'address';\n const placeType = await typeCollection.getOrCreate(slug);\n\n // Extract address components\n const components = location.addressComponents || {};\n\n // Create place\n return await this.create({\n typeId: placeType.id,\n parentId: parentId ?? null,\n name: location.name,\n description: '',\n\n // Geo fields from location\n latitude: location.latitude,\n longitude: location.longitude,\n streetNumber: components.streetNumber || '',\n streetName: components.streetName || '',\n city: components.city || '',\n region: components.region || '',\n country: components.country || '',\n postalCode: components.postalCode || '',\n countryCode: location.countryCode || '',\n timezone: location.timezone || '',\n\n // Metadata\n externalId: location.id,\n source: location.raw?.provider || 'unknown',\n metadata: JSON.stringify({ raw: location.raw ?? null }),\n });\n }\n\n /**\n * Discover POIs near a coordinate and persist them as Place rows.\n *\n * Composes `@happyvertical/geo`'s `findPoisNear` with `ensureFromLocation`\n * so every returned POI is either reused from the local DB (when the\n * provider returns an id matching an existing Place `externalId`) or\n * created fresh otherwise. The cache is effectively automatic because\n * the provider's own place_id becomes the Place row's `externalId`, so\n * calling `discoverNearby` twice for the same area on the same provider\n * is a no-op after the first run when the provider returns stable ids.\n *\n * Requires a geo provider that implements `findPoisNear`. Throws a clear\n * error otherwise so consumers can fall back to `lookupOrCreate` or\n * switch providers.\n */\n async discoverNearby(\n latitude: number,\n longitude: number,\n radiusMeters: number,\n options: DiscoverNearbyOptions = {},\n ): Promise<Place[]> {\n if (!(radiusMeters > 0)) {\n throw new Error(\n `discoverNearby: radiusMeters must be > 0 (got ${radiusMeters})`,\n );\n }\n const detailed = await this.discoverNearbyDetailed(\n latitude,\n longitude,\n radiusMeters,\n options,\n );\n return detailed.map((d) => d.place);\n }\n\n /**\n * Internal variant of `discoverNearby` that exposes whether each\n * returned Place was created during this call (`true`) or reused from\n * an earlier call (`false`). Used by `resolveTrackPlaces` to classify\n * buckets as cache hits without having to re-scan the Place table.\n */\n private async discoverNearbyDetailed(\n latitude: number,\n longitude: number,\n radiusMeters: number,\n options: DiscoverNearbyOptions = {},\n ): Promise<Array<{ place: Place; created: boolean }>> {\n const {\n geoProvider = 'openstreetmap',\n types,\n keyword,\n limit,\n language,\n typeSlug,\n parentId,\n } = options;\n\n const geo = await this.getGeoAdapter(geoProvider);\n if (typeof geo.findPoisNear !== 'function') {\n throw new Error(\n `Geo provider '${geoProvider}' does not implement findPoisNear`,\n );\n }\n\n const results = await geo.findPoisNear(latitude, longitude, radiusMeters, {\n types,\n keyword,\n limit,\n language,\n });\n\n const detailed: Array<{ place: Place; created: boolean }> = [];\n for (const result of results) {\n detailed.push(await this.ensureFromLocation(result, typeSlug, parentId));\n }\n return detailed;\n }\n\n /**\n * Resolve POIs along a GPS track (e.g. a video's per-frame path).\n *\n * Naively walking every point would hammer the provider with redundant\n * requests — consecutive samples are usually within a few meters. This\n * method buckets points into a `bucketMeters`-wide grid, calls\n * `discoverNearby` once per distinct bucket, and throttles requests per\n * `throttleMs` so free tiers (Overpass, Nominatim) stay inside their\n * community rate limits without the caller having to manage a queue.\n *\n * The returned `places` are deduped across buckets by Place id, so a\n * POI that falls within several overlapping search radii appears once.\n */\n async resolveTrackPlaces(\n points: ReadonlyArray<TrackPoint>,\n options: ResolveTrackPlacesOptions = {},\n ): Promise<TrackPlacesResult> {\n const radiusMeters = options.radiusMeters ?? 50;\n const bucketMeters = options.bucketMeters ?? 50;\n const throttleMs = options.throttleMs ?? 1100;\n\n if (!(radiusMeters > 0)) {\n throw new Error(\n `resolveTrackPlaces: radiusMeters must be > 0 (got ${radiusMeters})`,\n );\n }\n if (!(bucketMeters > 0)) {\n // Grid/greedy bucketing both divide by bucketMeters; a non-positive\n // value would either NaN the math or produce \"everything in one\n // bucket\", neither of which the caller likely meant.\n throw new Error(\n `resolveTrackPlaces: bucketMeters must be > 0 (got ${bucketMeters})`,\n );\n }\n if (throttleMs < 0 || !Number.isFinite(throttleMs)) {\n throw new Error(\n `resolveTrackPlaces: throttleMs must be a finite non-negative number (got ${throttleMs})`,\n );\n }\n\n // Greedy proximity-based bucketing: each new point joins the nearest\n // existing bucket within `bucketMeters` (Haversine), otherwise seeds a\n // new bucket with itself as the center. This matches the documented\n // semantic (\"points within bucketMeters of each other collapse into\n // one request\") more faithfully than a `Math.round`-on-grid scheme,\n // which can split two points ~0.2m apart if they straddle a cell\n // boundary and inflate requestCount exactly when the user was trying\n // to rate-limit.\n const bucketMetersKm = bucketMeters / 1000;\n const bucketCenters: TrackPoint[] = [];\n for (const point of points) {\n if (!Number.isFinite(point.lat) || !Number.isFinite(point.lng)) continue;\n let bestIdx = -1;\n let bestKm = Number.POSITIVE_INFINITY;\n for (let i = 0; i < bucketCenters.length; i += 1) {\n const c = bucketCenters[i];\n const km = this.calculateDistance(c.lat, c.lng, point.lat, point.lng);\n if (km <= bucketMetersKm && km < bestKm) {\n bestKm = km;\n bestIdx = i;\n }\n }\n if (bestIdx < 0) bucketCenters.push(point);\n }\n\n const result: TrackPlacesResult = {\n places: [],\n requestCount: 0,\n cacheHitCount: 0,\n bucketCount: bucketCenters.length,\n };\n const seen = new Map<string, Place>();\n\n let lastCallAt = 0;\n for (const center of bucketCenters) {\n const wait = lastCallAt + throttleMs - Date.now();\n if (wait > 0) {\n await new Promise((resolve) => setTimeout(resolve, wait));\n }\n\n const detailed = await this.discoverNearbyDetailed(\n center.lat,\n center.lng,\n radiusMeters,\n options,\n );\n lastCallAt = Date.now();\n result.requestCount += 1;\n\n // Cache hit = the provider returned results and every one of them\n // matched a Place that already existed (explicit `created === false`\n // from ensureFromLocation). No timestamp heuristics, no re-scan.\n if (detailed.length > 0 && detailed.every((d) => !d.created)) {\n result.cacheHitCount += 1;\n }\n\n for (const { place } of detailed) {\n if (place.id && !seen.has(place.id)) seen.set(place.id, place);\n }\n }\n\n result.places = [...seen.values()];\n return result;\n }\n\n /**\n * Provider wiring (env keys, user-agent string, etc.) that `geocode`\n * and `discoverNearby` share so the two code paths can't drift. Kept\n * separate from the adapter call itself so tests and future providers\n * can inspect or override the options before construction.\n */\n private getGeoAdapterOptions(\n provider: 'google' | 'openstreetmap',\n ):\n | { provider: 'google'; apiKey: string }\n | { provider: 'openstreetmap'; userAgent: string } {\n if (provider === 'google') {\n return {\n provider: 'google',\n apiKey: process.env.GOOGLE_MAPS_API_KEY || '',\n };\n }\n return { provider: 'openstreetmap', userAgent: '@have/places' };\n }\n\n /**\n * Build a geo adapter configured for this call. Single source of truth\n * for provider wiring — `geocode` and `discoverNearby` both come through\n * here.\n */\n private async getGeoAdapter(\n provider: 'google' | 'openstreetmap',\n ): Promise<GeoAdapterWithPoiSearch> {\n return getGeoAdapter(this.getGeoAdapterOptions(provider));\n }\n\n /**\n * Get immediate children of a parent place\n *\n * @param parentId - The parent place ID\n * @returns Array of child places\n */\n async getChildren(parentId: string): Promise<Place[]> {\n return await this.list({\n where: { parentId },\n });\n }\n\n /**\n * Get root places (no parent)\n *\n * @returns Array of root places\n */\n async getRootPlaces(): Promise<Place[]> {\n return await this.list({\n where: { parentId: null },\n });\n }\n\n /**\n * Get places by type\n *\n * @param typeSlug - PlaceType slug\n * @returns Array of places of that type\n */\n async getByType(typeSlug: string): Promise<Place[]> {\n // Get type ID\n const typeCollection = await (PlaceTypeCollection as any).create(\n this.options,\n );\n\n const placeType = await typeCollection.getBySlug(typeSlug);\n if (!placeType) return [];\n\n return await this.list({\n where: { typeId: placeType.id },\n });\n }\n\n /**\n * Get place hierarchy (all ancestors and descendants)\n *\n * @param placeId - The place ID\n * @returns Object with ancestors, current place, and descendants\n */\n async getHierarchy(placeId: string) {\n const place = await this.get({ id: placeId });\n if (!place) throw new Error(`Place '${placeId}' not found`);\n\n return await place.getHierarchy();\n }\n\n async getAssets(placeId: string, relationship?: string): Promise<Asset[]> {\n return getOwnedAssetsFromCollection(this, placeId, relationship);\n }\n\n async addAsset(\n placeId: string,\n asset: Asset,\n relationship = 'attachment',\n sortOrder = 0,\n ): Promise<void> {\n await addOwnedAssetFromCollection(\n this,\n 'Place',\n placeId,\n asset,\n relationship,\n sortOrder,\n );\n }\n\n async removeAsset(\n placeId: string,\n assetId: string,\n relationship?: string,\n ): Promise<void> {\n await removeOwnedAssetFromCollection(\n this,\n 'Place',\n placeId,\n assetId,\n relationship,\n );\n }\n\n /**\n * Search places by proximity to coordinates\n *\n * @param latitude - Center latitude\n * @param longitude - Center longitude\n * @param radiusKm - Search radius in kilometers\n * @returns Array of places within radius, sorted by distance\n */\n async searchByProximity(\n latitude: number,\n longitude: number,\n radiusKm: number = 10,\n ): Promise<Place[]> {\n // Get all places with coordinates\n const places = await this.list({\n where: {\n latitude: { $ne: null },\n longitude: { $ne: null },\n },\n });\n\n // Calculate distances and filter by radius\n const placesWithDistance = places\n .map((place) => {\n if (place.latitude === null || place.longitude === null) return null;\n\n const distance = this.calculateDistance(\n latitude,\n longitude,\n place.latitude,\n place.longitude,\n );\n\n return { place, distance };\n })\n .filter(\n (p): p is { place: Place; distance: number } =>\n p !== null && p.distance <= radiusKm,\n )\n .sort((a, b) => a.distance - b.distance);\n\n return placesWithDistance.map((p) => p.place);\n }\n\n /**\n * Calculate distance between two coordinates using Haversine formula\n *\n * @param lat1 - First latitude\n * @param lng1 - First longitude\n * @param lat2 - Second latitude\n * @param lng2 - Second longitude\n * @returns Distance in kilometers\n */\n private calculateDistance(\n lat1: number,\n lng1: number,\n lat2: number,\n lng2: number,\n ): number {\n const R = 6371; // Earth radius in km\n const dLat = this.toRad(lat2 - lat1);\n const dLng = this.toRad(lng2 - lng1);\n\n const a =\n Math.sin(dLat / 2) * Math.sin(dLat / 2) +\n Math.cos(this.toRad(lat1)) *\n Math.cos(this.toRad(lat2)) *\n Math.sin(dLng / 2) *\n Math.sin(dLng / 2);\n\n const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));\n return R * c;\n }\n\n /**\n * Convert degrees to radians\n */\n private toRad(degrees: number): number {\n return degrees * (Math.PI / 180);\n }\n\n // ─────────────────────────────────────────────────────────────────────────────\n // Tenant Helper Methods\n // ─────────────────────────────────────────────────────────────────────────────\n\n /**\n * Find all places belonging to a specific tenant\n *\n * @param tenantId - The tenant ID to filter by\n * @returns Array of places for the tenant\n */\n async findByTenant(tenantId: string): Promise<Place[]> {\n return this.list({ where: { tenantId } });\n }\n\n /**\n * Find all global places (not associated with any tenant).\n *\n * Routes through the shared tenant-global helper so it does not throw under\n * an active tenant context (an explicit `tenant_id IS NULL` filter would be\n * flagged as an isolation violation). (#1600)\n *\n * @returns Array of global places\n */\n async findGlobal(): Promise<Place[]> {\n return queryGlobal<Place>(this);\n }\n\n /**\n * Find places for a tenant including global places.\n *\n * Fails closed if an active tenant context requests a different tenant's\n * rows; the admin/system path keeps the cross-tenant capability. (#1600)\n *\n * @param tenantId - The tenant ID to include\n * @returns Array of tenant-specific and global places\n */\n async findWithGlobals(tenantId: string): Promise<Place[]> {\n return queryWithGlobals<Place>(this, tenantId, 'Place.findWithGlobals');\n }\n}\n"],"names":["__decorateClass","PlaceCollection","PlaceTypeCollection","PlaceAssetCollection","tenantId"],"mappings":";;;;;AAsBA,eAAe;AAAA,EACb,IAAA,IAAA,mBAAA,YAAA,GAAA;AACF;;;;;;;;;;;ACEO,IAAM,aAAN,cAAyB,WAAW;AAAA,EAEzC,WAA0B;AAAA,EAG1B,UAAU;AAAA,EAGV,UAAU;AAAA,EAGV,eAAe;AAAA,EAGf,YAAY;AAAA,EAEZ,YAAY,UAA6B,IAAI;AAC3C,UAAM,OAAO;AACb,QAAI,QAAQ,QAAS,MAAK,UAAU,QAAQ;AAC5C,QAAI,QAAQ,QAAS,MAAK,UAAU,QAAQ;AAC5C,QAAI,QAAQ,aAAc,MAAK,eAAe,QAAQ;AACtD,QAAI,QAAQ,cAAc,OAAW,MAAK,YAAY,QAAQ;AAC9D,QAAI,QAAQ,aAAa,OAAW,MAAK,WAAW,QAAQ;AAAA,EAC9D;AACF;AAtBEA,kBAAA;AAAA,EADC,SAAS,EAAE,UAAU,KAAA,CAAM;AAAA,GADjB,WAEX,WAAA,YAAA,CAAA;AAGAA,kBAAA;AAAA,EADC,WAAW,SAAS,EAAE,UAAU,MAAM;AAAA,GAJ5B,WAKX,WAAA,WAAA,CAAA;AAGAA,kBAAA;AAAA,EADC,gBAAgB,oCAAoC,EAAE,UAAU,MAAM;AAAA,GAP5D,WAQX,WAAA,WAAA,CAAA;AAGAA,kBAAA;AAAA,EADC,MAAM,EAAE,UAAU,KAAA,CAAM;AAAA,GAVd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O,WAAW,KAAK,KAAK;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,MAAM,aAAaI,WAAoC;AACrD,WAAO,KAAK,KAAK,EAAE,OAAO,EAAE,UAAAA,UAAA,GAAY;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAM,aAA+B;AACnC,WAAO,YAAmB,IAAI;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAM,gBAAgBA,WAAoC;AACxD,WAAO,iBAAwB,MAAMA,WAAU,uBAAuB;AAAA,EACxE;AACF;;;;;"}
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "version": "1.0.0",
3
- "timestamp": 1782241438689,
3
+ "timestamp": 1782251998744,
4
4
  "packageName": "@happyvertical/smrt-places",
5
- "packageVersion": "0.34.0",
5
+ "packageVersion": "0.34.2",
6
6
  "objects": {
7
7
  "@happyvertical/smrt-places:PlaceAssetCollection": {
8
8
  "name": "placeassetcollection",
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "generatedAt": "2026-06-23T19:04:01.153Z",
3
+ "generatedAt": "2026-06-23T22:00:04.325Z",
4
4
  "packageName": "@happyvertical/smrt-places",
5
- "packageVersion": "0.34.0",
5
+ "packageVersion": "0.34.2",
6
6
  "sourceManifestPath": "dist/manifest.json",
7
7
  "agentDocPath": "AGENTS.md",
8
8
  "sourceHashes": {
9
- "manifest": "74eab59612f13b4631570fc71db93b47bf50bc0a199078c87f355134372ddc3e",
10
- "packageJson": "e30221c338d667d1c6473c3bf4032426148380f84f278e6b0949f6083554879b",
9
+ "manifest": "7c6553117b4752797d3fb3c7c4ea9df7d578827ec8688abd98b3c9665b4ed638",
10
+ "packageJson": "861d76b5f1112ccd65fcdb311e6c7e40258515327261b5e08c85c63bf8b03cc5",
11
11
  "agents": "1f12a465f3ef103ac0ba27bcec1ec2b982fd0f5e8a63b9a42738f2c79ecebe49"
12
12
  },
13
13
  "exports": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@happyvertical/smrt-places",
3
- "version": "0.34.0",
3
+ "version": "0.34.2",
4
4
  "description": "Hierarchical place management with geo integration and SMRT framework support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -30,9 +30,9 @@
30
30
  "@happyvertical/logger": "^0.74.7",
31
31
  "@happyvertical/sql": "^0.74.7",
32
32
  "@happyvertical/utils": "^0.74.7",
33
- "@happyvertical/smrt-core": "0.34.0",
34
- "@happyvertical/smrt-assets": "0.34.0",
35
- "@happyvertical/smrt-tenancy": "0.34.0"
33
+ "@happyvertical/smrt-core": "0.34.2",
34
+ "@happyvertical/smrt-tenancy": "0.34.2",
35
+ "@happyvertical/smrt-assets": "0.34.2"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/node": "25.0.9",
@@ -40,7 +40,7 @@
40
40
  "typescript": "^5.9.3",
41
41
  "vite": "^7.3.1",
42
42
  "vitest": "^4.0.17",
43
- "@happyvertical/smrt-vitest": "0.34.0"
43
+ "@happyvertical/smrt-vitest": "0.34.2"
44
44
  },
45
45
  "keywords": [
46
46
  "ai",