@happyvertical/smrt-places 0.35.0 → 0.35.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 +9 -9
- package/dist/index.js +3 -7
- package/dist/index.js.map +1 -1
- package/dist/manifest.json +5 -5
- package/dist/smrt-knowledge.json +4 -4
- package/dist/types.d.ts +86 -5
- package/dist/utils.js +3 -2
- package/dist/utils.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -198,25 +198,25 @@ export declare class Place extends SmrtHierarchical {
|
|
|
198
198
|
*
|
|
199
199
|
* @returns Parsed metadata object or empty object if no metadata
|
|
200
200
|
*/
|
|
201
|
-
getMetadata(): Record<string,
|
|
201
|
+
getMetadata(): Record<string, unknown>;
|
|
202
202
|
/**
|
|
203
203
|
* Set metadata from object
|
|
204
204
|
*
|
|
205
205
|
* @param data - Metadata object to store
|
|
206
206
|
*/
|
|
207
|
-
setMetadata(data: Record<string,
|
|
207
|
+
setMetadata(data: Record<string, unknown>): void;
|
|
208
208
|
/**
|
|
209
209
|
* Update metadata by merging with existing values
|
|
210
210
|
*
|
|
211
211
|
* @param updates - Partial metadata to merge
|
|
212
212
|
*/
|
|
213
|
-
updateMetadata(updates: Record<string,
|
|
213
|
+
updateMetadata(updates: Record<string, unknown>): void;
|
|
214
214
|
/**
|
|
215
215
|
* Get the place type
|
|
216
216
|
*
|
|
217
217
|
* @returns PlaceType instance or null if not found
|
|
218
218
|
*/
|
|
219
|
-
getType(): Promise<
|
|
219
|
+
getType(): Promise<PlaceType | null>;
|
|
220
220
|
private getPlaceAssetCollection;
|
|
221
221
|
getAssets(relationship?: string): Promise<Asset[]>;
|
|
222
222
|
addAsset(asset: Asset, relationship?: string, sortOrder?: number): Promise<void>;
|
|
@@ -456,9 +456,9 @@ export declare class PlaceCollection extends SmrtCollection<Place> {
|
|
|
456
456
|
* Place hierarchy structure
|
|
457
457
|
*/
|
|
458
458
|
export declare interface PlaceHierarchy {
|
|
459
|
-
ancestors:
|
|
460
|
-
current:
|
|
461
|
-
descendants:
|
|
459
|
+
ancestors: Place[];
|
|
460
|
+
current: Place;
|
|
461
|
+
descendants: Place[];
|
|
462
462
|
}
|
|
463
463
|
|
|
464
464
|
/**
|
|
@@ -483,7 +483,7 @@ export declare interface PlaceOptions extends SmrtObjectOptions {
|
|
|
483
483
|
timezone?: string;
|
|
484
484
|
externalId?: string;
|
|
485
485
|
source?: string;
|
|
486
|
-
metadata?: Record<string,
|
|
486
|
+
metadata?: Record<string, unknown> | string;
|
|
487
487
|
createdAt?: Date;
|
|
488
488
|
updatedAt?: Date;
|
|
489
489
|
}
|
|
@@ -580,7 +580,7 @@ export declare interface ResolveTrackPlacesOptions extends DiscoverNearbyOptions
|
|
|
580
580
|
*/
|
|
581
581
|
export declare interface TrackPlacesResult {
|
|
582
582
|
/** De-duplicated Place rows touched during resolution. */
|
|
583
|
-
places:
|
|
583
|
+
places: Place[];
|
|
584
584
|
/** Number of provider requests issued. */
|
|
585
585
|
requestCount: number;
|
|
586
586
|
/** Number of bucketed points that reused existing Place rows. */
|
package/dist/index.js
CHANGED
|
@@ -594,14 +594,12 @@ class PlaceCollection extends SmrtCollection {
|
|
|
594
594
|
* @returns Created Place instance
|
|
595
595
|
*/
|
|
596
596
|
async createFromLocation(location, typeSlug, parentId) {
|
|
597
|
-
const typeCollection = await PlaceTypeCollection.create(
|
|
598
|
-
this.options
|
|
599
|
-
);
|
|
597
|
+
const typeCollection = await PlaceTypeCollection.create(this.options);
|
|
600
598
|
const slug = typeSlug || location.type || "address";
|
|
601
599
|
const placeType = await typeCollection.getOrCreate(slug);
|
|
602
600
|
const components = location.addressComponents || {};
|
|
603
601
|
return await this.create({
|
|
604
|
-
typeId: placeType.id,
|
|
602
|
+
typeId: placeType.id ?? void 0,
|
|
605
603
|
parentId: parentId ?? null,
|
|
606
604
|
name: location.name,
|
|
607
605
|
description: "",
|
|
@@ -815,9 +813,7 @@ class PlaceCollection extends SmrtCollection {
|
|
|
815
813
|
* @returns Array of places of that type
|
|
816
814
|
*/
|
|
817
815
|
async getByType(typeSlug) {
|
|
818
|
-
const typeCollection = await PlaceTypeCollection.create(
|
|
819
|
-
this.options
|
|
820
|
-
);
|
|
816
|
+
const typeCollection = await PlaceTypeCollection.create(this.options);
|
|
821
817
|
const placeType = await typeCollection.getBySlug(typeSlug);
|
|
822
818
|
if (!placeType) return [];
|
|
823
819
|
return await this.list({
|
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 { 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,WAWX,WAAA,gBAAA,CAAA;AAGAA,kBAAA;AAAA,EADC,MAAA;AAAM,GAbI,WAcX,WAAA,aAAA,CAAA;AAdW,aAANA,kBAAA;AAAA,EARN,aAAa,EAAE,MAAM,YAAY;AAAA,EACjC,KAAK;AAAA,IACJ,WAAW;AAAA,IACX,iBAAiB,CAAC,YAAY,YAAY,cAAc;AA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;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
|
+
{"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;\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, unknown> {\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, unknown>): 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, unknown>): 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.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.create(this.options);\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 ?? undefined,\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.create(this.options);\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","Pla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A;AAAA;AAAA;AAAA,EAWA,MAAM,gBAAgBA,WAAoC;AACxD,WAAO,iBAAwB,MAAMA,WAAU,uBAAuB;AAAA,EACxE;AACF;;;;;"}
|
package/dist/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": "1.0.0",
|
|
3
|
-
"timestamp":
|
|
3
|
+
"timestamp": 1782340527454,
|
|
4
4
|
"packageName": "@happyvertical/smrt-places",
|
|
5
|
-
"packageVersion": "0.35.
|
|
5
|
+
"packageVersion": "0.35.2",
|
|
6
6
|
"objects": {
|
|
7
7
|
"@happyvertical/smrt-places:PlaceAssetCollection": {
|
|
8
8
|
"name": "placeassetcollection",
|
|
@@ -1324,7 +1324,7 @@
|
|
|
1324
1324
|
"name": "getMetadata",
|
|
1325
1325
|
"async": false,
|
|
1326
1326
|
"parameters": [],
|
|
1327
|
-
"returnType": "Record<string
|
|
1327
|
+
"returnType": "Record<string>",
|
|
1328
1328
|
"isStatic": false,
|
|
1329
1329
|
"isPublic": true
|
|
1330
1330
|
},
|
|
@@ -1334,7 +1334,7 @@
|
|
|
1334
1334
|
"parameters": [
|
|
1335
1335
|
{
|
|
1336
1336
|
"name": "data",
|
|
1337
|
-
"type": "Record<string
|
|
1337
|
+
"type": "Record<string>",
|
|
1338
1338
|
"optional": false
|
|
1339
1339
|
}
|
|
1340
1340
|
],
|
|
@@ -1348,7 +1348,7 @@
|
|
|
1348
1348
|
"parameters": [
|
|
1349
1349
|
{
|
|
1350
1350
|
"name": "updates",
|
|
1351
|
-
"type": "Record<string
|
|
1351
|
+
"type": "Record<string>",
|
|
1352
1352
|
"optional": false
|
|
1353
1353
|
}
|
|
1354
1354
|
],
|
package/dist/smrt-knowledge.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"generatedAt": "2026-06-
|
|
3
|
+
"generatedAt": "2026-06-24T22:35:31.321Z",
|
|
4
4
|
"packageName": "@happyvertical/smrt-places",
|
|
5
|
-
"packageVersion": "0.35.
|
|
5
|
+
"packageVersion": "0.35.2",
|
|
6
6
|
"sourceManifestPath": "dist/manifest.json",
|
|
7
7
|
"agentDocPath": "AGENTS.md",
|
|
8
8
|
"sourceHashes": {
|
|
9
|
-
"manifest": "
|
|
10
|
-
"packageJson": "
|
|
9
|
+
"manifest": "75bc827967d97cc8981e70ff6f2f2acbefdb95b29246ec9ff9a94879a193fc37",
|
|
10
|
+
"packageJson": "f6addf2537e7c114a7ef3b60d6b0ee0b402e1c385d01482cef84f323e0e97297",
|
|
11
11
|
"agents": "1f12a465f3ef103ac0ba27bcec1ec2b982fd0f5e8a63b9a42738f2c79ecebe49"
|
|
12
12
|
},
|
|
13
13
|
"exports": [
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { Asset } from '@happyvertical/smrt-assets';
|
|
2
|
+
import { SmrtHierarchical } from '@happyvertical/smrt-core';
|
|
3
|
+
import { SmrtObject } from '@happyvertical/smrt-core';
|
|
1
4
|
import { SmrtObjectOptions } from '@happyvertical/smrt-core';
|
|
2
5
|
|
|
3
6
|
/**
|
|
@@ -72,13 +75,76 @@ export declare interface LookupOrCreateOptions {
|
|
|
72
75
|
};
|
|
73
76
|
}
|
|
74
77
|
|
|
78
|
+
declare class Place extends SmrtHierarchical {
|
|
79
|
+
tenantId: string | null;
|
|
80
|
+
typeId: string;
|
|
81
|
+
name: string;
|
|
82
|
+
description: string;
|
|
83
|
+
latitude: number | null;
|
|
84
|
+
longitude: number | null;
|
|
85
|
+
streetNumber: string;
|
|
86
|
+
streetName: string;
|
|
87
|
+
city: string;
|
|
88
|
+
region: string;
|
|
89
|
+
country: string;
|
|
90
|
+
postalCode: string;
|
|
91
|
+
countryCode: string;
|
|
92
|
+
timezone: string;
|
|
93
|
+
externalId: string;
|
|
94
|
+
source: string;
|
|
95
|
+
metadata: string;
|
|
96
|
+
createdAt: Date;
|
|
97
|
+
updatedAt: Date;
|
|
98
|
+
constructor(options?: PlaceOptions);
|
|
99
|
+
/**
|
|
100
|
+
* Get geographic data for this place
|
|
101
|
+
*
|
|
102
|
+
* @returns GeoData object with all geo fields
|
|
103
|
+
*/
|
|
104
|
+
getGeoData(): GeoData;
|
|
105
|
+
/**
|
|
106
|
+
* Check if this place has geographic coordinates
|
|
107
|
+
*
|
|
108
|
+
* @returns True if latitude and longitude are set
|
|
109
|
+
*/
|
|
110
|
+
hasCoordinates(): boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Get metadata as parsed object
|
|
113
|
+
*
|
|
114
|
+
* @returns Parsed metadata object or empty object if no metadata
|
|
115
|
+
*/
|
|
116
|
+
getMetadata(): Record<string, unknown>;
|
|
117
|
+
/**
|
|
118
|
+
* Set metadata from object
|
|
119
|
+
*
|
|
120
|
+
* @param data - Metadata object to store
|
|
121
|
+
*/
|
|
122
|
+
setMetadata(data: Record<string, unknown>): void;
|
|
123
|
+
/**
|
|
124
|
+
* Update metadata by merging with existing values
|
|
125
|
+
*
|
|
126
|
+
* @param updates - Partial metadata to merge
|
|
127
|
+
*/
|
|
128
|
+
updateMetadata(updates: Record<string, unknown>): void;
|
|
129
|
+
/**
|
|
130
|
+
* Get the place type
|
|
131
|
+
*
|
|
132
|
+
* @returns PlaceType instance or null if not found
|
|
133
|
+
*/
|
|
134
|
+
getType(): Promise<PlaceType | null>;
|
|
135
|
+
private getPlaceAssetCollection;
|
|
136
|
+
getAssets(relationship?: string): Promise<Asset[]>;
|
|
137
|
+
addAsset(asset: Asset, relationship?: string, sortOrder?: number): Promise<void>;
|
|
138
|
+
removeAsset(assetId: string, relationship?: string): Promise<void>;
|
|
139
|
+
}
|
|
140
|
+
|
|
75
141
|
/**
|
|
76
142
|
* Place hierarchy structure
|
|
77
143
|
*/
|
|
78
144
|
export declare interface PlaceHierarchy {
|
|
79
|
-
ancestors:
|
|
80
|
-
current:
|
|
81
|
-
descendants:
|
|
145
|
+
ancestors: Place[];
|
|
146
|
+
current: Place;
|
|
147
|
+
descendants: Place[];
|
|
82
148
|
}
|
|
83
149
|
|
|
84
150
|
/**
|
|
@@ -103,11 +169,26 @@ export declare interface PlaceOptions extends SmrtObjectOptions {
|
|
|
103
169
|
timezone?: string;
|
|
104
170
|
externalId?: string;
|
|
105
171
|
source?: string;
|
|
106
|
-
metadata?: Record<string,
|
|
172
|
+
metadata?: Record<string, unknown> | string;
|
|
107
173
|
createdAt?: Date;
|
|
108
174
|
updatedAt?: Date;
|
|
109
175
|
}
|
|
110
176
|
|
|
177
|
+
declare class PlaceType extends SmrtObject {
|
|
178
|
+
name: string;
|
|
179
|
+
description?: string;
|
|
180
|
+
createdAt: Date;
|
|
181
|
+
updatedAt: Date;
|
|
182
|
+
constructor(options?: PlaceTypeOptions);
|
|
183
|
+
/**
|
|
184
|
+
* Convenience method for slug-based lookup
|
|
185
|
+
*
|
|
186
|
+
* @param slug - The slug to search for
|
|
187
|
+
* @returns PlaceType instance or null if not found
|
|
188
|
+
*/
|
|
189
|
+
static getBySlug(_slug: string): Promise<PlaceType | null>;
|
|
190
|
+
}
|
|
191
|
+
|
|
111
192
|
/**
|
|
112
193
|
* Options for creating/updating a PlaceType
|
|
113
194
|
*/
|
|
@@ -151,7 +232,7 @@ export declare interface ResolveTrackPlacesOptions extends DiscoverNearbyOptions
|
|
|
151
232
|
*/
|
|
152
233
|
export declare interface TrackPlacesResult {
|
|
153
234
|
/** De-duplicated Place rows touched during resolution. */
|
|
154
|
-
places:
|
|
235
|
+
places: Place[];
|
|
155
236
|
/** Number of provider requests issued. */
|
|
156
237
|
requestCount: number;
|
|
157
238
|
/** Number of bucketed points that reused existing Place rows. */
|
package/dist/utils.js
CHANGED
|
@@ -67,15 +67,16 @@ function parseCoordinates(coordString) {
|
|
|
67
67
|
}
|
|
68
68
|
function normalizeAddressComponents(components) {
|
|
69
69
|
const normalized = {};
|
|
70
|
+
const writable = normalized;
|
|
70
71
|
for (const [key, value] of Object.entries(components)) {
|
|
71
72
|
if (value === null || value === void 0) continue;
|
|
72
73
|
if (typeof value === "string") {
|
|
73
74
|
const trimmed = value.trim();
|
|
74
75
|
if (trimmed) {
|
|
75
|
-
|
|
76
|
+
writable[key] = trimmed;
|
|
76
77
|
}
|
|
77
78
|
} else {
|
|
78
|
-
|
|
79
|
+
writable[key] = value;
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
82
|
return normalized;
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../src/utils.ts"],"sourcesContent":["/**\n * Utility functions for @have/places package\n */\n\nimport type { Location } from '@happyvertical/geo';\nimport type { GeoData } from './types';\n\n/**\n * Map Location type from @happyvertical/geo to PlaceType slug\n *\n * @param locationType - Location type from geocoding provider\n * @returns PlaceType slug\n */\nexport function mapLocationTypeToPlaceType(locationType: string): string {\n const typeMap: Record<string, string> = {\n // Standard types\n country: 'country',\n region: 'region',\n city: 'city',\n address: 'address',\n point_of_interest: 'point_of_interest',\n\n // Additional mappings\n state: 'region',\n province: 'region',\n town: 'city',\n village: 'city',\n building: 'building',\n room: 'room',\n zone: 'zone',\n };\n\n return typeMap[locationType.toLowerCase()] || 'address';\n}\n\n/**\n * Convert Location from @happyvertical/geo to GeoData\n *\n * @param location - Location from geocoding\n * @returns GeoData object\n */\nexport function locationToGeoData(location: Location): GeoData {\n const components = location.addressComponents || {};\n\n return {\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}\n\n/**\n * Validate geographic coordinates\n *\n * @param latitude - Latitude value\n * @param longitude - Longitude value\n * @returns Object with valid flag and optional error message\n */\nexport function validateCoordinates(\n latitude: number,\n longitude: number,\n): { valid: boolean; error?: string } {\n if (latitude < -90 || latitude > 90) {\n return { valid: false, error: 'Invalid latitude (must be -90 to 90)' };\n }\n\n if (longitude < -180 || longitude > 180) {\n return { valid: false, error: 'Invalid longitude (must be -180 to 180)' };\n }\n\n return { valid: true };\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 */\nexport function 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 = toRad(lat2 - lat1);\n const dLng = toRad(lng2 - lng1);\n\n const a =\n Math.sin(dLat / 2) * Math.sin(dLat / 2) +\n Math.cos(toRad(lat1)) *\n Math.cos(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 */\nfunction toRad(degrees: number): number {\n return degrees * (Math.PI / 180);\n}\n\n/**\n * Format coordinates as string\n *\n * @param latitude - Latitude value\n * @param longitude - Longitude value\n * @param precision - Number of decimal places (default: 6)\n * @returns Formatted coordinate string\n */\nexport function formatCoordinates(\n latitude: number,\n longitude: number,\n precision: number = 6,\n): string {\n return `${latitude.toFixed(precision)}, ${longitude.toFixed(precision)}`;\n}\n\n/**\n * Parse coordinate string to lat/lng\n *\n * Supports formats:\n * - \"lat, lng\"\n * - \"lat,lng\"\n * - \"lat lng\"\n *\n * @param coordString - Coordinate string\n * @returns Object with lat and lng, or null if invalid\n */\nexport function parseCoordinates(\n coordString: string,\n): { lat: number; lng: number } | null {\n // Remove extra whitespace and split\n const parts = coordString\n .trim()\n .replace(/\\s+/g, ' ')\n .replace(/,\\s*/g, ',')\n .split(/[,\\s]+/);\n\n if (parts.length !== 2) return null;\n\n const lat = parseFloat(parts[0]);\n const lng = parseFloat(parts[1]);\n\n if (Number.isNaN(lat) || Number.isNaN(lng)) return null;\n\n const validation = validateCoordinates(lat, lng);\n if (!validation.valid) return null;\n\n return { lat, lng };\n}\n\n/**\n * Normalize address components by trimming and removing empty values\n *\n * @param components - Address components\n * @returns Normalized components\n */\nexport function normalizeAddressComponents(\n components: Partial<GeoData>,\n): Partial<GeoData> {\n const normalized: Partial<GeoData> = {};\n\n for (const [key, value] of Object.entries(components)) {\n if (value === null || value === undefined) continue;\n\n if (typeof value === 'string') {\n const trimmed = value.trim();\n if (trimmed) {\n
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../src/utils.ts"],"sourcesContent":["/**\n * Utility functions for @have/places package\n */\n\nimport type { Location } from '@happyvertical/geo';\nimport type { GeoData } from './types';\n\n/**\n * Map Location type from @happyvertical/geo to PlaceType slug\n *\n * @param locationType - Location type from geocoding provider\n * @returns PlaceType slug\n */\nexport function mapLocationTypeToPlaceType(locationType: string): string {\n const typeMap: Record<string, string> = {\n // Standard types\n country: 'country',\n region: 'region',\n city: 'city',\n address: 'address',\n point_of_interest: 'point_of_interest',\n\n // Additional mappings\n state: 'region',\n province: 'region',\n town: 'city',\n village: 'city',\n building: 'building',\n room: 'room',\n zone: 'zone',\n };\n\n return typeMap[locationType.toLowerCase()] || 'address';\n}\n\n/**\n * Convert Location from @happyvertical/geo to GeoData\n *\n * @param location - Location from geocoding\n * @returns GeoData object\n */\nexport function locationToGeoData(location: Location): GeoData {\n const components = location.addressComponents || {};\n\n return {\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}\n\n/**\n * Validate geographic coordinates\n *\n * @param latitude - Latitude value\n * @param longitude - Longitude value\n * @returns Object with valid flag and optional error message\n */\nexport function validateCoordinates(\n latitude: number,\n longitude: number,\n): { valid: boolean; error?: string } {\n if (latitude < -90 || latitude > 90) {\n return { valid: false, error: 'Invalid latitude (must be -90 to 90)' };\n }\n\n if (longitude < -180 || longitude > 180) {\n return { valid: false, error: 'Invalid longitude (must be -180 to 180)' };\n }\n\n return { valid: true };\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 */\nexport function 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 = toRad(lat2 - lat1);\n const dLng = toRad(lng2 - lng1);\n\n const a =\n Math.sin(dLat / 2) * Math.sin(dLat / 2) +\n Math.cos(toRad(lat1)) *\n Math.cos(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 */\nfunction toRad(degrees: number): number {\n return degrees * (Math.PI / 180);\n}\n\n/**\n * Format coordinates as string\n *\n * @param latitude - Latitude value\n * @param longitude - Longitude value\n * @param precision - Number of decimal places (default: 6)\n * @returns Formatted coordinate string\n */\nexport function formatCoordinates(\n latitude: number,\n longitude: number,\n precision: number = 6,\n): string {\n return `${latitude.toFixed(precision)}, ${longitude.toFixed(precision)}`;\n}\n\n/**\n * Parse coordinate string to lat/lng\n *\n * Supports formats:\n * - \"lat, lng\"\n * - \"lat,lng\"\n * - \"lat lng\"\n *\n * @param coordString - Coordinate string\n * @returns Object with lat and lng, or null if invalid\n */\nexport function parseCoordinates(\n coordString: string,\n): { lat: number; lng: number } | null {\n // Remove extra whitespace and split\n const parts = coordString\n .trim()\n .replace(/\\s+/g, ' ')\n .replace(/,\\s*/g, ',')\n .split(/[,\\s]+/);\n\n if (parts.length !== 2) return null;\n\n const lat = parseFloat(parts[0]);\n const lng = parseFloat(parts[1]);\n\n if (Number.isNaN(lat) || Number.isNaN(lng)) return null;\n\n const validation = validateCoordinates(lat, lng);\n if (!validation.valid) return null;\n\n return { lat, lng };\n}\n\n/**\n * Normalize address components by trimming and removing empty values\n *\n * @param components - Address components\n * @returns Normalized components\n */\nexport function normalizeAddressComponents(\n components: Partial<GeoData>,\n): Partial<GeoData> {\n const normalized: Partial<GeoData> = {};\n // Each GeoData key has a distinct value type, so writing a single `value`\n // through a `keyof GeoData` index requires the broad value union. Capture it\n // once here instead of casting at each assignment.\n const writable = normalized as Partial<\n Record<keyof GeoData, GeoData[keyof GeoData]>\n >;\n\n for (const [key, value] of Object.entries(components)) {\n if (value === null || value === undefined) continue;\n\n if (typeof value === 'string') {\n const trimmed = value.trim();\n if (trimmed) {\n writable[key as keyof GeoData] = trimmed;\n }\n } else {\n writable[key as keyof GeoData] = value;\n }\n }\n\n return normalized;\n}\n\n/**\n * Generate a display name from address components\n *\n * @param components - Address components\n * @returns Formatted display name\n */\nexport function generateDisplayName(components: Partial<GeoData>): string {\n const parts: string[] = [];\n\n if (components.streetNumber && components.streetName) {\n parts.push(`${components.streetNumber} ${components.streetName}`);\n } else if (components.streetName) {\n parts.push(components.streetName);\n }\n\n if (components.city) parts.push(components.city);\n if (components.region) parts.push(components.region);\n if (components.country) parts.push(components.country);\n\n return parts.join(', ');\n}\n\n/**\n * Check if two coordinates are within a threshold distance\n *\n * @param lat1 - First latitude\n * @param lng1 - First longitude\n * @param lat2 - Second latitude\n * @param lng2 - Second longitude\n * @param thresholdKm - Distance threshold in kilometers\n * @returns True if coordinates are within threshold\n */\nexport function areCoordinatesNear(\n lat1: number,\n lng1: number,\n lat2: number,\n lng2: number,\n thresholdKm: number = 0.1,\n): boolean {\n const distance = calculateDistance(lat1, lng1, lat2, lng2);\n return distance <= thresholdKm;\n}\n"],"names":[],"mappings":"AAaO,SAAS,2BAA2B,cAA8B;AACvE,QAAM,UAAkC;AAAA;AAAA,IAEtC,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,SAAS;AAAA,IACT,mBAAmB;AAAA;AAAA,IAGnB,OAAO;AAAA,IACP,UAAU;AAAA,IACV,MAAM;AAAA,IACN,SAAS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AW,QAAS,OAAM,KAAK,WAAW,OAAO;AAErD,SAAO,MAAM,KAAK,IAAI;AACxB;AAYO,SAAS,mBACd,MACA,MACA,MACA,MACA,cAAsB,KACb;AACT,QAAM,WAAW,kBAAkB,MAAM,MAAM,MAAM,IAAI;AACzD,SAAO,YAAY;AACrB;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@happyvertical/smrt-places",
|
|
3
|
-
"version": "0.35.
|
|
3
|
+
"version": "0.35.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-assets": "0.35.
|
|
34
|
-
"@happyvertical/smrt-
|
|
35
|
-
"@happyvertical/smrt-
|
|
33
|
+
"@happyvertical/smrt-assets": "0.35.2",
|
|
34
|
+
"@happyvertical/smrt-core": "0.35.2",
|
|
35
|
+
"@happyvertical/smrt-tenancy": "0.35.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.35.
|
|
43
|
+
"@happyvertical/smrt-vitest": "0.35.2"
|
|
44
44
|
},
|
|
45
45
|
"keywords": [
|
|
46
46
|
"ai",
|