@happyvertical/smrt-manufacturing 0.53.5 → 0.53.6

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 (67) hide show
  1. package/AGENTS.md +18 -6
  2. package/README.md +69 -3
  3. package/agents/multilevel-and-runs.md +28 -0
  4. package/dist/collections/ProductionRunCollection.d.ts +15 -0
  5. package/dist/collections/ProductionRunCollection.d.ts.map +1 -0
  6. package/dist/collections/ProductionRunCompletionCollection.d.ts +14 -0
  7. package/dist/collections/ProductionRunCompletionCollection.d.ts.map +1 -0
  8. package/dist/collections/index.d.ts +2 -0
  9. package/dist/collections/index.d.ts.map +1 -1
  10. package/dist/index.d.ts +13 -5
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +972 -81
  13. package/dist/index.js.map +1 -1
  14. package/dist/manifest.json +630 -1
  15. package/dist/models/ProductionRun.d.ts +67 -0
  16. package/dist/models/ProductionRun.d.ts.map +1 -0
  17. package/dist/models/ProductionRunCompletion.d.ts +36 -0
  18. package/dist/models/ProductionRunCompletion.d.ts.map +1 -0
  19. package/dist/models/index.d.ts +2 -0
  20. package/dist/models/index.d.ts.map +1 -1
  21. package/dist/operation-types.d.ts +9 -0
  22. package/dist/operation-types.d.ts.map +1 -1
  23. package/dist/production-run-types.d.ts +100 -0
  24. package/dist/production-run-types.d.ts.map +1 -0
  25. package/dist/quantity.d.ts +36 -0
  26. package/dist/quantity.d.ts.map +1 -0
  27. package/dist/services/AssemblyService.d.ts +7 -2
  28. package/dist/services/AssemblyService.d.ts.map +1 -1
  29. package/dist/services/BomService.d.ts +84 -5
  30. package/dist/services/BomService.d.ts.map +1 -1
  31. package/dist/services/ProductionRunService.d.ts +123 -0
  32. package/dist/services/ProductionRunService.d.ts.map +1 -0
  33. package/dist/services/ProductionService.d.ts +11 -0
  34. package/dist/services/ProductionService.d.ts.map +1 -1
  35. package/dist/services/index.d.ts +2 -0
  36. package/dist/services/index.d.ts.map +1 -1
  37. package/dist/services/structure-walk.d.ts +77 -0
  38. package/dist/services/structure-walk.d.ts.map +1 -0
  39. package/dist/smrt-knowledge.json +514 -7
  40. package/dist/svelte/components/ProductionRunList.svelte +213 -0
  41. package/dist/svelte/components/ProductionRunList.svelte.d.ts +18 -0
  42. package/dist/svelte/components/ProductionRunList.svelte.d.ts.map +1 -0
  43. package/dist/svelte/components/RequirementsTree.svelte +125 -0
  44. package/dist/svelte/components/RequirementsTree.svelte.d.ts +13 -0
  45. package/dist/svelte/components/RequirementsTree.svelte.d.ts.map +1 -0
  46. package/dist/svelte/components/RequirementsTreeLevel.svelte +120 -0
  47. package/dist/svelte/components/RequirementsTreeLevel.svelte.d.ts +12 -0
  48. package/dist/svelte/components/RequirementsTreeLevel.svelte.d.ts.map +1 -0
  49. package/dist/svelte/i18n.d.ts +32 -0
  50. package/dist/svelte/i18n.d.ts.map +1 -1
  51. package/dist/svelte/i18n.js +32 -0
  52. package/dist/svelte/index.d.ts +9 -4
  53. package/dist/svelte/index.d.ts.map +1 -1
  54. package/dist/svelte/index.js +9 -4
  55. package/dist/svelte/types.d.ts +87 -0
  56. package/dist/svelte/types.d.ts.map +1 -1
  57. package/dist/svelte/types.js +123 -0
  58. package/dist/tenant-scope.d.ts +25 -0
  59. package/dist/tenant-scope.d.ts.map +1 -0
  60. package/dist/types.d.ts +207 -3
  61. package/dist/types.d.ts.map +1 -1
  62. package/dist/types.js +13 -1
  63. package/dist/types.js.map +1 -1
  64. package/dist/ui.d.ts.map +1 -1
  65. package/dist/ui.js +23 -1
  66. package/dist/ui.js.map +1 -1
  67. package/package.json +11 -10
