@rytass/wms-module-core 0.8.1 → 0.9.1

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 (141) hide show
  1. package/index.cjs.js +1689 -199
  2. package/index.d.mts +6 -0
  3. package/{index.js → index.mjs} +97 -87
  4. package/lib/constants/consumption-change-kind.d.ts +17 -0
  5. package/lib/constants/consumption-change-kind.mjs +20 -0
  6. package/lib/constants/index.d.ts +2 -0
  7. package/lib/constants/operations.d.ts +1 -1
  8. package/lib/constants/{operations.js → operations.mjs} +9 -0
  9. package/lib/constants/order-type.d.ts +30 -0
  10. package/lib/constants/order-type.mjs +33 -0
  11. package/lib/constants/stock-status.d.ts +4 -1
  12. package/lib/constants/{stock-status.js → stock-status.mjs} +6 -0
  13. package/lib/{core.module.js → core.module.mjs} +118 -34
  14. package/lib/events/index.d.ts +2 -1
  15. package/lib/events/stock-change.subscriber.d.ts +26 -1
  16. package/lib/events/{stock-change.subscriber.js → stock-change.subscriber.mjs} +100 -17
  17. package/lib/events/{wms-event.collector.js → wms-event.collector.mjs} +1 -1
  18. package/lib/events/{wms-event.dispatcher.js → wms-event.dispatcher.mjs} +1 -1
  19. package/lib/events/wms-event.tokens.d.ts +2 -0
  20. package/lib/events/{wms-event.tokens.js → wms-event.tokens.mjs} +3 -1
  21. package/lib/events/wms-event.types.d.ts +38 -6
  22. package/lib/events/wms-operation-runner.d.ts +57 -0
  23. package/lib/events/wms-operation-runner.mjs +101 -0
  24. package/lib/models/extensions/allocate-inventory-order/{allocate-inventory-order-change.entity.js → allocate-inventory-order-change.entity.mjs} +1 -1
  25. package/lib/models/extensions/allocate-inventory-order/{allocate-inventory-order-item.entity.js → allocate-inventory-order-item.entity.mjs} +12 -12
  26. package/lib/models/extensions/consumption-order/consumption-order-change.entity.d.ts +19 -0
  27. package/lib/models/extensions/consumption-order/consumption-order-change.entity.mjs +59 -0
  28. package/lib/models/extensions/consumption-order/consumption-order-item.entity.d.ts +26 -0
  29. package/lib/models/extensions/consumption-order/consumption-order-item.entity.mjs +114 -0
  30. package/lib/models/extensions/consumption-order/consumption-order.entity.d.ts +32 -0
  31. package/lib/models/extensions/consumption-order/consumption-order.entity.mjs +69 -0
  32. package/lib/models/extensions/consumption-order/index.d.ts +3 -0
  33. package/lib/models/extensions/hold-inventory-order/{hold-inventory-order-change.entity.js → hold-inventory-order-change.entity.mjs} +1 -1
  34. package/lib/models/extensions/hold-inventory-order/{hold-inventory-order-item.entity.js → hold-inventory-order-item.entity.mjs} +12 -12
  35. package/lib/models/extensions/index.d.ts +4 -0
  36. package/lib/models/extensions/inventory-count-order/{inventory-count-order-change.entity.js → inventory-count-order-change.entity.mjs} +1 -1
  37. package/lib/models/extensions/inventory-count-order/inventory-count-order-item.entity.d.ts +13 -1
  38. package/lib/models/extensions/inventory-count-order/{inventory-count-order-item.entity.js → inventory-count-order-item.entity.mjs} +29 -13
  39. package/lib/models/extensions/inventory-count-order/{inventory-count-order.entity.js → inventory-count-order.entity.mjs} +12 -12
  40. package/lib/models/extensions/merge-batch-order/{merge-batch-order-change.entity.js → merge-batch-order-change.entity.mjs} +1 -1
  41. package/lib/models/extensions/merge-batch-order/{merge-batch-order-item.entity.js → merge-batch-order-item.entity.mjs} +12 -12
  42. package/lib/models/extensions/order-reference/index.d.ts +1 -0
  43. package/lib/models/extensions/order-reference/order-reference.entity.d.ts +49 -0
  44. package/lib/models/extensions/order-reference/order-reference.entity.mjs +95 -0
  45. package/lib/models/extensions/quality-inspection-order/{quality-inspection-order-change.entity.js → quality-inspection-order-change.entity.mjs} +1 -1
  46. package/lib/models/extensions/quality-inspection-order/{quality-inspection-order-item.entity.js → quality-inspection-order-item.entity.mjs} +12 -12
  47. package/lib/models/extensions/receive-inventory-order/{receive-inventory-order-change.entity.js → receive-inventory-order-change.entity.mjs} +2 -2
  48. package/lib/models/extensions/receive-inventory-order/{receive-inventory-order-item.entity.js → receive-inventory-order-item.entity.mjs} +2 -2
  49. package/lib/models/extensions/receive-inventory-order/{receive-inventory-order.entity.js → receive-inventory-order.entity.mjs} +2 -2
  50. package/lib/models/extensions/reclassify-inventory-order/{reclassify-inventory-order-change.entity.js → reclassify-inventory-order-change.entity.mjs} +1 -1
  51. package/lib/models/extensions/reclassify-inventory-order/{reclassify-inventory-order-item.entity.js → reclassify-inventory-order-item.entity.mjs} +12 -12
  52. package/lib/models/extensions/scrape-order/{scrape-order-change.entity.js → scrape-order-change.entity.mjs} +1 -1
  53. package/lib/models/extensions/scrape-order/{scrape-order-item.entity.js → scrape-order-item.entity.mjs} +12 -12
  54. package/lib/models/extensions/ship-inventory-order/{ship-inventory-order-change.entity.js → ship-inventory-order-change.entity.mjs} +2 -2
  55. package/lib/models/extensions/ship-inventory-order/{ship-inventory-order-item.entity.js → ship-inventory-order-item.entity.mjs} +2 -2
  56. package/lib/models/extensions/ship-inventory-order/{ship-inventory-order.entity.js → ship-inventory-order.entity.mjs} +2 -2
  57. package/lib/models/extensions/split-batch-order/{split-batch-order-change.entity.js → split-batch-order-change.entity.mjs} +1 -1
  58. package/lib/models/extensions/split-batch-order/{split-batch-order-item.entity.js → split-batch-order-item.entity.mjs} +12 -12
  59. package/lib/models/extensions/transfer-customer-order/{transfer-customer-order-change.entity.js → transfer-customer-order-change.entity.mjs} +1 -1
  60. package/lib/models/extensions/transfer-customer-order/{transfer-customer-order-item.entity.js → transfer-customer-order-item.entity.mjs} +12 -12
  61. package/lib/models/extensions/transfer-order/{transfer-order-change.entity.js → transfer-order-change.entity.mjs} +1 -1
  62. package/lib/models/extensions/transfer-order/{transfer-order-item.entity.js → transfer-order-item.entity.mjs} +12 -12
  63. package/lib/models/extensions/transfer-vendor-order/{transfer-vendor-order-change.entity.js → transfer-vendor-order-change.entity.mjs} +1 -1
  64. package/lib/models/extensions/transfer-vendor-order/{transfer-vendor-order-item.entity.js → transfer-vendor-order-item.entity.mjs} +12 -12
  65. package/lib/models/metadata/batch.entity.d.ts +46 -0
  66. package/lib/models/metadata/batch.entity.mjs +131 -0
  67. package/lib/models/metadata/{loader.entity.js → loader.entity.mjs} +1 -1
  68. package/lib/models/metadata/{material-unit.entity.js → material-unit.entity.mjs} +1 -1
  69. package/lib/models/metadata/{stock.entity.js → stock.entity.mjs} +1 -1
  70. package/lib/models/{models.module.js → models.module.mjs} +60 -52
  71. package/lib/models/{wms-entities.js → wms-entities.mjs} +5 -5
  72. package/lib/services/{allocate-inventory-order.service.js → allocate-inventory-order.service.mjs} +60 -56
  73. package/lib/services/base-order.service.d.ts +18 -3
  74. package/lib/services/base-order.service.mjs +76 -0
  75. package/lib/services/batch.service.d.ts +17 -0
  76. package/lib/services/{batch.service.js → batch.service.mjs} +93 -53
  77. package/lib/services/consumption-order.service.d.ts +75 -0
  78. package/lib/services/consumption-order.service.mjs +504 -0
  79. package/lib/services/{hold-inventory-order.service.js → hold-inventory-order.service.mjs} +60 -56
  80. package/lib/services/index.d.ts +3 -0
  81. package/lib/services/{inventory-count-order.service.js → inventory-count-order.service.mjs} +64 -57
  82. package/lib/services/{loader.service.js → loader.service.mjs} +56 -52
  83. package/lib/services/{location.service.js → location.service.mjs} +56 -52
  84. package/lib/services/{material.service.js → material.service.mjs} +56 -52
  85. package/lib/services/{merge-batch-order.service.js → merge-batch-order.service.mjs} +60 -56
  86. package/lib/services/order-reference.service.d.ts +50 -0
  87. package/lib/services/order-reference.service.mjs +136 -0
  88. package/lib/services/{quality-inspection-order.service.js → quality-inspection-order.service.mjs} +59 -55
  89. package/lib/services/{receive-inventory-order.service.js → receive-inventory-order.service.mjs} +189 -135
  90. package/lib/services/{reclassify-inventory-order.service.js → reclassify-inventory-order.service.mjs} +60 -56
  91. package/lib/services/{sale-order.service.js → sale-order.service.mjs} +1 -1
  92. package/lib/services/{scrape.service.js → scrape.service.mjs} +59 -55
  93. package/lib/services/{ship-inventory-order.service.js → ship-inventory-order.service.mjs} +60 -56
  94. package/lib/services/split-batch-order.service.mjs +191 -0
  95. package/lib/services/{stock.service.js → stock.service.mjs} +86 -56
  96. package/lib/services/{transfer-customer-order.service.js → transfer-customer-order.service.mjs} +60 -56
  97. package/lib/services/{transfer-order.service.js → transfer-order.service.mjs} +61 -57
  98. package/lib/services/{transfer-vendor-order.service.js → transfer-vendor-order.service.mjs} +60 -56
  99. package/lib/services/{unit.service.js → unit.service.mjs} +56 -52
  100. package/lib/services/{warehouse-map.service.js → warehouse-map.service.mjs} +1 -1
  101. package/lib/typings/aggregated-stock.d.ts +6 -0
  102. package/lib/typings/consumption-order.input.d.ts +72 -0
  103. package/lib/typings/core-module-options.d.ts +34 -1
  104. package/lib/typings/custom-change-table.d.ts +70 -0
  105. package/lib/typings/find-stock.input.d.ts +14 -0
  106. package/lib/typings/get-batch.input.d.ts +16 -0
  107. package/lib/typings/index.d.ts +3 -0
  108. package/lib/typings/order-reference.input.d.ts +28 -0
  109. package/lib/typings/split-batch.input.d.ts +11 -0
  110. package/package.json +19 -7
  111. package/lib/models/metadata/batch.entity.js +0 -73
  112. package/lib/services/split-batch-order.service.js +0 -168
  113. package/lib/typings/entity-overrides.d.ts +0 -34
  114. package/lib/typings/entity-overrides.js +0 -7
  115. package/src/lib/models/extensions/README.md +0 -219
  116. /package/lib/constants/{inventory-count-status.js → inventory-count-status.mjs} +0 -0
  117. /package/lib/events/{dispatch-scope.js → dispatch-scope.mjs} +0 -0
  118. /package/lib/events/{inventory-count-lock.subscriber.js → inventory-count-lock.subscriber.mjs} +0 -0
  119. /package/lib/models/extensions/allocate-inventory-order/{allocate-inventory-order.entity.js → allocate-inventory-order.entity.mjs} +0 -0
  120. /package/lib/models/extensions/hold-inventory-order/{hold-inventory-order.entity.js → hold-inventory-order.entity.mjs} +0 -0
  121. /package/lib/models/extensions/merge-batch-order/{merge-batch-order.entity.js → merge-batch-order.entity.mjs} +0 -0
  122. /package/lib/models/extensions/quality-inspection-order/{quality-inspection-order.entity.js → quality-inspection-order.entity.mjs} +0 -0
  123. /package/lib/models/extensions/reclassify-inventory-order/{reclassify-inventory-order.entity.js → reclassify-inventory-order.entity.mjs} +0 -0
  124. /package/lib/models/extensions/scrape-order/{scrape-order.entity.js → scrape-order.entity.mjs} +0 -0
  125. /package/lib/models/extensions/ship-inventory-order/{ship-inventory-order-reference.entity.js → ship-inventory-order-reference.entity.mjs} +0 -0
  126. /package/lib/models/extensions/split-batch-order/{split-batch-order.entity.js → split-batch-order.entity.mjs} +0 -0
  127. /package/lib/models/extensions/transfer-customer-order/{transfer-customer-order.entity.js → transfer-customer-order.entity.mjs} +0 -0
  128. /package/lib/models/extensions/transfer-order/{transfer-order.entity.js → transfer-order.entity.mjs} +0 -0
  129. /package/lib/models/extensions/transfer-vendor-order/{transfer-vendor-order.entity.js → transfer-vendor-order.entity.mjs} +0 -0
  130. /package/lib/models/metadata/{batch-group.entity.js → batch-group.entity.mjs} +0 -0
  131. /package/lib/models/metadata/{loader-type.entity.js → loader-type.entity.mjs} +0 -0
  132. /package/lib/models/metadata/{loader-unit.entity.js → loader-unit.entity.mjs} +0 -0
  133. /package/lib/models/metadata/{location.entity.js → location.entity.mjs} +0 -0
  134. /package/lib/models/metadata/{material.entity.js → material.entity.mjs} +0 -0
  135. /package/lib/models/metadata/{order.entity.js → order.entity.mjs} +0 -0
  136. /package/lib/models/metadata/{sale-order.entity.js → sale-order.entity.mjs} +0 -0
  137. /package/lib/models/metadata/{unit.entity.js → unit.entity.mjs} +0 -0
  138. /package/lib/services/{helper.service.js → helper.service.mjs} +0 -0
  139. /package/lib/typings/{core-module-options.js → core-module-options.mjs} +0 -0
  140. /package/lib/typings/{find-receive-inventory-order.input.js → find-receive-inventory-order.input.mjs} +0 -0
  141. /package/lib/typings/{find-ship-inventory-order.input.js → find-ship-inventory-order.input.mjs} +0 -0
