@operato/ops-contract 0.9.31 → 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 +47 -0
- package/dist/contract.js +34 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/operational-ingest.js +47 -4
- package/dist/work-shift-basis.d.ts +40 -0
- package/dist/work-shift-basis.js +49 -0
- package/dist-cjs/index.cjs +107 -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;
|
|
@@ -2023,7 +2024,49 @@ export interface TaskState {
|
|
|
2023
2024
|
* 실적 쪽 대응은 `TaskState`(`SegmentResponse`) 다 — 요구와 응답을 한 짝으로 읽어야 "얼마나 시켰고
|
|
2024
2025
|
* 얼마나 됐나" 가 나온다.
|
|
2025
2026
|
*/
|
|
2027
|
+
/** Source-selected recipe evidence. Digests refer to source records; the reduced payload is not their full signed encoding. */
|
|
2028
|
+
export interface RecipeExecutionBasis {
|
|
2029
|
+
basisId: string;
|
|
2030
|
+
recipeId: string;
|
|
2031
|
+
revisionId: string;
|
|
2032
|
+
planId: string;
|
|
2033
|
+
contentHash: string;
|
|
2034
|
+
businessTime: ISOTime;
|
|
2035
|
+
recipe: {
|
|
2036
|
+
key: string;
|
|
2037
|
+
label: string;
|
|
2038
|
+
inputs: {
|
|
2039
|
+
material: string;
|
|
2040
|
+
qty: number;
|
|
2041
|
+
operation?: string;
|
|
2042
|
+
}[];
|
|
2043
|
+
outputs: {
|
|
2044
|
+
material: string;
|
|
2045
|
+
qty: number;
|
|
2046
|
+
}[];
|
|
2047
|
+
route?: string;
|
|
2048
|
+
};
|
|
2049
|
+
route?: {
|
|
2050
|
+
key: string;
|
|
2051
|
+
steps: string[];
|
|
2052
|
+
};
|
|
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;
|
|
2026
2067
|
export interface OrderState {
|
|
2068
|
+
materialBasis?: MaterialExecutionBasis[];
|
|
2069
|
+
recipeBasis?: RecipeExecutionBasis;
|
|
2027
2070
|
id: string;
|
|
2028
2071
|
kind: string;
|
|
2029
2072
|
status: string;
|
|
@@ -3434,6 +3477,7 @@ export declare function isFailureStatus(value: unknown): boolean;
|
|
|
3434
3477
|
/** 계획정지였나 — 계획 조업 시간에서 빼는 것(§`OeeCounters.holdMs`). */
|
|
3435
3478
|
export declare function isPlannedStopStatus(value: unknown): boolean;
|
|
3436
3479
|
export interface EquipmentStatePeriodFact {
|
|
3480
|
+
workShiftBasis?: import('./work-shift-basis.ts').WorkShiftExecutionBasis;
|
|
3437
3481
|
moverId: string;
|
|
3438
3482
|
/**
|
|
3439
3483
|
* 그 구간의 상태 — **선언된 다섯 중 하나**(§`EQUIPMENT_STATUS`).
|
|
@@ -3533,6 +3577,7 @@ export interface MaterialActual {
|
|
|
3533
3577
|
lotId?: string;
|
|
3534
3578
|
}
|
|
3535
3579
|
export interface TaskStatusDelta {
|
|
3580
|
+
workShiftBasis?: import('./work-shift-basis.ts').WorkShiftExecutionBasis;
|
|
3536
3581
|
taskId: string;
|
|
3537
3582
|
/** 착수 시각(절대 sim-clock) — 보간 앵커. TaskState 와 같은 뜻. */
|
|
3538
3583
|
startedAtSimMs?: number;
|
|
@@ -3666,6 +3711,8 @@ export interface ObservedOrderLine {
|
|
|
3666
3711
|
allocated?: number;
|
|
3667
3712
|
}
|
|
3668
3713
|
export interface OrderStatusDelta {
|
|
3714
|
+
materialBasis?: MaterialExecutionBasis[];
|
|
3715
|
+
recipeBasis?: RecipeExecutionBasis;
|
|
3669
3716
|
orderId: string;
|
|
3670
3717
|
kind: string;
|
|
3671
3718
|
status: string;
|
package/dist/contract.js
CHANGED
|
@@ -1085,6 +1085,40 @@ export function homeOf(e) {
|
|
|
1085
1085
|
const id = e?.homeLocation;
|
|
1086
1086
|
return id ? { id, kind: e?.homeLocationKind ?? 'location' } : undefined;
|
|
1087
1087
|
}
|
|
1088
|
+
export function isRecipeExecutionBasis(value) {
|
|
1089
|
+
if (!value || typeof value !== 'object')
|
|
1090
|
+
return false;
|
|
1091
|
+
const v = value;
|
|
1092
|
+
const text = (x) => typeof x === 'string' && x.trim().length > 0;
|
|
1093
|
+
const lines = (x) => Array.isArray(x) && x.length > 0 && x.every(row => row && text(row.material) &&
|
|
1094
|
+
typeof row.qty === 'number' && Number.isFinite(row.qty) && row.qty > 0 && (row.operation === undefined || text(row.operation)));
|
|
1095
|
+
return [v.basisId, v.recipeId, v.revisionId, v.planId, v.contentHash, v.businessTime].every(text) &&
|
|
1096
|
+
/(?:Z|[+-]\d{2}:\d{2})$/.test(v.businessTime) && Number.isFinite(Date.parse(v.businessTime)) &&
|
|
1097
|
+
!!v.recipe && text(v.recipe.key) && text(v.recipe.label) && lines(v.recipe.inputs) && lines(v.recipe.outputs) &&
|
|
1098
|
+
(v.recipe.route === undefined ? v.route === undefined && v.recipe.inputs.every(line => !line.operation) : text(v.recipe.route) && !!v.route &&
|
|
1099
|
+
v.route.key === v.recipe.route && Array.isArray(v.route.steps) && v.route.steps.every(text) &&
|
|
1100
|
+
v.recipe.inputs.every(line => !line.operation || v.route.steps.includes(line.operation)));
|
|
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
|
+
}
|
|
1088
1122
|
// ── 운영 델타(비-EPCIS) — State 채널의 나머지 절반 ──────────────────────────
|
|
1089
1123
|
// EPCIS 이벤트는 재고/위치만 재구성 가능. tasks·equipment·orders 의 운영 상태는
|
|
1090
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 } 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,23 @@ const SPECS = {
|
|
|
224
230
|
*
|
|
225
231
|
* 새 어휘가 아니다 — 계약이 `recipeKey` 를 네 자리에서 이미 쓴다. 오더 관측에만 자리가 없었다.
|
|
226
232
|
*/
|
|
227
|
-
recipeKey: 'string'
|
|
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
|
+
},
|
|
245
|
+
recipeBasis: {
|
|
246
|
+
required: ['basisId', 'recipeId', 'revisionId', 'planId', 'contentHash', 'businessTime', 'recipe'],
|
|
247
|
+
fields: { basisId: 'string', recipeId: 'string', revisionId: 'string', planId: 'string', contentHash: 'string', businessTime: 'string' }
|
|
248
|
+
// Owned composition and captured route are additionally checked by isRecipeExecutionBasis below.
|
|
249
|
+
},
|
|
234
250
|
allocated: {
|
|
235
251
|
required: ['epc', 'qty'],
|
|
236
252
|
fields: { epc: 'string', qty: 'number' },
|
|
@@ -300,7 +316,13 @@ const SPECS = {
|
|
|
300
316
|
fields: {
|
|
301
317
|
moverId: 'string', status: 'string', from: 'string', to: 'string', // vocabulary-guard: allow
|
|
302
318
|
/* 사람이 정한 사유 — 없을 수 있다(적지 않은 것과 사유가 없는 것은 다르므로 지어내지 않는다). */
|
|
303
|
-
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
|
+
}
|
|
304
326
|
},
|
|
305
327
|
enums: { status: EQUIPMENT_STATUS }
|
|
306
328
|
},
|
|
@@ -617,9 +639,30 @@ export function ingestOperationalRecords(records, opts) {
|
|
|
617
639
|
* 사건 시각이 되고, 그러면 어제 있었던 정지가 오늘 일어난 것으로 저널에 적힌다. 적은 때는
|
|
618
640
|
* `recordTime` 에 남는다.
|
|
619
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
|
+
}
|
|
620
651
|
if (kind === 'test' && r.specificationBasis !== undefined && !isTestSpecificationBasis(r.specificationBasis)) {
|
|
621
652
|
errors.push('test.specificationBasis: invalid pinned specification evidence');
|
|
622
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
|
+
}
|
|
662
|
+
if (kind === 'order' && r.recipeBasis !== undefined && (!isRecipeExecutionBasis(r.recipeBasis) ||
|
|
663
|
+
(r.recipeKey !== undefined && r.recipeKey !== r.recipeBasis.recipe.key))) {
|
|
664
|
+
errors.push('order.recipeBasis: invalid pinned recipe evidence');
|
|
665
|
+
}
|
|
623
666
|
const closedPeriodEnd = kind === 'equipment-period' ? String(r.to ?? '').trim() : '';
|
|
624
667
|
const at = closedPeriodEnd || String(r.at ?? '').trim() || opts.defaultEventTime;
|
|
625
668
|
const atMs = at ? Date.parse(at) : Number.NaN;
|
|
@@ -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,15 +170,18 @@ __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,
|
|
176
177
|
isPlannedStopStatus: () => isPlannedStopStatus,
|
|
178
|
+
isRecipeExecutionBasis: () => isRecipeExecutionBasis,
|
|
177
179
|
isResourceKind: () => isResourceKind,
|
|
178
180
|
isTestSpecificationBasis: () => isTestSpecificationBasis,
|
|
179
181
|
isTransformationRecord: () => isTransformationRecord,
|
|
180
182
|
isWebhookDeliveryCode: () => isWebhookDeliveryCode,
|
|
181
183
|
isWebhookSecretSegment: () => isWebhookSecretSegment,
|
|
184
|
+
isWorkShiftExecutionBasis: () => isWorkShiftExecutionBasis,
|
|
182
185
|
isoDurationHours: () => isoDurationHours,
|
|
183
186
|
itemKeyOf: () => itemKeyOf,
|
|
184
187
|
judgeAgainstSpec: () => judgeAgainstSpec,
|
|
@@ -254,6 +257,7 @@ __export(index_exports, {
|
|
|
254
257
|
webhookSecretMissingNote: () => webhookSecretMissingNote,
|
|
255
258
|
webhookSenderAction: () => webhookSenderAction,
|
|
256
259
|
weekdayAt: () => weekdayAt,
|
|
260
|
+
workShiftAttribution: () => workShiftAttribution,
|
|
257
261
|
workingHoursBetween: () => workingHoursBetween,
|
|
258
262
|
workingTimeOfWeek: () => workingTimeOfWeek
|
|
259
263
|
});
|
|
@@ -890,6 +894,25 @@ function homeOf(e) {
|
|
|
890
894
|
const id = e?.homeLocation;
|
|
891
895
|
return id ? { id, kind: e?.homeLocationKind ?? "location" } : void 0;
|
|
892
896
|
}
|
|
897
|
+
function isRecipeExecutionBasis(value) {
|
|
898
|
+
if (!value || typeof value !== "object") return false;
|
|
899
|
+
const v = value;
|
|
900
|
+
const text = (x) => typeof x === "string" && x.trim().length > 0;
|
|
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)));
|
|
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)));
|
|
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
|
+
}
|
|
893
916
|
var OP_EVENT = {
|
|
894
917
|
task: "task.status",
|
|
895
918
|
equipment: "equipment.status",
|
|
@@ -3527,6 +3550,45 @@ function readEpochMs(raw) {
|
|
|
3527
3550
|
return Number.isNaN(at2) ? void 0 : at2;
|
|
3528
3551
|
}
|
|
3529
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
|
+
|
|
3530
3592
|
// src/operational-ingest.ts
|
|
3531
3593
|
function shapeErrors(where, row, shape) {
|
|
3532
3594
|
if (!shape) return [];
|
|
@@ -3595,7 +3657,8 @@ var SPECS = {
|
|
|
3595
3657
|
startTime: "string",
|
|
3596
3658
|
endTime: "string",
|
|
3597
3659
|
materialActual: "object[]",
|
|
3598
|
-
recordTime: "string"
|
|
3660
|
+
recordTime: "string",
|
|
3661
|
+
workShiftBasis: "object"
|
|
3599
3662
|
},
|
|
3600
3663
|
/*
|
|
3601
3664
|
* **자재 줄의 안쪽** — 계약의 `MaterialActual` 그대로다.
|
|
@@ -3611,6 +3674,11 @@ var SPECS = {
|
|
|
3611
3674
|
* 물려받으면 단위를 모르는 현장의 사실이 통째로 거절된다.
|
|
3612
3675
|
*/
|
|
3613
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
|
+
},
|
|
3614
3682
|
materialActual: {
|
|
3615
3683
|
required: ["definitionId", "use"],
|
|
3616
3684
|
fields: { definitionId: "string", lotId: "string", quantity: "number", uom: "string" },
|
|
@@ -3736,13 +3804,25 @@ var SPECS = {
|
|
|
3736
3804
|
*
|
|
3737
3805
|
* 새 어휘가 아니다 — 계약이 `recipeKey` 를 네 자리에서 이미 쓴다. 오더 관측에만 자리가 없었다.
|
|
3738
3806
|
*/
|
|
3739
|
-
recipeKey: "string"
|
|
3807
|
+
recipeKey: "string",
|
|
3808
|
+
recipeBasis: "object",
|
|
3809
|
+
materialBasis: "object[]"
|
|
3740
3810
|
},
|
|
3741
3811
|
/*
|
|
3742
3812
|
* 확보분의 안쪽을 본다 — 열쇠와 수 둘이다(§`AllocatedQuantity`). 안 보면 틀린 이름이 조용히
|
|
3743
3813
|
* 지나가고(`epcs`·`quantity` 따위), 미러는 잡힌 수를 0 으로 읽는다.
|
|
3744
3814
|
*/
|
|
3745
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
|
+
},
|
|
3821
|
+
recipeBasis: {
|
|
3822
|
+
required: ["basisId", "recipeId", "revisionId", "planId", "contentHash", "businessTime", "recipe"],
|
|
3823
|
+
fields: { basisId: "string", recipeId: "string", revisionId: "string", planId: "string", contentHash: "string", businessTime: "string" }
|
|
3824
|
+
// Owned composition and captured route are additionally checked by isRecipeExecutionBasis below.
|
|
3825
|
+
},
|
|
3746
3826
|
allocated: {
|
|
3747
3827
|
required: ["epc", "qty"],
|
|
3748
3828
|
fields: { epc: "string", qty: "number" },
|
|
@@ -3823,7 +3903,14 @@ var SPECS = {
|
|
|
3823
3903
|
/* 사람이 정한 사유 — 없을 수 있다(적지 않은 것과 사유가 없는 것은 다르므로 지어내지 않는다). */
|
|
3824
3904
|
reasonCode: "string",
|
|
3825
3905
|
decidedBy: "string",
|
|
3826
|
-
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
|
+
}
|
|
3827
3914
|
},
|
|
3828
3915
|
enums: { status: EQUIPMENT_STATUS2 }
|
|
3829
3916
|
},
|
|
@@ -4089,9 +4176,22 @@ function ingestOperationalRecords(records, opts) {
|
|
|
4089
4176
|
}
|
|
4090
4177
|
}
|
|
4091
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
|
+
}
|
|
4092
4184
|
if (kind === "test" && r.specificationBasis !== void 0 && !isTestSpecificationBasis(r.specificationBasis)) {
|
|
4093
4185
|
errors.push("test.specificationBasis: invalid pinned specification evidence");
|
|
4094
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
|
+
}
|
|
4192
|
+
if (kind === "order" && r.recipeBasis !== void 0 && (!isRecipeExecutionBasis(r.recipeBasis) || r.recipeKey !== void 0 && r.recipeKey !== r.recipeBasis.recipe.key)) {
|
|
4193
|
+
errors.push("order.recipeBasis: invalid pinned recipe evidence");
|
|
4194
|
+
}
|
|
4095
4195
|
const closedPeriodEnd = kind === "equipment-period" ? String(r.to ?? "").trim() : "";
|
|
4096
4196
|
const at2 = closedPeriodEnd || String(r.at ?? "").trim() || opts.defaultEventTime;
|
|
4097
4197
|
const atMs = at2 ? Date.parse(at2) : Number.NaN;
|
|
@@ -4910,15 +5010,18 @@ function nonEmpty(value) {
|
|
|
4910
5010
|
isFailureStatus,
|
|
4911
5011
|
isFlowOrder,
|
|
4912
5012
|
isMasterDataRecord,
|
|
5013
|
+
isMaterialExecutionBasis,
|
|
4913
5014
|
isOperationalAttentionV1,
|
|
4914
5015
|
isOperationalRecord,
|
|
4915
5016
|
isOrderTerminal,
|
|
4916
5017
|
isPlannedStopStatus,
|
|
5018
|
+
isRecipeExecutionBasis,
|
|
4917
5019
|
isResourceKind,
|
|
4918
5020
|
isTestSpecificationBasis,
|
|
4919
5021
|
isTransformationRecord,
|
|
4920
5022
|
isWebhookDeliveryCode,
|
|
4921
5023
|
isWebhookSecretSegment,
|
|
5024
|
+
isWorkShiftExecutionBasis,
|
|
4922
5025
|
isoDurationHours,
|
|
4923
5026
|
itemKeyOf,
|
|
4924
5027
|
judgeAgainstSpec,
|
|
@@ -4994,6 +5097,7 @@ function nonEmpty(value) {
|
|
|
4994
5097
|
webhookSecretMissingNote,
|
|
4995
5098
|
webhookSenderAction,
|
|
4996
5099
|
weekdayAt,
|
|
5100
|
+
workShiftAttribution,
|
|
4997
5101
|
workingHoursBetween,
|
|
4998
5102
|
workingTimeOfWeek
|
|
4999
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",
|