@rytass/wms-module-graphql 0.10.1 → 0.11.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 (58) hide show
  1. package/index.cjs.js +1017 -114
  2. package/lib/dto/consumption-order-item.dto.d.ts +17 -0
  3. package/lib/dto/consumption-order-item.dto.js +43 -0
  4. package/lib/dto/consumption-order.dto.d.ts +14 -0
  5. package/lib/dto/consumption-order.dto.js +52 -0
  6. package/lib/dto/index.d.ts +3 -0
  7. package/lib/dto/inventory-count-order.dto.d.ts +7 -1
  8. package/lib/dto/inventory-count-order.dto.js +11 -1
  9. package/lib/dto/order-reference.dto.d.ts +22 -0
  10. package/lib/dto/order-reference.dto.js +73 -0
  11. package/lib/dto/stock.dto.d.ts +15 -0
  12. package/lib/dto/stock.dto.js +28 -0
  13. package/lib/events/operation-result-map.d.ts +13 -0
  14. package/lib/events/typed-maps.d.ts +17 -7
  15. package/lib/events/wms-mutation.interceptor.d.ts +11 -9
  16. package/lib/events/wms-mutation.interceptor.js +19 -45
  17. package/lib/graphql.module.d.ts +1 -1
  18. package/lib/graphql.module.js +30 -13
  19. package/lib/inputs/consumption-order.args.d.ts +47 -0
  20. package/lib/inputs/consumption-order.args.js +182 -0
  21. package/lib/inputs/find-stock.args.d.ts +6 -0
  22. package/lib/inputs/find-stock.args.js +10 -0
  23. package/lib/inputs/order-reference.args.d.ts +32 -0
  24. package/lib/inputs/order-reference.args.js +103 -0
  25. package/lib/inputs/split-batch.args.d.ts +6 -0
  26. package/lib/inputs/split-batch.args.js +11 -0
  27. package/lib/mutations/consumption-order.mutation.d.ts +18 -0
  28. package/lib/mutations/consumption-order.mutation.js +90 -0
  29. package/lib/mutations/loader.mutation.js +3 -0
  30. package/lib/mutations/material.mutation.js +3 -0
  31. package/lib/mutations/order-reference.mutation.d.ts +13 -0
  32. package/lib/mutations/order-reference.mutation.js +57 -0
  33. package/lib/mutations/receive-inventory-order.mutation.js +3 -0
  34. package/lib/mutations/ship-inventory-order.mutation.js +3 -0
  35. package/lib/queries/consumption-order.query.d.ts +9 -0
  36. package/lib/queries/consumption-order.query.js +45 -0
  37. package/lib/queries/loader.query.js +4 -3
  38. package/lib/queries/material.query.js +3 -0
  39. package/lib/queries/order-reference.query.d.ts +8 -0
  40. package/lib/queries/order-reference.query.js +34 -0
  41. package/lib/queries/recieve-inventory-order.query.js +3 -0
  42. package/lib/queries/ship-inventory-order.query.js +3 -0
  43. package/lib/queries/stock.query.js +4 -5
  44. package/lib/resolvers/aggregated-stock.resolver.js +3 -0
  45. package/lib/resolvers/change-log.resolver.js +3 -0
  46. package/lib/resolvers/consumption-order.resolver.d.ts +40 -0
  47. package/lib/resolvers/consumption-order.resolver.js +238 -0
  48. package/lib/resolvers/loader-type.resolver.js +3 -0
  49. package/lib/resolvers/loader.resolver.js +3 -1
  50. package/lib/resolvers/material.resolver.js +3 -1
  51. package/lib/resolvers/receive-inventory-order.resolver.js +3 -0
  52. package/lib/resolvers/ship-inventory-order.resolver.js +3 -0
  53. package/lib/resolvers/stock.resolver.js +3 -0
  54. package/lib/resolvers/transfer-order.resolver.js +3 -0
  55. package/lib/scalars/index.d.ts +1 -0
  56. package/lib/scalars/json-object.scalar.d.ts +2 -0
  57. package/lib/scalars/json-object.scalar.js +62 -0
  58. package/package.json +2 -2
package/index.cjs.js CHANGED
@@ -11,6 +11,7 @@ var DataLoader = require('dataloader');
11
11
  var graphql = require('@nestjs/graphql');
12
12
  var core = require('@nestjs/core');
13
13
  var rxjs = require('rxjs');
14
+ var graphql$1 = require('graphql');
14
15
  var wmsBaseNestjsModule = require('@rytass/wms-base-nestjs-module');
15
16
 
