@operato/ops-contract 0.9.32 → 0.9.33
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/dist/contract.d.ts +17 -0
- package/dist/contract.js +20 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/operational-ingest.js +38 -4
- package/dist/work-shift-basis.d.ts +40 -0
- package/dist/work-shift-basis.js +49 -0
- package/dist-cjs/index.cjs +89 -3
- package/package.json +1 -1
package/dist/contract.d.ts
CHANGED
|
@@ -1967,6 +1967,7 @@ export interface WorkDirectiveRef {
|
|
|
1967
1967
|
workMasterId?: string;
|
|
1968
1968
|
}
|
|
1969
1969
|
export interface TaskState {
|
|
1970
|
+
workShiftBasis?: import('./work-shift-basis.ts').WorkShiftExecutionBasis;
|
|
1970
1971
|
id: string;
|
|
1971
1972
|
kind: string;
|
|
1972
1973
|
status: TaskStatus;
|
|
@@ -2051,7 +2052,20 @@ export interface RecipeExecutionBasis {
|
|
|
2051
2052
|
};
|
|
2052
2053
|
}
|
|
2053
2054
|
export declare function isRecipeExecutionBasis(value: unknown): value is RecipeExecutionBasis;
|
|
2055
|
+
/** Source-pinned material definition; not a replacement of the Twin's current master projection. */
|
|
2056
|
+
export interface MaterialExecutionBasis {
|
|
2057
|
+
basisId: string;
|
|
2058
|
+
materialId: string;
|
|
2059
|
+
revisionId: string;
|
|
2060
|
+
revisionNumber: number;
|
|
2061
|
+
planId: string;
|
|
2062
|
+
contentHash: string;
|
|
2063
|
+
businessTime: ISOTime;
|
|
2064
|
+
material: MaterialDefinition;
|
|
2065
|
+
}
|
|
2066
|
+
export declare function isMaterialExecutionBasis(value: unknown): value is MaterialExecutionBasis;
|
|
2054
2067
|
export interface OrderState {
|
|
2068
|
+
materialBasis?: MaterialExecutionBasis[];
|
|
2055
2069
|
recipeBasis?: RecipeExecutionBasis;
|
|
2056
2070
|
id: string;
|
|
2057
2071
|
kind: string;
|
|
@@ -3463,6 +3477,7 @@ export declare function isFailureStatus(value: unknown): boolean;
|
|
|
3463
3477
|
/** 계획정지였나 — 계획 조업 시간에서 빼는 것(§`OeeCounters.holdMs`). */
|
|
3464
3478
|
export declare function isPlannedStopStatus(value: unknown): boolean;
|
|
3465
3479
|
export interface EquipmentStatePeriodFact {
|
|
3480
|
+
workShiftBasis?: import('./work-shift-basis.ts').WorkShiftExecutionBasis;
|
|
3466
3481
|
moverId: string;
|
|
3467
3482
|
/**
|
|
3468
3483
|
* 그 구간의 상태 — **선언된 다섯 중 하나**(§`EQUIPMENT_STATUS`).
|
|
@@ -3562,6 +3577,7 @@ export interface MaterialActual {
|
|
|
3562
3577
|
lotId?: string;
|
|
3563
3578
|
}
|
|
3564
3579
|
export interface TaskStatusDelta {
|
|
3580
|
+
workShiftBasis?: import('./work-shift-basis.ts').WorkShiftExecutionBasis;
|
|
3565
3581
|
taskId: string;
|
|
3566
3582
|
/** 착수 시각(절대 sim-clock) — 보간 앵커. TaskState 와 같은 뜻. */
|
|
3567
3583
|
startedAtSimMs?: number;
|
|
@@ -3695,6 +3711,7 @@ export interface ObservedOrderLine {
|
|
|
3695
3711
|
allocated?: number;
|
|
3696
3712
|
}
|
|
3697
3713
|
export interface OrderStatusDelta {
|
|
3714
|
+
materialBasis?: MaterialExecutionBasis[];
|
|
3698
3715
|
recipeBasis?: RecipeExecutionBasis;
|
|
3699
3716
|
orderId: string;
|
|
3700
3717
|
kind: string;
|
package/dist/contract.js
CHANGED
|
@@ -1099,6 +1099,26 @@ export function isRecipeExecutionBasis(value) {
|
|
|
1099
1099
|
v.route.key === v.recipe.route && Array.isArray(v.route.steps) && v.route.steps.every(text) &&
|
|
1100
1100
|
v.recipe.inputs.every(line => !line.operation || v.route.steps.includes(line.operation)));
|
|
1101
1101
|
}
|
|
1102
|
+
export function isMaterialExecutionBasis(value) {
|
|
1103
|
+
if (!value || typeof value !== 'object')
|
|
1104
|
+
return false;
|
|
1105
|
+
const v = value;
|
|
1106
|
+
const text = (x) => typeof x === 'string' && x.trim().length > 0;
|
|
1107
|
+
let count = 0;
|
|
1108
|
+
const properties = (rows, depth = 0) => rows === undefined ||
|
|
1109
|
+
(Array.isArray(rows) && depth <= 32 && rows.every(p => {
|
|
1110
|
+
if (++count > 1000 || !p || !text(p.id))
|
|
1111
|
+
return false;
|
|
1112
|
+
if (p.value != null && typeof p.value !== 'string' && (typeof p.value !== 'number' || !Number.isFinite(p.value)))
|
|
1113
|
+
return false;
|
|
1114
|
+
return properties(p.children, depth + 1);
|
|
1115
|
+
}));
|
|
1116
|
+
return [v.basisId, v.materialId, v.revisionId, v.planId, v.contentHash, v.businessTime].every(text) &&
|
|
1117
|
+
/(?:Z|[+-]\d{2}:\d{2})$/.test(v.businessTime) && Number.isFinite(Date.parse(v.businessTime)) &&
|
|
1118
|
+
Number.isInteger(v.revisionNumber) && v.revisionNumber > 0 && !!v.material && text(v.material.id) &&
|
|
1119
|
+
properties(v.material.properties) &&
|
|
1120
|
+
[v.material.materialClassIds, v.material.testSpecificationIds].every(ids => ids === undefined || Array.isArray(ids) && ids.every(text));
|
|
1121
|
+
}
|
|
1102
1122
|
// ── 운영 델타(비-EPCIS) — State 채널의 나머지 절반 ──────────────────────────
|
|
1103
1123
|
// EPCIS 이벤트는 재고/위치만 재구성 가능. tasks·equipment·orders 의 운영 상태는
|
|
1104
1124
|
// 이 델타로 미러한다. envelope.eventType = 'task.status' | 'equipment.status' | 'order.status'.
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from './iso-duration.ts';
|
|
|
11
11
|
export * from './master-data.ts';
|
|
12
12
|
export * from './mes-profile.ts';
|
|
13
13
|
export * from './operational-ingest.ts';
|
|
14
|
+
export * from './work-shift-basis.ts';
|
|
14
15
|
export * from './operations-capability.ts';
|
|
15
16
|
export * from './scenario-validate.ts';
|
|
16
17
|
export * from './vocabulary.ts';
|
package/dist/index.js
CHANGED
|
@@ -32,6 +32,7 @@ export * from "./iso-duration.js";
|
|
|
32
32
|
export * from "./master-data.js";
|
|
33
33
|
export * from "./mes-profile.js";
|
|
34
34
|
export * from "./operational-ingest.js";
|
|
35
|
+
export * from "./work-shift-basis.js";
|
|
35
36
|
export * from "./operations-capability.js";
|
|
36
37
|
export * from "./scenario-validate.js";
|
|
37
38
|
export * from "./vocabulary.js";
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
* 모르는 필드는 **조용히 버리지 않고 거부한다.** `taskID` 처럼 한 글자 틀린 이름은 통과시키면 영원히
|
|
35
35
|
* 보이지 않는 손실이 된다(이 문에는 아직 옛 발신자가 없어 호환 부담도 없다).
|
|
36
36
|
*/
|
|
37
|
-
import { OP_EVENT, DISPOSITION_DECISION, MATERIAL_ACTUAL_USE, MATERIAL_LOT_USE, isTestSpecificationBasis, isRecipeExecutionBasis } from "./contract.js";
|
|
37
|
+
import { OP_EVENT, DISPOSITION_DECISION, MATERIAL_ACTUAL_USE, MATERIAL_LOT_USE, isTestSpecificationBasis, isRecipeExecutionBasis, isMaterialExecutionBasis } from "./contract.js";
|
|
38
|
+
import { isWorkShiftExecutionBasis } from "./work-shift-basis.js";
|
|
38
39
|
/**
|
|
39
40
|
* 객체 한 줄이 선언된 안쪽 모양을 지키나 — **선언하지 않은 자리는 보지 않는다.**
|
|
40
41
|
*
|
|
@@ -122,7 +123,7 @@ const SPECS = {
|
|
|
122
123
|
itemRefs: 'string[]', resourceRef: 'string', resources: 'string[]', personnel: 'string[]', assets: 'string[]',
|
|
123
124
|
orderId: 'string', intent: 'string', progress: 'number', remainingMs: 'number', durationMs: 'number',
|
|
124
125
|
startedAtSimMs: 'number', outcome: 'string', priority: 'number', startTime: 'string', endTime: 'string',
|
|
125
|
-
materialActual: 'object[]', recordTime: 'string'
|
|
126
|
+
materialActual: 'object[]', recordTime: 'string', workShiftBasis: 'object'
|
|
126
127
|
},
|
|
127
128
|
/*
|
|
128
129
|
* **자재 줄의 안쪽** — 계약의 `MaterialActual` 그대로다.
|
|
@@ -138,6 +139,11 @@ const SPECS = {
|
|
|
138
139
|
* 물려받으면 단위를 모르는 현장의 사실이 통째로 거절된다.
|
|
139
140
|
*/
|
|
140
141
|
shapes: {
|
|
142
|
+
workShiftBasis: {
|
|
143
|
+
required: ['basisId', 'arrangementId', 'revisionId', 'revisionNumber', 'planId', 'contentHash', 'businessTime', 'timezone', 'shifts', 'workDate'],
|
|
144
|
+
fields: { basisId: 'string', arrangementId: 'string', revisionId: 'string', revisionNumber: 'number', planId: 'string', contentHash: 'string', businessTime: 'string', timezone: 'string', workDate: 'string' }
|
|
145
|
+
// Full nested content and selected occurrence are checked by isWorkShiftExecutionBasis below.
|
|
146
|
+
},
|
|
141
147
|
materialActual: {
|
|
142
148
|
required: ['definitionId', 'use'],
|
|
143
149
|
fields: { definitionId: 'string', lotId: 'string', quantity: 'number', uom: 'string' },
|
|
@@ -224,13 +230,18 @@ const SPECS = {
|
|
|
224
230
|
*
|
|
225
231
|
* 새 어휘가 아니다 — 계약이 `recipeKey` 를 네 자리에서 이미 쓴다. 오더 관측에만 자리가 없었다.
|
|
226
232
|
*/
|
|
227
|
-
recipeKey: 'string', recipeBasis: 'object'
|
|
233
|
+
recipeKey: 'string', recipeBasis: 'object', materialBasis: 'object[]'
|
|
228
234
|
},
|
|
229
235
|
/*
|
|
230
236
|
* 확보분의 안쪽을 본다 — 열쇠와 수 둘이다(§`AllocatedQuantity`). 안 보면 틀린 이름이 조용히
|
|
231
237
|
* 지나가고(`epcs`·`quantity` 따위), 미러는 잡힌 수를 0 으로 읽는다.
|
|
232
238
|
*/
|
|
233
239
|
shapes: {
|
|
240
|
+
materialBasis: {
|
|
241
|
+
required: ['basisId', 'materialId', 'revisionId', 'revisionNumber', 'planId', 'contentHash', 'businessTime', 'material'],
|
|
242
|
+
fields: { basisId: 'string', materialId: 'string', revisionId: 'string', revisionNumber: 'number', planId: 'string', contentHash: 'string', businessTime: 'string' }
|
|
243
|
+
// Recursive material properties and reference lists are checked by isMaterialExecutionBasis.
|
|
244
|
+
},
|
|
234
245
|
recipeBasis: {
|
|
235
246
|
required: ['basisId', 'recipeId', 'revisionId', 'planId', 'contentHash', 'businessTime', 'recipe'],
|
|
236
247
|
fields: { basisId: 'string', recipeId: 'string', revisionId: 'string', planId: 'string', contentHash: 'string', businessTime: 'string' }
|
|
@@ -305,7 +316,13 @@ const SPECS = {
|
|
|
305
316
|
fields: {
|
|
306
317
|
moverId: 'string', status: 'string', from: 'string', to: 'string', // vocabulary-guard: allow
|
|
307
318
|
/* 사람이 정한 사유 — 없을 수 있다(적지 않은 것과 사유가 없는 것은 다르므로 지어내지 않는다). */
|
|
308
|
-
reasonCode: 'string', decidedBy: 'string', recordTime: 'string'
|
|
319
|
+
reasonCode: 'string', decidedBy: 'string', recordTime: 'string', workShiftBasis: 'object'
|
|
320
|
+
},
|
|
321
|
+
shapes: {
|
|
322
|
+
workShiftBasis: {
|
|
323
|
+
required: ['basisId', 'arrangementId', 'revisionId', 'revisionNumber', 'planId', 'contentHash', 'businessTime', 'timezone', 'shifts', 'workDate'],
|
|
324
|
+
fields: { basisId: 'string', arrangementId: 'string', revisionId: 'string', revisionNumber: 'number', planId: 'string', contentHash: 'string', businessTime: 'string', timezone: 'string', workDate: 'string' }
|
|
325
|
+
}
|
|
309
326
|
},
|
|
310
327
|
enums: { status: EQUIPMENT_STATUS }
|
|
311
328
|
},
|
|
@@ -622,9 +639,26 @@ export function ingestOperationalRecords(records, opts) {
|
|
|
622
639
|
* 사건 시각이 되고, 그러면 어제 있었던 정지가 오늘 일어난 것으로 저널에 적힌다. 적은 때는
|
|
623
640
|
* `recordTime` 에 남는다.
|
|
624
641
|
*/
|
|
642
|
+
if ((kind === 'task' || kind === 'equipment-period') && r.workShiftBasis !== undefined) {
|
|
643
|
+
if (!isWorkShiftExecutionBasis(r.workShiftBasis) ||
|
|
644
|
+
(kind === 'equipment-period' && Date.parse(r.workShiftBasis.businessTime) !== Date.parse(String(r.from))) ||
|
|
645
|
+
(kind === 'task' && (r.startTime ?? r.endTime) !== undefined && Date.parse(r.workShiftBasis.businessTime) !== Date.parse(String(r.startTime ?? r.endTime)))) {
|
|
646
|
+
errors.push(kind + '.workShiftBasis: invalid pinned shift evidence');
|
|
647
|
+
}
|
|
648
|
+
else
|
|
649
|
+
data.workShiftBasis = structuredClone(r.workShiftBasis);
|
|
650
|
+
}
|
|
625
651
|
if (kind === 'test' && r.specificationBasis !== undefined && !isTestSpecificationBasis(r.specificationBasis)) {
|
|
626
652
|
errors.push('test.specificationBasis: invalid pinned specification evidence');
|
|
627
653
|
}
|
|
654
|
+
if (kind === 'order' && r.materialBasis !== undefined) {
|
|
655
|
+
const bases = r.materialBasis;
|
|
656
|
+
if (!Array.isArray(bases) || !bases.length || bases.length > 1000 || !bases.every(isMaterialExecutionBasis) ||
|
|
657
|
+
new Set(bases.map(b => b.material.id)).size !== bases.length ||
|
|
658
|
+
(r.gtin !== undefined && !bases.some(b => b.material.id === r.gtin)) ||
|
|
659
|
+
(isRecipeExecutionBasis(r.recipeBasis) && [...r.recipeBasis.recipe.inputs, ...r.recipeBasis.recipe.outputs].some(line => !bases.some(b => b.material.id === line.material))))
|
|
660
|
+
errors.push('order.materialBasis: invalid pinned material evidence');
|
|
661
|
+
}
|
|
628
662
|
if (kind === 'order' && r.recipeBasis !== undefined && (!isRecipeExecutionBasis(r.recipeBasis) ||
|
|
629
663
|
(r.recipeKey !== undefined && r.recipeKey !== r.recipeBasis.recipe.key))) {
|
|
630
664
|
errors.push('order.recipeBasis: invalid pinned recipe evidence');
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Source-signed shift evidence, not a mutable calendar or an activation command. */
|
|
2
|
+
export interface WorkShiftExecutionBasis {
|
|
3
|
+
basisId: string;
|
|
4
|
+
arrangementId: string;
|
|
5
|
+
revisionId: string;
|
|
6
|
+
revisionNumber: number;
|
|
7
|
+
planId: string;
|
|
8
|
+
/** Opaque source digest. Authentication and digest verification belong to the producer/transport. */
|
|
9
|
+
contentHash: string;
|
|
10
|
+
businessTime: string;
|
|
11
|
+
timezone: string;
|
|
12
|
+
shifts: {
|
|
13
|
+
name: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
fromDate: number;
|
|
16
|
+
fromTime: string;
|
|
17
|
+
toDate: number;
|
|
18
|
+
toTime: string;
|
|
19
|
+
daysOfWeek: string;
|
|
20
|
+
}[];
|
|
21
|
+
/** Attribution captured at businessTime; never recomputed against today's calendar. */
|
|
22
|
+
workDate: string;
|
|
23
|
+
shiftName?: string;
|
|
24
|
+
occurrence?: {
|
|
25
|
+
from: string;
|
|
26
|
+
to: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export declare function isWorkShiftExecutionBasis(value: unknown): value is WorkShiftExecutionBasis;
|
|
30
|
+
/** Journal readers can inspect the captured attribution without a current master lookup. */
|
|
31
|
+
export declare function workShiftAttribution(value: unknown): {
|
|
32
|
+
workDate: string;
|
|
33
|
+
shiftName: string | undefined;
|
|
34
|
+
timezone: string;
|
|
35
|
+
revisionNumber: number;
|
|
36
|
+
occurrence: {
|
|
37
|
+
from: string;
|
|
38
|
+
to: string;
|
|
39
|
+
} | undefined;
|
|
40
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const instant = (value) => typeof value === 'string' && /(?:Z|[+-]\d{2}:\d{2})$/.test(value) && Number.isFinite(Date.parse(value));
|
|
2
|
+
const nonempty = (value) => typeof value === 'string' && !!value.trim();
|
|
3
|
+
const clock = (value) => typeof value === 'string' && /^(?:[01]\d|2[0-3]):[0-5]\d$/.test(value);
|
|
4
|
+
export function isWorkShiftExecutionBasis(value) {
|
|
5
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
6
|
+
return false;
|
|
7
|
+
const b = value;
|
|
8
|
+
if (![b.basisId, b.arrangementId, b.revisionId, b.planId, b.contentHash].every(nonempty) ||
|
|
9
|
+
!Number.isSafeInteger(b.revisionNumber) || b.revisionNumber < 1 || !instant(b.businessTime) || !nonempty(b.timezone))
|
|
10
|
+
return false;
|
|
11
|
+
try {
|
|
12
|
+
new Intl.DateTimeFormat('en', { timeZone: b.timezone }).format(0);
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
if (typeof b.workDate !== 'string' || !/^\d{4}-\d{2}-\d{2}$/.test(b.workDate) ||
|
|
18
|
+
!Number.isFinite(Date.parse(b.workDate)) || new Date(b.workDate).toISOString().slice(0, 10) !== b.workDate)
|
|
19
|
+
return false;
|
|
20
|
+
if (!Array.isArray(b.shifts) || !b.shifts.length || b.shifts.length > 64)
|
|
21
|
+
return false;
|
|
22
|
+
const names = new Set();
|
|
23
|
+
for (const s of b.shifts) {
|
|
24
|
+
if (!s || typeof s !== 'object' || !nonempty(s.name) || names.has(s.name) ||
|
|
25
|
+
(s.description !== undefined && typeof s.description !== 'string') ||
|
|
26
|
+
![-1, 0, 1].includes(s.fromDate) || ![-1, 0, 1].includes(s.toDate) || !clock(s.fromTime) || !clock(s.toTime) ||
|
|
27
|
+
typeof s.daysOfWeek !== 'string' || !/^(?:[0-6](?:,[0-6])*)?$/.test(s.daysOfWeek))
|
|
28
|
+
return false;
|
|
29
|
+
const minutes = (time) => Number(time.slice(0, 2)) * 60 + Number(time.slice(3));
|
|
30
|
+
const duration = (s.toDate - s.fromDate) * 1440 + minutes(s.toTime) - minutes(s.fromTime);
|
|
31
|
+
if (duration <= 0 || duration > 1440)
|
|
32
|
+
return false;
|
|
33
|
+
names.add(s.name);
|
|
34
|
+
}
|
|
35
|
+
if (b.shiftName === undefined)
|
|
36
|
+
return b.occurrence === undefined;
|
|
37
|
+
if (!nonempty(b.shiftName) || !names.has(b.shiftName) || !b.occurrence ||
|
|
38
|
+
!instant(b.occurrence.from) || !instant(b.occurrence.to))
|
|
39
|
+
return false;
|
|
40
|
+
const at = Date.parse(b.businessTime);
|
|
41
|
+
return Date.parse(b.occurrence.from) <= at && at < Date.parse(b.occurrence.to);
|
|
42
|
+
}
|
|
43
|
+
/** Journal readers can inspect the captured attribution without a current master lookup. */
|
|
44
|
+
export function workShiftAttribution(value) {
|
|
45
|
+
if (!isWorkShiftExecutionBasis(value))
|
|
46
|
+
throw new Error('Invalid pinned work shift evidence');
|
|
47
|
+
return { workDate: value.workDate, shiftName: value.shiftName, timezone: value.timezone,
|
|
48
|
+
revisionNumber: value.revisionNumber, occurrence: value.occurrence ? { ...value.occurrence } : undefined };
|
|
49
|
+
}
|
package/dist-cjs/index.cjs
CHANGED
|
@@ -170,6 +170,7 @@ __export(index_exports, {
|
|
|
170
170
|
isFailureStatus: () => isFailureStatus,
|
|
171
171
|
isFlowOrder: () => isFlowOrder,
|
|
172
172
|
isMasterDataRecord: () => isMasterDataRecord,
|
|
173
|
+
isMaterialExecutionBasis: () => isMaterialExecutionBasis,
|
|
173
174
|
isOperationalAttentionV1: () => isOperationalAttentionV1,
|
|
174
175
|
isOperationalRecord: () => isOperationalRecord,
|
|
175
176
|
isOrderTerminal: () => isOrderTerminal,
|
|
@@ -180,6 +181,7 @@ __export(index_exports, {
|
|
|
180
181
|
isTransformationRecord: () => isTransformationRecord,
|
|
181
182
|
isWebhookDeliveryCode: () => isWebhookDeliveryCode,
|
|
182
183
|
isWebhookSecretSegment: () => isWebhookSecretSegment,
|
|
184
|
+
isWorkShiftExecutionBasis: () => isWorkShiftExecutionBasis,
|
|
183
185
|
isoDurationHours: () => isoDurationHours,
|
|
184
186
|
itemKeyOf: () => itemKeyOf,
|
|
185
187
|
judgeAgainstSpec: () => judgeAgainstSpec,
|
|
@@ -255,6 +257,7 @@ __export(index_exports, {
|
|
|
255
257
|
webhookSecretMissingNote: () => webhookSecretMissingNote,
|
|
256
258
|
webhookSenderAction: () => webhookSenderAction,
|
|
257
259
|
weekdayAt: () => weekdayAt,
|
|
260
|
+
workShiftAttribution: () => workShiftAttribution,
|
|
258
261
|
workingHoursBetween: () => workingHoursBetween,
|
|
259
262
|
workingTimeOfWeek: () => workingTimeOfWeek
|
|
260
263
|
});
|
|
@@ -898,6 +901,18 @@ function isRecipeExecutionBasis(value) {
|
|
|
898
901
|
const lines = (x) => Array.isArray(x) && x.length > 0 && x.every((row) => row && text(row.material) && typeof row.qty === "number" && Number.isFinite(row.qty) && row.qty > 0 && (row.operation === void 0 || text(row.operation)));
|
|
899
902
|
return [v.basisId, v.recipeId, v.revisionId, v.planId, v.contentHash, v.businessTime].every(text) && /(?:Z|[+-]\d{2}:\d{2})$/.test(v.businessTime) && Number.isFinite(Date.parse(v.businessTime)) && !!v.recipe && text(v.recipe.key) && text(v.recipe.label) && lines(v.recipe.inputs) && lines(v.recipe.outputs) && (v.recipe.route === void 0 ? v.route === void 0 && v.recipe.inputs.every((line) => !line.operation) : text(v.recipe.route) && !!v.route && v.route.key === v.recipe.route && Array.isArray(v.route.steps) && v.route.steps.every(text) && v.recipe.inputs.every((line) => !line.operation || v.route.steps.includes(line.operation)));
|
|
900
903
|
}
|
|
904
|
+
function isMaterialExecutionBasis(value) {
|
|
905
|
+
if (!value || typeof value !== "object") return false;
|
|
906
|
+
const v = value;
|
|
907
|
+
const text = (x) => typeof x === "string" && x.trim().length > 0;
|
|
908
|
+
let count = 0;
|
|
909
|
+
const properties = (rows, depth = 0) => rows === void 0 || Array.isArray(rows) && depth <= 32 && rows.every((p) => {
|
|
910
|
+
if (++count > 1e3 || !p || !text(p.id)) return false;
|
|
911
|
+
if (p.value != null && typeof p.value !== "string" && (typeof p.value !== "number" || !Number.isFinite(p.value))) return false;
|
|
912
|
+
return properties(p.children, depth + 1);
|
|
913
|
+
});
|
|
914
|
+
return [v.basisId, v.materialId, v.revisionId, v.planId, v.contentHash, v.businessTime].every(text) && /(?:Z|[+-]\d{2}:\d{2})$/.test(v.businessTime) && Number.isFinite(Date.parse(v.businessTime)) && Number.isInteger(v.revisionNumber) && v.revisionNumber > 0 && !!v.material && text(v.material.id) && properties(v.material.properties) && [v.material.materialClassIds, v.material.testSpecificationIds].every((ids) => ids === void 0 || Array.isArray(ids) && ids.every(text));
|
|
915
|
+
}
|
|
901
916
|
var OP_EVENT = {
|
|
902
917
|
task: "task.status",
|
|
903
918
|
equipment: "equipment.status",
|
|
@@ -3535,6 +3550,45 @@ function readEpochMs(raw) {
|
|
|
3535
3550
|
return Number.isNaN(at2) ? void 0 : at2;
|
|
3536
3551
|
}
|
|
3537
3552
|
|
|
3553
|
+
// src/work-shift-basis.ts
|
|
3554
|
+
var instant = (value) => typeof value === "string" && /(?:Z|[+-]\d{2}:\d{2})$/.test(value) && Number.isFinite(Date.parse(value));
|
|
3555
|
+
var nonempty = (value) => typeof value === "string" && !!value.trim();
|
|
3556
|
+
var clock = (value) => typeof value === "string" && /^(?:[01]\d|2[0-3]):[0-5]\d$/.test(value);
|
|
3557
|
+
function isWorkShiftExecutionBasis(value) {
|
|
3558
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
3559
|
+
const b = value;
|
|
3560
|
+
if (![b.basisId, b.arrangementId, b.revisionId, b.planId, b.contentHash].every(nonempty) || !Number.isSafeInteger(b.revisionNumber) || b.revisionNumber < 1 || !instant(b.businessTime) || !nonempty(b.timezone)) return false;
|
|
3561
|
+
try {
|
|
3562
|
+
new Intl.DateTimeFormat("en", { timeZone: b.timezone }).format(0);
|
|
3563
|
+
} catch {
|
|
3564
|
+
return false;
|
|
3565
|
+
}
|
|
3566
|
+
if (typeof b.workDate !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(b.workDate) || !Number.isFinite(Date.parse(b.workDate)) || new Date(b.workDate).toISOString().slice(0, 10) !== b.workDate) return false;
|
|
3567
|
+
if (!Array.isArray(b.shifts) || !b.shifts.length || b.shifts.length > 64) return false;
|
|
3568
|
+
const names = /* @__PURE__ */ new Set();
|
|
3569
|
+
for (const s of b.shifts) {
|
|
3570
|
+
if (!s || typeof s !== "object" || !nonempty(s.name) || names.has(s.name) || s.description !== void 0 && typeof s.description !== "string" || ![-1, 0, 1].includes(s.fromDate) || ![-1, 0, 1].includes(s.toDate) || !clock(s.fromTime) || !clock(s.toTime) || typeof s.daysOfWeek !== "string" || !/^(?:[0-6](?:,[0-6])*)?$/.test(s.daysOfWeek)) return false;
|
|
3571
|
+
const minutes = (time) => Number(time.slice(0, 2)) * 60 + Number(time.slice(3));
|
|
3572
|
+
const duration = (s.toDate - s.fromDate) * 1440 + minutes(s.toTime) - minutes(s.fromTime);
|
|
3573
|
+
if (duration <= 0 || duration > 1440) return false;
|
|
3574
|
+
names.add(s.name);
|
|
3575
|
+
}
|
|
3576
|
+
if (b.shiftName === void 0) return b.occurrence === void 0;
|
|
3577
|
+
if (!nonempty(b.shiftName) || !names.has(b.shiftName) || !b.occurrence || !instant(b.occurrence.from) || !instant(b.occurrence.to)) return false;
|
|
3578
|
+
const at2 = Date.parse(b.businessTime);
|
|
3579
|
+
return Date.parse(b.occurrence.from) <= at2 && at2 < Date.parse(b.occurrence.to);
|
|
3580
|
+
}
|
|
3581
|
+
function workShiftAttribution(value) {
|
|
3582
|
+
if (!isWorkShiftExecutionBasis(value)) throw new Error("Invalid pinned work shift evidence");
|
|
3583
|
+
return {
|
|
3584
|
+
workDate: value.workDate,
|
|
3585
|
+
shiftName: value.shiftName,
|
|
3586
|
+
timezone: value.timezone,
|
|
3587
|
+
revisionNumber: value.revisionNumber,
|
|
3588
|
+
occurrence: value.occurrence ? { ...value.occurrence } : void 0
|
|
3589
|
+
};
|
|
3590
|
+
}
|
|
3591
|
+
|
|
3538
3592
|
// src/operational-ingest.ts
|
|
3539
3593
|
function shapeErrors(where, row, shape) {
|
|
3540
3594
|
if (!shape) return [];
|
|
@@ -3603,7 +3657,8 @@ var SPECS = {
|
|
|
3603
3657
|
startTime: "string",
|
|
3604
3658
|
endTime: "string",
|
|
3605
3659
|
materialActual: "object[]",
|
|
3606
|
-
recordTime: "string"
|
|
3660
|
+
recordTime: "string",
|
|
3661
|
+
workShiftBasis: "object"
|
|
3607
3662
|
},
|
|
3608
3663
|
/*
|
|
3609
3664
|
* **자재 줄의 안쪽** — 계약의 `MaterialActual` 그대로다.
|
|
@@ -3619,6 +3674,11 @@ var SPECS = {
|
|
|
3619
3674
|
* 물려받으면 단위를 모르는 현장의 사실이 통째로 거절된다.
|
|
3620
3675
|
*/
|
|
3621
3676
|
shapes: {
|
|
3677
|
+
workShiftBasis: {
|
|
3678
|
+
required: ["basisId", "arrangementId", "revisionId", "revisionNumber", "planId", "contentHash", "businessTime", "timezone", "shifts", "workDate"],
|
|
3679
|
+
fields: { basisId: "string", arrangementId: "string", revisionId: "string", revisionNumber: "number", planId: "string", contentHash: "string", businessTime: "string", timezone: "string", workDate: "string" }
|
|
3680
|
+
// Full nested content and selected occurrence are checked by isWorkShiftExecutionBasis below.
|
|
3681
|
+
},
|
|
3622
3682
|
materialActual: {
|
|
3623
3683
|
required: ["definitionId", "use"],
|
|
3624
3684
|
fields: { definitionId: "string", lotId: "string", quantity: "number", uom: "string" },
|
|
@@ -3745,13 +3805,19 @@ var SPECS = {
|
|
|
3745
3805
|
* 새 어휘가 아니다 — 계약이 `recipeKey` 를 네 자리에서 이미 쓴다. 오더 관측에만 자리가 없었다.
|
|
3746
3806
|
*/
|
|
3747
3807
|
recipeKey: "string",
|
|
3748
|
-
recipeBasis: "object"
|
|
3808
|
+
recipeBasis: "object",
|
|
3809
|
+
materialBasis: "object[]"
|
|
3749
3810
|
},
|
|
3750
3811
|
/*
|
|
3751
3812
|
* 확보분의 안쪽을 본다 — 열쇠와 수 둘이다(§`AllocatedQuantity`). 안 보면 틀린 이름이 조용히
|
|
3752
3813
|
* 지나가고(`epcs`·`quantity` 따위), 미러는 잡힌 수를 0 으로 읽는다.
|
|
3753
3814
|
*/
|
|
3754
3815
|
shapes: {
|
|
3816
|
+
materialBasis: {
|
|
3817
|
+
required: ["basisId", "materialId", "revisionId", "revisionNumber", "planId", "contentHash", "businessTime", "material"],
|
|
3818
|
+
fields: { basisId: "string", materialId: "string", revisionId: "string", revisionNumber: "number", planId: "string", contentHash: "string", businessTime: "string" }
|
|
3819
|
+
// Recursive material properties and reference lists are checked by isMaterialExecutionBasis.
|
|
3820
|
+
},
|
|
3755
3821
|
recipeBasis: {
|
|
3756
3822
|
required: ["basisId", "recipeId", "revisionId", "planId", "contentHash", "businessTime", "recipe"],
|
|
3757
3823
|
fields: { basisId: "string", recipeId: "string", revisionId: "string", planId: "string", contentHash: "string", businessTime: "string" }
|
|
@@ -3837,7 +3903,14 @@ var SPECS = {
|
|
|
3837
3903
|
/* 사람이 정한 사유 — 없을 수 있다(적지 않은 것과 사유가 없는 것은 다르므로 지어내지 않는다). */
|
|
3838
3904
|
reasonCode: "string",
|
|
3839
3905
|
decidedBy: "string",
|
|
3840
|
-
recordTime: "string"
|
|
3906
|
+
recordTime: "string",
|
|
3907
|
+
workShiftBasis: "object"
|
|
3908
|
+
},
|
|
3909
|
+
shapes: {
|
|
3910
|
+
workShiftBasis: {
|
|
3911
|
+
required: ["basisId", "arrangementId", "revisionId", "revisionNumber", "planId", "contentHash", "businessTime", "timezone", "shifts", "workDate"],
|
|
3912
|
+
fields: { basisId: "string", arrangementId: "string", revisionId: "string", revisionNumber: "number", planId: "string", contentHash: "string", businessTime: "string", timezone: "string", workDate: "string" }
|
|
3913
|
+
}
|
|
3841
3914
|
},
|
|
3842
3915
|
enums: { status: EQUIPMENT_STATUS2 }
|
|
3843
3916
|
},
|
|
@@ -4103,9 +4176,19 @@ function ingestOperationalRecords(records, opts) {
|
|
|
4103
4176
|
}
|
|
4104
4177
|
}
|
|
4105
4178
|
}
|
|
4179
|
+
if ((kind === "task" || kind === "equipment-period") && r.workShiftBasis !== void 0) {
|
|
4180
|
+
if (!isWorkShiftExecutionBasis(r.workShiftBasis) || kind === "equipment-period" && Date.parse(r.workShiftBasis.businessTime) !== Date.parse(String(r.from)) || kind === "task" && (r.startTime ?? r.endTime) !== void 0 && Date.parse(r.workShiftBasis.businessTime) !== Date.parse(String(r.startTime ?? r.endTime))) {
|
|
4181
|
+
errors.push(kind + ".workShiftBasis: invalid pinned shift evidence");
|
|
4182
|
+
} else data.workShiftBasis = structuredClone(r.workShiftBasis);
|
|
4183
|
+
}
|
|
4106
4184
|
if (kind === "test" && r.specificationBasis !== void 0 && !isTestSpecificationBasis(r.specificationBasis)) {
|
|
4107
4185
|
errors.push("test.specificationBasis: invalid pinned specification evidence");
|
|
4108
4186
|
}
|
|
4187
|
+
if (kind === "order" && r.materialBasis !== void 0) {
|
|
4188
|
+
const bases = r.materialBasis;
|
|
4189
|
+
if (!Array.isArray(bases) || !bases.length || bases.length > 1e3 || !bases.every(isMaterialExecutionBasis) || new Set(bases.map((b) => b.material.id)).size !== bases.length || r.gtin !== void 0 && !bases.some((b) => b.material.id === r.gtin) || isRecipeExecutionBasis(r.recipeBasis) && [...r.recipeBasis.recipe.inputs, ...r.recipeBasis.recipe.outputs].some((line) => !bases.some((b) => b.material.id === line.material)))
|
|
4190
|
+
errors.push("order.materialBasis: invalid pinned material evidence");
|
|
4191
|
+
}
|
|
4109
4192
|
if (kind === "order" && r.recipeBasis !== void 0 && (!isRecipeExecutionBasis(r.recipeBasis) || r.recipeKey !== void 0 && r.recipeKey !== r.recipeBasis.recipe.key)) {
|
|
4110
4193
|
errors.push("order.recipeBasis: invalid pinned recipe evidence");
|
|
4111
4194
|
}
|
|
@@ -4927,6 +5010,7 @@ function nonEmpty(value) {
|
|
|
4927
5010
|
isFailureStatus,
|
|
4928
5011
|
isFlowOrder,
|
|
4929
5012
|
isMasterDataRecord,
|
|
5013
|
+
isMaterialExecutionBasis,
|
|
4930
5014
|
isOperationalAttentionV1,
|
|
4931
5015
|
isOperationalRecord,
|
|
4932
5016
|
isOrderTerminal,
|
|
@@ -4937,6 +5021,7 @@ function nonEmpty(value) {
|
|
|
4937
5021
|
isTransformationRecord,
|
|
4938
5022
|
isWebhookDeliveryCode,
|
|
4939
5023
|
isWebhookSecretSegment,
|
|
5024
|
+
isWorkShiftExecutionBasis,
|
|
4940
5025
|
isoDurationHours,
|
|
4941
5026
|
itemKeyOf,
|
|
4942
5027
|
judgeAgainstSpec,
|
|
@@ -5012,6 +5097,7 @@ function nonEmpty(value) {
|
|
|
5012
5097
|
webhookSecretMissingNote,
|
|
5013
5098
|
webhookSenderAction,
|
|
5014
5099
|
weekdayAt,
|
|
5100
|
+
workShiftAttribution,
|
|
5015
5101
|
workingHoursBetween,
|
|
5016
5102
|
workingTimeOfWeek
|
|
5017
5103
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@operato/ops-contract",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.33",
|
|
4
4
|
"description": "Operations domain contract — the standard vocabulary that producers and readers agree on (EPCIS 2.0/GS1, ISA-95, IEC 61850/ISO 50001). Types, guards, validation. No state, no engine.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist-cjs/index.cjs",
|