@operato/ops-contract 0.9.39 → 0.9.41

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.
@@ -1,5 +1,6 @@
1
1
  import { type RatedUsage, type UsedUsage } from './rated-usage.ts';
2
2
  import type { FoldedOrders, OrderFoldPolicy } from './order-fold.ts';
3
+ import type { ReferencedLocation } from './referenced-location.ts';
3
4
  export type ISOTime = string;
4
5
  export interface CanonicalEnvelope<T = unknown> {
5
6
  eventId: string;
@@ -2570,6 +2571,8 @@ export interface StateSnapshot {
2570
2571
  allocatedWithUnknownLotUse?: number;
2571
2572
  };
2572
2573
  locations: LocationState[];
2574
+ /** 이 트윈이 참조만 하는 다른 렌즈의 자리 — 모델의 선언을 그대로 싣는다(없으면 칸이 없다). */
2575
+ referencedLocations?: ReferencedLocation[];
2573
2576
  items: ItemState[];
2574
2577
  /**
2575
2578
  * 설비 — **ISA-95 `Equipment`.** 고정 설비(도장기·용접로봇)와 이동 설비(지게차·호슬러)를 한 그릇에
@@ -3874,6 +3877,11 @@ export interface TwinModelDef {
3874
3877
  properties?: ResourceProperty[];
3875
3878
  testSpecificationIds?: TestSpecificationRefs;
3876
3879
  })[];
3880
+ /**
3881
+ * **다른 렌즈의 자리** — 참조만 한다(§`ReferencedLocation`). 이 트윈의 자리가 아니므로 능력 · 용량 · 종류가 없고, 거기로 간
3882
+ * 물품은 이 트윈의 재고에서 빠진다. 없으면 참조하는 자리가 없다.
3883
+ */
3884
+ referencedLocations?: ReferencedLocation[];
3877
3885
  /**
3878
3886
  * 설비 — ISA-95 `Equipment`. mtbfMs/mttrMs 지정 시 확률적 고장 모델 참여(OEE Availability 손실).
3879
3887
  * 미지정=고장 없음. `window` 지정 시 그 시간대에만 일한다(교대·가동시간) — 미지정이면 24시간 가용.
package/dist/erp.d.ts CHANGED
@@ -149,6 +149,60 @@ export declare function materialMovementKey(e: Pick<ProductionPerformanceEntry,
149
149
  * 거절 이유를 목록으로 낸다. 첫 번째에서 멈추면 사람이 한 번에 하나씩 고치게 된다.
150
150
  */
151
151
  export declare function validatePerformance(e: ProductionPerformanceEntry, nowMs: number): string[];
152
+ /**
153
+ * ERP 에 앉아 있는 실적 한 줄 — **되읽은 것**이다.
154
+ *
155
+ * 사람이 반영하는 ERP(`traits.posting: 'manual-export'`)는 우리가 내보낸 줄이 실제로 앉았는지 이것으로만 안다.
156
+ * API 로 올리는 ERP 에서도 대사에 쓴다. 우리 실적과 짝짓는 것은 부르는 쪽(MES)의 함수 하나가 한다 — 여기는
157
+ * ERP 가 가진 사실만 옮긴다. 짝이 없거나 둘 이상이면 짐작하지 않는다.
158
+ */
159
+ export interface ErpPerformanceRecord {
160
+ /** ERP 의 오더번호. */
161
+ orderId: string;
162
+ operationId?: string;
163
+ goodQuantity: number;
164
+ scrapQuantity?: number;
165
+ uom: string;
166
+ /** ERP 가 그 실적을 앉힌 날짜 · 시각(원문 그대로). */
167
+ postedAt?: ISOTime;
168
+ /** ERP 의 문서 번호 — 있으면 짝이 맞은 뒤 우리 기록에 남는다. */
169
+ documentRef?: string;
170
+ /**
171
+ * ERP 가 보존하는 칸(비고 등)에 실려 돌아온 우리 멱등 키(`performanceKey`). 있으면 짝짓기는 이것으로 한다.
172
+ * ERP 가 그런 칸을 갖는지는 어댑터가 확인해 둔다 — 없으면 비운다(지어내지 않는다).
173
+ */
174
+ carriedKey?: string;
175
+ }
176
+ /** ERP 에 있는 재고 한 줄 — 되읽은 것. */
177
+ export interface ErpInventoryRecord {
178
+ materialDefinitionId: string;
179
+ quantity: number;
180
+ uom: string;
181
+ site?: string;
182
+ location?: string;
183
+ lot?: string;
184
+ /** 그 수량이 언제 기준인가(원문 그대로). */
185
+ asOf?: ISOTime;
186
+ }
187
+ /** 되읽기의 범위. 빠진 칸은 「제한 없음」이 아니라 어댑터가 정한 창이다. */
188
+ export interface ErpReadQuery {
189
+ since?: ISOTime;
190
+ orderIds?: string[];
191
+ }
192
+ /**
193
+ * 사람이 ERP 에 붙여 넣거나 올릴 실적 묶음.
194
+ *
195
+ * ERP 마다 붙여넣기 열 순서 · 날짜 모양이 다르므로 내용은 어댑터가 만든다. 줄마다 우리 멱등 키를 함께 돌려줘서
196
+ * 부르는 쪽이 「내보냄 · 확인 대기」로 적을 줄을 안다 — 내보냈다고 올라간 것이 아니다.
197
+ */
198
+ export interface ErpExport {
199
+ fileName: string;
200
+ /** `text/tab-separated-values` · `text/csv` 처럼. */
201
+ mediaType: string;
202
+ body: string;
203
+ /** 이 묶음에 든 실적의 멱등 키, 줄 순서대로. */
204
+ keys: string[];
205
+ }
152
206
  /**
153
207
  * 잘못 올린 실적을 되돌리는 요청 — **삭제가 아니라 역분개다.**
154
208
  *
@@ -216,6 +270,18 @@ export interface ErpAdapter {
216
270
  reversePerformance?(cfg: ErpConfig, reversal: PerformanceReversal, key: string): Promise<ErpOutcome<ErpDocumentRef>>;
217
271
  /** 마스터를 당긴다 — 구조는 밀지 않고 당겨 간다(사실과 다른 규율). */
218
272
  readMaster?(cfg: ErpConfig, axis: ErpMasterAxis): Promise<ErpOutcome<unknown[]>>;
273
+ /**
274
+ * 사람이 반영할 실적 묶음을 만든다 — `traits.posting: 'manual-export'` 인 ERP 의 「올리기」다.
275
+ * 값을 바꾸지 않는다. 사람이 반영했는지는 `readPerformance` 로 되읽어야 안다.
276
+ */
277
+ exportPerformance?(cfg: ErpConfig, entries: {
278
+ entry: ProductionPerformanceEntry;
279
+ key: string;
280
+ }[]): Promise<ErpOutcome<ErpExport>>;
281
+ /** ERP 에 앉은 실적을 되읽는다(결정 2). */
282
+ readPerformance?(cfg: ErpConfig, query?: ErpReadQuery): Promise<ErpOutcome<ErpPerformanceRecord[]>>;
283
+ /** ERP 의 재고를 되읽는다(결정 2). */
284
+ readInventory?(cfg: ErpConfig, query?: ErpReadQuery): Promise<ErpOutcome<ErpInventoryRecord[]>>;
219
285
  }
