@rytass/wms-module-core 0.8.1 → 0.9.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 (73) hide show
  1. package/index.cjs.js +1689 -199
  2. package/index.js +11 -1
  3. package/lib/constants/consumption-change-kind.d.ts +17 -0
  4. package/lib/constants/consumption-change-kind.js +20 -0
  5. package/lib/constants/index.d.ts +2 -0
  6. package/lib/constants/operations.d.ts +1 -1
  7. package/lib/constants/operations.js +9 -0
  8. package/lib/constants/order-type.d.ts +30 -0
  9. package/lib/constants/order-type.js +33 -0
  10. package/lib/constants/stock-status.d.ts +4 -1
  11. package/lib/constants/stock-status.js +6 -0
  12. package/lib/core.module.js +87 -3
  13. package/lib/events/index.d.ts +2 -1
  14. package/lib/events/stock-change.subscriber.d.ts +26 -1
  15. package/lib/events/stock-change.subscriber.js +98 -15
  16. package/lib/events/wms-event.tokens.d.ts +2 -0
  17. package/lib/events/wms-event.tokens.js +3 -1
  18. package/lib/events/wms-event.types.d.ts +38 -6
  19. package/lib/events/wms-operation-runner.d.ts +57 -0
  20. package/lib/events/wms-operation-runner.js +101 -0
  21. package/lib/models/extensions/consumption-order/consumption-order-change.entity.d.ts +19 -0
  22. package/lib/models/extensions/consumption-order/consumption-order-change.entity.js +59 -0
  23. package/lib/models/extensions/consumption-order/consumption-order-item.entity.d.ts +26 -0
  24. package/lib/models/extensions/consumption-order/consumption-order-item.entity.js +114 -0
  25. package/lib/models/extensions/consumption-order/consumption-order.entity.d.ts +32 -0
  26. package/lib/models/extensions/consumption-order/consumption-order.entity.js +69 -0
  27. package/lib/models/extensions/consumption-order/index.d.ts +3 -0
  28. package/lib/models/extensions/index.d.ts +4 -0
  29. package/lib/models/extensions/inventory-count-order/inventory-count-order-item.entity.d.ts +13 -1
  30. package/lib/models/extensions/inventory-count-order/inventory-count-order-item.entity.js +17 -1
  31. package/lib/models/extensions/order-reference/index.d.ts +1 -0
  32. package/lib/models/extensions/order-reference/order-reference.entity.d.ts +49 -0
  33. package/lib/models/extensions/order-reference/order-reference.entity.js +95 -0
  34. package/lib/models/metadata/batch.entity.d.ts +46 -0
  35. package/lib/models/metadata/batch.entity.js +58 -0
  36. package/lib/models/models.module.js +8 -0
  37. package/lib/services/allocate-inventory-order.service.js +4 -0
  38. package/lib/services/base-order.service.d.ts +18 -3
  39. package/lib/services/base-order.service.js +76 -0
  40. package/lib/services/batch.service.d.ts +17 -0
  41. package/lib/services/batch.service.js +41 -1
  42. package/lib/services/consumption-order.service.d.ts +75 -0
  43. package/lib/services/consumption-order.service.js +504 -0
  44. package/lib/services/hold-inventory-order.service.js +4 -0
  45. package/lib/services/index.d.ts +3 -0
  46. package/lib/services/inventory-count-order.service.js +7 -0
  47. package/lib/services/loader.service.js +4 -0
  48. package/lib/services/location.service.js +4 -0
  49. package/lib/services/material.service.js +4 -0
  50. package/lib/services/merge-batch-order.service.js +4 -0
  51. package/lib/services/order-reference.service.d.ts +50 -0
  52. package/lib/services/order-reference.service.js +136 -0
  53. package/lib/services/quality-inspection-order.service.js +4 -0
  54. package/lib/services/receive-inventory-order.service.js +132 -78
  55. package/lib/services/reclassify-inventory-order.service.js +4 -0
  56. package/lib/services/scrape.service.js +4 -0
  57. package/lib/services/ship-inventory-order.service.js +4 -0
  58. package/lib/services/split-batch-order.service.js +69 -46
  59. package/lib/services/stock.service.js +32 -2
  60. package/lib/services/transfer-customer-order.service.js +4 -0
  61. package/lib/services/transfer-order.service.js +4 -0
  62. package/lib/services/transfer-vendor-order.service.js +4 -0
  63. package/lib/services/unit.service.js +4 -0
  64. package/lib/typings/aggregated-stock.d.ts +6 -0
  65. package/lib/typings/consumption-order.input.d.ts +72 -0
  66. package/lib/typings/core-module-options.d.ts +34 -1
  67. package/lib/typings/custom-change-table.d.ts +70 -0
  68. package/lib/typings/find-stock.input.d.ts +14 -0
  69. package/lib/typings/get-batch.input.d.ts +16 -0
  70. package/lib/typings/index.d.ts +3 -0
  71. package/lib/typings/order-reference.input.d.ts +28 -0
  72. package/lib/typings/split-batch.input.d.ts +11 -0
  73. package/package.json +1 -1
package/index.js CHANGED
@@ -52,6 +52,11 @@ export { ScrapeOrderChangeEntity, ScrapeOrderChangeEntityClass } from './lib/mod
52
52
  export { InventoryCountOrderEntity, InventoryCountOrderEntityClass, InventoryCountOrderLocationEntity, InventoryCountOrderLocationEntityClass } from './lib/models/extensions/inventory-count-order/inventory-count-order.entity.js';
53
53
  export { InventoryCountOrderItemEntity, InventoryCountOrderItemEntityClass } from './lib/models/extensions/inventory-count-order/inventory-count-order-item.entity.js';
54
54
  export { InventoryCountOrderChangeEntity, InventoryCountOrderChangeEntityClass } from './lib/models/extensions/inventory-count-order/inventory-count-order-change.entity.js';
