@rytass/wms-module-graphql 0.11.0 → 0.12.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 (169) hide show
  1. package/README.md +19 -0
  2. package/docs/README.md +5 -2
  3. package/docs/api-reference.md +10 -8
  4. package/docs/integration-guide.md +34 -17
  5. package/docs/inventory-count.md +372 -0
  6. package/index.cjs.js +10 -0
  7. package/lib/inputs/inventory-count-order.args.d.ts +6 -0
  8. package/package.json +12 -11
  9. package/adapters/event-emitter.js +0 -41
  10. package/adapters/member-base.js +0 -63
  11. package/index.js +0 -12
  12. package/lib/auth/host-skip.constant.js +0 -29
  13. package/lib/auth/wms-auth.guard.js +0 -41
  14. package/lib/auth/wms-auth.types.js +0 -6
  15. package/lib/auth/wms-operation.decorator.js +0 -29
  16. package/lib/dto/allocate-inventory-order-item.dto.js +0 -36
  17. package/lib/dto/allocate-inventory-order.dto.js +0 -31
  18. package/lib/dto/batch.dto.js +0 -26
  19. package/lib/dto/consumption-order-item.dto.js +0 -43
  20. package/lib/dto/consumption-order.dto.js +0 -52
  21. package/lib/dto/hold-inventory-order-item.dto.js +0 -37
  22. package/lib/dto/hold-inventory-order.dto.js +0 -47
  23. package/lib/dto/inventory-count-order.dto.js +0 -207
  24. package/lib/dto/loader-type.dto.js +0 -46
  25. package/lib/dto/loader-unit.dto.js +0 -21
  26. package/lib/dto/loader.dto.js +0 -71
  27. package/lib/dto/location.dto.js +0 -36
  28. package/lib/dto/material-unit.dto.js +0 -46
  29. package/lib/dto/material.dto.js +0 -36
  30. package/lib/dto/merge-batch-order.dto.js +0 -50
  31. package/lib/dto/order-reference.dto.js +0 -73
  32. package/lib/dto/pagination.dto.js +0 -51
  33. package/lib/dto/quality-inspection-order-item.dto.js +0 -50
  34. package/lib/dto/quality-inspection-order.dto.js +0 -42
  35. package/lib/dto/receive-inventory-order-item.dto.js +0 -60
  36. package/lib/dto/receive-inventory-order.dto.js +0 -58
  37. package/lib/dto/reclassify-inventory-order.dto.js +0 -55
  38. package/lib/dto/sale-order.dto.js +0 -20
  39. package/lib/dto/scrape-order-item.dto.js +0 -56
  40. package/lib/dto/scrape-order.dto.js +0 -37
  41. package/lib/dto/ship-inventory-order-item.dto.js +0 -56
  42. package/lib/dto/ship-inventory-order-reference.dto.js +0 -48
  43. package/lib/dto/ship-inventory-order.dto.js +0 -58
  44. package/lib/dto/split-batch-order.dto.js +0 -50
  45. package/lib/dto/stock.dto.js +0 -166
  46. package/lib/dto/transfer-customer-order-item.dto.js +0 -61
  47. package/lib/dto/transfer-customer-order.dto.js +0 -37
  48. package/lib/dto/transfer-order-item.dto.js +0 -41
  49. package/lib/dto/transfer-order.dto.js +0 -57
  50. package/lib/dto/transfer-vendor-order-item.dto.js +0 -61
  51. package/lib/dto/transfer-vendor-order.dto.js +0 -37
  52. package/lib/dto/unit.dto.js +0 -20
  53. package/lib/dto/warehouse-map.dto.js +0 -165
  54. package/lib/events/wms-mutation-event.constants.js +0 -4
  55. package/lib/events/wms-mutation-event.decorator.js +0 -20
  56. package/lib/events/wms-mutation.interceptor.js +0 -64
  57. package/lib/graphql.module.js +0 -183
  58. package/lib/helpers/create-wms-loaders.js +0 -11
  59. package/lib/helpers/helper.module.js +0 -15
  60. package/lib/helpers/loader.service.js +0 -230
  61. package/lib/helpers/query-path.js +0 -19
  62. package/lib/inputs/cancel-ship-order.args.js +0 -20
  63. package/lib/inputs/cancel-transfer-order.args.js +0 -23
  64. package/lib/inputs/consumption-order.args.js +0 -182
  65. package/lib/inputs/create-allocate-inventory-order-item.args.js +0 -50
  66. package/lib/inputs/create-allocate-inventory-order.args.js +0 -36
  67. package/lib/inputs/create-hold-inventory-order-item.args.js +0 -40
  68. package/lib/inputs/create-hold-inventory-order.args.js +0 -41
  69. package/lib/inputs/create-loader-type.args.js +0 -35
  70. package/lib/inputs/create-loader.args.js +0 -130
  71. package/lib/inputs/create-location.args.js +0 -50
  72. package/lib/inputs/create-material-unit.args.js +0 -25
  73. package/lib/inputs/create-material.args.js +0 -51
  74. package/lib/inputs/create-quality-inspection-order.args.js +0 -50
  75. package/lib/inputs/create-receive-inventory-order-item.args.js +0 -70
  76. package/lib/inputs/create-receive-inventory-order.args.js +0 -51
  77. package/lib/inputs/create-ship-inventory-order-item.args.js +0 -45
  78. package/lib/inputs/create-ship-inventory-order-reference.args.js +0 -65
  79. package/lib/inputs/create-ship-inventory-order.args.js +0 -57
  80. package/lib/inputs/create-transfer-customer-order-item.args.js +0 -40
  81. package/lib/inputs/create-transfer-customer-order.args.js +0 -51
  82. package/lib/inputs/create-transfer-order-item.args.js +0 -40
  83. package/lib/inputs/create-transfer-order.args.js +0 -61
  84. package/lib/inputs/create-transfer-vendor-order-item.args.js +0 -40
  85. package/lib/inputs/create-transfer-vendor-order.args.js +0 -51
  86. package/lib/inputs/date-range.args.js +0 -20
  87. package/lib/inputs/deallocate-order.args.js +0 -25
  88. package/lib/inputs/find-allocate-inventory-order.args.js +0 -42
  89. package/lib/inputs/find-batch.args.js +0 -21
  90. package/lib/inputs/find-hold-inventory-order.args.js +0 -42
  91. package/lib/inputs/find-loader-type.args.js +0 -32
  92. package/lib/inputs/find-loader.args.js +0 -72
  93. package/lib/inputs/find-location.args.js +0 -26
  94. package/lib/inputs/find-material.args.js +0 -21
  95. package/lib/inputs/find-receive-inventory-order.args.js +0 -71
  96. package/lib/inputs/find-sale-order.args.js +0 -16
  97. package/lib/inputs/find-ship-inventory-order.args.js +0 -71
  98. package/lib/inputs/find-stock.args.js +0 -102
  99. package/lib/inputs/find-transfer-order.args.js +0 -82
  100. package/lib/inputs/inventory-count-order.args.js +0 -257
  101. package/lib/inputs/merge-batch.args.js +0 -40
  102. package/lib/inputs/order-reference.args.js +0 -103
  103. package/lib/inputs/pagination.args.js +0 -20
  104. package/lib/inputs/receive-order.args.js +0 -40
  105. package/lib/inputs/reclassify-inventory-order.args.js +0 -40
  106. package/lib/inputs/release-order.args.js +0 -25
  107. package/lib/inputs/return-transfer-customer-order.args.js +0 -35
  108. package/lib/inputs/return-transfer-vendor-order.args.js +0 -35
  109. package/lib/inputs/scrape-order.args.js +0 -35
  110. package/lib/inputs/ship-order.args.js +0 -20
  111. package/lib/inputs/split-batch.args.js +0 -51
  112. package/lib/inputs/transfer-order.args.js +0 -20
  113. package/lib/inputs/update-warehouse-map.args.js +0 -121
  114. package/lib/mutations/allocate-inventory-order.mutation.js +0 -91
  115. package/lib/mutations/consumption-order.mutation.js +0 -90
  116. package/lib/mutations/hold-inventory-order.mutation.js +0 -91
  117. package/lib/mutations/inventory-count-order.mutation.js +0 -138
  118. package/lib/mutations/loader.mutation.js +0 -123
  119. package/lib/mutations/location.mutation.js +0 -47
  120. package/lib/mutations/material.mutation.js +0 -74
  121. package/lib/mutations/merge-batch.mutation.js +0 -50
  122. package/lib/mutations/order-reference.mutation.js +0 -57
  123. package/lib/mutations/quality-inspection-order.mutation.js +0 -50
  124. package/lib/mutations/receive-inventory-order.mutation.js +0 -106
  125. package/lib/mutations/reclassify-inventory-order.mutation.js +0 -51
  126. package/lib/mutations/scrape-order.mutation.js +0 -44
  127. package/lib/mutations/ship-inventory-order.mutation.js +0 -123
  128. package/lib/mutations/split-batch.mutation.js +0 -44
  129. package/lib/mutations/transfer-customer-order.mutation.js +0 -91
  130. package/lib/mutations/transfer-order.mutation.js +0 -96
  131. package/lib/mutations/transfer-vendor-order.mutation.js +0 -91
  132. package/lib/mutations/warehouse-map.mutation.js +0 -60
  133. package/lib/queries/allocate-inventory-order.query.js +0 -33
  134. package/lib/queries/batch.query.js +0 -36
  135. package/lib/queries/consumption-order.query.js +0 -45
  136. package/lib/queries/hold-inventory-order.query.js +0 -33
  137. package/lib/queries/inventory-count-order.query.js +0 -63
  138. package/lib/queries/loader.query.js +0 -167
  139. package/lib/queries/location.query.js +0 -51
  140. package/lib/queries/material.query.js +0 -79
  141. package/lib/queries/order-reference.query.js +0 -34
  142. package/lib/queries/recieve-inventory-order.query.js +0 -77
  143. package/lib/queries/sale-order.query.js +0 -57
  144. package/lib/queries/ship-inventory-order.query.js +0 -77
  145. package/lib/queries/stock.query.js +0 -116
  146. package/lib/queries/transfer-order.query.js +0 -46
  147. package/lib/queries/unit.query.js +0 -30
  148. package/lib/queries/warehouse-map.query.js +0 -32
  149. package/lib/registry/operation-registry.js +0 -136
  150. package/lib/resolvers/aggregated-stock.resolver.js +0 -119
  151. package/lib/resolvers/allocate-inventory-order.resolver.js +0 -27
  152. package/lib/resolvers/change-log.resolver.js +0 -99
  153. package/lib/resolvers/consumption-order.resolver.js +0 -238
  154. package/lib/resolvers/hold-inventory-order.resolver.js +0 -27
  155. package/lib/resolvers/inventory-count-order.resolver.js +0 -148
  156. package/lib/resolvers/loader-type.resolver.js +0 -54
  157. package/lib/resolvers/loader.resolver.js +0 -99
  158. package/lib/resolvers/location.resolver.js +0 -80
  159. package/lib/resolvers/material.resolver.js +0 -87
  160. package/lib/resolvers/merge-batch.resolver.js +0 -26
  161. package/lib/resolvers/receive-inventory-order.resolver.js +0 -156
  162. package/lib/resolvers/ship-inventory-order.resolver.js +0 -301
  163. package/lib/resolvers/split-batch.resolver.js +0 -26
  164. package/lib/resolvers/stock.resolver.js +0 -99
  165. package/lib/resolvers/transfer-customer-order.resolver.js +0 -27
  166. package/lib/resolvers/transfer-order.resolver.js +0 -246
  167. package/lib/resolvers/transfer-vendor-order.resolver.js +0 -27
  168. package/lib/resolvers/warehouse-map.resolver.js +0 -41
  169. package/lib/scalars/json-object.scalar.js +0 -62