16
17
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -369,32 +370,24 @@ const WmsOperation = (requirement) => common.applyDecorators(common.SetMetadata(
369
370
  /** Reflector metadata key carrying the {@link WmsMutationEventConfig}. */
370
371
  const WMS_MUTATION_EVENT_METADATA = 'wms:mutation-event';
371
372
 
372
- const defaultResolveId = (result, args) => {
373
- if (result &&
374
- typeof result === 'object' &&
375
- 'id' in result &&
376
- typeof result.id === 'string') {
377
- return result.id;
378
- }
379
- const argId = args['id'];
380
- return typeof argId === 'string' ? argId : null;
381
- };
382
373
  /**
383
- * Wraps each `@WmsMutationEvent` mutation in a dispatch scope:
384
- * 1. runs the before-hook (throw -> veto, before any transaction);
385
- * 2. executes the resolver (services collect stock events into the scope);
386
- * 3. emits the operation event after the handler resolves (post-commit);
387
- * 4. flushes the whole buffer to after-listeners + emitter bridge.
374
+ * Hands each `@WmsMutationEvent` mutation to {@link WmsOperationRunner}, which
375
+ * owns the before-hook / dispatch scope / post-commit flush sequence.
388
376
  *
389
- * When no hook/listener/bridge is configured it passes through untouched.
377
+ * All this adds on top is what only a GraphQL request can supply: the raw
378
+ * arguments and the actor. Keeping the sequence itself in core is what stops
379
+ * the GraphQL path and a host's direct service call from drifting apart.
380
+ *
381
+ * When no hook, listener or bridge is configured the runner passes through
382
+ * untouched.
390
383
  */
391
384
  exports.WmsMutationInterceptor = class WmsMutationInterceptor {
392
385
  reflector;
393
- dispatcher;
386
+ runner;
394
387
  actorExtractor;
395
- constructor(reflector, dispatcher, actorExtractor = null) {
388
+ constructor(reflector, runner, actorExtractor = null) {
396
389
  this.reflector = reflector;
397
- this.dispatcher = dispatcher;
390
+ this.runner = runner;
398
391
  this.actorExtractor = actorExtractor;
399
392
  }
400
393
  resolveActor(context) {
@@ -411,34 +404,16 @@ exports.WmsMutationInterceptor = class WmsMutationInterceptor {
411
404
  }
412
405
  async intercept(context, next) {
413
406
  const config = this.reflector.get(WMS_MUTATION_EVENT_METADATA, context.getHandler());
414
- if (!config || !this.dispatcher.isActive()) {
407
+ if (!config) {
415
408
  return next.handle();
416
409
  }
417
- const args = graphql.GqlExecutionContext.create(context).getArgs() ??
418
- {};
419
- const actor = this.resolveActor(context);
420
- // Before-hook runs before any DB work; a throw vetoes with zero side effects.
421
- await this.dispatcher.runBeforeHook({
410
+ const result = await this.runner.run({
422
411
  event: config.event,
423
- args,
412
+ args: graphql.GqlExecutionContext.create(context).getArgs() ?? {},
413
+ actor: this.resolveActor(context),
414
+ resolveId: config.resolveId,
424
415
  executionContext: context,
425
- actor,
426
- });
427
- const { result, events } = await wmsModuleCore.runInDispatchScope(async () => {
428
- const handlerResult = await rxjs.firstValueFrom(next.handle());
429
- const id = config.resolveId
430
- ? config.resolveId(handlerResult, args)
431
- : defaultResolveId(handlerResult, args);
432
- const operationEvent = {
433
- name: config.event,
434
- payload: { id, result: handlerResult, args, actor },
435
- };
436
- wmsModuleCore.collectToScope(operationEvent);
437
- return handlerResult;
438
- });
439
- if (events) {
440
- await this.dispatcher.flush(events);
441
- }
416
+ }, () => rxjs.firstValueFrom(next.handle()));
442
417
  return rxjs.of(result);
443
418
  }
444
419
  };
@@ -447,7 +422,7 @@ exports.WmsMutationInterceptor = tslib.__decorate([
447
422
  tslib.__param(2, common.Optional()),
448
423
  tslib.__param(2, common.Inject(wmsModuleCore.WMS_ACTOR_EXTRACTOR)),
449
424
  tslib.__metadata("design:paramtypes", [core.Reflector,
450
- wmsModuleCore.WmsEventDispatcher, Object])
425
+ wmsModuleCore.WmsOperationRunner, Object])
451
426
  ], exports.WmsMutationInterceptor);
452
427
 
453
428
  /**
@@ -822,6 +797,65 @@ MaterialUnits = tslib.__decorate([
822
797
  graphql.ObjectType()
823
798
  ], MaterialUnits);
824
799
 
800
+ /**
801
+ * A JSON object scalar, defined here rather than pulled from `graphql-type-json`
802
+ * so the package keeps its peer dependency list as it is — `graphql` is already
803
+ * required, and this is the whole of what we need from such a library.
804
+ *
805
+ * Deliberately narrower than "any JSON": the values it guards (a batch's
806
+ * host-defined `attributes`) are always a keyed record, and refusing a bare
807
+ * scalar or array at the edge means every consumer downstream can rely on that
808
+ * without re-checking.
809
+ */
810
+ function parseLiteralValue(node) {
811
+ switch (node.kind) {
812
+ case graphql$1.Kind.STRING:
813
+ case graphql$1.Kind.BOOLEAN:
814
+ return node.value;
815
+ case graphql$1.Kind.INT:
816
+ case graphql$1.Kind.FLOAT:
817
+ return Number(node.value);
818
+ case graphql$1.Kind.NULL:
819
+ return null;
820
+ case graphql$1.Kind.LIST:
821
+ return node.values.map(parseLiteralValue);
822
+ case graphql$1.Kind.OBJECT:
823
+ return parseObjectLiteral(node);
824
+ default:
825
+ throw new graphql$1.GraphQLError(`JSONObject cannot represent a ${node.kind} literal`, { nodes: node });
826
+ }
827
+ }
828
+ function parseObjectLiteral(node) {
829
+ return node.fields.reduce((carry, field) => {
830
+ return { ...carry, [field.name.value]: parseLiteralValue(field.value) };
831
+ }, {});
832
+ }
833
+ function assertPlainObject(value) {
834
+ if (typeof value !== 'object' ||
835
+ value === null ||
836
+ Array.isArray(value) ||
837
+ // A Date or any other class instance serializes to something the host did
838
+ // not write; reject it here rather than let it reach the column.
839
+ Object.getPrototypeOf(value) !== Object.prototype) {
840
+ throw new graphql$1.GraphQLError('JSONObject must be a plain JSON object');
841
+ }
842
+ return value;
843
+ }
844
+ const GraphQLJSONObject = new graphql$1.GraphQLScalarType({
845
+ name: 'JSONObject',
846
+ description: 'An arbitrary JSON object supplied by the host. Its keys and values are stored verbatim and are never interpreted by this module.',
847
+ serialize: (value) => assertPlainObject(value),
848
+ parseValue: (value) => assertPlainObject(value),
849
+ parseLiteral: (node) => {
850
+ if (node.kind !== graphql$1.Kind.OBJECT) {
851
+ throw new graphql$1.GraphQLError('JSONObject must be an object literal', {
852
+ nodes: node,
853
+ });
854
+ }
855
+ return parseObjectLiteral(node);
856
+ },
857
+ });
858
+
825
859
  let StockDto = class StockDto {
826
860
  id;
827
861
  loaderId;
@@ -867,6 +901,21 @@ let AggregatedStockDto = class AggregatedStockDto {
867
901
  customerId;
868
902
  vendorId;
869
903
  inspectionResult;
904
+ /**
905
+ * Whether anyone asked for this batch to be inspected. Paired with
906
+ * `inspectionResult`, it is what separates "awaiting inspection" from
907
+ * "nobody ever intended to inspect this", which `inspectionResult` alone
908
+ * cannot say.
909
+ */
910
+ requiresInspection;
911
+ /**
912
+ * Batch lineage and the host's own attributes, flattened onto the row the way
913
+ * every other batch column here already is. `batch` resolves to the batch
914
+ * *group*, which is what carries the human-readable key — these two live on
915
+ * the batch itself and would otherwise be unreachable from a stock list.
916
+ */
917
+ parentBatchId;
918
+ attributes;
870
919
  };
871
920
  tslib.__decorate([
872
921
  graphql.Field(() => graphql.Int),
@@ -908,6 +957,18 @@ tslib.__decorate([
908
957
  graphql.Field(() => Boolean, { nullable: true }),
909
958
  tslib.__metadata("design:type", Boolean)
910
959
  ], AggregatedStockDto.prototype, "inspectionResult", void 0);
960
+ tslib.__decorate([
961
+ graphql.Field(() => Boolean, { nullable: true }),
962
+ tslib.__metadata("design:type", Boolean)
963
+ ], AggregatedStockDto.prototype, "requiresInspection", void 0);
964
+ tslib.__decorate([
965
+ graphql.Field(() => graphql.ID, { nullable: true }),
966
+ tslib.__metadata("design:type", Object)
967
+ ], AggregatedStockDto.prototype, "parentBatchId", void 0);
968
+ tslib.__decorate([
969
+ graphql.Field(() => GraphQLJSONObject, { nullable: true }),
970
+ tslib.__metadata("design:type", Object)
971
+ ], AggregatedStockDto.prototype, "attributes", void 0);
911
972
  AggregatedStockDto = tslib.__decorate([
912
973
  graphql.ObjectType()
913
974
  ], AggregatedStockDto);
@@ -1767,8 +1828,14 @@ let InventoryCountOrderItemDto = class InventoryCountOrderItemDto {
1767
1828
  // a record of what was found. `null` before counting has started.
1768
1829
  held;
1769
1830
  inShipment;
1770
- /** `null` = awaiting inspection, `false` = failed, `true` = passed. */
1831
+ /**
1832
+ * `false` = failed, `true` = passed, `null` = not inspected — which is the
1833
+ * resting state of almost every batch and does **not** on its own mean
1834
+ * awaiting inspection. Pair it with `requiresInspection`.
1835
+ */
1771
1836
  inspectionResult;
1837
+ /** Whether anybody had asked for this position to be inspected. */
1838
+ requiresInspection;
1772
1839
  transferId;
1773
1840
  vendorId;
1774
1841
  customerId;
@@ -1827,6 +1894,10 @@ tslib.__decorate([
1827
1894
  graphql.Field(() => Boolean, { nullable: true }),
1828
1895
  tslib.__metadata("design:type", Object)
1829
1896
  ], InventoryCountOrderItemDto.prototype, "inspectionResult", void 0);
1897
+ tslib.__decorate([
1898
+ graphql.Field(() => Boolean, { nullable: true }),
1899
+ tslib.__metadata("design:type", Object)
1900
+ ], InventoryCountOrderItemDto.prototype, "requiresInspection", void 0);
1830
1901
  tslib.__decorate([
1831
1902
  graphql.Field(() => graphql.ID, { nullable: true }),
1832
1903
  tslib.__metadata("design:type", Object)
@@ -1925,6 +1996,156 @@ InventoryCountOrders = tslib.__decorate([
1925
1996
  graphql.ObjectType()
1926
1997
  ], InventoryCountOrders);
1927
1998
 
1999
+ let ConsumptionOrderItemDto = class ConsumptionOrderItemDto {
2000
+ id;
2001
+ materialId;
2002
+ batchId;
2003
+ locationId;
2004
+ loaderId;
2005
+ targetLocationId;
2006
+ targetLoaderId;
2007
+ orderId;
2008
+ unitId;
2009
+ targetConsumedQuantity;
2010
+ removedAt;
2011
+ };
2012
+ tslib.__decorate([
2013
+ graphql.Field(() => graphql.ID),
2014
+ tslib.__metadata("design:type", String)
2015
+ ], ConsumptionOrderItemDto.prototype, "id", void 0);
2016
+ tslib.__decorate([
2017
+ graphql.Field(() => String, { nullable: true }),
2018
+ tslib.__metadata("design:type", Object)
2019
+ ], ConsumptionOrderItemDto.prototype, "unitId", void 0);
2020
+ tslib.__decorate([
2021
+ graphql.Field(() => graphql.Float),
2022
+ tslib.__metadata("design:type", Number)
2023
+ ], ConsumptionOrderItemDto.prototype, "targetConsumedQuantity", void 0);
2024
+ tslib.__decorate([
2025
+ graphql.Field(() => Date, { nullable: true }),
2026
+ tslib.__metadata("design:type", Object)
2027
+ ], ConsumptionOrderItemDto.prototype, "removedAt", void 0);
2028
+ ConsumptionOrderItemDto = tslib.__decorate([
2029
+ graphql.ObjectType()
2030
+ ], ConsumptionOrderItemDto);
2031
+ let ConsumptionOrderItems = class ConsumptionOrderItems extends PaginatedResponse(ConsumptionOrderItemDto) {
2032
+ };
2033
+ ConsumptionOrderItems = tslib.__decorate([
2034
+ graphql.ObjectType()
2035
+ ], ConsumptionOrderItems);
2036
+
2037
+ let ConsumptionOrderDto = class ConsumptionOrderDto {
2038
+ id;
2039
+ key;
2040
+ description;
2041
+ createdBy;
2042
+ removedAt;
2043
+ createdAt;
2044
+ items;
2045
+ };
2046
+ tslib.__decorate([
2047
+ graphql.Field(() => graphql.ID),
2048
+ tslib.__metadata("design:type", String)
2049
+ ], ConsumptionOrderDto.prototype, "id", void 0);
2050
+ tslib.__decorate([
2051
+ graphql.Field(() => String),
2052
+ tslib.__metadata("design:type", String)
2053
+ ], ConsumptionOrderDto.prototype, "key", void 0);
2054
+ tslib.__decorate([
2055
+ graphql.Field(() => String, { nullable: true }),
2056
+ tslib.__metadata("design:type", Object)
2057
+ ], ConsumptionOrderDto.prototype, "description", void 0);
2058
+ tslib.__decorate([
2059
+ graphql.Field(() => String, { nullable: true }),
2060
+ tslib.__metadata("design:type", Object)
2061
+ ], ConsumptionOrderDto.prototype, "createdBy", void 0);
2062
+ tslib.__decorate([
2063
+ graphql.Field(() => Date, { nullable: true }),
2064
+ tslib.__metadata("design:type", Object)
2065
+ ], ConsumptionOrderDto.prototype, "removedAt", void 0);
2066
+ tslib.__decorate([
2067
+ graphql.Field(() => Date),
2068
+ tslib.__metadata("design:type", Date)
2069
+ ], ConsumptionOrderDto.prototype, "createdAt", void 0);
2070
+ tslib.__decorate([
2071
+ graphql.Field(() => [ConsumptionOrderItemDto]),
2072
+ tslib.__metadata("design:type", Array)
2073
+ ], ConsumptionOrderDto.prototype, "items", void 0);
2074
+ ConsumptionOrderDto = tslib.__decorate([
2075
+ graphql.ObjectType()
2076
+ ], ConsumptionOrderDto);
2077
+ let ConsumptionOrders = class ConsumptionOrders extends PaginatedResponse(ConsumptionOrderDto) {
2078
+ };
2079
+ ConsumptionOrders = tslib.__decorate([
2080
+ graphql.ObjectType()
2081
+ ], ConsumptionOrders);
2082
+
2083
+ graphql.registerEnumType(wmsModuleCore.WmsOrderType, {
2084
+ name: 'WmsOrderType',
2085
+ description: 'An order family in this module, named the same way `@WmsOperation` names it.',
2086
+ });
2087
+ /**
2088
+ * A link from one of this module's orders to the document in the host system it
2089
+ * was opened for. The module stores `referenceType` / `referenceId` verbatim
2090
+ * and never resolves them — turning one into a link is the host's job (see
2091
+ * `referenceLinkResolver` in `@rytass/wms-module-react`).
2092
+ */
2093
+ let OrderReferenceDto = class OrderReferenceDto {
2094
+ id;
2095
+ orderType;
2096
+ orderId;
2097
+ itemId;
2098
+ referenceType;
2099
+ referenceId;
2100
+ referenceLine;
2101
+ metadata;
2102
+ createdAt;
2103
+ };
2104
+ tslib.__decorate([
2105
+ graphql.Field(() => graphql.ID),
2106
+ tslib.__metadata("design:type", String)
2107
+ ], OrderReferenceDto.prototype, "id", void 0);
2108
+ tslib.__decorate([
2109
+ graphql.Field(() => wmsModuleCore.WmsOrderType),
2110
+ tslib.__metadata("design:type", String)
2111
+ ], OrderReferenceDto.prototype, "orderType", void 0);
2112
+ tslib.__decorate([
2113
+ graphql.Field(() => graphql.ID),
2114
+ tslib.__metadata("design:type", String)
2115
+ ], OrderReferenceDto.prototype, "orderId", void 0);
2116
+ tslib.__decorate([
2117
+ graphql.Field(() => graphql.ID, { nullable: true }),
2118
+ tslib.__metadata("design:type", Object)
2119
+ ], OrderReferenceDto.prototype, "itemId", void 0);
2120
+ tslib.__decorate([
2121
+ graphql.Field(() => String),
2122
+ tslib.__metadata("design:type", String)
2123
+ ], OrderReferenceDto.prototype, "referenceType", void 0);
2124
+ tslib.__decorate([
2125
+ graphql.Field(() => String),
2126
+ tslib.__metadata("design:type", String)
2127
+ ], OrderReferenceDto.prototype, "referenceId", void 0);
2128
+ tslib.__decorate([
2129
+ graphql.Field(() => String, { nullable: true }),
2130
+ tslib.__metadata("design:type", Object)
2131
+ ], OrderReferenceDto.prototype, "referenceLine", void 0);
2132
+ tslib.__decorate([
2133
+ graphql.Field(() => GraphQLJSONObject, { nullable: true }),
2134
+ tslib.__metadata("design:type", Object)
2135
+ ], OrderReferenceDto.prototype, "metadata", void 0);
2136
+ tslib.__decorate([
2137
+ graphql.Field(() => Date),
2138
+ tslib.__metadata("design:type", Date)
2139
+ ], OrderReferenceDto.prototype, "createdAt", void 0);
2140
+ OrderReferenceDto = tslib.__decorate([
2141
+ graphql.ObjectType()
2142
+ ], OrderReferenceDto);
2143
+ let OrderReferences = class OrderReferences extends PaginatedResponse(OrderReferenceDto) {
2144
+ };
2145
+ OrderReferences = tslib.__decorate([
2146
+ graphql.ObjectType()
2147
+ ], OrderReferences);
2148
+
1928
2149
  let CreateLoaderTypeArgs = class CreateLoaderTypeArgs {
1929
2150
  description;
1930
2151
  key;
@@ -2351,9 +2572,7 @@ let LoaderQuery = class LoaderQuery {
2351
2572
  if (loader.locationId === locationId)
2352
2573
  loaders.push(loader);
2353
2574
  });
2354
- const [aggregatedStocks] = await this.stockService.findAggregatedStocks({
2355
- aggregated: true,
2356
- });
2575
+ const [aggregatedStocks] = await this.stockService.findAggregatedStocks({});
2357
2576
  // Collect loaderIds that currently have stock
2358
2577
  const loaderIdsWithStock = new Set(aggregatedStocks.map((s) => s.loaderId).filter(Boolean));
2359
2578
  // Find targetLoaderIds booked in not-yet-executed transfer order items
@@ -2599,6 +2818,12 @@ let FindStockArgs = class FindStockArgs extends PaginationArgs {
2599
2818
  materialId;
2600
2819
  batchId;
2601
2820
  locationId;
2821
+ /**
2822
+ * Locations to leave out of the result. Subtractive counterpart to
2823
+ * `locationId`: a stock report uses it to drop locations that do not hold
2824
+ * available inventory (staging, quarantine, a host's work-in-progress lane).
2825
+ */
2826
+ excludeLocationIds;
2602
2827
  loaderId;
2603
2828
  ids;
2604
2829
  description;
@@ -2629,6 +2854,10 @@ tslib.__decorate([
2629
2854
  graphql.Field(() => graphql.ID, { nullable: true }),
2630
2855
  tslib.__metadata("design:type", String)
2631
2856
  ], FindStockArgs.prototype, "locationId", void 0);
2857
+ tslib.__decorate([
2858
+ graphql.Field(() => [graphql.ID], { nullable: true }),
2859
+ tslib.__metadata("design:type", Array)
2860
+ ], FindStockArgs.prototype, "excludeLocationIds", void 0);
2632
2861
  tslib.__decorate([
2633
2862
  graphql.Field(() => graphql.ID, { nullable: true }),
2634
2863
  tslib.__metadata("design:type", String)
@@ -2700,16 +2929,12 @@ let StockQuery = class StockQuery {
2700
2929
  async aggregatedStocks(args) {
2701
2930
  const [items, total] = await this.stockService.findAggregatedStocks({
2702
2931
  ...args,
2703
- aggregated: true,
2704
2932
  aggregatedKeys: args.ids?.length ? args.ids : [],
2705
2933
  });
2706
2934
  return { items, total };
2707
2935
  }
2708
2936
  async changeLogs(args) {
2709
- const [items, total] = await this.stockService.findChangeLogs({
2710
- ...args,
2711
- aggregated: false,
2712
- });
2937
+ const [items, total] = await this.stockService.findChangeLogs(args);
2713
2938
  return {
2714
2939
  items: items.map((item) => ({
2715
2940
  ...item,
@@ -3512,7 +3737,6 @@ let LoaderResolver = class LoaderResolver {
3512
3737
  async totalQuantity({ id }) {
3513
3738
  const [aggregatedStocks] = await this.stockService.findAggregatedStocks({
3514
3739
  loaderId: id,
3515
- aggregated: true,
3516
3740
  });
3517
3741
  if (!aggregatedStocks.length)
3518
3742
  return 0;
@@ -3573,7 +3797,6 @@ let MaterialResolver = class MaterialResolver {
3573
3797
  // TODO: should be compatible with dataloader in the future
3574
3798
  const [items] = await this.stockService.findAggregatedStocks({
3575
3799
  materialId: id,
3576
- aggregated: true,
3577
3800
  });
3578
3801
  return items;
3579
3802
  }
@@ -5192,65 +5415,723 @@ BatchQuery = tslib.__decorate([
5192
5415
  tslib.__metadata("design:paramtypes", [wmsModuleCore.BatchService])
5193
5416
  ], BatchQuery);
5194
5417
 
5195
- let ChangeLogResolver = class ChangeLogResolver {
5196
- entities;
5197
- /**
5198
- * The configured entities, not the built-in classes: `__entity` decides which
5199
- * repository the DataLoader opens, so it has to follow whatever the consumer
5200
- * passed to `WMSBaseModuleOptions`. Loading a built-in class outright filters
5201
- * on its single-table-inheritance discriminator and resolves nothing for an
5202
- * override.
5203
- */
5204
- constructor(entities) {
5205
- this.entities = entities;
5206
- }
5207
- material({ materialId }, { loaders }) {
5208
- return loaders.batchSingle.load({
5209
- __entity: this.entities.material,
5210
- __from: { id: materialId },
5211
- });
5212
- }
5213
- location({ locationId }, { loaders }) {
5214
- return loaders.batchSingle.load({
5215
- __entity: this.entities.location,
5216
- __from: { id: locationId },
5217
- });
5418
+ /**
5419
+ * Reads the link in either direction: give it an order to list what that order
5420
+ * was opened for, or a `referenceType` / `referenceId` to list every order
5421
+ * opened for that document.
5422
+ *
5423
+ * `referenceType` / `referenceId` / `referenceLine` match exactly, never as a
5424
+ * substring — they are identifiers the host owns, and a partial match on
5425
+ * 「WO-1」 would quietly sweep in 「WO-10」.
5426
+ */
5427
+ let FindOrderReferenceArgs = class FindOrderReferenceArgs extends PaginationArgs {
5428
+ orderType;
5429
+ orderId;
5430
+ itemId;
5431
+ referenceType;
5432
+ referenceId;
5433
+ referenceLine;
5434
+ };
5435
+ tslib.__decorate([
5436
+ graphql.Field(() => wmsModuleCore.WmsOrderType, { nullable: true }),
5437
+ tslib.__metadata("design:type", String)
5438
+ ], FindOrderReferenceArgs.prototype, "orderType", void 0);
5439
+ tslib.__decorate([
5440
+ graphql.Field(() => graphql.ID, { nullable: true }),
5441
+ tslib.__metadata("design:type", String)
5442
+ ], FindOrderReferenceArgs.prototype, "orderId", void 0);
5443
+ tslib.__decorate([
5444
+ graphql.Field(() => graphql.ID, { nullable: true }),
5445
+ tslib.__metadata("design:type", String)
5446
+ ], FindOrderReferenceArgs.prototype, "itemId", void 0);
5447
+ tslib.__decorate([
5448
+ graphql.Field(() => String, { nullable: true }),
5449
+ tslib.__metadata("design:type", String)
5450
+ ], FindOrderReferenceArgs.prototype, "referenceType", void 0);
5451
+ tslib.__decorate([
5452
+ graphql.Field(() => String, { nullable: true }),
5453
+ tslib.__metadata("design:type", String)
5454
+ ], FindOrderReferenceArgs.prototype, "referenceId", void 0);
5455
+ tslib.__decorate([
5456
+ graphql.Field(() => String, { nullable: true }),
5457
+ tslib.__metadata("design:type", String)
5458
+ ], FindOrderReferenceArgs.prototype, "referenceLine", void 0);
5459
+ FindOrderReferenceArgs = tslib.__decorate([
5460
+ graphql.ArgsType()
5461
+ ], FindOrderReferenceArgs);
5462
+ let OrderReferenceInputType = class OrderReferenceInputType {
5463
+ referenceType;
5464
+ referenceId;
5465
+ referenceLine;
5466
+ /** The order item this link is about; omit for an order-level link. */
5467
+ itemId;
5468
+ metadata;
5469
+ };
5470
+ tslib.__decorate([
5471
+ graphql.Field(() => String),
5472
+ tslib.__metadata("design:type", String)
5473
+ ], OrderReferenceInputType.prototype, "referenceType", void 0);
5474
+ tslib.__decorate([
5475
+ graphql.Field(() => String),
5476
+ tslib.__metadata("design:type", String)
5477
+ ], OrderReferenceInputType.prototype, "referenceId", void 0);
5478
+ tslib.__decorate([
5479
+ graphql.Field(() => String, { nullable: true }),
5480
+ tslib.__metadata("design:type", Object)
5481
+ ], OrderReferenceInputType.prototype, "referenceLine", void 0);
5482
+ tslib.__decorate([
5483
+ graphql.Field(() => graphql.ID, { nullable: true }),
5484
+ tslib.__metadata("design:type", Object)
5485
+ ], OrderReferenceInputType.prototype, "itemId", void 0);
5486
+ tslib.__decorate([
5487
+ graphql.Field(() => GraphQLJSONObject, { nullable: true }),
5488
+ tslib.__metadata("design:type", Object)
5489
+ ], OrderReferenceInputType.prototype, "metadata", void 0);
5490
+ OrderReferenceInputType = tslib.__decorate([
5491
+ graphql.InputType()
5492
+ ], OrderReferenceInputType);
5493
+ let AttachOrderReferencesArgs = class AttachOrderReferencesArgs {
5494
+ orderType;
5495
+ orderId;
5496
+ references;
5497
+ };
5498
+ tslib.__decorate([
5499
+ graphql.Field(() => wmsModuleCore.WmsOrderType),
5500
+ tslib.__metadata("design:type", String)
5501
+ ], AttachOrderReferencesArgs.prototype, "orderType", void 0);
5502
+ tslib.__decorate([
5503
+ graphql.Field(() => graphql.ID),
5504
+ tslib.__metadata("design:type", String)
5505
+ ], AttachOrderReferencesArgs.prototype, "orderId", void 0);
5506
+ tslib.__decorate([
5507
+ graphql.Field(() => [OrderReferenceInputType]),
5508
+ tslib.__metadata("design:type", Array)
5509
+ ], AttachOrderReferencesArgs.prototype, "references", void 0);
5510
+ AttachOrderReferencesArgs = tslib.__decorate([
5511
+ graphql.ArgsType()
5512
+ ], AttachOrderReferencesArgs);
5513
+
5514
+ let OrderReferenceQuery = class OrderReferenceQuery {
5515
+ orderReferenceService;
5516
+ constructor(orderReferenceService) {
5517
+ this.orderReferenceService = orderReferenceService;
5218
5518
  }
5219
- async batch({ batchId }, { loaders }) {
5220
- const { groupId } = await loaders.batchSingle.load({
5221
- __entity: this.entities.batch,
5222
- __from: { id: batchId },
5223
- });
5224
- return loaders.batchSingle.load({
5225
- __entity: wmsModuleCore.BatchGroupEntityClass,
5226
- __from: { id: groupId },
5227
- });
5519
+ async orderReferences(args) {
5520
+ const [items, total] = await this.orderReferenceService.findMany(args);
5521
+ return { items, total };
5228
5522
  }
5229
5523
  };
5230
5524
  tslib.__decorate([
5231
- graphql.ResolveField(() => MaterialDto),
5232
- tslib.__param(0, graphql.Parent()),
5233
- tslib.__param(1, graphql.Context()),
5525
+ graphql.Query(() => OrderReferences),
5526
+ WmsOperation({ resource: 'order-reference', action: 'read' }),
5527
+ tslib.__param(0, graphql.Args()),
5234
5528
  tslib.__metadata("design:type", Function),
5235
- tslib.__metadata("design:paramtypes", [wmsModuleCore.StockEntityClass, Object]),
5529
+ tslib.__metadata("design:paramtypes", [FindOrderReferenceArgs]),
5236
5530
  tslib.__metadata("design:returntype", Promise)
5237
- ], ChangeLogResolver.prototype, "material", null);
5531
+ ], OrderReferenceQuery.prototype, "orderReferences", null);
5532
+ OrderReferenceQuery = tslib.__decorate([
5533
+ common.Injectable(),
5534
+ graphql.Resolver(),
5535
+ tslib.__metadata("design:paramtypes", [wmsModuleCore.OrderReferenceService])
5536
+ ], OrderReferenceQuery);
5537
+
5538
+ let OrderReferenceMutation = class OrderReferenceMutation {
5539
+ orderReferenceService;
5540
+ constructor(orderReferenceService) {
5541
+ this.orderReferenceService = orderReferenceService;
5542
+ }
5543
+ /**
5544
+ * Additive: attaching twice leaves both sets in place. Detach the ones that
5545
+ * no longer apply rather than expecting this to replace them.
5546
+ */
5547
+ attachOrderReferences(args) {
5548
+ return this.orderReferenceService.attach({
5549
+ orderType: args.orderType,
5550
+ orderId: args.orderId,
5551
+ references: args.references,
5552
+ });
5553
+ }
5554
+ async detachOrderReference(id) {
5555
+ await this.orderReferenceService.detach(id);
5556
+ return true;
5557
+ }
5558
+ };
5238
5559
  tslib.__decorate([
5239
- graphql.ResolveField(() => LocationDto),
5240
- tslib.__param(0, graphql.Parent()),
5241
- tslib.__param(1, graphql.Context()),
5560
+ graphql.Mutation(() => [OrderReferenceDto]),
5561
+ WmsOperation({ resource: 'order-reference', action: 'attach' }),
5562
+ WmsMutationEvent({ event: 'order-reference.attached' }),
5563
+ tslib.__param(0, graphql.Args()),
5242
5564
  tslib.__metadata("design:type", Function),
5243
- tslib.__metadata("design:paramtypes", [wmsModuleCore.StockEntityClass, Object]),
5565
+ tslib.__metadata("design:paramtypes", [AttachOrderReferencesArgs]),
5244
5566
  tslib.__metadata("design:returntype", Promise)
5245
- ], ChangeLogResolver.prototype, "location", null);
5567
+ ], OrderReferenceMutation.prototype, "attachOrderReferences", null);
5246
5568
  tslib.__decorate([
5247
- graphql.ResolveField(() => BatchDto),
5248
- tslib.__param(0, graphql.Parent()),
5249
- tslib.__param(1, graphql.Context()),
5569
+ graphql.Mutation(() => Boolean),
5570
+ WmsOperation({ resource: 'order-reference', action: 'detach' }),
5571
+ WmsMutationEvent({ event: 'order-reference.detached' }),
5572
+ tslib.__param(0, graphql.Args('id', { type: () => graphql.ID })),
5250
5573
  tslib.__metadata("design:type", Function),
5251
- tslib.__metadata("design:paramtypes", [wmsModuleCore.StockEntityClass, Object]),
5574
+ tslib.__metadata("design:paramtypes", [String]),
5252
5575
  tslib.__metadata("design:returntype", Promise)
5253
- ], ChangeLogResolver.prototype, "batch", null);
5576
+ ], OrderReferenceMutation.prototype, "detachOrderReference", null);
5577
+ OrderReferenceMutation = tslib.__decorate([
5578
+ common.Injectable(),
5579
+ graphql.Resolver(),
5580
+ tslib.__metadata("design:paramtypes", [wmsModuleCore.OrderReferenceService])
5581
+ ], OrderReferenceMutation);
5582
+
5583
+ let CreateConsumptionOrderItemInputType = class CreateConsumptionOrderItemInputType {
5584
+ materialId;
5585
+ batchId;
5586
+ /** Where the material is issued from. Defaults to the module's default location. */
5587
+ locationId;
5588
+ loaderId;
5589
+ unitId;
5590
+ quantity;
5591
+ /** Where it sits while the process holds it. Defaults to the source location. */
5592
+ targetLocationId;
5593
+ targetLoaderId;
5594
+ };
5595
+ tslib.__decorate([
5596
+ graphql.Field(() => graphql.ID),
5597
+ tslib.__metadata("design:type", String)
5598
+ ], CreateConsumptionOrderItemInputType.prototype, "materialId", void 0);
5599
+ tslib.__decorate([
5600
+ graphql.Field(() => graphql.ID),
5601
+ tslib.__metadata("design:type", String)
5602
+ ], CreateConsumptionOrderItemInputType.prototype, "batchId", void 0);
5603
+ tslib.__decorate([
5604
+ graphql.Field(() => graphql.ID, { nullable: true }),
5605
+ tslib.__metadata("design:type", String)
5606
+ ], CreateConsumptionOrderItemInputType.prototype, "locationId", void 0);
5607
+ tslib.__decorate([
5608
+ graphql.Field(() => graphql.ID, { nullable: true }),
5609
+ tslib.__metadata("design:type", String)
5610
+ ], CreateConsumptionOrderItemInputType.prototype, "loaderId", void 0);
5611
+ tslib.__decorate([
5612
+ graphql.Field(() => graphql.ID, { nullable: true }),
5613
+ tslib.__metadata("design:type", String)
5614
+ ], CreateConsumptionOrderItemInputType.prototype, "unitId", void 0);
5615
+ tslib.__decorate([
5616
+ graphql.Field(() => graphql.Float),
5617
+ tslib.__metadata("design:type", Number)
5618
+ ], CreateConsumptionOrderItemInputType.prototype, "quantity", void 0);
5619
+ tslib.__decorate([
5620
+ graphql.Field(() => graphql.ID, { nullable: true }),
5621
+ tslib.__metadata("design:type", String)
5622
+ ], CreateConsumptionOrderItemInputType.prototype, "targetLocationId", void 0);
5623
+ tslib.__decorate([
5624
+ graphql.Field(() => graphql.ID, { nullable: true }),
5625
+ tslib.__metadata("design:type", String)
5626
+ ], CreateConsumptionOrderItemInputType.prototype, "targetLoaderId", void 0);
5627
+ CreateConsumptionOrderItemInputType = tslib.__decorate([
5628
+ graphql.InputType()
5629
+ ], CreateConsumptionOrderItemInputType);
5630
+ let CreateConsumptionOrderArgs = class CreateConsumptionOrderArgs {
5631
+ description;
5632
+ createdBy;
5633
+ items;
5634
+ };
5635
+ tslib.__decorate([
5636
+ graphql.Field(() => String, { nullable: true }),
5637
+ tslib.__metadata("design:type", String)
5638
+ ], CreateConsumptionOrderArgs.prototype, "description", void 0);
5639
+ tslib.__decorate([
5640
+ graphql.Field(() => String, { nullable: true }),
5641
+ tslib.__metadata("design:type", String)
5642
+ ], CreateConsumptionOrderArgs.prototype, "createdBy", void 0);
5643
+ tslib.__decorate([
5644
+ graphql.Field(() => [CreateConsumptionOrderItemInputType]),
5645
+ tslib.__metadata("design:type", Array)
5646
+ ], CreateConsumptionOrderArgs.prototype, "items", void 0);
5647
+ CreateConsumptionOrderArgs = tslib.__decorate([
5648
+ graphql.ArgsType()
5649
+ ], CreateConsumptionOrderArgs);
5650
+ let UpdateConsumptionOrderArgs = class UpdateConsumptionOrderArgs {
5651
+ id;
5652
+ description;
5653
+ /** Replaces every line. Refused once the order has moved any stock. */
5654
+ items;
5655
+ };
5656
+ tslib.__decorate([
5657
+ graphql.Field(() => graphql.ID),
5658
+ tslib.__metadata("design:type", String)
5659
+ ], UpdateConsumptionOrderArgs.prototype, "id", void 0);
5660
+ tslib.__decorate([
5661
+ graphql.Field(() => String, { nullable: true }),
5662
+ tslib.__metadata("design:type", String)
5663
+ ], UpdateConsumptionOrderArgs.prototype, "description", void 0);
5664
+ tslib.__decorate([
5665
+ graphql.Field(() => [CreateConsumptionOrderItemInputType], { nullable: true }),
5666
+ tslib.__metadata("design:type", Array)
5667
+ ], UpdateConsumptionOrderArgs.prototype, "items", void 0);
5668
+ UpdateConsumptionOrderArgs = tslib.__decorate([
5669
+ graphql.ArgsType()
5670
+ ], UpdateConsumptionOrderArgs);
5671
+ let ConsumptionOrderLineInputType = class ConsumptionOrderLineInputType {
5672
+ itemId;
5673
+ /** Omit for whatever is outstanding on that line. */
5674
+ quantity;
5675
+ };
5676
+ tslib.__decorate([
5677
+ graphql.Field(() => graphql.ID),
5678
+ tslib.__metadata("design:type", String)
5679
+ ], ConsumptionOrderLineInputType.prototype, "itemId", void 0);
5680
+ tslib.__decorate([
5681
+ graphql.Field(() => graphql.Float, { nullable: true }),
5682
+ tslib.__metadata("design:type", Number)
5683
+ ], ConsumptionOrderLineInputType.prototype, "quantity", void 0);
5684
+ ConsumptionOrderLineInputType = tslib.__decorate([
5685
+ graphql.InputType()
5686
+ ], ConsumptionOrderLineInputType);
5687
+ let ConsumptionOrderActionArgs = class ConsumptionOrderActionArgs {
5688
+ orderId;
5689
+ /** Omit to act on every line of the order. */
5690
+ items;
5691
+ };
5692
+ tslib.__decorate([
5693
+ graphql.Field(() => graphql.ID),
5694
+ tslib.__metadata("design:type", String)
5695
+ ], ConsumptionOrderActionArgs.prototype, "orderId", void 0);
5696
+ tslib.__decorate([
5697
+ graphql.Field(() => [ConsumptionOrderLineInputType], { nullable: true }),
5698
+ tslib.__metadata("design:type", Array)
5699
+ ], ConsumptionOrderActionArgs.prototype, "items", void 0);
5700
+ ConsumptionOrderActionArgs = tslib.__decorate([
5701
+ graphql.ArgsType()
5702
+ ], ConsumptionOrderActionArgs);
5703
+ let FindConsumptionOrderArgs = class FindConsumptionOrderArgs extends PaginationArgs {
5704
+ ids;
5705
+ key;
5706
+ description;
5707
+ materialId;
5708
+ batchId;
5709
+ /** Matches either the source or the consuming location. */
5710
+ locationId;
5711
+ createdBy;
5712
+ createdAtFrom;
5713
+ createdAtTo;
5714
+ includeRemoved;
5715
+ };
5716
+ tslib.__decorate([
5717
+ graphql.Field(() => [graphql.ID], { nullable: true }),
5718
+ tslib.__metadata("design:type", Array)
5719
+ ], FindConsumptionOrderArgs.prototype, "ids", void 0);
5720
+ tslib.__decorate([
5721
+ graphql.Field(() => String, { nullable: true }),
5722
+ tslib.__metadata("design:type", String)
5723
+ ], FindConsumptionOrderArgs.prototype, "key", void 0);
5724
+ tslib.__decorate([
5725
+ graphql.Field(() => String, { nullable: true }),
5726
+ tslib.__metadata("design:type", String)
5727
+ ], FindConsumptionOrderArgs.prototype, "description", void 0);
5728
+ tslib.__decorate([
5729
+ graphql.Field(() => graphql.ID, { nullable: true }),
5730
+ tslib.__metadata("design:type", String)
5731
+ ], FindConsumptionOrderArgs.prototype, "materialId", void 0);
5732
+ tslib.__decorate([
5733
+ graphql.Field(() => graphql.ID, { nullable: true }),
5734
+ tslib.__metadata("design:type", String)
5735
+ ], FindConsumptionOrderArgs.prototype, "batchId", void 0);
5736
+ tslib.__decorate([
5737
+ graphql.Field(() => graphql.ID, { nullable: true }),
5738
+ tslib.__metadata("design:type", String)
5739
+ ], FindConsumptionOrderArgs.prototype, "locationId", void 0);
5740
+ tslib.__decorate([
5741
+ graphql.Field(() => String, { nullable: true }),
5742
+ tslib.__metadata("design:type", String)
5743
+ ], FindConsumptionOrderArgs.prototype, "createdBy", void 0);
5744
+ tslib.__decorate([
5745
+ graphql.Field(() => Date, { nullable: true }),
5746
+ tslib.__metadata("design:type", Date)
5747
+ ], FindConsumptionOrderArgs.prototype, "createdAtFrom", void 0);
5748
+ tslib.__decorate([
5749
+ graphql.Field(() => Date, { nullable: true }),
5750
+ tslib.__metadata("design:type", Date)
5751
+ ], FindConsumptionOrderArgs.prototype, "createdAtTo", void 0);
5752
+ tslib.__decorate([
5753
+ graphql.Field(() => Boolean, { nullable: true }),
5754
+ tslib.__metadata("design:type", Boolean)
5755
+ ], FindConsumptionOrderArgs.prototype, "includeRemoved", void 0);
5756
+ FindConsumptionOrderArgs = tslib.__decorate([
5757
+ graphql.ArgsType()
5758
+ ], FindConsumptionOrderArgs);
5759
+
5760
+ let ConsumptionOrderQuery = class ConsumptionOrderQuery {
5761
+ consumptionOrderService;
5762
+ constructor(consumptionOrderService) {
5763
+ this.consumptionOrderService = consumptionOrderService;
5764
+ }
5765
+ consumptionOrder(id) {
5766
+ return this.consumptionOrderService.findOne(id);
5767
+ }
5768
+ async consumptionOrders(args) {
5769
+ const [items, total] = await this.consumptionOrderService.findMany(args);
5770
+ return { items, total };
5771
+ }
5772
+ };
5773
+ tslib.__decorate([
5774
+ graphql.Query(() => ConsumptionOrderDto),
5775
+ WmsOperation({ resource: 'consumption-order', action: 'read' }),
5776
+ tslib.__param(0, graphql.Args('id', { type: () => graphql.ID })),
5777
+ tslib.__metadata("design:type", Function),
5778
+ tslib.__metadata("design:paramtypes", [String]),
5779
+ tslib.__metadata("design:returntype", Promise)
5780
+ ], ConsumptionOrderQuery.prototype, "consumptionOrder", null);
5781
+ tslib.__decorate([
5782
+ graphql.Query(() => ConsumptionOrders),
5783
+ WmsOperation({ resource: 'consumption-order', action: 'read' }),
5784
+ tslib.__param(0, graphql.Args()),
5785
+ tslib.__metadata("design:type", Function),
5786
+ tslib.__metadata("design:paramtypes", [FindConsumptionOrderArgs]),
5787
+ tslib.__metadata("design:returntype", Promise)
5788
+ ], ConsumptionOrderQuery.prototype, "consumptionOrders", null);
5789
+ ConsumptionOrderQuery = tslib.__decorate([
5790
+ common.Injectable(),
5791
+ graphql.Resolver(),
5792
+ tslib.__metadata("design:paramtypes", [wmsModuleCore.ConsumptionOrderService])
5793
+ ], ConsumptionOrderQuery);
5794
+
5795
+ /**
5796
+ * The three actions are separate mutations rather than one with a mode
5797
+ * argument: they carry different permissions (a host may well let the floor
5798
+ * issue and return but not settle) and different events, and both of those are
5799
+ * keyed per field.
5800
+ */
5801
+ let ConsumptionOrderMutation = class ConsumptionOrderMutation {
5802
+ consumptionOrderService;
5803
+ constructor(consumptionOrderService) {
5804
+ this.consumptionOrderService = consumptionOrderService;
5805
+ }
5806
+ createConsumptionOrder(args) {
5807
+ return this.consumptionOrderService.createConsumptionOrder(args);
5808
+ }
5809
+ updateConsumptionOrder(args) {
5810
+ return this.consumptionOrderService.updateConsumptionOrder(args);
5811
+ }
5812
+ issueConsumptionOrder(args) {
5813
+ return this.consumptionOrderService.issue(args);
5814
+ }
5815
+ returnConsumptionOrder(args) {
5816
+ return this.consumptionOrderService.return(args);
5817
+ }
5818
+ settleConsumptionOrder(args) {
5819
+ return this.consumptionOrderService.settle(args);
5820
+ }
5821
+ };
5822
+ tslib.__decorate([
5823
+ graphql.Mutation(() => ConsumptionOrderDto),
5824
+ WmsOperation({ resource: 'consumption-order', action: 'create' }),
5825
+ WmsMutationEvent({ event: 'consumption-order.created' }),
5826
+ tslib.__param(0, graphql.Args()),
5827
+ tslib.__metadata("design:type", Function),
5828
+ tslib.__metadata("design:paramtypes", [CreateConsumptionOrderArgs]),
5829
+ tslib.__metadata("design:returntype", Promise)
5830
+ ], ConsumptionOrderMutation.prototype, "createConsumptionOrder", null);
5831
+ tslib.__decorate([
5832
+ graphql.Mutation(() => ConsumptionOrderDto),
5833
+ WmsOperation({ resource: 'consumption-order', action: 'update' }),
5834
+ WmsMutationEvent({ event: 'consumption-order.updated' }),
5835
+ tslib.__param(0, graphql.Args()),
5836
+ tslib.__metadata("design:type", Function),
5837
+ tslib.__metadata("design:paramtypes", [UpdateConsumptionOrderArgs]),
5838
+ tslib.__metadata("design:returntype", Promise)
5839
+ ], ConsumptionOrderMutation.prototype, "updateConsumptionOrder", null);
5840
+ tslib.__decorate([
5841
+ graphql.Mutation(() => Boolean),
5842
+ WmsOperation({ resource: 'consumption-order', action: 'issue' }),
5843
+ WmsMutationEvent({ event: 'consumption-order.issued' }),
5844
+ tslib.__param(0, graphql.Args()),
5845
+ tslib.__metadata("design:type", Function),
5846
+ tslib.__metadata("design:paramtypes", [ConsumptionOrderActionArgs]),
5847
+ tslib.__metadata("design:returntype", Promise)
5848
+ ], ConsumptionOrderMutation.prototype, "issueConsumptionOrder", null);
5849
+ tslib.__decorate([
5850
+ graphql.Mutation(() => Boolean),
5851
+ WmsOperation({ resource: 'consumption-order', action: 'return' }),
5852
+ WmsMutationEvent({ event: 'consumption-order.returned' }),
5853
+ tslib.__param(0, graphql.Args()),
5854
+ tslib.__metadata("design:type", Function),
5855
+ tslib.__metadata("design:paramtypes", [ConsumptionOrderActionArgs]),
5856
+ tslib.__metadata("design:returntype", Promise)
5857
+ ], ConsumptionOrderMutation.prototype, "returnConsumptionOrder", null);
5858
+ tslib.__decorate([
5859
+ graphql.Mutation(() => Boolean),
5860
+ WmsOperation({ resource: 'consumption-order', action: 'settle' }),
5861
+ WmsMutationEvent({ event: 'consumption-order.settled' }),
5862
+ tslib.__param(0, graphql.Args()),
5863
+ tslib.__metadata("design:type", Function),
5864
+ tslib.__metadata("design:paramtypes", [ConsumptionOrderActionArgs]),
5865
+ tslib.__metadata("design:returntype", Promise)
5866
+ ], ConsumptionOrderMutation.prototype, "settleConsumptionOrder", null);
5867
+ ConsumptionOrderMutation = tslib.__decorate([
5868
+ common.Injectable(),
5869
+ graphql.Resolver(),
5870
+ tslib.__metadata("design:paramtypes", [wmsModuleCore.ConsumptionOrderService])
5871
+ ], ConsumptionOrderMutation);
5872
+
5873
+ let ConsumptionOrderResolver = class ConsumptionOrderResolver {
5874
+ items({ id }, { loaders }) {
5875
+ return loaders.batchMany.load({
5876
+ __entity: wmsModuleCore.ConsumptionOrderItemEntityClass,
5877
+ __from: { orderId: id },
5878
+ });
5879
+ }
5880
+ };
5881
+ tslib.__decorate([
5882
+ graphql.ResolveField(() => [ConsumptionOrderItemDto]),
5883
+ tslib.__param(0, graphql.Parent()),
5884
+ tslib.__param(1, graphql.Context()),
5885
+ tslib.__metadata("design:type", Function),
5886
+ tslib.__metadata("design:paramtypes", [ConsumptionOrderDto, Object]),
5887
+ tslib.__metadata("design:returntype", Promise)
5888
+ ], ConsumptionOrderResolver.prototype, "items", null);
5889
+ ConsumptionOrderResolver = tslib.__decorate([
5890
+ graphql.Resolver(() => ConsumptionOrderDto)
5891
+ ], ConsumptionOrderResolver);
5892
+ let ConsumptionOrderItemResolver = class ConsumptionOrderItemResolver {
5893
+ entities;
5894
+ /**
5895
+ * The configured entities, not the built-in classes: `__entity` decides which
5896
+ * repository the DataLoader opens, so it has to follow whatever the consumer
5897
+ * passed to `WMSBaseModuleOptions`. Loading a built-in class outright filters
5898
+ * on its single-table-inheritance discriminator and resolves nothing for an
5899
+ * override.
5900
+ */
5901
+ constructor(entities) {
5902
+ this.entities = entities;
5903
+ }
5904
+ /**
5905
+ * How much this line has moved, by kind.
5906
+ *
5907
+ * Read back from the changes rather than denormalised onto the item: the
5908
+ * changes are what the stock ledger and the `stock.*` events agree with, and a
5909
+ * counter maintained alongside them is a second answer waiting to disagree.
5910
+ */
5911
+ async movedQuantity(itemId, kind, loaders) {
5912
+ const changes = await loaders.batchMany.load({
5913
+ __entity: wmsModuleCore.ConsumptionOrderChangeEntityClass,
5914
+ __from: { itemId },
5915
+ });
5916
+ return changes
5917
+ .filter((change) => change.kind === kind)
5918
+ .reduce((total, { quantityChanged }) => total + Math.abs(Number(quantityChanged)), 0);
5919
+ }
5920
+ material({ materialId }, { loaders }) {
5921
+ return loaders.batchSingle.load({
5922
+ __entity: this.entities.material,
5923
+ __from: { id: materialId },
5924
+ });
5925
+ }
5926
+ async batch({ batchId }, { loaders }) {
5927
+ if (!batchId)
5928
+ return null;
5929
+ const { groupId } = await loaders.batchSingle.load({
5930
+ __entity: this.entities.batch,
5931
+ __from: { id: batchId },
5932
+ });
5933
+ return loaders.batchSingle.load({
5934
+ __entity: wmsModuleCore.BatchGroupEntityClass,
5935
+ __from: { id: groupId },
5936
+ });
5937
+ }
5938
+ async location({ locationId }, { loaders }) {
5939
+ if (!locationId)
5940
+ return null;
5941
+ return loaders.batchSingle.load({
5942
+ __entity: this.entities.location,
5943
+ __from: { id: locationId },
5944
+ });
5945
+ }
5946
+ async targetLocation({ targetLocationId }, { loaders }) {
5947
+ if (!targetLocationId)
5948
+ return null;
5949
+ return loaders.batchSingle.load({
5950
+ __entity: this.entities.location,
5951
+ __from: { id: targetLocationId },
5952
+ });
5953
+ }
5954
+ async loader({ loaderId }, { loaders }) {
5955
+ if (!loaderId)
5956
+ return null;
5957
+ return loaders.batchSingle.load({
5958
+ __entity: wmsModuleCore.LoadersEntityClass,
5959
+ __from: { id: loaderId },
5960
+ });
5961
+ }
5962
+ async targetLoader({ targetLoaderId }, { loaders }) {
5963
+ if (!targetLoaderId)
5964
+ return null;
5965
+ return loaders.batchSingle.load({
5966
+ __entity: wmsModuleCore.LoadersEntityClass,
5967
+ __from: { id: targetLoaderId },
5968
+ });
5969
+ }
5970
+ issuedQuantity({ id }, { loaders }) {
5971
+ return this.movedQuantity(id, wmsModuleCore.ConsumptionChangeKind.ISSUE, loaders);
5972
+ }
5973
+ returnedQuantity({ id }, { loaders }) {
5974
+ return this.movedQuantity(id, wmsModuleCore.ConsumptionChangeKind.RETURN, loaders);
5975
+ }
5976
+ settledQuantity({ id }, { loaders }) {
5977
+ return this.movedQuantity(id, wmsModuleCore.ConsumptionChangeKind.SETTLE, loaders);
5978
+ }
5979
+ /** Issued minus returned minus settled: what the process still holds. */
5980
+ async outstandingQuantity({ id }, { loaders }) {
5981
+ const changes = await loaders.batchMany.load({
5982
+ __entity: wmsModuleCore.ConsumptionOrderChangeEntityClass,
5983
+ __from: { itemId: id },
5984
+ });
5985
+ // The sign already carries the direction here — an issue is positive, a
5986
+ // return and a settlement negative — so the outstanding amount is just the
5987
+ // sum, no filtering by kind needed.
5988
+ return changes.reduce((total, { quantityChanged }) => total + Number(quantityChanged), 0);
5989
+ }
5990
+ };
5991
+ tslib.__decorate([
5992
+ graphql.ResolveField(() => MaterialDto),
5993
+ tslib.__param(0, graphql.Parent()),
5994
+ tslib.__param(1, graphql.Context()),
5995
+ tslib.__metadata("design:type", Function),
5996
+ tslib.__metadata("design:paramtypes", [wmsModuleCore.ConsumptionOrderItemEntityClass, Object]),
5997
+ tslib.__metadata("design:returntype", Promise)
5998
+ ], ConsumptionOrderItemResolver.prototype, "material", null);
5999
+ tslib.__decorate([
6000
+ graphql.ResolveField(() => BatchDto, { nullable: true }),
6001
+ tslib.__param(0, graphql.Parent()),
6002
+ tslib.__param(1, graphql.Context()),
6003
+ tslib.__metadata("design:type", Function),
6004
+ tslib.__metadata("design:paramtypes", [wmsModuleCore.ConsumptionOrderItemEntityClass, Object]),
6005
+ tslib.__metadata("design:returntype", Promise)
6006
+ ], ConsumptionOrderItemResolver.prototype, "batch", null);
6007
+ tslib.__decorate([
6008
+ graphql.ResolveField(() => LocationDto, { nullable: true }),
6009
+ tslib.__param(0, graphql.Parent()),
6010
+ tslib.__param(1, graphql.Context()),
6011
+ tslib.__metadata("design:type", Function),
6012
+ tslib.__metadata("design:paramtypes", [wmsModuleCore.ConsumptionOrderItemEntityClass, Object]),
6013
+ tslib.__metadata("design:returntype", Promise)
6014
+ ], ConsumptionOrderItemResolver.prototype, "location", null);
6015
+ tslib.__decorate([
6016
+ graphql.ResolveField(() => LocationDto, { nullable: true }),
6017
+ tslib.__param(0, graphql.Parent()),
6018
+ tslib.__param(1, graphql.Context()),
6019
+ tslib.__metadata("design:type", Function),
6020
+ tslib.__metadata("design:paramtypes", [wmsModuleCore.ConsumptionOrderItemEntityClass, Object]),
6021
+ tslib.__metadata("design:returntype", Promise)
6022
+ ], ConsumptionOrderItemResolver.prototype, "targetLocation", null);
6023
+ tslib.__decorate([
6024
+ graphql.ResolveField(() => LoaderDto, { nullable: true }),
6025
+ tslib.__param(0, graphql.Parent()),
6026
+ tslib.__param(1, graphql.Context()),
6027
+ tslib.__metadata("design:type", Function),
6028
+ tslib.__metadata("design:paramtypes", [wmsModuleCore.ConsumptionOrderItemEntityClass, Object]),
6029
+ tslib.__metadata("design:returntype", Promise)
6030
+ ], ConsumptionOrderItemResolver.prototype, "loader", null);
6031
+ tslib.__decorate([
6032
+ graphql.ResolveField(() => LoaderDto, { nullable: true }),
6033
+ tslib.__param(0, graphql.Parent()),
6034
+ tslib.__param(1, graphql.Context()),
6035
+ tslib.__metadata("design:type", Function),
6036
+ tslib.__metadata("design:paramtypes", [wmsModuleCore.ConsumptionOrderItemEntityClass, Object]),
6037
+ tslib.__metadata("design:returntype", Promise)
6038
+ ], ConsumptionOrderItemResolver.prototype, "targetLoader", null);
6039
+ tslib.__decorate([
6040
+ graphql.ResolveField(() => graphql.Float),
6041
+ tslib.__param(0, graphql.Parent()),
6042
+ tslib.__param(1, graphql.Context()),
6043
+ tslib.__metadata("design:type", Function),
6044
+ tslib.__metadata("design:paramtypes", [wmsModuleCore.ConsumptionOrderItemEntityClass, Object]),
6045
+ tslib.__metadata("design:returntype", Promise)
6046
+ ], ConsumptionOrderItemResolver.prototype, "issuedQuantity", null);
6047
+ tslib.__decorate([
6048
+ graphql.ResolveField(() => graphql.Float),
6049
+ tslib.__param(0, graphql.Parent()),
6050
+ tslib.__param(1, graphql.Context()),
6051
+ tslib.__metadata("design:type", Function),
6052
+ tslib.__metadata("design:paramtypes", [wmsModuleCore.ConsumptionOrderItemEntityClass, Object]),
6053
+ tslib.__metadata("design:returntype", Promise)
6054
+ ], ConsumptionOrderItemResolver.prototype, "returnedQuantity", null);
6055
+ tslib.__decorate([
6056
+ graphql.ResolveField(() => graphql.Float),
6057
+ tslib.__param(0, graphql.Parent()),
6058
+ tslib.__param(1, graphql.Context()),
6059
+ tslib.__metadata("design:type", Function),
6060
+ tslib.__metadata("design:paramtypes", [wmsModuleCore.ConsumptionOrderItemEntityClass, Object]),
6061
+ tslib.__metadata("design:returntype", Promise)
6062
+ ], ConsumptionOrderItemResolver.prototype, "settledQuantity", null);
6063
+ tslib.__decorate([
6064
+ graphql.ResolveField(() => graphql.Float),
6065
+ tslib.__param(0, graphql.Parent()),
6066
+ tslib.__param(1, graphql.Context()),
6067
+ tslib.__metadata("design:type", Function),
6068
+ tslib.__metadata("design:paramtypes", [wmsModuleCore.ConsumptionOrderItemEntityClass, Object]),
6069
+ tslib.__metadata("design:returntype", Promise)
6070
+ ], ConsumptionOrderItemResolver.prototype, "outstandingQuantity", null);
6071
+ ConsumptionOrderItemResolver = tslib.__decorate([
6072
+ graphql.Resolver(() => ConsumptionOrderItemDto),
6073
+ tslib.__metadata("design:paramtypes", [wmsModuleCore.WmsEntities])
6074
+ ], ConsumptionOrderItemResolver);
6075
+
6076
+ let ChangeLogResolver = class ChangeLogResolver {
6077
+ entities;
6078
+ /**
6079
+ * The configured entities, not the built-in classes: `__entity` decides which
6080
+ * repository the DataLoader opens, so it has to follow whatever the consumer
6081
+ * passed to `WMSBaseModuleOptions`. Loading a built-in class outright filters
6082
+ * on its single-table-inheritance discriminator and resolves nothing for an
6083
+ * override.
6084
+ */
6085
+ constructor(entities) {
6086
+ this.entities = entities;
6087
+ }
6088
+ material({ materialId }, { loaders }) {
6089
+ return loaders.batchSingle.load({
6090
+ __entity: this.entities.material,
6091
+ __from: { id: materialId },
6092
+ });
6093
+ }
6094
+ location({ locationId }, { loaders }) {
6095
+ return loaders.batchSingle.load({
6096
+ __entity: this.entities.location,
6097
+ __from: { id: locationId },
6098
+ });
6099
+ }
6100
+ async batch({ batchId }, { loaders }) {
6101
+ const { groupId } = await loaders.batchSingle.load({
6102
+ __entity: this.entities.batch,
6103
+ __from: { id: batchId },
6104
+ });
6105
+ return loaders.batchSingle.load({
6106
+ __entity: wmsModuleCore.BatchGroupEntityClass,
6107
+ __from: { id: groupId },
6108
+ });
6109
+ }
6110
+ };
6111
+ tslib.__decorate([
6112
+ graphql.ResolveField(() => MaterialDto),
6113
+ tslib.__param(0, graphql.Parent()),
6114
+ tslib.__param(1, graphql.Context()),
6115
+ tslib.__metadata("design:type", Function),
6116
+ tslib.__metadata("design:paramtypes", [wmsModuleCore.StockEntityClass, Object]),
6117
+ tslib.__metadata("design:returntype", Promise)
6118
+ ], ChangeLogResolver.prototype, "material", null);
6119
+ tslib.__decorate([
6120
+ graphql.ResolveField(() => LocationDto),
6121
+ tslib.__param(0, graphql.Parent()),
6122
+ tslib.__param(1, graphql.Context()),
6123
+ tslib.__metadata("design:type", Function),
6124
+ tslib.__metadata("design:paramtypes", [wmsModuleCore.StockEntityClass, Object]),
6125
+ tslib.__metadata("design:returntype", Promise)
6126
+ ], ChangeLogResolver.prototype, "location", null);
6127
+ tslib.__decorate([
6128
+ graphql.ResolveField(() => BatchDto),
6129
+ tslib.__param(0, graphql.Parent()),
6130
+ tslib.__param(1, graphql.Context()),
6131
+ tslib.__metadata("design:type", Function),
6132
+ tslib.__metadata("design:paramtypes", [wmsModuleCore.StockEntityClass, Object]),
6133
+ tslib.__metadata("design:returntype", Promise)
6134
+ ], ChangeLogResolver.prototype, "batch", null);
5254
6135
  ChangeLogResolver = tslib.__decorate([
5255
6136
  graphql.Resolver(() => ChangeLogDto),
5256
6137
  tslib.__metadata("design:paramtypes", [wmsModuleCore.WmsEntities])
@@ -6003,6 +6884,12 @@ SaleOrderQuery = tslib.__decorate([
6003
6884
  let SplitBatchItemInput = class SplitBatchItemInput {
6004
6885
  batchKey;
6005
6886
  quantity;
6887
+ /**
6888
+ * Host-defined attributes for this child batch. Applied only when the split
6889
+ * creates the batch; reusing an existing `batchKey` keeps what that batch
6890
+ * already carries.
6891
+ */
6892
+ attributes;
6006
6893
  };
6007
6894
  tslib.__decorate([
6008
6895
  graphql.Field(() => graphql.ID),
@@ -6012,6 +6899,10 @@ tslib.__decorate([
6012
6899
  graphql.Field(() => Number),
6013
6900
  tslib.__metadata("design:type", Number)
6014
6901
  ], SplitBatchItemInput.prototype, "quantity", void 0);
6902
+ tslib.__decorate([
6903
+ graphql.Field(() => GraphQLJSONObject, { nullable: true }),
6904
+ tslib.__metadata("design:type", Object)
6905
+ ], SplitBatchItemInput.prototype, "attributes", void 0);
6015
6906
  SplitBatchItemInput = tslib.__decorate([
6016
6907
  graphql.InputType()
6017
6908
  ], SplitBatchItemInput);
@@ -7652,6 +8543,12 @@ const exportDependencies = [
7652
8543
  InventoryCountOrderMutation,
7653
8544
  InventoryCountOrderResolver,
7654
8545
  InventoryCountOrderItemResolver,
8546
+ OrderReferenceQuery,
8547
+ OrderReferenceMutation,
8548
+ ConsumptionOrderQuery,
8549
+ ConsumptionOrderMutation,
8550
+ ConsumptionOrderResolver,
8551
+ ConsumptionOrderItemResolver,
7655
8552
  ];
7656
8553
  exports.WmsModuleGraphqlModule = WmsModuleGraphqlModule_1 = class WmsModuleGraphqlModule {
7657
8554
  static forRootAsync(options) {
@@ -7665,25 +8562,31 @@ exports.WmsModuleGraphqlModule = WmsModuleGraphqlModule_1 = class WmsModuleGraph
7665
8562
  disabledOperations,
7666
8563
  disabledFields,
7667
8564
  });
7668
- // coreOptions still carries `enrichStockEvents`, forwarded to the core module.
7669
- const coreModule = wmsModuleCore.WmsModuleCoreModule.forRootAsync(coreOptions);
7670
- const authOptions = { authChecker };
7671
- // The typed hook maps are a compile-time refinement of the core maps; at
7672
- // runtime the dispatched payload IS the concrete result type, so handing the
7673
- // refined maps to the (looser) core option contract is sound.
7674
- const eventOptions = {
8565
+ /*
8566
+ * The event wiring goes down to the core module rather than being bound
8567
+ * here. `WmsOperationRunner` lives in core so a host calling a service
8568
+ * directly gets the same guarantee, and binding the same tokens in both
8569
+ * modules would leave two live bindings whose winner depends on which
8570
+ * injector the consumer reached first.
8571
+ *
8572
+ * `coreOptions` still carries `enrichStockEvents`, also forwarded.
8573
+ */
8574
+ const coreModule = wmsModuleCore.WmsModuleCoreModule.forRootAsync({
8575
+ ...coreOptions,
8576
+ // The typed hook maps are a compile-time refinement of the core maps; at
8577
+ // runtime the dispatched payload IS the concrete result type, so handing
8578
+ // the refined maps to the (looser) core option contract is sound.
7675
8579
  beforeHooks: beforeHooks,
7676
8580
  afterListeners: afterListeners,
7677
- };
8581
+ actorExtractor,
8582
+ eventEmitterBridge,
8583
+ });
8584
+ const authOptions = { authChecker };
7678
8585
  const providers = [
7679
8586
  ...exportDependencies,
7680
8587
  exports.WmsAuthGuard,
7681
8588
  { provide: WMS_AUTH_OPTIONS, useValue: authOptions },
7682
- { provide: wmsModuleCore.WMS_EVENT_OPTIONS, useValue: eventOptions },
7683
- { provide: wmsModuleCore.WMS_ACTOR_EXTRACTOR, useValue: actorExtractor ?? null },
7684
- wmsModuleCore.WmsEventDispatcher,
7685
8589
  exports.WmsMutationInterceptor,
7686
- ...(eventEmitterBridge ? [eventEmitterBridge] : []),
7687
8590
  ];
7688
8591
  return {
7689
8592
  module: WmsModuleGraphqlModule_1,