55
+ export { ConsumptionOrderEntity, ConsumptionOrderEntityClass } from './lib/models/extensions/consumption-order/consumption-order.entity.js';
56
+ export { ConsumptionOrderItemEntity, ConsumptionOrderItemEntityClass } from './lib/models/extensions/consumption-order/consumption-order-item.entity.js';
57
+ export { ConsumptionOrderChangeEntity, ConsumptionOrderChangeEntityClass } from './lib/models/extensions/consumption-order/consumption-order-change.entity.js';
58
+ export { OrderReferenceEntity, OrderReferenceEntityClass } from './lib/models/extensions/order-reference/order-reference.entity.js';
59
+ export { BaseOrderService } from './lib/services/base-order.service.js';
55
60
  export { StockService } from './lib/services/stock.service.js';
56
61
  export { LoaderService } from './lib/services/loader.service.js';
57
62
  export { MaterialService } from './lib/services/material.service.js';
@@ -65,6 +70,8 @@ export { HoldInventoryOrderService } from './lib/services/hold-inventory-order.s
65
70
  export { AllocateInventoryOrderService } from './lib/services/allocate-inventory-order.service.js';
66
71
  export { SplitBatchOrderService } from './lib/services/split-batch-order.service.js';
67
72
  export { MergeBatchOrderService } from './lib/services/merge-batch-order.service.js';
73
+ export { ConsumptionOrderService } from './lib/services/consumption-order.service.js';
74
+ export { OrderReferenceService } from './lib/services/order-reference.service.js';
68
75
  export { ReclassifyInventoryOrderService } from './lib/services/reclassify-inventory-order.service.js';
69
76
  export { TransferVendorOrderService } from './lib/services/transfer-vendor-order.service.js';
70
77
  export { QualityInspectionOrderService } from './lib/services/quality-inspection-order.service.js';
@@ -77,12 +84,15 @@ export { HelperService } from './lib/services/helper.service.js';
77
84
  export { WMS_CORE_MODULE_OPTIONS } from './lib/typings/core-module-options.js';
78
85
  export { ReceiveInventoryOrderStatus } from './lib/typings/find-receive-inventory-order.input.js';
79
86
  export { ShipInventoryOrderStatus } from './lib/typings/find-ship-inventory-order.input.js';
87
+ export { ConsumptionChangeKind } from './lib/constants/consumption-change-kind.js';
80
88
  export { InventoryCountStatus } from './lib/constants/inventory-count-status.js';
81
89
  export { WMS_OPERATION_NAMES } from './lib/constants/operations.js';
90
+ export { WmsOrderType } from './lib/constants/order-type.js';
82
91
  export { ChangeType, StockStatus } from './lib/constants/stock-status.js';
83
- export { WMS_ACTOR_EXTRACTOR, WMS_EVENT_EMITTER_BRIDGE, WMS_EVENT_OPTIONS, WMS_STOCK_ENRICH } from './lib/events/wms-event.tokens.js';
92
+ export { WMS_ACTOR_EXTRACTOR, WMS_CUSTOM_CHANGE_TABLES, WMS_EVENT_EMITTER_BRIDGE, WMS_EVENT_OPTIONS, WMS_STOCK_ENRICH } from './lib/events/wms-event.tokens.js';
84
93
  export { WmsEventCollector } from './lib/events/wms-event.collector.js';
85
94
  export { WmsEventDispatcher } from './lib/events/wms-event.dispatcher.js';
95
+ export { WmsOperationRunner } from './lib/events/wms-operation-runner.js';
86
96
  export { collectToScope, runInDispatchScope } from './lib/events/dispatch-scope.js';
87
97
  export { InventoryCountLockSubscriber } from './lib/events/inventory-count-lock.subscriber.js';
88
98
  export { OrderEntity as OrderEntityClass } from '@rytass/wms-base-nestjs-module';
@@ -0,0 +1,17 @@
1
+ /**
2
+ * What a `consumption_order_changes` row records.
3
+ *
4
+ * The three actions cannot be told apart by the sign of `quantityChanged`
5
+ * alone, which is how every other change table in this package encodes
6
+ * direction: a return and a settlement are both negative, and the difference
7
+ * between "it came back to the shelf" and "it is gone" is the entire point of
8
+ * the order. So the intent is stored rather than inferred.
9
+ */
10
+ export declare enum ConsumptionChangeKind {
11
+ /** Material left the shelf for the consuming location. */
12
+ ISSUE = "ISSUE",
13
+ /** Material came back from the consuming location, unused. */
14
+ RETURN = "RETURN",
15
+ /** Material at the consuming location was used up and left inventory. */
16
+ SETTLE = "SETTLE"
17
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * What a `consumption_order_changes` row records.
3
+ *
4
+ * The three actions cannot be told apart by the sign of `quantityChanged`
5
+ * alone, which is how every other change table in this package encodes
6
+ * direction: a return and a settlement are both negative, and the difference
7
+ * between "it came back to the shelf" and "it is gone" is the entire point of
8
+ * the order. So the intent is stored rather than inferred.
9
+ */
10
+ var ConsumptionChangeKind;
11
+ (function (ConsumptionChangeKind) {
12
+ /** Material left the shelf for the consuming location. */
13
+ ConsumptionChangeKind["ISSUE"] = "ISSUE";
14
+ /** Material came back from the consuming location, unused. */
15
+ ConsumptionChangeKind["RETURN"] = "RETURN";
16
+ /** Material at the consuming location was used up and left inventory. */
17
+ ConsumptionChangeKind["SETTLE"] = "SETTLE";
18
+ })(ConsumptionChangeKind || (ConsumptionChangeKind = {}));
19
+
20
+ export { ConsumptionChangeKind };
@@ -1,3 +1,5 @@
1
+ export * from './consumption-change-kind';
1
2
  export * from './inventory-count-status';
2
3
  export * from './operations';
4
+ export * from './order-type';
3
5
  export * from './stock-status';
@@ -26,7 +26,7 @@
26
26
  * `loader:create` 3 each, and 7 more cover 2). Disabling a name disables every
27
27
  * field carrying it — use `disabledFields` when you need finer granularity.