@@ -0,0 +1,67 @@
1
+ /**
2
+ * ProductionRun — a build of some quantity of a product against one
3
+ * {@link BillOfMaterials}, reported as it happens: "25 to build, 12 done".
4
+ *
5
+ * The run pins the bill it was started against, carries the target and the
6
+ * completed quantity, and moves through `planned` → `in_progress` → `done`,
7
+ * or to `cancelled`. Each report of finished units is a dated
8
+ * {@link ProductionRunCompletion}; `completedQty` is their sum.
9
+ *
10
+ * Writes go through `ProductionRunService`, which keeps `completedQty` equal
11
+ * to the completions under concurrent reporting and enforces the status
12
+ * transitions. The generated REST/MCP/CLI surfaces are read-only for that
13
+ * reason.
14
+ *
15
+ * This is the shop-floor record of building. It is not the commercial
16
+ * instruction to make goods (`ProductionOrder` in `@happyvertical/smrt-commerce`,
17
+ * which carries terms and money); several runs may serve one order, or none
18
+ * (make to stock). An application that has both links them itself.
19
+ *
20
+ * @packageDocumentation
21
+ */
22
+ import { SmrtObject, type SmrtObjectOptions } from '@happyvertical/smrt-core';
23
+ /**
24
+ * Where a {@link ProductionRun} is:
25
+ *
26
+ * - `planned` — created, nothing reported yet.
27
+ * - `in_progress` — started, or at least one completion reported.
28
+ * - `done` — the target was reached, or the run was finished short.
29
+ * - `cancelled` — stopped; completions already reported stay.
30
+ */
31
+ export type ProductionRunStatus = 'planned' | 'in_progress' | 'done' | 'cancelled';
32
+ /** Every {@link ProductionRunStatus}, in lifecycle order. */
33
+ export declare const PRODUCTION_RUN_STATUSES: readonly ProductionRunStatus[];
34
+ /**
35
+ * Options accepted by the {@link ProductionRun} constructor.
36
+ */
37
+ export interface ProductionRunOptions extends SmrtObjectOptions {
38
+ tenantId?: string | null;
39
+ bomId?: string;
40
+ targetQty?: number;
41
+ completedQty?: number;
42
+ status?: ProductionRunStatus;
43
+ }
44
+ export declare class ProductionRun extends SmrtObject {
45
+ /** Tenant scope. `null` means the run is a global record. */
46
+ tenantId: string | null;
47
+ /**
48
+ * The bill the run builds against, pinned when the run is created.
49
+ * Restrict: a bill with runs is history and is not deleted.
50
+ */
51
+ bomId: string;
52
+ /** Units of the bill's product to build. Decimal; greater than zero. */
53
+ targetQty: number;
54
+ /** Units reported done so far: the sum of the run's completions. */
55
+ completedQty: number;
56
+ /** Lifecycle status; see {@link ProductionRunStatus}. */
57
+ status: ProductionRunStatus;
58
+ constructor(options?: ProductionRunOptions);
59
+ /**
60
+ * Units still to build, at the six-decimal quantity precision; `0` once
61
+ * the target is reached.
62
+ */
63
+ remainingQty(): number;
64
+ /** Refuses a status outside the lifecycle and impossible quantities. */
65
+ protected validateBeforeSave(): Promise<void>;
66
+ }
67
+ //# sourceMappingURL=ProductionRun.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProductionRun.d.ts","sourceRoot":"","sources":["../../src/models/ProductionRun.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAGL,UAAU,EACV,KAAK,iBAAiB,EAGvB,MAAM,0BAA0B,CAAC;AAKlC;;;;;;;GAOG;AACH,MAAM,MAAM,mBAAmB,GAC3B,SAAS,GACT,aAAa,GACb,MAAM,GACN,WAAW,CAAC;AAEhB,6DAA6D;AAC7D,eAAO,MAAM,uBAAuB,EAAE,SAAS,mBAAmB,EAKjE,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,iBAAiB;IAC7D,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,mBAAmB,CAAC;CAC9B;AAED,qBASa,aAAc,SAAQ,UAAU;IAC3C,6DAA6D;IAE7D,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAE/B;;;OAGG;IAEH,KAAK,EAAE,MAAM,CAAM;IAEnB,wEAAwE;IAExE,SAAS,EAAE,MAAM,CAAO;IAExB,oEAAoE;IAEpE,YAAY,EAAE,MAAM,CAAO;IAE3B,yDAAyD;IAEzD,MAAM,EAAE,mBAAmB,CAAa;gBAE5B,OAAO,GAAE,oBAAyB;IAU9C;;;OAGG;IACH,YAAY,IAAI,MAAM;IAOtB,wEAAwE;cAC/C,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;CAuB7D"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * ProductionRunCompletion — one dated report of finished units on a
3
+ * {@link ProductionRun} ("12 done on Tuesday").
4
+ *
5
+ * Written only by `ProductionRunService.recordCompletion`, in the same
6
+ * transaction that adds `qty` to the run's `completedQty` and, when the
7
+ * caller asks, posts the stock movements; those movements carry
8
+ * `sourceType: 'ProductionRunCompletion'` and this row's id. Read-only over
9
+ * the generated surfaces.
10
+ *
11
+ * @packageDocumentation
12
+ */
13
+ import { SmrtObject, type SmrtObjectOptions } from '@happyvertical/smrt-core';
14
+ /**
15
+ * Options accepted by the {@link ProductionRunCompletion} constructor.
16
+ */
17
+ export interface ProductionRunCompletionOptions extends SmrtObjectOptions {
18
+ tenantId?: string | null;
19
+ runId?: string;
20
+ qty?: number;
21
+ completedAt?: Date | string;
22
+ }
23
+ export declare class ProductionRunCompletion extends SmrtObject {
24
+ /** Tenant scope. `null` means a global record. */
25
+ tenantId: string | null;
26
+ /** The run the units were built on. Cascade: completions belong to their run. */
27
+ runId: string;
28
+ /** Units finished in this report. Decimal; greater than zero. */
29
+ qty: number;
30
+ /** When the units were finished (defaults to when the report was made). */
31
+ completedAt: Date;
32
+ constructor(options?: ProductionRunCompletionOptions);
33
+ /** Refuses a report of zero, negative or non-finite units. */
34
+ protected validateBeforeSave(): Promise<void>;
35
+ }
36
+ //# sourceMappingURL=ProductionRunCompletion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProductionRunCompletion.d.ts","sourceRoot":"","sources":["../../src/models/ProductionRunCompletion.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAGL,UAAU,EACV,KAAK,iBAAiB,EAGvB,MAAM,0BAA0B,CAAC;AAIlC;;GAEG;AACH,MAAM,WAAW,8BAA+B,SAAQ,iBAAiB;IACvE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;CAC7B;AAED,qBAQa,uBAAwB,SAAQ,UAAU;IACrD,kDAAkD;IAElD,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAE/B,iFAAiF;IAEjF,KAAK,EAAE,MAAM,CAAM;IAEnB,iEAAiE;IAEjE,GAAG,EAAE,MAAM,CAAO;IAElB,2EAA2E;IAC3E,WAAW,EAAE,IAAI,CAAc;gBAEnB,OAAO,GAAE,8BAAmC;IAYxD,8DAA8D;cACrC,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;CAU7D"}
@@ -13,5 +13,7 @@ export { Assembly, type AssemblyOptions } from './Assembly.js';
13
13
  export { BillOfMaterials, type BillOfMaterialsOptions, } from './BillOfMaterials.js';
