@happyvertical/smrt-manufacturing 0.53.4 → 0.53.6

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.
Files changed (106) hide show
  1. package/AGENTS.md +58 -7
  2. package/README.md +228 -4
  3. package/agents/multilevel-and-runs.md +28 -0
  4. package/dist/collections/AssemblyCollection.d.ts +15 -0
  5. package/dist/collections/AssemblyCollection.d.ts.map +1 -0
  6. package/dist/collections/OperationCollection.d.ts +20 -0
  7. package/dist/collections/OperationCollection.d.ts.map +1 -0
  8. package/dist/collections/ProductionRunCollection.d.ts +15 -0
  9. package/dist/collections/ProductionRunCollection.d.ts.map +1 -0
  10. package/dist/collections/ProductionRunCompletionCollection.d.ts +14 -0
  11. package/dist/collections/ProductionRunCompletionCollection.d.ts.map +1 -0
  12. package/dist/collections/RoutingStepCollection.d.ts +15 -0
  13. package/dist/collections/RoutingStepCollection.d.ts.map +1 -0
  14. package/dist/collections/index.d.ts +5 -0
  15. package/dist/collections/index.d.ts.map +1 -1
  16. package/dist/index.d.ts +23 -5
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +1660 -42
  19. package/dist/index.js.map +1 -1
  20. package/dist/manifest.json +1910 -161
  21. package/dist/models/Assembly.d.ts +62 -0
  22. package/dist/models/Assembly.d.ts.map +1 -0
  23. package/dist/models/BillOfMaterials.d.ts +12 -4
  24. package/dist/models/BillOfMaterials.d.ts.map +1 -1
  25. package/dist/models/BomLine.d.ts +11 -5
  26. package/dist/models/BomLine.d.ts.map +1 -1
  27. package/dist/models/Operation.d.ts +59 -0
  28. package/dist/models/Operation.d.ts.map +1 -0
  29. package/dist/models/ProductionRun.d.ts +67 -0
  30. package/dist/models/ProductionRun.d.ts.map +1 -0
  31. package/dist/models/ProductionRunCompletion.d.ts +36 -0
  32. package/dist/models/ProductionRunCompletion.d.ts.map +1 -0
  33. package/dist/models/RoutingStep.d.ts +46 -0
  34. package/dist/models/RoutingStep.d.ts.map +1 -0
  35. package/dist/models/index.d.ts +5 -0
  36. package/dist/models/index.d.ts.map +1 -1
  37. package/dist/operation-types.d.ts +108 -0
  38. package/dist/operation-types.d.ts.map +1 -0
  39. package/dist/production-run-types.d.ts +100 -0
  40. package/dist/production-run-types.d.ts.map +1 -0
  41. package/dist/quantity.d.ts +36 -0
  42. package/dist/quantity.d.ts.map +1 -0
  43. package/dist/services/AssemblyService.d.ts +222 -0
  44. package/dist/services/AssemblyService.d.ts.map +1 -0
  45. package/dist/services/BomService.d.ts +108 -5
  46. package/dist/services/BomService.d.ts.map +1 -1
  47. package/dist/services/OperationService.d.ts +48 -0
  48. package/dist/services/OperationService.d.ts.map +1 -0
  49. package/dist/services/ProductionRunService.d.ts +123 -0
  50. package/dist/services/ProductionRunService.d.ts.map +1 -0
  51. package/dist/services/ProductionService.d.ts +11 -0
  52. package/dist/services/ProductionService.d.ts.map +1 -1
  53. package/dist/services/RoutingService.d.ts +50 -0
  54. package/dist/services/RoutingService.d.ts.map +1 -0
  55. package/dist/services/index.d.ts +5 -0
  56. package/dist/services/index.d.ts.map +1 -1
  57. package/dist/services/structure-walk.d.ts +77 -0
  58. package/dist/services/structure-walk.d.ts.map +1 -0
  59. package/dist/smrt-knowledge.json +1771 -207
  60. package/dist/svelte/components/AssemblyForm.svelte +69 -0
  61. package/dist/svelte/components/AssemblyForm.svelte.d.ts +38 -0
  62. package/dist/svelte/components/AssemblyForm.svelte.d.ts.map +1 -0
  63. package/dist/svelte/components/AssemblyList.svelte +229 -0
  64. package/dist/svelte/components/AssemblyList.svelte.d.ts +28 -0
  65. package/dist/svelte/components/AssemblyList.svelte.d.ts.map +1 -0
  66. package/dist/svelte/components/BomEditor.svelte +575 -0
  67. package/dist/svelte/components/BomEditor.svelte.d.ts +29 -0
  68. package/dist/svelte/components/BomEditor.svelte.d.ts.map +1 -0
  69. package/dist/svelte/components/BomStructureTree.svelte +164 -0
  70. package/dist/svelte/components/BomStructureTree.svelte.d.ts +16 -0
  71. package/dist/svelte/components/BomStructureTree.svelte.d.ts.map +1 -0
  72. package/dist/svelte/components/OperationForm.svelte +258 -0
  73. package/dist/svelte/components/OperationForm.svelte.d.ts +17 -0
  74. package/dist/svelte/components/OperationForm.svelte.d.ts.map +1 -0
  75. package/dist/svelte/components/OperationList.svelte +170 -0
  76. package/dist/svelte/components/OperationList.svelte.d.ts +17 -0
  77. package/dist/svelte/components/OperationList.svelte.d.ts.map +1 -0
  78. package/dist/svelte/components/ProductionRunList.svelte +213 -0
  79. package/dist/svelte/components/ProductionRunList.svelte.d.ts +18 -0
  80. package/dist/svelte/components/ProductionRunList.svelte.d.ts.map +1 -0
  81. package/dist/svelte/components/RequirementsTree.svelte +125 -0
  82. package/dist/svelte/components/RequirementsTree.svelte.d.ts +13 -0
  83. package/dist/svelte/components/RequirementsTree.svelte.d.ts.map +1 -0
  84. package/dist/svelte/components/RequirementsTreeLevel.svelte +120 -0
  85. package/dist/svelte/components/RequirementsTreeLevel.svelte.d.ts +12 -0
  86. package/dist/svelte/components/RequirementsTreeLevel.svelte.d.ts.map +1 -0
  87. package/dist/svelte/i18n.d.ts +119 -0
  88. package/dist/svelte/i18n.d.ts.map +1 -0
  89. package/dist/svelte/i18n.js +119 -0
  90. package/dist/svelte/index.d.ts +33 -0
  91. package/dist/svelte/index.d.ts.map +1 -0
  92. package/dist/svelte/index.js +34 -0
  93. package/dist/svelte/types.d.ts +257 -0
  94. package/dist/svelte/types.d.ts.map +1 -0
  95. package/dist/svelte/types.js +249 -0
  96. package/dist/tenant-scope.d.ts +25 -0
  97. package/dist/tenant-scope.d.ts.map +1 -0
  98. package/dist/types.d.ts +207 -3
  99. package/dist/types.d.ts.map +1 -1
  100. package/dist/types.js +13 -1
  101. package/dist/types.js.map +1 -1
  102. package/dist/ui.d.ts +17 -0
  103. package/dist/ui.d.ts.map +1 -0
  104. package/dist/ui.js +94 -0
  105. package/dist/ui.js.map +1 -0
  106. package/package.json +41 -11
@@ -3,35 +3,50 @@
3
3
  "sensitiveFieldsExcluded": true,
4
4
  "generatedAt": "1970-01-01T00:00:00.000Z",
5
5
  "packageName": "@happyvertical/smrt-manufacturing",
6
- "packageVersion": "0.53.4",
6
+ "packageVersion": "0.53.6",
7
7
  "sourceManifestPath": "dist/manifest.json",
8
8
  "agentDocPath": "AGENTS.md",
9
9
  "sourceHashes": {
10
- "manifest": "bf94ab872eb2ab071b1a43e8ee6286f63faaf3e162b71ca2421e7cb27869586a",
11
- "packageJson": "b8542ff6ff2fb43bf90164c60e7c8219e76b9b0bc286ac747b934f7e665dcd58",
12
- "agents": "94d10408c859743730368f932f77e5602ebefb8fe9a8ac3178fa4b211e95ad29"
10
+ "manifest": "14da998a347684165c850751fd725040b4b68aef3ad189df41dd45f74b415dd9",
11
+ "packageJson": "deef24b4b78a758c9be6f5c83885f321c441f7cc580c4497fc02819ff92613c1",
12
+ "agents": "de169f8ea3f02692b4c6c05d8706b1b9dc7fae8373bc16e0eb5d364938a07bee",
13
+ "moduleDoc:agents/multilevel-and-runs.md": "544d519356801f3cb3beb9e6d49a3e0eec93fdddf3f56150cf3141f766f98c9d"
13
14
  },
14
15
  "exports": [
15
16
  ".",
16
17
  "./manifest",
17
- "./manifest.json"
18
+ "./manifest.json",
19
+ "./svelte",
20
+ "./ui"
18
21
  ],
19
22
  "dependencies": {
20
23
  "@happyvertical/logger": "catalog:",
21
24
  "@happyvertical/smrt-core": "workspace:*",
25
+ "@happyvertical/smrt-fields": "workspace:*",
22
26
  "@happyvertical/smrt-inventory": "workspace:*",
27
+ "@happyvertical/smrt-products": "workspace:*",
23
28
  "@happyvertical/smrt-tenancy": "workspace:*",
29
+ "@happyvertical/smrt-types": "workspace:*",
30
+ "@happyvertical/smrt-ui": "workspace:*",
24
31
  "@happyvertical/sql": "catalog:",
25
32
  "@happyvertical/smrt-vitest": "workspace:*",
33
+ "@sveltejs/package": "^2.5.8",
34
+ "@sveltejs/vite-plugin-svelte": "^7.3.0",
26
35
  "@types/node": "24.13.6",
36
+ "svelte": "^5.57.0",
37
+ "svelte-check": "^4.7.6",
27
38
  "typescript": "6.0.3",
28
39
  "vite": "8.1.4",
29
40
  "vitest": "4.1.10"
30
41
  },
31
42
  "smrtDependencies": [
32
43
  "@happyvertical/smrt-core",
44
+ "@happyvertical/smrt-fields",
33
45
  "@happyvertical/smrt-inventory",
46
+ "@happyvertical/smrt-products",
34
47
  "@happyvertical/smrt-tenancy",
48
+ "@happyvertical/smrt-types",
49
+ "@happyvertical/smrt-ui",
35
50
  "@happyvertical/smrt-vitest"
36
51
  ],
37
52
  "sdkDependencies": [
@@ -39,6 +54,7 @@
39
54
  "@happyvertical/sql"
40
55
  ],
41
56
  "tags": [
57
+ "assembly",
42
58
  "bill-of-materials",
43
59
  "bom",
44
60
  "cost-rollup",
@@ -48,7 +64,9 @@
48
64
  "smrt"
49
65
  ],
50
66
  "risks": [
51
- "sensitive-fields-excluded"
67
+ "cross-package-refs:1",
68
+ "sensitive-fields-excluded",
69
+ "sti-inheritance"
52
70
  ],
