@tailor-platform/erp-kit 0.5.0 → 0.6.0

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 (262) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/cli.mjs +139 -35
  3. package/package.json +1 -1
  4. package/skills/erp-kit-app-5-impl-backend/SKILL.md +10 -5
  5. package/skills/erp-kit-app-7-impl-review/SKILL.md +1 -1
  6. package/skills/erp-kit-module-6-impl-review/SKILL.md +39 -17
  7. package/src/commands/generate-doc.ts +1 -1
  8. package/src/commands/init-module.test.ts +17 -3
  9. package/src/commands/init-module.ts +0 -12
  10. package/src/commands/lib/discovery.test.ts +13 -3
  11. package/src/commands/lib/discovery.ts +10 -2
  12. package/src/commands/lib/paths.ts +4 -2
  13. package/src/commands/lib/sync-check-tests.test.ts +84 -6
  14. package/src/commands/lib/sync-check-tests.ts +63 -3
  15. package/src/commands/sync-check.ts +7 -3
  16. package/src/generator/generate-app-code.ts +51 -16
  17. package/src/generator/generate-code-boilerplate.test.ts +9 -1
  18. package/src/generator/generate-stubs.ts +4 -0
  19. package/src/generator/scaffold.ts +6 -2
  20. package/src/generator/stub-templates.test.ts +11 -0
  21. package/src/generator/stub-templates.ts +22 -1
  22. package/src/mdschema.ts +39 -3
  23. package/src/modules/inventory/docs/features/inventory-adjustment.md +2 -1
  24. package/src/modules/inventory/docs/features/scrap-management.md +39 -1
  25. package/src/modules/manufacturing/README.md +63 -0
  26. package/src/modules/manufacturing/command/activateBillOfMaterial.generated.ts +6 -0
  27. package/src/modules/manufacturing/command/activateBillOfMaterial.test.ts +166 -0
  28. package/src/modules/manufacturing/command/activateBillOfMaterial.ts +173 -0
  29. package/src/modules/manufacturing/command/activateRouting.generated.ts +6 -0
  30. package/src/modules/manufacturing/command/activateRouting.test.ts +152 -0
  31. package/src/modules/manufacturing/command/activateRouting.ts +92 -0
  32. package/src/modules/manufacturing/command/activateWorkCenter.generated.ts +6 -0
  33. package/src/modules/manufacturing/command/activateWorkCenter.test.ts +135 -0
  34. package/src/modules/manufacturing/command/activateWorkCenter.ts +91 -0
  35. package/src/modules/manufacturing/command/cancelProductionOrder.generated.ts +6 -0
  36. package/src/modules/manufacturing/command/cancelProductionOrder.test.ts +151 -0
  37. package/src/modules/manufacturing/command/cancelProductionOrder.ts +114 -0
  38. package/src/modules/manufacturing/command/closeProductionOrder.generated.ts +6 -0
  39. package/src/modules/manufacturing/command/closeProductionOrder.test.ts +126 -0
  40. package/src/modules/manufacturing/command/closeProductionOrder.ts +87 -0
  41. package/src/modules/manufacturing/command/completeProductionOrder.generated.ts +6 -0
  42. package/src/modules/manufacturing/command/completeProductionOrder.test.ts +132 -0
  43. package/src/modules/manufacturing/command/completeProductionOrder.ts +97 -0
  44. package/src/modules/manufacturing/command/completeWorkOrder.generated.ts +6 -0
  45. package/src/modules/manufacturing/command/completeWorkOrder.test.ts +369 -0
  46. package/src/modules/manufacturing/command/completeWorkOrder.ts +212 -0
  47. package/src/modules/manufacturing/command/createBillOfMaterial.generated.ts +6 -0
  48. package/src/modules/manufacturing/command/createBillOfMaterial.test.ts +210 -0
  49. package/src/modules/manufacturing/command/createBillOfMaterial.ts +176 -0
  50. package/src/modules/manufacturing/command/createProductionOrder.generated.ts +6 -0
  51. package/src/modules/manufacturing/command/createProductionOrder.test.ts +160 -0
  52. package/src/modules/manufacturing/command/createProductionOrder.ts +129 -0
  53. package/src/modules/manufacturing/command/createRouting.generated.ts +6 -0
  54. package/src/modules/manufacturing/command/createRouting.test.ts +168 -0
  55. package/src/modules/manufacturing/command/createRouting.ts +128 -0
  56. package/src/modules/manufacturing/command/createWorkCenter.generated.ts +6 -0
  57. package/src/modules/manufacturing/command/createWorkCenter.test.ts +148 -0
  58. package/src/modules/manufacturing/command/createWorkCenter.ts +131 -0
  59. package/src/modules/manufacturing/command/deactivateBillOfMaterial.generated.ts +6 -0
  60. package/src/modules/manufacturing/command/deactivateBillOfMaterial.test.ts +103 -0
  61. package/src/modules/manufacturing/command/deactivateBillOfMaterial.ts +78 -0
  62. package/src/modules/manufacturing/command/deactivateRouting.generated.ts +6 -0
  63. package/src/modules/manufacturing/command/deactivateRouting.test.ts +112 -0
  64. package/src/modules/manufacturing/command/deactivateRouting.ts +76 -0
  65. package/src/modules/manufacturing/command/deactivateWorkCenter.generated.ts +6 -0
  66. package/src/modules/manufacturing/command/deactivateWorkCenter.test.ts +113 -0
  67. package/src/modules/manufacturing/command/deactivateWorkCenter.ts +85 -0
  68. package/src/modules/manufacturing/command/pauseWorkOrder.generated.ts +6 -0
  69. package/src/modules/manufacturing/command/pauseWorkOrder.test.ts +118 -0
  70. package/src/modules/manufacturing/command/pauseWorkOrder.ts +82 -0
  71. package/src/modules/manufacturing/command/recordInventoryIssueOutcome.generated.ts +6 -0
  72. package/src/modules/manufacturing/command/recordInventoryIssueOutcome.test.ts +183 -0
  73. package/src/modules/manufacturing/command/recordInventoryIssueOutcome.ts +139 -0
  74. package/src/modules/manufacturing/command/recordManufacturingCostSettlementAcknowledgment.generated.ts +6 -0
  75. package/src/modules/manufacturing/command/recordManufacturingCostSettlementAcknowledgment.test.ts +120 -0
  76. package/src/modules/manufacturing/command/recordManufacturingCostSettlementAcknowledgment.ts +110 -0
  77. package/src/modules/manufacturing/command/releaseProductionOrder.generated.ts +6 -0
  78. package/src/modules/manufacturing/command/releaseProductionOrder.test.ts +220 -0
  79. package/src/modules/manufacturing/command/releaseProductionOrder.ts +450 -0
  80. package/src/modules/manufacturing/command/reopenProductionOrder.generated.ts +6 -0
  81. package/src/modules/manufacturing/command/reopenProductionOrder.test.ts +196 -0
  82. package/src/modules/manufacturing/command/reopenProductionOrder.ts +98 -0
  83. package/src/modules/manufacturing/command/reportWorkOrderProgress.generated.ts +6 -0
  84. package/src/modules/manufacturing/command/reportWorkOrderProgress.test.ts +204 -0
  85. package/src/modules/manufacturing/command/reportWorkOrderProgress.ts +129 -0
  86. package/src/modules/manufacturing/command/rescheduleProductionOrder.generated.ts +6 -0
  87. package/src/modules/manufacturing/command/rescheduleProductionOrder.test.ts +185 -0
  88. package/src/modules/manufacturing/command/rescheduleProductionOrder.ts +95 -0
  89. package/src/modules/manufacturing/command/resumeWorkOrder.generated.ts +6 -0
  90. package/src/modules/manufacturing/command/resumeWorkOrder.test.ts +122 -0
  91. package/src/modules/manufacturing/command/resumeWorkOrder.ts +94 -0
  92. package/src/modules/manufacturing/command/reviewManufacturingCostSummary.generated.ts +6 -0
  93. package/src/modules/manufacturing/command/reviewManufacturingCostSummary.test.ts +231 -0
  94. package/src/modules/manufacturing/command/reviewManufacturingCostSummary.ts +137 -0
  95. package/src/modules/manufacturing/command/startWorkOrder.generated.ts +6 -0
  96. package/src/modules/manufacturing/command/startWorkOrder.test.ts +118 -0
  97. package/src/modules/manufacturing/command/startWorkOrder.ts +126 -0
  98. package/src/modules/manufacturing/command/technicallyCompleteProductionOrder.generated.ts +6 -0
  99. package/src/modules/manufacturing/command/technicallyCompleteProductionOrder.test.ts +153 -0
  100. package/src/modules/manufacturing/command/technicallyCompleteProductionOrder.ts +106 -0
  101. package/src/modules/manufacturing/command/unreleaseProductionOrder.generated.ts +6 -0
  102. package/src/modules/manufacturing/command/unreleaseProductionOrder.test.ts +140 -0
  103. package/src/modules/manufacturing/command/unreleaseProductionOrder.ts +131 -0
  104. package/src/modules/manufacturing/command/updateBillOfMaterial.generated.ts +6 -0
  105. package/src/modules/manufacturing/command/updateBillOfMaterial.test.ts +149 -0
  106. package/src/modules/manufacturing/command/updateBillOfMaterial.ts +174 -0
  107. package/src/modules/manufacturing/command/updateProductionOrder.generated.ts +6 -0
  108. package/src/modules/manufacturing/command/updateProductionOrder.test.ts +112 -0
  109. package/src/modules/manufacturing/command/updateProductionOrder.ts +145 -0
  110. package/src/modules/manufacturing/command/updateRouting.generated.ts +6 -0
  111. package/src/modules/manufacturing/command/updateRouting.test.ts +211 -0
  112. package/src/modules/manufacturing/command/updateRouting.ts +124 -0
  113. package/src/modules/manufacturing/command/updateWorkCenter.generated.ts +6 -0
  114. package/src/modules/manufacturing/command/updateWorkCenter.test.ts +152 -0
  115. package/src/modules/manufacturing/command/updateWorkCenter.ts +137 -0
  116. package/src/modules/manufacturing/db/.gitkeep +0 -0
  117. package/src/modules/manufacturing/db/billOfMaterial.ts +70 -0
  118. package/src/modules/manufacturing/db/billOfMaterialLine.ts +49 -0
  119. package/src/modules/manufacturing/db/costVarianceLine.ts +53 -0
  120. package/src/modules/manufacturing/db/manufacturingCostLine.ts +35 -0
  121. package/src/modules/manufacturing/db/manufacturingCostSettlementRecord.ts +39 -0
  122. package/src/modules/manufacturing/db/manufacturingCostSummary.ts +59 -0
  123. package/src/modules/manufacturing/db/productionOrder.ts +83 -0
  124. package/src/modules/manufacturing/db/productionOrderBomSnapshot.ts +44 -0
  125. package/src/modules/manufacturing/db/productionOrderCostBaseline.ts +44 -0
  126. package/src/modules/manufacturing/db/productionOrderMaterialRequirement.ts +57 -0
  127. package/src/modules/manufacturing/db/productionOrderRoutingSnapshot.ts +43 -0
  128. package/src/modules/manufacturing/db/routing.ts +63 -0
  129. package/src/modules/manufacturing/db/routingOperation.ts +57 -0
  130. package/src/modules/manufacturing/db/workCenter.ts +87 -0
  131. package/src/modules/manufacturing/db/workOrder.ts +65 -0
  132. package/src/modules/manufacturing/db/workOrderExecutionEvent.ts +54 -0
  133. package/src/modules/manufacturing/docs/commands/ActivateBillOfMaterial.md +50 -0
  134. package/src/modules/manufacturing/docs/commands/ActivateRouting.md +48 -0
  135. package/src/modules/manufacturing/docs/commands/ActivateWorkCenter.md +49 -0
  136. package/src/modules/manufacturing/docs/commands/CancelProductionOrder.md +48 -0
  137. package/src/modules/manufacturing/docs/commands/CloseProductionOrder.md +46 -0
  138. package/src/modules/manufacturing/docs/commands/CompleteProductionOrder.md +48 -0
  139. package/src/modules/manufacturing/docs/commands/CompleteWorkOrder.md +66 -0
  140. package/src/modules/manufacturing/docs/commands/CreateBillOfMaterial.md +54 -0
  141. package/src/modules/manufacturing/docs/commands/CreateProductionOrder.md +49 -0
  142. package/src/modules/manufacturing/docs/commands/CreateRouting.md +50 -0
  143. package/src/modules/manufacturing/docs/commands/CreateWorkCenter.md +51 -0
  144. package/src/modules/manufacturing/docs/commands/DeactivateBillOfMaterial.md +45 -0
  145. package/src/modules/manufacturing/docs/commands/DeactivateRouting.md +45 -0
  146. package/src/modules/manufacturing/docs/commands/DeactivateWorkCenter.md +45 -0
  147. package/src/modules/manufacturing/docs/commands/PauseWorkOrder.md +44 -0
  148. package/src/modules/manufacturing/docs/commands/RecordInventoryIssueOutcome.md +59 -0
  149. package/src/modules/manufacturing/docs/commands/RecordManufacturingCostSettlementAcknowledgment.md +49 -0
  150. package/src/modules/manufacturing/docs/commands/ReleaseProductionOrder.md +57 -0
  151. package/src/modules/manufacturing/docs/commands/ReopenProductionOrder.md +54 -0
  152. package/src/modules/manufacturing/docs/commands/ReportWorkOrderProgress.md +53 -0
  153. package/src/modules/manufacturing/docs/commands/RescheduleProductionOrder.md +45 -0
  154. package/src/modules/manufacturing/docs/commands/ResumeWorkOrder.md +44 -0
  155. package/src/modules/manufacturing/docs/commands/ReviewManufacturingCostSummary.md +52 -0
  156. package/src/modules/manufacturing/docs/commands/StartWorkOrder.md +46 -0
  157. package/src/modules/manufacturing/docs/commands/TechnicallyCompleteProductionOrder.md +51 -0
  158. package/src/modules/manufacturing/docs/commands/UnreleaseProductionOrder.md +46 -0
  159. package/src/modules/manufacturing/docs/commands/UpdateBillOfMaterial.md +48 -0
  160. package/src/modules/manufacturing/docs/commands/UpdateProductionOrder.md +48 -0
  161. package/src/modules/manufacturing/docs/commands/UpdateRouting.md +52 -0
  162. package/src/modules/manufacturing/docs/commands/UpdateWorkCenter.md +48 -0
  163. package/src/modules/manufacturing/docs/features/bill-of-material-management.md +83 -0
  164. package/src/modules/manufacturing/docs/features/manufacturing-cost-and-variance.md +191 -0
  165. package/src/modules/manufacturing/docs/features/production-order-lifecycle.md +103 -0
  166. package/src/modules/manufacturing/docs/features/routing-and-work-center-definition.md +63 -0
  167. package/src/modules/manufacturing/docs/features/work-order-execution.md +115 -0
  168. package/src/modules/manufacturing/docs/models/BillOfMaterial.md +60 -0
  169. package/src/modules/manufacturing/docs/models/ManufacturingCostSummary.md +66 -0
  170. package/src/modules/manufacturing/docs/models/ProductionOrder.md +76 -0
  171. package/src/modules/manufacturing/docs/models/Routing.md +58 -0
  172. package/src/modules/manufacturing/docs/models/WorkCenter.md +56 -0
  173. package/src/modules/manufacturing/docs/models/WorkOrder.md +63 -0
  174. package/src/modules/manufacturing/docs/queries/DetectBillOfMaterialCircularReference.md +39 -0
  175. package/src/modules/manufacturing/docs/queries/ExplodeBillOfMaterial.md +56 -0
  176. package/src/modules/manufacturing/docs/queries/GetBillOfMaterial.md +37 -0
  177. package/src/modules/manufacturing/docs/queries/GetManufacturingCostSummary.md +39 -0
  178. package/src/modules/manufacturing/docs/queries/GetProductionOrder.md +37 -0
  179. package/src/modules/manufacturing/docs/queries/GetRouting.md +39 -0
  180. package/src/modules/manufacturing/docs/queries/GetWorkCenter.md +35 -0
  181. package/src/modules/manufacturing/docs/queries/GetWorkOrder.md +38 -0
  182. package/src/modules/manufacturing/docs/queries/ListBillOfMaterialsByItem.md +42 -0
  183. package/src/modules/manufacturing/docs/queries/ListManufacturingCostSummariesByStatus.md +41 -0
  184. package/src/modules/manufacturing/docs/queries/ListProductionOrdersByStatus.md +41 -0
  185. package/src/modules/manufacturing/docs/queries/ListRoutingsByItem.md +42 -0
  186. package/src/modules/manufacturing/docs/queries/ListWorkCentersBySite.md +38 -0
  187. package/src/modules/manufacturing/docs/queries/ListWorkOrdersByProductionOrder.md +39 -0
  188. package/src/modules/manufacturing/docs/queries/ListWorkOrdersByWorkCenter.md +43 -0
  189. package/src/modules/manufacturing/executor/.gitkeep +0 -0
  190. package/src/modules/manufacturing/generated/enums.ts +113 -0
  191. package/src/modules/manufacturing/generated/kysely-tailordb.ts +247 -0
  192. package/src/modules/manufacturing/index.ts +2 -0
  193. package/src/modules/manufacturing/lib/_db_deps.ts +22 -0
  194. package/src/modules/manufacturing/lib/errors.generated.ts +592 -0
  195. package/src/modules/manufacturing/lib/permissions.generated.ts +35 -0
  196. package/src/modules/manufacturing/lib/types.ts +111 -0
  197. package/src/modules/manufacturing/module.ts +226 -0
  198. package/src/modules/manufacturing/permissions.ts +3 -0
  199. package/src/modules/manufacturing/query/.gitkeep +0 -0
  200. package/src/modules/manufacturing/query/detectBillOfMaterialCircularReference.generated.ts +5 -0
  201. package/src/modules/manufacturing/query/detectBillOfMaterialCircularReference.test.ts +115 -0
  202. package/src/modules/manufacturing/query/detectBillOfMaterialCircularReference.ts +79 -0
  203. package/src/modules/manufacturing/query/explodeBillOfMaterial.generated.ts +5 -0
  204. package/src/modules/manufacturing/query/explodeBillOfMaterial.test.ts +445 -0
  205. package/src/modules/manufacturing/query/explodeBillOfMaterial.ts +306 -0
  206. package/src/modules/manufacturing/query/getBillOfMaterial.generated.ts +5 -0
  207. package/src/modules/manufacturing/query/getBillOfMaterial.test.ts +64 -0
  208. package/src/modules/manufacturing/query/getBillOfMaterial.ts +27 -0
  209. package/src/modules/manufacturing/query/getManufacturingCostSummary.generated.ts +5 -0
  210. package/src/modules/manufacturing/query/getManufacturingCostSummary.test.ts +147 -0
  211. package/src/modules/manufacturing/query/getManufacturingCostSummary.ts +46 -0
  212. package/src/modules/manufacturing/query/getProductionOrder.generated.ts +5 -0
  213. package/src/modules/manufacturing/query/getProductionOrder.test.ts +139 -0
  214. package/src/modules/manufacturing/query/getProductionOrder.ts +84 -0
  215. package/src/modules/manufacturing/query/getRouting.generated.ts +5 -0
  216. package/src/modules/manufacturing/query/getRouting.test.ts +71 -0
  217. package/src/modules/manufacturing/query/getRouting.ts +34 -0
  218. package/src/modules/manufacturing/query/getWorkCenter.generated.ts +5 -0
  219. package/src/modules/manufacturing/query/getWorkCenter.test.ts +37 -0
  220. package/src/modules/manufacturing/query/getWorkCenter.ts +21 -0
  221. package/src/modules/manufacturing/query/getWorkOrder.generated.ts +5 -0
  222. package/src/modules/manufacturing/query/getWorkOrder.test.ts +73 -0
  223. package/src/modules/manufacturing/query/getWorkOrder.ts +28 -0
  224. package/src/modules/manufacturing/query/listBillOfMaterialsByItem.generated.ts +5 -0
  225. package/src/modules/manufacturing/query/listBillOfMaterialsByItem.test.ts +107 -0
  226. package/src/modules/manufacturing/query/listBillOfMaterialsByItem.ts +58 -0
  227. package/src/modules/manufacturing/query/listManufacturingCostSummariesByStatus.generated.ts +5 -0
  228. package/src/modules/manufacturing/query/listManufacturingCostSummariesByStatus.test.ts +96 -0
  229. package/src/modules/manufacturing/query/listManufacturingCostSummariesByStatus.ts +77 -0
  230. package/src/modules/manufacturing/query/listProductionOrdersByStatus.generated.ts +5 -0
  231. package/src/modules/manufacturing/query/listProductionOrdersByStatus.test.ts +121 -0
  232. package/src/modules/manufacturing/query/listProductionOrdersByStatus.ts +83 -0
  233. package/src/modules/manufacturing/query/listRoutingsByItem.generated.ts +5 -0
  234. package/src/modules/manufacturing/query/listRoutingsByItem.test.ts +110 -0
  235. package/src/modules/manufacturing/query/listRoutingsByItem.ts +54 -0
  236. package/src/modules/manufacturing/query/listWorkCentersBySite.generated.ts +5 -0
  237. package/src/modules/manufacturing/query/listWorkCentersBySite.test.ts +81 -0
  238. package/src/modules/manufacturing/query/listWorkCentersBySite.ts +70 -0
  239. package/src/modules/manufacturing/query/listWorkOrdersByProductionOrder.generated.ts +5 -0
  240. package/src/modules/manufacturing/query/listWorkOrdersByProductionOrder.test.ts +102 -0
  241. package/src/modules/manufacturing/query/listWorkOrdersByProductionOrder.ts +53 -0
  242. package/src/modules/manufacturing/query/listWorkOrdersByWorkCenter.generated.ts +5 -0
  243. package/src/modules/manufacturing/query/listWorkOrdersByWorkCenter.test.ts +143 -0
  244. package/src/modules/manufacturing/query/listWorkOrdersByWorkCenter.ts +56 -0
  245. package/src/modules/manufacturing/seed/index.ts +19 -0
  246. package/src/modules/manufacturing/tailor.config.ts +13 -0
  247. package/src/modules/manufacturing/tailor.d.ts +13 -0
  248. package/src/modules/manufacturing/testing/commandTestUtils.ts +29 -0
  249. package/src/modules/manufacturing/testing/fixtures.ts +402 -0
  250. package/templates/scaffold/app/backend/package.json +9 -2
  251. package/templates/scaffold/app/backend/src/tests/utils/graphql-client.ts +66 -0
  252. package/templates/scaffold/app/backend/src/tests/utils/setup.ts +21 -0
  253. package/templates/scaffold/app/backend/tsconfig.json +9 -2
  254. package/templates/scaffold/app/backend/vitest.config.ts +35 -0
  255. package/templates/scaffold/app/frontend/package.json +2 -2
  256. package/templates/scaffold/module/__dot__gitignore +3 -0
  257. package/templates/scaffold/module/eslint.config.js +31 -0
  258. package/templates/scaffold/module/generated/kysely-tailordb.ts +3 -0
  259. package/templates/scaffold/module/lib/types.ts +1 -6
  260. package/templates/scaffold/module/package.json +26 -0
  261. package/templates/scaffold/module/tsconfig.json +16 -0
  262. /package/{templates/scaffold/module/generated → src/modules/manufacturing/command}/.gitkeep +0 -0