@@ -1,64 +0,0 @@
1
- import { __decorate, __param, __metadata } from 'tslib';
2
- import { Injectable, Optional, Inject } from '@nestjs/common';
3
- import { Reflector } from '@nestjs/core';
4
- import { GqlExecutionContext } from '@nestjs/graphql';
5
- import { WMS_ACTOR_EXTRACTOR, WmsOperationRunner } from '@rytass/wms-module-core';
6
- import { firstValueFrom, of } from 'rxjs';
7
- import { WMS_MUTATION_EVENT_METADATA } from './wms-mutation-event.constants.js';
8
-
9
- /**
10
- * Hands each `@WmsMutationEvent` mutation to {@link WmsOperationRunner}, which
11
- * owns the before-hook / dispatch scope / post-commit flush sequence.
12
- *
13
- * All this adds on top is what only a GraphQL request can supply: the raw
14
- * arguments and the actor. Keeping the sequence itself in core is what stops
15
- * the GraphQL path and a host's direct service call from drifting apart.
16
- *
17
- * When no hook, listener or bridge is configured the runner passes through
18
- * untouched.
19
- */
20
- let WmsMutationInterceptor = class WmsMutationInterceptor {
21
- reflector;
22
- runner;
23
- actorExtractor;
24
- constructor(reflector, runner, actorExtractor = null) {
25
- this.reflector = reflector;
26
- this.runner = runner;
27
- this.actorExtractor = actorExtractor;
28
- }
29
- resolveActor(context) {
30
- if (!this.actorExtractor) {
31
- return null;
32
- }
33
- try {
34
- return this.actorExtractor(context);
35
- }
36
- catch {
37
- // Fail-open on actor resolution: never break a mutation over audit metadata.
38
- return null;
39
- }
40
- }
41
- async intercept(context, next) {
42
- const config = this.reflector.get(WMS_MUTATION_EVENT_METADATA, context.getHandler());
43
- if (!config) {
44
- return next.handle();
45
- }
46
- const result = await this.runner.run({
47
- event: config.event,
48
- args: GqlExecutionContext.create(context).getArgs() ?? {},
49
- actor: this.resolveActor(context),
50
- resolveId: config.resolveId,
51
- executionContext: context,
52
- }, () => firstValueFrom(next.handle()));
53
- return of(result);
54
- }
55
- };
56
- WmsMutationInterceptor = __decorate([
57
- Injectable(),
58
- __param(2, Optional()),
59
- __param(2, Inject(WMS_ACTOR_EXTRACTOR)),
60
- __metadata("design:paramtypes", [Reflector,
61
- WmsOperationRunner, Object])
62
- ], WmsMutationInterceptor);
63
-
64
- export { WmsMutationInterceptor };
@@ -1,183 +0,0 @@
1
- import { __decorate } from 'tslib';
2
- import { Module } from '@nestjs/common';
3
- import { WmsModuleCoreModule } from '@rytass/wms-module-core';
4
- import './helpers/loader.service.js';
5
- import { HelperModule } from './helpers/helper.module.js';
6
- import './helpers/query-path.js';
7
- import { WmsAuthGuard } from './auth/wms-auth.guard.js';
8
- import { WMS_AUTH_OPTIONS } from './auth/wms-auth.types.js';
9
- import { WmsMutationInterceptor } from './events/wms-mutation.interceptor.js';
10
- import { pruneDisabledOperations } from './registry/operation-registry.js';
11
- import { LoaderMutation } from './mutations/loader.mutation.js';
12
- import { LoaderQuery } from './queries/loader.query.js';
13
- import { MaterialMutation } from './mutations/material.mutation.js';
14
- import { MaterialQuery } from './queries/material.query.js';
15
- import { StockQuery } from './queries/stock.query.js';
16
- import { ReceiveInventoryOrderMutation } from './mutations/receive-inventory-order.mutation.js';
17
- import { ReceiveInventoryOrderQuery } from './queries/recieve-inventory-order.query.js';
18
- import { ShipInventoryOrderMutation } from './mutations/ship-inventory-order.mutation.js';
19
- import { ShipInventoryOrderQuery } from './queries/ship-inventory-order.query.js';
20
- import { LoaderResolver } from './resolvers/loader.resolver.js';
21
- import { MaterialResolver } from './resolvers/material.resolver.js';
22
- import { StockResolver } from './resolvers/stock.resolver.js';
23
- import { WarehouseMapMutation } from './mutations/warehouse-map.mutation.js';
24
- import { LocationResolver } from './resolvers/location.resolver.js';
25
- import { LocationQuery } from './queries/location.query.js';
26
- import { LocationMutation } from './mutations/location.mutation.js';
27
- import { LoaderTypeResolver } from './resolvers/loader-type.resolver.js';
28
- import { UnitQuery } from './queries/unit.query.js';
29
- import { AggregatedStockResolver } from './resolvers/aggregated-stock.resolver.js';
30
- import { TransferOrderMutation } from './mutations/transfer-order.mutation.js';
31
- import { TransferOrderQuery } from './queries/transfer-order.query.js';
32
- import { TransferOrderResolver, TransferOrderItemResolver } from './resolvers/transfer-order.resolver.js';
33
- import { HoldInventoryOrderMutation } from './mutations/hold-inventory-order.mutation.js';
34
- import { HoldInventoryOrderQuery } from './queries/hold-inventory-order.query.js';
35
- import { HoldInventoryOrderResolver } from './resolvers/hold-inventory-order.resolver.js';
36
- import { BatchQuery } from './queries/batch.query.js';
37
- import { OrderReferenceQuery } from './queries/order-reference.query.js';
38
- import { OrderReferenceMutation } from './mutations/order-reference.mutation.js';
39
- import { ConsumptionOrderQuery } from './queries/consumption-order.query.js';
40
- import { ConsumptionOrderMutation } from './mutations/consumption-order.mutation.js';
41
- import { ConsumptionOrderResolver, ConsumptionOrderItemResolver } from './resolvers/consumption-order.resolver.js';
42
- import { ChangeLogResolver } from './resolvers/change-log.resolver.js';
43
- import { ReceiveInventoryOrderResolver, ReceiveInventoryOrderItemResolver } from './resolvers/receive-inventory-order.resolver.js';
44
- import { AllocateInventoryOrderQuery } from './queries/allocate-inventory-order.query.js';
45
- import { AllocateInventoryOrderResolver } from './resolvers/allocate-inventory-order.resolver.js';
46
- import { AllocateInventoryOrderMutation } from './mutations/allocate-inventory-order.mutation.js';
47
- import { ShipInventoryOrderResolver, ShipInventoryOrderItemResolver, ShipInventoryOrderReferenceResolver } from './resolvers/ship-inventory-order.resolver.js';
48
- import { SaleOrderQuery } from './queries/sale-order.query.js';
49
- import { SplitBatchMutation } from './mutations/split-batch.mutation.js';
50
- import { MergeBatchMutation } from './mutations/merge-batch.mutation.js';
51
- import { ReclassifyInventoryOrderMutation } from './mutations/reclassify-inventory-order.mutation.js';
52
- import { TransferCustomerOrderMutation } from './mutations/transfer-customer-order.mutation.js';
53
- import { TransferCustomerOrderResolver } from './resolvers/transfer-customer-order.resolver.js';
54
- import { TransferVendorOrderMutation } from './mutations/transfer-vendor-order.mutation.js';
55
- import { TransferVendorOrderResolver } from './resolvers/transfer-vendor-order.resolver.js';
56
- import { SplitBatchResolver } from './resolvers/split-batch.resolver.js';
57
- import { MergeBatchOrderResolver } from './resolvers/merge-batch.resolver.js';
58
- import { ScrapeMutation } from './mutations/scrape-order.mutation.js';
59
- import { QualityInspectionOrderMutation } from './mutations/quality-inspection-order.mutation.js';
60
- import { WarehouseMapDataQuery } from './queries/warehouse-map.query.js';
61
- import { MapRangeUnionResolver } from './resolvers/warehouse-map.resolver.js';
62
- import { InventoryCountOrderQuery } from './queries/inventory-count-order.query.js';
63
- import { InventoryCountOrderMutation } from './mutations/inventory-count-order.mutation.js';
64
- import { InventoryCountOrderResolver, InventoryCountOrderItemResolver } from './resolvers/inventory-count-order.resolver.js';
65
-
66
- var WmsModuleGraphqlModule_1;
67
- const exportDependencies = [
68
- UnitQuery,
69
- LoaderMutation,
70
- LoaderQuery,
71
- LoaderResolver,
72
- LoaderTypeResolver,
73
- MaterialMutation,
74
- MaterialQuery,
75
- MaterialResolver,
76
- BatchQuery,
77
- StockQuery,
78
- StockResolver,
79
- ChangeLogResolver,
80
- AggregatedStockResolver,
81
- ReceiveInventoryOrderMutation,
82
- ReceiveInventoryOrderQuery,
83
- ReceiveInventoryOrderResolver,
84
- ReceiveInventoryOrderItemResolver,
85
- ShipInventoryOrderMutation,
86
- ShipInventoryOrderQuery,
87
- ShipInventoryOrderResolver,
88
- ShipInventoryOrderItemResolver,
89
- ShipInventoryOrderReferenceResolver,
90
- TransferOrderMutation,
91
- TransferOrderQuery,
92
- TransferOrderResolver,
93
- HoldInventoryOrderMutation,
94
- HoldInventoryOrderQuery,
95
- HoldInventoryOrderResolver,
96
- WarehouseMapMutation,
97
- LocationMutation,
98
- LocationQuery,
99
- LocationResolver,
100
- TransferOrderMutation,
101
- TransferOrderResolver,
102
- TransferOrderItemResolver,
103
- AllocateInventoryOrderQuery,
104
- AllocateInventoryOrderResolver,
105
- AllocateInventoryOrderMutation,
106
- TransferCustomerOrderMutation,
107
- TransferCustomerOrderResolver,
108
- TransferVendorOrderMutation,
109
- TransferVendorOrderResolver,
110
- SaleOrderQuery,
111
- SplitBatchMutation,
112
- SplitBatchResolver,
113
- MergeBatchMutation,
114
- MergeBatchOrderResolver,
115
- ReclassifyInventoryOrderMutation,
116
- ScrapeMutation,
117
- QualityInspectionOrderMutation,
118
- WarehouseMapDataQuery,
119
- MapRangeUnionResolver,
120
- InventoryCountOrderQuery,
121
- InventoryCountOrderMutation,
122
- InventoryCountOrderResolver,
123
- InventoryCountOrderItemResolver,
124
- OrderReferenceQuery,
125
- OrderReferenceMutation,
126
- ConsumptionOrderQuery,
127
- ConsumptionOrderMutation,
128
- ConsumptionOrderResolver,
129
- ConsumptionOrderItemResolver,
130
- ];
131
- let WmsModuleGraphqlModule = WmsModuleGraphqlModule_1 = class WmsModuleGraphqlModule {
132
- static forRootAsync(options) {
133
- const { authChecker, beforeHooks, afterListeners, actorExtractor, eventEmitterBridge, enabledOperations, disabledOperations, disabledFields, ...coreOptions } = options;
134
- // Must run before `GraphQLModule` builds the schema. `forRootAsync` is
135
- // called while `AppModule` is still being defined, so this is the earliest
136
- // point at which the deployment's switches are known — and it is early
137
- // enough: the schema is not built until the app bootstraps.
138
- pruneDisabledOperations(exportDependencies, {
139
- enabledOperations,
140
- disabledOperations,
141
- disabledFields,
142
- });
143
- /*
144
- * The event wiring goes down to the core module rather than being bound
145
- * here. `WmsOperationRunner` lives in core so a host calling a service
146
- * directly gets the same guarantee, and binding the same tokens in both
147
- * modules would leave two live bindings whose winner depends on which
148
- * injector the consumer reached first.
149
- *
150
- * `coreOptions` still carries `enrichStockEvents`, also forwarded.
151
- */
152
- const coreModule = WmsModuleCoreModule.forRootAsync({
153
- ...coreOptions,
154
- // The typed hook maps are a compile-time refinement of the core maps; at
155
- // runtime the dispatched payload IS the concrete result type, so handing
156
- // the refined maps to the (looser) core option contract is sound.
157
- beforeHooks: beforeHooks,
158
- afterListeners: afterListeners,
159
- actorExtractor,
160
- eventEmitterBridge,
161
- });
162
- const authOptions = { authChecker };
163
- const providers = [
164
- ...exportDependencies,
165
- WmsAuthGuard,
166
- { provide: WMS_AUTH_OPTIONS, useValue: authOptions },
167
- WmsMutationInterceptor,
168
- ];
169
- return {
170
- module: WmsModuleGraphqlModule_1,
171
- imports: [coreModule, HelperModule],
172
- providers,
173
- exports: [...exportDependencies, WmsAuthGuard, HelperModule, coreModule],
174
- };
175
- }
176
- };
177
- WmsModuleGraphqlModule = WmsModuleGraphqlModule_1 = __decorate([
178
- Module({
179
- providers: exportDependencies,
180
- })
181
- ], WmsModuleGraphqlModule);
182
-
183
- export { WmsModuleGraphqlModule };
@@ -1,11 +0,0 @@
1
- function createWmsLoaders(loaderService) {
2
- return {
3
- loaders: {
4
- batchSingle: loaderService.batchEntity(),
5
- batchMany: loaderService.batchEntities(),
6
- batchManyWithPagination: loaderService.batchEntitiesWithPagination(),
7
- },
8
- };
9
- }
10
-
11
- export { createWmsLoaders };
@@ -1,15 +0,0 @@
1
- import { __decorate } from 'tslib';
2
- import { Global, Module } from '@nestjs/common';
3
- import { LoaderService } from './loader.service.js';
4
-
5
- let HelperModule = class HelperModule {
6
- };
7
- HelperModule = __decorate([
8
- Global(),
9
- Module({
10
- providers: [LoaderService],
11
- exports: [LoaderService],
12
- })
13
- ], HelperModule);
14
-
15
- export { HelperModule };
@@ -1,230 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import { Injectable } from '@nestjs/common';
3
- import { createHash } from 'crypto';
4
- import _ from 'lodash';
5
- import { LRUCache } from 'lru-cache';
6
- import { DataSource, Brackets, In } from 'typeorm';
7
- import DataLoader from 'dataloader';
8
-
9
- let LoaderService = class LoaderService {
10
- dataSource;
11
- cache;
12
- constructor(dataSource) {
13
- this.dataSource = dataSource;
14
- this.cache = new LRUCache({
15
- max: 10000,
16
- ttlAutopurge: true,
17
- ttl: 500,
18
- });
19
- }
20
- /**
21
- * create hash from `__entity` in loader option, and return option with `__hash` set with hash value.
22
- * @param LoaderOptions
23
- * @returns LoaderOptions
24
- */
25
- useHash(options) {
26
- const algorithm = createHash('sha1');
27
- algorithm.update(options.__entity.toString());
28
- algorithm.update(_(Object.keys(options.__from)).sort().join(''));
29
- if (options.__seed)
30
- algorithm.update(options.__seed);
31
- if (options.__conditions)
32
- algorithm.update(options.__conditions.toString());
33
- return { ...options, __hash: algorithm.digest('hex') };
34
- }
35
- /**
36
- * generate index by queried data primary keys, which is defined in loader option `__from`
37
- * @param object
38
- * @param LoaderOptions
39
- * @returns Map<string, data>
40
- */
41
- useIndex(data, { __hash, __from }) {
42
- const fields = _(Object.keys(__from)).sort();
43
- return `${__hash}_${fields.map((field) => data[field]).join('_')}`;
44
- }
45
- /**
46
- * resolve a `__from` property name to the physical column it is stored in.
47
- *
48
- * TypeORM's `FindOptionsWhere` only accepts real column properties. A
49
- * `@RelationId()` property — e.g. `LocationEntityClass.parentId`, which mirrors
50
- * the `parent` tree relation — is virtual and is rejected with
51
- * `EntityPropertyNotFoundError`, even though it is backed by the relation's
52
- * join column. Map those back to their join column so they stay batchable.
53
- * @param EntityMetadata
54
- * @param string
55
- * @returns string | null
56
- */
57
- resolveColumnName(metadata, propertyName) {
58
- const column = metadata.findColumnWithPropertyName(propertyName);
59
- if (column)
60
- return column.databaseName;
61
- const relationId = metadata.relationIds.find((candidate) => candidate.propertyName === propertyName);
62
- const joinColumns = relationId?.relation.joinColumns ?? [];
63
- return joinColumns.length === 1 ? joinColumns[0].databaseName : null;
64
- }
65
- /**
66
- * build the where clause for `__from` keys that TypeORM's find options cannot
67
- * express (see {@link resolveColumnName}), by addressing the columns directly.
68
- * @param SelectQueryBuilder
69
- * @param EntityMetadata
70
- * @param LoaderOptions[]
71
- * @param (keyof T)[]
72
- */
73
- applyColumnWhere(qb, metadata, options, primaryKeys) {
74
- const columns = primaryKeys.map((primaryKey) => {
75
- const columnName = this.resolveColumnName(metadata, String(primaryKey));
76
- if (!columnName)
77
- throw new Error(`Loader cannot resolve property "${String(primaryKey)}" to a column of "${metadata.name}".`);
78
- return {
79
- primaryKey,
80
- column: `entity.${this.dataSource.driver.escape(columnName)}`,
81
- };
82
- });
83
- if (columns.length === 1) {
84
- const [{ primaryKey, column }] = columns;
85
- qb.andWhere(`${column} IN (:...wmsLoaderValues)`, {
86
- wmsLoaderValues: options.map(({ __from }) => __from[primaryKey]),
87
- });
88
- return;
89
- }
90
- qb.andWhere(new Brackets((where) => {
91
- options.forEach(({ __from }, optionIndex) => {
92
- const parameters = {};
93
- const predicate = columns
94
- .map(({ primaryKey, column }, columnIndex) => {
95
- const parameter = `wmsLoaderValue_${optionIndex}_${columnIndex}`;
96
- parameters[parameter] = __from[primaryKey];
97
- return `${column} = :${parameter}`;
98
- })
99
- .join(' AND ');
100
- where.orWhere(`(${predicate})`, parameters);
101
- });
102
- }));
103
- }
104
- /**
105
- * query data by collecting primary keys from options with same `__entity`
106
- * @param LoaderOptions[]
107
- * @returns object[]
108
- */
109
- async core(options) {
110
- const [{ __entity, __from, __conditions }] = options;
111
- const repo = this.dataSource.getRepository(__entity);
112
- let qb = repo.createQueryBuilder('entity');
113
- const primaryKeys = Object.keys(__from);
114
- const hasVirtualKey = primaryKeys.some((primaryKey) => !repo.metadata.findColumnWithPropertyName(String(primaryKey)));
115
- if (hasVirtualKey)
116
- this.applyColumnWhere(qb, repo.metadata, options, primaryKeys);
117
- else if (primaryKeys.length > 1)
118
- qb.setFindOptions({ where: options.map(({ __from }) => __from) });
119
- else {
120
- const [primaryKey] = primaryKeys;
121
- qb.setFindOptions({
122
- where: {
123
- [primaryKey]: In(options.map(({ __from }) => __from[primaryKey])),
124
- },
125
- });
126
- }
127
- if (__conditions)
128
- qb = __conditions(qb);
129
- return qb.getMany();
130
- }
131
- /**
132
- * batch single entity to load function calls.
133
- * @returns object
134
- */
135
- batchEntity() {
136
- return new DataLoader(async (inputs) => {
137
- const options = inputs.map((input) => this.useHash(input));
138
- const dataMap = new Map();
139
- const processMap = _(options)
140
- .groupBy((x) => x.__hash)
141
- .value();
142
- await Promise.all(Object.keys(processMap).map(async (entityHash) => {
143
- const options = processMap[entityHash];
144
- const [option] = options;
145
- const entities = await this.core(options);
146
- entities.map((entity) => dataMap.set(this.useIndex(entity, option), entity));
147
- }));
148
- return options.map((option) => dataMap.get(this.useIndex(option.__from, option)));
149
- }, {
150
- batchScheduleFn: (callback) => setTimeout(callback, 50),
151
- cacheKeyFn: (option) => this.useIndex(option.__from, this.useHash(option)),
152
- cacheMap: this.cache,
153
- });
154
- }
155
- /**
156
- * batch many entities to load function calls.
157
- * @returns object[]
158
- */
159
- batchEntities() {
160
- return new DataLoader(async (inputs) => {
161
- const options = inputs.map((input) => this.useHash(input));
162
- const dataMap = new Map();
163
- const processMap = _(options)
164
- .groupBy((x) => x.__hash)
165
- .value();
166
- await Promise.all(Object.keys(processMap).map(async (entityHash) => {
167
- const options = processMap[entityHash];
168
- const [option] = options;
169
- const entities = await this.core(options);
170
- entities.map((entity) => {
171
- const index = this.useIndex(entity, option);
172
- const entities = dataMap.get(index) ?? [];
173
- entities.push(entity);
174
- dataMap.set(index, entities);
175
- });
176
- }));
177
- return options.map((option) => {
178
- const result = dataMap.get(this.useIndex(option.__from, option)) ?? [];
179
- return option.__pagination
180
- ? result.slice(option.__pagination.offset, option.__pagination.offset + option.__pagination.limit)
181
- : result;
182
- });
183
- }, {
184
- batchScheduleFn: (callback) => setTimeout(callback, 100),
185
- cacheKeyFn: (option) => this.useIndex(option.__from, this.useHash(option)),
186
- cacheMap: this.cache,
187
- });
188
- }
189
- batchEntitiesWithPagination() {
190
- return new DataLoader(async (inputs) => {
191
- const options = inputs.map((input) => this.useHash(input));
192
- const dataMap = new Map();
193
- const processMap = _(options)
194
- .groupBy((x) => x.__hash)
195
- .value();
196
- await Promise.all(Object.keys(processMap).map(async (entityHash) => {
197
- const options = processMap[entityHash];
198
- const [option] = options;
199
- const entities = await this.core(options);
200
- entities.map((entity) => {
201
- const index = this.useIndex(entity, option);
202
- const entities = dataMap.get(index) ?? [];
203
- entities.push(entity);
204
- dataMap.set(index, entities);
205
- });
206
- }));
207
- return options.map((option) => {
208
- const result = dataMap.get(this.useIndex(option.__from, option));
209
- if (!result)
210
- return { items: [], total: 0 };
211
- return {
212
- items: option.__pagination
213
- ? result.slice(option.__pagination.offset, option.__pagination.offset + option.__pagination.limit)
214
- : result,
215
- total: result.length,
216
- };
217
- });
218
- }, {
219
- batchScheduleFn: (callback) => setTimeout(callback, 100),
220
- cacheKeyFn: (option) => this.useIndex(option.__from, this.useHash(option)),
221
- cacheMap: this.cache,
222
- });
223
- }
224
- };
225
- LoaderService = __decorate([
226
- Injectable(),
227
- __metadata("design:paramtypes", [DataSource])
228
- ], LoaderService);
229
-
230
- export { LoaderService };
@@ -1,19 +0,0 @@
1
- import { createParamDecorator } from '@nestjs/common';
2
- import { GqlExecutionContext } from '@nestjs/graphql';
3
- import _ from 'lodash';
4
-
5
- createParamDecorator((data, context) => {
6
- if (context.getType().toString() === 'graphql') {
7
- const ctx = GqlExecutionContext.create(context).getInfo();
8
- const extractPath = ({ prev, key }, paths) => {
9
- if (key && _.isString(key))
10
- paths.unshift(key);
11
- if (prev)
12
- return extractPath(prev, paths);
13
- return paths;
14
- };
15
- const paths = extractPath(ctx.path, []);
16
- return paths.join('/');
17
- }
18
- return null;
19
- });
@@ -1,20 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import { Field, ID, Int, InputType } from '@nestjs/graphql';
3
-
4
- let CancelShipOrderArgs = class CancelShipOrderArgs {
5
- itemId;
6
- quantity;
7
- };
8
- __decorate([
9
- Field(() => ID),
10
- __metadata("design:type", String)
11
- ], CancelShipOrderArgs.prototype, "itemId", void 0);
12
- __decorate([
13
- Field(() => Int, { nullable: true }),
14
- __metadata("design:type", Number)
15
- ], CancelShipOrderArgs.prototype, "quantity", void 0);
16
- CancelShipOrderArgs = __decorate([
17
- InputType()
18
- ], CancelShipOrderArgs);
19
-
20
- export { CancelShipOrderArgs };
@@ -1,23 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import { Field, ID, Int, InputType } from '@nestjs/graphql';
3
-
4
- let CancelTransferOrderArgs = class CancelTransferOrderArgs {
5
- itemId;
6
- quantity;
7
- };
8
- __decorate([
9
- Field(() => ID, { description: 'The ID of transfer order item' }),
10
- __metadata("design:type", String)
11
- ], CancelTransferOrderArgs.prototype, "itemId", void 0);
12
- __decorate([
13
- Field(() => Int, {
14
- nullable: true,
15
- description: 'The quantity to cancel. If not provided, cancels all remaining cancellable quantity.',
16
- }),
17
- __metadata("design:type", Number)
18
- ], CancelTransferOrderArgs.prototype, "quantity", void 0);
19
- CancelTransferOrderArgs = __decorate([
20
- InputType()
21
- ], CancelTransferOrderArgs);
22
-
23
- export { CancelTransferOrderArgs };