53
71
  "objects": [
54
72
  {
@@ -238,6 +256,623 @@
238
256
  "tags": [],
239
257
  "risks": []
240
258
  },
259
+ {
260
+ "name": "OperationCollection",
261
+ "qualifiedName": "@happyvertical/smrt-manufacturing:OperationCollection",
262
+ "collection": "operations",
263
+ "tableName": "manufacturing_operations",
264
+ "packageName": "@happyvertical/smrt-manufacturing",
265
+ "extends": "SmrtCollection",
266
+ "fields": [],
267
+ "relationships": [],
268
+ "methods": [
269
+ "findByCode",
270
+ "listOperations"
271
+ ],
272
+ "methodSignatures": [
273
+ {
274
+ "name": "findByCode",
275
+ "async": true,
276
+ "params": [
277
+ "code: string"
278
+ ],
279
+ "returns": "Promise<Operation | null>"
280
+ },
281
+ {
282
+ "name": "listOperations",
283
+ "async": true,
284
+ "params": [
285
+ "options?: object"
286
+ ],
287
+ "returns": "Promise<Operation[]>"
288
+ }
289
+ ],
290
+ "surfaces": [
291
+ {
292
+ "kind": "api",
293
+ "name": "operations.findByCode",
294
+ "operation": "findByCode",
295
+ "objectName": "@happyvertical/smrt-manufacturing:OperationCollection",
296
+ "path": "/operations/findByCode",
297
+ "method": "POST"
298
+ },
299
+ {
300
+ "kind": "api",
301
+ "name": "operations.listOperations",
302
+ "operation": "listOperations",
303
+ "objectName": "@happyvertical/smrt-manufacturing:OperationCollection",
304
+ "path": "/operations/listOperations",
305
+ "method": "POST"
306
+ },
307
+ {
308
+ "kind": "cli",
309
+ "name": "operationcollection_findByCode",
310
+ "operation": "findByCode",
311
+ "objectName": "@happyvertical/smrt-manufacturing:OperationCollection"
312
+ },
313
+ {
314
+ "kind": "cli",
315
+ "name": "operationcollection_listOperations",
316
+ "operation": "listOperations",
317
+ "objectName": "@happyvertical/smrt-manufacturing:OperationCollection"
318
+ },
319
+ {
320
+ "kind": "mcp",
321
+ "name": "operationcollection_findbycode",
322
+ "operation": "findByCode",
323
+ "objectName": "@happyvertical/smrt-manufacturing:OperationCollection"
324
+ },
325
+ {
326
+ "kind": "mcp",
327
+ "name": "operationcollection_listoperations",
328
+ "operation": "listOperations",
329
+ "objectName": "@happyvertical/smrt-manufacturing:OperationCollection"
330
+ }
331
+ ],
332
+ "relationshipFeatures": [
333
+ "uuidColumns"
334
+ ],
335
+ "tags": [],
336
+ "risks": []
337
+ },
338
+ {
339
+ "name": "ProductionRunCollection",
340
+ "qualifiedName": "@happyvertical/smrt-manufacturing:ProductionRunCollection",
341
+ "collection": "productionruns",
342
+ "tableName": "manufacturing_production_runs",
343
+ "packageName": "@happyvertical/smrt-manufacturing",
344
+ "extends": "SmrtCollection",
345
+ "fields": [],
346
+ "relationships": [],
347
+ "methods": [
348
+ "findByBom",
349
+ "findByStatus"
350
+ ],
351
+ "methodSignatures": [
352
+ {
353
+ "name": "findByBom",
354
+ "async": true,
355
+ "params": [
356
+ "bomId: string"
357
+ ],
358
+ "returns": "Promise<ProductionRun[]>"
359
+ },
360
+ {
361
+ "name": "findByStatus",
362
+ "async": true,
363
+ "params": [
364
+ "status: ProductionRunStatus"
365
+ ],
366
+ "returns": "Promise<ProductionRun[]>"
367
+ }
368
+ ],
369
+ "surfaces": [
370
+ {
371
+ "kind": "api",
372
+ "name": "productionruns.findByBom",
373
+ "operation": "findByBom",
374
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCollection",
375
+ "path": "/productionruns/findByBom",
376
+ "method": "POST"
377
+ },
378
+ {
379
+ "kind": "api",
380
+ "name": "productionruns.findByStatus",
381
+ "operation": "findByStatus",
382
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCollection",
383
+ "path": "/productionruns/findByStatus",
384
+ "method": "POST"
385
+ },
386
+ {
387
+ "kind": "cli",
388
+ "name": "productionruncollection_findByBom",
389
+ "operation": "findByBom",
390
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCollection"
391
+ },
392
+ {
393
+ "kind": "cli",
394
+ "name": "productionruncollection_findByStatus",
395
+ "operation": "findByStatus",
396
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCollection"
397
+ },
398
+ {
399
+ "kind": "mcp",
400
+ "name": "productionruncollection_findbybom",
401
+ "operation": "findByBom",
402
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCollection"
403
+ },
404
+ {
405
+ "kind": "mcp",
406
+ "name": "productionruncollection_findbystatus",
407
+ "operation": "findByStatus",
408
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCollection"
409
+ }
410
+ ],
411
+ "relationshipFeatures": [
412
+ "uuidColumns"
413
+ ],
414
+ "tags": [],
415
+ "risks": []
416
+ },
417
+ {
418
+ "name": "ProductionRunCompletionCollection",
419
+ "qualifiedName": "@happyvertical/smrt-manufacturing:ProductionRunCompletionCollection",
420
+ "collection": "productionruncompletions",
421
+ "tableName": "manufacturing_production_run_completions",
422
+ "packageName": "@happyvertical/smrt-manufacturing",
423
+ "extends": "SmrtCollection",
424
+ "fields": [],
425
+ "relationships": [],
426
+ "methods": [
427
+ "findByRun"
428
+ ],
429
+ "methodSignatures": [
430
+ {
431
+ "name": "findByRun",
432
+ "async": true,
433
+ "params": [
434
+ "runId: string"
435
+ ],
436
+ "returns": "Promise<ProductionRunCompletion[]>"
437
+ }
438
+ ],
439
+ "surfaces": [
440
+ {
441
+ "kind": "api",
442
+ "name": "productionruncompletions.findByRun",
443
+ "operation": "findByRun",
444
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCompletionCollection",
445
+ "path": "/productionruncompletions/findByRun",
446
+ "method": "POST"
447
+ },
448
+ {
449
+ "kind": "cli",
450
+ "name": "productionruncompletioncollection_findByRun",
451
+ "operation": "findByRun",
452
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCompletionCollection"
453
+ },
454
+ {
455
+ "kind": "mcp",
456
+ "name": "productionruncompletioncollection_findbyrun",
457
+ "operation": "findByRun",
458
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCompletionCollection"
459
+ }
460
+ ],
461
+ "relationshipFeatures": [
462
+ "uuidColumns"
463
+ ],
464
+ "tags": [],
465
+ "risks": []
466
+ },
467
+ {
468
+ "name": "RoutingStepCollection",
469
+ "qualifiedName": "@happyvertical/smrt-manufacturing:RoutingStepCollection",
470
+ "collection": "routingsteps",
471
+ "tableName": "manufacturing_routing_steps",
472
+ "packageName": "@happyvertical/smrt-manufacturing",
473
+ "extends": "SmrtCollection",
474
+ "fields": [],
475
+ "relationships": [],
476
+ "methods": [
477
+ "findByBom",
478
+ "findByOperation"
479
+ ],
480
+ "methodSignatures": [
481
+ {
482
+ "name": "findByBom",
483
+ "async": true,
484
+ "params": [
485
+ "bomId: string"
486
+ ],
487
+ "returns": "Promise<RoutingStep[]>"
488
+ },
489
+ {
490
+ "name": "findByOperation",
491
+ "async": true,
492
+ "params": [
493
+ "operationId: string"
494
+ ],
495
+ "returns": "Promise<RoutingStep[]>"
496
+ }
497
+ ],
498
+ "surfaces": [
499
+ {
500
+ "kind": "api",
501
+ "name": "routingsteps.findByBom",
502
+ "operation": "findByBom",
503
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStepCollection",
504
+ "path": "/routingsteps/findByBom",
505
+ "method": "POST"
506
+ },
507
+ {
508
+ "kind": "api",
509
+ "name": "routingsteps.findByOperation",
510
+ "operation": "findByOperation",
511
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStepCollection",
512
+ "path": "/routingsteps/findByOperation",
513
+ "method": "POST"
514
+ },
515
+ {
516
+ "kind": "cli",
517
+ "name": "routingstepcollection_findByBom",
518
+ "operation": "findByBom",
519
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStepCollection"
520
+ },
521
+ {
522
+ "kind": "cli",
523
+ "name": "routingstepcollection_findByOperation",
524
+ "operation": "findByOperation",
525
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStepCollection"
526
+ },
527
+ {
528
+ "kind": "mcp",
529
+ "name": "routingstepcollection_findbybom",
530
+ "operation": "findByBom",
531
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStepCollection"
532
+ },
533
+ {
534
+ "kind": "mcp",
535
+ "name": "routingstepcollection_findbyoperation",
536
+ "operation": "findByOperation",
537
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStepCollection"
538
+ }
539
+ ],
540
+ "relationshipFeatures": [
541
+ "uuidColumns"
542
+ ],
543
+ "tags": [],
544
+ "risks": []
545
+ },
546
+ {
547
+ "name": "Assembly",
548
+ "qualifiedName": "@happyvertical/smrt-manufacturing:Assembly",
549
+ "collection": "products",
550
+ "tableName": "products",
551
+ "packageName": "@happyvertical/smrt-manufacturing",
552
+ "extends": "Product",
553
+ "fields": [
554
+ {
555
+ "name": "created_at",
556
+ "type": "datetime",
557
+ "required": false,
558
+ "columnType": "TIMESTAMP"
559
+ },
560
+ {
561
+ "name": "updated_at",
562
+ "type": "datetime",
563
+ "required": false,
564
+ "columnType": "TIMESTAMP"
565
+ },
566
+ {
567
+ "name": "tenantId",
568
+ "type": "text",
569
+ "required": false,
570
+ "columnType": "UUID"
571
+ },
572
+ {
573
+ "name": "productType",
574
+ "type": "json",
575
+ "required": false,
576
+ "columnType": "TEXT"
577
+ },
578
+ {
579
+ "name": "name",
580
+ "type": "text",
581
+ "required": false,
582
+ "columnType": "TEXT"
583
+ },
584
+ {
585
+ "name": "description",
586
+ "type": "text",
587
+ "required": false,
588
+ "columnType": "TEXT"
589
+ },
590
+ {
591
+ "name": "category",
592
+ "type": "text",
593
+ "required": false,
594
+ "columnType": "TEXT"
595
+ },
596
+ {
597
+ "name": "manufacturer",
598
+ "type": "text",
599
+ "required": false,
600
+ "columnType": "TEXT"
601
+ },
602
+ {
603
+ "name": "model",
604
+ "type": "text",
605
+ "required": false,
606
+ "columnType": "TEXT"
607
+ },
608
+ {
609
+ "name": "price",
610
+ "type": "integer",
611
+ "required": true,
612
+ "columnType": "INTEGER",
613
+ "default": 0
614
+ },
615
+ {
616
+ "name": "inStock",
617
+ "type": "boolean",
618
+ "required": true,
619
+ "columnType": "BOOLEAN",
620
+ "default": true
621
+ },
622
+ {
623
+ "name": "specifications",
624
+ "type": "json",
625
+ "required": false,
626
+ "columnType": "JSON",
627
+ "default": {}
628
+ },
629
+ {
630
+ "name": "tags",
631
+ "type": "json",
632
+ "required": false,
633
+ "columnType": "JSON",
634
+ "default": []
635
+ },
636
+ {
637
+ "name": "estimatedLabourMinutes",
638
+ "type": "integer",
639
+ "required": false,
640
+ "columnType": "INTEGER",
641
+ "default": 0
642
+ },
643
+ {
644
+ "name": "defaultOperationId",
645
+ "type": "foreignKey",
646
+ "required": false,
647
+ "related": "Operation",
648
+ "columnType": "UUID"
649
+ },
650
+ {
651
+ "name": "partReference",
652
+ "type": "text",
653
+ "required": false,
654
+ "columnType": "TEXT",
655
+ "default": ""
656
+ }
657
+ ],
658
+ "relationships": [
659
+ {
660
+ "name": "defaultOperationId",
661
+ "type": "foreignKey",
662
+ "required": false,
663
+ "related": "Operation",
664
+ "columnType": "UUID"
665
+ }
666
+ ],
667
+ "methods": [
668
+ "addAsset",
669
+ "getAssets",
670
+ "getSpecification",
671
+ "removeAsset",
672
+ "updateSpecification"
673
+ ],
674
+ "methodSignatures": [
675
+ {
676
+ "name": "addAsset",
677
+ "async": true,
678
+ "params": [
679
+ "asset: Asset",
680
+ "relationship?: any",
681
+ "sortOrder?: any"
682
+ ],
683
+ "returns": "Promise<void>"
684
+ },
685
+ {
686
+ "name": "getAssets",
687
+ "async": true,
688
+ "params": [
689
+ "relationship?: string"
690
+ ],
691
+ "returns": "Promise<Asset[]>"
692
+ },
693
+ {
694
+ "name": "getSpecification",
695
+ "async": true,
696
+ "params": [
697
+ "key: string"
698
+ ],
699
+ "returns": "Promise<unknown>"
700
+ },
701
+ {
702
+ "name": "removeAsset",
703
+ "async": true,
704
+ "params": [
705
+ "assetId: string",
706
+ "relationship?: string"
707
+ ],
708
+ "returns": "Promise<void>"
709
+ },
710
+ {
711
+ "name": "updateSpecification",
712
+ "async": true,
713
+ "params": [
714
+ "key: string",
715
+ "value: unknown"
716
+ ],
717
+ "returns": "Promise<void>"
718
+ }
719
+ ],
720
+ "tenant": {
721
+ "scoped": true,
722
+ "mode": "optional",
723
+ "field": "tenantId"
724
+ },
725
+ "tableStrategy": "sti",
726
+ "surfaces": [
727
+ {
728
+ "kind": "api",
729
+ "name": "products.list",
730
+ "operation": "list",
731
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly",
732
+ "path": "/products",
733
+ "method": "GET"
734
+ },
735
+ {
736
+ "kind": "api",
737
+ "name": "products.get",
738
+ "operation": "get",
739
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly",
740
+ "path": "/products/[id]",
741
+ "method": "GET"
742
+ },
743
+ {
744
+ "kind": "api",
745
+ "name": "products.create",
746
+ "operation": "create",
747
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly",
748
+ "path": "/products",
749
+ "method": "POST"
750
+ },
751
+ {
752
+ "kind": "api",
753
+ "name": "products.update",
754
+ "operation": "update",
755
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly",
756
+ "path": "/products/[id]",
757
+ "method": "PATCH"
758
+ },
759
+ {
760
+ "kind": "cli",
761
+ "name": "assembly_list",
762
+ "operation": "list",
763
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
764
+ },
765
+ {
766
+ "kind": "cli",
767
+ "name": "assembly_get",
768
+ "operation": "get",
769
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
770
+ },
771
+ {
772
+ "kind": "cli",
773
+ "name": "assembly_create",
774
+ "operation": "create",
775
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
776
+ },
777
+ {
778
+ "kind": "cli",
779
+ "name": "assembly_update",
780
+ "operation": "update",
781
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
782
+ },
783
+ {
784
+ "kind": "cli",
785
+ "name": "assembly_delete",
786
+ "operation": "delete",
787
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
788
+ },
789
+ {
790
+ "kind": "cli",
791
+ "name": "assembly_getSpecification",
792
+ "operation": "getSpecification",
793
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
794
+ },
795
+ {
796
+ "kind": "cli",
797
+ "name": "assembly_updateSpecification",
798
+ "operation": "updateSpecification",
799
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
800
+ },
801
+ {
802
+ "kind": "cli",
803
+ "name": "assembly_getAssets",
804
+ "operation": "getAssets",
805
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
806
+ },
807
+ {
808
+ "kind": "cli",
809
+ "name": "assembly_addAsset",
810
+ "operation": "addAsset",
811
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
812
+ },
813
+ {
814
+ "kind": "cli",
815
+ "name": "assembly_removeAsset",
816
+ "operation": "removeAsset",
817
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
818
+ },
819
+ {
820
+ "kind": "mcp",
821
+ "name": "assembly_list",
822
+ "operation": "list",
823
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
824
+ },
825
+ {
826
+ "kind": "mcp",
827
+ "name": "assembly_get",
828
+ "operation": "get",
829
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
830
+ }
831
+ ],
832
+ "withheldSurfaces": [
833
+ {
834
+ "kind": "api",
835
+ "operation": "addAsset",
836
+ "code": "not-included",
837
+ "reason": "not listed in api.include",
838
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
839
+ },
840
+ {
841
+ "kind": "api",
842
+ "operation": "getAssets",
843
+ "code": "not-included",
844
+ "reason": "not listed in api.include",
845
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
846
+ },
847
+ {
848
+ "kind": "api",
849
+ "operation": "getSpecification",
850
+ "code": "not-included",
851
+ "reason": "not listed in api.include",
852
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
853
+ },
854
+ {
855
+ "kind": "api",
856
+ "operation": "removeAsset",
857
+ "code": "not-included",
858
+ "reason": "not listed in api.include",
859
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
860
+ },
861
+ {
862
+ "kind": "api",
863
+ "operation": "updateSpecification",
864
+ "code": "not-included",
865
+ "reason": "not listed in api.include",
866
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
867
+ }
868
+ ],
869
+ "relationshipFeatures": [
870
+ "foreignKey",
871
+ "uuidColumns"
872
+ ],
873
+ "tags": [],
874
+ "risks": []
875
+ },
241
876
  {
242
877
  "name": "BillOfMaterials",
243
878
  "qualifiedName": "@happyvertical/smrt-manufacturing:BillOfMaterials",
@@ -253,48 +888,610 @@
253
888
  "columnType": "UUID"
254
889
  },
255
890
  {
256
- "name": "productId",
891
+ "name": "productId",
892
+ "type": "text",
893
+ "required": true,
894
+ "columnType": "TEXT",
895
+ "default": ""
896
+ },
897
+ {
898
+ "name": "version",
899
+ "type": "integer",
900
+ "required": true,
901
+ "columnType": "INTEGER",
902
+ "default": 1
903
+ },
904
+ {
905
+ "name": "effectiveDate",
906
+ "type": "datetime",
907
+ "required": false,
908
+ "columnType": "TIMESTAMP"
909
+ },
910
+ {
911
+ "name": "status",
912
+ "type": "text",
913
+ "required": true,
914
+ "columnType": "TEXT",
915
+ "default": "draft"
916
+ },
917
+ {
918
+ "name": "notes",
919
+ "type": "text",
920
+ "required": false,
921
+ "columnType": "TEXT",
922
+ "default": ""
923
+ },
924
+ {
925
+ "name": "currency",
926
+ "type": "text",
927
+ "required": false,
928
+ "columnType": "TEXT",
929
+ "default": "USD"
930
+ }
931
+ ],
932
+ "relationships": [],
933
+ "methods": [],
934
+ "tenant": {
935
+ "scoped": true,
936
+ "mode": "optional",
937
+ "field": "tenantId"
938
+ },
939
+ "conflictColumns": [
940
+ "product_id",
941
+ "version",
942
+ "tenant_id"
943
+ ],
944
+ "surfaces": [
945
+ {
946
+ "kind": "api",
947
+ "name": "billofmaterialses.list",
948
+ "operation": "list",
949
+ "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterials",
950
+ "path": "/billofmaterialses",
951
+ "method": "GET"
952
+ },
953
+ {
954
+ "kind": "api",
955
+ "name": "billofmaterialses.get",
956
+ "operation": "get",
957
+ "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterials",
958
+ "path": "/billofmaterialses/[id]",
959
+ "method": "GET"
960
+ },
961
+ {
962
+ "kind": "api",
963
+ "name": "billofmaterialses.create",
964
+ "operation": "create",
965
+ "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterials",
966
+ "path": "/billofmaterialses",
967
+ "method": "POST"
968
+ },
969
+ {
970
+ "kind": "api",
971
+ "name": "billofmaterialses.update",
972
+ "operation": "update",
973
+ "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterials",
974
+ "path": "/billofmaterialses/[id]",
975
+ "method": "PATCH"
976
+ },
977
+ {
978
+ "kind": "cli",
979
+ "name": "billofmaterials_list",
980
+ "operation": "list",
981
+ "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterials"
982
+ },
983
+ {
984
+ "kind": "cli",
985
+ "name": "billofmaterials_get",
986
+ "operation": "get",
987
+ "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterials"
988
+ },
989
+ {
990
+ "kind": "cli",
991
+ "name": "billofmaterials_create",
992
+ "operation": "create",
993
+ "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterials"
994
+ },
995
+ {
996
+ "kind": "cli",
997
+ "name": "billofmaterials_update",
998
+ "operation": "update",
999
+ "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterials"
1000
+ },
1001
+ {
1002
+ "kind": "cli",
1003
+ "name": "billofmaterials_delete",
1004
+ "operation": "delete",
1005
+ "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterials"
1006
+ },
1007
+ {
1008
+ "kind": "mcp",
1009
+ "name": "billofmaterials_list",
1010
+ "operation": "list",
1011
+ "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterials"
1012
+ },
1013
+ {
1014
+ "kind": "mcp",
1015
+ "name": "billofmaterials_get",
1016
+ "operation": "get",
1017
+ "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterials"
1018
+ }
1019
+ ],
1020
+ "relationshipFeatures": [
1021
+ "uuidColumns"
1022
+ ],
1023
+ "tags": [],
1024
+ "risks": []
1025
+ },
1026
+ {
1027
+ "name": "BomLine",
1028
+ "qualifiedName": "@happyvertical/smrt-manufacturing:BomLine",
1029
+ "collection": "bomlines",
1030
+ "tableName": "manufacturing_bom_lines",
1031
+ "packageName": "@happyvertical/smrt-manufacturing",
1032
+ "extends": "SmrtObject",
1033
+ "fields": [
1034
+ {
1035
+ "name": "tenantId",
1036
+ "type": "text",
1037
+ "required": false,
1038
+ "columnType": "UUID"
1039
+ },
1040
+ {
1041
+ "name": "bomId",
1042
+ "type": "text",
1043
+ "required": true,
1044
+ "columnType": "TEXT",
1045
+ "default": ""
1046
+ },
1047
+ {
1048
+ "name": "componentSkuId",
1049
+ "type": "text",
1050
+ "required": true,
1051
+ "columnType": "TEXT",
1052
+ "default": ""
1053
+ },
1054
+ {
1055
+ "name": "qtyPerUnit",
1056
+ "type": "decimal",
1057
+ "required": false,
1058
+ "columnType": "REAL"
1059
+ },
1060
+ {
1061
+ "name": "uom",
1062
+ "type": "text",
1063
+ "required": false,
1064
+ "columnType": "TEXT",
1065
+ "default": "each"
1066
+ },
1067
+ {
1068
+ "name": "wastePercent",
1069
+ "type": "decimal",
1070
+ "required": false,
1071
+ "columnType": "REAL"
1072
+ },
1073
+ {
1074
+ "name": "notes",
1075
+ "type": "text",
1076
+ "required": false,
1077
+ "columnType": "TEXT",
1078
+ "default": ""
1079
+ }
1080
+ ],
1081
+ "relationships": [],
1082
+ "methods": [
1083
+ "effectiveQtyPerUnit"
1084
+ ],
1085
+ "methodSignatures": [
1086
+ {
1087
+ "name": "effectiveQtyPerUnit",
1088
+ "returns": "number"
1089
+ }
1090
+ ],
1091
+ "tenant": {
1092
+ "scoped": true,
1093
+ "mode": "optional",
1094
+ "field": "tenantId"
1095
+ },
1096
+ "conflictColumns": [
1097
+ "bom_id",
1098
+ "component_sku_id",
1099
+ "tenant_id"
1100
+ ],
1101
+ "surfaces": [
1102
+ {
1103
+ "kind": "api",
1104
+ "name": "bomlines.list",
1105
+ "operation": "list",
1106
+ "objectName": "@happyvertical/smrt-manufacturing:BomLine",
1107
+ "path": "/bomlines",
1108
+ "method": "GET"
1109
+ },
1110
+ {
1111
+ "kind": "api",
1112
+ "name": "bomlines.get",
1113
+ "operation": "get",
1114
+ "objectName": "@happyvertical/smrt-manufacturing:BomLine",
1115
+ "path": "/bomlines/[id]",
1116
+ "method": "GET"
1117
+ },
1118
+ {
1119
+ "kind": "api",
1120
+ "name": "bomlines.create",
1121
+ "operation": "create",
1122
+ "objectName": "@happyvertical/smrt-manufacturing:BomLine",
1123
+ "path": "/bomlines",
1124
+ "method": "POST"
1125
+ },
1126
+ {
1127
+ "kind": "api",
1128
+ "name": "bomlines.update",
1129
+ "operation": "update",
1130
+ "objectName": "@happyvertical/smrt-manufacturing:BomLine",
1131
+ "path": "/bomlines/[id]",
1132
+ "method": "PATCH"
1133
+ },
1134
+ {
1135
+ "kind": "cli",
1136
+ "name": "bomline_list",
1137
+ "operation": "list",
1138
+ "objectName": "@happyvertical/smrt-manufacturing:BomLine"
1139
+ },
1140
+ {
1141
+ "kind": "cli",
1142
+ "name": "bomline_get",
1143
+ "operation": "get",
1144
+ "objectName": "@happyvertical/smrt-manufacturing:BomLine"
1145
+ },
1146
+ {
1147
+ "kind": "cli",
1148
+ "name": "bomline_create",
1149
+ "operation": "create",
1150
+ "objectName": "@happyvertical/smrt-manufacturing:BomLine"
1151
+ },
1152
+ {
1153
+ "kind": "cli",
1154
+ "name": "bomline_update",
1155
+ "operation": "update",
1156
+ "objectName": "@happyvertical/smrt-manufacturing:BomLine"
1157
+ },
1158
+ {
1159
+ "kind": "cli",
1160
+ "name": "bomline_delete",
1161
+ "operation": "delete",
1162
+ "objectName": "@happyvertical/smrt-manufacturing:BomLine"
1163
+ },
1164
+ {
1165
+ "kind": "cli",
1166
+ "name": "bomline_effectiveQtyPerUnit",
1167
+ "operation": "effectiveQtyPerUnit",
1168
+ "objectName": "@happyvertical/smrt-manufacturing:BomLine"
1169
+ },
1170
+ {
1171
+ "kind": "mcp",
1172
+ "name": "bomline_list",
1173
+ "operation": "list",
1174
+ "objectName": "@happyvertical/smrt-manufacturing:BomLine"
1175
+ },
1176
+ {
1177
+ "kind": "mcp",
1178
+ "name": "bomline_get",
1179
+ "operation": "get",
1180
+ "objectName": "@happyvertical/smrt-manufacturing:BomLine"
1181
+ }
1182
+ ],
1183
+ "withheldSurfaces": [
1184
+ {
1185
+ "kind": "api",
1186
+ "operation": "effectiveQtyPerUnit",
1187
+ "code": "not-included",
1188
+ "reason": "not listed in api.include",
1189
+ "objectName": "@happyvertical/smrt-manufacturing:BomLine"
1190
+ }
1191
+ ],
1192
+ "relationshipFeatures": [
1193
+ "uuidColumns"
1194
+ ],
1195
+ "tags": [],
1196
+ "risks": []
1197
+ },
1198
+ {
1199
+ "name": "Operation",
1200
+ "qualifiedName": "@happyvertical/smrt-manufacturing:Operation",
1201
+ "collection": "operations",
1202
+ "tableName": "manufacturing_operations",
1203
+ "packageName": "@happyvertical/smrt-manufacturing",
1204
+ "extends": "SmrtObject",
1205
+ "fields": [
1206
+ {
1207
+ "name": "tenantId",
1208
+ "type": "text",
1209
+ "required": false,
1210
+ "columnType": "UUID"
1211
+ },
1212
+ {
1213
+ "name": "code",
257
1214
  "type": "text",
258
1215
  "required": true,
259
1216
  "columnType": "TEXT",
260
1217
  "default": ""
261
1218
  },
262
1219
  {
263
- "name": "version",
264
- "type": "integer",
1220
+ "name": "name",
1221
+ "type": "text",
265
1222
  "required": true,
266
- "columnType": "INTEGER",
267
- "default": 1
1223
+ "columnType": "TEXT",
1224
+ "default": ""
268
1225
  },
269
1226
  {
270
- "name": "effectiveDate",
271
- "type": "datetime",
1227
+ "name": "category",
1228
+ "type": "text",
272
1229
  "required": false,
273
- "columnType": "TIMESTAMP"
1230
+ "columnType": "TEXT",
1231
+ "default": ""
1232
+ },
1233
+ {
1234
+ "name": "isActive",
1235
+ "type": "boolean",
1236
+ "required": false,
1237
+ "columnType": "BOOLEAN",
1238
+ "default": true
1239
+ },
1240
+ {
1241
+ "name": "requiredQualificationId",
1242
+ "type": "crossPackageRef",
1243
+ "required": false,
1244
+ "related": "@happyvertical/smrt-human-resources:Qualification",
1245
+ "columnType": "UUID"
1246
+ }
1247
+ ],
1248
+ "relationships": [
1249
+ {
1250
+ "name": "requiredQualificationId",
1251
+ "type": "crossPackageRef",
1252
+ "required": false,
1253
+ "related": "@happyvertical/smrt-human-resources:Qualification",
1254
+ "columnType": "UUID"
1255
+ }
1256
+ ],
1257
+ "methods": [
1258
+ "delete"
1259
+ ],
1260
+ "methodSignatures": [
1261
+ {
1262
+ "name": "delete",
1263
+ "async": true,
1264
+ "returns": "Promise<void>"
1265
+ }
1266
+ ],
1267
+ "tenant": {
1268
+ "scoped": true,
1269
+ "mode": "optional",
1270
+ "field": "tenantId"
1271
+ },
1272
+ "conflictColumns": [
1273
+ "code",
1274
+ "tenant_id"
1275
+ ],
1276
+ "surfaces": [
1277
+ {
1278
+ "kind": "api",
1279
+ "name": "operations.list",
1280
+ "operation": "list",
1281
+ "objectName": "@happyvertical/smrt-manufacturing:Operation",
1282
+ "path": "/operations",
1283
+ "method": "GET"
1284
+ },
1285
+ {
1286
+ "kind": "api",
1287
+ "name": "operations.get",
1288
+ "operation": "get",
1289
+ "objectName": "@happyvertical/smrt-manufacturing:Operation",
1290
+ "path": "/operations/[id]",
1291
+ "method": "GET"
1292
+ },
1293
+ {
1294
+ "kind": "cli",
1295
+ "name": "operation_list",
1296
+ "operation": "list",
1297
+ "objectName": "@happyvertical/smrt-manufacturing:Operation"
1298
+ },
1299
+ {
1300
+ "kind": "cli",
1301
+ "name": "operation_get",
1302
+ "operation": "get",
1303
+ "objectName": "@happyvertical/smrt-manufacturing:Operation"
1304
+ },
1305
+ {
1306
+ "kind": "mcp",
1307
+ "name": "operation_list",
1308
+ "operation": "list",
1309
+ "objectName": "@happyvertical/smrt-manufacturing:Operation"
1310
+ },
1311
+ {
1312
+ "kind": "mcp",
1313
+ "name": "operation_get",
1314
+ "operation": "get",
1315
+ "objectName": "@happyvertical/smrt-manufacturing:Operation"
1316
+ }
1317
+ ],
1318
+ "relationshipFeatures": [
1319
+ "crossPackageRef",
1320
+ "uuidColumns"
1321
+ ],
1322
+ "tags": [],
1323
+ "risks": []
1324
+ },
1325
+ {
1326
+ "name": "ProductionRun",
1327
+ "qualifiedName": "@happyvertical/smrt-manufacturing:ProductionRun",
1328
+ "collection": "productionruns",
1329
+ "tableName": "manufacturing_production_runs",
1330
+ "packageName": "@happyvertical/smrt-manufacturing",
1331
+ "extends": "SmrtObject",
1332
+ "fields": [
1333
+ {
1334
+ "name": "tenantId",
1335
+ "type": "text",
1336
+ "required": false,
1337
+ "columnType": "UUID"
1338
+ },
1339
+ {
1340
+ "name": "bomId",
1341
+ "type": "foreignKey",
1342
+ "required": true,
1343
+ "related": "BillOfMaterials",
1344
+ "columnType": "UUID"
1345
+ },
1346
+ {
1347
+ "name": "targetQty",
1348
+ "type": "decimal",
1349
+ "required": false,
1350
+ "columnType": "REAL"
1351
+ },
1352
+ {
1353
+ "name": "completedQty",
1354
+ "type": "decimal",
1355
+ "required": false,
1356
+ "columnType": "REAL"
274
1357
  },
275
1358
  {
276
1359
  "name": "status",
277
1360
  "type": "text",
278
1361
  "required": true,
279
1362
  "columnType": "TEXT",
280
- "default": "draft"
1363
+ "default": "planned"
1364
+ }
1365
+ ],
1366
+ "relationships": [
1367
+ {
1368
+ "name": "bomId",
1369
+ "type": "foreignKey",
1370
+ "required": true,
1371
+ "related": "BillOfMaterials",
1372
+ "columnType": "UUID"
1373
+ }
1374
+ ],
1375
+ "methods": [
1376
+ "remainingQty"
1377
+ ],
1378
+ "methodSignatures": [
1379
+ {
1380
+ "name": "remainingQty",
1381
+ "returns": "number"
1382
+ }
1383
+ ],
1384
+ "tenant": {
1385
+ "scoped": true,
1386
+ "mode": "optional",
1387
+ "field": "tenantId"
1388
+ },
1389
+ "conflictColumns": [
1390
+ "tenant_id",
1391
+ "slug",
1392
+ "context"
1393
+ ],
1394
+ "surfaces": [
1395
+ {
1396
+ "kind": "api",
1397
+ "name": "productionruns.list",
1398
+ "operation": "list",
1399
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRun",
1400
+ "path": "/productionruns",
1401
+ "method": "GET"
281
1402
  },
282
1403
  {
283
- "name": "notes",
1404
+ "kind": "api",
1405
+ "name": "productionruns.get",
1406
+ "operation": "get",
1407
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRun",
1408
+ "path": "/productionruns/[id]",
1409
+ "method": "GET"
1410
+ },
1411
+ {
1412
+ "kind": "cli",
1413
+ "name": "productionrun_list",
1414
+ "operation": "list",
1415
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRun"
1416
+ },
1417
+ {
1418
+ "kind": "cli",
1419
+ "name": "productionrun_get",
1420
+ "operation": "get",
1421
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRun"
1422
+ },
1423
+ {
1424
+ "kind": "mcp",
1425
+ "name": "productionrun_list",
1426
+ "operation": "list",
1427
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRun"
1428
+ },
1429
+ {
1430
+ "kind": "mcp",
1431
+ "name": "productionrun_get",
1432
+ "operation": "get",
1433
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRun"
1434
+ }
1435
+ ],
1436
+ "withheldSurfaces": [
1437
+ {
1438
+ "kind": "api",
1439
+ "operation": "remainingQty",
1440
+ "code": "not-included",
1441
+ "reason": "not listed in api.include",
1442
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRun"
1443
+ }
1444
+ ],
1445
+ "relationshipFeatures": [
1446
+ "foreignKey",
1447
+ "uuidColumns"
1448
+ ],
1449
+ "tags": [],
1450
+ "risks": []
1451
+ },
1452
+ {
1453
+ "name": "ProductionRunCompletion",
1454
+ "qualifiedName": "@happyvertical/smrt-manufacturing:ProductionRunCompletion",
1455
+ "collection": "productionruncompletions",
1456
+ "tableName": "manufacturing_production_run_completions",
1457
+ "packageName": "@happyvertical/smrt-manufacturing",
1458
+ "extends": "SmrtObject",
1459
+ "fields": [
1460
+ {
1461
+ "name": "tenantId",
284
1462
  "type": "text",
285
1463
  "required": false,
286
- "columnType": "TEXT",
287
- "default": ""
1464
+ "columnType": "UUID"
288
1465
  },
289
1466
  {
290
- "name": "currency",
291
- "type": "text",
1467
+ "name": "runId",
1468
+ "type": "foreignKey",
1469
+ "required": true,
1470
+ "related": "ProductionRun",
1471
+ "columnType": "UUID"
1472
+ },
1473
+ {
1474
+ "name": "qty",
1475
+ "type": "decimal",
1476
+ "required": false,
1477
+ "columnType": "REAL"
1478
+ },
1479
+ {
1480
+ "name": "completedAt",
1481
+ "type": "datetime",
292
1482
  "required": false,
293
- "columnType": "TEXT",
294
- "default": "USD"
1483
+ "columnType": "TIMESTAMP"
1484
+ }
1485
+ ],
1486
+ "relationships": [
1487
+ {
1488
+ "name": "runId",
1489
+ "type": "foreignKey",
1490
+ "required": true,
1491
+ "related": "ProductionRun",
1492
+ "columnType": "UUID"
295
1493
  }
296
1494
  ],
297
- "relationships": [],
298
1495
  "methods": [],
299
1496
  "tenant": {
300
1497
  "scoped": true,
@@ -302,97 +1499,64 @@
302
1499
  "field": "tenantId"
303
1500
  },
304
1501
  "conflictColumns": [
305
- "product_id",
306
- "version",
307
- "tenant_id"
1502
+ "tenant_id",
1503
+ "slug",
1504
+ "context"
308
1505
  ],
309
1506
  "surfaces": [
310
1507
  {
311
1508
  "kind": "api",
312
- "name": "billofmaterialses.list",
1509
+ "name": "productionruncompletions.list",
313
1510
  "operation": "list",
314
- "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterials",
315
- "path": "/billofmaterialses",
1511
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCompletion",
1512
+ "path": "/productionruncompletions",
316
1513
  "method": "GET"
317
1514
  },
318
1515
  {
319
1516
  "kind": "api",
320
- "name": "billofmaterialses.get",
1517
+ "name": "productionruncompletions.get",
321
1518
  "operation": "get",
322
- "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterials",
323
- "path": "/billofmaterialses/[id]",
1519
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCompletion",
1520
+ "path": "/productionruncompletions/[id]",
324
1521
  "method": "GET"
325
1522
  },
326
- {
327
- "kind": "api",
328
- "name": "billofmaterialses.create",
329
- "operation": "create",
330
- "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterials",
331
- "path": "/billofmaterialses",
332
- "method": "POST"
333
- },
334
- {
335
- "kind": "api",
336
- "name": "billofmaterialses.update",
337
- "operation": "update",
338
- "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterials",
339
- "path": "/billofmaterialses/[id]",
340
- "method": "PATCH"
341
- },
342
1523
  {
343
1524
  "kind": "cli",
344
- "name": "billofmaterials_list",
1525
+ "name": "productionruncompletion_list",
345
1526
  "operation": "list",
346
- "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterials"
1527
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCompletion"
347
1528
  },
348
1529
  {
349
1530
  "kind": "cli",
350
- "name": "billofmaterials_get",
1531
+ "name": "productionruncompletion_get",
351
1532
  "operation": "get",
352
- "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterials"
353
- },
354
- {
355
- "kind": "cli",
356
- "name": "billofmaterials_create",
357
- "operation": "create",
358
- "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterials"
359
- },
360
- {
361
- "kind": "cli",
362
- "name": "billofmaterials_update",
363
- "operation": "update",
364
- "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterials"
365
- },
366
- {
367
- "kind": "cli",
368
- "name": "billofmaterials_delete",
369
- "operation": "delete",
370
- "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterials"
1533
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCompletion"
371
1534
  },
372
1535
  {
373
1536
  "kind": "mcp",
374
- "name": "billofmaterials_list",
1537
+ "name": "productionruncompletion_list",
375
1538
  "operation": "list",
376
- "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterials"
1539
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCompletion"
377
1540
  },
378
1541
  {
379
1542
  "kind": "mcp",
380
- "name": "billofmaterials_get",
1543
+ "name": "productionruncompletion_get",
381
1544
  "operation": "get",
382
- "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterials"
1545
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCompletion"
383
1546
  }
384
1547
  ],
385
1548
  "relationshipFeatures": [
1549
+ "foreignKey",
386
1550
  "uuidColumns"
387
1551
  ],
388
1552
  "tags": [],
389
1553
  "risks": []
390
1554
  },