@@ -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 { ChangeType } from '../constants/stock-status.js';
6
- import { WmsEventCollector } from './wms-event.collector.js';
7
- import { WMS_STOCK_ENRICH } from './wms-event.tokens.js';
5
+ import { ConsumptionChangeKind } from '../constants/consumption-change-kind.mjs';
6
+ import { ChangeType } from '../constants/stock-status.mjs';
7
+ import { WmsEventCollector } from './wms-event.collector.mjs';
8
+ import { WMS_STOCK_ENRICH, WMS_CUSTOM_CHANGE_TABLES } from './wms-event.tokens.mjs';
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 };
@@ -1,6 +1,6 @@
1
1
  import { __decorate } from 'tslib';
2
2
  import { Injectable } from '@nestjs/common';
3
- import { collectToScope } from './dispatch-scope.js';
3
+ import { collectToScope } from './dispatch-scope.mjs';
4
4
 
5
5
  /**
6
6
  * Injected into core services so they can record stock domain events at the
@@ -1,6 +1,6 @@
1
1
  import { __decorate, __param, __metadata } from 'tslib';
2
2
  import { Injectable, Inject, Optional, Logger } from '@nestjs/common';
3
- import { WMS_EVENT_OPTIONS, WMS_EVENT_EMITTER_BRIDGE } from './wms-event.tokens.js';
3
+ import { WMS_EVENT_OPTIONS, WMS_EVENT_EMITTER_BRIDGE } from './wms-event.tokens.mjs';
4
4
 
5
5
  var WmsEventDispatcher_1;
6
6
  /**
@@ -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 };
@@ -15,8 +15,18 @@ import type { ChangeType } from '../constants/stock-status';
15
15
  * names and payloads. Wiring is opt-in via `forRootAsync({ beforeHooks,
16
16
  * afterListeners })`; when nothing is configured the whole chain is inert.
17
17
  */