14
14
  export { BomLine, type BomLineOptions } from './BomLine.js';
15
15
  export { Operation, type OperationOptions } from './Operation.js';
16
+ export { PRODUCTION_RUN_STATUSES, ProductionRun, type ProductionRunOptions, type ProductionRunStatus, } from './ProductionRun.js';
17
+ export { ProductionRunCompletion, type ProductionRunCompletionOptions, } from './ProductionRunCompletion.js';
16
18
  export { RoutingStep, type RoutingStepOptions } from './RoutingStep.js';
17
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,yBAAyB,CAAC;AAEjC,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EACL,eAAe,EACf,KAAK,sBAAsB,GAC5B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,KAAK,kBAAkB,EAAE,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,yBAAyB,CAAC;AAEjC,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EACL,eAAe,EACf,KAAK,sBAAsB,GAC5B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EACL,uBAAuB,EACvB,aAAa,EACb,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,GACzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,uBAAuB,EACvB,KAAK,8BAA8B,GACpC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,KAAK,kBAAkB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -6,6 +6,7 @@
6
6
  * @packageDocumentation
7
7
  */
8
8
  import type { Operation } from './models/Operation.js';
9
+ import type { SubAssemblyLabour } from './types.js';
9
10
  /**
10
11
  * Callback that returns the hourly labour rate for an operation, in the bill's
11
12
  * currency, or `null` / `undefined` when no rate is known. The package holds no
@@ -55,6 +56,14 @@ export interface LabourEstimate {
55
56
  steps: RoutingStepEstimate[];
56
57
  /** `true` when a step's rate was unavailable, so `totalCost` is a lower bound. */
57
58
  hasMissingRates: boolean;
59
+ /**
60
+ * Multi-level only (`{ levels }` above 1): every sub-assembly the walk
61
+ * opened, at any depth, with its own routing estimate and how many units of
62
+ * it one unit of this bill's product needs. `totalMinutes`, `totalCost`,
63
+ * `hasRouting` and `hasMissingRates` then cover them too; `steps` stays this
64
+ * bill's own routing.
65
+ */
66
+ subAssemblies?: SubAssemblyLabour[];
58
67
  }
59
68
  /** One step handed to `RoutingService.replaceRouting`. */