28
28
  */
29
- export type WmsOperationName = 'allocate-inventory-order:create' | 'allocate-inventory-order:deallocate' | 'allocate-inventory-order:read' | 'allocate-inventory-order:update' | 'batch:merge' | 'batch:read' | 'batch:split' | 'hold-inventory-order:create' | 'hold-inventory-order:read' | 'hold-inventory-order:release' | 'hold-inventory-order:update' | 'inventory-count-order:add-item' | 'inventory-count-order:cancel' | 'inventory-count-order:count' | 'inventory-count-order:create' | 'inventory-count-order:read' | 'inventory-count-order:read-items' | 'inventory-count-order:remove-item' | 'inventory-count-order:reset' | 'inventory-count-order:settle' | 'inventory-count-order:start' | 'inventory-count-order:update' | 'loader:create' | 'loader:read' | 'loader:update' | 'location:create' | 'location:read' | 'location:update' | 'material:create' | 'material:read' | 'material:update' | 'quality-inspection-order:inspect' | 'receive-inventory-order:create' | 'receive-inventory-order:read' | 'receive-inventory-order:receive' | 'receive-inventory-order:update' | 'reclassify-inventory-order:reclassify' | 'sale-order:read' | 'scrape-order:scrape' | 'ship-inventory-order:cancel' | 'ship-inventory-order:create' | 'ship-inventory-order:read' | 'ship-inventory-order:ship' | 'ship-inventory-order:update' | 'stock:read' | 'transfer-customer-order:create' | 'transfer-customer-order:return' | 'transfer-customer-order:update' | 'transfer-order:cancel' | 'transfer-order:create' | 'transfer-order:read' | 'transfer-order:transfer' | 'transfer-order:update' | 'transfer-vendor-order:create' | 'transfer-vendor-order:return' | 'transfer-vendor-order:update' | 'unit:read' | 'warehouse-map:read' | 'warehouse-map:update';
29
+ export type WmsOperationName = 'allocate-inventory-order:create' | 'allocate-inventory-order:deallocate' | 'allocate-inventory-order:read' | 'allocate-inventory-order:update' | 'batch:merge' | 'batch:read' | 'batch:split' | 'consumption-order:create' | 'consumption-order:issue' | 'consumption-order:read' | 'consumption-order:return' | 'consumption-order:settle' | 'consumption-order:update' | 'hold-inventory-order:create' | 'hold-inventory-order:read' | 'hold-inventory-order:release' | 'hold-inventory-order:update' | 'inventory-count-order:add-item' | 'inventory-count-order:cancel' | 'inventory-count-order:count' | 'inventory-count-order:create' | 'inventory-count-order:read' | 'inventory-count-order:read-items' | 'inventory-count-order:remove-item' | 'inventory-count-order:reset' | 'inventory-count-order:settle' | 'inventory-count-order:start' | 'inventory-count-order:update' | 'loader:create' | 'loader:read' | 'loader:update' | 'location:create' | 'location:read' | 'location:update' | 'material:create' | 'material:read' | 'material:update' | 'order-reference:attach' | 'order-reference:detach' | 'order-reference:read' | 'quality-inspection-order:inspect' | 'receive-inventory-order:create' | 'receive-inventory-order:read' | 'receive-inventory-order:receive' | 'receive-inventory-order:update' | 'reclassify-inventory-order:reclassify' | 'sale-order:read' | 'scrape-order:scrape' | 'ship-inventory-order:cancel' | 'ship-inventory-order:create' | 'ship-inventory-order:read' | 'ship-inventory-order:ship' | 'ship-inventory-order:update' | 'stock:read' | 'transfer-customer-order:create' | 'transfer-customer-order:return' | 'transfer-customer-order:update' | 'transfer-order:cancel' | 'transfer-order:create' | 'transfer-order:read' | 'transfer-order:transfer' | 'transfer-order:update' | 'transfer-vendor-order:create' | 'transfer-vendor-order:return' | 'transfer-vendor-order:update' | 'unit:read' | 'warehouse-map:read' | 'warehouse-map:update';
30
30
  /**
31
31
  * Runtime counterpart of {@link WmsOperationName}. Iterate it to build a UI, to
32
32
  * diff against a host's own allow-list, or to assert the invariant above.
@@ -10,6 +10,12 @@ const WMS_OPERATION_NAMES = [
10
10
  'batch:merge',
11
11
  'batch:read',
12
12
  'batch:split',
13
+ 'consumption-order:create',
14
+ 'consumption-order:issue',
15
+ 'consumption-order:read',
16
+ 'consumption-order:return',
17
+ 'consumption-order:settle',
18
+ 'consumption-order:update',
13
19
  'hold-inventory-order:create',
14
20
  'hold-inventory-order:read',
15
21
  'hold-inventory-order:release',
@@ -34,6 +40,9 @@ const WMS_OPERATION_NAMES = [
34
40
  'material:create',
35
41
  'material:read',
36
42
  'material:update',
43
+ 'order-reference:attach',
44
+ 'order-reference:detach',
45
+ 'order-reference:read',
37
46
  'quality-inspection-order:inspect',
38
47
  'receive-inventory-order:create',
39
48
  'receive-inventory-order:read',
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @file order-type.ts
3
+ * The order families this package owns, named exactly as the `resource` half of
4
+ * the matching {@link WmsOperationName}s.
5
+ *
6
+ * One vocabulary, two uses: it is what `@WmsOperation` already calls each
7
+ * family, and it is what `order_references.orderType` stores. Reusing the
8
+ * strings rather than inventing a parallel set means a host that has switched
9
+ * `hold-inventory-order:create` off already knows the name to look for when it
10
+ * queries that family's references.
11
+ *
12
+ * Adding a family here is additive for consumers; renaming one is a breaking
13
+ * change, because the value is persisted in `order_references`.
14
+ */
15
+ export declare enum WmsOrderType {
16
+ ALLOCATE_INVENTORY_ORDER = "allocate-inventory-order",
17
+ CONSUMPTION_ORDER = "consumption-order",
18
+ HOLD_INVENTORY_ORDER = "hold-inventory-order",
19
+ INVENTORY_COUNT_ORDER = "inventory-count-order",
20
+ MERGE_BATCH_ORDER = "merge-batch-order",
21
+ QUALITY_INSPECTION_ORDER = "quality-inspection-order",
22
+ RECEIVE_INVENTORY_ORDER = "receive-inventory-order",
23
+ RECLASSIFY_INVENTORY_ORDER = "reclassify-inventory-order",
24
+ SCRAPE_ORDER = "scrape-order",
25
+ SHIP_INVENTORY_ORDER = "ship-inventory-order",
26
+ SPLIT_BATCH_ORDER = "split-batch-order",
27
+ TRANSFER_CUSTOMER_ORDER = "transfer-customer-order",
28
+ TRANSFER_ORDER = "transfer-order",
29
+ TRANSFER_VENDOR_ORDER = "transfer-vendor-order"
30
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @file order-type.ts
3
+ * The order families this package owns, named exactly as the `resource` half of
4
+ * the matching {@link WmsOperationName}s.
5
+ *
6
+ * One vocabulary, two uses: it is what `@WmsOperation` already calls each
7
+ * family, and it is what `order_references.orderType` stores. Reusing the
8
+ * strings rather than inventing a parallel set means a host that has switched
9
+ * `hold-inventory-order:create` off already knows the name to look for when it
10
+ * queries that family's references.
11
+ *
12
+ * Adding a family here is additive for consumers; renaming one is a breaking
13
+ * change, because the value is persisted in `order_references`.
14
+ */
15
+ var WmsOrderType;
16
+ (function (WmsOrderType) {
17
+ WmsOrderType["ALLOCATE_INVENTORY_ORDER"] = "allocate-inventory-order";
18
+ WmsOrderType["CONSUMPTION_ORDER"] = "consumption-order";
19
+ WmsOrderType["HOLD_INVENTORY_ORDER"] = "hold-inventory-order";
20
+ WmsOrderType["INVENTORY_COUNT_ORDER"] = "inventory-count-order";
21
+ WmsOrderType["MERGE_BATCH_ORDER"] = "merge-batch-order";
22
+ WmsOrderType["QUALITY_INSPECTION_ORDER"] = "quality-inspection-order";
23
+ WmsOrderType["RECEIVE_INVENTORY_ORDER"] = "receive-inventory-order";
24
+ WmsOrderType["RECLASSIFY_INVENTORY_ORDER"] = "reclassify-inventory-order";
25
+ WmsOrderType["SCRAPE_ORDER"] = "scrape-order";
26
+ WmsOrderType["SHIP_INVENTORY_ORDER"] = "ship-inventory-order";
27
+ WmsOrderType["SPLIT_BATCH_ORDER"] = "split-batch-order";
28
+ WmsOrderType["TRANSFER_CUSTOMER_ORDER"] = "transfer-customer-order";
29
+ WmsOrderType["TRANSFER_ORDER"] = "transfer-order";
30
+ WmsOrderType["TRANSFER_VENDOR_ORDER"] = "transfer-vendor-order";
31
+ })(WmsOrderType || (WmsOrderType = {}));
32
+
33
+ export { WmsOrderType };
@@ -28,5 +28,8 @@ export declare enum ChangeType {
28
28
  RECLASSIFIED = "RECLASSIFIED",
29
29
  COUNT_GAINED = "COUNT_GAINED",
30
30
  COUNT_LOST = "COUNT_LOST",
31
- SCRAPED = "SCRAPED"
31
+ SCRAPED = "SCRAPED",
32
+ ISSUED = "ISSUED",
33
+ RETURNED = "RETURNED",
34
+ CONSUMED = "CONSUMED"
32
35
  }
@@ -50,6 +50,12 @@ var ChangeType;
50
50
  ChangeType["COUNT_LOST"] = "COUNT_LOST";
51
51
  // scrape-order-change.entity.ts
52
52
  ChangeType["SCRAPED"] = "SCRAPED";
53
+ // consumption-order-change.entity.ts, kind = ISSUE
54
+ ChangeType["ISSUED"] = "ISSUED";
55
+ // consumption-order-change.entity.ts, kind = RETURN
56
+ ChangeType["RETURNED"] = "RETURNED";
57
+ // consumption-order-change.entity.ts, kind = SETTLE
58
+ ChangeType["CONSUMED"] = "CONSUMED";
53
59
  })(ChangeType || (ChangeType = {}));