18
- export type WmsOperationEventName = 'receive-inventory-order.created' | 'receive-inventory-order.updated' | 'receive-inventory-order.received' | 'ship-inventory-order.created' | 'ship-inventory-order.updated' | 'ship-inventory-order.shipped' | 'ship-inventory-order.ship-cancelled' | 'transfer-order.created' | 'transfer-order.updated' | 'transfer-order.transferred' | 'transfer-order.transfer-cancelled' | 'hold-inventory-order.created' | 'hold-inventory-order.updated' | 'hold-inventory-order.released' | 'allocate-inventory-order.created' | 'allocate-inventory-order.updated' | 'allocate-inventory-order.deallocated' | 'transfer-vendor-order.created' | 'transfer-vendor-order.updated' | 'transfer-vendor-order.returned' | 'transfer-customer-order.created' | 'transfer-customer-order.updated' | 'transfer-customer-order.returned' | 'quality-inspection-order.inspected' | 'scrape-order.scraped' | 'reclassify-inventory-order.reclassified' | 'batch.merged' | 'batch.splitted' | 'material.created' | 'material.updated' | 'loader.created' | 'loader.batch-created' | 'loader.updated' | 'loader.type-created' | 'loader.type-updated' | 'location.created' | 'location.updated' | 'warehouse-map.updated' | 'inventory-count-order.created' | 'inventory-count-order.updated' | 'inventory-count-order.started' | 'inventory-count-order.counted' | 'inventory-count-order.reset' | 'inventory-count-order.cancelled' | 'inventory-count-order.settled';
19
- export type WmsStockEventName = 'stock.received' | 'stock.in-shipment' | 'stock.shipped' | 'stock.in-transfer' | 'stock.transferred' | 'stock.vendor-transferred' | 'stock.vendor-returned' | 'stock.held' | 'stock.released' | 'stock.customer-held' | 'stock.customer-returned' | 'stock.splitted' | 'stock.merged' | 'stock.allocated' | 'stock.deallocated' | 'stock.reclassified' | 'stock.scraped' | 'stock.inspection-resolved' | 'stock.count-gained' | 'stock.count-lost';
18
+ export type WmsOperationEventName = 'receive-inventory-order.created' | 'receive-inventory-order.updated' | 'receive-inventory-order.received' | 'ship-inventory-order.created' | 'ship-inventory-order.updated' | 'ship-inventory-order.shipped' | 'ship-inventory-order.ship-cancelled' | 'transfer-order.created' | 'transfer-order.updated' | 'transfer-order.transferred' | 'transfer-order.transfer-cancelled' | 'hold-inventory-order.created' | 'hold-inventory-order.updated' | 'hold-inventory-order.released' | 'allocate-inventory-order.created' | 'allocate-inventory-order.updated' | 'allocate-inventory-order.deallocated' | 'transfer-vendor-order.created' | 'transfer-vendor-order.updated' | 'transfer-vendor-order.returned' | 'transfer-customer-order.created' | 'transfer-customer-order.updated' | 'transfer-customer-order.returned' | 'quality-inspection-order.inspected' | 'scrape-order.scraped' | 'reclassify-inventory-order.reclassified' | 'batch.merged' | 'batch.splitted' | 'material.created' | 'material.updated' | 'loader.created' | 'loader.batch-created' | 'loader.updated' | 'loader.type-created' | 'loader.type-updated' | 'location.created' | 'location.updated' | 'warehouse-map.updated' | 'inventory-count-order.created' | 'inventory-count-order.updated' | 'inventory-count-order.started' | 'inventory-count-order.counted' | 'inventory-count-order.reset' | 'inventory-count-order.cancelled' | 'inventory-count-order.settled' | 'consumption-order.created' | 'consumption-order.updated' | 'consumption-order.issued' | 'consumption-order.returned' | 'consumption-order.settled' | 'order-reference.attached' | 'order-reference.detached';
19
+ export type WmsStockEventName = 'stock.received' | 'stock.in-shipment' | 'stock.shipped' | 'stock.in-transfer' | 'stock.transferred' | 'stock.vendor-transferred' | 'stock.vendor-returned' | 'stock.held' | 'stock.released' | 'stock.customer-held' | 'stock.customer-returned' | 'stock.splitted' | 'stock.merged' | 'stock.allocated' | 'stock.deallocated' | 'stock.reclassified' | 'stock.scraped' | 'stock.inspection-resolved' | 'stock.count-gained' | 'stock.count-lost' | 'stock.issued' | 'stock.returned' | 'stock.consumed'
20
+ /**
21
+ * A movement on a change table the host registered through
22
+ * `customChangeTables`, whose kind this package has no name for. The host's
23
+ * own string arrives as `payload.customChangeType`.
24
+ *
25
+ * One event name rather than an open union on purpose: `WmsStockEventName`
26
+ * stays closed, so the typed listener map, the GraphQL `ChangeType` enum and
27
+ * every exhaustive switch a consumer wrote keep working.
28
+ */
29
+ | 'stock.custom';
20
30
  export type WmsEventName = WmsOperationEventName | WmsStockEventName;
