@happyvertical/smrt-inventory 0.51.31 → 0.51.33

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.js CHANGED
@@ -2,7 +2,7 @@ import { ObjectRegistry, SmrtCollection, SmrtObject, field, resolveDatabase, smr
2
2
  import { TenantScoped, tenantId } from "@happyvertical/smrt-tenancy";
3
3
  import { createLogger } from "@happyvertical/logger";
4
4
  //#region src/__smrt-register__.ts
5
- ObjectRegistry.registerPackageManifest(JSON.parse("{\"version\":\"1.0.0\",\"timestamp\":0,\"packageName\":\"@happyvertical/smrt-inventory\",\"packageVersion\":\"0.51.31\",\"objects\":{\"@happyvertical/smrt-inventory:InventoryLocationCollection\":{\"name\":\"inventorylocationcollection\",\"className\":\"InventoryLocationCollection\",\"qualifiedName\":\"@happyvertical/smrt-inventory:InventoryLocationCollection\",\"collection\":\"inventorylocations\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/inventory/src/collections/InventoryLocationCollection.ts\",\"packageName\":\"@happyvertical/smrt-inventory\",\"fields\":{},\"methods\":{\"findByCode\":{\"name\":\"findByCode\",\"async\":true,\"parameters\":[{\"name\":\"code\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<InventoryLocation | null>\",\"isStatic\":false,\"isPublic\":true},\"findByKind\":{\"name\":\"findByKind\",\"async\":true,\"parameters\":[{\"name\":\"kind\",\"type\":\"InventoryLocationKind\",\"optional\":false}],\"returnType\":\"Promise<InventoryLocation[]>\",\"isStatic\":false,\"isPublic\":true},\"findByPlace\":{\"name\":\"findByPlace\",\"async\":true,\"parameters\":[{\"name\":\"placeId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<InventoryLocation[]>\",\"isStatic\":false,\"isPublic\":true},\"findActive\":{\"name\":\"findActive\",\"async\":true,\"parameters\":[{\"name\":\"kind\",\"type\":\"InventoryLocationKind\",\"optional\":true}],\"returnType\":\"Promise<InventoryLocation[]>\",\"isStatic\":false,\"isPublic\":true}},\"decoratorConfig\":{\"tableName\":\"inventory_locations\"},\"extends\":\"SmrtCollection\",\"extendsTypeArg\":\"InventoryLocation\",\"exportName\":\"InventoryLocationCollection\",\"collectionExportName\":\"InventoryLocationCollectionCollection\",\"schema\":{\"tableName\":\"inventory_locations\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"inventory_locations\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"tenant_id\\\" UUID,\\n \\\"code\\\" TEXT NOT NULL DEFAULT '',\\n \\\"name\\\" TEXT DEFAULT '',\\n \\\"kind\\\" TEXT DEFAULT 'warehouse',\\n \\\"place_id\\\" TEXT DEFAULT '',\\n \\\"active\\\" BOOLEAN DEFAULT TRUE\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false,\"unique\":false},\"code\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"\"},\"name\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false,\"default\":\"\"},\"kind\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false,\"default\":\"warehouse\"},\"place_id\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false,\"default\":\"\"},\"active\":{\"type\":\"BOOLEAN\",\"notNull\":false,\"unique\":false,\"default\":true}},\"indexes\":[{\"name\":\"inventory_locations_code_tenant_id_idx\",\"columns\":[\"code\",\"tenant_id\"],\"unique\":true,\"nullsNotDistinct\":true},{\"name\":\"inventory_locations_slug_context_idx\",\"columns\":[\"slug\",\"context\"]},{\"name\":\"inventory_locations_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]}],\"version\":\"401c28a1\"},\"importPath\":\"@happyvertical/smrt-inventory\"},\"@happyvertical/smrt-inventory:StockLevelCollection\":{\"name\":\"stocklevelcollection\",\"className\":\"StockLevelCollection\",\"qualifiedName\":\"@happyvertical/smrt-inventory:StockLevelCollection\",\"collection\":\"stocklevels\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/inventory/src/collections/StockLevelCollection.ts\",\"packageName\":\"@happyvertical/smrt-inventory\",\"fields\":{},\"methods\":{\"getLevel\":{\"name\":\"getLevel\",\"async\":true,\"parameters\":[{\"name\":\"skuId\",\"type\":\"string\",\"optional\":false},{\"name\":\"locationId\",\"type\":\"string\",\"optional\":false},{\"name\":\"state\",\"type\":\"StockState\",\"optional\":true,\"default\":\"available\"}],\"returnType\":\"Promise<StockLevel | null>\",\"isStatic\":false,\"isPublic\":true},\"findBySku\":{\"name\":\"findBySku\",\"async\":true,\"parameters\":[{\"name\":\"skuId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<StockLevel[]>\",\"isStatic\":false,\"isPublic\":true},\"findByLocation\":{\"name\":\"findByLocation\",\"async\":true,\"parameters\":[{\"name\":\"locationId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<StockLevel[]>\",\"isStatic\":false,\"isPublic\":true},\"totalForSku\":{\"name\":\"totalForSku\",\"async\":true,\"parameters\":[{\"name\":\"skuId\",\"type\":\"string\",\"optional\":false},{\"name\":\"state\",\"type\":\"StockState\",\"optional\":true}],\"returnType\":\"Promise<number>\",\"isStatic\":false,\"isPublic\":true},\"totalForLocation\":{\"name\":\"totalForLocation\",\"async\":true,\"parameters\":[{\"name\":\"locationId\",\"type\":\"string\",\"optional\":false},{\"name\":\"state\",\"type\":\"StockState\",\"optional\":true}],\"returnType\":\"Promise<number>\",\"isStatic\":false,\"isPublic\":true}},\"decoratorConfig\":{\"tableName\":\"inventory_stock_levels\"},\"extends\":\"SmrtCollection\",\"extendsTypeArg\":\"StockLevel\",\"exportName\":\"StockLevelCollection\",\"collectionExportName\":\"StockLevelCollectionCollection\",\"schema\":{\"tableName\":\"inventory_stock_levels\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"inventory_stock_levels\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"tenant_id\\\" UUID,\\n \\\"sku_id\\\" TEXT NOT NULL DEFAULT '',\\n \\\"location_id\\\" TEXT NOT NULL DEFAULT '',\\n \\\"state\\\" TEXT NOT NULL DEFAULT 'available',\\n \\\"qty\\\" REAL\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false,\"unique\":false},\"sku_id\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"\"},\"location_id\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"\"},\"state\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"available\"},\"qty\":{\"type\":\"REAL\",\"notNull\":false,\"unique\":false}},\"indexes\":[{\"name\":\"inventory_stock_levels_sku_id_location_id_idx\",\"columns\":[\"sku_id\",\"location_id\",\"state\",\"tenant_id\"],\"unique\":true,\"nullsNotDistinct\":true},{\"name\":\"inventory_stock_levels_slug_context_idx\",\"columns\":[\"slug\",\"context\"]},{\"name\":\"inventory_stock_levels_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]}],\"version\":\"7b08362b\"},\"importPath\":\"@happyvertical/smrt-inventory\"},\"@happyvertical/smrt-inventory:StockMovementCollection\":{\"name\":\"stockmovementcollection\",\"className\":\"StockMovementCollection\",\"qualifiedName\":\"@happyvertical/smrt-inventory:StockMovementCollection\",\"collection\":\"stockmovements\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/inventory/src/collections/StockMovementCollection.ts\",\"packageName\":\"@happyvertical/smrt-inventory\",\"fields\":{},\"methods\":{\"findBySku\":{\"name\":\"findBySku\",\"async\":true,\"parameters\":[{\"name\":\"skuId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<StockMovement[]>\",\"isStatic\":false,\"isPublic\":true},\"findByLocation\":{\"name\":\"findByLocation\",\"async\":true,\"parameters\":[{\"name\":\"locationId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<StockMovement[]>\",\"isStatic\":false,\"isPublic\":true},\"findBySource\":{\"name\":\"findBySource\",\"async\":true,\"parameters\":[{\"name\":\"sourceType\",\"type\":\"string\",\"optional\":false},{\"name\":\"sourceId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<StockMovement[]>\",\"isStatic\":false,\"isPublic\":true},\"findByReason\":{\"name\":\"findByReason\",\"async\":true,\"parameters\":[{\"name\":\"reasonCode\",\"type\":\"StockMovementReason\",\"optional\":false}],\"returnType\":\"Promise<StockMovement[]>\",\"isStatic\":false,\"isPublic\":true}},\"decoratorConfig\":{\"tableName\":\"inventory_stock_movements\"},\"extends\":\"SmrtCollection\",\"extendsTypeArg\":\"StockMovement\",\"exportName\":\"StockMovementCollection\",\"collectionExportName\":\"StockMovementCollectionCollection\",\"schema\":{\"tableName\":\"inventory_stock_movements\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"inventory_stock_movements\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"tenant_id\\\" UUID,\\n \\\"sku_id\\\" TEXT NOT NULL DEFAULT '',\\n \\\"location_id\\\" TEXT NOT NULL DEFAULT '',\\n \\\"from_state\\\" TEXT,\\n \\\"to_state\\\" TEXT,\\n \\\"qty\\\" REAL,\\n \\\"reason_code\\\" TEXT NOT NULL DEFAULT 'adjustment',\\n \\\"source_type\\\" TEXT DEFAULT '',\\n \\\"source_id\\\" TEXT DEFAULT '',\\n \\\"note\\\" TEXT DEFAULT '',\\n \\\"occurred_at\\\" TIMESTAMP\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false,\"unique\":false},\"sku_id\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"\"},\"location_id\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"\"},\"from_state\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"to_state\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"qty\":{\"type\":\"REAL\",\"notNull\":false,\"unique\":false},\"reason_code\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"adjustment\"},\"source_type\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false,\"default\":\"\"},\"source_id\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false,\"default\":\"\"},\"note\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false,\"default\":\"\"},\"occurred_at\":{\"type\":\"TIMESTAMP\",\"notNull\":false,\"unique\":false}},\"indexes\":[{\"name\":\"inventory_stock_movements_slug_context_idx\",\"columns\":[\"slug\",\"context\"]},{\"name\":\"inventory_stock_movements_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]}],\"version\":\"3c5a0445\"},\"importPath\":\"@happyvertical/smrt-inventory\"},\"@happyvertical/smrt-inventory:InventoryLocation\":{\"name\":\"inventorylocation\",\"className\":\"InventoryLocation\",\"qualifiedName\":\"@happyvertical/smrt-inventory:InventoryLocation\",\"collection\":\"inventorylocations\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/inventory/src/models/InventoryLocation.ts\",\"packageName\":\"@happyvertical/smrt-inventory\",\"fields\":{\"tenantId\":{\"type\":\"text\",\"required\":false,\"_meta\":{\"sqlType\":\"UUID\",\"nullable\":true,\"__tenancy\":{\"isTenantIdField\":true,\"autoFilter\":true,\"required\":false,\"autoPopulate\":true,\"nullable\":true,\"mode\":\"optional\",\"field\":\"tenantId\",\"allowSuperAdminBypass\":false}}},\"code\":{\"type\":\"text\",\"required\":true,\"default\":\"\",\"_meta\":{\"required\":true}},\"name\":{\"type\":\"text\",\"required\":false,\"default\":\"\"},\"kind\":{\"type\":\"text\",\"required\":false,\"default\":\"warehouse\"},\"placeId\":{\"type\":\"text\",\"required\":false,\"default\":\"\"},\"active\":{\"type\":\"boolean\",\"required\":false,\"default\":true}},\"methods\":{},\"decoratorConfig\":{\"tableName\":\"inventory_locations\",\"conflictColumns\":[\"code\",\"tenant_id\"],\"api\":{\"include\":[\"list\",\"get\",\"create\",\"update\"]},\"mcp\":{\"include\":[\"list\",\"get\"]},\"cli\":true,\"tenantScoped\":{\"mode\":\"optional\"}},\"extends\":\"SmrtObject\",\"exportName\":\"InventoryLocation\",\"collectionExportName\":\"InventoryLocationCollection\",\"validationRules\":[{\"field\":\"code\",\"rule\":\"required\",\"fieldType\":\"text\"}],\"schema\":{\"tableName\":\"inventory_locations\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"inventory_locations\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"tenant_id\\\" UUID,\\n \\\"code\\\" TEXT NOT NULL DEFAULT '',\\n \\\"name\\\" TEXT DEFAULT '',\\n \\\"kind\\\" TEXT DEFAULT 'warehouse',\\n \\\"place_id\\\" TEXT DEFAULT '',\\n \\\"active\\\" BOOLEAN DEFAULT TRUE\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false,\"unique\":false},\"code\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"\"},\"name\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false,\"default\":\"\"},\"kind\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false,\"default\":\"warehouse\"},\"place_id\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false,\"default\":\"\"},\"active\":{\"type\":\"BOOLEAN\",\"notNull\":false,\"unique\":false,\"default\":true}},\"indexes\":[{\"name\":\"inventory_locations_code_tenant_id_idx\",\"columns\":[\"code\",\"tenant_id\"],\"unique\":true,\"nullsNotDistinct\":true},{\"name\":\"inventory_locations_slug_context_idx\",\"columns\":[\"slug\",\"context\"]},{\"name\":\"inventory_locations_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]}],\"version\":\"401c28a1\"},\"importPath\":\"@happyvertical/smrt-inventory\"},\"@happyvertical/smrt-inventory:StockLevel\":{\"name\":\"stocklevel\",\"className\":\"StockLevel\",\"qualifiedName\":\"@happyvertical/smrt-inventory:StockLevel\",\"collection\":\"stocklevels\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/inventory/src/models/StockLevel.ts\",\"packageName\":\"@happyvertical/smrt-inventory\",\"fields\":{\"tenantId\":{\"type\":\"text\",\"required\":false,\"_meta\":{\"sqlType\":\"UUID\",\"nullable\":true,\"__tenancy\":{\"isTenantIdField\":true,\"autoFilter\":true,\"required\":false,\"autoPopulate\":true,\"nullable\":true,\"mode\":\"optional\",\"field\":\"tenantId\",\"allowSuperAdminBypass\":false}}},\"skuId\":{\"type\":\"text\",\"required\":true,\"default\":\"\",\"_meta\":{\"required\":true}},\"locationId\":{\"type\":\"text\",\"required\":true,\"default\":\"\",\"_meta\":{\"required\":true}},\"state\":{\"type\":\"text\",\"required\":true,\"default\":\"available\",\"_meta\":{\"required\":true}},\"qty\":{\"type\":\"decimal\",\"required\":false,\"_meta\":{}}},\"methods\":{},\"decoratorConfig\":{\"tableName\":\"inventory_stock_levels\",\"conflictColumns\":[\"sku_id\",\"location_id\",\"state\",\"tenant_id\"],\"api\":{\"include\":[\"list\",\"get\"]},\"mcp\":{\"include\":[\"list\",\"get\"]},\"cli\":{\"include\":[\"list\",\"get\"]},\"tenantScoped\":{\"mode\":\"optional\"}},\"extends\":\"SmrtObject\",\"exportName\":\"StockLevel\",\"collectionExportName\":\"StockLevelCollection\",\"validationRules\":[{\"field\":\"skuId\",\"rule\":\"required\",\"fieldType\":\"text\"},{\"field\":\"locationId\",\"rule\":\"required\",\"fieldType\":\"text\"},{\"field\":\"state\",\"rule\":\"required\",\"fieldType\":\"text\"}],\"schema\":{\"tableName\":\"inventory_stock_levels\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"inventory_stock_levels\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"tenant_id\\\" UUID,\\n \\\"sku_id\\\" TEXT NOT NULL DEFAULT '',\\n \\\"location_id\\\" TEXT NOT NULL DEFAULT '',\\n \\\"state\\\" TEXT NOT NULL DEFAULT 'available',\\n \\\"qty\\\" REAL\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false,\"unique\":false},\"sku_id\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"\"},\"location_id\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"\"},\"state\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"available\"},\"qty\":{\"type\":\"REAL\",\"notNull\":false,\"unique\":false}},\"indexes\":[{\"name\":\"inventory_stock_levels_sku_id_location_id_idx\",\"columns\":[\"sku_id\",\"location_id\",\"state\",\"tenant_id\"],\"unique\":true,\"nullsNotDistinct\":true},{\"name\":\"inventory_stock_levels_slug_context_idx\",\"columns\":[\"slug\",\"context\"]},{\"name\":\"inventory_stock_levels_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]}],\"version\":\"7b08362b\"},\"importPath\":\"@happyvertical/smrt-inventory\"},\"@happyvertical/smrt-inventory:StockMovement\":{\"name\":\"stockmovement\",\"className\":\"StockMovement\",\"qualifiedName\":\"@happyvertical/smrt-inventory:StockMovement\",\"collection\":\"stockmovements\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/inventory/src/models/StockMovement.ts\",\"packageName\":\"@happyvertical/smrt-inventory\",\"fields\":{\"tenantId\":{\"type\":\"text\",\"required\":false,\"_meta\":{\"sqlType\":\"UUID\",\"nullable\":true,\"__tenancy\":{\"isTenantIdField\":true,\"autoFilter\":true,\"required\":false,\"autoPopulate\":true,\"nullable\":true,\"mode\":\"optional\",\"field\":\"tenantId\",\"allowSuperAdminBypass\":false}}},\"skuId\":{\"type\":\"text\",\"required\":true,\"default\":\"\",\"_meta\":{\"required\":true}},\"locationId\":{\"type\":\"text\",\"required\":true,\"default\":\"\",\"_meta\":{\"required\":true}},\"fromState\":{\"type\":\"text\",\"required\":false},\"toState\":{\"type\":\"text\",\"required\":false},\"qty\":{\"type\":\"decimal\",\"required\":false,\"_meta\":{}},\"reasonCode\":{\"type\":\"text\",\"required\":true,\"default\":\"adjustment\",\"_meta\":{\"required\":true}},\"sourceType\":{\"type\":\"text\",\"required\":false,\"default\":\"\"},\"sourceId\":{\"type\":\"text\",\"required\":false,\"default\":\"\"},\"note\":{\"type\":\"text\",\"required\":false,\"default\":\"\"},\"occurredAt\":{\"type\":\"datetime\",\"required\":false}},\"methods\":{},\"decoratorConfig\":{\"tableName\":\"inventory_stock_movements\",\"conflictColumns\":[\"id\"],\"api\":{\"include\":[\"list\",\"get\"]},\"mcp\":{\"include\":[\"list\",\"get\"]},\"cli\":{\"include\":[\"list\",\"get\"]},\"tenantScoped\":{\"mode\":\"optional\"}},\"extends\":\"SmrtObject\",\"exportName\":\"StockMovement\",\"collectionExportName\":\"StockMovementCollection\",\"validationRules\":[{\"field\":\"skuId\",\"rule\":\"required\",\"fieldType\":\"text\"},{\"field\":\"locationId\",\"rule\":\"required\",\"fieldType\":\"text\"},{\"field\":\"reasonCode\",\"rule\":\"required\",\"fieldType\":\"text\"}],\"schema\":{\"tableName\":\"inventory_stock_movements\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"inventory_stock_movements\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"tenant_id\\\" UUID,\\n \\\"sku_id\\\" TEXT NOT NULL DEFAULT '',\\n \\\"location_id\\\" TEXT NOT NULL DEFAULT '',\\n \\\"from_state\\\" TEXT,\\n \\\"to_state\\\" TEXT,\\n \\\"qty\\\" REAL,\\n \\\"reason_code\\\" TEXT NOT NULL DEFAULT 'adjustment',\\n \\\"source_type\\\" TEXT DEFAULT '',\\n \\\"source_id\\\" TEXT DEFAULT '',\\n \\\"note\\\" TEXT DEFAULT '',\\n \\\"occurred_at\\\" TIMESTAMP\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false,\"unique\":false},\"sku_id\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"\"},\"location_id\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"\"},\"from_state\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"to_state\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"qty\":{\"type\":\"REAL\",\"notNull\":false,\"unique\":false},\"reason_code\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"adjustment\"},\"source_type\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false,\"default\":\"\"},\"source_id\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false,\"default\":\"\"},\"note\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false,\"default\":\"\"},\"occurred_at\":{\"type\":\"TIMESTAMP\",\"notNull\":false,\"unique\":false}},\"indexes\":[{\"name\":\"inventory_stock_movements_slug_context_idx\",\"columns\":[\"slug\",\"context\"]},{\"name\":\"inventory_stock_movements_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]}],\"version\":\"3c5a0445\"},\"importPath\":\"@happyvertical/smrt-inventory\"}},\"moduleType\":\"smrt\",\"smrtDependencies\":[\"@happyvertical/smrt-core\",\"@happyvertical/smrt-tenancy\"]}"));
5
+ ObjectRegistry.registerPackageManifest(JSON.parse("{\"version\":\"1.0.0\",\"timestamp\":0,\"packageName\":\"@happyvertical/smrt-inventory\",\"packageVersion\":\"0.51.33\",\"objects\":{\"@happyvertical/smrt-inventory:InventoryLocationCollection\":{\"name\":\"inventorylocationcollection\",\"className\":\"InventoryLocationCollection\",\"qualifiedName\":\"@happyvertical/smrt-inventory:InventoryLocationCollection\",\"collection\":\"inventorylocations\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/inventory/src/collections/InventoryLocationCollection.ts\",\"packageName\":\"@happyvertical/smrt-inventory\",\"fields\":{},\"methods\":{\"findByCode\":{\"name\":\"findByCode\",\"async\":true,\"parameters\":[{\"name\":\"code\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<InventoryLocation | null>\",\"isStatic\":false,\"isPublic\":true},\"findByKind\":{\"name\":\"findByKind\",\"async\":true,\"parameters\":[{\"name\":\"kind\",\"type\":\"InventoryLocationKind\",\"optional\":false}],\"returnType\":\"Promise<InventoryLocation[]>\",\"isStatic\":false,\"isPublic\":true},\"findByPlace\":{\"name\":\"findByPlace\",\"async\":true,\"parameters\":[{\"name\":\"placeId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<InventoryLocation[]>\",\"isStatic\":false,\"isPublic\":true},\"findActive\":{\"name\":\"findActive\",\"async\":true,\"parameters\":[{\"name\":\"kind\",\"type\":\"InventoryLocationKind\",\"optional\":true}],\"returnType\":\"Promise<InventoryLocation[]>\",\"isStatic\":false,\"isPublic\":true}},\"decoratorConfig\":{\"tableName\":\"inventory_locations\"},\"extends\":\"SmrtCollection\",\"extendsTypeArg\":\"InventoryLocation\",\"exportName\":\"InventoryLocationCollection\",\"collectionExportName\":\"InventoryLocationCollectionCollection\",\"schema\":{\"tableName\":\"inventory_locations\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"inventory_locations\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"tenant_id\\\" UUID,\\n \\\"code\\\" TEXT NOT NULL DEFAULT '',\\n \\\"name\\\" TEXT DEFAULT '',\\n \\\"kind\\\" TEXT DEFAULT 'warehouse',\\n \\\"place_id\\\" TEXT DEFAULT '',\\n \\\"active\\\" BOOLEAN DEFAULT TRUE\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false,\"unique\":false},\"code\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"\"},\"name\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false,\"default\":\"\"},\"kind\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false,\"default\":\"warehouse\"},\"place_id\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false,\"default\":\"\"},\"active\":{\"type\":\"BOOLEAN\",\"notNull\":false,\"unique\":false,\"default\":true}},\"indexes\":[{\"name\":\"inventory_locations_code_tenant_id_idx\",\"columns\":[\"code\",\"tenant_id\"],\"unique\":true,\"nullsNotDistinct\":true},{\"name\":\"inventory_locations_slug_context_idx\",\"columns\":[\"slug\",\"context\"]},{\"name\":\"inventory_locations_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]}],\"version\":\"401c28a1\"},\"importPath\":\"@happyvertical/smrt-inventory\"},\"@happyvertical/smrt-inventory:StockLevelCollection\":{\"name\":\"stocklevelcollection\",\"className\":\"StockLevelCollection\",\"qualifiedName\":\"@happyvertical/smrt-inventory:StockLevelCollection\",\"collection\":\"stocklevels\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/inventory/src/collections/StockLevelCollection.ts\",\"packageName\":\"@happyvertical/smrt-inventory\",\"fields\":{},\"methods\":{\"getLevel\":{\"name\":\"getLevel\",\"async\":true,\"parameters\":[{\"name\":\"skuId\",\"type\":\"string\",\"optional\":false},{\"name\":\"locationId\",\"type\":\"string\",\"optional\":false},{\"name\":\"state\",\"type\":\"StockState\",\"optional\":true,\"default\":\"available\"}],\"returnType\":\"Promise<StockLevel | null>\",\"isStatic\":false,\"isPublic\":true},\"findBySku\":{\"name\":\"findBySku\",\"async\":true,\"parameters\":[{\"name\":\"skuId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<StockLevel[]>\",\"isStatic\":false,\"isPublic\":true},\"findByLocation\":{\"name\":\"findByLocation\",\"async\":true,\"parameters\":[{\"name\":\"locationId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<StockLevel[]>\",\"isStatic\":false,\"isPublic\":true},\"totalForSku\":{\"name\":\"totalForSku\",\"async\":true,\"parameters\":[{\"name\":\"skuId\",\"type\":\"string\",\"optional\":false},{\"name\":\"state\",\"type\":\"StockState\",\"optional\":true}],\"returnType\":\"Promise<number>\",\"isStatic\":false,\"isPublic\":true},\"totalForLocation\":{\"name\":\"totalForLocation\",\"async\":true,\"parameters\":[{\"name\":\"locationId\",\"type\":\"string\",\"optional\":false},{\"name\":\"state\",\"type\":\"StockState\",\"optional\":true}],\"returnType\":\"Promise<number>\",\"isStatic\":false,\"isPublic\":true}},\"decoratorConfig\":{\"tableName\":\"inventory_stock_levels\"},\"extends\":\"SmrtCollection\",\"extendsTypeArg\":\"StockLevel\",\"exportName\":\"StockLevelCollection\",\"collectionExportName\":\"StockLevelCollectionCollection\",\"schema\":{\"tableName\":\"inventory_stock_levels\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"inventory_stock_levels\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"tenant_id\\\" UUID,\\n \\\"sku_id\\\" TEXT NOT NULL DEFAULT '',\\n \\\"location_id\\\" TEXT NOT NULL DEFAULT '',\\n \\\"state\\\" TEXT NOT NULL DEFAULT 'available',\\n \\\"qty\\\" REAL\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false,\"unique\":false},\"sku_id\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"\"},\"location_id\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"\"},\"state\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"available\"},\"qty\":{\"type\":\"REAL\",\"notNull\":false,\"unique\":false}},\"indexes\":[{\"name\":\"inventory_stock_levels_sku_id_location_id_idx\",\"columns\":[\"sku_id\",\"location_id\",\"state\",\"tenant_id\"],\"unique\":true,\"nullsNotDistinct\":true},{\"name\":\"inventory_stock_levels_slug_context_idx\",\"columns\":[\"slug\",\"context\"]},{\"name\":\"inventory_stock_levels_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]}],\"version\":\"7b08362b\"},\"importPath\":\"@happyvertical/smrt-inventory\"},\"@happyvertical/smrt-inventory:StockMovementCollection\":{\"name\":\"stockmovementcollection\",\"className\":\"StockMovementCollection\",\"qualifiedName\":\"@happyvertical/smrt-inventory:StockMovementCollection\",\"collection\":\"stockmovements\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/inventory/src/collections/StockMovementCollection.ts\",\"packageName\":\"@happyvertical/smrt-inventory\",\"fields\":{},\"methods\":{\"findBySku\":{\"name\":\"findBySku\",\"async\":true,\"parameters\":[{\"name\":\"skuId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<StockMovement[]>\",\"isStatic\":false,\"isPublic\":true},\"findByLocation\":{\"name\":\"findByLocation\",\"async\":true,\"parameters\":[{\"name\":\"locationId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<StockMovement[]>\",\"isStatic\":false,\"isPublic\":true},\"findBySource\":{\"name\":\"findBySource\",\"async\":true,\"parameters\":[{\"name\":\"sourceType\",\"type\":\"string\",\"optional\":false},{\"name\":\"sourceId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<StockMovement[]>\",\"isStatic\":false,\"isPublic\":true},\"findByReason\":{\"name\":\"findByReason\",\"async\":true,\"parameters\":[{\"name\":\"reasonCode\",\"type\":\"StockMovementReason\",\"optional\":false}],\"returnType\":\"Promise<StockMovement[]>\",\"isStatic\":false,\"isPublic\":true}},\"decoratorConfig\":{\"tableName\":\"inventory_stock_movements\"},\"extends\":\"SmrtCollection\",\"extendsTypeArg\":\"StockMovement\",\"exportName\":\"StockMovementCollection\",\"collectionExportName\":\"StockMovementCollectionCollection\",\"schema\":{\"tableName\":\"inventory_stock_movements\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"inventory_stock_movements\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"tenant_id\\\" UUID,\\n \\\"sku_id\\\" TEXT NOT NULL DEFAULT '',\\n \\\"location_id\\\" TEXT NOT NULL DEFAULT '',\\n \\\"from_state\\\" TEXT,\\n \\\"to_state\\\" TEXT,\\n \\\"qty\\\" REAL,\\n \\\"reason_code\\\" TEXT NOT NULL DEFAULT 'adjustment',\\n \\\"source_type\\\" TEXT DEFAULT '',\\n \\\"source_id\\\" TEXT DEFAULT '',\\n \\\"note\\\" TEXT DEFAULT '',\\n \\\"occurred_at\\\" TIMESTAMP\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false,\"unique\":false},\"sku_id\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"\"},\"location_id\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"\"},\"from_state\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"to_state\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"qty\":{\"type\":\"REAL\",\"notNull\":false,\"unique\":false},\"reason_code\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"adjustment\"},\"source_type\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false,\"default\":\"\"},\"source_id\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false,\"default\":\"\"},\"note\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false,\"default\":\"\"},\"occurred_at\":{\"type\":\"TIMESTAMP\",\"notNull\":false,\"unique\":false}},\"indexes\":[{\"name\":\"inventory_stock_movements_slug_context_idx\",\"columns\":[\"slug\",\"context\"]},{\"name\":\"inventory_stock_movements_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]}],\"version\":\"3c5a0445\"},\"importPath\":\"@happyvertical/smrt-inventory\"},\"@happyvertical/smrt-inventory:InventoryLocation\":{\"name\":\"inventorylocation\",\"className\":\"InventoryLocation\",\"qualifiedName\":\"@happyvertical/smrt-inventory:InventoryLocation\",\"collection\":\"inventorylocations\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/inventory/src/models/InventoryLocation.ts\",\"packageName\":\"@happyvertical/smrt-inventory\",\"fields\":{\"tenantId\":{\"type\":\"text\",\"required\":false,\"_meta\":{\"sqlType\":\"UUID\",\"nullable\":true,\"__tenancy\":{\"isTenantIdField\":true,\"autoFilter\":true,\"required\":false,\"autoPopulate\":true,\"nullable\":true,\"mode\":\"optional\",\"field\":\"tenantId\",\"allowSuperAdminBypass\":false}}},\"code\":{\"type\":\"text\",\"required\":true,\"default\":\"\",\"_meta\":{\"required\":true}},\"name\":{\"type\":\"text\",\"required\":false,\"default\":\"\"},\"kind\":{\"type\":\"text\",\"required\":false,\"default\":\"warehouse\"},\"placeId\":{\"type\":\"text\",\"required\":false,\"default\":\"\"},\"active\":{\"type\":\"boolean\",\"required\":false,\"default\":true}},\"methods\":{},\"decoratorConfig\":{\"tableName\":\"inventory_locations\",\"conflictColumns\":[\"code\",\"tenant_id\"],\"api\":{\"include\":[\"list\",\"get\",\"create\",\"update\"]},\"mcp\":{\"include\":[\"list\",\"get\"]},\"cli\":true,\"tenantScoped\":{\"mode\":\"optional\"}},\"extends\":\"SmrtObject\",\"exportName\":\"InventoryLocation\",\"collectionExportName\":\"InventoryLocationCollection\",\"validationRules\":[{\"field\":\"code\",\"rule\":\"required\",\"fieldType\":\"text\"}],\"schema\":{\"tableName\":\"inventory_locations\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"inventory_locations\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"tenant_id\\\" UUID,\\n \\\"code\\\" TEXT NOT NULL DEFAULT '',\\n \\\"name\\\" TEXT DEFAULT '',\\n \\\"kind\\\" TEXT DEFAULT 'warehouse',\\n \\\"place_id\\\" TEXT DEFAULT '',\\n \\\"active\\\" BOOLEAN DEFAULT TRUE\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false,\"unique\":false},\"code\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"\"},\"name\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false,\"default\":\"\"},\"kind\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false,\"default\":\"warehouse\"},\"place_id\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false,\"default\":\"\"},\"active\":{\"type\":\"BOOLEAN\",\"notNull\":false,\"unique\":false,\"default\":true}},\"indexes\":[{\"name\":\"inventory_locations_code_tenant_id_idx\",\"columns\":[\"code\",\"tenant_id\"],\"unique\":true,\"nullsNotDistinct\":true},{\"name\":\"inventory_locations_slug_context_idx\",\"columns\":[\"slug\",\"context\"]},{\"name\":\"inventory_locations_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]}],\"version\":\"401c28a1\"},\"importPath\":\"@happyvertical/smrt-inventory\"},\"@happyvertical/smrt-inventory:StockLevel\":{\"name\":\"stocklevel\",\"className\":\"StockLevel\",\"qualifiedName\":\"@happyvertical/smrt-inventory:StockLevel\",\"collection\":\"stocklevels\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/inventory/src/models/StockLevel.ts\",\"packageName\":\"@happyvertical/smrt-inventory\",\"fields\":{\"tenantId\":{\"type\":\"text\",\"required\":false,\"_meta\":{\"sqlType\":\"UUID\",\"nullable\":true,\"__tenancy\":{\"isTenantIdField\":true,\"autoFilter\":true,\"required\":false,\"autoPopulate\":true,\"nullable\":true,\"mode\":\"optional\",\"field\":\"tenantId\",\"allowSuperAdminBypass\":false}}},\"skuId\":{\"type\":\"text\",\"required\":true,\"default\":\"\",\"_meta\":{\"required\":true}},\"locationId\":{\"type\":\"text\",\"required\":true,\"default\":\"\",\"_meta\":{\"required\":true}},\"state\":{\"type\":\"text\",\"required\":true,\"default\":\"available\",\"_meta\":{\"required\":true}},\"qty\":{\"type\":\"decimal\",\"required\":false,\"_meta\":{}}},\"methods\":{},\"decoratorConfig\":{\"tableName\":\"inventory_stock_levels\",\"conflictColumns\":[\"sku_id\",\"location_id\",\"state\",\"tenant_id\"],\"api\":{\"include\":[\"list\",\"get\"]},\"mcp\":{\"include\":[\"list\",\"get\"]},\"cli\":{\"include\":[\"list\",\"get\"]},\"tenantScoped\":{\"mode\":\"optional\"}},\"extends\":\"SmrtObject\",\"exportName\":\"StockLevel\",\"collectionExportName\":\"StockLevelCollection\",\"validationRules\":[{\"field\":\"skuId\",\"rule\":\"required\",\"fieldType\":\"text\"},{\"field\":\"locationId\",\"rule\":\"required\",\"fieldType\":\"text\"},{\"field\":\"state\",\"rule\":\"required\",\"fieldType\":\"text\"}],\"schema\":{\"tableName\":\"inventory_stock_levels\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"inventory_stock_levels\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"tenant_id\\\" UUID,\\n \\\"sku_id\\\" TEXT NOT NULL DEFAULT '',\\n \\\"location_id\\\" TEXT NOT NULL DEFAULT '',\\n \\\"state\\\" TEXT NOT NULL DEFAULT 'available',\\n \\\"qty\\\" REAL\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false,\"unique\":false},\"sku_id\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"\"},\"location_id\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"\"},\"state\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"available\"},\"qty\":{\"type\":\"REAL\",\"notNull\":false,\"unique\":false}},\"indexes\":[{\"name\":\"inventory_stock_levels_sku_id_location_id_idx\",\"columns\":[\"sku_id\",\"location_id\",\"state\",\"tenant_id\"],\"unique\":true,\"nullsNotDistinct\":true},{\"name\":\"inventory_stock_levels_slug_context_idx\",\"columns\":[\"slug\",\"context\"]},{\"name\":\"inventory_stock_levels_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]}],\"version\":\"7b08362b\"},\"importPath\":\"@happyvertical/smrt-inventory\"},\"@happyvertical/smrt-inventory:StockMovement\":{\"name\":\"stockmovement\",\"className\":\"StockMovement\",\"qualifiedName\":\"@happyvertical/smrt-inventory:StockMovement\",\"collection\":\"stockmovements\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/inventory/src/models/StockMovement.ts\",\"packageName\":\"@happyvertical/smrt-inventory\",\"fields\":{\"tenantId\":{\"type\":\"text\",\"required\":false,\"_meta\":{\"sqlType\":\"UUID\",\"nullable\":true,\"__tenancy\":{\"isTenantIdField\":true,\"autoFilter\":true,\"required\":false,\"autoPopulate\":true,\"nullable\":true,\"mode\":\"optional\",\"field\":\"tenantId\",\"allowSuperAdminBypass\":false}}},\"skuId\":{\"type\":\"text\",\"required\":true,\"default\":\"\",\"_meta\":{\"required\":true}},\"locationId\":{\"type\":\"text\",\"required\":true,\"default\":\"\",\"_meta\":{\"required\":true}},\"fromState\":{\"type\":\"text\",\"required\":false},\"toState\":{\"type\":\"text\",\"required\":false},\"qty\":{\"type\":\"decimal\",\"required\":false,\"_meta\":{}},\"reasonCode\":{\"type\":\"text\",\"required\":true,\"default\":\"adjustment\",\"_meta\":{\"required\":true}},\"sourceType\":{\"type\":\"text\",\"required\":false,\"default\":\"\"},\"sourceId\":{\"type\":\"text\",\"required\":false,\"default\":\"\"},\"note\":{\"type\":\"text\",\"required\":false,\"default\":\"\"},\"occurredAt\":{\"type\":\"datetime\",\"required\":false}},\"methods\":{},\"decoratorConfig\":{\"tableName\":\"inventory_stock_movements\",\"conflictColumns\":[\"id\"],\"api\":{\"include\":[\"list\",\"get\"]},\"mcp\":{\"include\":[\"list\",\"get\"]},\"cli\":{\"include\":[\"list\",\"get\"]},\"tenantScoped\":{\"mode\":\"optional\"}},\"extends\":\"SmrtObject\",\"exportName\":\"StockMovement\",\"collectionExportName\":\"StockMovementCollection\",\"validationRules\":[{\"field\":\"skuId\",\"rule\":\"required\",\"fieldType\":\"text\"},{\"field\":\"locationId\",\"rule\":\"required\",\"fieldType\":\"text\"},{\"field\":\"reasonCode\",\"rule\":\"required\",\"fieldType\":\"text\"}],\"schema\":{\"tableName\":\"inventory_stock_movements\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"inventory_stock_movements\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"tenant_id\\\" UUID,\\n \\\"sku_id\\\" TEXT NOT NULL DEFAULT '',\\n \\\"location_id\\\" TEXT NOT NULL DEFAULT '',\\n \\\"from_state\\\" TEXT,\\n \\\"to_state\\\" TEXT,\\n \\\"qty\\\" REAL,\\n \\\"reason_code\\\" TEXT NOT NULL DEFAULT 'adjustment',\\n \\\"source_type\\\" TEXT DEFAULT '',\\n \\\"source_id\\\" TEXT DEFAULT '',\\n \\\"note\\\" TEXT DEFAULT '',\\n \\\"occurred_at\\\" TIMESTAMP\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false,\"unique\":false},\"sku_id\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"\"},\"location_id\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"\"},\"from_state\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"to_state\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"qty\":{\"type\":\"REAL\",\"notNull\":false,\"unique\":false},\"reason_code\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false,\"default\":\"adjustment\"},\"source_type\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false,\"default\":\"\"},\"source_id\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false,\"default\":\"\"},\"note\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false,\"default\":\"\"},\"occurred_at\":{\"type\":\"TIMESTAMP\",\"notNull\":false,\"unique\":false}},\"indexes\":[{\"name\":\"inventory_stock_movements_slug_context_idx\",\"columns\":[\"slug\",\"context\"]},{\"name\":\"inventory_stock_movements_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]}],\"version\":\"3c5a0445\"},\"importPath\":\"@happyvertical/smrt-inventory\"}},\"moduleType\":\"smrt\",\"smrtDependencies\":[\"@happyvertical/smrt-core\",\"@happyvertical/smrt-tenancy\"]}"));
6
6
  //#endregion
7
7
  //#region src/models/InventoryLocation.ts
8
8
  var __defProp$2 = Object.defineProperty;
@@ -2,7 +2,7 @@
2
2
  "version": "1.0.0",
3
3
  "timestamp": 0,
4
4
  "packageName": "@happyvertical/smrt-inventory",
5
- "packageVersion": "0.51.31",
5
+ "packageVersion": "0.51.33",
6
6
  "objects": {
7
7
  "@happyvertical/smrt-inventory:InventoryLocationCollection": {
8
8
  "name": "inventorylocationcollection",
@@ -0,0 +1,58 @@
1
+ /**
2
+ * InventoryLocation — a physical or virtual place where stock can sit.
3
+ *
4
+ * `kind` is intentionally a free-form string (see
5
+ * {@link InventoryLocationKind}). Common values are `'warehouse'`,
6
+ * `'factory'`, `'retail'`, `'in_transit'`, or `'virtual'`, but the
7
+ * framework does not special-case any of them. Each application is free
8
+ * to extend the vocabulary.
9
+ *
10
+ * Locations may optionally point at a place row in
11
+ * `@happyvertical/smrt-places` via the plain-string `placeId` — useful
12
+ * when an InventoryLocation maps to a real-world address or POI. The
13
+ * reference is a plain string id, not a `@foreignKey()`, to avoid a
14
+ * cross-package dependency on `smrt-places`.
15
+ *
16
+ * @packageDocumentation
17
+ */
18
+ import { SmrtObject, type SmrtObjectOptions } from '@happyvertical/smrt-core';
19
+ import type { InventoryLocationKind } from '../types.js';
20
+ /**
21
+ * Options accepted by the {@link InventoryLocation} constructor.
22
+ */
23
+ export interface InventoryLocationOptions extends SmrtObjectOptions {
24
+ tenantId?: string | null;
25
+ code?: string;
26
+ name?: string;
27
+ kind?: InventoryLocationKind;
28
+ placeId?: string;
29
+ active?: boolean;
30
+ }
31
+ export declare class InventoryLocation extends SmrtObject {
32
+ /** Tenant scope. `null` means the location record is global. */
33
+ tenantId: string | null;
34
+ /**
35
+ * Short stable identifier (`'WH-EAST'`, `'STORE-42'`, `'IN-TRANSIT'`).
36
+ * Together with `tenantId` this is the natural key.
37
+ */
38
+ code: string;
39
+ /** Display name for UIs. */
40
+ name: string;
41
+ /**
42
+ * Open-ended classifier (`'warehouse'`, `'factory'`, `'retail'`,
43
+ * `'in_transit'`, `'virtual'`, or anything else your domain needs).
44
+ * The framework never branches on this value.
45
+ */
46
+ kind: InventoryLocationKind;
47
+ /**
48
+ * Optional plain-string reference to a `Place.id` in
49
+ * `@happyvertical/smrt-places`. Cross-package id; intentionally not a
50
+ * `@foreignKey()` so this package can be used without `smrt-places`
51
+ * installed.
52
+ */
53
+ placeId: string;
54
+ /** Soft-active flag — inactive locations stay queryable for history. */
55
+ active: boolean;
56
+ constructor(options?: InventoryLocationOptions);
57
+ }
58
+ //# sourceMappingURL=InventoryLocation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InventoryLocation.d.ts","sourceRoot":"","sources":["../../src/models/InventoryLocation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAEL,UAAU,EACV,KAAK,iBAAiB,EAEvB,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEzD;;GAEG;AACH,MAAM,WAAW,wBAAyB,SAAQ,iBAAiB;IACjE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,qBAAqB,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,qBAQa,iBAAkB,SAAQ,UAAU;IAC/C,gEAAgE;IAEhE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAE/B;;;OAGG;IAEH,IAAI,EAAE,MAAM,CAAM;IAElB,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAM;IAElB;;;;OAIG;IACH,IAAI,EAAE,qBAAqB,CAAe;IAE1C;;;;;OAKG;IACH,OAAO,EAAE,MAAM,CAAM;IAErB,wEAAwE;IACxE,MAAM,EAAE,OAAO,CAAQ;gBAEX,OAAO,GAAE,wBAA6B;CASnD"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * StockLevel — materialized quantity at a `(skuId, locationId, state)` tuple.
3
+ *
4
+ * StockLevel is the live, mutable view of on-hand stock. There is at most
5
+ * one row per `(skuId, locationId, state)` per tenant; the natural key
6
+ * (`conflictColumns`) gives us idempotent upserts. Each row's `qty`
7
+ * floats up and down as the {@link StockService} processes
8
+ * receive/reserve/release/fulfill/transfer/adjust calls.
9
+ *
10
+ * **Do not call `create()` or `save()` on StockLevel directly.** All
11
+ * mutations must go through {@link StockService}, which guarantees that
12
+ * the level change and the corresponding append-only StockMovement land
13
+ * together. Direct writes will silently desync the audit ledger and make
14
+ * cycle counts unreliable.
15
+ *
16
+ * @packageDocumentation
17
+ */
18
+ import { SmrtObject, type SmrtObjectOptions } from '@happyvertical/smrt-core';
19
+ import type { StockState } from '../types.js';
20
+ /**
21
+ * Options accepted by the {@link StockLevel} constructor.
22
+ */
23
+ export interface StockLevelOptions extends SmrtObjectOptions {
24
+ tenantId?: string | null;
25
+ skuId?: string;
26
+ locationId?: string;
27
+ state?: StockState;
28
+ qty?: number;
29
+ }
30
+ export declare class StockLevel extends SmrtObject {
31
+ /** Tenant scope. `null` means the level row is global. */
32
+ tenantId: string | null;
33
+ /** Plain string reference to the {@link Sku} this row tracks. */
34
+ skuId: string;
35
+ /** Plain string reference to the {@link InventoryLocation} this row tracks. */
36
+ locationId: string;
37
+ /** Logical state — `available`, `allocated`, `wip`, `qc_hold`, `damaged`. */
38
+ state: StockState;
39
+ /**
40
+ * Current quantity. Fractional values are allowed (`= 0.0`) for
41
+ * domains that count in units of measure other than whole pieces
42
+ * (kilograms, litres, metres).
43
+ */
44
+ qty: number;
45
+ constructor(options?: StockLevelOptions);
46
+ }
47
+ //# sourceMappingURL=StockLevel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StockLevel.d.ts","sourceRoot":"","sources":["../../src/models/StockLevel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAEL,UAAU,EACV,KAAK,iBAAiB,EAEvB,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;IAC1D,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,qBAgBa,UAAW,SAAQ,UAAU;IACxC,0DAA0D;IAE1D,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAE/B,iEAAiE;IAEjE,KAAK,EAAE,MAAM,CAAM;IAEnB,+EAA+E;IAE/E,UAAU,EAAE,MAAM,CAAM;IAExB,6EAA6E;IAE7E,KAAK,EAAE,UAAU,CAAe;IAEhC;;;;OAIG;IAEH,GAAG,EAAE,MAAM,CAAO;gBAEN,OAAO,GAAE,iBAAsB;CAQ5C"}
@@ -0,0 +1,88 @@
1
+ /**
2
+ * StockMovement — append-only audit row written for every stock mutation.
3
+ *
4
+ * Every call into {@link StockService} produces exactly one StockMovement
5
+ * row (or two for `transfer`, one per leg). These rows are the ledger of
6
+ * record: balances on {@link StockLevel} are derived state that could
7
+ * always, in principle, be reconstructed by replaying movements in
8
+ * order.
9
+ *
10
+ * **Movements are append-only.** The package treats updates as a bug and
11
+ * relies on this for cycle-count reconciliation, audit, and source-system
12
+ * attribution. Never call `save()` on a previously-persisted StockMovement
13
+ * with mutated fields, and never let CRUD UIs expose update/delete on the
14
+ * table.
15
+ *
16
+ * Cross-package attribution lives in `sourceType` + `sourceId` so a
17
+ * downstream package can write `'Contract'` + the contract id when it
18
+ * reserves stock, then later query "which movements were caused by
19
+ * contract X?" without joining across the framework.
20
+ *
21
+ * @packageDocumentation
22
+ */
23
+ import { SmrtObject, type SmrtObjectOptions } from '@happyvertical/smrt-core';
24
+ import type { StockMovementReason, StockState } from '../types.js';
25
+ /**
26
+ * Options accepted by the {@link StockMovement} constructor.
27
+ */
28
+ export interface StockMovementOptions extends SmrtObjectOptions {
29
+ tenantId?: string | null;
30
+ skuId?: string;
31
+ locationId?: string;
32
+ fromState?: StockState | null;
33
+ toState?: StockState | null;
34
+ qty?: number;
35
+ reasonCode?: StockMovementReason;
36
+ sourceType?: string;
37
+ sourceId?: string;
38
+ note?: string;
39
+ occurredAt?: Date | string;
40
+ }
41
+ export declare class StockMovement extends SmrtObject {
42
+ /** Tenant scope. `null` means the movement is global. */
43
+ tenantId: string | null;
44
+ /** Plain string reference to the {@link Sku} being moved. */
45
+ skuId: string;
46
+ /** Plain string reference to the {@link InventoryLocation} being mutated. */
47
+ locationId: string;
48
+ /**
49
+ * Origin state for transitions (e.g. `available` → `allocated` for a
50
+ * reservation). `null` indicates "no origin" — used when stock enters
51
+ * the system fresh via {@link StockService.receive} or production.
52
+ */
53
+ fromState: StockState | null;
54
+ /**
55
+ * Destination state. `null` indicates "no destination" — used for
56
+ * fulfilment, where stock leaves the building entirely.
57
+ */
58
+ toState: StockState | null;
59
+ /** Quantity moved. Always positive; the direction is encoded by from/to. */
60
+ qty: number;
61
+ /**
62
+ * Why the movement happened (see {@link StockMovementReason}). Drawn
63
+ * from the canonical list when emitted by {@link StockService}; free-form
64
+ * strings are allowed for vertical-specific reasons.
65
+ */
66
+ reasonCode: StockMovementReason;
67
+ /**
68
+ * Cross-package attribution tag — e.g. `'Contract'`, `'Fulfillment'`,
69
+ * `'ProductionOrder'`, `'CycleCount'`. The package writing the
70
+ * movement decides what tag makes sense; readers can group by
71
+ * `(sourceType, sourceId)` to reconstruct "what caused this".
72
+ */
73
+ sourceType: string;
74
+ /**
75
+ * Cross-package id of the row that caused this movement. Plain string;
76
+ * the framework never dereferences it.
77
+ */
78
+ sourceId: string;
79
+ /** Optional free-form note shown in audit UIs. */
80
+ note: string;
81
+ /**
82
+ * When the movement happened. Set to `now` at write time; explicit
83
+ * values are allowed when back-dating an import.
84
+ */
85
+ occurredAt: Date;
86
+ constructor(options?: StockMovementOptions);
87
+ }
88
+ //# sourceMappingURL=StockMovement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StockMovement.d.ts","sourceRoot":"","sources":["../../src/models/StockMovement.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAEL,UAAU,EACV,KAAK,iBAAiB,EAEvB,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,iBAAiB;IAC7D,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IAC9B,OAAO,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,mBAAmB,CAAC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;CAC5B;AAED,qBAmBa,aAAc,SAAQ,UAAU;IAC3C,yDAAyD;IAEzD,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAE/B,6DAA6D;IAE7D,KAAK,EAAE,MAAM,CAAM;IAEnB,6EAA6E;IAE7E,UAAU,EAAE,MAAM,CAAM;IAExB;;;;OAIG;IACH,SAAS,EAAE,UAAU,GAAG,IAAI,CAAQ;IAEpC;;;OAGG;IACH,OAAO,EAAE,UAAU,GAAG,IAAI,CAAQ;IAElC,4EAA4E;IAE5E,GAAG,EAAE,MAAM,CAAO;IAElB;;;;OAIG;IAEH,UAAU,EAAE,mBAAmB,CAAgB;IAE/C;;;;;OAKG;IACH,UAAU,EAAE,MAAM,CAAM;IAExB;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAM;IAEtB,kDAAkD;IAClD,IAAI,EAAE,MAAM,CAAM;IAElB;;;OAGG;IACH,UAAU,EAAE,IAAI,CAAc;gBAElB,OAAO,GAAE,oBAAyB;CAmB/C"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Model exports for `@happyvertical/smrt-inventory`.
3
+ *
4
+ * Importing this barrel triggers `__smrt-register__.ts` first so the
5
+ * package's build-time manifest is published before any `@smrt()`
6
+ * decorator on a class module fires. See `__smrt-register__.ts` and
7
+ * issue #1132 for the full background.
8
+ *
9
+ * @packageDocumentation
10
+ */
11
+ import '../__smrt-register__.js';
12
+ export { InventoryLocation, type InventoryLocationOptions, } from './InventoryLocation.js';
13
+ export { StockLevel, type StockLevelOptions } from './StockLevel.js';
14
+ export { StockMovement, type StockMovementOptions } from './StockMovement.js';
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,yBAAyB,CAAC;AAEjC,OAAO,EACL,iBAAiB,EACjB,KAAK,wBAAwB,GAC9B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,228 @@
1
+ /**
2
+ * StockService — the only sanctioned way to mutate stock.
3
+ *
4
+ * Every mutation goes through one of six methods (`receive`, `reserve`,
5
+ * `release`, `fulfill`, `transfer`, `adjust`). Each one:
6
+ *
7
+ * 1. Updates the materialized {@link StockLevel} row(s) for the affected
8
+ * `(skuId, locationId, state)` tuples via the collection's upsert path.
9
+ * 2. Writes exactly one append-only {@link StockMovement} (or two for
10
+ * `transfer`, one per leg) carrying the reason, source attribution,
11
+ * quantity, and from/to state transition.
12
+ *
13
+ * **Atomicity**: each method runs every write inside a single database
14
+ * transaction (`db.transaction(...)` on `@happyvertical/sql >= 0.74.0`).
15
+ * Partial failure — e.g. the level write succeeds but the movement
16
+ * write throws — rolls the entire mutation back, so the materialized
17
+ * balance and the audit ledger never disagree. `transfer` writes both
18
+ * legs (source out, destination in) plus both movement rows in one tx,
19
+ * so a failure mid-`transfer` is also fully rolled back.
20
+ *
21
+ * If the underlying adapter does not expose `transaction()` (rare —
22
+ * sqlite, postgres, and duckdb all do as of 0.74.0; the JSON adapter
23
+ * does too), the service degrades to serial writes and emits a one-time
24
+ * `console.warn`. Tests and consumers that observe that warning should
25
+ * upgrade their adapter.
26
+ *
27
+ * Callers should never reach into the level or movement collections
28
+ * directly to mutate balances — doing so silently desyncs the audit
29
+ * ledger and breaks cycle counts.
30
+ *
31
+ * Concurrency: each method is a read-modify-write on the underlying
32
+ * StockLevel row. Awaited (serial) callers always see a consistent
33
+ * balance. Unawaited `Promise.all([reserve, reserve, ...])` against the
34
+ * same `(skuId, locationId)` can still over-allocate — the per-tx
35
+ * locking guarantees atomicity of each individual call, not isolation
36
+ * across concurrent transactions. Callers that need hard atomicity
37
+ * across concurrent reservations should serialise upstream (e.g. via
38
+ * the job runner from `@happyvertical/smrt-jobs`).
39
+ *
40
+ * @packageDocumentation
41
+ */
42
+ import { type DatabaseConfig } from '@happyvertical/smrt-core';
43
+ import { InventoryLocationCollection, StockLevelCollection, StockMovementCollection } from '../collections/index.js';
44
+ import type { StockMovementReason, StockState } from '../types.js';
45
+ /**
46
+ * Thrown by {@link StockService.reserve} (and {@link StockService.fulfill},
47
+ * {@link StockService.transfer}) when the caller asks to move more stock
48
+ * than the source state currently holds. Carries enough context for a
49
+ * caller to surface a meaningful UI message and decide whether to retry,
50
+ * backorder, or cancel.
51
+ */
52
+ export declare class InsufficientStockError extends Error {
53
+ readonly skuId: string;
54
+ readonly locationId: string;
55
+ readonly state: StockState;
56
+ readonly requested: number;
57
+ readonly available: number;
58
+ name: string;
59
+ constructor(skuId: string, locationId: string, state: StockState, requested: number, available: number);
60
+ }
61
+ /**
62
+ * Options shared by every {@link StockService} method that wants to leave
63
+ * an audit attribution behind. Pairs neatly with the cross-package
64
+ * pattern in {@link StockMovement.sourceType} / {@link StockMovement.sourceId}.
65
+ */
66
+ export interface StockMutationOptions {
67
+ /** Cross-package tag, e.g. `'Contract'`, `'Fulfillment'`, `'CycleCount'`. */
68
+ sourceType?: string;
69
+ /** Cross-package id of the row that caused this mutation. */
70
+ sourceId?: string;
71
+ /** Free-form note shown in audit UIs. */
72
+ note?: string;
73
+ /**
74
+ * Override the reason code stamped on the {@link StockMovement}. Each
75
+ * method picks a sensible default; explicit overrides are useful when a
76
+ * vertical wants to flag a more specific reason (e.g. `'return'`
77
+ * instead of `'receipt'`).
78
+ */
79
+ reasonCode?: StockMovementReason;
80
+ }
81
+ /**
82
+ * Options accepted by the {@link StockService} factory.
83
+ */
84
+ export interface StockServiceOptions {
85
+ /**
86
+ * Database to read/write through. Accepts the same shapes that
87
+ * `SmrtCollection.create({ db })` accepts — a `DatabaseInterface`, a
88
+ * connection-string URL, or a `{ type, url }` config object. Reused by
89
+ * the internal collections so the service, level reads, and movement
90
+ * writes always hit the same connection / pool.
91
+ */
92
+ db: DatabaseConfig;
93
+ }
94
+ /**
95
+ * Sanctioned stock-mutation surface.
96
+ *
97
+ * Construct via {@link createStockService} — the static factory wires up
98
+ * the underlying collections and shares one database connection across
99
+ * level reads and movement writes.
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * const service = await createStockService({ db });
104
+ * await service.receive(sku.id, warehouse.id, 100, {
105
+ * sourceType: 'PurchaseOrder',
106
+ * sourceId: po.id,
107
+ * });
108
+ * await service.reserve(sku.id, warehouse.id, 10, {
109
+ * sourceType: 'Contract',
110
+ * sourceId: order.id,
111
+ * });
112
+ * await service.fulfill(sku.id, warehouse.id, 10, {
113
+ * sourceType: 'Fulfillment',
114
+ * sourceId: fulfillment.id,
115
+ * });
116
+ * ```
117
+ */
118
+ export declare class StockService {
119
+ /**
120
+ * The database config this service was bound to (URL string, config
121
+ * object, or already-resolved `DatabaseInterface`). Exposed so
122
+ * downstream services that compose StockService (e.g. BomService,
123
+ * ProductionService in `@happyvertical/smrt-manufacturing`) can pass
124
+ * the same value to their own collection factories without reaching
125
+ * into private fields on the collections.
126
+ */
127
+ readonly db: DatabaseConfig;
128
+ readonly levels: StockLevelCollection;
129
+ readonly movements: StockMovementCollection;
130
+ readonly locations: InventoryLocationCollection;
131
+ /**
132
+ * Marks a service instance handed to a {@link withTransaction}
133
+ * callback. Public mutation methods on a tx-bound instance skip
134
+ * opening a nested transaction and just execute against the already-
135
+ * bound collections; outer (non-tx) instances open a fresh
136
+ * transaction per mutation. Internal flag — consumers never set it.
137
+ */
138
+ private readonly inTransaction;
139
+ private constructor();
140
+ /** Internal factory — prefer {@link createStockService}. */
141
+ static create(options: StockServiceOptions): Promise<StockService>;
142
+ /**
143
+ * Run `work` inside a single database transaction with a tx-bound
144
+ * {@link StockService} instance. All mutation calls on `tx` commit
145
+ * atomically when `work` resolves and roll back if it throws.
146
+ *
147
+ * Use this when you need atomicity ACROSS multiple stock-service
148
+ * calls — e.g. consuming materials for every line of a production
149
+ * order in `@happyvertical/smrt-manufacturing`'s `ProductionService`,
150
+ * or a custom workflow that reserves + fulfills + writes a custom
151
+ * audit comment in one indivisible step. Individual mutation methods
152
+ * (`receive`, `reserve`, etc.) are already atomic on their own — you
153
+ * only need `withTransaction` for cross-call composition.
154
+ *
155
+ * Nesting is safe: calling `tx.withTransaction(...)` inside an
156
+ * already-tx-bound callback simply runs the inner `work` on the same
157
+ * transaction without opening a savepoint.
158
+ *
159
+ * When the underlying adapter does not expose `transaction()`, falls
160
+ * through to a serial run on the regular collections with a one-time
161
+ * warning. All four built-in adapters in `@happyvertical/sql >= 0.74.0`
162
+ * support it; only test stubs would hit this branch.
163
+ */
164
+ withTransaction<T>(work: (tx: StockService) => Promise<T>): Promise<T>;
165
+ /**
166
+ * Internal: run a single-method mutation in a transaction. If we're
167
+ * already inside one (the instance was handed to a `withTransaction`
168
+ * callback), reuse it; otherwise open a fresh one.
169
+ */
170
+ private runAtomically;
171
+ /**
172
+ * Add `qty` to available stock at the given location. Used for
173
+ * purchase-order receipts, customer returns going back into available
174
+ * inventory, and the "produce" leg of a production order.
175
+ */
176
+ receive(skuId: string, locationId: string, qty: number, options?: StockMutationOptions): Promise<void>;
177
+ /**
178
+ * Move `qty` from `available` to `allocated` at the given location.
179
+ * Throws {@link InsufficientStockError} if available stock would go
180
+ * negative.
181
+ */
182
+ reserve(skuId: string, locationId: string, qty: number, options?: StockMutationOptions): Promise<void>;
183
+ /**
184
+ * Move `qty` from `allocated` back to `available`. Used when a
185
+ * reservation is cancelled and the previously-reserved stock should
186
+ * go back into the available pool.
187
+ */
188
+ release(skuId: string, locationId: string, qty: number, options?: StockMutationOptions): Promise<void>;
189
+ /**
190
+ * Remove `qty` from `allocated` at the given location. Stock leaves
191
+ * the building entirely (shipped, picked up, consumed). Throws
192
+ * {@link InsufficientStockError} if allocated stock would go negative.
193
+ */
194
+ fulfill(skuId: string, locationId: string, qty: number, options?: StockMutationOptions): Promise<void>;
195
+ /**
196
+ * Move `qty` of `available` stock from `fromLocationId` to
197
+ * `toLocationId`. Writes two movement rows — one for the `transfer_out`
198
+ * leg, one for the `transfer_in` leg — so the audit log preserves the
199
+ * lineage in both directions. Throws {@link InsufficientStockError} if
200
+ * source available stock would go negative.
201
+ *
202
+ * Both legs (level writes + movement rows) run inside one transaction
203
+ * — a failure mid-`transfer` rolls back the source debit so there's no
204
+ * "ghost stock disappearance" (source decremented, destination never
205
+ * credited).
206
+ */
207
+ transfer(skuId: string, fromLocationId: string, toLocationId: string, qty: number, options?: StockMutationOptions): Promise<void>;
208
+ /**
209
+ * Apply a positive or negative `delta` to a level row. Used for cycle
210
+ * counts and one-off corrections; `delta=+5` adds five units,
211
+ * `delta=-2` removes two. By default the adjustment targets
212
+ * `available` stock; pass an explicit `state` to adjust a different
213
+ * bucket (e.g. `'damaged'` after a quality-control reclassification).
214
+ *
215
+ * Adjusting by `0` is rejected as a probable programming error — the
216
+ * caller almost always meant a non-zero delta and a no-op write would
217
+ * still cost an audit row.
218
+ */
219
+ adjust(skuId: string, locationId: string, delta: number, options?: StockMutationOptions & {
220
+ state?: StockState;
221
+ }): Promise<void>;
222
+ }
223
+ /**
224
+ * Convenience factory. Returns a fully-initialized {@link StockService}
225
+ * sharing the given database with its internal collections.
226
+ */
227
+ export declare function createStockService(options: StockServiceOptions): Promise<StockService>;
228
+ //# sourceMappingURL=StockService.d.ts.map