220
286
  /**
221
287
  * ERP 마다 갈리는 성질.
@@ -245,9 +311,19 @@ export interface ErpTraits {
245
311
  * 기다리지 않는다.
246
312
  */
247
313
  reversal: 'api' | 'manual' | 'none';
314
+ /**
315
+ * 실적이 어떻게 ERP 에 들어가나 (ADR-0110 결정 1).
316
+ *
317
+ * api 우리가 부르면 앉는다 — `postPerformance`
318
+ * manual-export 사람이 ERP 화면에 붙여 넣거나 올린다 — 우리는 `exportPerformance` 로 묶음을 만들 뿐이다.
319
+ * 국내 중소 ERP 에 흔하다(미라텍의 SystemEver: 작업실적에 파일 업로드도 공식 API 도 없다)
320
+ *
321
+ * 이 칸이 없으면 내보낸 줄을 올라간 것으로 적는 거짓이 생긴다. 그래서 필수다.
322
+ */
323
+ posting: 'api' | 'manual-export';
248
324
  }
249
325
  /** 이 ERP 가 할 수 있다고 선언하는 것. 구현이 없으면 없는 것으로 읽는다. */
250
- export declare const ERP_CAPABILITY: readonly ["schedule", "performance", "material-movement", "reversal", "master"];
326
+ export declare const ERP_CAPABILITY: readonly ["schedule", "performance", "material-movement", "reversal", "master", "performance-read", "inventory-read"];
251
327
  export type ErpCapability = (typeof ERP_CAPABILITY)[number];
252
328
  /** 당겨 올 수 있는 마스터의 축. */