54
60
 
55
61
  export { ChangeType, StockStatus };
@@ -22,6 +22,8 @@ import { HoldInventoryOrderService } from './services/hold-inventory-order.servi
22
22
  import { AllocateInventoryOrderService } from './services/allocate-inventory-order.service.js';
23
23
  import { SplitBatchOrderService } from './services/split-batch-order.service.js';
24
24
  import { MergeBatchOrderService } from './services/merge-batch-order.service.js';
25
+ import { ConsumptionOrderService } from './services/consumption-order.service.js';
26
+ import { OrderReferenceService } from './services/order-reference.service.js';
25
27
  import { ReclassifyInventoryOrderService } from './services/reclassify-inventory-order.service.js';
26
28
  import { TransferVendorOrderService } from './services/transfer-vendor-order.service.js';
27
29
  import { QualityInspectionOrderService } from './services/quality-inspection-order.service.js';
@@ -31,9 +33,11 @@ import { InventoryCountOrderService } from './services/inventory-count-order.ser
31
33
  import { ScrapeService } from './services/scrape.service.js';
32
34
  import { WarehouseMapDataService } from './services/warehouse-map.service.js';
33
35
  import { HelperService } from './services/helper.service.js';
34
- import { StockChangeSubscriber } from './events/stock-change.subscriber.js';
36
+ import { StockChangeSubscriber, OWNED_CHANGE_TABLES } from './events/stock-change.subscriber.js';
35
37
  import { InventoryCountLockSubscriber } from './events/inventory-count-lock.subscriber.js';
