@operato/ops-contract 0.9.34 → 0.9.35
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/epcis.d.ts +30 -0
- package/dist/epcis.js +67 -0
- package/dist/scenario-validate.js +8 -0
- package/dist-cjs/index.cjs +40 -0
- package/package.json +1 -1
package/dist/epcis.d.ts
CHANGED
|
@@ -360,6 +360,36 @@ export interface ParsedEpc {
|
|
|
360
360
|
* 로트를 SKU 이름으로 표시할 위험이 있었다). 뜯는 일은 여기 한 곳에서 한다.
|
|
361
361
|
*/
|
|
362
362
|
export declare function parseEpc(uri: string): ParsedEpc;
|
|
363
|
+
/**
|
|
364
|
+
* **이 클래스의 품목 클래스** — 로트 클래스면 로트를 뗀 품목 클래스, 그 밖은 원문 그대로.
|
|
365
|
+
*
|
|
366
|
+
* ── 왜 필요한가 (2026-09-24, ADR-0076 ⑥ · ADR-0082 결정 2) ────────────────────
|
|
367
|
+
* 오더 줄은 **품목**을 달라고 하고(`urn:epc:idpat:sgtin:P.R.*` · `<ns>/class/<품번>`), 재고는 **로트**를 든다
|
|
368
|
+
* (`urn:epc:class:lgtin:P.R.L` · `<ns>/class/<품번>;lot=<로트>`). 글자로 견주면 로트 재고가 오더에 한 건도 안 잡히고
|
|
369
|
+
* 출고가 오류 없이 0 이 된다. 견주는 곳은 `sameItemClass` 하나다.
|
|
370
|
+
*
|
|
371
|
+
* LGTIN → `urn:epc:idpat:sgtin:<gtinKey>.*`
|
|
372
|
+
* 사내 로트 클래스 → 같은 이름공간의 `classUri` 모양 품목 클래스(품번을 `classUri` 의 규칙으로 다시 부호화)
|
|
373
|
+
* 그 밖(품목 클래스 · 개체 · 모르는 모양) → 원문 그대로 — 추측해서 묶지 않는다
|
|
374
|
+
*/
|
|
375
|
+
export declare function itemClassOf(uri: string | undefined): string | undefined;
|
|
376
|
+
/**
|
|
377
|
+
* **이 품목 클래스의 그 로트** — `itemClassOf` 의 반대 방향. 시뮬의 도착 생성기처럼 품목 클래스만 들고 있는 곳이 부른다.
|
|
378
|
+
*
|
|
379
|
+
* `urn:epc:idpat:sgtin:P.R.*` → `lotClassUri({ gtin: 'P.R', lot })` — 자리 수가 틀리면 던진다
|
|
380
|
+
* `<ns>/class/<품번>` · `<ns>:class:<품번>` → `lotClassUri({ namespace: <ns>, item: <품번>, lot })`
|
|
381
|
+
* 그 밖(개체 · 이미 로트인 클래스 · 모르는 모양) → `undefined` — 로트를 붙일 자리를 지어내지 않는다
|
|
382
|
+
*
|
|
383
|
+
* 성립하는 것: `itemClassOf(lotClassOfItem(c, lot)) === c` (시험 `item-class`).
|
|
384
|
+
*/
|
|
385
|
+
export declare function lotClassOfItem(itemClass: string | undefined, lot: string): string | undefined;
|
|
386
|
+
/**
|
|
387
|
+
* **같은 품목인가** — 오더 줄과 재고를 맞추는 곳은 전부 이것을 부른다.
|
|
388
|
+
*
|
|
389
|
+
* 한 곳에서 거른다. 맞춤 자리마다 `itemClassOf(a) === itemClassOf(b)` 를 적으면 다음에 로트 철자가 바뀔 때
|
|
390
|
+
* 하나가 남는다. 어느 쪽이든 비어 있으면 같지 않다 — 「모름」을 같은 품목으로 읽지 않는다.
|
|
391
|
+
*/
|
|
392
|
+
export declare function sameItemClass(a: string | undefined, b: string | undefined): boolean;
|
|
363
393
|
/** 거래문서 식별자 = GDTI (PO/SO/WO/어포인트먼트 등). */
|
|
364
394
|
export declare function gdtiUri(companyPrefix: string, docType: string, serial: number): string;
|
|
365
395
|
/**
|
package/dist/epcis.js
CHANGED
|
@@ -243,6 +243,73 @@ function decodedPair(item, lot) {
|
|
|
243
243
|
return undefined;
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* **이 클래스의 품목 클래스** — 로트 클래스면 로트를 뗀 품목 클래스, 그 밖은 원문 그대로.
|
|
248
|
+
*
|
|
249
|
+
* ── 왜 필요한가 (2026-09-24, ADR-0076 ⑥ · ADR-0082 결정 2) ────────────────────
|
|
250
|
+
* 오더 줄은 **품목**을 달라고 하고(`urn:epc:idpat:sgtin:P.R.*` · `<ns>/class/<품번>`), 재고는 **로트**를 든다
|
|
251
|
+
* (`urn:epc:class:lgtin:P.R.L` · `<ns>/class/<품번>;lot=<로트>`). 글자로 견주면 로트 재고가 오더에 한 건도 안 잡히고
|
|
252
|
+
* 출고가 오류 없이 0 이 된다. 견주는 곳은 `sameItemClass` 하나다.
|
|
253
|
+
*
|
|
254
|
+
* LGTIN → `urn:epc:idpat:sgtin:<gtinKey>.*`
|
|
255
|
+
* 사내 로트 클래스 → 같은 이름공간의 `classUri` 모양 품목 클래스(품번을 `classUri` 의 규칙으로 다시 부호화)
|
|
256
|
+
* 그 밖(품목 클래스 · 개체 · 모르는 모양) → 원문 그대로 — 추측해서 묶지 않는다
|
|
257
|
+
*/
|
|
258
|
+
export function itemClassOf(uri) {
|
|
259
|
+
if (!uri)
|
|
260
|
+
return undefined;
|
|
261
|
+
const parsed = parseEpc(uri);
|
|
262
|
+
if (parsed.scheme === 'lgtin' && parsed.gtinKey)
|
|
263
|
+
return `urn:epc:idpat:sgtin:${parsed.gtinKey}.*`;
|
|
264
|
+
if (parsed.item !== undefined) {
|
|
265
|
+
const marker = /^(.*(?:\/class\/|:class:))[^/:\s]+$/.exec(parsed.uri);
|
|
266
|
+
if (marker)
|
|
267
|
+
return `${marker[1]}${parsed.item.replace(STRUCTURE_BREAKING, c => PERCENT_ENCODED[c])}`;
|
|
268
|
+
}
|
|
269
|
+
return parsed.uri;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* **이 품목 클래스의 그 로트** — `itemClassOf` 의 반대 방향. 시뮬의 도착 생성기처럼 품목 클래스만 들고 있는 곳이 부른다.
|
|
273
|
+
*
|
|
274
|
+
* `urn:epc:idpat:sgtin:P.R.*` → `lotClassUri({ gtin: 'P.R', lot })` — 자리 수가 틀리면 던진다
|
|
275
|
+
* `<ns>/class/<품번>` · `<ns>:class:<품번>` → `lotClassUri({ namespace: <ns>, item: <품번>, lot })`
|
|
276
|
+
* 그 밖(개체 · 이미 로트인 클래스 · 모르는 모양) → `undefined` — 로트를 붙일 자리를 지어내지 않는다
|
|
277
|
+
*
|
|
278
|
+
* 성립하는 것: `itemClassOf(lotClassOfItem(c, lot)) === c` (시험 `item-class`).
|
|
279
|
+
*/
|
|
280
|
+
export function lotClassOfItem(itemClass, lot) {
|
|
281
|
+
if (!itemClass)
|
|
282
|
+
return undefined;
|
|
283
|
+
const idpat = /^urn:epc:idpat:sgtin:(\d+)\.(\d+)\.\*$/.exec(itemClass);
|
|
284
|
+
if (idpat)
|
|
285
|
+
return lotClassUri({ namespace: '', item: '', lot, gtin: `${idpat[1]}.${idpat[2]}` });
|
|
286
|
+
const parsed = parseEpc(itemClass);
|
|
287
|
+
if (parsed.instance || parsed.lot !== undefined)
|
|
288
|
+
return undefined;
|
|
289
|
+
const url = /^(https?:\/\/.+)\/class\/([^/:\s]+)$/.exec(itemClass);
|
|
290
|
+
const urn = /^(urn:.+):class:([^/:\s]+)$/.exec(itemClass);
|
|
291
|
+
const at = url ?? urn;
|
|
292
|
+
if (!at)
|
|
293
|
+
return undefined;
|
|
294
|
+
let item;
|
|
295
|
+
try {
|
|
296
|
+
item = decodeURIComponent(at[2]);
|
|
297
|
+
}
|
|
298
|
+
catch {
|
|
299
|
+
return undefined;
|
|
300
|
+
}
|
|
301
|
+
return lotClassUri({ namespace: at[1], item, lot });
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* **같은 품목인가** — 오더 줄과 재고를 맞추는 곳은 전부 이것을 부른다.
|
|
305
|
+
*
|
|
306
|
+
* 한 곳에서 거른다. 맞춤 자리마다 `itemClassOf(a) === itemClassOf(b)` 를 적으면 다음에 로트 철자가 바뀔 때
|
|
307
|
+
* 하나가 남는다. 어느 쪽이든 비어 있으면 같지 않다 — 「모름」을 같은 품목으로 읽지 않는다.
|
|
308
|
+
*/
|
|
309
|
+
export function sameItemClass(a, b) {
|
|
310
|
+
const x = itemClassOf(a);
|
|
311
|
+
return x !== undefined && x === itemClassOf(b);
|
|
312
|
+
}
|
|
246
313
|
/** 거래문서 식별자 = GDTI (PO/SO/WO/어포인트먼트 등). */
|
|
247
314
|
export function gdtiUri(companyPrefix, docType, serial) {
|
|
248
315
|
return `urn:epc:id:gdti:${companyPrefix}.${docType}.${serial}`;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { gs1KeyDigitViolation } from "./epcis.js";
|
|
1
2
|
const DISTRIBUTIONS = new Set(['poisson', 'uniform', 'constant', 'profile']);
|
|
2
3
|
const isNum = (v) => typeof v === 'number' && Number.isFinite(v);
|
|
3
4
|
const bad = (errorCode, errorParams) => ({ ok: false, errorCode, errorParams });
|
|
@@ -27,6 +28,13 @@ function validateGenerator(g, at) {
|
|
|
27
28
|
for (const s of content.skuMix) {
|
|
28
29
|
if (!s?.gtin || typeof s.gtin !== 'string')
|
|
29
30
|
return bad('scenario-sku-gtin-required', { at, kind: g.kind });
|
|
31
|
+
/*
|
|
32
|
+
* 자리 수가 틀린 GTIN 은 선언에서 거절한다(2026-09-24). 도착 생성기가 이 품목으로 로트 클래스를 만들 때
|
|
33
|
+
* 계약이 던지므로(`lotClassUri`), 여기서 거르지 않으면 시뮬이 도중에 멈춘다 — 선언이 틀린 것은 선언에서 말한다.
|
|
34
|
+
*/
|
|
35
|
+
const digits = gs1KeyDigitViolation(s.gtin);
|
|
36
|
+
if (digits)
|
|
37
|
+
return bad('scenario-sku-gtin-digits', { at, kind: g.kind, gtin: s.gtin, reason: digits });
|
|
30
38
|
if (!isNum(s.weight) || s.weight <= 0)
|
|
31
39
|
return bad('scenario-sku-weight-invalid', { at, kind: g.kind, gtin: String(s.gtin) });
|
|
32
40
|
}
|
package/dist-cjs/index.cjs
CHANGED
|
@@ -183,6 +183,7 @@ __export(index_exports, {
|
|
|
183
183
|
isWebhookSecretSegment: () => isWebhookSecretSegment,
|
|
184
184
|
isWorkShiftExecutionBasis: () => isWorkShiftExecutionBasis,
|
|
185
185
|
isoDurationHours: () => isoDurationHours,
|
|
186
|
+
itemClassOf: () => itemClassOf,
|
|
186
187
|
itemKeyOf: () => itemKeyOf,
|
|
187
188
|
judgeAgainstSpec: () => judgeAgainstSpec,
|
|
188
189
|
levelOfLocationType: () => levelOfLocationType,
|
|
@@ -190,6 +191,7 @@ __export(index_exports, {
|
|
|
190
191
|
localDayIndexAt: () => localDayIndexAt,
|
|
191
192
|
localDayStartMs: () => localDayStartMs,
|
|
192
193
|
locationStatusOf: () => locationStatusOf,
|
|
194
|
+
lotClassOfItem: () => lotClassOfItem,
|
|
193
195
|
lotClassUri: () => lotClassUri,
|
|
194
196
|
lotFromAttributes: () => lotFromAttributes,
|
|
195
197
|
mapRecord: () => mapRecord,
|
|
@@ -231,6 +233,7 @@ __export(index_exports, {
|
|
|
231
233
|
retiredVocabularyIn: () => retiredVocabularyIn,
|
|
232
234
|
reversalKey: () => reversalKey,
|
|
233
235
|
rolledThroughputYield: () => rolledThroughputYield,
|
|
236
|
+
sameItemClass: () => sameItemClass,
|
|
234
237
|
sgtinClass: () => sgtinClass,
|
|
235
238
|
sgtinUri: () => sgtinUri,
|
|
236
239
|
splitFlowOrders: () => splitFlowOrders,
|
|
@@ -3060,6 +3063,38 @@ function decodedPair(item, lot) {
|
|
|
3060
3063
|
return void 0;
|
|
3061
3064
|
}
|
|
3062
3065
|
}
|
|
3066
|
+
function itemClassOf(uri) {
|
|
3067
|
+
if (!uri) return void 0;
|
|
3068
|
+
const parsed = parseEpc(uri);
|
|
3069
|
+
if (parsed.scheme === "lgtin" && parsed.gtinKey) return `urn:epc:idpat:sgtin:${parsed.gtinKey}.*`;
|
|
3070
|
+
if (parsed.item !== void 0) {
|
|
3071
|
+
const marker = /^(.*(?:\/class\/|:class:))[^/:\s]+$/.exec(parsed.uri);
|
|
3072
|
+
if (marker) return `${marker[1]}${parsed.item.replace(STRUCTURE_BREAKING, (c) => PERCENT_ENCODED[c])}`;
|
|
3073
|
+
}
|
|
3074
|
+
return parsed.uri;
|
|
3075
|
+
}
|
|
3076
|
+
function lotClassOfItem(itemClass, lot) {
|
|
3077
|
+
if (!itemClass) return void 0;
|
|
3078
|
+
const idpat = /^urn:epc:idpat:sgtin:(\d+)\.(\d+)\.\*$/.exec(itemClass);
|
|
3079
|
+
if (idpat) return lotClassUri({ namespace: "", item: "", lot, gtin: `${idpat[1]}.${idpat[2]}` });
|
|
3080
|
+
const parsed = parseEpc(itemClass);
|
|
3081
|
+
if (parsed.instance || parsed.lot !== void 0) return void 0;
|
|
3082
|
+
const url = /^(https?:\/\/.+)\/class\/([^/:\s]+)$/.exec(itemClass);
|
|
3083
|
+
const urn = /^(urn:.+):class:([^/:\s]+)$/.exec(itemClass);
|
|
3084
|
+
const at2 = url ?? urn;
|
|
3085
|
+
if (!at2) return void 0;
|
|
3086
|
+
let item;
|
|
3087
|
+
try {
|
|
3088
|
+
item = decodeURIComponent(at2[2]);
|
|
3089
|
+
} catch {
|
|
3090
|
+
return void 0;
|
|
3091
|
+
}
|
|
3092
|
+
return lotClassUri({ namespace: at2[1], item, lot });
|
|
3093
|
+
}
|
|
3094
|
+
function sameItemClass(a, b) {
|
|
3095
|
+
const x = itemClassOf(a);
|
|
3096
|
+
return x !== void 0 && x === itemClassOf(b);
|
|
3097
|
+
}
|
|
3063
3098
|
function gdtiUri(companyPrefix, docType, serial) {
|
|
3064
3099
|
return `urn:epc:id:gdti:${companyPrefix}.${docType}.${serial}`;
|
|
3065
3100
|
}
|
|
@@ -4337,6 +4372,8 @@ function validateGenerator(g, at2) {
|
|
|
4337
4372
|
if (!Array.isArray(content.skuMix) || content.skuMix.length === 0) return bad("scenario-sku-mix-required", { at: at2, kind: g.kind });
|
|
4338
4373
|
for (const s of content.skuMix) {
|
|
4339
4374
|
if (!s?.gtin || typeof s.gtin !== "string") return bad("scenario-sku-gtin-required", { at: at2, kind: g.kind });
|
|
4375
|
+
const digits = gs1KeyDigitViolation(s.gtin);
|
|
4376
|
+
if (digits) return bad("scenario-sku-gtin-digits", { at: at2, kind: g.kind, gtin: s.gtin, reason: digits });
|
|
4340
4377
|
if (!isNum(s.weight) || s.weight <= 0) return bad("scenario-sku-weight-invalid", { at: at2, kind: g.kind, gtin: String(s.gtin) });
|
|
4341
4378
|
}
|
|
4342
4379
|
const q = content.qtyPerLine;
|
|
@@ -5061,6 +5098,7 @@ function nonEmpty(value) {
|
|
|
5061
5098
|
isWebhookSecretSegment,
|
|
5062
5099
|
isWorkShiftExecutionBasis,
|
|
5063
5100
|
isoDurationHours,
|
|
5101
|
+
itemClassOf,
|
|
5064
5102
|
itemKeyOf,
|
|
5065
5103
|
judgeAgainstSpec,
|
|
5066
5104
|
levelOfLocationType,
|
|
@@ -5068,6 +5106,7 @@ function nonEmpty(value) {
|
|
|
5068
5106
|
localDayIndexAt,
|
|
5069
5107
|
localDayStartMs,
|
|
5070
5108
|
locationStatusOf,
|
|
5109
|
+
lotClassOfItem,
|
|
5071
5110
|
lotClassUri,
|
|
5072
5111
|
lotFromAttributes,
|
|
5073
5112
|
mapRecord,
|
|
@@ -5109,6 +5148,7 @@ function nonEmpty(value) {
|
|
|
5109
5148
|
retiredVocabularyIn,
|
|
5110
5149
|
reversalKey,
|
|
5111
5150
|
rolledThroughputYield,
|
|
5151
|
+
sameItemClass,
|
|
5112
5152
|
sgtinClass,
|
|
5113
5153
|
sgtinUri,
|
|
5114
5154
|
splitFlowOrders,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@operato/ops-contract",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.35",
|
|
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",
|