21
31
  /**
22
32
  * The authenticated identity that performed a mutation, in a host-neutral shape.
@@ -61,8 +71,18 @@ export interface WmsStockEventPayload {
61
71
  readonly itemId: string;
62
72
  /** `change.quantityChanged` — sign carries direction (in: +, out: -). */
63
73
  readonly quantityDelta: number;
64
- /** The resolved `ChangeType` for this stock movement (null for inspection). */
74
+ /**
75
+ * The resolved `ChangeType` for this stock movement. `null` for a quality
76
+ * inspection, which has none, and for a `stock.custom` movement, which
77
+ * carries the host's own name in {@link WmsStockEventPayload.customChangeType}
78
+ * instead.
79
+ */
65
80
  readonly changeType: ChangeType | null;
81
+ /**
82
+ * The host's own change type, present only on `stock.custom`. Opaque: this
83
+ * package never interprets it.
84
+ */
85
+ readonly customChangeType?: string;
66
86
  /** Quality-inspection result, present only on `stock.inspection-resolved`. */
67
87
  readonly inspectionResult?: boolean | null;
68
88
  readonly materialId?: string | null;
@@ -83,13 +103,25 @@ export interface WmsDomainEvent<N extends WmsEventName = WmsEventName> {
83
103
  }
84
104
  /**
85
105
  * Context handed to a before-hook. Runs *before* any DB work, so it sees the
86
- * mutation **intent** (raw GraphQL arguments) rather than a result. Throwing
87
- * vetoes the whole mutation with zero side effects.
106
+ * operation **intent** (the raw arguments) rather than a result. Throwing
107
+ * vetoes the whole operation with zero side effects.
88
108
  */