253
329
  export declare const ERP_MASTER_AXIS: readonly ["product", "bom", "routing", "work-center"];
package/dist/erp.js CHANGED
@@ -107,7 +107,15 @@ export function reversalKey(performanceKey) {
107
107
  return `${performanceKey}|reversal`;
108
108
  }
109
109
  /** 이 ERP 가 할 수 있다고 선언하는 것. 구현이 없으면 없는 것으로 읽는다. */
110
- export const ERP_CAPABILITY = ['schedule', 'performance', 'material-movement', 'reversal', 'master'];
110
+ export const ERP_CAPABILITY = [
111
+ 'schedule',
112
+ 'performance',
113
+ 'material-movement',
114
+ 'reversal',
115
+ 'master',
116
+ 'performance-read',
117
+ 'inventory-read'
118
+ ];
111
119
  /** 당겨 올 수 있는 마스터의 축. */
112
120
  export const ERP_MASTER_AXIS = ['product', 'bom', 'routing', 'work-center'];
113
121
  /**
@@ -117,12 +125,16 @@ export const ERP_MASTER_AXIS = ['product', 'bom', 'routing', 'work-center'];
117
125
  * 화면에 서지 않는다.
118
126
  */
119
127
  export function erpCapabilityGaps(adapter) {
128
+ const manual = adapter.traits?.posting === 'manual-export';
120
129
  const needs = {
121
130
  schedule: 'readSchedules',
122
- performance: 'postPerformance',
131
+ /* 사람이 반영하는 ERP 에서 「실적을 올린다」는 묶음을 만드는 것이다. */
132
+ performance: manual ? 'exportPerformance' : 'postPerformance',
123
133
  'material-movement': 'postMaterialMovement',
124
134
  reversal: 'reversePerformance',
125
- master: 'readMaster'
135
+ master: 'readMaster',
136
+ 'performance-read': 'readPerformance',
137
+ 'inventory-read': 'readInventory'
126
138
  };
127
139
  const gaps = [];
128
140
  for (const cap of adapter.capabilities ?? []) {
@@ -141,5 +153,23 @@ export function erpCapabilityGaps(adapter) {
141
153
  if (adapter.traits?.materialWithPerformance && typeof adapter.postMaterialMovement === 'function') {
142
154
  gaps.push('traits.materialWithPerformance 가 참인데 postMaterialMovement 가 따로 있다 — 소비가 두 번 앉는다');
143
155
  }
156
+ /*
157
+ * 사람이 반영하는 ERP 에 부르면 앉는 문이 있으면, 펌프가 그 문으로 「올라갔다」고 적는다 — 아무것도 안 앉았는데
158
+ * (ADR-0110 결정 1 가). 실적과 함께 앉는 자재도 같다.
159
+ */
160
+ if (manual) {
161
+ if (typeof adapter.postPerformance === 'function') {
162
+ gaps.push('traits.posting 이 manual-export 인데 postPerformance 가 있다 — 부르면 앉는 ERP 가 아니다');
163
+ }
164
+ if (typeof adapter.postMaterialMovement === 'function') {
165
+ gaps.push('traits.posting 이 manual-export 인데 postMaterialMovement 가 있다');
166
+ }
167
+ if (adapter.capabilities?.includes('material-movement')) {
168
+ gaps.push('traits.posting 이 manual-export 인데 material-movement 능력을 선언했다');
169
+ }
170
+ }
171
+ if (adapter.traits?.posting !== 'api' && adapter.traits?.posting !== 'manual-export') {
172
+ gaps.push('traits.posting 이 없다 — api 인지 manual-export 인지 말해야 펌프가 내보낸 줄을 올라간 것으로 적지 않는다');
173
+ }
144
174
  return gaps;
145
175
  }
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export * from './ems-profile.ts';
7
7
  export * from './energy-ingest.ts';
8
8
  export * from './epcis.ts';
9
9
  export * from './order-fold.ts';
10
+ export * from './referenced-location.ts';
10
11
  export * from './face2-adapter.ts';
11
12
  export * from './iso-duration.ts';
12
13
  export * from './master-data.ts';
package/dist/index.js CHANGED
@@ -28,6 +28,7 @@ export * from "./ems-profile.js";
28
28
  export * from "./energy-ingest.js";
29
29
  export * from "./epcis.js";
30
30
  export * from "./order-fold.js";
31
+ export * from "./referenced-location.js";
31
32
  export * from "./face2-adapter.js";
32
33
  export * from "./iso-duration.js";
33
34
  export * from "./master-data.js";
@@ -0,0 +1,20 @@
1
+ export interface ReferencedLocation {
2
+ id: string;
3
+ /** 그 자리를 정의하는 영역 — 기준정보가 말한 그대로(`mes` · `wms` · `yms` …). */
4
+ system: string;
5
+ }
6
+ /** 모델이 참조만 하는 자리의 id 집합. 선언이 없으면 빈 집합이다. */
7
+ export declare function referencedLocationIds(def: {
8
+ referencedLocations?: readonly ReferencedLocation[];
9
+ } | null | undefined): Set<string>;
10
+ /**
11
+ * 기준정보의 자리를 렌즈 기준으로 가른다 — 자리가 자기 영역을 말하지 않았으면 이 렌즈의 것이다(옛 원본 · 영역 없는 원본은
12
+ * 지금까지와 같이 선다). 영역을 말했고 이 렌즈와 다르면 참조다.
13
+ */
14
+ export declare function partitionLensLocations<T extends {
15
+ id: string;
16
+ system?: string;
17
+ }>(locations: readonly T[], lensSystem: string): {
18
+ own: T[];
19
+ referenced: ReferencedLocation[];
20
+ };
@@ -0,0 +1,20 @@
1
+ /** 모델이 참조만 하는 자리의 id 집합. 선언이 없으면 빈 집합이다. */
2
+ export function referencedLocationIds(def) {
3
+ return new Set((def?.referencedLocations ?? []).map(r => r.id).filter(Boolean));
4
+ }
5
+ /**
6
+ * 기준정보의 자리를 렌즈 기준으로 가른다 — 자리가 자기 영역을 말하지 않았으면 이 렌즈의 것이다(옛 원본 · 영역 없는 원본은
7
+ * 지금까지와 같이 선다). 영역을 말했고 이 렌즈와 다르면 참조다.
8
+ */
9
+ export function partitionLensLocations(locations, lensSystem) {
10
+ const own = [];
11
+ const referenced = [];
12
+ for (const l of locations) {
13
+ const system = typeof l.system === 'string' ? l.system.trim() : '';
14
+ if (system && system !== lensSystem)
15
+ referenced.push({ id: l.id, system });
16
+ else
17
+ own.push(l);
18
+ }
19
+ return { own, referenced };
20
+ }
@@ -228,6 +228,7 @@ __export(index_exports, {
228
228
  outsideLimit: () => outsideLimit,
229
229
  parseEpc: () => parseEpc,
230
230
  parseIsoDuration: () => parseIsoDuration,
231
+ partitionLensLocations: () => partitionLensLocations,
231
232
  passThroughReversible: () => passThroughReversible,
232
233
  performanceKey: () => performanceKey,
233
234
  periodFactId: () => periodFactId,
@@ -241,6 +242,7 @@ __export(index_exports, {
241
242
  readBoardAssets: () => readBoardAssets,
242
243
  readBoardEquipment: () => readBoardEquipment,
243
244
  readBoardLocations: () => readBoardLocations,
245
+ referencedLocationIds: () => referencedLocationIds,
244
246
  relationsFrom: () => relationsFrom,
245
247
  relationsTo: () => relationsTo,
246
248
  requiredTestsFor: () => requiredTestsFor,
@@ -3513,6 +3515,21 @@ function finishedFlowOrdersWithin(hot, folded, nowMs, policy = ORDER_FOLD_DEFAUL
3513
3515
  return { fromMs, toMs: nowMs, count, byStatus };
3514
3516
  }
3515
3517
 
3518
+ // src/referenced-location.ts
3519
+ function referencedLocationIds(def) {
3520
+ return new Set((def?.referencedLocations ?? []).map((r) => r.id).filter(Boolean));
3521
+ }
3522
+ function partitionLensLocations(locations, lensSystem) {
3523
+ const own = [];
3524
+ const referenced = [];
3525
+ for (const l of locations) {
3526
+ const system = typeof l.system === "string" ? l.system.trim() : "";
3527
+ if (system && system !== lensSystem) referenced.push({ id: l.id, system });
3528
+ else own.push(l);
3529
+ }
3530
+ return { own, referenced };
3531
+ }
3532
+
3516
3533
  // src/face2-adapter.ts
3517
3534
  function isAggregationRecord(record) {
3518
3535
  if (!record || typeof record !== "object") return false;
@@ -4970,15 +4987,27 @@ function reversalKey(performanceKey2) {
4970
4987
  if (!String(performanceKey2 ?? "").trim()) throw new Error("reversalKey: \uB418\uB3CC\uB9B4 \uC2E4\uC801\uC758 \uD0A4\uAC00 \uC5C6\uB2E4");
4971
4988
  return `${performanceKey2}|reversal`;
4972
4989
  }
4973
- var ERP_CAPABILITY = ["schedule", "performance", "material-movement", "reversal", "master"];
4990
+ var ERP_CAPABILITY = [
4991
+ "schedule",
4992
+ "performance",
4993
+ "material-movement",
4994
+ "reversal",
4995
+ "master",
4996
+ "performance-read",
4997
+ "inventory-read"
4998
+ ];
4974
4999
  var ERP_MASTER_AXIS = ["product", "bom", "routing", "work-center"];
4975
5000
  function erpCapabilityGaps(adapter) {
5001
+ const manual = adapter.traits?.posting === "manual-export";
4976
5002
  const needs = {
4977
5003
  schedule: "readSchedules",
4978
- performance: "postPerformance",
5004
+ /* 사람이 반영하는 ERP 에서 「실적을 올린다」는 묶음을 만드는 것이다. */
5005
+ performance: manual ? "exportPerformance" : "postPerformance",
4979
5006
  "material-movement": "postMaterialMovement",
4980
5007
  reversal: "reversePerformance",
4981
- master: "readMaster"
5008
+ master: "readMaster",
5009
+ "performance-read": "readPerformance",
5010
+ "inventory-read": "readInventory"
4982
5011
  };
4983
5012
  const gaps = [];
4984
5013
  for (const cap of adapter.capabilities ?? []) {
@@ -4994,6 +5023,20 @@ function erpCapabilityGaps(adapter) {
4994
5023
  if (adapter.traits?.materialWithPerformance && typeof adapter.postMaterialMovement === "function") {
4995
5024
  gaps.push("traits.materialWithPerformance \uAC00 \uCC38\uC778\uB370 postMaterialMovement \uAC00 \uB530\uB85C \uC788\uB2E4 \u2014 \uC18C\uBE44\uAC00 \uB450 \uBC88 \uC549\uB294\uB2E4");
4996
5025
  }
5026
+ if (manual) {
5027
+ if (typeof adapter.postPerformance === "function") {
5028
+ gaps.push("traits.posting \uC774 manual-export \uC778\uB370 postPerformance \uAC00 \uC788\uB2E4 \u2014 \uBD80\uB974\uBA74 \uC549\uB294 ERP \uAC00 \uC544\uB2C8\uB2E4");
5029
+ }
5030
+ if (typeof adapter.postMaterialMovement === "function") {
5031
+ gaps.push("traits.posting \uC774 manual-export \uC778\uB370 postMaterialMovement \uAC00 \uC788\uB2E4");
5032
+ }
5033
+ if (adapter.capabilities?.includes("material-movement")) {
5034
+ gaps.push("traits.posting \uC774 manual-export \uC778\uB370 material-movement \uB2A5\uB825\uC744 \uC120\uC5B8\uD588\uB2E4");
5035
+ }
5036
+ }
5037
+ if (adapter.traits?.posting !== "api" && adapter.traits?.posting !== "manual-export") {
5038
+ gaps.push("traits.posting \uC774 \uC5C6\uB2E4 \u2014 api \uC778\uC9C0 manual-export \uC778\uC9C0 \uB9D0\uD574\uC57C \uD38C\uD504\uAC00 \uB0B4\uBCF4\uB0B8 \uC904\uC744 \uC62C\uB77C\uAC04 \uAC83\uC73C\uB85C \uC801\uC9C0 \uC54A\uB294\uB2E4");
5039
+ }
4997
5040
  return gaps;
4998
5041
  }
4999
5042
 
@@ -5311,6 +5354,7 @@ function nonEmpty(value) {
5311
5354
  outsideLimit,
5312
5355
  parseEpc,
5313
5356
  parseIsoDuration,
5357
+ partitionLensLocations,
5314
5358
  passThroughReversible,
5315
5359
  performanceKey,
5316
5360
  periodFactId,
@@ -5324,6 +5368,7 @@ function nonEmpty(value) {
5324
5368
  readBoardAssets,
5325
5369
  readBoardEquipment,
5326
5370
  readBoardLocations,
5371
+ referencedLocationIds,
5327
5372
  relationsFrom,
5328
5373
  relationsTo,
5329
5374
  requiredTestsFor,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@operato/ops-contract",
3
- "version": "0.9.39",
3
+ "version": "0.9.41",
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",