@@ -0,0 +1,111 @@
1
+ import type { DB } from "../generated/kysely-tailordb";
2
+ import type {
3
+ InferSchema,
4
+ Selectable,
5
+ Insertable,
6
+ Updateable,
7
+ } from "@tailor-platform/erp-kit/module";
8
+
9
+ export type Schema = InferSchema<DB>;
10
+
11
+ export type WorkCenter<T extends { WorkCenter: object }> = Selectable<T["WorkCenter"]>;
12
+ export type WorkCenterCreate<T extends { WorkCenter: object }> = Insertable<T["WorkCenter"]>;
13
+ export type WorkCenterUpdate<T extends { WorkCenter: object }> = Updateable<T["WorkCenter"]>;
14
+
15
+ export type Routing<T extends { Routing: object }> = Selectable<T["Routing"]>;
16
+ export type RoutingCreate<T extends { Routing: object }> = Insertable<T["Routing"]>;
17
+ export type RoutingUpdate<T extends { Routing: object }> = Updateable<T["Routing"]>;
18
+
19
+ export type RoutingOperation<T extends { RoutingOperation: object }> = Selectable<
20
+ T["RoutingOperation"]
21
+ >;
22
+ export type RoutingOperationCreate<T extends { RoutingOperation: object }> = Insertable<
23
+ T["RoutingOperation"]
24
+ >;
25
+
26
+ export type BillOfMaterial<T extends { BillOfMaterial: object }> = Selectable<T["BillOfMaterial"]>;
27
+ export type BillOfMaterialCreate<T extends { BillOfMaterial: object }> = Insertable<
28
+ T["BillOfMaterial"]
29
+ >;
30
+ export type BillOfMaterialUpdate<T extends { BillOfMaterial: object }> = Updateable<
31
+ T["BillOfMaterial"]
32
+ >;
33
+
34
+ export type BillOfMaterialLine<T extends { BillOfMaterialLine: object }> = Selectable<
35
+ T["BillOfMaterialLine"]
36
+ >;
37
+ export type BillOfMaterialLineCreate<T extends { BillOfMaterialLine: object }> = Insertable<
38
+ T["BillOfMaterialLine"]
39
+ >;
40
+
41
+ export type ProductionOrder<T extends { ProductionOrder: object }> = Selectable<
42
+ T["ProductionOrder"]
43
+ >;
44
+ export type ProductionOrderCreate<T extends { ProductionOrder: object }> = Insertable<
45
+ T["ProductionOrder"]
46
+ >;
47
+ export type ProductionOrderUpdate<T extends { ProductionOrder: object }> = Updateable<
48
+ T["ProductionOrder"]
49
+ >;
50
+
51
+ export type ProductionOrderMaterialRequirement<
52
+ T extends { ProductionOrderMaterialRequirement: object },
53
+ > = Selectable<T["ProductionOrderMaterialRequirement"]>;
54
+ export type ProductionOrderMaterialRequirementCreate<
55
+ T extends { ProductionOrderMaterialRequirement: object },
56
+ > = Insertable<T["ProductionOrderMaterialRequirement"]>;
57
+
58
+ export type ProductionOrderBomSnapshot<T extends { ProductionOrderBomSnapshot: object }> =
59
+ Selectable<T["ProductionOrderBomSnapshot"]>;
60
+ export type ProductionOrderBomSnapshotCreate<T extends { ProductionOrderBomSnapshot: object }> =
61
+ Insertable<T["ProductionOrderBomSnapshot"]>;
62
+
63
+ export type ProductionOrderRoutingSnapshot<T extends { ProductionOrderRoutingSnapshot: object }> =
64
+ Selectable<T["ProductionOrderRoutingSnapshot"]>;
65
+ export type ProductionOrderRoutingSnapshotCreate<
66
+ T extends { ProductionOrderRoutingSnapshot: object },
67
+ > = Insertable<T["ProductionOrderRoutingSnapshot"]>;
68
+
69
+ export type ProductionOrderCostBaseline<T extends { ProductionOrderCostBaseline: object }> =
70
+ Selectable<T["ProductionOrderCostBaseline"]>;
71
+ export type ProductionOrderCostBaselineCreate<T extends { ProductionOrderCostBaseline: object }> =
72
+ Insertable<T["ProductionOrderCostBaseline"]>;
73
+
74
+ export type WorkOrder<T extends { WorkOrder: object }> = Selectable<T["WorkOrder"]>;
75
+ export type WorkOrderCreate<T extends { WorkOrder: object }> = Insertable<T["WorkOrder"]>;
76
+ export type WorkOrderUpdate<T extends { WorkOrder: object }> = Updateable<T["WorkOrder"]>;
77
+
78
+ export type WorkOrderExecutionEvent<T extends { WorkOrderExecutionEvent: object }> = Selectable<
79
+ T["WorkOrderExecutionEvent"]
80
+ >;
81
+ export type WorkOrderExecutionEventCreate<T extends { WorkOrderExecutionEvent: object }> =
82
+ Insertable<T["WorkOrderExecutionEvent"]>;
83
+
84
+ export type ManufacturingCostSummary<T extends { ManufacturingCostSummary: object }> = Selectable<
85
+ T["ManufacturingCostSummary"]
86
+ >;
87
+ export type ManufacturingCostSummaryCreate<T extends { ManufacturingCostSummary: object }> =
88
+ Insertable<T["ManufacturingCostSummary"]>;
89
+ export type ManufacturingCostSummaryUpdate<T extends { ManufacturingCostSummary: object }> =
90
+ Updateable<T["ManufacturingCostSummary"]>;
91
+
92
+ export type ManufacturingCostLine<T extends { ManufacturingCostLine: object }> = Selectable<
93
+ T["ManufacturingCostLine"]
94
+ >;
95
+ export type ManufacturingCostLineCreate<T extends { ManufacturingCostLine: object }> = Insertable<
96
+ T["ManufacturingCostLine"]
97
+ >;
98
+
99
+ export type CostVarianceLine<T extends { CostVarianceLine: object }> = Selectable<
100
+ T["CostVarianceLine"]
101
+ >;
102
+ export type CostVarianceLineCreate<T extends { CostVarianceLine: object }> = Insertable<
103
+ T["CostVarianceLine"]
104
+ >;
105
+
106
+ export type ManufacturingCostSettlementRecord<
107
+ T extends { ManufacturingCostSettlementRecord: object },
108
+ > = Selectable<T["ManufacturingCostSettlementRecord"]>;
109
+ export type ManufacturingCostSettlementRecordCreate<
110
+ T extends { ManufacturingCostSettlementRecord: object },
111
+ > = Insertable<T["ManufacturingCostSettlementRecord"]>;
@@ -0,0 +1,226 @@
1
+ import { type TailorAnyDBField } from "@tailor-platform/sdk";
2
+ import type { defineModule as defineOrganizationModule } from "../organization";
3
+ import type { defineModule as defineItemManagementModule } from "../item-management";
4
+ import { createWorkCenterType, type CreateWorkCenterTypeParams } from "./db/workCenter";
5
+ import { createRoutingType } from "./db/routing";
6
+ import { createRoutingOperationType } from "./db/routingOperation";
7
+ import { createBillOfMaterialType } from "./db/billOfMaterial";
8
+ import { createBillOfMaterialLineType } from "./db/billOfMaterialLine";
9
+ import { createProductionOrderType } from "./db/productionOrder";
10
+ import { createProductionOrderMaterialRequirementType } from "./db/productionOrderMaterialRequirement";
11
+ import { createProductionOrderBomSnapshotType } from "./db/productionOrderBomSnapshot";
12
+ import { createProductionOrderRoutingSnapshotType } from "./db/productionOrderRoutingSnapshot";
13
+ import { createProductionOrderCostBaselineType } from "./db/productionOrderCostBaseline";
14
+ import { createWorkOrderType } from "./db/workOrder";
15
+ import { createWorkOrderExecutionEventType } from "./db/workOrderExecutionEvent";
16
+ import { createManufacturingCostSummaryType } from "./db/manufacturingCostSummary";
17
+ import { createManufacturingCostLineType } from "./db/manufacturingCostLine";
18
+ import { createCostVarianceLineType } from "./db/costVarianceLine";
19
+ import { createManufacturingCostSettlementRecordType } from "./db/manufacturingCostSettlementRecord";
20
+ // Commands
21
+ import { createWorkCenter } from "./command/createWorkCenter.generated";
22
+ import { updateWorkCenter } from "./command/updateWorkCenter.generated";
23
+ import { activateWorkCenter } from "./command/activateWorkCenter.generated";
24
+ import { deactivateWorkCenter } from "./command/deactivateWorkCenter.generated";
25
+ import { createRouting } from "./command/createRouting.generated";
26
+ import { updateRouting } from "./command/updateRouting.generated";
27
+ import { activateRouting } from "./command/activateRouting.generated";
28
+ import { deactivateRouting } from "./command/deactivateRouting.generated";
29
+ import { createBillOfMaterial } from "./command/createBillOfMaterial.generated";
30
+ import { updateBillOfMaterial } from "./command/updateBillOfMaterial.generated";
31
+ import { activateBillOfMaterial } from "./command/activateBillOfMaterial.generated";
32
+ import { deactivateBillOfMaterial } from "./command/deactivateBillOfMaterial.generated";
33
+ import { createProductionOrder } from "./command/createProductionOrder.generated";
34
+ import { updateProductionOrder } from "./command/updateProductionOrder.generated";
35
+ import { releaseProductionOrder } from "./command/releaseProductionOrder.generated";
36
+ import { unreleaseProductionOrder } from "./command/unreleaseProductionOrder.generated";
37
+ import { rescheduleProductionOrder } from "./command/rescheduleProductionOrder.generated";
38
+ import { cancelProductionOrder } from "./command/cancelProductionOrder.generated";
39
+ import { reopenProductionOrder } from "./command/reopenProductionOrder.generated";
40
+ import { completeProductionOrder } from "./command/completeProductionOrder.generated";
41
+ import { technicallyCompleteProductionOrder } from "./command/technicallyCompleteProductionOrder.generated";
42
+ import { closeProductionOrder } from "./command/closeProductionOrder.generated";
43
+ import { startWorkOrder } from "./command/startWorkOrder.generated";
44
+ import { pauseWorkOrder } from "./command/pauseWorkOrder.generated";
45
+ import { resumeWorkOrder } from "./command/resumeWorkOrder.generated";
46
+ import { completeWorkOrder } from "./command/completeWorkOrder.generated";
47
+ import { reportWorkOrderProgress } from "./command/reportWorkOrderProgress.generated";
48
+ import { recordInventoryIssueOutcome } from "./command/recordInventoryIssueOutcome.generated";
49
+ import { reviewManufacturingCostSummary } from "./command/reviewManufacturingCostSummary.generated";
50
+ import { recordManufacturingCostSettlementAcknowledgment } from "./command/recordManufacturingCostSettlementAcknowledgment.generated";
51
+ // Queries
52
+ import { getWorkCenter } from "./query/getWorkCenter.generated";
53
+ import { listWorkCentersBySite } from "./query/listWorkCentersBySite.generated";
54
+ import { getRouting } from "./query/getRouting.generated";
55
+ import { listRoutingsByItem } from "./query/listRoutingsByItem.generated";
56
+ import { getBillOfMaterial } from "./query/getBillOfMaterial.generated";
57
+ import { listBillOfMaterialsByItem } from "./query/listBillOfMaterialsByItem.generated";
58
+ import { detectBillOfMaterialCircularReference } from "./query/detectBillOfMaterialCircularReference.generated";
59
+ import { explodeBillOfMaterial } from "./query/explodeBillOfMaterial.generated";
60
+ import { getProductionOrder } from "./query/getProductionOrder.generated";
61
+ import { listProductionOrdersByStatus } from "./query/listProductionOrdersByStatus.generated";
62
+ import { getWorkOrder } from "./query/getWorkOrder.generated";
63
+ import { listWorkOrdersByProductionOrder } from "./query/listWorkOrdersByProductionOrder.generated";
64
+ import { listWorkOrdersByWorkCenter } from "./query/listWorkOrdersByWorkCenter.generated";
65
+ import { getManufacturingCostSummary } from "./query/getManufacturingCostSummary.generated";
66
+ import { listManufacturingCostSummariesByStatus } from "./query/listManufacturingCostSummariesByStatus.generated";
67
+ import { type EmptyFields, type FieldsToInsertable } from "@tailor-platform/erp-kit/module";
68
+
69
+ type OrganizationModule = ReturnType<typeof defineOrganizationModule>;
70
+ type OrganizationDB = OrganizationModule["db"];
71
+
72
+ type ItemManagementModule = ReturnType<typeof defineItemManagementModule>;
73
+ type ItemManagementDB = ItemManagementModule["db"];
74
+
75
+ export interface DefineModuleParams<WCF extends Record<string, TailorAnyDBField>> {
76
+ workCenter?: Omit<CreateWorkCenterTypeParams<WCF>, "companyType" | "siteType">;
77
+ organization: {
78
+ db: { company: OrganizationDB["company"]; site: OrganizationDB["site"] };
79
+ };
80
+ itemManagement: {
81
+ db: { item: ItemManagementDB["item"] };
82
+ };
83
+ }
84
+
85
+ export const defineModule = <const WCF extends Record<string, TailorAnyDBField> = EmptyFields>(
86
+ params: DefineModuleParams<WCF>,
87
+ ) => {
88
+ const companyType = params.organization.db.company;
89
+ const siteType = params.organization.db.site;
90
+ const itemType = params.itemManagement.db.item;
91
+
92
+ // Master data
93
+ const workCenter = createWorkCenterType({
94
+ ...params.workCenter,
95
+ companyType,
96
+ siteType,
97
+ });
98
+ const routing = createRoutingType({ companyType, siteType, itemType });
99
+ const routingOperation = createRoutingOperationType({
100
+ routingType: routing,
101
+ workCenterType: workCenter,
102
+ });
103
+ const billOfMaterial = createBillOfMaterialType({
104
+ companyType,
105
+ siteType,
106
+ itemType,
107
+ });
108
+ const billOfMaterialLine = createBillOfMaterialLineType({
109
+ billOfMaterialType: billOfMaterial,
110
+ itemType,
111
+ });
112
+
113
+ // Production orders
114
+ const productionOrder = createProductionOrderType({
115
+ companyType,
116
+ siteType,
117
+ itemType,
118
+ });
119
+ const productionOrderMaterialRequirement = createProductionOrderMaterialRequirementType({
120
+ productionOrderType: productionOrder,
121
+ itemType,
122
+ });
123
+ const productionOrderBomSnapshot = createProductionOrderBomSnapshotType({
124
+ productionOrderType: productionOrder,
125
+ });
126
+ const productionOrderRoutingSnapshot = createProductionOrderRoutingSnapshotType({
127
+ productionOrderType: productionOrder,
128
+ });
129
+ const productionOrderCostBaseline = createProductionOrderCostBaselineType({
130
+ productionOrderType: productionOrder,
131
+ });
132
+
133
+ // Work orders
134
+ const workOrder = createWorkOrderType({
135
+ productionOrderType: productionOrder,
136
+ workCenterType: workCenter,
137
+ });
138
+ const workOrderExecutionEvent = createWorkOrderExecutionEventType({
139
+ workOrderType: workOrder,
140
+ });
141
+
142
+ // Cost management
143
+ const manufacturingCostSummary = createManufacturingCostSummaryType({
144
+ productionOrderType: productionOrder,
145
+ });
146
+ const manufacturingCostLine = createManufacturingCostLineType({
147
+ costSummaryType: manufacturingCostSummary,
148
+ });
149
+ const costVarianceLine = createCostVarianceLineType({
150
+ costSummaryType: manufacturingCostSummary,
151
+ });
152
+ const manufacturingCostSettlementRecord = createManufacturingCostSettlementRecordType({
153
+ costSummaryType: manufacturingCostSummary,
154
+ });
155
+
156
+ return {
157
+ db: {
158
+ workCenter,
159
+ routing,
160
+ routingOperation,
161
+ billOfMaterial,
162
+ billOfMaterialLine,
163
+ productionOrder,
164
+ productionOrderMaterialRequirement,
165
+ productionOrderBomSnapshot,
166
+ productionOrderRoutingSnapshot,
167
+ productionOrderCostBaseline,
168
+ workOrder,
169
+ workOrderExecutionEvent,
170
+ manufacturingCostSummary,
171
+ manufacturingCostLine,
172
+ costVarianceLine,
173
+ manufacturingCostSettlementRecord,
174
+ },
175
+ queries: {
176
+ getWorkCenter,
177
+ listWorkCentersBySite,
178
+ getRouting,
179
+ listRoutingsByItem,
180
+ getBillOfMaterial,
181
+ listBillOfMaterialsByItem,
182
+ detectBillOfMaterialCircularReference,
183
+ explodeBillOfMaterial,
184
+ getProductionOrder,
185
+ listProductionOrdersByStatus,
186
+ getWorkOrder,
187
+ listWorkOrdersByProductionOrder,
188
+ listWorkOrdersByWorkCenter,
189
+ getManufacturingCostSummary,
190
+ listManufacturingCostSummariesByStatus,
191
+ },
192
+ commands: {
193
+ createWorkCenter: createWorkCenter<FieldsToInsertable<WCF>>(),
194
+ updateWorkCenter: updateWorkCenter(),
195
+ activateWorkCenter: activateWorkCenter(),
196
+ deactivateWorkCenter: deactivateWorkCenter(),
197
+ createRouting: createRouting(),
198
+ updateRouting: updateRouting(),
199
+ activateRouting: activateRouting(),
200
+ deactivateRouting: deactivateRouting(),
201
+ createBillOfMaterial: createBillOfMaterial(),
202
+ updateBillOfMaterial: updateBillOfMaterial(),
203
+ activateBillOfMaterial: activateBillOfMaterial(),
204
+ deactivateBillOfMaterial: deactivateBillOfMaterial(),
205
+ createProductionOrder: createProductionOrder(),
206
+ updateProductionOrder: updateProductionOrder(),
207
+ releaseProductionOrder: releaseProductionOrder(),
208
+ unreleaseProductionOrder: unreleaseProductionOrder(),
209
+ rescheduleProductionOrder: rescheduleProductionOrder(),
210
+ cancelProductionOrder: cancelProductionOrder(),
211
+ reopenProductionOrder: reopenProductionOrder(),
212
+ completeProductionOrder: completeProductionOrder(),
213
+ technicallyCompleteProductionOrder: technicallyCompleteProductionOrder(),
214
+ closeProductionOrder: closeProductionOrder(),
215
+ startWorkOrder: startWorkOrder(),
216
+ pauseWorkOrder: pauseWorkOrder(),
217
+ resumeWorkOrder: resumeWorkOrder(),
218
+ completeWorkOrder: completeWorkOrder(),
219
+ reportWorkOrderProgress: reportWorkOrderProgress(),
220
+ recordInventoryIssueOutcome: recordInventoryIssueOutcome(),
221
+ reviewManufacturingCostSummary: reviewManufacturingCostSummary(),
222
+ recordManufacturingCostSettlementAcknowledgment:
223
+ recordManufacturingCostSettlementAcknowledgment(),
224
+ },
225
+ };
226
+ };
@@ -0,0 +1,3 @@
1
+ import { definePermissions } from "@tailor-platform/erp-kit/module";
2
+
3
+ export const { permissions, own, all } = definePermissions("manufacturing", [] as const);
File without changes
@@ -0,0 +1,5 @@
1
+ // @generated — do not edit
2
+ import { run } from "./detectBillOfMaterialCircularReference";
3
+ import { defineQuery } from "@tailor-platform/erp-kit/module";
4
+
5
+ export const detectBillOfMaterialCircularReference = defineQuery(run);
@@ -0,0 +1,115 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { createMockDb } from "../../../testing/index";
3
+ import type { DB } from "../generated/kysely-tailordb";
4
+ import { expectOk, expectErr } from "../testing/commandTestUtils";
5
+ import { CompanyScopeRequiredError, ItemReferenceRequiredError } from "../lib/errors.generated";
6
+ import { run } from "./detectBillOfMaterialCircularReference";
7
+
8
+ describe("detectBillOfMaterialCircularReference", () => {
9
+ it("detects a direct BOM loop", async () => {
10
+ const { db, spies } = createMockDb<DB>();
11
+ // B has an active BOM with a subassembly line pointing back to A
12
+ spies.select.mockReturnValueOnce([{ id: "bom-b" }]); // active BOMs for B
13
+ spies.select.mockReturnValueOnce([{ itemId: "item-1" }]); // subassembly lines -> back to A
14
+
15
+ const result = await run(db, {
16
+ companyId: "company-1",
17
+ parentItemId: "item-1",
18
+ childItemId: "item-2",
19
+ });
20
+ const value = expectOk<{
21
+ hasCircularReference: boolean;
22
+ path: string[];
23
+ }>(result as never);
24
+
25
+ expect(value.hasCircularReference).toBe(true);
26
+ expect(value.path).toContain("item-1");
27
+ expect(value.path).toContain("item-2");
28
+ });
29
+
30
+ it("detects an indirect BOM loop across multiple subassemblies", async () => {
31
+ const { db, spies } = createMockDb<DB>();
32
+ // A -> B -> C -> A (circular)
33
+ // B has active BOM with subassembly line to C
34
+ spies.select.mockReturnValueOnce([{ id: "bom-b" }]); // active BOMs for B
35
+ spies.select.mockReturnValueOnce([{ itemId: "item-3" }]); // subassembly lines -> C
36
+ // C has active BOM with subassembly line back to A
37
+ spies.select.mockReturnValueOnce([{ id: "bom-c" }]); // active BOMs for C
38
+ spies.select.mockReturnValueOnce([{ itemId: "item-1" }]); // subassembly lines -> A (circular!)
39
+
40
+ const result = await run(db, {
41
+ companyId: "company-1",
42
+ parentItemId: "item-1",
43
+ childItemId: "item-2",
44
+ });
45
+ const value = expectOk<{
46
+ hasCircularReference: boolean;
47
+ path: string[];
48
+ }>(result as never);
49
+
50
+ expect(value.hasCircularReference).toBe(true);
51
+ expect(value.path).toContain("item-1");
52
+ });
53
+
54
+ it("returns no loop when the graph is acyclic", async () => {
55
+ const { db, spies } = createMockDb<DB>();
56
+ // B has active BOM with subassembly line to C (not A)
57
+ spies.select.mockReturnValueOnce([{ id: "bom-b" }]); // active BOMs for B
58
+ spies.select.mockReturnValueOnce([{ itemId: "item-3" }]); // subassembly lines -> C
59
+ // C has no active BOMs (leaf node)
60
+ spies.select.mockReturnValueOnce([]); // active BOMs for C - none
61
+
62
+ const result = await run(db, {
63
+ companyId: "company-1",
64
+ parentItemId: "item-1",
65
+ childItemId: "item-2",
66
+ });
67
+ const value = expectOk<{
68
+ hasCircularReference: boolean;
69
+ path: string[] | null;
70
+ }>(result as never);
71
+
72
+ expect(value.hasCircularReference).toBe(false);
73
+ expect(value.path).toBeNull();
74
+ });
75
+
76
+ it("scopes detection to the requested company", async () => {
77
+ const { db, spies } = createMockDb<DB>();
78
+ // No active BOMs found for this company scope
79
+ spies.select.mockReturnValueOnce([]); // no active BOMs for B in company-2
80
+
81
+ const result = await run(db, {
82
+ companyId: "company-2",
83
+ parentItemId: "item-1",
84
+ childItemId: "item-2",
85
+ });
86
+ const value = expectOk<{
87
+ hasCircularReference: boolean;
88
+ path: string[] | null;
89
+ }>(result as never);
90
+
91
+ expect(value.hasCircularReference).toBe(false);
92
+ });
93
+
94
+ it("returns error when parent or child reference is missing", async () => {
95
+ const { db } = createMockDb<DB>();
96
+
97
+ const result = await run(db, {
98
+ companyId: "company-1",
99
+ parentItemId: "item-1",
100
+ childItemId: "",
101
+ });
102
+ expectErr(result as never, ItemReferenceRequiredError);
103
+ });
104
+
105
+ it("returns error when company scope is missing", async () => {
106
+ const { db } = createMockDb<DB>();
107
+
108
+ const result = await run(db, {
109
+ companyId: "",
110
+ parentItemId: "item-1",
111
+ childItemId: "item-2",
112
+ });
113
+ expectErr(result as never, CompanyScopeRequiredError);
114
+ });
115
+ });
@@ -0,0 +1,79 @@
1
+ import type { DB } from "../generated/kysely-tailordb";
2
+ import { CompanyScopeRequiredError, ItemReferenceRequiredError } from "../lib/errors.generated";
3
+ import { ok, err, type ReadonlyDB } from "@tailor-platform/erp-kit/module";
4
+
5
+ export interface DetectBillOfMaterialCircularReferenceInput {
6
+ companyId: string;
7
+ parentItemId: string;
8
+ childItemId: string;
9
+ }
10
+
11
+ export async function run(db: ReadonlyDB<DB>, input: DetectBillOfMaterialCircularReferenceInput) {
12
+ if (!input.companyId) {
13
+ return err(new CompanyScopeRequiredError("companyId"));
14
+ }
15
+
16
+ if (!input.parentItemId || !input.childItemId) {
17
+ return err(new ItemReferenceRequiredError("parentItemId and childItemId"));
18
+ }
19
+
20
+ // If child === parent, immediate circular reference
21
+ if (input.childItemId === input.parentItemId) {
22
+ return ok({
23
+ hasCircularReference: true,
24
+ path: [input.parentItemId, input.childItemId],
25
+ });
26
+ }
27
+
28
+ // BFS from childItemId through active BOMs to see if any path reaches parentItemId
29
+ const visited = new Set<string>();
30
+ const queue: { itemId: string; path: string[] }[] = [
31
+ { itemId: input.childItemId, path: [input.parentItemId, input.childItemId] },
32
+ ];
33
+
34
+ while (queue.length > 0) {
35
+ const current = queue.shift()!;
36
+
37
+ if (visited.has(current.itemId)) {
38
+ continue;
39
+ }
40
+ visited.add(current.itemId);
41
+
42
+ // Find active BOMs where this item is the parent
43
+ const activeBoms = await db
44
+ .selectFrom("BillOfMaterial")
45
+ .select("id")
46
+ .where("parentItemId", "=", current.itemId)
47
+ .where("companyId", "=", input.companyId)
48
+ .where("status", "=", "ACTIVE")
49
+ .execute();
50
+
51
+ if (activeBoms.length === 0) {
52
+ continue;
53
+ }
54
+
55
+ const bomIds = activeBoms.map((b) => b.id);
56
+
57
+ // Find subassembly lines for these BOMs
58
+ const subassemblyLines = await db
59
+ .selectFrom("BillOfMaterialLine")
60
+ .select("itemId")
61
+ .where("billOfMaterialId", "in", bomIds)
62
+ .where("isSubassembly", "=", true)
63
+ .execute();
64
+
65
+ for (const line of subassemblyLines) {
66
+ const newPath = [...current.path, line.itemId];
67
+
68
+ if (line.itemId === input.parentItemId) {
69
+ return ok({ hasCircularReference: true, path: newPath });
70
+ }
71
+
72
+ if (!visited.has(line.itemId)) {
73
+ queue.push({ itemId: line.itemId, path: newPath });
74
+ }
75
+ }
76
+ }
77
+
78
+ return ok({ hasCircularReference: false, path: null });
79
+ }
@@ -0,0 +1,5 @@
1
+ // @generated — do not edit
2
+ import { run } from "./explodeBillOfMaterial";
3
+ import { defineQuery } from "@tailor-platform/erp-kit/module";
4
+
5
+ export const explodeBillOfMaterial = defineQuery(run);