A TypeScript project for processing and analyzing JSON messages from queue systems.
- Message Analysis: Automatically analyze JSON message files and generate TypeScript interfaces
- Type Safety: Generated interfaces provide full type safety for message processing
- Batch Processing: Efficiently process large numbers of message files
To analyze all JSON messages in the messages/ folder and generate TypeScript interfaces:
pnpm run analyze-messagesThis will:
- Scan all
.jsonfiles in themessages/directory - Analyze their structure and infer TypeScript types
- Generate
message-types.tswith comprehensive interface definitions
The analysis generates two sets of interfaces:
- Auto-generated interface (
BootstrapInventoryMessage): Directly inferred from the JSON structure - Enhanced interfaces: Cleaned up with better type definitions and semantic naming
Example usage:
import type { BootstrapInventoryMessage } from './message-types.js';
// Type-safe message processing
const message: BootstrapInventoryMessage = JSON.parse(messageContent);
console.log(`Processing ${message.data.payload.length} products`);
// Access nested data with full IntelliSense support
for (const product of message.data.payload) {
console.log(`${product.title} by ${product.vendor}`);
for (const variant of product.variants) {
console.log(` - ${variant.title}: $${variant.price}`);
}
}The analyzed messages are BOOTSTRAP_INVENTORY type messages containing:
- Shop Information:
shopSlug,shopDomain,shopInventorySystem - Product Data: Array of products with full Shopify product structure
- Variants: Product variants with pricing and inventory information
- Metadata: Batch information, timestamps, and totals
The main message interface with complete type definitions for all discovered fields.
Individual product information including:
- Basic details (title, vendor, type)
- Shopify metadata (IDs, handles, status)
- Media and images
- Product variants
Variant-specific information:
- Pricing and inventory
- SKU and barcode data
- Shopify inventory item details
pnpm start- Run the main applicationpnpm run analyze-messages- Analyze JSON messages and generate types
See example-usage.ts for comprehensive examples of:
- Loading and parsing messages with type safety
- Filtering and processing product data
- Calculating inventory values
- Working with the generated interfaces
This project uses:
- Bun as the runtime
- TypeScript for type safety
- pnpm for package management
The message analysis script processes JSON files in batches and provides progress feedback for large datasets.