391
1555
  {
392
- "name": "BomLine",
393
- "qualifiedName": "@happyvertical/smrt-manufacturing:BomLine",
394
- "collection": "bomlines",
395
- "tableName": "manufacturing_bom_lines",
1556
+ "name": "RoutingStep",
1557
+ "qualifiedName": "@happyvertical/smrt-manufacturing:RoutingStep",
1558
+ "collection": "routingsteps",
1559
+ "tableName": "manufacturing_routing_steps",
396
1560
  "packageName": "@happyvertical/smrt-manufacturing",
397
1561
  "extends": "SmrtObject",
398
1562
  "fields": [
@@ -404,33 +1568,27 @@
404
1568
  },
405
1569
  {
406
1570
  "name": "bomId",
407
- "type": "text",
1571
+ "type": "foreignKey",
408
1572
  "required": true,
409
- "columnType": "TEXT",
410
- "default": ""
1573
+ "related": "BillOfMaterials",
1574
+ "columnType": "UUID"
411
1575
  },
412
1576
  {
413
- "name": "componentSkuId",
414
- "type": "text",
1577
+ "name": "operationId",
1578
+ "type": "foreignKey",
415
1579
  "required": true,
416
- "columnType": "TEXT",
417
- "default": ""
418
- },
419
- {
420
- "name": "qtyPerUnit",
421
- "type": "decimal",
422
- "required": false,
423
- "columnType": "REAL"
1580
+ "related": "Operation",
1581
+ "columnType": "UUID"
424
1582
  },
425
1583
  {
426
- "name": "uom",
427
- "type": "text",
428
- "required": false,
429
- "columnType": "TEXT",
430
- "default": "each"
1584
+ "name": "sequence",
1585
+ "type": "integer",
1586
+ "required": true,
1587
+ "columnType": "INTEGER",
1588
+ "default": 1
431
1589
  },
432
1590
  {
433
- "name": "wastePercent",
1591
+ "name": "estimatedMinutes",
434
1592
  "type": "decimal",
435
1593
  "required": false,
436
1594
  "columnType": "REAL"
@@ -443,16 +1601,23 @@
443
1601
  "default": ""
444
1602
  }
445
1603
  ],
