@michaelbhaines/photo-weather-shared
v1.0.0
Published
Shared types and utilities for Photo-to-DB backend and frontend projects
Maintainers
Readme
Photo-Weather Shared Package
Shared TypeScript types, constants, and utilities for the Photo-to-DB backend and Angular frontend projects.
📦 Installation
npm install @mhaines/photo-weather-shared🚀 Usage
Import Types
import {
WeatherData,
TidalData,
ImageMetadata,
ExifData,
ApiResponse
} from '@mhaines/photo-weather-shared';Import Constants
import {
ENDPOINTS,
QUERY_PARAMS,
DEFAULTS,
WeatherProvider,
DataQuality
} from '@mhaines/photo-weather-shared';Import Utilities
import {
validateCoordinates,
calculateDistance,
formatDateForAPI,
getRelativeTime
} from '@mhaines/photo-weather-shared';📋 What's Included
🌤️ Weather Types
WeatherData- Complete weather information structureTidalData- Tidal conditions and predictionsWeatherDataRequest- Request parameters for weather APIsWeatherProvider,DataQualityenums
📷 Image Types
ImageMetadata- Complete image informationExifData- Camera and GPS metadataImageUploadRequest/Response- Upload API contractsImageQueryParams- Filtering and pagination
🌐 API Types
ApiResponse<T>- Standardized API response formatApiError- Error response structureHealthCheckResponse- System health informationHttpStatusenum - Standard HTTP status codes
🔧 Utilities
- Coordinates: Validation, distance calculation, formatting
- Dates: API formatting, validation, relative time
- Constants: API endpoints, query parameters, defaults
🎯 Frontend Usage (Angular)
Service Integration
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import {
ENDPOINTS,
ImageUploadResponse,
WeatherData,
ApiResponse
} from '@mhaines/photo-weather-shared';
@Injectable()
export class PhotoService {
constructor(private http: HttpClient) {}
uploadImage(formData: FormData): Observable<ImageUploadResponse> {
return this.http.post<ImageUploadResponse>(ENDPOINTS.IMAGES.UPLOAD, formData);
}
getWeatherData(lat: number, lon: number): Observable<ApiResponse<WeatherData>> {
return this.http.get<ApiResponse<WeatherData>>(ENDPOINTS.WEATHER.BASE, {
params: { latitude: lat.toString(), longitude: lon.toString() }
});
}
}Component Usage
import { Component } from '@angular/core';
import {
ImageMetadata,
WeatherData,
formatDisplayDateTime,
getRelativeTime
} from '@mhaines/photo-weather-shared';
@Component({
template: `
<div *ngFor="let image of images">
<h3>{{ image.originalName }}</h3>
<p>Uploaded: {{ getRelativeTime(image.uploadDate) }}</p>
<div *ngIf="image.weatherData">
<p>Temperature: {{ image.weatherData.temperature.value }}°{{ image.weatherData.temperature.unit }}</p>
<p *ngIf="image.weatherData.tidalData">
Tide: {{ image.weatherData.tidalData.tidalPhase }}
</p>
</div>
</div>
`
})
export class ImageListComponent {
images: ImageMetadata[] = [];
getRelativeTime = getRelativeTime;
}🔧 Backend Usage (Node.js)
API Response Formatting
import { ApiResponse, ImageUploadResponse } from '@mhaines/photo-weather-shared';
export function createSuccessResponse<T>(data: T, message: string): ApiResponse<T> {
return {
success: true,
data,
message
};
}
export function createErrorResponse(error: string, message: string): ApiResponse {
return {
success: false,
error,
message
};
}Validation
import { validateCoordinates, isValidWeatherDate } from '@mhaines/photo-weather-shared';
export function validateWeatherRequest(lat: number, lon: number, date: Date) {
const coordValidation = validateCoordinates(lat, lon);
if (!coordValidation.isValid) {
throw new Error(coordValidation.errors.join(', '));
}
if (!isValidWeatherDate(date)) {
throw new Error('Invalid date for weather data');
}
}🔄 Development Workflow
Making Changes
- Update types/constants/utilities in this package
- Build and publish new version
- Update both backend and frontend projects
- Ensures consistency across projects
Publishing
npm run build
npm version patch # or minor/major
npm publishUpdating Projects
# In backend project
npm update @mhaines/photo-weather-shared
# In frontend project
npm update @mhaines/photo-weather-shared📝 Type Safety Benefits
- Consistent APIs: Same types across backend and frontend
- Compile-time Validation: Catch mismatches early
- IntelliSense Support: Better developer experience
- Refactoring Safety: Changes propagate across projects
- Documentation: Types serve as living documentation
🎯 Best Practices
- Version Carefully: Breaking changes require major version bump
- Document Changes: Update README for new features
- Test Thoroughly: Validate in both backend and frontend
- Keep Focused: Only shared code belongs here
- Semantic Versioning: Follow semver for predictable updates
Shared package ensures type safety and consistency across your Photo-to-DB ecosystem! 🚀