60
69
  export interface RoutingStepInput {
@@ -1 +1 @@
1
- {"version":3,"file":"operation-types.d.ts","sourceRoot":"","sources":["../src/operation-types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,MAAM,qBAAqB,GAAG,CAClC,SAAS,EAAE,SAAS,KACjB,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;AAEpE,0CAA0C;AAC1C,MAAM,WAAW,mBAAmB;IAClC,2BAA2B;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,wCAAwC;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,+DAA+D;IAC/D,aAAa,EAAE,MAAM,CAAC;IACtB,+DAA+D;IAC/D,aAAa,EAAE,MAAM,CAAC;IACtB,mDAAmD;IACnD,gBAAgB,EAAE,MAAM,CAAC;IACzB,8DAA8D;IAC9D,UAAU,EAAE,MAAM,CAAC;IACnB,8EAA8E;IAC9E,QAAQ,EAAE,MAAM,CAAC;IACjB,mEAAmE;IACnE,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,mCAAmC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,0DAA0D;IAC1D,UAAU,EAAE,OAAO,CAAC;IACpB,yDAAyD;IACzD,YAAY,EAAE,MAAM,CAAC;IACrB,2EAA2E;IAC3E,SAAS,EAAE,MAAM,CAAC;IAClB,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,8BAA8B;IAC9B,KAAK,EAAE,mBAAmB,EAAE,CAAC;IAC7B,kFAAkF;IAClF,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED,0DAA0D;AAC1D,MAAM,WAAW,gBAAgB;IAC/B,mDA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M,CAAC;CAClC;AAED,kDAAkD;AAClD,qBAAa,sBAAuB,SAAQ,KAAK;aAGnB,WAAW,EAAE,MAAM;IAFtC,IAAI,SAA4B;gBAEb,WAAW,EAAE,MAAM;CAGhD;AAED,sEAAsE;AACtE,qBAAa,2BAA4B,SAAQ,KAAK;aAGxB,IAAI,EAAE,MAAM;IAF/B,IAAI,SAAiC;gBAElB,IAAI,EAAE,MAAM;CAGzC;AAED,iEAAiE;AACjE,qBAAa,qBAAsB,SAAQ,KAAK;aAGlB,WAAW,EAAE,MAAM;IAFtC,IAAI,SAA2B;gBAEZ,WAAW,EAAE,MAAM;CAKhD;AAED,qDAAqD;AACrD,qBAAa,0BAA2B,SAAQ,KAAK;IAC1C,IAAI,SAAgC;CAC9C"}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Inputs, results and errors for `ProductionRunService`.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ import type { ProductionRun } from './models/ProductionRun.js';
7
+ import type { ProductionRunCompletion } from './models/ProductionRunCompletion.js';
8
+ import type { ConsumeResult, ProduceResult } from './services/ProductionService.js';
9
+ /** Input for `ProductionRunService.createRun`. Give `bomId`, or `productId` for its active bill. */
10
+ export interface CreateProductionRunInput {
11
+ /** The bill to build against. Wins over `productId`. */
12
+ bomId?: string;
13
+ /** A product (usually an `Assembly`) whose active bill the run pins. */
14
+ productId?: string;
15
+ /** Units to build; greater than zero. */
16
+ targetQty: number;
17
+ }
18
+ /** Stock to consume when a completion is recorded: the run's bill, for the completed units. */
19
+ export interface CompletionConsumeOptions {
20
+ /** Location the components are taken from. */
21
+ locationId: string;
22
+ /** Optional free-form note on each movement. */
23
+ note?: string;
24
+ }
25
+ /** Finished goods to receive when a completion is recorded. */
26
+ export interface CompletionProduceOptions {
27
+ /** Location the finished units are received into. */
28
+ locationId: string;
29
+ /** The SKU of the bill's product that was built. */
30
+ finishedSkuId: string;
31
+ /** Optional free-form note on the movement. */
32
+ note?: string;
33
+ }
34
+ /** Input for `ProductionRunService.recordCompletion`. */
35
+ export interface RecordCompletionInput {
36
+ /** Units finished; greater than zero and no more than the run has left. */
37
+ qty: number;
38
+ /** When they were finished. Defaults to now. */
39
+ completedAt?: Date | string;
40
+ /**
41
+ * Consume the run's bill for `qty` units, in the same transaction. Omit
42
+ * (the default) to record progress without touching stock.
43
+ */
44
+ consume?: CompletionConsumeOptions;
45
+ /**
46
+ * Receive `qty` finished units, in the same transaction. Omit (the
47
+ * default) to record progress without touching stock.
48
+ */
49
+ produce?: CompletionProduceOptions;
50
+ }
51
+ /** Result of `ProductionRunService.recordCompletion`. */
52
+ export interface RecordCompletionResult {
53
+ /** The run after the completion. */
54
+ run: ProductionRun;
55
+ /** The completion that was recorded. */
56
+ completion: ProductionRunCompletion;
57
+ /** Components consumed; empty unless `consume` was given. */
58
+ consumed: ConsumeResult[];
59
+ /** Finished goods received; `null` unless `produce` was given. */
60
+ produced: ProduceResult | null;
61
+ }
62
+ /** Thrown when a production run id does not exist. */
63
+ export declare class ProductionRunNotFoundError extends Error {
64
+ readonly runId: string;
65
+ name: string;
66
+ constructor(runId: string);
67
+ }
68
+ /** Thrown when an action is not allowed in the run's current status. */
69
+ export declare class ProductionRunStateError extends Error {
70
+ readonly runId: string;
71
+ /** The run's status when the action was refused. */
72
+ readonly status: string;
73
+ /** What was attempted: `start`, `complete`, `finish`, `cancel`, `retarget`. */
74
+ readonly action: string;
75
+ name: string;
76
+ constructor(runId: string,
77
+ /** The run's status when the action was refused. */
78
+ status: string,
79
+ /** What was attempted: `start`, `complete`, `finish`, `cancel`, `retarget`. */
80
+ action: string);
81
+ }
82
+ /** Thrown when a completion would take the run past its target. */
83
+ export declare class ProductionRunOverCompletionError extends Error {
84
+ readonly runId: string;
85
+ /** The quantity reported. */
86
+ readonly qty: number;
87
+ /** What the run had left to build. */
88
+ readonly remaining: number;
89
+ name: string;
90
+ constructor(runId: string,
91
+ /** The quantity reported. */
92
+ qty: number,
93
+ /** What the run had left to build. */
94
+ remaining: number);
95
+ }
96
+ /** Thrown for invalid production run input (quantities, dates, bill). */
97
+ export declare class InvalidProductionRunInputError extends Error {
98
+ name: string;
99
+ }
100
+ //# sourceMappingURL=production-run-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"production-run-types.d.ts","sourceRoot":"","sources":["../src/production-run-types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AACnF,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACd,MAAM,iCAAiC,CAAC;AAEzC,oGAAoG;AACpG,MAAM,WAAW,wBAAwB;IACvC,wDAAwD;IACxD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yCAAyC;IACzC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,+FAA+F;AAC/F,MAAM,WAAW,wBAAwB;IACvC,8CAA8C;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,gDAAgD;IAChD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,+DAA+D;AAC/D,MAAM,WAAW,wBAAwB;IACvC,qDAAqD;IACrD,UAAU,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,aAAa,EAAE,MAAM,CAAC;IACtB,+CAA+C;IAC/C,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,yDAAyD;AACzD,MAAM,WAAW,qBAAqB;IACpC,2EAA2E;IAC3E,GAAG,EAAE,MAAM,CAAC;IACZ,gDAAgD;IAChD,WAAW,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;IAC5B;;;OAGG;IACH,OAAO,CAAC,EAAE,wBAAwB,CAAC;IACnC;;;OAGG;IACH,OAAO,CAAC,EAAE,wBAAwB,CAAC;CACpC;AAED,yDAAyD;AACzD,MAAM,WAAW,sBAAsB;IACrC,oCAAoC;IACpC,GAAG,EAAE,aAAa,CAAC;IACnB,wCAAwC;IACxC,UAAU,EAAE,uBAAuB,CAAC;IACpC,6DAA6D;IAC7D,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,kEAAkE;IAClE,QAAQ,EAAE,aAAa,GAAG,IAAI,CAAC;CAChC;AAED,sDAAsD;AACtD,qBAAa,0BAA2B,SAAQ,KAAK;aAGvB,KAAK,EAAE,MAAM;IAFhC,IAAI,SAAgC;gBAEjB,KAAK,EAAE,MAAM;CAG1C;AAED,wEAAwE;AACxE,qBAAa,uBAAwB,SAAQ,KAAK;aAI9B,KAAK,EAAE,MAAM;IAC7B,oDAAoD;aACpC,MAAM,EAAE,MAAM;IAC9B,+EAA+E;aAC/D,MAAM,EAAE,MAAM;IAPvB,IAAI,SAA6B;gBAGxB,KAAK,EAAE,MAAM;IAC7B,oDAAoD;IACpC,MAAM,EAAE,MAAM;IAC9B,+EAA+E;IAC/D,MAAM,EAAE,MAAM;CAIjC;AAED,mEAAmE;AACnE,qBAAa,gCAAiC,SAAQ,KAAK;aAIvC,KAAK,EAAE,MAAM;IAC7B,6BAA6B;aACb,GAAG,EAAE,MAAM;IAC3B,sCAAsC;aACtB,SAAS,EAAE,MAAM;IAP1B,IAAI,SAAsC;gBAGjC,KAAK,EAAE,MAAM;IAC7B,6BAA6B;IACb,GAAG,EAAE,MAAM;IAC3B,sCAAsC;IACtB,SAAS,EAAE,MAAM;CAMpC;AAED,yEAAyE;AACzE,qBAAa,8BAA+B,SAAQ,KAAK;IAC9C,IAAI,SAAoC;CAClD"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Quantity precision for planning and production runs.
3
+ *
4
+ * Quantities are decimals held in binary floating point, so sums such as
5
+ * `0.1 + 0.2` and products such as `2.2 * 100` carry rounding noise. Rather
6
+ * than compare with a tolerance (which must grow with the value and so
7
+ * eventually hides a whole unit), quantities are kept to
8
+ * {@link QUANTITY_DECIMALS} decimal places: rounded through their decimal
9
+ * representation, and summed and compared exactly as whole millionths.
10
+ *
11
+ * @packageDocumentation
12
+ */
13
+ /** Decimal places a quantity is kept to: a millionth of a unit. */
14
+ export declare const QUANTITY_DECIMALS = 6;
15
+ /**
16
+ * The largest quantity a production run accepts (target or report): every
17
+ * value up to it with {@link QUANTITY_DECIMALS} places has at most 15
18
+ * significant digits, so it survives a round trip through a double exactly
19
+ * and sums of them stay exact.
20
+ */
21
+ export declare const MAX_QUANTITY = 999999999;
22
+ /**
23
+ * `value` rounded to {@link QUANTITY_DECIMALS} decimal places (correctly
24
+ * rounded through its decimal representation, so `0.1 + 0.2` becomes
25
+ * exactly `0.3`).
26
+ */
27
+ export declare function roundQuantity(value: number): number;
28
+ /**
29
+ * `value` as a whole number of millionths, exactly (read from its decimal
30
+ * representation, not multiplied). Exact for any value up to
31
+ * {@link MAX_QUANTITY}.
32
+ */
33
+ export declare function toMillionths(value: number): number;
34
+ /** A whole number of millionths back as a quantity. */
35
+ export declare function fromMillionths(millionths: number): number;
36
+ //# sourceMappingURL=quantity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quantity.d.ts","sourceRoot":"","sources":["../src/quantity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,mEAAmE;AACnE,eAAO,MAAM,iBAAiB,IAAI,CAAC;AAInC;;;;;GAKG;AACH,eAAO,MAAM,YAAY,YAAc,CAAC;AAExC;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,uDAAuD;AACvD,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAEzD"}
@@ -165,10 +165,15 @@ export declare class AssemblyService {
165
165
  */
166
166
  resolveComponent(skuId: string, options?: ResolveComponentOptions): Promise<ResolvedComponent>;
167
167
  /**
168
- * The highest-version active bill for a product, limited to one tenant's
169
- * bills when `options.tenantId` is given.
168
+ * The highest-version active bill for a product. With `options.tenantId`,
169
+ * that tenant's own bill, or else a global one; another tenant's never.
170
170
  */
171
171
  findActiveBom(productId: string, options?: ResolveComponentOptions): Promise<BillOfMaterials | null>;
172
+ /**
173
+ * One row by id: through the collection's `get` without an explicit
174
+ * tenant, else as a list read of that tenant's and global rows.
175
+ */
176
+ private byId;
172
177
  /** `true` when the SKU belongs to an {@link Assembly}. */
173
178
  isAssembly(skuId: string): Promise<boolean>;
174
179
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"AssemblyService.d.ts","sourceRoot":"","sources":["../../src/services/AssemblyService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EACL,KAAK,cAAc,EAEnB,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,iBAAiB,EACjB,aAAa,EACd,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAEL,KAAK,OAAO,EACZ,KAAK,GAAG,EACT,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,yBAAyB,EAAE,MAAM,6CAA6C,CAAC;AACxF,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAGpD;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,UAAU,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE3E;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,8CAA8C;IAC9C,KAAK,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,IAAI,EAAE,aAAa,CAAC;IACpB,sDAAsD;IACtD,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC;IAChB;;;O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lC;;;OAGG;YACW,IAAI;IAgBlB,0DAA0D;IACpD,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIjD;;;;;;OAMG;IACG,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAkB7D;;;;;;OAMG;IACG,SAAS,CACb,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,SAAS,MAAM,EAAE,EAClC,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,iBAAiB,EAAE,GAAG,IAAI,CAAC;IAyCtC;;;;;;;OAOG;IACG,iBAAiB,CACrB,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,gBAAgB,CAAC,GAC9C,OAAO,CAAC,IAAI,CAAC;IAUhB;;;;;;;;;;;;OAYG;IACG,iBAAiB,CACrB,GAAG,EAAE,IAAI,CACP,eAAe,EACf,IAAI,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,GAAG,UAAU,CACvD,GACA,OAAO,CAAC,IAAI,CAAC;IA+BhB,OAAO,CAAC,aAAa;CAYtB;AAED,uDAAuD;AACvD,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,eAAe,CAAC,CAE1B"}
@@ -9,6 +9,14 @@
9
9
  * - "What do I need to buy / pull to make N units?" via {@link explodeRequirements}
10
10
  * - "Do I have enough on hand?" via {@link canProduce}
11
11
  *
12
+ * Every method reads one level of the bill by default. Pass `{ levels }` to
13
+ * walk sub-assemblies too: a line whose component SKU belongs to an
14
+ * `Assembly` with an active bill is opened, to the given depth or (`'all'`)
15
+ * down to materials and bought items. {@link explode} returns that walk line
16
+ * by line with the rolled-up totals, and {@link planRequirements} nets it
17
+ * against stock: how much of each sub-assembly is available, how much is
18
+ * short, and what building the shortfall takes.
19
+ *
12
20
  * Construct via {@link BomService.create} — the static factory wires up
13
21
  * the BOM, BOM-line, and inventory collections so a single `db` (or a
14
22
  * pre-built {@link StockService}) drives everything.
@@ -30,7 +38,8 @@ import { OperationCollection } from '../collections/OperationCollection.js';
30
38
  import { RoutingStepCollection } from '../collections/RoutingStepCollection.js';
31
39
  import type { BomLine } from '../models/BomLine.js';
32
40
  import type { LabourEstimate, OperationRateResolver } from '../operation-types.js';
33
- import { type BomCostRollup, type CanProduceResult, type MaterialRequirement } from '../types.js';
41
+ import { type BomCostRollup, type CanProduceResult, type Explosion, type ExplosionOptions, type MaterialRequirement, type RequirementsPlan } from '../types.js';
42
+ import { AssemblyService } from './AssemblyService.js';
34
43
  /**
35
44
  * Callback signature for resolving the unit cost of a component SKU.
36
45
  *
@@ -104,6 +113,8 @@ export declare class BomService {
104
113
  readonly routingSteps: RoutingStepCollection;
105
114
  readonly operations: OperationCollection;
106
115
  private readonly rateResolver;
116
+ /** Resolves components for the multi-level walks. */
117
+ readonly assemblies: AssemblyService;
107
118
  private constructor();
108
119
  /** Factory — prefer {@link createBomService}. */
109
120
  static create(options: BomServiceOptions): Promise<BomService>;
@@ -118,8 +129,16 @@ export declare class BomService {
118
129
  * set `costUnavailable: true` on their breakdown row; the aggregate
119
130
  * `hasMissingCosts` flag mirrors this so callers can surface a UI
120
131
  * warning.
132
+ *
133
+ * With `{ levels }` above 1, a sub-assembly line whose bill the walk opens
134
+ * is costed from that bill instead of the resolver: its `unitCost` is the
135
+ * bill's rolled-up material cost per unit, its `components` hold that
136
+ * bill's lines, and a missing cost anywhere below marks it and
137
+ * `hasMissingCosts` (its known part still counts, so the total is a lower
138
+ * bound). Other lines, including sub-assemblies with no active bill, use
139
+ * the resolver as before.
121
140
  */
122
- computeMaterialCost(bomId: string): Promise<BomCostRollup>;
141
+ computeMaterialCost(bomId: string, options?: ExplosionOptions): Promise<BomCostRollup>;
123
142
  /**
124
143
  * Roll up the estimated labour to build one unit from the bill's routing:
125
144
  * total minutes, plus cost when a `rateResolver` was supplied (hourly rate
@@ -127,9 +146,15 @@ export declare class BomService {
127
146
  * estimate with zero totals, so callers can add it to the material cost
128
147
  * unconditionally. Retired operations still count: the routing names them.
129
148
  *
149
+ * With `{ levels }` above 1, every sub-assembly the walk opens adds its own
150
+ * bill's routing, multiplied by the units of it one unit needs (waste
151
+ * included); see {@link LabourEstimate.subAssemblies}.
152
+ *
130
153
  * Throws {@link BomNotFoundError} when the BOM does not exist.
131
154
  */
132
- computeLabourEstimate(bomId: string): Promise<LabourEstimate>;
155
+ computeLabourEstimate(bomId: string, options?: ExplosionOptions): Promise<LabourEstimate>;
156
+ /** One bill's own routing estimate, per unit of its product. */
157
+ private labourFor;
133
158
  /**
134
159
  * Return a "shopping list" of materials needed to produce `qty` units of
135
160
  * the parent product against the given BOM. Lines that reference the
@@ -140,10 +165,14 @@ export declare class BomService {
140
165
  * {@link ProductionService.consumeMaterials} when you're ready to write
141
166
  * stock movements.
142
167
  *
168
+ * With `{ levels }` above 1, sub-assemblies with an active bill are
169
+ * replaced by what their bills need, waste compounding down the levels;
170
+ * this is {@link explode}'s `totals`.
171
+ *
143
172
  * Throws {@link BomNotFoundError} when the BOM does not exist; throws a
144
173
  * plain `Error` when `qty` is not a positive finite number.
145
174
  */
146
- explodeRequirements(bomId: string, qty: number): Promise<MaterialRequirement[]>;
175
+ explodeRequirements(bomId: string, qty: number, options?: ExplosionOptions): Promise<MaterialRequirement[]>;
147
176
  /**
148
177
  * Check whether the requirements for producing `qty` units against the
149
178
  * given BOM are currently satisfied by available stock. Returns
@@ -156,14 +185,64 @@ export declare class BomService {
156
185
  * "where do we pull from?" is left to the caller of
157
186
  * {@link ProductionService.consumeMaterials}).
158
187
  *
188
+ * With `{ levels }` above 1 the check is {@link planRequirements}: a
189
+ * sub-assembly that is short and has an active bill is opened for its
190
+ * shortfall, and each shortage is reported on the line where it occurs,
191
+ * with its `level` and `path`. Stock is allocated as the walk goes, so a
192
+ * component used in two places is not counted twice.
193
+ *
159
194
  * Throws {@link BomNotFoundError} when the BOM does not exist.
160
195
  */
161
- canProduce(bomId: string, qty: number): Promise<CanProduceResult>;
196
+ canProduce(bomId: string, qty: number, options?: ExplosionOptions): Promise<CanProduceResult>;
197
+ /**
198
+ * Walk the bill for `qty` units and return every line, depth first, with
199
+ * its level, the path of bills above it and its quantity for the run, plus
200
+ * the rolled-up `totals`. Gross requirements: stock is not read.
201
+ *
202
+ * `levels` (default `1`) says how far to open sub-assemblies; see
203
+ * {@link ExplosionLevels}. Waste compounds: a sub-assembly line's quantity
204
+ * includes its own waste, and its bill's lines are multiplied by it.
205
+ *
206
+ * Throws {@link BomNotFoundError}, `BomStructureCycleError` when stored
207
+ * data already has a product containing itself, `BomExplosionLimitError`
208
+ * past the depth or line limits, and a plain `Error` for a bad `qty` or
209
+ * `levels`.
210
+ */
211
+ explode(bomId: string, qty: number, options?: ExplosionOptions): Promise<Explosion>;
212
+ /**
213
+ * Net the walk against stock: for each line, the available stock (all
214
+ * locations) not yet allocated to an earlier line and how much is short.
215
+ * A sub-assembly that is short and has an active bill is opened for the
216
+ * shortfall only, so its lines say what building that shortfall takes;
217
+ * one covered by stock is not opened. Lines that are short and cannot be
218
+ * opened are the `shortages`, each at its own level.
219
+ *
220
+ * These are facts, not a decision: the application decides whether a
221
+ * short sub-assembly is built or bought. Does not mutate stock.
222
+ *
223
+ * Throws as {@link explode} does.
224
+ */
225
+ planRequirements(bomId: string, qty: number, options?: ExplosionOptions): Promise<RequirementsPlan>;
162
226
  /**
163
227
  * Fetch a BOM by id or throw {@link BomNotFoundError}. Centralises the
164
228
  * "missing BOM" error path so callers don't have to repeat the check.
165
229
  */
230
+ /**
231
+ * A bill's lines: its own tenant's and global ones, whatever tenant
232
+ * context is active (a context alone would hide a global bill's lines).
233
+ */
234
+ private linesOf;
166
235
  private requireBom;
236
+ /**
237
+ * Available stock of a SKU across locations, counting only the top bill's
238
+ * tenant's rows and global ones, whatever tenant context is active (the
239
+ * walk reads its structure the same way).
240
+ */
241
+ private availableInTenant;
242
+ /** {@link computeMaterialCost} with `levels` above 1. */
243
+ private computeMultiLevelCost;
244
+ /** {@link computeLabourEstimate} with `levels` above 1. */
245
+ private computeMultiLevelLabour;
167
246
  /** Run the {@link OperationRateResolver}; `null` when there is no rate. */
168
247
  private resolveRate;
169
248
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"BomService.d.ts","sourceRoot":"","sources":["../../src/services/BomService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,KAAK,cAAc,EAAmB,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAEL,KAAK,YAAY,EAClB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,6CAA6C,CAAC;AACxF,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,yCAAyC,CAAC;AAEhF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,KAAK,EACV,cAAc,EACd,qBAAqB,EAEtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,KAAK,aAAa,EAGlB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EAEzB,MAAM,aAAa,CAAC;AAErB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,qBAAqB,GAAG,CAClC,cAAc,EAAE,MAAM,KACnB,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;AAEpE;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;;OAIG;IACH,YAAY,CAAC,EAAE,qBAAqB,CAAC;IACrC;;;;OAIG;IACH,YAAY,CAAC,EAAE,qBAAqB,CAAC;CACtC,GAAG,CACA;IAAE,EAAE,EAAE,cAAc,CAAC;IAAC,YAAY,CAAC,EAAE,YAAY,CA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AGG;IACH;;;OAGG;YACW,OAAO;YASP,UAAU;IAgBxB;;;;OAIG;YACW,iBAAiB;IAa/B,yDAAyD;YAC3C,qBAAqB;IA2DnC,2DAA2D;YAC7C,uBAAuB;IAkErC,2EAA2E;YAC7D,WAAW;IAUzB;;;;OAIG;YACW,WAAW;CAO1B;AAkFD;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,UAAU,CAAC,CAErB;AAID,YAAY,EAAE,OAAO,EAAE,CAAC"}
@@ -0,0 +1,123 @@
1
+ /**
2
+ * ProductionRunService — create production runs and report work on them as
3
+ * it happens: "25 to build, 12 done".
4
+ *
5
+ * Every write runs in one database transaction that first saves the run
6
+ * row. That save is revision-guarded, so it takes the row's lock and a
7
+ * concurrent writer's save fails with a revision conflict; the loser's whole
8
+ * transaction is retried against the committed run. Two people reporting
9
+ * completions at once therefore both count, and a run never goes past its
10
+ * target.
11
+ *
12
+ * Recording a completion moves no stock unless the caller asks. With
13
+ * `consume` and/or `produce`, it uses the {@link ProductionService} paths
14
+ * inside the same transaction as the completion, so a stock shortfall rolls
15
+ * the completion back too.
16
+ *
17
+ * @packageDocumentation
18
+ */
19
+ import { type DatabaseConfig } from '@happyvertical/smrt-core';
20
+ import { type StockService } from '@happyvertical/smrt-inventory';
21
+ import { BillOfMaterialsCollection } from '../collections/BillOfMaterialsCollection.js';
22
+ import { ProductionRunCollection } from '../collections/ProductionRunCollection.js';
23
+ import { ProductionRunCompletionCollection } from '../collections/ProductionRunCompletionCollection.js';
24
+ import type { ProductionRun } from '../models/ProductionRun.js';
25
+ import type { ProductionRunCompletion } from '../models/ProductionRunCompletion.js';
26
+ import { type CreateProductionRunInput, type RecordCompletionInput, type RecordCompletionResult } from '../production-run-types.js';
27
+ /**
28
+ * Options accepted by {@link ProductionRunService.create}. With a
29
+ * `stockService`, its database is used for everything, so a completion and
30
+ * its stock movements share one transaction.
31
+ */
32
+ export type ProductionRunServiceOptions = {
33
+ db: DatabaseConfig;
34
+ stockService?: undefined;
35
+ } | {
36
+ stockService: StockService;
37
+ db?: undefined;
38
+ };
39
+ /**
40
+ * Creates runs and records their progress. Construct with
41
+ * {@link ProductionRunService.create} or {@link createProductionRunService}.
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * const runs = await ProductionRunService.create({ db });
46
+ * const run = await runs.createRun({ productId: frame.id, targetQty: 25 });
47
+ * await runs.recordCompletion(run.id!, { qty: 12 });
48
+ * // run: 25 to build, 12 done, in_progress
49
+ * ```
50
+ */
51
+ export declare class ProductionRunService {
52
+ /** The stock service whose database every collection here shares. */
53
+ readonly stockService: StockService;
54
+ /** Production runs (reads; writes go through this service). */
55
+ readonly runs: ProductionRunCollection;
56
+ /** Completions (reads; writes go through this service). */
57
+ readonly completions: ProductionRunCompletionCollection;
58
+ /** Bills, to pin a run's bill. */
59
+ readonly boms: BillOfMaterialsCollection;
60
+ private constructor();
61
+ /** Factory — prefer {@link createProductionRunService}. */
62
+ static create(options: ProductionRunServiceOptions): Promise<ProductionRunService>;
63
+ /**
64
+ * Create a `planned` run of `targetQty` units, pinned to `bomId`, or to the
65
+ * active bill of `productId`.
66
+ *
67
+ * @throws {InvalidProductionRunInputError} for a target that is not a
68
+ * positive number, or when neither `bomId` nor `productId` is given.
69
+ * @throws {BomNotFoundError} when `bomId` does not exist.
70
+ * @throws {NoActiveBomForProductError} when `productId` has no active bill.
71
+ */
72
+ createRun(input: CreateProductionRunInput): Promise<ProductionRun>;
73
+ /** The run, or `null` when no run has this id. */
74
+ get(runId: string): Promise<ProductionRun | null>;
75
+ /** A run's completions in the order they happened. */
76
+ listCompletions(runId: string): Promise<ProductionRunCompletion[]>;
77
+ /** Mark a `planned` run `in_progress`. */
78
+ start(runId: string): Promise<ProductionRun>;
79
+ /** Mark an open run `done`, short of its target if work stopped early. */
80
+ finish(runId: string): Promise<ProductionRun>;
81
+ /** Cancel an open run. Completions already reported stay. */
82
+ cancel(runId: string): Promise<ProductionRun>;
83
+ /**
84
+ * Change an open run's target. It may not go below what is already done;
85
+ * setting it to exactly that finishes the run.
86
+ *
87
+ * @throws {InvalidProductionRunInputError} for a target that is not a
88
+ * positive number or is below the completed quantity.
89
+ */
90
+ setTarget(runId: string, targetQty: number): Promise<ProductionRun>;
91
+ /**
92
+ * Report `qty` finished units on an open run: records a dated completion,
93
+ * adds it to `completedQty`, moves a `planned` run to `in_progress`, and
94
+ * marks the run `done` when the target is reached. With `consume` and/or
95
+ * `produce`, also writes the stock movements through
96
+ * {@link ProductionService}, stamped `sourceType: 'ProductionRunCompletion'`
97
+ * with the completion id. Everything runs in one transaction.
98
+ *
99
+ * Consumption takes the run's bill's own lines for `qty` units: a
100
+ * sub-assembly on the bill is taken from stock as a component. Building
101
+ * that sub-assembly is its own run.
102
+ *
103
+ * @throws {ProductionRunNotFoundError}
104
+ * @throws {ProductionRunStateError} when the run is `done` or `cancelled`.
105
+ * @throws {ProductionRunOverCompletionError} when `qty` is more than the
106
+ * run has left.
107
+ * @throws {InvalidProductionRunInputError} for a bad `qty` or date.
108
+ * @throws `InsufficientStockError` from inventory when consuming would
109
+ * drive stock below zero; nothing is recorded then.
110
+ */
111
+ recordCompletion(runId: string, input: RecordCompletionInput): Promise<RecordCompletionResult>;
112
+ /** Apply `apply` to an open run and save it, in one transaction. */
113
+ private change;
114
+ private load;
115
+ /**
116
+ * Run `work` in one transaction on collections bound to it, rerunning the
117
+ * whole transaction when it lost a revision race on the run row.
118
+ */
119
+ private inTransaction;
120
+ }
121
+ /** Convenience factory for {@link ProductionRunService}. */
122
+ export declare function createProductionRunService(options: ProductionRunServiceOptions): Promise<ProductionRunService>;
123
+ //# sourceMappingURL=ProductionRunService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProductionRunService.d.ts","sourceRoot":"","sources":["../../src/services/ProductionRunService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,KAAK,cAAc,EAAmB,MAAM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