89
109
  export interface WmsBeforeHookContext<N extends WmsEventName = WmsEventName> {
90
110
  readonly event: N;
91
111
  readonly args: Readonly<Record<string, unknown>>;
92
- readonly executionContext: ExecutionContext;
112
+ /**
113
+ * The NestJS execution context, or `null` when the operation did not arrive
114
+ * through one.
115
+ *
116
+ * A host calling a domain service directly through `WmsOperationRunner` has
117
+ * no execution context to offer, and fabricating one would be worse than
118
+ * admitting it: a hook that reaches into the request would get a lie instead
119
+ * of an obvious `null`. Branch on {@link WmsBeforeHookContext.source} rather
120
+ * than on this field being present.
121
+ */
122
+ readonly executionContext: ExecutionContext | null;
123
+ /** Where the operation came in from. `'host'` means a direct service call. */
124
+ readonly source: 'graphql' | 'host';
93
125
  readonly actor: WmsActor | null;
94
126
  }
95
127
  /** Context handed to an after-listener. Runs post-commit with the event payload. */
@@ -0,0 +1,57 @@
1
+ import { type ExecutionContext } from '@nestjs/common';
2
+ import { WmsEventDispatcher } from './wms-event.dispatcher';
3
+ import type { WmsActor, WmsOperationEventName } from './wms-event.types';
4
+ export interface WmsOperationRunOptions {
5
+ /**
6
+ * The operation event to emit once the operation resolves. Omit to open a
7
+ * dispatch scope without an operation event — the shape a host wants when it
8
+ * calls a domain service directly and only cares that the `stock.*` events
9
+ * that service collects are flushed.
10
+ */
11
+ readonly event?: WmsOperationEventName;
12
+ /** The operation's intent, handed to the before-hook and the event payload. */
13
+ readonly args?: Readonly<Record<string, unknown>>;
14
+ /** Who performed it. `null` when the host does not track an actor. */
15
+ readonly actor?: WmsActor | null;
16
+ /** Override how the event's correlation id is derived from the result. */
17
+ readonly resolveId?: (result: unknown, args: Readonly<Record<string, unknown>>) => string | null;
18
+ /**
19
+ * The NestJS execution context, when there is one. `null` for a host calling
20
+ * a service directly — which is why {@link WmsBeforeHookContext} declares it
21
+ * nullable.
22
+ */
23
+ readonly executionContext?: ExecutionContext | null;
24
+ }
25
+ /**
26
+ * Runs one WMS operation with the full event guarantee, from any caller.
27
+ *
28
+ * The four steps — before-hook (a throw vetoes, before any DB work), the
29
+ * operation itself, the operation event, and a single post-commit flush of
30
+ * everything the services collected on the way — used to live inside
31
+ * `WmsMutationInterceptor`, which meant they only happened for callers coming
32
+ * in through GraphQL. A host driving the warehouse from its own code path got
33
+ * no hooks, no actor and no events: `StockChangeSubscriber` still collected
34
+ * them, but with no scope open there was nothing to collect into and nobody to
35
+ * flush.
36
+ *
37
+ * That is the case that matters. A host with its own inbound flow calls the
38
+ * domain services directly, and `InventoryCountLockSubscriber` already goes out
39
+ * of its way to cover exactly that caller.
40
+ *
41
+ * The interceptor now delegates here, so the two paths cannot drift.
42
+ *
43
+ * ```ts
44
+ * await runner.run(
45
+ * { event: 'transfer-order.transferred', args: { orderId }, actor },
46
+ * () => transferOrderService.transfer(orderId),
47
+ * );
48
+ * ```
49
+ *
50
+ * Nesting is safe: an inner call joins the outer scope and only the outermost
51
+ * one flushes, so a host may wrap a service that itself runs operations.
52
+ */
53
+ export declare class WmsOperationRunner {
54
+ private readonly dispatcher;
55
+ constructor(dispatcher: WmsEventDispatcher);
56
+ run<T>(options: WmsOperationRunOptions, operation: () => Promise<T>): Promise<T>;
57
+ }
@@ -0,0 +1,101 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import { Injectable } from '@nestjs/common';
3
+ import { runInDispatchScope, collectToScope } from './dispatch-scope.mjs';
4
+ import { WmsEventDispatcher } from './wms-event.dispatcher.mjs';
5
+
6
+ /**
7
+ * Derive the operation event's correlation id from whatever the operation
8
+ * returned, falling back to an `id` argument. Action operations that return a
9
+ * bare `boolean` land on the argument.
10
+ */
11
+ const defaultResolveId = (result, args) => {
12
+ if (result &&
13
+ typeof result === 'object' &&
14
+ 'id' in result &&
15
+ typeof result.id === 'string') {
16
+ return result.id;
17
+ }
18
+ const argId = args['id'];
19
+ return typeof argId === 'string' ? argId : null;
20
+ };
21
+ /**
22
+ * Runs one WMS operation with the full event guarantee, from any caller.
23
+ *
24
+ * The four steps — before-hook (a throw vetoes, before any DB work), the
25
+ * operation itself, the operation event, and a single post-commit flush of
26
+ * everything the services collected on the way — used to live inside
27
+ * `WmsMutationInterceptor`, which meant they only happened for callers coming
28
+ * in through GraphQL. A host driving the warehouse from its own code path got
29
+ * no hooks, no actor and no events: `StockChangeSubscriber` still collected
30
+ * them, but with no scope open there was nothing to collect into and nobody to
31
+ * flush.
32
+ *
33
+ * That is the case that matters. A host with its own inbound flow calls the
34
+ * domain services directly, and `InventoryCountLockSubscriber` already goes out
35
+ * of its way to cover exactly that caller.
36
+ *
37
+ * The interceptor now delegates here, so the two paths cannot drift.
38
+ *
39
+ * ```ts
40
+ * await runner.run(
41
+ * { event: 'transfer-order.transferred', args: { orderId }, actor },
42
+ * () => transferOrderService.transfer(orderId),
43
+ * );
44
+ * ```
45
+ *
46
+ * Nesting is safe: an inner call joins the outer scope and only the outermost
47
+ * one flushes, so a host may wrap a service that itself runs operations.
48
+ */
49
+ let WmsOperationRunner = class WmsOperationRunner {
50
+ dispatcher;
51
+ constructor(dispatcher) {
52
+ this.dispatcher = dispatcher;
53
+ }
54
+ async run(options, operation) {
55
+ // Nothing wired: run the operation and skip the machinery entirely, the way
56
+ // the interceptor always has. `collectToScope` is already a no-op outside a
57
+ // scope, so the services behave identically.
58
+ if (!this.dispatcher.isActive()) {
59
+ return operation();
60
+ }
61
+ const args = options.args ?? {};
62
+ const actor = options.actor ?? null;
63
+ if (options.event) {
64
+ // Before any DB work, so a throw vetoes with zero side effects.
65
+ await this.dispatcher.runBeforeHook({
66
+ event: options.event,
67
+ args,
68
+ executionContext: options.executionContext ?? null,
69
+ source: options.executionContext ? 'graphql' : 'host',
70
+ actor,
71
+ });
72
+ }
73
+ const { result, events } = await runInDispatchScope(async () => {
74
+ const operationResult = await operation();
75
+ if (options.event) {
76
+ const resolveId = options.resolveId ?? defaultResolveId;
77
+ const operationEvent = {
78
+ name: options.event,
79
+ payload: {
80
+ id: resolveId(operationResult, args),
81
+ result: operationResult,
82
+ args,
83
+ actor,
84
+ },
85
+ };
86
+ collectToScope(operationEvent);
87
+ }
88
+ return operationResult;
89
+ });
90
+ if (events) {
91
+ await this.dispatcher.flush(events);
92
+ }
93
+ return result;
94
+ }
95
+ };
96
+ WmsOperationRunner = __decorate([
97
+ Injectable(),
98
+ __metadata("design:paramtypes", [WmsEventDispatcher])
99
+ ], WmsOperationRunner);
100
+
101
+ export { WmsOperationRunner };
@@ -1,7 +1,7 @@
1
1
  import { __decorate, __metadata } from 'tslib';
