Skip to content

bryceeppler/message-processor

Repository files navigation

Message Processor

A TypeScript project for processing and analyzing JSON messages from queue systems.

Features

  • 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

Quick Start

Analyze Messages

To analyze all JSON messages in the messages/ folder and generate TypeScript interfaces:

pnpm run analyze-messages

This will:

  • Scan all .json files in the messages/ directory
  • Analyze their structure and infer TypeScript types
  • Generate message-types.ts with comprehensive interface definitions

Generated Types

The analysis generates two sets of interfaces:

  1. Auto-generated interface (BootstrapInventoryMessage): Directly inferred from the JSON structure
  2. 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}`);
  }
}

Message Structure

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

Key Interfaces

BootstrapInventoryMessage

The main message interface with complete type definitions for all discovered fields.

Product

Individual product information including:

  • Basic details (title, vendor, type)
  • Shopify metadata (IDs, handles, status)
  • Media and images
  • Product variants

ProductVariant

Variant-specific information:

  • Pricing and inventory
  • SKU and barcode data
  • Shopify inventory item details

Scripts

  • pnpm start - Run the main application
  • pnpm run analyze-messages - Analyze JSON messages and generate types

Example

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

Development

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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors