@operato/ops-contract 0.9.42 → 0.9.44
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.
- package/README.md +33 -0
- package/dist/actuation.d.ts +1 -0
- package/dist/capability.d.ts +6 -1
- package/dist/capability.js +0 -13
- package/dist/capacity.d.ts +0 -7
- package/dist/capacity.js +6 -123
- package/dist/contract.d.ts +40 -13
- package/dist/contract.js +37 -0
- package/dist/dock-facts.d.ts +73 -0
- package/dist/dock-facts.js +134 -0
- package/dist/domain-definition.d.ts +1 -1
- package/dist/domain-definition.js +2 -2
- package/dist/ems-profile.d.ts +1 -2
- package/dist/ems-profile.js +19 -8
- package/dist/epcis.d.ts +47 -7
- package/dist/epcis.js +56 -3
- package/dist/erp.d.ts +4 -4
- package/dist/gs1.d.ts +27 -0
- package/dist/gs1.js +86 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/material-move.d.ts +124 -0
- package/dist/material-move.js +229 -0
- package/dist/mes-profile.js +1 -1
- package/dist/oee.js +8 -4
- package/dist/operational-attention.d.ts +27 -0
- package/dist/operational-attention.js +95 -15
- package/dist/operational-ingest.js +5 -6
- package/dist/operations-capability.d.ts +1 -8
- package/dist/operations-capability.js +0 -99
- package/dist/order-fold.d.ts +0 -30
- package/dist/order-fold.js +0 -75
- package/dist/party.d.ts +70 -0
- package/dist/party.js +131 -0
- package/dist/records-of-event.d.ts +74 -0
- package/dist/records-of-event.js +129 -0
- package/dist/yield.d.ts +1 -1
- package/dist/yms-profile.d.ts +82 -0
- package/dist/yms-profile.js +88 -0
- package/dist-cjs/index.cjs +705 -208
- package/package.json +12 -3
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
export declare const MOVE_KIND: {
|
|
2
|
+
/** warehouse → plant: a pick for a production order put this container at the line. */
|
|
3
|
+
readonly issue: "issue";
|
|
4
|
+
/** warehouse → plant: the issue was taken back - what was still on the way came back (ADR-0143 decision 5). */
|
|
5
|
+
readonly issueCancel: "issue-cancel";
|
|
6
|
+
/** plant → warehouse: the line took this much of an issue. */
|
|
7
|
+
readonly receipt: "receipt";
|
|
8
|
+
/** plant → warehouse: what is left at the line goes back (decision 3). */
|
|
9
|
+
readonly return: "return";
|
|
10
|
+
/** plant → warehouse: finished goods leave the line for the warehouse (decision 4). */
|
|
11
|
+
readonly handover: "handover";
|
|
12
|
+
/** warehouse → plant: this much of a return arrived. */
|
|
13
|
+
readonly returnReceived: "return-received";
|
|
14
|
+
/** warehouse → plant: this much of a handover arrived. */
|
|
15
|
+
readonly handoverReceived: "handover-received";
|
|
16
|
+
/** site → site: a transfer left for the peer site, one lot (ADR-0154 decision 1). */
|
|
17
|
+
readonly transfer: "transfer";
|
|
18
|
+
/** site → site: this much of a transfer arrived at the peer site. */
|
|
19
|
+
readonly transferReceived: "transfer-received";
|
|
20
|
+
};
|
|
21
|
+
export type MoveKind = (typeof MOVE_KIND)[keyof typeof MOVE_KIND];
|
|
22
|
+
export type DispatchMoveKind = typeof MOVE_KIND.return | typeof MOVE_KIND.handover | typeof MOVE_KIND.transfer;
|
|
23
|
+
export type ReceivedMoveKind = typeof MOVE_KIND.returnReceived | typeof MOVE_KIND.handoverReceived | typeof MOVE_KIND.transferReceived;
|
|
24
|
+
/** What the receiver sends back when goods a peer sent arrive, by the kind the peer sent. */
|
|
25
|
+
export declare const RECEIVED_MOVE_KIND: {
|
|
26
|
+
readonly return: "return-received";
|
|
27
|
+
readonly handover: "handover-received";
|
|
28
|
+
readonly transfer: "transfer-received";
|
|
29
|
+
};
|
|
30
|
+
/** An issue pick done - the container stands at the line place, `in_progress`. Quantities are in the sender's unit (decision 6). */
|
|
31
|
+
export interface IssueMoveFact {
|
|
32
|
+
moveId: string;
|
|
33
|
+
kind: typeof MOVE_KIND.issue;
|
|
34
|
+
/** The production order it serves - the order's document number. */
|
|
35
|
+
order: string;
|
|
36
|
+
/** The container at the line. */
|
|
37
|
+
unit: string;
|
|
38
|
+
/** The lot, as the contract spells it (`lotClassUri`). */
|
|
39
|
+
lotClass: string;
|
|
40
|
+
quantity: number;
|
|
41
|
+
uom?: string;
|
|
42
|
+
/** The line place it was put at. */
|
|
43
|
+
to: string;
|
|
44
|
+
/** The expiry the unit arrived with: a date (YYYY-MM-DD) when it was said as one, else an instant. */
|
|
45
|
+
expiry?: string;
|
|
46
|
+
/** The supplier's lot number, when the receipt said it. */
|
|
47
|
+
supplierLot?: string;
|
|
48
|
+
}
|
|
49
|
+
/** The warehouse took an issue back: which issue, how much came back (what the line had not received - may be 0). */
|
|
50
|
+
export interface IssueCancelMoveFact {
|
|
51
|
+
moveId: string;
|
|
52
|
+
kind: typeof MOVE_KIND.issueCancel;
|
|
53
|
+
issue: string;
|
|
54
|
+
quantity: number;
|
|
55
|
+
uom?: string;
|
|
56
|
+
}
|
|
57
|
+
/** The line took (part of) an issue. */
|
|
58
|
+
export interface ReceiptMoveFact {
|
|
59
|
+
moveId: string;
|
|
60
|
+
kind: typeof MOVE_KIND.receipt;
|
|
61
|
+
/** The issue it takes from - the warehouse's own `moveId`. */
|
|
62
|
+
issue: string;
|
|
63
|
+
quantity: number;
|
|
64
|
+
uom?: string;
|
|
65
|
+
}
|
|
66
|
+
/** Goods sent to a peer: the plant's return or handover, or a site's transfer - one lot each. */
|
|
67
|
+
export interface DispatchMoveFact {
|
|
68
|
+
moveId: string;
|
|
69
|
+
kind: DispatchMoveKind;
|
|
70
|
+
lotClass: string;
|
|
71
|
+
quantity: number;
|
|
72
|
+
uom?: string;
|
|
73
|
+
/** The place it leaves: the plant's line place, or the sending site's ship place. */
|
|
74
|
+
from: string;
|
|
75
|
+
/** For a handover: the job order that made it. For a transfer: the sending site's order. */
|
|
76
|
+
order?: string;
|
|
77
|
+
/** The lot's expiry as the sender knows it - FEFO reads it. */
|
|
78
|
+
expiry?: string;
|
|
79
|
+
/** For a transfer: the logistic units that left. */
|
|
80
|
+
units?: string[];
|
|
81
|
+
}
|
|
82
|
+
/** (Part of) what a peer sent arrived - may be 0: "nothing came" is a statement too. */
|
|
83
|
+
export interface ReceivedMoveFact {
|
|
84
|
+
moveId: string;
|
|
85
|
+
kind: ReceivedMoveKind;
|
|
86
|
+
/** The sender's id for the return, handover or transfer. */
|
|
87
|
+
dispatch: string;
|
|
88
|
+
quantity: number;
|
|
89
|
+
uom?: string;
|
|
90
|
+
}
|
|
91
|
+
export type MoveFact = IssueMoveFact | IssueCancelMoveFact | ReceiptMoveFact | DispatchMoveFact | ReceivedMoveFact;
|
|
92
|
+
/** Is this an expiry a fact may carry: a date (YYYY-MM-DD) or an instant with its offset. */
|
|
93
|
+
export declare function isMoveExpiry(value: unknown): value is string;
|
|
94
|
+
/**
|
|
95
|
+
* An expiry as a fact carries it. Text is kept as it was said - a date stays a date, an instant an instant (nothing is
|
|
96
|
+
* guessed from text). A stored `Date` (a date column comes back as midnight UTC) is folded to a date when it sits on
|
|
97
|
+
* midnight UTC - the only case where a guess is needed.
|
|
98
|
+
*/
|
|
99
|
+
export declare function moveExpiryText(expiry: Date | string | null | undefined): string | undefined;
|
|
100
|
+
/** Whether a record on a stream is a move (the plant's stream for the warehouse also carries lot statuses). */
|
|
101
|
+
export declare function isMoveRecord(record: unknown): boolean;
|
|
102
|
+
/**
|
|
103
|
+
* **Read one record as a move fact, or say why not.** Every kind is read by the same rules wherever it lands; the receiver
|
|
104
|
+
* then takes the kinds it takes (`takes`) and refuses the rest by name.
|
|
105
|
+
*/
|
|
106
|
+
export declare function moveFactOf(record: unknown, takes?: readonly MoveKind[]): {
|
|
107
|
+
fact: MoveFact;
|
|
108
|
+
} | {
|
|
109
|
+
errors: string[];
|
|
110
|
+
};
|
|
111
|
+
export declare function issueMoveFactOf(input: Omit<IssueMoveFact, 'kind'>): IssueMoveFact;
|
|
112
|
+
export declare function issueCancelMoveFactOf(input: Omit<IssueCancelMoveFact, 'kind'>): IssueCancelMoveFact;
|
|
113
|
+
export declare function receiptMoveFactOf(input: Omit<ReceiptMoveFact, 'kind'>): ReceiptMoveFact;
|
|
114
|
+
export declare function dispatchMoveFactOf(input: Omit<DispatchMoveFact, 'expiry'> & {
|
|
115
|
+
expiry?: Date | string | null;
|
|
116
|
+
}): DispatchMoveFact;
|
|
117
|
+
/** What the receiver sends when goods arrive: which dispatch, how much - the kind follows the kind that was sent. */
|
|
118
|
+
export declare function receivedMoveFactOf(input: {
|
|
119
|
+
moveId: string;
|
|
120
|
+
sent: DispatchMoveKind;
|
|
121
|
+
dispatch: string;
|
|
122
|
+
quantity: number;
|
|
123
|
+
uom?: string;
|
|
124
|
+
}): ReceivedMoveFact;
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { isIsoDateTime, parseEpc } from "./epcis.js";
|
|
2
|
+
/*
|
|
3
|
+
* **Material moves between sites, the warehouse and the line** - the records both sides send and read (ADR-0143, ADR-0154).
|
|
4
|
+
*
|
|
5
|
+
* One physical move has one owner (ADR-0059 decision 5): the warehouse says it issued, the plant says it received. Each side
|
|
6
|
+
* sends its own fact on its own stream; each fact carries an id unique within its sender (`moveId`). What a receiver does with
|
|
7
|
+
* a repeat is the receiver's (the products take one per site, peer and `moveId` - README "계약이 정하는 것").
|
|
8
|
+
*
|
|
9
|
+
* Lifted on 2026-11-19 from the warehouse and the plant, which kept a copy each (`move-facts.ts`) and had drifted: the plant's
|
|
10
|
+
* reader took an arrival of 0 and the warehouse's refused it, only the plant checked an issue's lot. One reader here
|
|
11
|
+
* (ADR-0210 decision 12, the user). What stays with each product: its own statuses (the plant's issue · dispatch status), its
|
|
12
|
+
* quantity judgements (a receipt over what was issued, what a line still holds), how it numbers a transfer.
|
|
13
|
+
*
|
|
14
|
+
* Closed on purpose: an unknown kind is refused, not stored - a word the receiver does not know cannot move its stock.
|
|
15
|
+
*/
|
|
16
|
+
export const MOVE_KIND = {
|
|
17
|
+
/** warehouse → plant: a pick for a production order put this container at the line. */
|
|
18
|
+
issue: 'issue',
|
|
19
|
+
/** warehouse → plant: the issue was taken back - what was still on the way came back (ADR-0143 decision 5). */
|
|
20
|
+
issueCancel: 'issue-cancel',
|
|
21
|
+
/** plant → warehouse: the line took this much of an issue. */
|
|
22
|
+
receipt: 'receipt',
|
|
23
|
+
/** plant → warehouse: what is left at the line goes back (decision 3). */
|
|
24
|
+
return: 'return',
|
|
25
|
+
/** plant → warehouse: finished goods leave the line for the warehouse (decision 4). */
|
|
26
|
+
handover: 'handover',
|
|
27
|
+
/** warehouse → plant: this much of a return arrived. */
|
|
28
|
+
returnReceived: 'return-received',
|
|
29
|
+
/** warehouse → plant: this much of a handover arrived. */
|
|
30
|
+
handoverReceived: 'handover-received',
|
|
31
|
+
/** site → site: a transfer left for the peer site, one lot (ADR-0154 decision 1). */
|
|
32
|
+
transfer: 'transfer',
|
|
33
|
+
/** site → site: this much of a transfer arrived at the peer site. */
|
|
34
|
+
transferReceived: 'transfer-received'
|
|
35
|
+
};
|
|
36
|
+
/** What the receiver sends back when goods a peer sent arrive, by the kind the peer sent. */
|
|
37
|
+
export const RECEIVED_MOVE_KIND = {
|
|
38
|
+
[MOVE_KIND.return]: MOVE_KIND.returnReceived,
|
|
39
|
+
[MOVE_KIND.handover]: MOVE_KIND.handoverReceived,
|
|
40
|
+
[MOVE_KIND.transfer]: MOVE_KIND.transferReceived
|
|
41
|
+
};
|
|
42
|
+
const DAY_MS = 86_400_000;
|
|
43
|
+
const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
44
|
+
/** Is this an expiry a fact may carry: a date (YYYY-MM-DD) or an instant with its offset. */
|
|
45
|
+
export function isMoveExpiry(value) {
|
|
46
|
+
return typeof value === 'string' && ((DATE_RE.test(value) && !Number.isNaN(Date.parse(value))) || isIsoDateTime(value));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* An expiry as a fact carries it. Text is kept as it was said - a date stays a date, an instant an instant (nothing is
|
|
50
|
+
* guessed from text). A stored `Date` (a date column comes back as midnight UTC) is folded to a date when it sits on
|
|
51
|
+
* midnight UTC - the only case where a guess is needed.
|
|
52
|
+
*/
|
|
53
|
+
export function moveExpiryText(expiry) {
|
|
54
|
+
if (!expiry)
|
|
55
|
+
return undefined;
|
|
56
|
+
if (typeof expiry === 'string')
|
|
57
|
+
return isMoveExpiry(expiry) ? expiry : undefined;
|
|
58
|
+
if (Number.isNaN(expiry.getTime()))
|
|
59
|
+
return undefined;
|
|
60
|
+
return expiry.getTime() % DAY_MS === 0 ? expiry.toISOString().slice(0, 10) : expiry.toISOString();
|
|
61
|
+
}
|
|
62
|
+
/** Whether a record on a stream is a move (the plant's stream for the warehouse also carries lot statuses). */
|
|
63
|
+
export function isMoveRecord(record) {
|
|
64
|
+
const r = record;
|
|
65
|
+
return !!r && typeof r === 'object' && typeof r.moveId === 'string' && typeof r.kind === 'string';
|
|
66
|
+
}
|
|
67
|
+
/** Does this class name a lot - an LGTIN or an in-house class with a lot part. */
|
|
68
|
+
function namesALot(lotClass) {
|
|
69
|
+
try {
|
|
70
|
+
return !!parseEpc(lotClass)?.lot;
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* **Read one record as a move fact, or say why not.** Every kind is read by the same rules wherever it lands; the receiver
|
|
78
|
+
* then takes the kinds it takes (`takes`) and refuses the rest by name.
|
|
79
|
+
*/
|
|
80
|
+
export function moveFactOf(record, takes) {
|
|
81
|
+
const r = record;
|
|
82
|
+
if (!isMoveRecord(r))
|
|
83
|
+
return { errors: ['the record is not a move: moveId and kind are needed'] };
|
|
84
|
+
const kind = r.kind;
|
|
85
|
+
if (!Object.values(MOVE_KIND).includes(kind))
|
|
86
|
+
return { errors: [`${kind} is not a move kind`] };
|
|
87
|
+
if (takes && !takes.includes(kind))
|
|
88
|
+
return { errors: [`a move of kind ${kind} is not one this receiver takes`] };
|
|
89
|
+
const errors = [];
|
|
90
|
+
const text = (key) => typeof r[key] === 'string' && r[key].trim() !== '';
|
|
91
|
+
const trimmed = (key) => r[key].trim();
|
|
92
|
+
const quantity = (atLeast) => {
|
|
93
|
+
const q = r.quantity;
|
|
94
|
+
const ok = typeof q === 'number' && Number.isFinite(q) && (atLeast === 'above-zero' ? q > 0 : q >= 0);
|
|
95
|
+
if (!ok)
|
|
96
|
+
errors.push(atLeast === 'above-zero' ? 'quantity must be a number above 0' : 'quantity must be a number, 0 or above');
|
|
97
|
+
};
|
|
98
|
+
const uom = () => (typeof r.uom === 'string' && r.uom.trim() ? { uom: r.uom.trim() } : {});
|
|
99
|
+
if (!text('moveId'))
|
|
100
|
+
errors.push('moveId is empty');
|
|
101
|
+
if (r.uom !== undefined && typeof r.uom !== 'string')
|
|
102
|
+
errors.push('uom must be text');
|
|
103
|
+
switch (kind) {
|
|
104
|
+
case MOVE_KIND.issue: {
|
|
105
|
+
if (!text('order'))
|
|
106
|
+
errors.push('order is missing: an issue names the production order it serves');
|
|
107
|
+
if (!text('unit'))
|
|
108
|
+
errors.push('unit is missing: an issue names the container at the line');
|
|
109
|
+
if (!text('lotClass'))
|
|
110
|
+
errors.push('lotClass is missing');
|
|
111
|
+
else if (!namesALot(trimmed('lotClass')))
|
|
112
|
+
errors.push(`${r.lotClass} does not name a lot`);
|
|
113
|
+
if (!text('to'))
|
|
114
|
+
errors.push('to is missing: an issue names the line place');
|
|
115
|
+
if (r.expiry !== undefined && !isMoveExpiry(r.expiry))
|
|
116
|
+
errors.push('expiry is not a date (YYYY-MM-DD) or an instant with its offset');
|
|
117
|
+
quantity('above-zero');
|
|
118
|
+
if (errors.length)
|
|
119
|
+
return { errors };
|
|
120
|
+
return {
|
|
121
|
+
fact: {
|
|
122
|
+
moveId: trimmed('moveId'),
|
|
123
|
+
kind: MOVE_KIND.issue,
|
|
124
|
+
order: trimmed('order'),
|
|
125
|
+
unit: trimmed('unit'),
|
|
126
|
+
lotClass: trimmed('lotClass'),
|
|
127
|
+
quantity: r.quantity,
|
|
128
|
+
...uom(),
|
|
129
|
+
to: trimmed('to'),
|
|
130
|
+
...(typeof r.expiry === 'string' ? { expiry: r.expiry } : {}),
|
|
131
|
+
...(text('supplierLot') ? { supplierLot: trimmed('supplierLot') } : {})
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
case MOVE_KIND.issueCancel:
|
|
136
|
+
case MOVE_KIND.receipt: {
|
|
137
|
+
if (!text('issue'))
|
|
138
|
+
errors.push(`issue is missing: ${kind === MOVE_KIND.receipt ? 'a receipt names the issue it takes from' : 'a cancel names the issue it takes back'}`);
|
|
139
|
+
quantity(kind === MOVE_KIND.receipt ? 'above-zero' : 'zero-or-more');
|
|
140
|
+
if (errors.length)
|
|
141
|
+
return { errors };
|
|
142
|
+
return { fact: { moveId: trimmed('moveId'), kind, issue: trimmed('issue'), quantity: r.quantity, ...uom() } };
|
|
143
|
+
}
|
|
144
|
+
case MOVE_KIND.return:
|
|
145
|
+
case MOVE_KIND.handover:
|
|
146
|
+
case MOVE_KIND.transfer: {
|
|
147
|
+
if (!text('lotClass'))
|
|
148
|
+
errors.push('lotClass is missing');
|
|
149
|
+
/*
|
|
150
|
+
* A return or a handover is one lot of the plant's - it must name one. A transfer is not checked here: a site transfers
|
|
151
|
+
* what its units are classed by, and a class without a lot part is a fact the sending site may truly have.
|
|
152
|
+
*/ else if (kind !== MOVE_KIND.transfer && !namesALot(trimmed('lotClass')))
|
|
153
|
+
errors.push(`${r.lotClass} does not name a lot`);
|
|
154
|
+
if (!text('from'))
|
|
155
|
+
errors.push('from is missing: the place it leaves');
|
|
156
|
+
if (r.order !== undefined && !text('order'))
|
|
157
|
+
errors.push('order must be text');
|
|
158
|
+
if (r.expiry !== undefined && !isMoveExpiry(r.expiry))
|
|
159
|
+
errors.push('expiry is not a date (YYYY-MM-DD) or an instant with its offset');
|
|
160
|
+
if (r.units !== undefined && (!Array.isArray(r.units) || !r.units.length || !r.units.every(unit => typeof unit === 'string' && unit.trim()))) {
|
|
161
|
+
errors.push('units must be a list of unit identifiers');
|
|
162
|
+
}
|
|
163
|
+
quantity('above-zero');
|
|
164
|
+
if (errors.length)
|
|
165
|
+
return { errors };
|
|
166
|
+
return {
|
|
167
|
+
fact: {
|
|
168
|
+
moveId: trimmed('moveId'),
|
|
169
|
+
kind,
|
|
170
|
+
lotClass: trimmed('lotClass'),
|
|
171
|
+
quantity: r.quantity,
|
|
172
|
+
...uom(),
|
|
173
|
+
from: trimmed('from'),
|
|
174
|
+
...(text('order') ? { order: trimmed('order') } : {}),
|
|
175
|
+
...(typeof r.expiry === 'string' ? { expiry: r.expiry } : {}),
|
|
176
|
+
...(Array.isArray(r.units) ? { units: r.units.map(unit => unit.trim()) } : {})
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
default: {
|
|
181
|
+
/* the three received kinds */
|
|
182
|
+
if (!text('dispatch'))
|
|
183
|
+
errors.push('dispatch is missing: it names what was sent');
|
|
184
|
+
quantity('zero-or-more');
|
|
185
|
+
if (errors.length)
|
|
186
|
+
return { errors };
|
|
187
|
+
return { fact: { moveId: trimmed('moveId'), kind: kind, dispatch: trimmed('dispatch'), quantity: r.quantity, ...uom() } };
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/* ── Builders - what a sender writes. Optional fields are left out when empty, never sent as empty. ── */
|
|
192
|
+
export function issueMoveFactOf(input) {
|
|
193
|
+
return {
|
|
194
|
+
moveId: input.moveId,
|
|
195
|
+
kind: MOVE_KIND.issue,
|
|
196
|
+
order: input.order,
|
|
197
|
+
unit: input.unit,
|
|
198
|
+
lotClass: input.lotClass,
|
|
199
|
+
quantity: input.quantity,
|
|
200
|
+
...(input.uom ? { uom: input.uom } : {}),
|
|
201
|
+
to: input.to,
|
|
202
|
+
...(input.expiry ? { expiry: input.expiry } : {}),
|
|
203
|
+
...(input.supplierLot ? { supplierLot: input.supplierLot } : {})
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
export function issueCancelMoveFactOf(input) {
|
|
207
|
+
return { moveId: input.moveId, kind: MOVE_KIND.issueCancel, issue: input.issue, quantity: input.quantity, ...(input.uom ? { uom: input.uom } : {}) };
|
|
208
|
+
}
|
|
209
|
+
export function receiptMoveFactOf(input) {
|
|
210
|
+
return { moveId: input.moveId, kind: MOVE_KIND.receipt, issue: input.issue, quantity: input.quantity, ...(input.uom ? { uom: input.uom } : {}) };
|
|
211
|
+
}
|
|
212
|
+
export function dispatchMoveFactOf(input) {
|
|
213
|
+
const expiry = moveExpiryText(input.expiry);
|
|
214
|
+
return {
|
|
215
|
+
moveId: input.moveId,
|
|
216
|
+
kind: input.kind,
|
|
217
|
+
lotClass: input.lotClass,
|
|
218
|
+
quantity: input.quantity,
|
|
219
|
+
...(input.uom ? { uom: input.uom } : {}),
|
|
220
|
+
from: input.from,
|
|
221
|
+
...(input.order ? { order: input.order } : {}),
|
|
222
|
+
...(expiry ? { expiry } : {}),
|
|
223
|
+
...(input.units?.length ? { units: input.units } : {})
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
/** What the receiver sends when goods arrive: which dispatch, how much - the kind follows the kind that was sent. */
|
|
227
|
+
export function receivedMoveFactOf(input) {
|
|
228
|
+
return { moveId: input.moveId, kind: RECEIVED_MOVE_KIND[input.sent], dispatch: input.dispatch, quantity: input.quantity, ...(input.uom ? { uom: input.uom } : {}) };
|
|
229
|
+
}
|
package/dist/mes-profile.js
CHANGED
|
@@ -69,7 +69,7 @@ export const MES_TYPES = [
|
|
|
69
69
|
export const MES_COMMANDS = [
|
|
70
70
|
{
|
|
71
71
|
type: 'production.order',
|
|
72
|
-
label: '
|
|
72
|
+
label: 'twin.command.production.order',
|
|
73
73
|
/*
|
|
74
74
|
* 되돌릴 수 없다. 지시가 나가면 사람과 설비가 그것으로 움직이고, 취소해도 이미 만든 것은 남는다.
|
|
75
75
|
* 그래서 사람 승인을 지난다(§`requiresApproval`).
|
package/dist/oee.js
CHANGED
|
@@ -48,14 +48,18 @@ export function computeOee(c, nowMs) {
|
|
|
48
48
|
if (produced <= 0)
|
|
49
49
|
missing.push('produced-quantity');
|
|
50
50
|
const quality = produced > 0 ? c.goodCount / produced : undefined;
|
|
51
|
-
/*
|
|
51
|
+
/*
|
|
52
|
+
* 성능률 — 표준 시간이 없으면 내지 않는다. 실 생산 시간이 0 이어도 나눌 수 없다.
|
|
53
|
+
*
|
|
54
|
+
* 가동률과 같은 이유로 **1 로 자르지 않는다**(2026-11-19 내용 점검). 1 을 넘으면 표준 시간보다 빨리
|
|
55
|
+
* 만들었다는 사실이거나, 선언된 표준 시간이 틀렸다는 신호다. 자르면 둘 다 「표준대로」와 같아지고,
|
|
56
|
+
* `overall` 도 A×P×Q 의 정직한 곱이 아니게 된다.
|
|
57
|
+
*/
|
|
52
58
|
if (c.plannedRunTimePerItemMs == null)
|
|
53
59
|
missing.push('planned-run-time-per-item');
|
|
54
60
|
else if (c.runMs <= 0)
|
|
55
61
|
missing.push('actual-production-time');
|
|
56
|
-
const performance = c.plannedRunTimePerItemMs != null && c.runMs > 0
|
|
57
|
-
? Math.min(1, (c.plannedRunTimePerItemMs * produced) / c.runMs)
|
|
58
|
-
: undefined;
|
|
62
|
+
const performance = c.plannedRunTimePerItemMs != null && c.runMs > 0 ? (c.plannedRunTimePerItemMs * produced) / c.runMs : undefined;
|
|
59
63
|
const overall = availability != null && performance != null && quality != null ? availability * performance * quality : undefined;
|
|
60
64
|
return {
|
|
61
65
|
...(availability != null ? { availability } : {}),
|
|
@@ -39,5 +39,32 @@ export interface OperationalAttentionV1 {
|
|
|
39
39
|
/** At least one stable producer fact is mandatory; labels alone are not evidence. */
|
|
40
40
|
facts: OperationalFactReference[];
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* A producer-owned, namespaced reason code: `<product>.<code>`, lower case, words joined by `-`
|
|
44
|
+
* (`plant.job-order-past-due`, `yard.late`). The namespace keeps two products' codes from meaning one thing;
|
|
45
|
+
* which product name a sender uses is not checked here.
|
|
46
|
+
*/
|
|
47
|
+
export declare const OPERATIONAL_ATTENTION_KIND_PATTERN: RegExp;
|
|
48
|
+
/**
|
|
49
|
+
* Why a value is not an operational.attention.v1 - one line per field, empty when it is one.
|
|
50
|
+
* A receiver keeps these lines with the rejected record, so the sender learns which field to fix.
|
|
51
|
+
*/
|
|
52
|
+
export declare function operationalAttentionErrors(value: unknown): string[];
|
|
42
53
|
export declare function isOperationalAttentionV1(value: unknown): value is OperationalAttentionV1;
|
|
43
54
|
export declare function assertOperationalAttentionV1(value: unknown): asserts value is OperationalAttentionV1;
|
|
55
|
+
/**
|
|
56
|
+
* **The record a producer sends** for one step of an attention it keeps. Asserted before it leaves - a producer never
|
|
57
|
+
* sends what a consumer would reject.
|
|
58
|
+
*/
|
|
59
|
+
export declare function operationalAttentionOf(producer: {
|
|
60
|
+
system: string;
|
|
61
|
+
domainId: string;
|
|
62
|
+
}, attention: {
|
|
63
|
+
attentionId: string;
|
|
64
|
+
dedupeKey: string;
|
|
65
|
+
kind: string;
|
|
66
|
+
subjectLabel: string;
|
|
67
|
+
impact: OperationalAttentionImpact;
|
|
68
|
+
evidenceFingerprint: string;
|
|
69
|
+
facts: readonly Omit<OperationalFactReference, 'system'>[];
|
|
70
|
+
}, transition: OperationalAttentionTransition, observedAt: ISOTime): OperationalAttentionV1;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isIsoDateTime } from "./epcis.js";
|
|
1
2
|
/**
|
|
2
3
|
* Product-neutral evidence for an operational concern that another product's
|
|
3
4
|
* Twin/AI may analyse. It is not an alarm protocol and never authorises work.
|
|
@@ -9,27 +10,106 @@
|
|
|
9
10
|
export const OPERATIONAL_ATTENTION_CONTRACT = 'operational.attention.v1';
|
|
10
11
|
export const OPERATIONAL_ATTENTION_TRANSITIONS = ['opened', 'changed', 'resolved', 'reopened'];
|
|
11
12
|
export const OPERATIONAL_ATTENTION_IMPACTS = ['medium', 'high'];
|
|
12
|
-
|
|
13
|
+
/**
|
|
14
|
+
* A producer-owned, namespaced reason code: `<product>.<code>`, lower case, words joined by `-`
|
|
15
|
+
* (`plant.job-order-past-due`, `yard.late`). The namespace keeps two products' codes from meaning one thing;
|
|
16
|
+
* which product name a sender uses is not checked here.
|
|
17
|
+
*/
|
|
18
|
+
export const OPERATIONAL_ATTENTION_KIND_PATTERN = /^[a-z][a-z0-9-]*(\.[a-z0-9][a-z0-9-]*)+$/;
|
|
19
|
+
/**
|
|
20
|
+
* Why a value is not an operational.attention.v1 - one line per field, empty when it is one.
|
|
21
|
+
* A receiver keeps these lines with the rejected record, so the sender learns which field to fix.
|
|
22
|
+
*/
|
|
23
|
+
export function operationalAttentionErrors(value) {
|
|
13
24
|
const one = value;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
if (!one || typeof one !== 'object')
|
|
26
|
+
return ['record: not an object'];
|
|
27
|
+
const errors = [];
|
|
28
|
+
if (one.contract !== OPERATIONAL_ATTENTION_CONTRACT)
|
|
29
|
+
errors.push(`contract: must be ${OPERATIONAL_ATTENTION_CONTRACT}`);
|
|
30
|
+
for (const field of ['domainId', 'attentionId', 'dedupeKey', 'subjectLabel', 'evidenceFingerprint']) {
|
|
31
|
+
if (!nonEmpty(one[field]))
|
|
32
|
+
errors.push(`${field}: required`);
|
|
33
|
+
}
|
|
34
|
+
if (!nonEmpty(one.kind))
|
|
35
|
+
errors.push('kind: required');
|
|
36
|
+
else if (!OPERATIONAL_ATTENTION_KIND_PATTERN.test(one.kind))
|
|
37
|
+
errors.push('kind: must be <product>.<code> in lower case');
|
|
38
|
+
if (!isIsoDateTime(one.observedAt))
|
|
39
|
+
errors.push('observedAt: must be ISO 8601 with seconds and Z or an offset');
|
|
40
|
+
if (!OPERATIONAL_ATTENTION_TRANSITIONS.includes(one.transition)) {
|
|
41
|
+
errors.push(`transition: must be one of ${OPERATIONAL_ATTENTION_TRANSITIONS.join('|')}`);
|
|
42
|
+
}
|
|
43
|
+
if (!OPERATIONAL_ATTENTION_IMPACTS.includes(one.impact)) {
|
|
44
|
+
errors.push(`impact: must be one of ${OPERATIONAL_ATTENTION_IMPACTS.join('|')}`);
|
|
45
|
+
}
|
|
46
|
+
if (!Array.isArray(one.facts) || one.facts.length === 0) {
|
|
47
|
+
errors.push('facts: stable source-fact references are required (at least one {system,type,id})');
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
one.facts.forEach((fact, i) => {
|
|
51
|
+
for (const reason of factReferenceErrors(fact))
|
|
52
|
+
errors.push(`facts[${i}].${reason}`);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return errors;
|
|
56
|
+
}
|
|
57
|
+
export function isOperationalAttentionV1(value) {
|
|
58
|
+
return operationalAttentionErrors(value).length === 0;
|
|
21
59
|
}
|
|
22
60
|
export function assertOperationalAttentionV1(value) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
61
|
+
const errors = operationalAttentionErrors(value);
|
|
62
|
+
if (errors.length)
|
|
63
|
+
throw new Error(`invalid operational.attention.v1: ${errors.join('; ')}`);
|
|
26
64
|
}
|
|
27
|
-
function
|
|
65
|
+
function factReferenceErrors(value) {
|
|
28
66
|
const one = value;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
67
|
+
if (!one || typeof one !== 'object')
|
|
68
|
+
return ['reference: not an object'];
|
|
69
|
+
const errors = [];
|
|
70
|
+
for (const field of ['system', 'type', 'id']) {
|
|
71
|
+
if (!nonEmpty(one[field]))
|
|
72
|
+
errors.push(`${field}: required (stable source-fact references are required)`);
|
|
73
|
+
}
|
|
74
|
+
if (one.observedAt !== undefined && !isIsoDateTime(one.observedAt)) {
|
|
75
|
+
errors.push('observedAt: must be ISO 8601 with seconds and Z or an offset');
|
|
76
|
+
}
|
|
77
|
+
if (one.label !== undefined && !nonEmpty(one.label))
|
|
78
|
+
errors.push('label: empty');
|
|
79
|
+
return errors;
|
|
32
80
|
}
|
|
33
81
|
function nonEmpty(value) {
|
|
34
82
|
return typeof value === 'string' && value.trim().length > 0;
|
|
35
83
|
}
|
|
84
|
+
/* ── The producer's record ────────────────────────────────────────────────────────────────────────────────────────
|
|
85
|
+
*
|
|
86
|
+
* What the contract holds of an attention: the record above, the meaning of its words, and what a consumer may rely on -
|
|
87
|
+
* · **one attention per dedupeKey** - its `attentionId` stays the same across every step; a thing that comes back after it
|
|
88
|
+
* resolved is `reopened`, not a new attention;
|
|
89
|
+
* · `evidenceFingerprint` is the same text for the same evidence rows - a consumer treats a repeat of
|
|
90
|
+
* (domain, source, instance, attention, fingerprint) as one.
|
|
91
|
+
* **How a producer decides its steps** (reconcile a scan against what it keeps, which kinds a scan may resolve, how the
|
|
92
|
+
* fingerprint is made) is the producer's policy - it lives with the producers, in `@things-factory/webhook`
|
|
93
|
+
* (`reconcileAttentions`, `attentionFingerprint`; moved there 2026-11-19, contract content review).
|
|
94
|
+
*/
|
|
95
|
+
/**
|
|
96
|
+
* **The record a producer sends** for one step of an attention it keeps. Asserted before it leaves - a producer never
|
|
97
|
+
* sends what a consumer would reject.
|
|
98
|
+
*/
|
|
99
|
+
export function operationalAttentionOf(producer, attention, transition, observedAt) {
|
|
100
|
+
const record = {
|
|
101
|
+
contract: OPERATIONAL_ATTENTION_CONTRACT,
|
|
102
|
+
domainId: producer.domainId,
|
|
103
|
+
attentionId: attention.attentionId,
|
|
104
|
+
dedupeKey: attention.dedupeKey,
|
|
105
|
+
kind: attention.kind,
|
|
106
|
+
subjectLabel: attention.subjectLabel,
|
|
107
|
+
transition,
|
|
108
|
+
impact: attention.impact,
|
|
109
|
+
observedAt,
|
|
110
|
+
evidenceFingerprint: attention.evidenceFingerprint,
|
|
111
|
+
facts: attention.facts.map(one => ({ system: producer.system, ...one }))
|
|
112
|
+
};
|
|
113
|
+
assertOperationalAttentionV1(record);
|
|
114
|
+
return record;
|
|
115
|
+
}
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
* 모르는 필드는 **조용히 버리지 않고 거부한다.** `taskID` 처럼 한 글자 틀린 이름은 통과시키면 영원히
|
|
35
35
|
* 보이지 않는 손실이 된다(이 문에는 아직 옛 발신자가 없어 호환 부담도 없다).
|
|
36
36
|
*/
|
|
37
|
-
import { OP_EVENT, BASIS_UNKNOWN, DISPOSITION_DECISION, MATERIAL_ACTUAL_USE, MATERIAL_LOT_USE, isTestSpecificationBasis, isRecipeExecutionBasis, isMaterialExecutionBasis } from "./contract.js";
|
|
37
|
+
import { OP_EVENT, TASK_STATUS, BASIS_UNKNOWN, EQUIPMENT_STATUS, PERSON_STATUS, ASSET_STATUS, DISPOSITION_DECISION, MATERIAL_ACTUAL_USE, MATERIAL_LOT_USE, isTestSpecificationBasis, isRecipeExecutionBasis, isMaterialExecutionBasis } from "./contract.js";
|
|
38
38
|
import { isWorkShiftExecutionBasis } from "./work-shift-basis.js";
|
|
39
39
|
/**
|
|
40
40
|
* 객체 한 줄이 선언된 안쪽 모양을 지키나 — **선언하지 않은 자리는 보지 않는다.**
|
|
@@ -90,11 +90,10 @@ function shapeErrors(where, row, shape) {
|
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
92
92
|
* 닫아 둔 낱말과 그 이유.
|
|
93
|
-
* · 작업 상태 —
|
|
93
|
+
* · 작업 상태 — 목록은 계약의 `TASK_STATUS` 하나다(`contract.ts` — 그 까닭도 거기). 여기에 다시 적지 않는다.
|
|
94
94
|
* · 설비 상태 — OEE 누적기가 `busy`·`down` 만 센다. 그 밖의 낱말은 가동률 0% 로 조용히 앉는다.
|
|
95
95
|
* · 사람·자산 상태 — 배정이 `idle` 을 찾는다. 다른 낱말이면 있는 자원이 없는 것이 된다.
|
|
96
96
|
*/
|
|
97
|
-
const TASK_STATUS = ['created', 'assigned', 'in-progress', 'completed'];
|
|
98
97
|
/*
|
|
99
98
|
* 설비 상태 — **ISO 22400-2 의 시간 모델에 하나씩 대응한다**(2026-08-30).
|
|
100
99
|
*
|
|
@@ -106,10 +105,10 @@ const TASK_STATUS = ['created', 'assigned', 'in-progress', 'completed'];
|
|
|
106
105
|
*
|
|
107
106
|
* `down` 과 `idle` 은 22400 에서 다른 항목이고 공장이 손 쓰는 방법도 다르다(고장은 보전, 대기는
|
|
108
107
|
* 자재·일정). 처음부터 갈라 두었던 것이 맞았고, 여기에 둘을 더해 22400 의 시간 모델을 덮는다.
|
|
108
|
+
*
|
|
109
|
+
* The lists themselves (equipment, person, asset) live in the contract (`contract.ts`) and are imported here, so
|
|
110
|
+
* the ingest boundary accepts exactly what the contract declares.
|
|
109
111
|
*/
|
|
110
|
-
const EQUIPMENT_STATUS = ['idle', 'busy', 'down', 'setup', 'planned-stop'];
|
|
111
|
-
const PERSON_STATUS = ['idle', 'busy'];
|
|
112
|
-
const ASSET_STATUS = ['idle', 'in-use'];
|
|
113
112
|
const SPECS = {
|
|
114
113
|
task: {
|
|
115
114
|
eventType: OP_EVENT.task,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { CapacityAnalysis, CapacityInput, CapacityRequirement } from './capacity.ts';
|
|
2
2
|
import { type ISOTime, type WorkCalendarEntry } from './contract.ts';
|
|
3
3
|
/**
|
|
4
4
|
* 능력의 종류 — **표준 열거형**(B2MML `CapabilityTypeType`). 우리 낱말을 새로 만들지 않는다.
|
|
@@ -108,10 +108,3 @@ export interface OperationsCapabilityInput {
|
|
|
108
108
|
* 공휴일이 사라지고, 그 오차는 조용하다.
|
|
109
109
|
*/
|
|
110
110
|
export declare function workingHoursBetween(calendar: readonly WorkCalendarEntry[] | undefined, fromMs: number, toMs: number, utcOffsetMinutes?: number): number;
|
|
111
|
-
/**
|
|
112
|
-
* 생산 능력 보고서 — 있는 용량 분석 위에 **구간 · 종류 · 약정**을 올린다.
|
|
113
|
-
*
|
|
114
|
-
* 용량 분석을 두 번 부른다(전량 · 가용). 같은 함수를 두 번 부르는 것이 요점이다: 달성불가를 따로
|
|
115
|
-
* 계산하면 규칙이 두 벌이 되고, 두 벌은 어긋난다.
|
|
116
|
-
*/
|
|
117
|
-
export declare function operationsCapabilityOf(input: OperationsCapabilityInput): OperationsCapabilityReport;
|