@operato/ops-contract 0.9.40 → 0.9.42

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.
@@ -77,6 +77,7 @@ __export(index_exports, {
77
77
  REFUSED_WITHOUT_CODE: () => REFUSED_WITHOUT_CODE,
78
78
  RESOURCE_KIND: () => RESOURCE_KIND,
79
79
  RETIRED_VOCABULARY: () => RETIRED_VOCABULARY,
80
+ RETURN_TO_SUPPLIER: () => RETURN_TO_SUPPLIER,
80
81
  SCHEDULE_STATUS: () => SCHEDULE_STATUS,
81
82
  SIGNATURE_REJECTED_REASONS: () => SIGNATURE_REJECTED_REASONS,
82
83
  TWIN_AXES: () => TWIN_AXES,
@@ -137,6 +138,7 @@ __export(index_exports, {
137
138
  effectivityAt: () => effectivityAt,
138
139
  electricalUpstreamOf: () => electricalUpstreamOf,
139
140
  emptyFoldedOrders: () => emptyFoldedOrders,
141
+ epcCandidatesOfGs1: () => epcCandidatesOfGs1,
140
142
  equipmentClassMembership: () => equipmentClassMembership,
141
143
  erpCapabilityGaps: () => erpCapabilityGaps,
142
144
  expiryFromAttributes: () => expiryFromAttributes,
@@ -148,6 +150,8 @@ __export(index_exports, {
148
150
  generationFractionAt: () => generationFractionAt,
149
151
  graiUri: () => graiUri,
150
152
  gs1KeyDigitViolation: () => gs1KeyDigitViolation,
153
+ gtin14OfItem: () => gtin14OfItem,
154
+ gtin14OfItemClass: () => gtin14OfItemClass,
151
155
  hierarchyOf: () => hierarchyOf,
152
156
  homeOf: () => homeOf,
153
157
  hourStartOf: () => hourStartOf,
@@ -165,6 +169,8 @@ __export(index_exports, {
165
169
  ingestEnergyUsagePeriodRecords: () => ingestEnergyUsagePeriodRecords,
166
170
  ingestMasterData: () => ingestMasterData,
167
171
  ingestOperationalRecords: () => ingestOperationalRecords,
172
+ inheritedExpiry: () => inheritedExpiry,
173
+ inheritedLotUse: () => inheritedLotUse,
168
174
  isAggregationRecord: () => isAggregationRecord,
169
175
  isCacheableTense: () => isCacheableTense,
170
176
  isCommandTerminal: () => isCommandTerminal,
@@ -207,8 +213,10 @@ __export(index_exports, {
207
213
  lotClassOfItem: () => lotClassOfItem,
208
214
  lotClassUri: () => lotClassUri,
209
215
  lotFromAttributes: () => lotFromAttributes,
216
+ lotLineageOf: () => lotLineageOf,
210
217
  mapRecord: () => mapRecord,
211
218
  mapRecordChecked: () => mapRecordChecked,
219
+ materialDefinitionIdOf: () => materialDefinitionIdOf,
212
220
  materialMovementKey: () => materialMovementKey,
213
221
  meetsTests: () => meetsTests,
214
222
  minuteOfDayAt: () => minuteOfDayAt,
@@ -227,6 +235,7 @@ __export(index_exports, {
227
235
  orderFoldPolicyOf: () => orderFoldPolicyOf,
228
236
  outsideLimit: () => outsideLimit,
229
237
  parseEpc: () => parseEpc,
238
+ parseGs1: () => parseGs1,
230
239
  parseIsoDuration: () => parseIsoDuration,
231
240
  partitionLensLocations: () => partitionLensLocations,
232
241
  passThroughReversible: () => passThroughReversible,
@@ -256,6 +265,7 @@ __export(index_exports, {
256
265
  sgtinUri: () => sgtinUri,
257
266
  splitFlowOrders: () => splitFlowOrders,
258
267
  splitRelationIds: () => splitRelationIds,
268
+ ssccDigitsOf: () => ssccDigitsOf,
259
269
  ssccUri: () => ssccUri,
260
270
  standsNewOrderRow: () => standsNewOrderRow,
261
271
  stateFieldsOf: () => stateFieldsOf,
@@ -1343,100 +1353,6 @@ function nonWorkingMsIn(calendar, fromMs, toMs, utcOffsetMinutes) {
1343
1353
  return closed * 6e4;
1344
1354
  }
1345
1355
 
1346
- // src/wms-profile.ts
1347
- var BIZSTEP = {
1348
- receiving: "urn:epcglobal:cbv:bizstep:receiving",
1349
- storing: "urn:epcglobal:cbv:bizstep:storing",
1350
- picking: "urn:epcglobal:cbv:bizstep:picking",
1351
- packing: "urn:epcglobal:cbv:bizstep:packing",
1352
- staging_outbound: "urn:epcglobal:cbv:bizstep:staging_outbound",
1353
- shipping: "urn:epcglobal:cbv:bizstep:shipping",
1354
- /**
1355
- * **Replenishment** — moving goods to where they are picked from. CBV has no `replenishing`; this contract
1356
- * wrote one until 2026-09-24, and the closed-list test found it. CBV `stocking` is the step that means it:
1357
- * "…within a location to make an object available to the customer or for order fulfilment within a DC"
1358
- * (CBV ontology, `BizStep-stocking`). Ruled by the chief architect; no reader branches on the value, and
1359
- * the journal keeps what it already wrote (ADR-0038).
1360
- */
1361
- stocking: "urn:epcglobal:cbv:bizstep:stocking",
1362
- /**
1363
- * **Counted, and the book set to the count** — CBV `cycle_counting`. Primary source: the CBV ontology
1364
- * (gs1/EPCIS `Ontology/CBV.ttl`, `cbv:BizStep-cycle_counting`, also served at ref.gs1.org/cbv): "Process of
1365
- * counting objects within a location in order to obtain an accurate inventory for business needs other
1366
- * than accounting purposes (e.g., replenishment and allocation)."
1367
- *
1368
- * **Only for an event somebody actually counted** (chief architect, 2026-09-24). A person correcting the
1369
- * book without counting is `CBV_BIZSTEP.other` with the reason carried as a value — `epcis.ts` says why:
1370
- * writing that as `cycle_counting` records a count that never happened. A count for the accounts is a
1371
- * different CBV step (`stock_taking`) and is not this one.
1372
- */
1373
- cycle_counting: "urn:epcglobal:cbv:bizstep:cycle_counting"
1374
- };
1375
- var BTT = {
1376
- /** Purchase Order — the document an inbound receipt is made against. */
1377
- po: "urn:epcglobal:cbv:btt:po",
1378
- /** Purchase Order Confirmation — the seller's sales order. */
1379
- poc: "urn:epcglobal:cbv:btt:poc",
1380
- /** Despatch Advice (ASN) — announces an inbound delivery; also attached when shipping. */
1381
- desadv: "urn:epcglobal:cbv:btt:desadv",
1382
- /** Receiving Advice — the reply once an inbound receipt is complete. */
1383
- recadv: "urn:epcglobal:cbv:btt:recadv",
1384
- /** Return Merchandise Authorization — what a return is received against. */
1385
- rma: "urn:epcglobal:cbv:btt:rma",
1386
- /** Bill of Lading — the carrier's document, attached when shipping. */
1387
- bol: "urn:epcglobal:cbv:btt:bol"
1388
- };
1389
- var WMS_ORDER_KIND = {
1390
- /**
1391
- * Expected receipt (ASN) — what was promised to arrive, and how much of it has.
1392
- *
1393
- * Flow metrics leave it out: the arrival both raises and fulfils it, so counting it would add a
1394
- * completed order per arrival and never clear the backlog (`isFlowOrder`).
1395
- */
1396
- inbound: "inbound",
1397
- /** Outbound order — what the kernel's sales order is. */
1398
- outbound: "outbound",
1399
- /** Receipt of returned goods. */
1400
- return: "return",
1401
- /** Stock transfer between sites. CBV has no document type for it: carry the id without a type. */
1402
- transfer: "transfer"
1403
- };
1404
- var WMS_RECEIVING_ORDER_KINDS = [WMS_ORDER_KIND.inbound, WMS_ORDER_KIND.return];
1405
- function isFlowOrder(o) {
1406
- const kind = String(o?.kind ?? "").trim();
1407
- return !WMS_RECEIVING_ORDER_KINDS.includes(kind);
1408
- }
1409
- function splitFlowOrders(orders) {
1410
- const flow = [];
1411
- let receiving = 0;
1412
- let kindless = 0;
1413
- for (const o of orders ?? []) {
1414
- const kind = String(o?.kind ?? "").trim();
1415
- if (WMS_RECEIVING_ORDER_KINDS.includes(kind)) {
1416
- receiving++;
1417
- continue;
1418
- }
1419
- if (!kind) kindless++;
1420
- flow.push(o);
1421
- }
1422
- return { flow, receiving, kindless };
1423
- }
1424
- var WMS_LOCATION_TYPES = ["dock", "storage", "staging", "dock-ship", "vas-station"];
1425
- var WMS_LOCATION_LEVEL = {
1426
- dock: "StorageZone",
1427
- storage: "StorageUnit",
1428
- staging: "StorageZone",
1429
- "dock-ship": "StorageZone",
1430
- "vas-station": "WorkCell"
1431
- };
1432
- var WMS_TYPES = [
1433
- ...WMS_LOCATION_TYPES.filter((k) => k !== "vas-station").map((k) => ({ key: k, role: "location", label: `twin.type.${k}`, standardClass: { epcis: "bizLocation" }, identity: { scheme: "gs1:SGLN" }, level: WMS_LOCATION_LEVEL[k], capabilities: ["storable"] })),
1434
- { key: "vas-station", role: "location", label: "twin.type.vas-station", standardClass: { epcis: "bizLocation", isa95: "WorkCenter" }, identity: { scheme: "gs1:SGLN" }, level: WMS_LOCATION_LEVEL["vas-station"], capabilities: ["storable", "processable"] },
1435
- { key: "forklift", role: "equipment", label: "twin.type.forklift", standardClass: { epcis: "object", iso55000: "Asset" }, identity: { scheme: "gs1:GIAI" }, capabilities: ["mobile", "operable"] },
1436
- /** 유통가공 작업자·작업대 설비 — 가공을 수행하는 능동 자원(ISA-95 `Equipment`). */
1437
- { key: "packer", role: "equipment", label: "twin.type.packer", standardClass: { epcis: "object", isa95: "Equipment" }, identity: { scheme: "gs1:GIAI" }, capabilities: ["processable", "operable"] }
1438
- ];
1439
-
1440
1356
  // src/epcis.ts
1441
1357
  var EPCIS_CONTEXT = "https://ref.gs1.org/standards/epcis/2.0.0/epcis-context.jsonld";
1442
1358
  var UTC_OFFSET = "+00:00";
@@ -1505,7 +1421,15 @@ var DISP = {
1505
1421
  * 그때 열되, **판정 자체는 여기서 끝난다.**
1506
1422
  */
1507
1423
  conformant: "urn:epcglobal:cbv:disp:conformant",
1508
- non_conformant: "urn:epcglobal:cbv:disp:non_conformant"
1424
+ non_conformant: "urn:epcglobal:cbv:disp:non_conformant",
1425
+ /**
1426
+ * **Sent back** — CBV `returned`. Primary source: the CBV ontology (gs1/EPCIS `Ontology/CBV.ttl`, versionInfo 2.0,
1427
+ * `cbv:Disp-returned`, read 2026-10-23): "Object has been sent or brought back for various reasons. It may or may not
1428
+ * be sellable." It is what goods going back to their supplier carry when they leave (`RETURN_TO_SUPPLIER`), and what
1429
+ * a customer's return may carry when it arrives. Added for the warehouse's return to supplier (operato-application
1430
+ * ADR-0154 decision 2, ruled: the words before the document).
1431
+ */
1432
+ returned: "urn:epcglobal:cbv:disp:returned"
1509
1433
  };
1510
1434
  var HATIOLAB_VOCABULARY = "https://hatiolab.com/voc/";
1511
1435
  var PRIVATE_BIZSTEP = {
@@ -1631,6 +1555,25 @@ function itemClassOf(uri) {
1631
1555
  }
1632
1556
  return parsed.uri;
1633
1557
  }
1558
+ function materialDefinitionIdOf(epcClass) {
1559
+ const raw = epcClass?.trim();
1560
+ if (!raw) return void 0;
1561
+ const parsed = parseEpc(raw);
1562
+ if (parsed.instance) return void 0;
1563
+ if (parsed.scheme === "lgtin" && parsed.gtinKey) {
1564
+ const [companyPrefix, itemRef] = parsed.gtinKey.split(".");
1565
+ return sgtinClass(companyPrefix, itemRef);
1566
+ }
1567
+ if (parsed.item !== void 0) return parsed.item;
1568
+ const inHouse = /(?:\/class\/|:class:)([^/:\s]+)$/.exec(raw);
1569
+ if (inHouse) {
1570
+ try {
1571
+ return decodeURIComponent(inHouse[1]);
1572
+ } catch {
1573
+ }
1574
+ }
1575
+ return raw;
1576
+ }
1634
1577
  function lotClassOfItem(itemClass, lot) {
1635
1578
  if (!itemClass) return void 0;
1636
1579
  const idpat = /^urn:epc:idpat:sgtin:(\d+)\.(\d+)\.\*$/.exec(itemClass);
@@ -1906,6 +1849,105 @@ function validateEpcisEvent(e) {
1906
1849
  return v;
1907
1850
  }
1908
1851
 
1852
+ // src/wms-profile.ts
1853
+ var BIZSTEP = {
1854
+ receiving: "urn:epcglobal:cbv:bizstep:receiving",
1855
+ storing: "urn:epcglobal:cbv:bizstep:storing",
1856
+ picking: "urn:epcglobal:cbv:bizstep:picking",
1857
+ packing: "urn:epcglobal:cbv:bizstep:packing",
1858
+ staging_outbound: "urn:epcglobal:cbv:bizstep:staging_outbound",
1859
+ shipping: "urn:epcglobal:cbv:bizstep:shipping",
1860
+ /**
1861
+ * **Replenishment** — moving goods to where they are picked from. CBV has no `replenishing`; this contract
1862
+ * wrote one until 2026-09-24, and the closed-list test found it. CBV `stocking` is the step that means it:
1863
+ * "…within a location to make an object available to the customer or for order fulfilment within a DC"
1864
+ * (CBV ontology, `BizStep-stocking`). Ruled by the chief architect; no reader branches on the value, and
1865
+ * the journal keeps what it already wrote (ADR-0038).
1866
+ */
1867
+ stocking: "urn:epcglobal:cbv:bizstep:stocking",
1868
+ /**
1869
+ * **Counted, and the book set to the count** — CBV `cycle_counting`. Primary source: the CBV ontology
1870
+ * (gs1/EPCIS `Ontology/CBV.ttl`, `cbv:BizStep-cycle_counting`, also served at ref.gs1.org/cbv): "Process of
1871
+ * counting objects within a location in order to obtain an accurate inventory for business needs other
1872
+ * than accounting purposes (e.g., replenishment and allocation)."
1873
+ *
1874
+ * **Only for an event somebody actually counted** (chief architect, 2026-09-24). A person correcting the
1875
+ * book without counting is `CBV_BIZSTEP.other` with the reason carried as a value — `epcis.ts` says why:
1876
+ * writing that as `cycle_counting` records a count that never happened. A count for the accounts is a
1877
+ * different CBV step (`stock_taking`) and is not this one.
1878
+ */
1879
+ cycle_counting: "urn:epcglobal:cbv:bizstep:cycle_counting"
1880
+ };
1881
+ var BTT = {
1882
+ /** Purchase Order — the document an inbound receipt is made against. */
1883
+ po: "urn:epcglobal:cbv:btt:po",
1884
+ /** Purchase Order Confirmation — the seller's sales order. */
1885
+ poc: "urn:epcglobal:cbv:btt:poc",
1886
+ /** Despatch Advice (ASN) — announces an inbound delivery; also attached when shipping. */
1887
+ desadv: "urn:epcglobal:cbv:btt:desadv",
1888
+ /** Receiving Advice — the reply once an inbound receipt is complete. */
1889
+ recadv: "urn:epcglobal:cbv:btt:recadv",
1890
+ /** Return Merchandise Authorization — what a return is received against. */
1891
+ rma: "urn:epcglobal:cbv:btt:rma",
1892
+ /** Bill of Lading — the carrier's document, attached when shipping. */
1893
+ bol: "urn:epcglobal:cbv:btt:bol"
1894
+ };
1895
+ var RETURN_TO_SUPPLIER = {
1896
+ bizStep: BIZSTEP.shipping,
1897
+ disposition: DISP.returned,
1898
+ bizTransactionType: BTT.rma
1899
+ };
1900
+ var WMS_ORDER_KIND = {
1901
+ /**
1902
+ * Expected receipt (ASN) — what was promised to arrive, and how much of it has.
1903
+ *
1904
+ * Flow metrics leave it out: the arrival both raises and fulfils it, so counting it would add a
1905
+ * completed order per arrival and never clear the backlog (`isFlowOrder`).
1906
+ */
1907
+ inbound: "inbound",
1908
+ /** Outbound order — what the kernel's sales order is. */
1909
+ outbound: "outbound",
1910
+ /** Receipt of returned goods. */
1911
+ return: "return",
1912
+ /** Stock transfer between sites. CBV has no document type for it: carry the id without a type. */
1913
+ transfer: "transfer"
1914
+ };
1915
+ var WMS_RECEIVING_ORDER_KINDS = [WMS_ORDER_KIND.inbound, WMS_ORDER_KIND.return];
1916
+ function isFlowOrder(o) {
1917
+ const kind = String(o?.kind ?? "").trim();
1918
+ return !WMS_RECEIVING_ORDER_KINDS.includes(kind);
1919
+ }
1920
+ function splitFlowOrders(orders) {
1921
+ const flow = [];
1922
+ let receiving = 0;
1923
+ let kindless = 0;
1924
+ for (const o of orders ?? []) {
1925
+ const kind = String(o?.kind ?? "").trim();
1926
+ if (WMS_RECEIVING_ORDER_KINDS.includes(kind)) {
1927
+ receiving++;
1928
+ continue;
1929
+ }
1930
+ if (!kind) kindless++;
1931
+ flow.push(o);
1932
+ }
1933
+ return { flow, receiving, kindless };
1934
+ }
1935
+ var WMS_LOCATION_TYPES = ["dock", "storage", "staging", "dock-ship", "vas-station"];
1936
+ var WMS_LOCATION_LEVEL = {
1937
+ dock: "StorageZone",
1938
+ storage: "StorageUnit",
1939
+ staging: "StorageZone",
1940
+ "dock-ship": "StorageZone",
1941
+ "vas-station": "WorkCell"
1942
+ };
1943
+ var WMS_TYPES = [
1944
+ ...WMS_LOCATION_TYPES.filter((k) => k !== "vas-station").map((k) => ({ key: k, role: "location", label: `twin.type.${k}`, standardClass: { epcis: "bizLocation" }, identity: { scheme: "gs1:SGLN" }, level: WMS_LOCATION_LEVEL[k], capabilities: ["storable"] })),
1945
+ { key: "vas-station", role: "location", label: "twin.type.vas-station", standardClass: { epcis: "bizLocation", isa95: "WorkCenter" }, identity: { scheme: "gs1:SGLN" }, level: WMS_LOCATION_LEVEL["vas-station"], capabilities: ["storable", "processable"] },
1946
+ { key: "forklift", role: "equipment", label: "twin.type.forklift", standardClass: { epcis: "object", iso55000: "Asset" }, identity: { scheme: "gs1:GIAI" }, capabilities: ["mobile", "operable"] },
1947
+ /** 유통가공 작업자·작업대 설비 — 가공을 수행하는 능동 자원(ISA-95 `Equipment`). */
1948
+ { key: "packer", role: "equipment", label: "twin.type.packer", standardClass: { epcis: "object", isa95: "Equipment" }, identity: { scheme: "gs1:GIAI" }, capabilities: ["processable", "operable"] }
1949
+ ];
1950
+
1909
1951
  // src/yms-profile.ts
1910
1952
  var YARD_BIZSTEP = {
1911
1953
  arriving: "urn:epcglobal:cbv:bizstep:arriving",
@@ -3413,6 +3455,181 @@ function ingestEnergyBillRecords(records, opts) {
3413
3455
  return { accepted, rejected };
3414
3456
  }
3415
3457
 
3458
+ // src/gs1.ts
3459
+ var FNC1 = "";
3460
+ var FIXED_LENGTH = {
3461
+ "00": 18,
3462
+ // SSCC
3463
+ "01": 14,
3464
+ // GTIN
3465
+ "02": 14,
3466
+ // 포장 안 품목의 GTIN
3467
+ "11": 6,
3468
+ // 생산일
3469
+ "12": 6,
3470
+ // 지급기일
3471
+ "13": 6,
3472
+ // 포장일
3473
+ "15": 6,
3474
+ // 품질유지기한
3475
+ "16": 6,
3476
+ // 판매기한
3477
+ "17": 6,
3478
+ // 사용기한
3479
+ "20": 2,
3480
+ // 제품 변형
3481
+ "414": 13
3482
+ // 물리적 위치의 GLN
3483
+ };
3484
+ var KNOWN_VARIABLE = ["10", "21", "30", "254"];
3485
+ function isBracketed(value) {
3486
+ return /^\(\d{2,4}\)/.test(value);
3487
+ }
3488
+ function parseGs1(value) {
3489
+ const raw = value;
3490
+ if (!raw?.trim()) {
3491
+ return { ok: false, because: "not-gs1", raw };
3492
+ }
3493
+ const parsed = isBracketed(raw) ? fromBracketed(raw) : fromRaw(raw);
3494
+ if (!parsed.ok) {
3495
+ return parsed;
3496
+ }
3497
+ const found = parsed.elements;
3498
+ const count = found["30"] !== void 0 ? Number(found["30"]) : void 0;
3499
+ return {
3500
+ ok: true,
3501
+ scan: {
3502
+ sscc: found["00"],
3503
+ gln: found["414"],
3504
+ glnExtension: found["254"],
3505
+ gtin: found["01"],
3506
+ lot: found["10"],
3507
+ serial: found["21"],
3508
+ useBy: found["17"],
3509
+ /* 숫자가 아니면 담지 않는다 — `NaN` 을 수량으로 두면 더하는 쪽에서 합계가 통째로 사라진다. */
3510
+ count: count !== void 0 && Number.isFinite(count) ? count : void 0,
3511
+ elements: found,
3512
+ raw
3513
+ }
3514
+ };
3515
+ }
3516
+ function fromBracketed(raw) {
3517
+ const elements = {};
3518
+ const pattern = /\((\d{2,4})\)([^(]*)/g;
3519
+ let match;
3520
+ let consumed = 0;
3521
+ while ((match = pattern.exec(raw)) !== null) {
3522
+ const ai = match[1];
3523
+ const value = match[2].trim();
3524
+ const fixed = FIXED_LENGTH[ai];
3525
+ if (fixed !== void 0 && value.length !== fixed) {
3526
+ return { ok: false, because: value.length < fixed ? "truncated" : "unterminated", raw };
3527
+ }
3528
+ elements[ai] = value;
3529
+ consumed = match.index + match[0].length;
3530
+ }
3531
+ if (!Object.keys(elements).length || consumed !== raw.length) {
3532
+ return { ok: false, because: "not-gs1", raw };
3533
+ }
3534
+ return { ok: true, elements };
3535
+ }
3536
+ function fromRaw(raw) {
3537
+ const elements = {};
3538
+ let rest = raw;
3539
+ while (rest.length) {
3540
+ if (rest.startsWith(FNC1)) {
3541
+ rest = rest.slice(1);
3542
+ continue;
3543
+ }
3544
+ const ai = aiAt(rest);
3545
+ if (!ai) {
3546
+ return { ok: false, because: Object.keys(elements).length ? "unterminated" : "not-gs1", raw };
3547
+ }
3548
+ rest = rest.slice(ai.length);
3549
+ const fixed = FIXED_LENGTH[ai];
3550
+ if (fixed !== void 0) {
3551
+ if (rest.length < fixed) {
3552
+ return { ok: false, because: "truncated", raw };
3553
+ }
3554
+ const value = rest.slice(0, fixed);
3555
+ if (value.includes(FNC1)) {
3556
+ return { ok: false, because: "truncated", raw };
3557
+ }
3558
+ elements[ai] = value;
3559
+ rest = rest.slice(fixed);
3560
+ continue;
3561
+ }
3562
+ const end = rest.indexOf(FNC1);
3563
+ elements[ai] = end === -1 ? rest : rest.slice(0, end);
3564
+ rest = end === -1 ? "" : rest.slice(end + 1);
3565
+ }
3566
+ return Object.keys(elements).length ? { ok: true, elements } : { ok: false, because: "not-gs1", raw };
3567
+ }
3568
+ function aiAt(rest) {
3569
+ const two = rest.slice(0, 2);
3570
+ if (!/^\d{2}$/.test(two)) {
3571
+ return void 0;
3572
+ }
3573
+ if (FIXED_LENGTH[two] !== void 0 || KNOWN_VARIABLE.includes(two)) {
3574
+ return two;
3575
+ }
3576
+ const three = rest.slice(0, 3);
3577
+ if (/^\d{3}$/.test(three) && (FIXED_LENGTH[three] !== void 0 || KNOWN_VARIABLE.includes(three))) {
3578
+ return three;
3579
+ }
3580
+ const four = rest.slice(0, 4);
3581
+ return /^\d{4}$/.test(four) ? four : two;
3582
+ }
3583
+ function checkDigitOf(body) {
3584
+ const sum = [...body].reverse().reduce((total, digit, at2) => total + Number(digit) * (at2 % 2 === 0 ? 3 : 1), 0);
3585
+ return String((10 - sum % 10) % 10);
3586
+ }
3587
+ function wellFormed(digits, length) {
3588
+ return !!digits && digits.length === length && /^\d+$/.test(digits) && checkDigitOf(digits.slice(0, -1)) === digits.slice(-1);
3589
+ }
3590
+ var PREFIX_LENGTHS = [6, 7, 8, 9, 10, 11, 12];
3591
+ function epcCandidatesOfGs1(scan) {
3592
+ const out = [];
3593
+ if (wellFormed(scan.sscc, 18)) {
3594
+ const d = scan.sscc;
3595
+ for (const l of PREFIX_LENGTHS) out.push(`urn:epc:id:sscc:${d.slice(1, 1 + l)}.${d[0]}${d.slice(1 + l, 17)}`);
3596
+ }
3597
+ if (wellFormed(scan.gtin, 14)) {
3598
+ const d = scan.gtin;
3599
+ for (const l of PREFIX_LENGTHS) {
3600
+ const prefix = d.slice(1, 1 + l);
3601
+ const itemRefAndIndicator = d[0] + d.slice(1 + l, 13);
3602
+ out.push(scan.lot ? lgtinClass(prefix, itemRefAndIndicator, scan.lot) : sgtinClass(prefix, itemRefAndIndicator));
3603
+ }
3604
+ }
3605
+ if (wellFormed(scan.gln, 13)) {
3606
+ const d = scan.gln;
3607
+ for (const l of PREFIX_LENGTHS) out.push(`urn:epc:id:sgln:${d.slice(0, l)}.${d.slice(l, 12)}.${scan.glnExtension || "0"}`);
3608
+ }
3609
+ return out;
3610
+ }
3611
+ function ssccDigitsOf(uri) {
3612
+ const match = /^urn:epc:id:sscc:(\d+)\.(\d+)$/.exec(uri ?? "");
3613
+ if (!match) return void 0;
3614
+ const [, prefix, reference] = match;
3615
+ const body = reference[0] + prefix + reference.slice(1);
3616
+ if (body.length !== 17) return void 0;
3617
+ return body + checkDigitOf(body);
3618
+ }
3619
+ function gtin14OfItemClass(definitionId) {
3620
+ const match = /^urn:epc:idpat:sgtin:(\d+)\.(\d+)\.\*$/.exec(definitionId ?? "");
3621
+ if (!match) return void 0;
3622
+ const [, prefix, reference] = match;
3623
+ const body = reference[0] + prefix + reference.slice(1);
3624
+ if (body.length !== 13) return void 0;
3625
+ return body + checkDigitOf(body);
3626
+ }
3627
+ function gtin14OfItem(definitionId) {
3628
+ const byClass = gtin14OfItemClass(definitionId);
3629
+ if (byClass) return byClass;
3630
+ return /^(\d{8}|\d{12,14})$/.test(definitionId ?? "") ? definitionId.padStart(14, "0") : void 0;
3631
+ }
3632
+
3416
3633
  // src/order-fold.ts
3417
3634
  var ORDER_FOLD_HOUR_MS = 60 * 60 * 1e3;
3418
3635
  var ORDER_FOLD_DEFAULT = Object.freeze({ afterMs: 24 * 60 * 60 * 1e3, maxTerminal: 1e3 });
@@ -4987,15 +5204,27 @@ function reversalKey(performanceKey2) {
4987
5204
  if (!String(performanceKey2 ?? "").trim()) throw new Error("reversalKey: \uB418\uB3CC\uB9B4 \uC2E4\uC801\uC758 \uD0A4\uAC00 \uC5C6\uB2E4");
4988
5205
  return `${performanceKey2}|reversal`;
4989
5206
  }
4990
- var ERP_CAPABILITY = ["schedule", "performance", "material-movement", "reversal", "master"];
5207
+ var ERP_CAPABILITY = [
5208
+ "schedule",
5209
+ "performance",
5210
+ "material-movement",
5211
+ "reversal",
5212
+ "master",
5213
+ "performance-read",
5214
+ "inventory-read"
5215
+ ];
4991
5216
  var ERP_MASTER_AXIS = ["product", "bom", "routing", "work-center"];
4992
5217
  function erpCapabilityGaps(adapter) {
5218
+ const manual = adapter.traits?.posting === "manual-export";
4993
5219
  const needs = {
4994
5220
  schedule: "readSchedules",
4995
- performance: "postPerformance",
5221
+ /* 사람이 반영하는 ERP 에서 「실적을 올린다」는 묶음을 만드는 것이다. */
5222
+ performance: manual ? "exportPerformance" : "postPerformance",
4996
5223
  "material-movement": "postMaterialMovement",
4997
5224
  reversal: "reversePerformance",
4998
- master: "readMaster"
5225
+ master: "readMaster",
5226
+ "performance-read": "readPerformance",
5227
+ "inventory-read": "readInventory"
4999
5228
  };
5000
5229
  const gaps = [];
5001
5230
  for (const cap of adapter.capabilities ?? []) {
@@ -5011,6 +5240,20 @@ function erpCapabilityGaps(adapter) {
5011
5240
  if (adapter.traits?.materialWithPerformance && typeof adapter.postMaterialMovement === "function") {
5012
5241
  gaps.push("traits.materialWithPerformance \uAC00 \uCC38\uC778\uB370 postMaterialMovement \uAC00 \uB530\uB85C \uC788\uB2E4 \u2014 \uC18C\uBE44\uAC00 \uB450 \uBC88 \uC549\uB294\uB2E4");
5013
5242
  }
5243
+ if (manual) {
5244
+ if (typeof adapter.postPerformance === "function") {
5245
+ gaps.push("traits.posting \uC774 manual-export \uC778\uB370 postPerformance \uAC00 \uC788\uB2E4 \u2014 \uBD80\uB974\uBA74 \uC549\uB294 ERP \uAC00 \uC544\uB2C8\uB2E4");
5246
+ }
5247
+ if (typeof adapter.postMaterialMovement === "function") {
5248
+ gaps.push("traits.posting \uC774 manual-export \uC778\uB370 postMaterialMovement \uAC00 \uC788\uB2E4");
5249
+ }
5250
+ if (adapter.capabilities?.includes("material-movement")) {
5251
+ gaps.push("traits.posting \uC774 manual-export \uC778\uB370 material-movement \uB2A5\uB825\uC744 \uC120\uC5B8\uD588\uB2E4");
5252
+ }
5253
+ }
5254
+ if (adapter.traits?.posting !== "api" && adapter.traits?.posting !== "manual-export") {
5255
+ 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");
5256
+ }
5014
5257
  return gaps;
5015
5258
  }
5016
5259
 
@@ -5117,6 +5360,41 @@ function isOperationalFactReference(value) {
5117
5360
  function nonEmpty(value) {
5118
5361
  return typeof value === "string" && value.trim().length > 0;
5119
5362
  }
5363
+
5364
+ // src/lot-lineage.ts
5365
+ function lotLineageOf(event, classOfUnit) {
5366
+ if (event.type !== "TransformationEvent") return [];
5367
+ const inputs = /* @__PURE__ */ new Set();
5368
+ for (const epc of event.inputEPCList ?? []) {
5369
+ const lot = classOfUnit(epc);
5370
+ if (lot) inputs.add(lot);
5371
+ }
5372
+ for (const one of event.inputQuantityList ?? []) if (one.epcClass) inputs.add(one.epcClass);
5373
+ const edges = [];
5374
+ for (const lot of new Set((event.outputQuantityList ?? []).map((one) => one.epcClass).filter(Boolean))) {
5375
+ for (const input of inputs) if (input !== lot) edges.push({ lot, input });
5376
+ }
5377
+ return edges;
5378
+ }
5379
+ function inheritedLotUse(lot, said, inputsOf, seen = /* @__PURE__ */ new Set()) {
5380
+ const own = said.get(lot);
5381
+ if (own?.use === "blocked") return { use: "blocked", status: own.status };
5382
+ const along = /* @__PURE__ */ new Set([...seen, lot]);
5383
+ const words = (inputsOf.get(lot) ?? []).filter((input) => !along.has(input)).map((input) => ({ input, word: inheritedLotUse(input, said, inputsOf, along) }));
5384
+ const blocked = words.find(({ word }) => word?.use === "blocked");
5385
+ if (blocked) return { use: "blocked", ...blocked.word.status !== void 0 ? { status: blocked.word.status } : {}, from: blocked.word.from ?? blocked.input };
5386
+ if (own?.use === "allowed") return { use: "allowed", status: own.status };
5387
+ if (!own && words.length && words.every(({ word }) => word?.use === "allowed")) return { use: "allowed" };
5388
+ return void 0;
5389
+ }
5390
+ function inheritedExpiry(inputExpiries) {
5391
+ let earliest;
5392
+ for (const at2 of inputExpiries) {
5393
+ if (typeof at2 !== "number" || !Number.isFinite(at2)) continue;
5394
+ if (earliest === void 0 || at2 < earliest) earliest = at2;
5395
+ }
5396
+ return earliest;
5397
+ }
5120
5398
  // Annotate the CommonJS export names for ESM import in node:
5121
5399
  0 && (module.exports = {
5122
5400
  ABSENCE,
@@ -5177,6 +5455,7 @@ function nonEmpty(value) {
5177
5455
  REFUSED_WITHOUT_CODE,
5178
5456
  RESOURCE_KIND,
5179
5457
  RETIRED_VOCABULARY,
5458
+ RETURN_TO_SUPPLIER,
5180
5459
  SCHEDULE_STATUS,
5181
5460
  SIGNATURE_REJECTED_REASONS,
5182
5461
  TWIN_AXES,
@@ -5237,6 +5516,7 @@ function nonEmpty(value) {
5237
5516
  effectivityAt,
5238
5517
  electricalUpstreamOf,
5239
5518
  emptyFoldedOrders,
5519
+ epcCandidatesOfGs1,
5240
5520
  equipmentClassMembership,
5241
5521
  erpCapabilityGaps,
5242
5522
  expiryFromAttributes,
@@ -5248,6 +5528,8 @@ function nonEmpty(value) {
5248
5528
  generationFractionAt,
5249
5529
  graiUri,
5250
5530
  gs1KeyDigitViolation,
5531
+ gtin14OfItem,
5532
+ gtin14OfItemClass,
5251
5533
  hierarchyOf,
5252
5534
  homeOf,
5253
5535
  hourStartOf,
@@ -5265,6 +5547,8 @@ function nonEmpty(value) {
5265
5547
  ingestEnergyUsagePeriodRecords,
5266
5548
  ingestMasterData,
5267
5549
  ingestOperationalRecords,
5550
+ inheritedExpiry,
5551
+ inheritedLotUse,
5268
5552
  isAggregationRecord,
5269
5553
  isCacheableTense,
5270
5554
  isCommandTerminal,
@@ -5307,8 +5591,10 @@ function nonEmpty(value) {
5307
5591
  lotClassOfItem,
5308
5592
  lotClassUri,
5309
5593
  lotFromAttributes,
5594
+ lotLineageOf,
5310
5595
  mapRecord,
5311
5596
  mapRecordChecked,
5597
+ materialDefinitionIdOf,
5312
5598
  materialMovementKey,
5313
5599
  meetsTests,
5314
5600
  minuteOfDayAt,
@@ -5327,6 +5613,7 @@ function nonEmpty(value) {
5327
5613
  orderFoldPolicyOf,
5328
5614
  outsideLimit,
5329
5615
  parseEpc,
5616
+ parseGs1,
5330
5617
  parseIsoDuration,
5331
5618
  partitionLensLocations,
5332
5619
  passThroughReversible,
@@ -5356,6 +5643,7 @@ function nonEmpty(value) {
5356
5643
  sgtinUri,
5357
5644
  splitFlowOrders,
5358
5645
  splitRelationIds,
5646
+ ssccDigitsOf,
5359
5647
  ssccUri,
5360
5648
  standsNewOrderRow,
5361
5649
  stateFieldsOf,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@operato/ops-contract",
3
- "version": "0.9.40",
3
+ "version": "0.9.42",
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",