export declare const ecommerceSchemaContent = "import { Events, makeSchema, Schema, SessionIdSymbol, State } from '@livestore/livestore'\n\n// E-commerce with inventory management and order processing\nexport const tables = {\n products: State.SQLite.table({\n name: 'products',\n columns: {\n id: State.SQLite.text({ primaryKey: true }),\n sku: State.SQLite.text(),\n name: State.SQLite.text(),\n description: State.SQLite.text(),\n price: State.SQLite.integer(), // Store as cents to avoid floating point issues\n currency: State.SQLite.text({ default: 'USD' }),\n stock: State.SQLite.integer({ default: 0 }),\n reservedStock: State.SQLite.integer({ default: 0 }), // For pending orders\n isActive: State.SQLite.boolean({ default: true }),\n weight: State.SQLite.real({ nullable: true }), // For shipping calculations\n dimensions: State.SQLite.text({ nullable: true }), // JSON: {width, height, depth}\n imageUrls: State.SQLite.text({ nullable: true }), // JSON array\n createdAt: State.SQLite.integer({ schema: Schema.DateFromNumber }),\n updatedAt: State.SQLite.integer({ schema: Schema.DateFromNumber }),\n deletedAt: State.SQLite.integer({ nullable: true, schema: Schema.DateFromNumber }),\n },\n }),\n \n categories: State.SQLite.table({\n name: 'categories',\n columns: {\n id: State.SQLite.text({ primaryKey: true }),\n name: State.SQLite.text(),\n slug: State.SQLite.text(),\n parentId: State.SQLite.text({ nullable: true }), // For hierarchical categories\n description: State.SQLite.text({ nullable: true }),\n imageUrl: State.SQLite.text({ nullable: true }),\n sortOrder: State.SQLite.integer({ default: 0 }),\n isActive: State.SQLite.boolean({ default: true }),\n createdAt: State.SQLite.integer({ schema: Schema.DateFromNumber }),\n },\n }),\n \n productCategories: State.SQLite.table({\n name: 'product_categories',\n columns: {\n productId: State.SQLite.text(),\n categoryId: State.SQLite.text(),\n createdAt: State.SQLite.integer({ schema: Schema.DateFromNumber }),\n },\n }),\n \n customers: State.SQLite.table({\n name: 'customers',\n columns: {\n id: State.SQLite.text({ primaryKey: true }),\n email: State.SQLite.text(),\n firstName: State.SQLite.text({ nullable: true }),\n lastName: State.SQLite.text({ nullable: true }),\n phone: State.SQLite.text({ nullable: true }),\n createdAt: State.SQLite.integer({ schema: Schema.DateFromNumber }),\n lastOrderAt: State.SQLite.integer({ nullable: true, schema: Schema.DateFromNumber }),\n },\n }),\n \n addresses: State.SQLite.table({\n name: 'addresses',\n columns: {\n id: State.SQLite.text({ primaryKey: true }),\n customerId: State.SQLite.text(),\n type: State.SQLite.text({ default: 'shipping' }), // shipping, billing\n firstName: State.SQLite.text(),\n lastName: State.SQLite.text(),\n company: State.SQLite.text({ nullable: true }),\n address1: State.SQLite.text(),\n address2: State.SQLite.text({ nullable: true }),\n city: State.SQLite.text(),\n state: State.SQLite.text(),\n country: State.SQLite.text(),\n postalCode: State.SQLite.text(),\n isDefault: State.SQLite.boolean({ default: false }),\n },\n }),\n \n orders: State.SQLite.table({\n name: 'orders',\n columns: {\n id: State.SQLite.text({ primaryKey: true }),\n orderNumber: State.SQLite.text(), // Human-readable order number\n customerId: State.SQLite.text(),\n status: State.SQLite.text({ default: 'draft' }), // draft, pending, paid, processing, shipped, delivered, cancelled\n paymentStatus: State.SQLite.text({ default: 'pending' }), // pending, paid, failed, refunded\n fulfillmentStatus: State.SQLite.text({ default: 'unfulfilled' }), // unfulfilled, partial, fulfilled\n \n subtotal: State.SQLite.integer(), // In cents\n taxAmount: State.SQLite.integer({ default: 0 }),\n shippingAmount: State.SQLite.integer({ default: 0 }),\n discountAmount: State.SQLite.integer({ default: 0 }),\n total: State.SQLite.integer(),\n currency: State.SQLite.text({ default: 'USD' }),\n \n shippingAddress: State.SQLite.text(), // JSON\n billingAddress: State.SQLite.text(), // JSON\n \n notes: State.SQLite.text({ nullable: true }),\n \n createdAt: State.SQLite.integer({ schema: Schema.DateFromNumber }),\n updatedAt: State.SQLite.integer({ schema: Schema.DateFromNumber }),\n cancelledAt: State.SQLite.integer({ nullable: true, schema: Schema.DateFromNumber }),\n shippedAt: State.SQLite.integer({ nullable: true, schema: Schema.DateFromNumber }),\n deliveredAt: State.SQLite.integer({ nullable: true, schema: Schema.DateFromNumber }),\n },\n }),\n \n orderItems: State.SQLite.table({\n name: 'order_items',\n columns: {\n id: State.SQLite.text({ primaryKey: true }),\n orderId: State.SQLite.text(),\n productId: State.SQLite.text(),\n variantId: State.SQLite.text({ nullable: true }),\n sku: State.SQLite.text(), // Snapshot at time of order\n name: State.SQLite.text(), // Product name at time of order\n quantity: State.SQLite.integer(),\n unitPrice: State.SQLite.integer(), // Price per unit in cents\n totalPrice: State.SQLite.integer(), // quantity * unitPrice\n fulfillmentStatus: State.SQLite.text({ default: 'unfulfilled' }),\n },\n }),\n \n // Inventory tracking with event sourcing\n inventoryEvents: State.SQLite.table({\n name: 'inventory_events',\n columns: {\n id: State.SQLite.text({ primaryKey: true }),\n productId: State.SQLite.text(),\n type: State.SQLite.text(), // 'adjustment', 'sale', 'return', 'damage', 'restock'\n quantity: State.SQLite.integer(), // Can be positive or negative\n reason: State.SQLite.text({ nullable: true }),\n referenceId: State.SQLite.text({ nullable: true }), // Order ID, adjustment ID, etc.\n createdAt: State.SQLite.integer({ schema: Schema.DateFromNumber }),\n },\n }),\n \n // Shopping cart (client-side state)\n cart: State.SQLite.clientDocument({\n name: 'cart',\n schema: Schema.Struct({\n items: Schema.Array(Schema.Struct({\n productId: Schema.String,\n quantity: Schema.Number,\n addedAt: Schema.Date,\n })),\n discountCode: Schema.NullOr(Schema.String),\n notes: Schema.String,\n }),\n default: { \n id: SessionIdSymbol, \n value: { items: [], discountCode: null, notes: '' }\n },\n }),\n}\n\nexport const events = {\n // Product management\n productCreated: Events.synced({\n name: 'v1.ProductCreated',\n schema: Schema.Struct({\n id: Schema.String,\n sku: Schema.String,\n name: Schema.String,\n description: Schema.String,\n price: Schema.Number, // In cents\n currency: Schema.String,\n createdAt: Schema.Date,\n }),\n }),\n \n productUpdated: Events.synced({\n name: 'v1.ProductUpdated',\n schema: Schema.Struct({\n id: Schema.String,\n name: Schema.NullOr(Schema.String),\n description: Schema.NullOr(Schema.String),\n price: Schema.NullOr(Schema.Number),\n updatedAt: Schema.Date,\n }),\n }),\n \n productStockAdjusted: Events.synced({\n name: 'v1.ProductStockAdjusted',\n schema: Schema.Struct({\n productId: Schema.String,\n adjustment: Schema.Number, // Can be positive or negative\n reason: Schema.String,\n referenceId: Schema.NullOr(Schema.String),\n createdAt: Schema.Date,\n }),\n }),\n \n productDeactivated: Events.synced({\n name: 'v1.ProductDeactivated',\n schema: Schema.Struct({ id: Schema.String }),\n }),\n \n // Customer management\n customerCreated: Events.synced({\n name: 'v1.CustomerCreated',\n schema: Schema.Struct({\n id: Schema.String,\n email: Schema.String,\n firstName: Schema.NullOr(Schema.String),\n lastName: Schema.NullOr(Schema.String),\n createdAt: Schema.Date,\n }),\n }),\n \n // Order lifecycle with state machine\n orderCreated: Events.synced({\n name: 'v1.OrderCreated',\n schema: Schema.Struct({\n id: Schema.String,\n orderNumber: Schema.String,\n customerId: Schema.String,\n items: Schema.Array(Schema.Struct({\n productId: Schema.String,\n sku: Schema.String,\n name: Schema.String,\n quantity: Schema.Number,\n unitPrice: Schema.Number,\n })),\n subtotal: Schema.Number,\n total: Schema.Number,\n shippingAddress: Schema.Object,\n billingAddress: Schema.Object,\n createdAt: Schema.Date,\n }),\n }),\n \n orderPaymentReceived: Events.synced({\n name: 'v1.OrderPaymentReceived',\n schema: Schema.Struct({\n orderId: Schema.String,\n amount: Schema.Number,\n paymentMethod: Schema.String,\n transactionId: Schema.String,\n paidAt: Schema.Date,\n }),\n }),\n \n orderShipped: Events.synced({\n name: 'v1.OrderShipped',\n schema: Schema.Struct({\n orderId: Schema.String,\n trackingNumber: Schema.NullOr(Schema.String),\n carrier: Schema.NullOr(Schema.String),\n shippedAt: Schema.Date,\n }),\n }),\n \n orderDelivered: Events.synced({\n name: 'v1.OrderDelivered',\n schema: Schema.Struct({\n orderId: Schema.String,\n deliveredAt: Schema.Date,\n }),\n }),\n \n orderCancelled: Events.synced({\n name: 'v1.OrderCancelled',\n schema: Schema.Struct({\n orderId: Schema.String,\n reason: Schema.String,\n cancelledAt: Schema.Date,\n }),\n }),\n \n // Cart management (local)\n cartUpdated: tables.cart.set,\n}\n\n// Materializers with business logic and constraints\nconst materializers = State.SQLite.materializers(events, {\n // Product materializers\n 'v1.ProductCreated': ({ id, sku, name, description, price, currency, createdAt }) =>\n tables.products.insert({ id, sku, name, description, price, currency, createdAt, updatedAt: createdAt }),\n \n 'v1.ProductUpdated': ({ id, name, description, price, updatedAt }) =>\n tables.products.update({ \n name: name ?? undefined,\n description: description ?? undefined, \n price: price ?? undefined,\n updatedAt \n }).where({ id }),\n \n 'v1.ProductStockAdjusted': ({ productId, adjustment, reason, referenceId, createdAt }) => [\n // Record the inventory event\n tables.inventoryEvents.insert({ \n id: crypto.randomUUID(),\n productId, \n type: 'adjustment',\n quantity: adjustment, \n reason, \n referenceId, \n createdAt \n }),\n // Update product stock (eventually consistent)\n tables.products.update({ \n stock: Math.max(0, tables.products.select('stock').where({ id: productId }).scalar() + adjustment),\n updatedAt: createdAt\n }).where({ id: productId }),\n ],\n \n 'v1.ProductDeactivated': ({ id }) =>\n tables.products.update({ isActive: false }).where({ id }),\n \n // Customer materializers\n 'v1.CustomerCreated': ({ id, email, firstName, lastName, createdAt }) =>\n tables.customers.insert({ id, email, firstName, lastName, createdAt }),\n \n // Order materializers with inventory reservation\n 'v1.OrderCreated': ({ id, orderNumber, customerId, items, subtotal, total, shippingAddress, billingAddress, createdAt }) => [\n // Create the order\n tables.orders.insert({ \n id, \n orderNumber, \n customerId, \n status: 'pending',\n subtotal, \n total, \n shippingAddress: JSON.stringify(shippingAddress),\n billingAddress: JSON.stringify(billingAddress),\n createdAt, \n updatedAt: createdAt \n }),\n // Create order items and reserve inventory\n ...items.flatMap(item => [\n tables.orderItems.insert({ \n id: crypto.randomUUID(),\n orderId: id,\n productId: item.productId,\n sku: item.sku,\n name: item.name,\n quantity: item.quantity,\n unitPrice: item.unitPrice,\n totalPrice: item.quantity * item.unitPrice,\n }),\n // Reserve stock\n tables.products.update({ \n reservedStock: tables.products.select('reservedStock').where({ id: item.productId }).scalar() + item.quantity\n }).where({ id: item.productId }),\n ]),\n ],\n \n 'v1.OrderPaymentReceived': ({ orderId, amount, paymentMethod, transactionId, paidAt }) =>\n tables.orders.update({ \n status: 'paid', \n paymentStatus: 'paid',\n updatedAt: paidAt \n }).where({ id: orderId }),\n \n 'v1.OrderShipped': ({ orderId, trackingNumber, carrier, shippedAt }) => [\n tables.orders.update({ \n status: 'shipped',\n fulfillmentStatus: 'fulfilled',\n shippedAt,\n updatedAt: shippedAt \n }).where({ id: orderId }),\n // Convert reserved stock to actual stock reduction\n ...tables.orderItems.select().where({ orderId }).map(item => \n tables.products.update({ \n stock: tables.products.select('stock').where({ id: item.productId }).scalar() - item.quantity,\n reservedStock: tables.products.select('reservedStock').where({ id: item.productId }).scalar() - item.quantity\n }).where({ id: item.productId })\n ),\n ],\n \n 'v1.OrderDelivered': ({ orderId, deliveredAt }) =>\n tables.orders.update({ \n status: 'delivered',\n deliveredAt,\n updatedAt: deliveredAt \n }).where({ id: orderId }),\n \n 'v1.OrderCancelled': ({ orderId, reason, cancelledAt }) => [\n tables.orders.update({ \n status: 'cancelled',\n cancelledAt,\n notes: reason,\n updatedAt: cancelledAt \n }).where({ id: orderId }),\n // Release reserved inventory\n ...tables.orderItems.select().where({ orderId }).map(item => \n tables.products.update({ \n reservedStock: Math.max(0, tables.products.select('reservedStock').where({ id: item.productId }).scalar() - item.quantity)\n }).where({ id: item.productId })\n ),\n ],\n})\n\nconst state = State.SQLite.makeState({ tables, materializers })\n\nexport const schema = makeSchema({ events, state })\n\n// Example queries for business intelligence:\n//\n// // Available products with real-time stock\n// const availableProducts$ = queryDb(\n// tables.products\n// .select()\n// .where({ isActive: true, deletedAt: null })\n// .having(tables.products.column('stock').minus(tables.products.column('reservedStock')).gt(0))\n// .orderBy('name'),\n// { label: 'availableProducts' }\n// )\n//\n// // Orders requiring fulfillment\n// const pendingOrders$ = queryDb(\n// tables.orders\n// .select()\n// .join(tables.customers, 'customerId', 'id')\n// .where({ \n// 'orders.status': 'paid',\n// 'orders.fulfillmentStatus': 'unfulfilled'\n// })\n// .orderBy('orders.createdAt'),\n// { label: 'pendingOrders' }\n// )\n//\n// // Low stock alerts\n// const lowStockProducts$ = queryDb(\n// tables.products\n// .select()\n// .where({ isActive: true })\n// .having(tables.products.column('stock').minus(tables.products.column('reservedStock')).lt(10))\n// .orderBy('stock'),\n// { label: 'lowStockProducts' }\n// )"; //# sourceMappingURL=ecommerce.d.ts.map