36
- import { WMS_STOCK_ENRICH } from './events/wms-event.tokens.js';
38
+ import { WMS_EVENT_OPTIONS, WMS_ACTOR_EXTRACTOR, WMS_CUSTOM_CHANGE_TABLES, WMS_STOCK_ENRICH } from './events/wms-event.tokens.js';
39
+ import { WmsEventDispatcher } from './events/wms-event.dispatcher.js';
40
+ import { WmsOperationRunner } from './events/wms-operation-runner.js';
37
41
  import { WMS_CORE_MODULE_OPTIONS } from './typings/core-module-options.js';
38
42
 
39
43
  var WmsModuleCoreModule_1;
@@ -131,12 +135,75 @@ const exportDependencies = [
131
135
  SaleOrderService,
132
136
  SplitBatchOrderService,
133
137
  MergeBatchOrderService,
138
+ OrderReferenceService,
139
+ ConsumptionOrderService,
134
140
  ReclassifyInventoryOrderService,
135
141
  ScrapeService,
136
142
  InventoryCountOrderService,
137
143
  QualityInspectionOrderService,
138
144
  WarehouseMapDataService,
139
145
  ];
146
+ /**
147
+ * The event machinery, bound here rather than in the graphql module so a
148
+ * consumer that only installs `@rytass/wms-module-core` still gets hooks,
149
+ * listeners and `WmsOperationRunner`. `WmsModuleGraphqlModule` forwards its own
150
+ * event options down to `forRootAsync`, which keeps exactly one binding per
151
+ * token — two live bindings would resolve to whichever module the injector
152
+ * reached first, the same hazard the overridable entity Symbols avoid.
153
+ */
154
+ const eventProviders = (wiring) => [
155
+ {
156
+ provide: WMS_EVENT_OPTIONS,
157
+ useValue: {
158
+ beforeHooks: wiring.beforeHooks,
159
+ afterListeners: wiring.afterListeners,
160
+ },
161
+ },
162
+ { provide: WMS_ACTOR_EXTRACTOR, useValue: wiring.actorExtractor ?? null },
163
+ WmsEventDispatcher,
164
+ WmsOperationRunner,
165
+ ...(wiring.eventEmitterBridge ? [wiring.eventEmitterBridge] : []),
166
+ ];
167
+ const eventExports = [
168
+ WmsEventDispatcher,
169
+ WmsOperationRunner,
170
+ WMS_EVENT_OPTIONS,
171
+ WMS_ACTOR_EXTRACTOR,
172
+ ];
173
+ /**
174
+ * Reject a registration that would shadow one of this package's own change
175
+ * tables.
176
+ *
177
+ * Silently letting a host redefine `receive_inventory_order_changes` would
178
+ * reclassify every receipt in the warehouse from somewhere the reader of that
179
+ * report would never think to look. Refusing at module-definition time costs a
180
+ * startup crash and buys an obvious one.
181
+ *
182
+ * The list is derived from `StockChangeSubscriber`'s own table map rather than
183
+ * restated here: two hand-maintained copies would drift, and the drift would
184
+ * open exactly the hole this guard exists to close.
185
+ */
186
+ const assertCustomChangeTables = (tables) => {
187
+ if (!tables?.length)
188
+ return [];
189
+ const seen = new Set();
190
+ for (const { table } of tables) {
191
+ if (OWNED_CHANGE_TABLES.has(table)) {
192
+ throw new Error(`WmsModuleCoreModule: customChangeTables cannot register "${table}" — this package owns it.`);
193
+ }
194
+ if (seen.has(table)) {
195
+ throw new Error(`WmsModuleCoreModule: customChangeTables registers "${table}" twice.`);
196
+ }
197
+ if (!table.endsWith('_order_changes')) {
198
+ // The inventory count lock keys off this suffix, so a table without it
199
+ // gets events but silently escapes the lock — the worse half of the
200
+ // bargain, and not one a host would knowingly take.
201
+ throw new Error(`WmsModuleCoreModule: customChangeTables entry "${table}" must end in "_order_changes" so the inventory count lock covers it too.`);
202
+ }
203
+ seen.add(table);
204
+ }
205
+ return tables;
206
+ };
140
207
  let WmsModuleCoreModule = WmsModuleCoreModule_1 = class WmsModuleCoreModule {
141
208
  static forRoot(options, coreOptions) {
142
209
  const coreModule = WMSBaseModule.forRoot(options);
@@ -148,6 +215,11 @@ let WmsModuleCoreModule = WmsModuleCoreModule_1 = class WmsModuleCoreModule {
148
215
  StockChangeSubscriber,
149
216
  InventoryCountLockSubscriber,
150
217
  ...resolvedEntityProviders,
218
+ ...eventProviders(coreOptions),
219
+ {
220
+ provide: WMS_CUSTOM_CHANGE_TABLES,
221
+ useValue: assertCustomChangeTables(coreOptions.customChangeTables),
222
+ },
151
223
  { provide: WMS_CORE_MODULE_OPTIONS, useValue: coreOptions },
152
224
  {
153
225
  provide: WMS_STOCK_ENRICH,
@@ -159,12 +231,13 @@ let WmsModuleCoreModule = WmsModuleCoreModule_1 = class WmsModuleCoreModule {
159
231
  coreModule,
160
232
  ModelsModule,
161
233
  ...exportedEntityTokens,
234
+ ...eventExports,
162
235
  WMS_CORE_MODULE_OPTIONS,
163
236
  ],
164
237
  };
165
238
  }
166
239
  static forRootAsync(options) {
167
- const { defaultLoaderSerialId, defaultLoaderTypeKey, defaultLocationKey, enrichStockEvents, ...baseOptions } = options;
240
+ const { defaultLoaderSerialId, defaultLoaderTypeKey, defaultLocationKey, enrichStockEvents, beforeHooks, afterListeners, actorExtractor, eventEmitterBridge, customChangeTables, ...baseOptions } = options;
168
241
  const coreModule = WMSBaseModule.forRootAsync(baseOptions);
169
242
  return {
170
243
  module: WmsModuleCoreModule_1,
@@ -174,6 +247,16 @@ let WmsModuleCoreModule = WmsModuleCoreModule_1 = class WmsModuleCoreModule {
174
247
  StockChangeSubscriber,
175
248
  InventoryCountLockSubscriber,
176
249
  ...resolvedEntityProviders,
250
+ ...eventProviders({
251
+ beforeHooks,
252
+ afterListeners,
253
+ actorExtractor,
254
+ eventEmitterBridge,
255
+ }),
256
+ {
257
+ provide: WMS_CUSTOM_CHANGE_TABLES,
258
+ useValue: assertCustomChangeTables(customChangeTables),
259
+ },
177
260
  {
178
261
  provide: WMS_CORE_MODULE_OPTIONS,
179
262
  useValue: {
@@ -189,6 +272,7 @@ let WmsModuleCoreModule = WmsModuleCoreModule_1 = class WmsModuleCoreModule {
189
272
  coreModule,
190
273
  ModelsModule,
191
274
  ...exportedEntityTokens,
275
+ ...eventExports,
192
276
  WMS_CORE_MODULE_OPTIONS,
193
277
  ],
194
278
  };
@@ -1,6 +1,7 @@
1
- export { WMS_ACTOR_EXTRACTOR, WMS_EVENT_EMITTER_BRIDGE, WMS_EVENT_OPTIONS, WMS_STOCK_ENRICH, } from './wms-event.tokens';
1
+ export { WMS_ACTOR_EXTRACTOR, WMS_CUSTOM_CHANGE_TABLES, WMS_EVENT_EMITTER_BRIDGE, WMS_EVENT_OPTIONS, WMS_STOCK_ENRICH, } from './wms-event.tokens';
2
2
  export { WmsEventCollector } from './wms-event.collector';
3
3
  export { WmsEventDispatcher } from './wms-event.dispatcher';
4
+ export { WmsOperationRunner, type WmsOperationRunOptions, } from './wms-operation-runner';
4
5
  export { collectToScope, runInDispatchScope, type DispatchScopeResult, } from './dispatch-scope';
5
6
  export type { WmsActor, WmsActorExtractor, WmsAfterEventContext, WmsAfterListener, WmsAfterListenerMap, WmsBeforeHook, WmsBeforeHookContext, WmsBeforeHookMap, WmsDomainEvent, WmsEventEmitterBridge, WmsEventModuleOptions, WmsEventName, WmsEventPayloadMap, WmsOperationEventName, WmsOperationEventPayload, WmsStockEventName, WmsStockEventPayload, } from './wms-event.types';
6
7
  export * from './inventory-count-lock.subscriber';
@@ -1,5 +1,18 @@
1
1
  import { DataSource, type EntitySubscriberInterface, type InsertEvent } from 'typeorm';
2
+ import type { WmsCustomChangeTable } from '../typings/custom-change-table';
2
3
  import { WmsEventCollector } from './wms-event.collector';
4
+ /**
5
+ * Every change table this package owns, derived from the map above rather than
6
+ * restated.
7
+ *
8
+ * `WmsModuleCoreModule` refuses to let a host register one of these, and the
9
+ * subscriber consults host registrations *before* the built-in map — so a table
10
+ * added to the map but forgotten in a hand-maintained copy of this list would
11
+ * become host-registrable, letting a host's resolver silently reclassify every
12
+ * row on it. Deriving it is the difference between a rule and a rule someone has
13
+ * to remember.
14
+ */
15
+ export declare const OWNED_CHANGE_TABLES: ReadonlySet<string>;
3
16
  /**
4
17
  * Centralized collection of stock domain events. Listens to every
5
18
  * `*_order_change` insert and, using the change table name plus the sign of
@@ -14,8 +27,20 @@ import { WmsEventCollector } from './wms-event.collector';
14
27
  export declare class StockChangeSubscriber implements EntitySubscriberInterface {
15
28
  private readonly collector;
16
29
  private readonly enrich;
17
- constructor(dataSource: DataSource, collector: WmsEventCollector, enrich?: boolean);
30
+ /** Host-registered tables, keyed by table name. Empty unless configured. */
31
+ private readonly customTables;
32
+ constructor(dataSource: DataSource, collector: WmsEventCollector, enrich?: boolean, customTables?: readonly WmsCustomChangeTable[] | null);
18
33
  afterInsert(event: InsertEvent<unknown>): Promise<void>;
34
+ /**
35
+ * Emit for a table the host registered.
36
+ *
37
+ * A resolver that names one of our own `ChangeType`s gets that type's event,
38
+ * so a movement the host models itself but which really is a receipt or a
39
+ * scrap still counts in reports as one. Anything else becomes `stock.custom`
40
+ * carrying the host's string, because inventing an event name per host would
41
+ * break every exhaustive listener in the package.
42
+ */
43
+ private collectCustom;
19
44
  /**
20
45
  * Load `materialId / batchId / locationId / loaderId` from the change's order
21
46
  * item (one PK lookup, same transaction). Generic across all 12 change tables
@@ -2,40 +2,54 @@ import { __decorate, __param, __metadata } from 'tslib';
2
2
  import { Injectable, Optional, Inject } from '@nestjs/common';
3
3
  import { InjectDataSource } from '@nestjs/typeorm';
4
4
  import { DataSource } from 'typeorm';
5
+ import { ConsumptionChangeKind } from '../constants/consumption-change-kind.js';
5
6
  import { ChangeType } from '../constants/stock-status.js';
6
7
  import { WmsEventCollector } from './wms-event.collector.js';
7
- import { WMS_STOCK_ENRICH } from './wms-event.tokens.js';
8
+ import { WMS_STOCK_ENRICH, WMS_CUSTOM_CHANGE_TABLES } from './wms-event.tokens.js';
8
9
 
9
10
  /**
10
- * Resolve the `ChangeType` for a change table. Tables whose semantics depend on
11
- * the sign of `quantityChanged` (ship / transfer / vendor / customer / hold /
12
- * allocate) branch on it; the rest are fixed.
11
+ * The consumption order's three actions, which the sign cannot separate: a
12
+ * return and a settlement are both negative.
13
+ */
14
+ const CONSUMPTION_KIND_TO_CHANGE_TYPE = {
15
+ [ConsumptionChangeKind.ISSUE]: ChangeType.ISSUED,
16
+ [ConsumptionChangeKind.RETURN]: ChangeType.RETURNED,
17
+ [ConsumptionChangeKind.SETTLE]: ChangeType.CONSUMED,
18
+ };
19
+ /**
20
+ * Resolve the `ChangeType` for a change table. Most tables whose semantics
21
+ * depend on direction (ship / transfer / vendor / customer / hold / allocate)
22
+ * branch on the sign of `quantityChanged`; the rest are fixed. The resolver is
23
+ * handed the whole row rather than just the quantity because the sign is not
24
+ * always enough — see `consumption_order_changes`.
13
25
  */
14
26
  const TABLE_TO_CHANGE_TYPE = new Map([
15
27
  ['receive_inventory_order_changes', () => ChangeType.RECEIVED],
16
28
  [
17
29
  'ship_inventory_order_changes',
18
- (q) => (q > 0 ? ChangeType.IN_SHIPMENT : ChangeType.SHIPPED),
30
+ ({ quantityChanged: q }) => Number(q) > 0 ? ChangeType.IN_SHIPMENT : ChangeType.SHIPPED,
19
31
  ],
20
32
  [
21
33
  'transfer_order_changes',
22
- (q) => (q > 0 ? ChangeType.IN_TRANSFER : ChangeType.TRANSFERRED),
34
+ ({ quantityChanged: q }) => Number(q) > 0 ? ChangeType.IN_TRANSFER : ChangeType.TRANSFERRED,
23
35
  ],
24
36
  [
25
37
  'transfer_vendor_order_changes',
26
- (q) => q > 0 ? ChangeType.VENDOR_TRANSFERRED : ChangeType.VENDOR_RETURNED,
38
+ ({ quantityChanged: q }) => Number(q) > 0
39
+ ? ChangeType.VENDOR_TRANSFERRED
40
+ : ChangeType.VENDOR_RETURNED,
27
41
  ],
28
42
  [
29
43
  'transfer_customer_order_changes',
30
- (q) => q > 0 ? ChangeType.CUSTOMER_HELD : ChangeType.CUSTOMER_RETURNED,
44
+ ({ quantityChanged: q }) => Number(q) > 0 ? ChangeType.CUSTOMER_HELD : ChangeType.CUSTOMER_RETURNED,
31
45
  ],
32
46
  [
33
47
  'hold_inventory_order_changes',
34
- (q) => (q > 0 ? ChangeType.HELD : ChangeType.RELEASED),
48
+ ({ quantityChanged: q }) => Number(q) > 0 ? ChangeType.HELD : ChangeType.RELEASED,
35
49
  ],
36
50
  [
37
51
  'allocate_inventory_order_changes',
38
- (q) => (q > 0 ? ChangeType.ALLOCATED : ChangeType.DEALLOCATED),
52
+ ({ quantityChanged: q }) => Number(q) > 0 ? ChangeType.ALLOCATED : ChangeType.DEALLOCATED,
39
53
  ],
40
54
  ['split_batch_order_changes', () => ChangeType.SPLITTED],
41
55
  ['merge_batch_order_changes', () => ChangeType.MERGED],
@@ -43,7 +57,11 @@ const TABLE_TO_CHANGE_TYPE = new Map([
43
57
  ['scrape_order_changes', () => ChangeType.SCRAPED],
44
58
  [
45
59
  'inventory_count_order_changes',
46
- (q) => (q > 0 ? ChangeType.COUNT_GAINED : ChangeType.COUNT_LOST),
60
+ ({ quantityChanged: q }) => Number(q) > 0 ? ChangeType.COUNT_GAINED : ChangeType.COUNT_LOST,
61
+ ],
62
+ [
63
+ 'consumption_order_changes',
64
+ ({ kind }) => (kind ? CONSUMPTION_KIND_TO_CHANGE_TYPE[kind] : null),
47
65
  ],
48
66
  ]);
49
67
  const CHANGE_TYPE_TO_EVENT = {
@@ -66,8 +84,28 @@ const CHANGE_TYPE_TO_EVENT = {
66
84
  [ChangeType.SCRAPED]: 'stock.scraped',
67
85
  [ChangeType.COUNT_GAINED]: 'stock.count-gained',
68
86
  [ChangeType.COUNT_LOST]: 'stock.count-lost',
87
+ [ChangeType.ISSUED]: 'stock.issued',
88
+ [ChangeType.RETURNED]: 'stock.returned',
89
+ [ChangeType.CONSUMED]: 'stock.consumed',
69
90
  };
70
91
  const QUALITY_INSPECTION_TABLE = 'quality_inspection_order_changes';
92
+ /**
93
+ * Every change table this package owns, derived from the map above rather than
94
+ * restated.
95
+ *
96
+ * `WmsModuleCoreModule` refuses to let a host register one of these, and the
97
+ * subscriber consults host registrations *before* the built-in map — so a table
98
+ * added to the map but forgotten in a hand-maintained copy of this list would
99
+ * become host-registrable, letting a host's resolver silently reclassify every
100
+ * row on it. Deriving it is the difference between a rule and a rule someone has
101
+ * to remember.
102
+ */
103
+ const OWNED_CHANGE_TABLES = new Set([
104
+ ...TABLE_TO_CHANGE_TYPE.keys(),
105
+ QUALITY_INSPECTION_TABLE,
106
+ ]);
107
+ /** Every `ChangeType` value, for deciding whether a host reused our vocabulary. */
108
+ const CHANGE_TYPE_VALUES = new Set(Object.values(ChangeType));
71
109
  /**
72
110
  * Centralized collection of stock domain events. Listens to every
73
111
  * `*_order_change` insert and, using the change table name plus the sign of
@@ -82,9 +120,12 @@ const QUALITY_INSPECTION_TABLE = 'quality_inspection_order_changes';
82
120
  let StockChangeSubscriber = class StockChangeSubscriber {
83
121
  collector;
84
122
  enrich;
85
- constructor(dataSource, collector, enrich = false) {
123
+ /** Host-registered tables, keyed by table name. Empty unless configured. */
124
+ customTables;
125
+ constructor(dataSource, collector, enrich = false, customTables = null) {
86
126
  this.collector = collector;
87
127
  this.enrich = enrich;
128
+ this.customTables = new Map((customTables ?? []).map((entry) => [entry.table, entry]));
88
129
  dataSource.subscribers.push(this);
89
130
  }
90
131
  async afterInsert(event) {
@@ -108,12 +149,22 @@ let StockChangeSubscriber = class StockChangeSubscriber {
108
149
  });
109
150
  return;
110
151
  }
152
+ const custom = this.customTables.get(tableName);
153
+ if (custom) {
154
+ await this.collectCustom(event, entity, quantityDelta, custom);
155
+ return;
156
+ }
111
157
  const resolveChangeType = TABLE_TO_CHANGE_TYPE.get(tableName);
112
158
  if (!resolveChangeType) {
113
159
  // Not a stock change table — enrich nothing, emit nothing.
114
160
  return;
115
161
  }
116
- const changeType = resolveChangeType(quantityDelta);
162
+ const changeType = resolveChangeType(entity);
163
+ if (!changeType) {
164
+ // A row the table's resolver could not classify. Emitting a wrong event
165
+ // would be worse than emitting none.
166
+ return;
167
+ }
117
168
  const enrichment = this.enrich
118
169
  ? await this.loadItemFields(event, entity.itemId)
119
170
  : undefined;
@@ -125,6 +176,36 @@ let StockChangeSubscriber = class StockChangeSubscriber {
125
176
  ...enrichment,
126
177
  });
127
178
  }
179
+ /**
180
+ * Emit for a table the host registered.
181
+ *
182
+ * A resolver that names one of our own `ChangeType`s gets that type's event,
183
+ * so a movement the host models itself but which really is a receipt or a
184
+ * scrap still counts in reports as one. Anything else becomes `stock.custom`
185
+ * carrying the host's string, because inventing an event name per host would
186
+ * break every exhaustive listener in the package.
187
+ */
188
+ async collectCustom(event, entity, quantityDelta, custom) {
189
+ const resolved = custom.changeType(entity);
190
+ if (!resolved) {
191
+ // The host says this row does not move stock. Nothing to say about it.
192
+ return;
193
+ }
194
+ const enrichment = this.enrich
195
+ ? await this.loadItemFields(event, entity.itemId)
196
+ : undefined;
197
+ const known = CHANGE_TYPE_VALUES.has(resolved)
198
+ ? resolved
199
+ : null;
200
+ this.collector.collect(known ? CHANGE_TYPE_TO_EVENT[known] : 'stock.custom', {
201
+ orderId: entity.id,
202
+ itemId: entity.itemId,
203
+ quantityDelta,
204
+ changeType: known,
205
+ ...(known ? {} : { customChangeType: resolved }),
206
+ ...enrichment,
207
+ });
208
+ }
128
209
  /**
129
210
  * Load `materialId / batchId / locationId / loaderId` from the change's order
130
211
  * item (one PK lookup, same transaction). Generic across all 12 change tables
@@ -162,8 +243,10 @@ StockChangeSubscriber = __decorate([
162
243
  __param(0, InjectDataSource()),
163
244
  __param(2, Optional()),
164
245
  __param(2, Inject(WMS_STOCK_ENRICH)),
246
+ __param(3, Optional()),
247
+ __param(3, Inject(WMS_CUSTOM_CHANGE_TABLES)),
165
248
  __metadata("design:paramtypes", [DataSource,
166
- WmsEventCollector, Object])
249
+ WmsEventCollector, Object, Object])
167
250
  ], StockChangeSubscriber);
168
251
 
169
- export { StockChangeSubscriber };
252
+ export { OWNED_CHANGE_TABLES, StockChangeSubscriber };
@@ -6,3 +6,5 @@ export declare const WMS_EVENT_EMITTER_BRIDGE: unique symbol;
6
6
  export declare const WMS_ACTOR_EXTRACTOR: unique symbol;
7
7
  /** DI token holding the boolean "enrich stock events" flag (default false). */
8
8
  export declare const WMS_STOCK_ENRICH: unique symbol;
9
+ /** DI token holding the host's registered custom change tables (default none). */
10
+ export declare const WMS_CUSTOM_CHANGE_TABLES: unique symbol;
@@ -6,5 +6,7 @@ const WMS_EVENT_EMITTER_BRIDGE = Symbol('WMS_EVENT_EMITTER_BRIDGE');
6
6
  const WMS_ACTOR_EXTRACTOR = Symbol('WMS_ACTOR_EXTRACTOR');
7
7
  /** DI token holding the boolean "enrich stock events" flag (default false). */
8
8
  const WMS_STOCK_ENRICH = Symbol('WMS_STOCK_ENRICH');
9
+ /** DI token holding the host's registered custom change tables (default none). */
10
+ const WMS_CUSTOM_CHANGE_TABLES = Symbol('WMS_CUSTOM_CHANGE_TABLES');
9
11
 
10
- export { WMS_ACTOR_EXTRACTOR, WMS_EVENT_EMITTER_BRIDGE, WMS_EVENT_OPTIONS, WMS_STOCK_ENRICH };
12
+ export { WMS_ACTOR_EXTRACTOR, WMS_CUSTOM_CHANGE_TABLES, WMS_EVENT_EMITTER_BRIDGE, WMS_EVENT_OPTIONS, WMS_STOCK_ENRICH };