2
2
  import { OrderEntity } from '@rytass/wms-base-nestjs-module';
3
3
  import { PrimaryGeneratedColumn, Column, OneToOne, JoinColumn, ManyToOne, Entity } from 'typeorm';
4
- import { AllocateInventoryOrderItemEntityClass } from './allocate-inventory-order-item.entity.js';
4
+ import { AllocateInventoryOrderItemEntityClass } from './allocate-inventory-order-item.entity.mjs';
5
5
 
6
6
  const AllocateInventoryOrderChangeEntity = Symbol('AllocateInventoryOrderChangeEntity');
7
7
  let AllocateInventoryOrderChangeEntityClass = class AllocateInventoryOrderChangeEntityClass {
@@ -1,18 +1,18 @@
1
1
  import { __decorate, __metadata } from 'tslib';
2
2
  import { PrimaryGeneratedColumn, Column, Index, ManyToOne, JoinColumn, Entity, TableInheritance } from 'typeorm';
3
- import '../../metadata/batch.entity.js';
4
- import '../../metadata/batch-group.entity.js';
5
- import { LoadersEntityClass } from '../../metadata/loader.entity.js';
6
- import '../../metadata/loader-type.entity.js';
7
- import '../../metadata/loader-unit.entity.js';
8
- import { LocationEntityClass } from '../../metadata/location.entity.js';
9
- import '../../metadata/material.entity.js';
10
- import '../../metadata/material-unit.entity.js';
3
+ import '../../metadata/batch.entity.mjs';
4
+ import '../../metadata/batch-group.entity.mjs';
5
+ import { LoadersEntityClass } from '../../metadata/loader.entity.mjs';
6
+ import '../../metadata/loader-type.entity.mjs';
7
+ import '../../metadata/loader-unit.entity.mjs';
8
+ import { LocationEntityClass } from '../../metadata/location.entity.mjs';
9
+ import '../../metadata/material.entity.mjs';
10
+ import '../../metadata/material-unit.entity.mjs';
11
11
  import '@rytass/wms-base-nestjs-module';
12
- import '../../metadata/sale-order.entity.js';
13
- import '../../metadata/stock.entity.js';
14
- import '../../metadata/unit.entity.js';
15
- import { AllocateInventoryOrderEntityClass } from './allocate-inventory-order.entity.js';
12
+ import '../../metadata/sale-order.entity.mjs';
13
+ import '../../metadata/stock.entity.mjs';
14
+ import '../../metadata/unit.entity.mjs';
15
+ import { AllocateInventoryOrderEntityClass } from './allocate-inventory-order.entity.mjs';
16
16
 
17
17
  const AllocateInventoryOrderItemEntity = Symbol('AllocateInventoryOrderItemEntity');
18
18
  let AllocateInventoryOrderItemEntityClass = class AllocateInventoryOrderItemEntityClass {
@@ -0,0 +1,19 @@
1
+ import { OrderEntity } from '@rytass/wms-base-nestjs-module';
2
+ import { ConsumptionChangeKind } from '../../../constants/consumption-change-kind';
3
+ import { ConsumptionOrderItemEntityClass } from './consumption-order-item.entity';
4
+ export declare const ConsumptionOrderChangeEntity: unique symbol;
5
+ export declare class ConsumptionOrderChangeEntityClass {
6
+ id: string;
7
+ itemId: string;
8
+ /** Positive for an issue, negative for a return or a settlement. */
9
+ quantityChanged: number;
10
+ /**
11
+ * Which of the three actions wrote this row. A return and a settlement are
12
+ * both negative, so the sign cannot carry it -- see
13
+ * {@link ConsumptionChangeKind}.
14
+ */
15
+ kind: ConsumptionChangeKind;
16
+ createdAt: Date;
17
+ order: OrderEntity;
18
+ item: ConsumptionOrderItemEntityClass;
19
+ }
@@ -0,0 +1,59 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import { OrderEntity } from '@rytass/wms-base-nestjs-module';
3
+ import { PrimaryGeneratedColumn, Column, Index, CreateDateColumn, OneToOne, JoinColumn, ManyToOne, Entity } from 'typeorm';
4
+ import '../../../constants/consumption-change-kind.mjs';
5
+ import { ConsumptionOrderItemEntityClass } from './consumption-order-item.entity.mjs';
6
+
7
+ const ConsumptionOrderChangeEntity = Symbol('ConsumptionOrderChangeEntity');
8
+ let ConsumptionOrderChangeEntityClass = class ConsumptionOrderChangeEntityClass {
9
+ id;
10
+ itemId;
11
+ /** Positive for an issue, negative for a return or a settlement. */
12
+ quantityChanged;
13
+ /**
14
+ * Which of the three actions wrote this row. A return and a settlement are
15
+ * both negative, so the sign cannot carry it -- see
16
+ * {@link ConsumptionChangeKind}.
17
+ */
18
+ kind;
19
+ createdAt;
20
+ order;
21
+ item;
22
+ };
23
+ __decorate([
24
+ PrimaryGeneratedColumn('uuid'),
25
+ __metadata("design:type", String)
26
+ ], ConsumptionOrderChangeEntityClass.prototype, "id", void 0);
27
+ __decorate([
28
+ Column({ type: 'uuid' }),
29
+ Index(),
30
+ __metadata("design:type", String)
31
+ ], ConsumptionOrderChangeEntityClass.prototype, "itemId", void 0);
32
+ __decorate([
33
+ Column({ type: 'numeric' }),
34
+ __metadata("design:type", Number)
35
+ ], ConsumptionOrderChangeEntityClass.prototype, "quantityChanged", void 0);
36
+ __decorate([
37
+ Column({ type: 'varchar' }),
38
+ Index(),
39
+ __metadata("design:type", String)
40
+ ], ConsumptionOrderChangeEntityClass.prototype, "kind", void 0);
41
+ __decorate([
42
+ CreateDateColumn({ type: 'timestamptz' }),
43
+ __metadata("design:type", Date)
44
+ ], ConsumptionOrderChangeEntityClass.prototype, "createdAt", void 0);
45
+ __decorate([
46
+ OneToOne('orders'),
47
+ JoinColumn({ name: 'id', referencedColumnName: 'id' }),
48
+ __metadata("design:type", OrderEntity)
49
+ ], ConsumptionOrderChangeEntityClass.prototype, "order", void 0);
50
+ __decorate([
51
+ ManyToOne('consumption_order_items', (item) => item.changes),
52
+ JoinColumn({ name: 'itemId', referencedColumnName: 'id' }),
53
+ __metadata("design:type", ConsumptionOrderItemEntityClass)
54
+ ], ConsumptionOrderChangeEntityClass.prototype, "item", void 0);
55
+ ConsumptionOrderChangeEntityClass = __decorate([
56
+ Entity('consumption_order_changes')
57
+ ], ConsumptionOrderChangeEntityClass);
58
+
59
+ export { ConsumptionOrderChangeEntity, ConsumptionOrderChangeEntityClass };