446
- "relationships": [],
447
- "methods": [
448
- "effectiveQtyPerUnit"
449
- ],
450
- "methodSignatures": [
1604
+ "relationships": [
451
1605
  {
452
- "name": "effectiveQtyPerUnit",
453
- "returns": "number"
1606
+ "name": "bomId",
1607
+ "type": "foreignKey",
1608
+ "required": true,
1609
+ "related": "BillOfMaterials",
1610
+ "columnType": "UUID"
1611
+ },
1612
+ {
1613
+ "name": "operationId",
1614
+ "type": "foreignKey",
1615
+ "required": true,
1616
+ "related": "Operation",
1617
+ "columnType": "UUID"
454
1618
  }
455
1619
  ],
1620
+ "methods": [],
456
1621
  "tenant": {
457
1622
  "scoped": true,
458
1623
  "mode": "optional",
@@ -460,101 +1625,71 @@
460
1625
  },
461
1626
  "conflictColumns": [
462
1627
  "bom_id",
463
- "component_sku_id",
1628
+ "sequence",
464
1629
  "tenant_id"
465
1630
  ],
466
1631
  "surfaces": [
467
1632
  {
468
1633
  "kind": "api",
469
- "name": "bomlines.list",
1634
+ "name": "routingsteps.list",
470
1635
  "operation": "list",
471
- "objectName": "@happyvertical/smrt-manufacturing:BomLine",
472
- "path": "/bomlines",
1636
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStep",
1637
+ "path": "/routingsteps",
473
1638
  "method": "GET"
474
1639
  },
475
1640
  {
476
1641
  "kind": "api",
477
- "name": "bomlines.get",
1642
+ "name": "routingsteps.get",
478
1643
  "operation": "get",
479
- "objectName": "@happyvertical/smrt-manufacturing:BomLine",
480
- "path": "/bomlines/[id]",
1644
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStep",
1645
+ "path": "/routingsteps/[id]",
481
1646
  "method": "GET"
482
1647
  },
483
- {
484
- "kind": "api",
485
- "name": "bomlines.create",
486
- "operation": "create",
487
- "objectName": "@happyvertical/smrt-manufacturing:BomLine",
488
- "path": "/bomlines",
489
- "method": "POST"
490
- },
491
- {
492
- "kind": "api",
493
- "name": "bomlines.update",
494
- "operation": "update",
495
- "objectName": "@happyvertical/smrt-manufacturing:BomLine",
496
- "path": "/bomlines/[id]",
497
- "method": "PATCH"
498
- },
499
1648
  {
500
1649
  "kind": "cli",
501
- "name": "bomline_list",
1650
+ "name": "routingstep_list",
502
1651
  "operation": "list",
503
- "objectName": "@happyvertical/smrt-manufacturing:BomLine"
1652
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStep"
504
1653
  },
505
1654
  {
506
1655
  "kind": "cli",
507
- "name": "bomline_get",
1656
+ "name": "routingstep_get",
508
1657
  "operation": "get",
509
- "objectName": "@happyvertical/smrt-manufacturing:BomLine"
1658
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStep"
510
1659
  },
511
1660
  {
512
1661
  "kind": "cli",
513
- "name": "bomline_create",
1662
+ "name": "routingstep_create",
514
1663
  "operation": "create",
515
- "objectName": "@happyvertical/smrt-manufacturing:BomLine"
1664
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStep"
516
1665
  },
517
1666
  {
518
1667
  "kind": "cli",
519
- "name": "bomline_update",
1668
+ "name": "routingstep_update",
520
1669
  "operation": "update",
521
- "objectName": "@happyvertical/smrt-manufacturing:BomLine"
1670
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStep"
522
1671
  },
523
1672
  {
524
1673
  "kind": "cli",
525
- "name": "bomline_delete",
1674
+ "name": "routingstep_delete",
526
1675
  "operation": "delete",
527
- "objectName": "@happyvertical/smrt-manufacturing:BomLine"
528
- },
529
- {
530
- "kind": "cli",
531
- "name": "bomline_effectiveQtyPerUnit",
532
- "operation": "effectiveQtyPerUnit",
533
- "objectName": "@happyvertical/smrt-manufacturing:BomLine"
1676
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStep"
534
1677
  },
535
1678
  {
536
1679
  "kind": "mcp",
537
- "name": "bomline_list",
1680
+ "name": "routingstep_list",
538
1681
  "operation": "list",
539
- "objectName": "@happyvertical/smrt-manufacturing:BomLine"
1682
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStep"
540
1683
  },
541
1684
  {
542
1685
  "kind": "mcp",
543
- "name": "bomline_get",
1686
+ "name": "routingstep_get",
544
1687
  "operation": "get",
545
- "objectName": "@happyvertical/smrt-manufacturing:BomLine"
546
- }
547
- ],
548
- "withheldSurfaces": [
549
- {
550
- "kind": "api",
551
- "operation": "effectiveQtyPerUnit",
552
- "code": "not-included",
553
- "reason": "not listed in api.include",
554
- "objectName": "@happyvertical/smrt-manufacturing:BomLine"
1688
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStep"
555
1689
  }
556
1690
  ],
557
1691
  "relationshipFeatures": [
1692
+ "foreignKey",
558
1693
  "uuidColumns"
559
1694
  ],
560
1695
  "tags": [],
@@ -564,103 +1699,347 @@
564
1699
  "surfaces": [
565
1700
  {
566
1701
  "kind": "api",
567
- "name": "billofmaterialses.findByProduct",
568
- "operation": "findByProduct",
569
- "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterialsCollection",
570
- "path": "/billofmaterialses/findByProduct",
1702
+ "name": "billofmaterialses.findByProduct",
1703
+ "operation": "findByProduct",
1704
+ "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterialsCollection",
1705
+ "path": "/billofmaterialses/findByProduct",
1706
+ "method": "POST"
1707
+ },
1708
+ {
1709
+ "kind": "api",
1710
+ "name": "billofmaterialses.findActiveForProduct",
1711
+ "operation": "findActiveForProduct",
1712
+ "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterialsCollection",
1713
+ "path": "/billofmaterialses/findActiveForProduct",
1714
+ "method": "POST"
1715
+ },
1716
+ {
1717
+ "kind": "api",
1718
+ "name": "billofmaterialses.findByStatus",
1719
+ "operation": "findByStatus",
1720
+ "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterialsCollection",
1721
+ "path": "/billofmaterialses/findByStatus",
1722
+ "method": "POST"
1723
+ },
1724
+ {
1725
+ "kind": "cli",
1726
+ "name": "billofmaterialscollection_findByProduct",
1727
+ "operation": "findByProduct",
1728
+ "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterialsCollection"
1729
+ },
1730
+ {
1731
+ "kind": "cli",
1732
+ "name": "billofmaterialscollection_findActiveForProduct",
1733
+ "operation": "findActiveForProduct",
1734
+ "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterialsCollection"
1735
+ },
1736
+ {
1737
+ "kind": "cli",
1738
+ "name": "billofmaterialscollection_findByStatus",
1739
+ "operation": "findByStatus",
1740
+ "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterialsCollection"
1741
+ },
1742
+ {
1743
+ "kind": "mcp",
1744
+ "name": "billofmaterialscollection_findbyproduct",
1745
+ "operation": "findByProduct",
1746
+ "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterialsCollection"
1747
+ },
1748
+ {
1749
+ "kind": "mcp",
1750
+ "name": "billofmaterialscollection_findactiveforproduct",
1751
+ "operation": "findActiveForProduct",
1752
+ "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterialsCollection"
1753
+ },
1754
+ {
1755
+ "kind": "mcp",
1756
+ "name": "billofmaterialscollection_findbystatus",
1757
+ "operation": "findByStatus",
1758
+ "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterialsCollection"
1759
+ },
1760
+ {
1761
+ "kind": "api",
1762
+ "name": "bomlines.findByBom",
1763
+ "operation": "findByBom",
1764
+ "objectName": "@happyvertical/smrt-manufacturing:BomLineCollection",
1765
+ "path": "/bomlines/findByBom",
1766
+ "method": "POST"
1767
+ },
1768
+ {
1769
+ "kind": "api",
1770
+ "name": "bomlines.findByComponent",
1771
+ "operation": "findByComponent",
1772
+ "objectName": "@happyvertical/smrt-manufacturing:BomLineCollection",
1773
+ "path": "/bomlines/findByComponent",
1774
+ "method": "POST"
1775
+ },
1776
+ {
1777
+ "kind": "cli",
1778
+ "name": "bomlinecollection_findByBom",
1779
+ "operation": "findByBom",
1780
+ "objectName": "@happyvertical/smrt-manufacturing:BomLineCollection"
1781
+ },
1782
+ {
1783
+ "kind": "cli",
1784
+ "name": "bomlinecollection_findByComponent",
1785
+ "operation": "findByComponent",
1786
+ "objectName": "@happyvertical/smrt-manufacturing:BomLineCollection"
1787
+ },
1788
+ {
1789
+ "kind": "mcp",
1790
+ "name": "bomlinecollection_findbybom",
1791
+ "operation": "findByBom",
1792
+ "objectName": "@happyvertical/smrt-manufacturing:BomLineCollection"
1793
+ },
1794
+ {
1795
+ "kind": "mcp",
1796
+ "name": "bomlinecollection_findbycomponent",
1797
+ "operation": "findByComponent",
1798
+ "objectName": "@happyvertical/smrt-manufacturing:BomLineCollection"
1799
+ },
1800
+ {
1801
+ "kind": "api",
1802
+ "name": "operations.findByCode",
1803
+ "operation": "findByCode",
1804
+ "objectName": "@happyvertical/smrt-manufacturing:OperationCollection",
1805
+ "path": "/operations/findByCode",
571
1806
  "method": "POST"
572
1807
  },
573
1808
  {
574
1809
  "kind": "api",
575
- "name": "billofmaterialses.findActiveForProduct",
576
- "operation": "findActiveForProduct",
577
- "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterialsCollection",
578
- "path": "/billofmaterialses/findActiveForProduct",
1810
+ "name": "operations.listOperations",
1811
+ "operation": "listOperations",
1812
+ "objectName": "@happyvertical/smrt-manufacturing:OperationCollection",
1813
+ "path": "/operations/listOperations",
579
1814
  "method": "POST"
580
1815
  },
1816
+ {
1817
+ "kind": "cli",
1818
+ "name": "operationcollection_findByCode",
1819
+ "operation": "findByCode",
1820
+ "objectName": "@happyvertical/smrt-manufacturing:OperationCollection"
1821
+ },
1822
+ {
1823
+ "kind": "cli",
1824
+ "name": "operationcollection_listOperations",
1825
+ "operation": "listOperations",
1826
+ "objectName": "@happyvertical/smrt-manufacturing:OperationCollection"
1827
+ },
1828
+ {
1829
+ "kind": "mcp",
1830
+ "name": "operationcollection_findbycode",
1831
+ "operation": "findByCode",
1832
+ "objectName": "@happyvertical/smrt-manufacturing:OperationCollection"
1833
+ },
1834
+ {
1835
+ "kind": "mcp",
1836
+ "name": "operationcollection_listoperations",
1837
+ "operation": "listOperations",
1838
+ "objectName": "@happyvertical/smrt-manufacturing:OperationCollection"
1839
+ },
581
1840
  {
582
1841
  "kind": "api",
583
- "name": "billofmaterialses.findByStatus",
584
- "operation": "findByStatus",
585
- "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterialsCollection",
586
- "path": "/billofmaterialses/findByStatus",
1842
+ "name": "productionruns.findByBom",
1843
+ "operation": "findByBom",
1844
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCollection",
1845
+ "path": "/productionruns/findByBom",
587
1846
  "method": "POST"
588
1847
  },
589
1848
  {
590
- "kind": "cli",
591
- "name": "billofmaterialscollection_findByProduct",
592
- "operation": "findByProduct",
593
- "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterialsCollection"
1849
+ "kind": "api",
1850
+ "name": "productionruns.findByStatus",
1851
+ "operation": "findByStatus",
1852
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCollection",
1853
+ "path": "/productionruns/findByStatus",
1854
+ "method": "POST"
594
1855
  },
595
1856
  {
596
1857
  "kind": "cli",
597
- "name": "billofmaterialscollection_findActiveForProduct",
598
- "operation": "findActiveForProduct",
599
- "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterialsCollection"
1858
+ "name": "productionruncollection_findByBom",
1859
+ "operation": "findByBom",
1860
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCollection"
600
1861
  },
601
1862
  {
602
1863
  "kind": "cli",
603
- "name": "billofmaterialscollection_findByStatus",
1864
+ "name": "productionruncollection_findByStatus",
604
1865
  "operation": "findByStatus",
605
- "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterialsCollection"
1866
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCollection"
606
1867
  },
607
1868
  {
608
1869
  "kind": "mcp",
609
- "name": "billofmaterialscollection_findbyproduct",
610
- "operation": "findByProduct",
611
- "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterialsCollection"
1870
+ "name": "productionruncollection_findbybom",
1871
+ "operation": "findByBom",
1872
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCollection"
612
1873
  },
613
1874
  {
614
1875
  "kind": "mcp",
615
- "name": "billofmaterialscollection_findactiveforproduct",
616
- "operation": "findActiveForProduct",
617
- "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterialsCollection"
1876
+ "name": "productionruncollection_findbystatus",
1877
+ "operation": "findByStatus",
1878
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCollection"
1879
+ },
1880
+ {
1881
+ "kind": "api",
1882
+ "name": "productionruncompletions.findByRun",
1883
+ "operation": "findByRun",
1884
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCompletionCollection",
1885
+ "path": "/productionruncompletions/findByRun",
1886
+ "method": "POST"
1887
+ },
1888
+ {
1889
+ "kind": "cli",
1890
+ "name": "productionruncompletioncollection_findByRun",
1891
+ "operation": "findByRun",
1892
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCompletionCollection"
618
1893
  },
619
1894
  {
620
1895
  "kind": "mcp",
621
- "name": "billofmaterialscollection_findbystatus",
622
- "operation": "findByStatus",
623
- "objectName": "@happyvertical/smrt-manufacturing:BillOfMaterialsCollection"
1896
+ "name": "productionruncompletioncollection_findbyrun",
1897
+ "operation": "findByRun",
1898
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCompletionCollection"
624
1899
  },
625
1900
  {
626
1901
  "kind": "api",
627
- "name": "bomlines.findByBom",
1902
+ "name": "routingsteps.findByBom",
628
1903
  "operation": "findByBom",
629
- "objectName": "@happyvertical/smrt-manufacturing:BomLineCollection",
630
- "path": "/bomlines/findByBom",
1904
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStepCollection",
1905
+ "path": "/routingsteps/findByBom",
631
1906
  "method": "POST"
632
1907
  },
633
1908
  {
634
1909
  "kind": "api",
635
- "name": "bomlines.findByComponent",
636
- "operation": "findByComponent",
637
- "objectName": "@happyvertical/smrt-manufacturing:BomLineCollection",
638
- "path": "/bomlines/findByComponent",
1910
+ "name": "routingsteps.findByOperation",
1911
+ "operation": "findByOperation",
1912
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStepCollection",
1913
+ "path": "/routingsteps/findByOperation",
639
1914
  "method": "POST"
640
1915
  },
641
1916
  {
642
1917
  "kind": "cli",
643
- "name": "bomlinecollection_findByBom",
1918
+ "name": "routingstepcollection_findByBom",
644
1919
  "operation": "findByBom",
645
- "objectName": "@happyvertical/smrt-manufacturing:BomLineCollection"
1920
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStepCollection"
646
1921
  },
647
1922
  {
648
1923
  "kind": "cli",
649
- "name": "bomlinecollection_findByComponent",
650
- "operation": "findByComponent",
651
- "objectName": "@happyvertical/smrt-manufacturing:BomLineCollection"
1924
+ "name": "routingstepcollection_findByOperation",
1925
+ "operation": "findByOperation",
1926
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStepCollection"
652
1927
  },
653
1928
  {
654
1929
  "kind": "mcp",
655
- "name": "bomlinecollection_findbybom",
1930
+ "name": "routingstepcollection_findbybom",
656
1931
  "operation": "findByBom",
657
- "objectName": "@happyvertical/smrt-manufacturing:BomLineCollection"
1932
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStepCollection"
658
1933
  },
659
1934
  {
660
1935
  "kind": "mcp",
661
- "name": "bomlinecollection_findbycomponent",
662
- "operation": "findByComponent",
663
- "objectName": "@happyvertical/smrt-manufacturing:BomLineCollection"
1936
+ "name": "routingstepcollection_findbyoperation",
1937
+ "operation": "findByOperation",
1938
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStepCollection"
1939
+ },
1940
+ {
1941
+ "kind": "api",
1942
+ "name": "products.list",
1943
+ "operation": "list",
1944
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly",
1945
+ "path": "/products",
1946
+ "method": "GET"
1947
+ },
1948
+ {
1949
+ "kind": "api",
1950
+ "name": "products.get",
1951
+ "operation": "get",
1952
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly",
1953
+ "path": "/products/[id]",
1954
+ "method": "GET"
1955
+ },
1956
+ {
1957
+ "kind": "api",
1958
+ "name": "products.create",
1959
+ "operation": "create",
1960
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly",
1961
+ "path": "/products",
1962
+ "method": "POST"
1963
+ },
1964
+ {
1965
+ "kind": "api",
1966
+ "name": "products.update",
1967
+ "operation": "update",
1968
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly",
1969
+ "path": "/products/[id]",
1970
+ "method": "PATCH"
1971
+ },
1972
+ {
1973
+ "kind": "cli",
1974
+ "name": "assembly_list",
1975
+ "operation": "list",
1976
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
1977
+ },
1978
+ {
1979
+ "kind": "cli",
1980
+ "name": "assembly_get",
1981
+ "operation": "get",
1982
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
1983
+ },
1984
+ {
1985
+ "kind": "cli",
1986
+ "name": "assembly_create",
1987
+ "operation": "create",
1988
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
1989
+ },
1990
+ {
1991
+ "kind": "cli",
1992
+ "name": "assembly_update",
1993
+ "operation": "update",
1994
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
1995
+ },
1996
+ {
1997
+ "kind": "cli",
1998
+ "name": "assembly_delete",
1999
+ "operation": "delete",
2000
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
2001
+ },
2002
+ {
2003
+ "kind": "cli",
2004
+ "name": "assembly_getSpecification",
2005
+ "operation": "getSpecification",
2006
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
2007
+ },
2008
+ {
2009
+ "kind": "cli",
2010
+ "name": "assembly_updateSpecification",
2011
+ "operation": "updateSpecification",
2012
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
2013
+ },
2014
+ {
2015
+ "kind": "cli",
2016
+ "name": "assembly_getAssets",
2017
+ "operation": "getAssets",
2018
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
2019
+ },
2020
+ {
2021
+ "kind": "cli",
2022
+ "name": "assembly_addAsset",
2023
+ "operation": "addAsset",
2024
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
2025
+ },
2026
+ {
2027
+ "kind": "cli",
2028
+ "name": "assembly_removeAsset",
2029
+ "operation": "removeAsset",
2030
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
2031
+ },
2032
+ {
2033
+ "kind": "mcp",
2034
+ "name": "assembly_list",
2035
+ "operation": "list",
2036
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
2037
+ },
2038
+ {
2039
+ "kind": "mcp",
2040
+ "name": "assembly_get",
2041
+ "operation": "get",
2042
+ "objectName": "@happyvertical/smrt-manufacturing:Assembly"
664
2043
  },
665
2044
  {
666
2045
  "kind": "api",
@@ -815,16 +2194,201 @@
815
2194
  "name": "bomline_get",
816
2195
  "operation": "get",
817
2196
  "objectName": "@happyvertical/smrt-manufacturing:BomLine"
2197
+ },
2198
+ {
2199
+ "kind": "api",
2200
+ "name": "operations.list",
2201
+ "operation": "list",
2202
+ "objectName": "@happyvertical/smrt-manufacturing:Operation",
2203
+ "path": "/operations",
2204
+ "method": "GET"
2205
+ },
2206
+ {
2207
+ "kind": "api",
2208
+ "name": "operations.get",
2209
+ "operation": "get",
2210
+ "objectName": "@happyvertical/smrt-manufacturing:Operation",
2211
+ "path": "/operations/[id]",
2212
+ "method": "GET"
2213
+ },
2214
+ {
2215
+ "kind": "cli",
2216
+ "name": "operation_list",
2217
+ "operation": "list",
2218
+ "objectName": "@happyvertical/smrt-manufacturing:Operation"
2219
+ },
2220
+ {
2221
+ "kind": "cli",
2222
+ "name": "operation_get",
2223
+ "operation": "get",
2224
+ "objectName": "@happyvertical/smrt-manufacturing:Operation"
2225
+ },
2226
+ {
2227
+ "kind": "mcp",
2228
+ "name": "operation_list",
2229
+ "operation": "list",
2230
+ "objectName": "@happyvertical/smrt-manufacturing:Operation"
2231
+ },
2232
+ {
2233
+ "kind": "mcp",
2234
+ "name": "operation_get",
2235
+ "operation": "get",
2236
+ "objectName": "@happyvertical/smrt-manufacturing:Operation"
2237
+ },
2238
+ {
2239
+ "kind": "api",
2240
+ "name": "productionruns.list",
2241
+ "operation": "list",
2242
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRun",
2243
+ "path": "/productionruns",
2244
+ "method": "GET"
2245
+ },
2246
+ {
2247
+ "kind": "api",
2248
+ "name": "productionruns.get",
2249
+ "operation": "get",
2250
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRun",
2251
+ "path": "/productionruns/[id]",
2252
+ "method": "GET"
2253
+ },
2254
+ {
2255
+ "kind": "cli",
2256
+ "name": "productionrun_list",
2257
+ "operation": "list",
2258
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRun"
2259
+ },
2260
+ {
2261
+ "kind": "cli",
2262
+ "name": "productionrun_get",
2263
+ "operation": "get",
2264
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRun"
2265
+ },
2266
+ {
2267
+ "kind": "mcp",
2268
+ "name": "productionrun_list",
2269
+ "operation": "list",
2270
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRun"
2271
+ },
2272
+ {
2273
+ "kind": "mcp",
2274
+ "name": "productionrun_get",
2275
+ "operation": "get",
2276
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRun"
2277
+ },
2278
+ {
2279
+ "kind": "api",
2280
+ "name": "productionruncompletions.list",
2281
+ "operation": "list",
2282
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCompletion",
2283
+ "path": "/productionruncompletions",
2284
+ "method": "GET"
2285
+ },
2286
+ {
2287
+ "kind": "api",
2288
+ "name": "productionruncompletions.get",
2289
+ "operation": "get",
2290
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCompletion",
2291
+ "path": "/productionruncompletions/[id]",
2292
+ "method": "GET"
2293
+ },
2294
+ {
2295
+ "kind": "cli",
2296
+ "name": "productionruncompletion_list",
2297
+ "operation": "list",
2298
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCompletion"
2299
+ },
2300
+ {
2301
+ "kind": "cli",
2302
+ "name": "productionruncompletion_get",
2303
+ "operation": "get",
2304
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCompletion"
2305
+ },
2306
+ {
2307
+ "kind": "mcp",
2308
+ "name": "productionruncompletion_list",
2309
+ "operation": "list",
2310
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCompletion"
2311
+ },
2312
+ {
2313
+ "kind": "mcp",
2314
+ "name": "productionruncompletion_get",
2315
+ "operation": "get",
2316
+ "objectName": "@happyvertical/smrt-manufacturing:ProductionRunCompletion"
2317
+ },
2318
+ {
2319
+ "kind": "api",
2320
+ "name": "routingsteps.list",
2321
+ "operation": "list",
2322
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStep",
2323
+ "path": "/routingsteps",
2324
+ "method": "GET"
2325
+ },
2326
+ {
2327
+ "kind": "api",
2328
+ "name": "routingsteps.get",
2329
+ "operation": "get",
2330
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStep",
2331
+ "path": "/routingsteps/[id]",
2332
+ "method": "GET"
2333
+ },
2334
+ {
2335
+ "kind": "cli",
2336
+ "name": "routingstep_list",
2337
+ "operation": "list",
2338
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStep"
2339
+ },
2340
+ {
2341
+ "kind": "cli",
2342
+ "name": "routingstep_get",
2343
+ "operation": "get",
2344
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStep"
2345
+ },
2346
+ {
2347
+ "kind": "cli",
2348
+ "name": "routingstep_create",
2349
+ "operation": "create",
2350
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStep"
2351
+ },
2352
+ {
2353
+ "kind": "cli",
2354
+ "name": "routingstep_update",
2355
+ "operation": "update",
2356
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStep"
2357
+ },
2358
+ {
2359
+ "kind": "cli",
2360
+ "name": "routingstep_delete",
2361
+ "operation": "delete",
2362
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStep"
2363
+ },
2364
+ {
2365
+ "kind": "mcp",
2366
+ "name": "routingstep_list",
2367
+ "operation": "list",
2368
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStep"
2369
+ },
2370
+ {
2371
+ "kind": "mcp",
2372
+ "name": "routingstep_get",
2373
+ "operation": "get",
2374
+ "objectName": "@happyvertical/smrt-manufacturing:RoutingStep"
818
2375
  }
819
2376
  ],
820
2377
  "prompts": [],
821
2378
  "relationshipsV2": {
822
- "foreignKeyFields": 0,
823
- "crossPackageRefFields": 0,
2379
+ "foreignKeyFields": 5,
2380
+ "crossPackageRefFields": 1,
824
2381
  "junctionCollections": 0,
825
2382
  "hierarchicalObjects": 0,
826
2383
  "polymorphicAssociations": 0,
827
- "uuidColumns": 8
2384
+ "uuidColumns": 37
828
2385
  },
829
- "agentDoc": "# @happyvertical/smrt-manufacturing\n\nBills of materials, cost rollup, and production-order operations. Strictly industry-neutral — the same primitives serve apparel, furniture, automotive, CPG, electronics, food production, custom hardware, and any vertical that builds finished goods from a recipe.\n\nSits on top of `@happyvertical/smrt-inventory` (stock) and works alongside the `ProductionOrder` Contract STI subtype already shipped in `@happyvertical/smrt-commerce`.\n\n## Models\n\n| Model | Purpose |\n|---|---|\n| `BillOfMaterials` | Recipe for a finished product. `productId` (plain string) references the upstream `Product` or any STI subtype. Multiple revisions per product via `version` + `status` (`draft` / `active` / `superseded`). `conflictColumns: ['product_id', 'version', 'tenant_id']`. |\n| `BomLine` | One component on a BOM. `bomId` (FK), `componentSkuId` (plain string ref — the `Sku` model lives in `@happyvertical/smrt-products`; inventory tracks stock motion against the id), `qtyPerUnit`, `uom` (open-ended — `yards`, `each`, `grams`, `kg`, ...), `wastePercent`, `notes`. `conflictColumns: ['bom_id', 'component_sku_id', 'tenant_id']`. |\n\nBoth models are `@TenantScoped({ mode: 'optional' })` with a nullable `tenantId` so they can be used either tenant-scoped or globally.\n\n`RoutingStep` (labor cost) is intentionally out of scope for v1 — see issue [#1245](https://github.com/happyvertical/smrt/issues/1245) for the planned follow-up.\n\n## BomService — planning helpers\n\n```typescript\nimport { BomService } from '@happyvertical/smrt-manufacturing';\n\nconst bom = await BomService.create({\n db,\n // Optional. Resolve unit cost for a component SKU.\n // Without this, every line rolls up to $0 and `costUnavailable` is set.\n costResolver: async (componentSkuId) => fetchLatestCost(componentSkuId),\n});\n\nconst rollup = await bom.computeMaterialCost(bomId);\n// { totalCost, currency, lineBreakdown, hasMissingCosts }\n\nconst requirements = await bom.explodeRequirements(bomId, 100);\n// [{ componentSkuId, totalQty, uom }, ...]\n\nconst check = await bom.canProduce(bomId, 100);\n// { ok: true } | { ok: false, shortages: [...] }\n```\n\n| Method | Behavior |\n|---|---|\n| `computeMaterialCost(bomId)` | Walks every BomLine, applies waste (`qtyPerUnit * (1 + wastePercent / 100)`), resolves unit costs via the optional `costResolver`, returns per-line breakdown plus rolled-up total. Lines with no cost set `costUnavailable: true` and contribute `0`. |\n| `explodeRequirements(bomId, qty)` | Returns a \"shopping list\" of materials needed for `qty` units. Duplicates across lines are summed. Does NOT mutate stock. |\n| `canProduce(bomId, qty)` | Calls `explodeRequirements`, then sums `available` stock across every location per component, returns `{ ok: true }` if everything's covered, else `{ ok: false, shortages: [...] }`. |\n\n## ProductionService — consume / produce\n\n```typescript\nimport { ProductionService } from '@happyvertical/smrt-manufacturing';\n\nconst production = await ProductionService.create({ db });\n\n// Drain materials at the factory.\nconst consumed = await production.consumeMaterials(\n { id: order.id, productId: order.productId, bomId: order.bomId },\n { locationId: factory.id, qty: runQty },\n);\n\n// Receive finished goods.\nconst produced = await production.produceFinishedGoods(\n { id: order.id, productId: order.productId },\n { locationId: factory.id, qty: runQty, finishedSkuId: variant.id },\n);\n\n// Or run both in one transaction — see \"Joint atomicity\" below.\nconst { consumed, produced } = await production.runProduction(\n { id: order.id, productId: order.productId, bomId: order.bomId },\n {\n consume: { locationId: factory.id, qty: runQty },\n produce: { locationId: factory.id, qty: runQty, finishedSkuId: variant.id },\n },\n);\n```\n\nAll three methods write through `StockService` and stamp every emitted `StockMovement` with `sourceType: 'ProductionOrder'` + the production order id so audit queries can roll them up later.\n\n### Joint atomicity — `runProduction` vs the two-call form\n\n`consumeMaterials` and `produceFinishedGoods` are each individually atomic, but calling them as two separate awaits is NOT jointly atomic — each opens its own `stockService.withTransaction(...)` scope. If something goes wrong between the two calls (process crash, transient adapter failure on the produce leg), you can land in a state where materials are deducted but no finished SKU receipt balances them. The audit ledger stays consistent within each call; what's missing is the cross-call invariant.\n\nWhen you need that invariant — typically make-to-stock flows where the factory step is invisible to the ledger — use `runProduction(order, { consume, produce })`. Both legs run inside one transaction; any failure (BOM shortage, adapter error, interceptor reject) rolls back both legs together.\n\nWhen NOT to use it: workflows where consume and produce represent a real wall-clock gap that downstream observers need to see (WIP dashboards, partial-run reporting, separate \"materials posted\" and \"production completed\" events on the dispatch bus). There, the two-call form is the right shape — each call is its own ledger event.\n\n### Location convention — explicit-arg design\n\nThe location where materials are consumed and finished goods are received is passed explicitly to `consumeMaterials` / `produceFinishedGoods`, not carried on the production order itself. Rationale:\n\n- The commerce `ProductionOrder` is a `Contract` STI subtype owned by `@happyvertical/smrt-commerce`. Adding an `originLocationId` field there would either need a schema change in commerce (cross-cutting) or a meta field that only manufacturing knows about (leaky).\n- Real shops often pick a location at run time (factory A is congested, route the run through factory B), so even if the order carried a default, the explicit-arg signature is the more flexible canonical form.\n- Callers that want a default can stash a `locationId` on their own production-order helper and pass it through.\n\n### Finished-SKU convention\n\nA `ProductionOrder` references a `productId`, but a `Product` typically has multiple SKUs (one per variant). The caller of `produceFinishedGoods` picks the concrete `finishedSkuId` because the multi-SKU mapping is application-specific (size run, finish mix, kit variant).\n\n## Opt-in DispatchBus hooks\n\nOff by default. Wire them up explicitly in the application's `smrt.ts`:\n\n```typescript\nimport { installManufacturingDispatchHandlers } from '@happyvertical/smrt-manufacturing';\n\nconst handlers = await installManufacturingDispatchHandlers({\n dispatchBus: bus,\n db,\n // Default: subscribe to production_order:posted, call consumeMaterials.\n installProductionPosted: true,\n // Default: don't auto-produce. Set to true if your shop emits a\n // separate production_order:completed event.\n installProductionCompleted: false,\n // Default: don't combine consume + produce on `posted`. Set to true\n // for make-to-stock-instantly workflows where the factory step is\n // invisible. Ignored when installProductionCompleted is true.\n producedOnPosted: false,\n});\n```\n\nThis subscribes to:\n\n- `production_order:posted` → `production.consumeMaterials(...)`; when `producedOnPosted: true` the handler instead calls `production.runProduction(...)` so consume + produce share one transaction. Process crashes or adapter errors between the two legs can never leave materials deducted with no finished-goods receipt.\n- `production_order:completed` → `production.produceFinishedGoods(...)` (opt-in)\n\nThe companion handlers for `contract:created` (reserve) and `fulfillment:shipped` (fulfil) live in `@happyvertical/smrt-inventory` — wire both packages' installers from `smrt.ts` to get the full lifecycle.\n\n## Gotchas\n\n- **`computeMaterialCost` without a resolver returns `$0`.** That is deliberate — manufacturing does not assume any particular cost source. A real wiring will plug in `@happyvertical/smrt-products` `Material.costPerUnit`, or a rolling average from purchase-order history, or a vendor price book. The `costUnavailable` flag tells UIs to surface \"unknown cost\" rather than silently rolling up zeros.\n- **`explodeRequirements` does not call any stock APIs.** It is a planning helper. To check whether the materials are actually on hand, use `canProduce`. To actually deduct them, use `ProductionService.consumeMaterials`.\n- **`canProduce` sums available stock across every location.** The planning question is \"do we have it at all?\". The operational question of \"which warehouse do we pull from?\" is left to the caller of `consumeMaterials`, which targets a single `locationId` per call.\n- **`consumeMaterials` propagates `InsufficientStockError`.** If a line would drive `available` below zero, the underlying `StockService.adjust` throws. Pre-flight with `canProduce` before posting if you want to avoid partial-failure mid-run.\n- **`consumeMaterials` is atomic across BOM lines.** All per-line deductions and their audit rows run inside a single `stockService.withTransaction(...)` scope (powered by `@happyvertical/sql >= 0.74.0`'s native `db.transaction()`). An `InsufficientStockError` on line N+1 rolls back lines 1..N so production-order posting never leaves materials half-consumed. The recommended pre-flight (`BomService.canProduce(orderId, qty)`) is still useful when you'd rather know upfront than discover the shortfall mid-run, but a missed pre-flight no longer corrupts state.\n- **`consumeMaterials` + `produceFinishedGoods` are NOT jointly atomic.** Each opens its own transaction. A failure on the produce leg leaves materials deducted with no finished SKU receipt to balance it. Use `runProduction(order, { consume, produce })` when you need both legs to commit or roll back together.\n- **Cross-package references are plain strings.** `productId`, `componentSkuId`, `bomId` (within this package) — all plain string ids, never `@foreignKey()`. Keeps the dependency graph DAG-shaped and lets each upstream package evolve independently.\n- **`conflictColumns` include `tenant_id`** on both models. NULL-matching semantics are handled by `@happyvertical/sql >= 0.74.0`; two saves with the same `(product_id, version, NULL)` tuple merge in place.\n- **Lazy table creation.** Like everything else in SMRT, the `manufacturing_boms` and `manufacturing_bom_lines` tables are created on first DB op via `syncSchema`. Safe for SSR.\n- **Cross-industry constraint.** This package's vocabulary stays generic. Apparel-specific concepts (`Style`, `Makeup`, `Colorway`, `tech-pack`, fashion `Season`) and their analogues in furniture / automotive / CPG live in the relevant template package, never here. PRs that introduce industry vocabulary should be rejected.\n\n## Source attribution\n\nEvery emitted `StockMovement` carries `sourceType: 'ProductionOrder'` plus `sourceId: order.id` so downstream queries can reconstruct \"what caused this movement\". Reason codes used:\n\n| reasonCode | Emitter | Note |\n|---|---|---|\n| `production_consume` | `ProductionService.consumeMaterials` | One per BOM line per consume call |\n| `production_produce` | `ProductionService.produceFinishedGoods` | One per produce call |\n\nThese join cleanly with the standard inventory reason codes (`receipt`, `reservation`, `release`, `fulfillment`, `transfer_out`, `transfer_in`, `adjustment`) defined in `@happyvertical/smrt-inventory`.\n\n## Dependencies\n\n| Package | Purpose |\n|---|---|\n| `@happyvertical/smrt-core` | SmrtObject / SmrtCollection / DispatchBus |\n| `@happyvertical/smrt-inventory` | StockService, stock levels, movements (the `Sku` model itself lives in `@happyvertical/smrt-products`; inventory tracks stock motion against the id) |\n| `@happyvertical/smrt-tenancy` | Optional tenant scoping |\n| `@happyvertical/sql` | Database adapter |\n"
2386
+ "agentDoc": "# @happyvertical/smrt-manufacturing\n\nBills of materials (multi-level through sub-assemblies), operations and routing, cost and labour rollup, production runs, and production-order stock movement. Strictly industry-neutral — the same primitives serve apparel, furniture, automotive, CPG, electronics, food production, custom hardware, and any vertical that builds finished goods from a recipe.\n\nSits on top of `@happyvertical/smrt-inventory` (stock) and `@happyvertical/smrt-products` (catalog: `Product`, `Material`, `Sku`), and works alongside the `ProductionOrder` Contract STI subtype already shipped in `@happyvertical/smrt-commerce`.\n\n## Models\n\n| Model | Purpose |\n|---|---|\n| `Assembly` | The product that is **made**, counterpart to `Material`. Cross-package STI subtype of `smrt-products` `Product` (`productType: 'assembly'`, `_meta_type: '@happyvertical/smrt-manufacturing:Assembly'`) in the shared `products` table. Own columns: `estimatedLabourMinutes` (integer, per unit; a save refuses anything but a whole number of minutes of zero or more), `defaultOperationId` (`@foreignKey(Operation)`, nullable, RESTRICT like `RoutingStep.operationId`: the operation work on it is booked to by default), `partReference` (the organization's drawing/part number). Name, price, tags come from `Product`; part number and stock from its `Sku` and inventory; structure from its bill; documents from `ProductAsset`. Exposure matches `Product` (REST list/get/create/update, MCP list/get), as the issue asks: unlike `Operation`, the assembly row has no service-owned invariant that generated writes could bypass. |\n| `BillOfMaterials` | Recipe for a finished product. `productId` (plain string) references the upstream `Product` or any STI subtype. Multiple revisions per product via `version` + `status` (`draft` / `active` / `superseded`). `conflictColumns: ['product_id', 'version', 'tenant_id']`. |\n| `BomLine` | One component on a BOM. `bomId` (FK), `componentSkuId` (plain string ref — the `Sku` model lives in `@happyvertical/smrt-products`; inventory tracks stock motion against the id), `qtyPerUnit`, `uom` (open-ended — `yards`, `each`, `grams`, `kg`, ...), `wastePercent`, `notes`. `conflictColumns: ['bom_id', 'component_sku_id', 'tenant_id']`. |\n| `Operation` | A kind of work (cut, weld, inspect), a managed list per tenant. `code` (unique per tenant; `conflictColumns: ['code', 'tenant_id']`, fixed once defined), `name`, `category`, `isActive` (retire/reinstate; never deleted, `delete()` throws), `requiredQualificationId` (nullable `@crossPackageRef('@happyvertical/smrt-human-resources:Qualification')`: metadata only, no dependency, unvalidated; an application reads it to gate who may start the operation). |\n| `ProductionRun` | A build against one bill, reported as it happens (\"25 to build, 12 done\"). `bomId` (`@foreignKey(BillOfMaterials)`, RESTRICT: pinned when created), `targetQty` and `completedQty` (decimal; completed is the sum of completions), `status` (`planned` / `in_progress` / `done` / `cancelled`). Generated list/get only; `ProductionRunService` owns writes. |\n| `ProductionRunCompletion` | One dated report on a run: `runId` (`@foreignKey(ProductionRun)`, CASCADE), `qty` (decimal, > 0), `completedAt`. Generated list/get only. |\n| `RoutingStep` | One operation in a BOM's optional routing. `bomId` (`@foreignKey(BillOfMaterials)`, CASCADE: a routing belongs to its bill), `operationId` (`@foreignKey(Operation)`, RESTRICT: operations are retired, never deleted), `sequence` (1..n, unique per bom), `estimatedMinutes` (decimal, per produced unit), `notes`. `conflictColumns: ['bom_id', 'sequence', 'tenant_id']`. |\n\nAll models are `@TenantScoped({ mode: 'optional' })` with a nullable `tenantId` so they can be used either tenant-scoped or globally.\n\n## Operations, routing and labour estimate\n\n- `OperationService` maintains the list (`define` rejects a duplicate code, including a retired one's; `rename`, `update`, `retire`, `reinstate`). `RoutingService.replaceRouting(bomId, steps)` swaps a bill's whole routing in one transaction and numbers it 1..n; a retired operation may stay on a routing that has it but cannot be newly added.\n- `BomService.computeLabourEstimate(bomId)` returns minutes and, only when the caller supplies `rateResolver` (hourly rate per `Operation`, mirroring `costResolver`), cost. No resolver means minutes only with `rateUnavailable` on each step. A bill with no routing returns an empty estimate; `computeMaterialCost` is unchanged.\n- `Operation` and `RoutingStep` expose generated list/get only; writes go through the services (generated create/update would upsert on a duplicate code or rename the code). `replaceRouting` saves the bill row inside its transaction (row lock) and retries on a revision conflict, so concurrent replacements serialize.\n- Deliberately absent: a default labour rate class (nothing here would use it; the resolver receives the whole `Operation` and can key on `code`/`category`), setup time, scheduling and work-centre capacity, and time recorded against an operation (that stays in `smrt-timesheets` or the application).\n- `./svelte` exports `OperationList` and `OperationForm` (props-driven; hosts persist through `OperationService`). Messages live in `src/svelte/i18n.ts`; component tests use the shared jsdom harness with axe assertions.\n- Tests: `operations-suite.ts` runs on SQLite (`operations.test.ts`) and PostgreSQL (`operations.optional.test.ts`, `pnpm test:postgres`; each test runs in its own tenant because PostgreSQL test data persists).\n\n## Assemblies — nesting lives in the bill\n\nA sub-assembly is a `BomLine` whose component SKU belongs to an `Assembly`; there is no children list on the model. `AssemblyService` is the one link from a line to what it names:\n\n| Method | Behavior |\n|---|---|\n| `resolveComponent(skuId, { tenantId? })` | `{ kind, sku, product, assembly, activeBom, buildable }`. `kind` is `assembly`, `material` (`Material`), `bought` (any other `Product`), or `missing` (unknown SKU, SKU with no product, or a non-UUID id; never throws). `activeBom` is the assembly's highest active bill, `null` when it has none; `buildable` is `assembly && activeBom`. Multi-level explosion (#3444) recurses on `activeBom` and stops at every other kind. |\n| `isAssembly(skuId)` | `resolveComponent(skuId).kind === 'assembly'`. |\n| `findActiveBom(productId, { tenantId? })` | Highest active bill. With `tenantId` (including `null`), that tenant's own bill, else a global one, and `resolveComponent` reads the SKU and product as that tenant's or global (through `tenant-scope.ts`, so a shared global component stays visible under a tenant context) and reports another tenant's as `missing`, whatever the tenant context; the cycle walk and `getBillStructure` pass the bill's own tenant, so a shared assembly resolves to the right tenant's bill on writes made without `withTenant()`. |\n| `getBillStructure(bomId)` | One level: the bill plus each line with its resolved component. Throws `BomNotFoundError`. |\n| `findCycle(productId, componentSkuIds)` | The path by which those components would make `productId` contain itself, following sub-assemblies' **active** bills only; `null` when none. |\n| `assertLineAcyclic(line)` / `assertBillAcyclic(bom)` | Throw `BomCycleError` (a `ValidationError`, code `MANUFACTURING_BOM_CYCLE`, `path` from the product back to itself). |\n\n**Cycle refusal runs in the models.** `BomLine.validateBeforeSave` checks every line save (draft bills too, so a loop is refused when written); `BillOfMaterials.validateBeforeSave` checks every save of an `active` bill (activation), including the lines of a stored bill with the same `(productId, version, tenantId)` that the save would upsert onto. The generated REST routes go through `save()`, so they refuse cycles as well. Not covered: re-pointing a `Sku.productId` (owned by `smrt-products`) and two concurrent saves that each close half of a loop.\n\n## Multi-level walks and production runs\n\nDetail: [agents/multilevel-and-runs.md](agents/multilevel-and-runs.md).\n\n- Every `BomService` method takes `{ levels }` (default `1`, unchanged; up to `MAX_EXPLOSION_DEPTH` = 32, or `'all'`). One walk (`services/structure-walk.ts`) serves `explode` (gross lines and totals), `planRequirements` (net of stock: available, short, what building a shortfall takes; facts, no make-or-buy policy), `canProduce`, cost and labour. A loop already in stored data fails with `BomStructureCycleError`; size limits with `BomExplosionLimitError`.\n- `ProductionRunService` writes `ProductionRun` / `ProductionRunCompletion` in one transaction per call, locking the run row through its revision-guarded save and retrying on a revision conflict; no adapter without `transaction()`. Stock moves only when the caller passes `consume` / `produce`.\n- A run is not commerce's `ProductionOrder` (a `Contract` with terms and money, in a package this one does not depend on); an application that has both links them.\n\n## Svelte components (`./svelte`)\n\nProps-driven; the host loads and persists. `AssemblyList` (field policy drops hidden columns via `policyToVisibleColumnIds`), `AssemblyForm` (smrt-fields `ObjectForm` for `@happyvertical/smrt-manufacturing:Assembly`, so price and every other field follow the consumer's field policy), `BomEditor` (add/edit/remove lines through host handlers; a sub-assembly shows whether it has its own bill and expands read-only through `loadBill`), `BomStructureTree` (the read-only nested view). `ProductionRunList` (progress, status, and with `oncomplete` a quantity field per open run; rows from `toProductionRunView`), `RequirementsTree` (read-only `explode` / `planRequirements` result by level with totals; `toRequirementTree`, `toRequirementTotals`; internal `RequirementsTreeLevel`). Adapters: `toAssemblyView`, `toBomEditorLines`. Strings are under `manufacturing.` in `src/svelte/i18n.ts`; the package is strict for raw primitives, hardcoded strings and JSDoc.\n\n\n## BomService — planning helpers\n\n```typescript\nimport { BomService } from '@happyvertical/smrt-manufacturing';\n\nconst bom = await BomService.create({\n db,\n // Optional. Resolve unit cost for a component SKU.\n // Without this, every line rolls up to $0 and `costUnavailable` is set.\n costResolver: async (componentSkuId) => fetchLatestCost(componentSkuId),\n});\n\nconst rollup = await bom.computeMaterialCost(bomId);\n// { totalCost, currency, lineBreakdown, hasMissingCosts }\n\nconst requirements = await bom.explodeRequirements(bomId, 100);\n// [{ componentSkuId, totalQty, uom }, ...]\n\nconst check = await bom.canProduce(bomId, 100);\n// { ok: true } | { ok: false, shortages: [...] }\n```\n\n| Method | Behavior |\n|---|---|\n| `computeMaterialCost(bomId)` | Walks every BomLine, applies waste (`qtyPerUnit * (1 + wastePercent / 100)`), resolves unit costs via the optional `costResolver`, returns per-line breakdown plus rolled-up total. Lines with no cost set `costUnavailable: true` and contribute `0`. |\n| `explodeRequirements(bomId, qty)` | Returns a \"shopping list\" of materials needed for `qty` units. Duplicates across lines are summed. Does NOT mutate stock. |\n| `canProduce(bomId, qty)` | Calls `explodeRequirements`, then sums `available` stock across every location per component, returns `{ ok: true }` if everything's covered, else `{ ok: false, shortages: [...] }`. |\n| `explode` / `planRequirements` | Multi-level walks; see \"Multi-level walks\" above. Each method above also takes `{ levels }`. |\n\n## ProductionService — consume / produce\n\n```typescript\nimport { ProductionService } from '@happyvertical/smrt-manufacturing';\n\nconst production = await ProductionService.create({ db });\n\n// Drain materials at the factory.\nconst consumed = await production.consumeMaterials(\n { id: order.id, productId: order.productId, bomId: order.bomId },\n { locationId: factory.id, qty: runQty },\n);\n\n// Receive finished goods.\nconst produced = await production.produceFinishedGoods(\n { id: order.id, productId: order.productId },\n { locationId: factory.id, qty: runQty, finishedSkuId: variant.id },\n);\n\n// Or run both in one transaction — see \"Joint atomicity\" below.\nconst { consumed, produced } = await production.runProduction(\n { id: order.id, productId: order.productId, bomId: order.bomId },\n {\n consume: { locationId: factory.id, qty: runQty },\n produce: { locationId: factory.id, qty: runQty, finishedSkuId: variant.id },\n },\n);\n```\n\nAll three methods write through `StockService` and stamp every emitted `StockMovement` with `sourceType: 'ProductionOrder'` (override with the `sourceType` option, as `ProductionRunService` does) + the production order id so audit queries can roll them up later.\n\n### Joint atomicity — `runProduction` vs the two-call form\n\n`consumeMaterials` and `produceFinishedGoods` are each individually atomic, but calling them as two separate awaits is NOT jointly atomic — each opens its own `stockService.withTransaction(...)` scope. If something goes wrong between the two calls (process crash, transient adapter failure on the produce leg), you can land in a state where materials are deducted but no finished SKU receipt balances them. The audit ledger stays consistent within each call; what's missing is the cross-call invariant.\n\nWhen you need that invariant — typically make-to-stock flows where the factory step is invisible to the ledger — use `runProduction(order, { consume, produce })`. Both legs run inside one transaction; any failure (BOM shortage, adapter error, interceptor reject) rolls back both legs together.\n\nWhen NOT to use it: workflows where consume and produce represent a real wall-clock gap that downstream observers need to see (WIP dashboards, partial-run reporting, separate \"materials posted\" and \"production completed\" events on the dispatch bus). There, the two-call form is the right shape — each call is its own ledger event.\n\n### Location convention — explicit-arg design\n\nThe location where materials are consumed and finished goods are received is passed explicitly to `consumeMaterials` / `produceFinishedGoods`, not carried on the production order itself. Rationale:\n\n- The commerce `ProductionOrder` is a `Contract` STI subtype owned by `@happyvertical/smrt-commerce`. Adding an `originLocationId` field there would either need a schema change in commerce (cross-cutting) or a meta field that only manufacturing knows about (leaky).\n- Real shops often pick a location at run time (factory A is congested, route the run through factory B), so even if the order carried a default, the explicit-arg signature is the more flexible canonical form.\n- Callers that want a default can stash a `locationId` on their own production-order helper and pass it through.\n\n### Finished-SKU convention\n\nA `ProductionOrder` references a `productId`, but a `Product` typically has multiple SKUs (one per variant). The caller of `produceFinishedGoods` picks the concrete `finishedSkuId` because the multi-SKU mapping is application-specific (size run, finish mix, kit variant).\n\n## Opt-in DispatchBus hooks\n\nOff by default. Wire them up explicitly in the application's `smrt.ts`:\n\n```typescript\nimport { installManufacturingDispatchHandlers } from '@happyvertical/smrt-manufacturing';\n\nconst handlers = await installManufacturingDispatchHandlers({\n dispatchBus: bus,\n db,\n // Default: subscribe to production_order:posted, call consumeMaterials.\n installProductionPosted: true,\n // Default: don't auto-produce. Set to true if your shop emits a\n // separate production_order:completed event.\n installProductionCompleted: false,\n // Default: don't combine consume + produce on `posted`. Set to true\n // for make-to-stock-instantly workflows where the factory step is\n // invisible. Ignored when installProductionCompleted is true.\n producedOnPosted: false,\n});\n```\n\nThis subscribes to:\n\n- `production_order:posted` → `production.consumeMaterials(...)`; when `producedOnPosted: true` the handler instead calls `production.runProduction(...)` so consume + produce share one transaction. Process crashes or adapter errors between the two legs can never leave materials deducted with no finished-goods receipt.\n- `production_order:completed` → `production.produceFinishedGoods(...)` (opt-in)\n\nThe companion handlers for `contract:created` (reserve) and `fulfillment:shipped` (fulfil) live in `@happyvertical/smrt-inventory` — wire both packages' installers from `smrt.ts` to get the full lifecycle.\n\n## Tests\n\n`multilevel-suite.ts` (rolled back on PostgreSQL) and `production-run-suite.ts` (base handle, per-test tenant, for real concurrent transactions) follow the same SQLite / `*.optional.test.ts` pattern. `src/__tests__/assembly-suite.ts` runs on SQLite (`assembly.test.ts`) and on PostgreSQL (`assembly.optional.test.ts`, skipped without `DATABASE_URL`; `pnpm test:postgres` and the PostgreSQL CI lane run it on a transaction-scoped handle). Component tests under `src/svelte/__tests__` use jsdom and assert axe.\n\n## Gotchas\n\n- **`computeMaterialCost` without a resolver returns `$0`.** That is deliberate — manufacturing does not assume any particular cost source. A real wiring will plug in `@happyvertical/smrt-products` `Material.costPerUnit`, or a rolling average from purchase-order history, or a vendor price book. The `costUnavailable` flag tells UIs to surface \"unknown cost\" rather than silently rolling up zeros.\n- **`explodeRequirements` does not call any stock APIs.** It is a planning helper. To check whether the materials are actually on hand, use `canProduce`. To actually deduct them, use `ProductionService.consumeMaterials`.\n- **`canProduce` sums available stock across every location.** The planning question is \"do we have it at all?\". The operational question of \"which warehouse do we pull from?\" is left to the caller of `consumeMaterials`, which targets a single `locationId` per call.\n- **`consumeMaterials` propagates `InsufficientStockError`.** If a line would drive `available` below zero, the underlying `StockService.adjust` throws. Pre-flight with `canProduce` before posting if you want to avoid partial-failure mid-run.\n- **`consumeMaterials` is atomic across BOM lines.** All per-line deductions and their audit rows run inside a single `stockService.withTransaction(...)` scope (powered by `@happyvertical/sql >= 0.74.0`'s native `db.transaction()`). An `InsufficientStockError` on line N+1 rolls back lines 1..N so production-order posting never leaves materials half-consumed. The recommended pre-flight (`BomService.canProduce(orderId, qty)`) is still useful when you'd rather know upfront than discover the shortfall mid-run, but a missed pre-flight no longer corrupts state.\n- **`consumeMaterials` + `produceFinishedGoods` are NOT jointly atomic.** Each opens its own transaction. A failure on the produce leg leaves materials deducted with no finished SKU receipt to balance it. Use `runProduction(order, { consume, produce })` when you need both legs to commit or roll back together.\n- **Cross-package references are plain strings.** `BillOfMaterials.productId`, `BomLine.componentSkuId` and `BomLine.bomId` are plain string ids (changing them to UUID references needs a migration window); the newer models (`RoutingStep`, `ProductionRun`, `ProductionRunCompletion`) reference this package's own models with `@foreignKey`. The package does depend on `smrt-products` (for `Assembly` and the resolve helper), but the bill schema does not couple to the catalog's table layout.\n- **`Assembly` fields are columns, not `Meta<T>`.** Unlike `Material`, its own fields are ordinary columns this package adds to `products` (filterable over REST). The PostgreSQL suite asserts they land there.\n- **`AssemblyCollection` lists exact `Assembly` rows.** An application subtype (e.g. one adding a customer) has its own `_meta_type`; read it through its own collection or `ProductCollection` (`resolveComponent` uses `instanceof Assembly`, so subtypes resolve as assemblies).\n- **`conflictColumns` include `tenant_id`** on both models. NULL-matching semantics are handled by `@happyvertical/sql >= 0.74.0`; two saves with the same `(product_id, version, NULL)` tuple merge in place.\n- **Lazy table creation.** Like everything else in SMRT, the `manufacturing_boms` and `manufacturing_bom_lines` tables are created on first DB op via `syncSchema`. Safe for SSR. A `BomLine` save now reads `product_skus` and `products` for the cycle check.\n- **Cross-industry constraint.** This package's vocabulary stays generic. Apparel-specific concepts (`Style`, `Makeup`, `Colorway`, `tech-pack`, fashion `Season`) and their analogues in furniture / automotive / CPG live in the relevant template package, never here. PRs that introduce industry vocabulary should be rejected.\n\n## Source attribution\n\nEvery emitted `StockMovement` carries `sourceType: 'ProductionOrder'` plus `sourceId: order.id` so downstream queries can reconstruct \"what caused this movement\". Reason codes used:\n\n| reasonCode | Emitter | Note |\n|---|---|---|\n| `production_consume` | `ProductionService.consumeMaterials` | One per BOM line per consume call |\n| `production_produce` | `ProductionService.produceFinishedGoods` | One per produce call |\n| either, with `sourceType: 'ProductionRunCompletion'` | `ProductionRunService.recordCompletion` | Only when the caller passes `consume` / `produce` |\n\nThese join cleanly with the standard inventory reason codes (`receipt`, `reservation`, `release`, `fulfillment`, `transfer_out`, `transfer_in`, `adjustment`) defined in `@happyvertical/smrt-inventory`.\n\n## Dependencies\n\n| Package | Purpose |\n|---|---|\n| `@happyvertical/smrt-core` | SmrtObject / SmrtCollection / DispatchBus |\n| `@happyvertical/smrt-inventory` | StockService, stock levels, movements (the `Sku` model itself lives in `@happyvertical/smrt-products`; inventory tracks stock motion against the id) |\n| `@happyvertical/smrt-products` | `Product` (the `Assembly` STI base), `Material`, `Sku` for the resolve helper and cycle check |\n| `@happyvertical/smrt-fields` | `ObjectForm` and field-policy column visibility for the Svelte components |\n| `@happyvertical/smrt-ui` / `smrt-types` | Svelte controls, i18n, module UI slots |\n| `@happyvertical/smrt-tenancy` | Optional tenant scoping |\n| `@happyvertical/sql` | Database adapter |\n",
2387
+ "moduleDocs": [
2388
+ {
2389
+ "path": "agents/multilevel-and-runs.md",
2390
+ "module": "multilevel-and-runs",
2391
+ "content": "# Multi-level walks and production runs\n\nDetail for `services/structure-walk.ts`, the multi-level forms of `BomService`, and `ProductionRunService`. Orientation and gotchas stay in the package [AGENTS.md](../AGENTS.md).\n\n## Multi-level walks (sub-assemblies)\n\nEvery `BomService` method takes `{ levels }` (`1` by default: the single-level behaviour, unchanged; a number up to `MAX_EXPLOSION_DEPTH` = 32; or `'all'`). The walk is `services/structure-walk.ts`, shared by all of them: resolve each line through `AssemblyService.resolveComponent` (in the top bill's tenant), open an assembly's active bill while `levels` allows, stop at materials, bought items, missing components and assemblies without an active bill.\n\n| Method | Multi-level behaviour |\n|---|---|\n| `explode(bomId, qty, { levels })` | Gross: every line depth first with `level`, `path` (bills from the top), `totalQty` (waste compounds: a child is the parent line's quantity times its own effective quantity), `buildable`, `expanded`; `totals` sums the lines not opened per SKU (first unit kept, as before). |\n| `planRequirements(bomId, qty, { levels })` | Net: per line, `available` stock not yet allocated to an earlier line and `short`; a short buildable sub-assembly is opened for the shortfall only. Lines short and not opened are `shortages`, each at its own level. Facts only: no make-or-buy policy. |\n| `explodeRequirements` / `canProduce` | `explode().totals` / the plan's shortages (`level`, `path`, `uom`, `buildable` added). |\n| `computeMaterialCost` | An opened sub-assembly is costed from its bill (`subBomId`, nested `components`); a missing price below marks it. A sub-assembly bill in another currency is not added: its line is priced through the resolver. |\n| `computeLabourEstimate` | Adds each opened sub-assembly's routing times its units per top unit (`subAssemblies`); `steps` stays the top routing. Minutes always count; cost from a bill in another currency does not, and sets `hasMissingRates`. |\n\nSafety: a loop already in stored data (written around the save-time refusal) fails with `BomStructureCycleError` (a `BomCycleError`) naming it; `'all'` past 32 levels or a walk past `MAX_EXPLOSION_LINES` (10,000, counted per use of a shared sub-assembly) fails with `BomExplosionLimitError`. Stock in a plan is summed across locations, as in `canProduce`, counting only the top bill's tenant's rows and global ones (like the lines the walk reads), whatever tenant context is active.\n\n## Production runs\n\n`ProductionRunService` (`createRun({ bomId } | { productId }, targetQty)`, `start`, `recordCompletion`, `finish`, `cancel`, `setTarget`, `get`, `listCompletions`). Every write is one transaction that saves the run row first; the revision-guarded save locks it, and a concurrent writer's conflict reruns its whole transaction (up to 10 attempts), so concurrent completions all count and never pass the target. The service refuses an adapter without `transaction()`; it never falls back to step-by-step writes.\n\n- Tenant: every structure read goes through `src/tenant-scope.ts`: list reads run in `withTenantGlobalRead` for the owning tenant (its rows plus global rows; a tenant context alone would hide global rows, no context would show every tenant's) and keep own-or-global rows. Routing and operations in `computeLabourEstimate`, and the top bill itself under a tenant context, are read the same way. `createRun` reads the active tenant's bills and global ones (no context: global bills only, by `productId` or `bomId`). The run takes its bill's tenant; a completion takes the run's; stock legs run inside `withTenant(run.tenantId)`, so the bill's lines and the levels read and written are that tenant's whatever the caller's context. `ProductionService` consumes only a bill's own tenant's lines and global ones (a global bill: global lines only), for every caller; a global run's stock legs run in the caller's context.\n- A completion moves no stock unless asked. With `consume` / `produce` it calls `ProductionService` (`runProduction` for both) on the transaction's stock service, stamping movements `sourceType: 'ProductionRunCompletion'` with the completion id; a shortfall rolls the completion back. Consumption is the run's bill's own lines: a sub-assembly is taken from stock, and building it is its own run.\n- Quantities are kept to `QUANTITY_DECIMALS` (6) places, never compared with a tolerance. A run's target, completed quantity and each report are summed and compared as whole millionths, exactly; a run accepts quantities up to `MAX_QUANTITY` (999,999,999, so every value has at most 15 significant digits and survives a double exactly) and refuses one that rounds to zero. A plan's `short` is rounded with `roundQuantity`.\n- Reaching the target marks the run `done`; `finish` closes it short; `cancel` keeps its completions; `setTarget` cannot go below what is done.\n- Why not commerce `ProductionOrder`: that is a `Contract` (terms, money, customer or vendor, a contract status flow), owned by `smrt-commerce`, which this package does not depend on. A run is the shop-floor record of building; one order may need several runs, and make-to-stock needs none. An application that has both links them.\n- Deliberately absent (nothing here would use them): a link to an order, who did the work, a location on the run (passed per call, as in `ProductionService`).\n"
2392
+ }
2393
+ ]
830
2394
  }