@operato/ops-contract 0.9.33 → 0.9.34
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 +38 -1
- package/dist/epcis.js +85 -7
- package/dist-cjs/index.cjs +44 -5
- package/package.json +1 -1
package/dist/epcis.d.ts
CHANGED
|
@@ -344,8 +344,10 @@ export interface ParsedEpc {
|
|
|
344
344
|
instance: boolean;
|
|
345
345
|
/** 품목 클래스 키 — `CompanyPrefix.ItemRef`(sgtin/lgtin/idpat 에서). */
|
|
346
346
|
gtinKey?: string;
|
|
347
|
-
/** 로트 번호
|
|
347
|
+
/** 로트 번호 — LGTIN 과, 선언된 이름공간의 로트 클래스(`<품번>;lot=<로트>`, §`lotClassUri`)에 있다. */
|
|
348
348
|
lot?: string;
|
|
349
|
+
/** 사내 품번 — 선언된 이름공간의 로트 클래스에서만 뜯는다. 로트 없는 품목 클래스는 지금처럼 원문만 낸다. */
|
|
350
|
+
item?: string;
|
|
349
351
|
/** 일련번호(SGTIN·SSCC 등 개체 식별자에만). */
|
|
350
352
|
serial?: string;
|
|
351
353
|
/** 원문 — 해석에 실패해도 잃지 않는다. */
|
|
@@ -411,6 +413,41 @@ export declare function objectUri(namespace: string, objId: string | number): st
|
|
|
411
413
|
* 그래서 한 표준에 방언이 둘이 됐다. 문을 낸다.
|
|
412
414
|
*/
|
|
413
415
|
export declare function classUri(namespace: string, classId: string | number): string | undefined;
|
|
416
|
+
/**
|
|
417
|
+
* **로트 클래스의 식별자** — 품번과 로트를 받아 class URI 하나를 낸다(ADR-0082 결정 2 · 2026-09-24 판정).
|
|
418
|
+
*
|
|
419
|
+
* ── 왜 계약이 갖는가 ──────────────────────────────────────────────────────
|
|
420
|
+
* plant 는 로트를 `${품번}-lot-${로트}` 로 적어 왔다(`epcis-genealogy.ts` 의 `lotClassOf`). 둘째 생산자
|
|
421
|
+
* (warehouse)와 커널의 시뮬이 같은 로트를 말하려면 **같은 글자**여야 하고, 그 글자를 정하는 곳은 하나여야 한다.
|
|
422
|
+
*
|
|
423
|
+
* ── 두 길 ──────────────────────────────────────────────────────────────────
|
|
424
|
+
* · GTIN 이 있으면 LGTIN(`lgtinClass`). `gtin` 은 파서의 `gtinKey` 와 같은 모양 `CompanyPrefix.ItemRefAndIndicator`
|
|
425
|
+
* 이다 — GTIN-14 만으로는 프리픽스 자리 수를 알 수 없어서 나눌 수 없다. 자리 수(`GS1_KEY_DIGITS`)가 틀리면
|
|
426
|
+
* **던진다.** 사내 철자로 떨어지면 같은 로트가 두 글자가 된다.
|
|
427
|
+
* · 없으면 `/class/` 뒤 **성분 하나** 안에서 가른다: `<품번>;lot=<로트>`(CBV 2.0 §8.3.4 — `/class/<품번>/lot/<로트>`
|
|
428
|
+
* 는 계약의 `CBV_URL_CLASS` 가 거절한다).
|
|
429
|
+
*
|
|
430
|
+
* ── 부호화 ─────────────────────────────────────────────────────────────────
|
|
431
|
+
* `classUri` 의 여섯 글자에 `;` 하나만 더한다. 값 안의 `;` 가 `%3B` 가 되므로 `;lot=` 는 성분 안에 정확히
|
|
432
|
+
* 한 번 나오고 파서는 그 자리에서 가른다. `=` 는 부호화하지 않는다 — 하면 `A=B` 라는 품번이 품목 클래스에서는
|
|
433
|
+
* `A=B`, 로트 클래스에서는 `A%3DB` 가 되어 같은 품번의 글자가 갈린다.
|
|
434
|
+
*
|
|
435
|
+
* `classUri(ns, 품번 + ';lot=' + …)` 로 부르지 않는다: `classUri` 가 `%` 를 다시 부호화하므로 미리 부호화한
|
|
436
|
+
* 값은 두 번 부호화되고(`A%2FB` → `A%252FB`), 원문을 넘기면 값 안의 `;` 가 남아 가르는 자리가 모호하다.
|
|
437
|
+
*
|
|
438
|
+
* ── 남는 것 ───────────────────────────────────────────────────────────────
|
|
439
|
+
* `;` 가 든 품번은 품목 클래스(`classUri` — `;` 를 그대로 둔다)와 로트 클래스의 품번 글자가 갈린다. `classUri`
|
|
440
|
+
* 를 바꾸면 저장된 정체성이 흔들리므로 두지 않는다. **「같은 품번인가」는 문자열 앞부분이 아니라 `parseEpc`
|
|
441
|
+
* 로 양쪽을 뜯어 품번을 견준다.**
|
|
442
|
+
*
|
|
443
|
+
* 이름공간이 없거나 GS1 공간이면 `undefined` 다(`classUri` 와 같다 — 부르는 쪽이 「선언 없음」으로 말한다).
|
|
444
|
+
*/
|
|
445
|
+
export declare function lotClassUri(input: {
|
|
446
|
+
namespace: string;
|
|
447
|
+
item: string;
|
|
448
|
+
lot: string;
|
|
449
|
+
gtin?: string;
|
|
450
|
+
}): string | undefined;
|
|
414
451
|
export declare function bizTransactionUri(namespace: string, transId: string | number): string | undefined;
|
|
415
452
|
/** 모든 빌더가 공통으로 받는 표준 헤더 옵션(선택) — 방출부가 필요할 때 채운다. */
|
|
416
453
|
export interface EpcisHeaderOptions {
|
package/dist/epcis.js
CHANGED
|
@@ -190,8 +190,16 @@ export function parseEpc(uri) {
|
|
|
190
190
|
*/
|
|
191
191
|
if (/(?:\/obj\/|:obj:)[^/:\s]+$/.test(raw))
|
|
192
192
|
return { scheme: 'unknown', instance: true, uri: raw };
|
|
193
|
-
|
|
194
|
-
|
|
193
|
+
const inHouseClass = raw.match(/(?:\/class\/|:class:)([^/:\s]+)$/);
|
|
194
|
+
if (inHouseClass) {
|
|
195
|
+
/*
|
|
196
|
+
* 로트 클래스면 `;lot=` 에서 가른다(§`lotClassUri`). 그 밖의 클래스는 **지금 답 그대로**다 — 저널에 남은
|
|
197
|
+
* 철자(plant 의 `-lot-` 포함)를 오늘 다르게 읽지 않는다(ADR-0038, 시험 `class-uri-regression`).
|
|
198
|
+
*/
|
|
199
|
+
const at = inHouseClass[1].indexOf(LOT_SEPARATOR);
|
|
200
|
+
const split = at > 0 ? decodedPair(inHouseClass[1].slice(0, at), inHouseClass[1].slice(at + LOT_SEPARATOR.length)) : undefined;
|
|
201
|
+
return split ? { scheme: 'unknown', instance: false, item: split[0], lot: split[1], uri: raw } : { scheme: 'unknown', instance: false, uri: raw };
|
|
202
|
+
}
|
|
195
203
|
const cls = raw.match(/^urn:epc:class:lgtin:(.+)$/);
|
|
196
204
|
if (cls) {
|
|
197
205
|
const seg = cls[1].split('.');
|
|
@@ -224,6 +232,17 @@ export function parseEpc(uri) {
|
|
|
224
232
|
}
|
|
225
233
|
return { scheme: 'unknown', instance: false, uri: raw };
|
|
226
234
|
}
|
|
235
|
+
/** 로트 클래스의 두 마디를 한 번 복호화한다. 우리가 만든 글자가 아니어서 뜯을 수 없으면 가르지 않는다. */
|
|
236
|
+
function decodedPair(item, lot) {
|
|
237
|
+
if (!lot)
|
|
238
|
+
return undefined;
|
|
239
|
+
try {
|
|
240
|
+
return [decodeURIComponent(item), decodeURIComponent(lot)];
|
|
241
|
+
}
|
|
242
|
+
catch {
|
|
243
|
+
return undefined;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
227
246
|
/** 거래문서 식별자 = GDTI (PO/SO/WO/어포인트먼트 등). */
|
|
228
247
|
export function gdtiUri(companyPrefix, docType, serial) {
|
|
229
248
|
return `urn:epc:id:gdti:${companyPrefix}.${docType}.${serial}`;
|
|
@@ -283,6 +302,60 @@ export function objectUri(namespace, objId) {
|
|
|
283
302
|
export function classUri(namespace, classId) {
|
|
284
303
|
return underNamespace(namespace, 'class', classId);
|
|
285
304
|
}
|
|
305
|
+
/**
|
|
306
|
+
* **로트 클래스의 식별자** — 품번과 로트를 받아 class URI 하나를 낸다(ADR-0082 결정 2 · 2026-09-24 판정).
|
|
307
|
+
*
|
|
308
|
+
* ── 왜 계약이 갖는가 ──────────────────────────────────────────────────────
|
|
309
|
+
* plant 는 로트를 `${품번}-lot-${로트}` 로 적어 왔다(`epcis-genealogy.ts` 의 `lotClassOf`). 둘째 생산자
|
|
310
|
+
* (warehouse)와 커널의 시뮬이 같은 로트를 말하려면 **같은 글자**여야 하고, 그 글자를 정하는 곳은 하나여야 한다.
|
|
311
|
+
*
|
|
312
|
+
* ── 두 길 ──────────────────────────────────────────────────────────────────
|
|
313
|
+
* · GTIN 이 있으면 LGTIN(`lgtinClass`). `gtin` 은 파서의 `gtinKey` 와 같은 모양 `CompanyPrefix.ItemRefAndIndicator`
|
|
314
|
+
* 이다 — GTIN-14 만으로는 프리픽스 자리 수를 알 수 없어서 나눌 수 없다. 자리 수(`GS1_KEY_DIGITS`)가 틀리면
|
|
315
|
+
* **던진다.** 사내 철자로 떨어지면 같은 로트가 두 글자가 된다.
|
|
316
|
+
* · 없으면 `/class/` 뒤 **성분 하나** 안에서 가른다: `<품번>;lot=<로트>`(CBV 2.0 §8.3.4 — `/class/<품번>/lot/<로트>`
|
|
317
|
+
* 는 계약의 `CBV_URL_CLASS` 가 거절한다).
|
|
318
|
+
*
|
|
319
|
+
* ── 부호화 ─────────────────────────────────────────────────────────────────
|
|
320
|
+
* `classUri` 의 여섯 글자에 `;` 하나만 더한다. 값 안의 `;` 가 `%3B` 가 되므로 `;lot=` 는 성분 안에 정확히
|
|
321
|
+
* 한 번 나오고 파서는 그 자리에서 가른다. `=` 는 부호화하지 않는다 — 하면 `A=B` 라는 품번이 품목 클래스에서는
|
|
322
|
+
* `A=B`, 로트 클래스에서는 `A%3DB` 가 되어 같은 품번의 글자가 갈린다.
|
|
323
|
+
*
|
|
324
|
+
* `classUri(ns, 품번 + ';lot=' + …)` 로 부르지 않는다: `classUri` 가 `%` 를 다시 부호화하므로 미리 부호화한
|
|
325
|
+
* 값은 두 번 부호화되고(`A%2FB` → `A%252FB`), 원문을 넘기면 값 안의 `;` 가 남아 가르는 자리가 모호하다.
|
|
326
|
+
*
|
|
327
|
+
* ── 남는 것 ───────────────────────────────────────────────────────────────
|
|
328
|
+
* `;` 가 든 품번은 품목 클래스(`classUri` — `;` 를 그대로 둔다)와 로트 클래스의 품번 글자가 갈린다. `classUri`
|
|
329
|
+
* 를 바꾸면 저장된 정체성이 흔들리므로 두지 않는다. **「같은 품번인가」는 문자열 앞부분이 아니라 `parseEpc`
|
|
330
|
+
* 로 양쪽을 뜯어 품번을 견준다.**
|
|
331
|
+
*
|
|
332
|
+
* 이름공간이 없거나 GS1 공간이면 `undefined` 다(`classUri` 와 같다 — 부르는 쪽이 「선언 없음」으로 말한다).
|
|
333
|
+
*/
|
|
334
|
+
export function lotClassUri(input) {
|
|
335
|
+
const item = String(input.item ?? '');
|
|
336
|
+
const lot = String(input.lot ?? '');
|
|
337
|
+
if (!lot)
|
|
338
|
+
throw new Error(`lotClassUri: 로트가 비었다 — 로트 없는 품목은 classUri 로 부른다 (item=${item})`);
|
|
339
|
+
if (input.gtin !== undefined) {
|
|
340
|
+
const [prefix, ref, ...rest] = String(input.gtin).split('.');
|
|
341
|
+
if (!prefix || !ref || rest.length) {
|
|
342
|
+
throw new Error(`lotClassUri: gtin 은 'CompanyPrefix.ItemRefAndIndicator' 여야 한다: ${input.gtin}`);
|
|
343
|
+
}
|
|
344
|
+
const uri = lgtinClass(prefix, ref, lot);
|
|
345
|
+
const wrong = gs1KeyDigitViolation(uri);
|
|
346
|
+
if (wrong)
|
|
347
|
+
throw new Error(`lotClassUri: ${wrong}`);
|
|
348
|
+
return uri;
|
|
349
|
+
}
|
|
350
|
+
if (!item)
|
|
351
|
+
throw new Error(`lotClassUri: 품번이 비었다 (lot=${lot})`);
|
|
352
|
+
const enc = (v) => v.replace(LOT_COMPONENT_BREAKING, c => PERCENT_ENCODED[c]);
|
|
353
|
+
return joinUnderNamespace(input.namespace, 'class', `${enc(item)}${LOT_SEPARATOR}${enc(lot)}`);
|
|
354
|
+
}
|
|
355
|
+
/** 로트 클래스 성분에서 품번과 로트를 가르는 자리. 값 안의 `;` 는 부호화되므로 한 번만 나온다. */
|
|
356
|
+
const LOT_SEPARATOR = ';lot=';
|
|
357
|
+
/** `STRUCTURE_BREAKING` 에 `;` 하나를 더한 것. 부호는 같은 표(`PERCENT_ENCODED`)에서 온다. */
|
|
358
|
+
const LOT_COMPONENT_BREAKING = /[%/:?# ;]/g;
|
|
286
359
|
export function bizTransactionUri(namespace, transId) {
|
|
287
360
|
return underNamespace(namespace, 'bt', transId);
|
|
288
361
|
}
|
|
@@ -319,16 +392,21 @@ const PERCENT_ENCODED = {
|
|
|
319
392
|
':': '%3A',
|
|
320
393
|
'?': '%3F',
|
|
321
394
|
'#': '%23',
|
|
322
|
-
' ': '%20'
|
|
395
|
+
' ': '%20',
|
|
396
|
+
/* 로트 클래스의 가르는 글자 — `lotClassUri` 만 쓴다(§`LOT_COMPONENT_BREAKING`). 표는 한 벌이다. */
|
|
397
|
+
';': '%3B'
|
|
323
398
|
};
|
|
324
399
|
function underNamespace(namespace, marker, id) {
|
|
325
|
-
const ns = namespace?.trim();
|
|
326
|
-
if (!ns)
|
|
327
|
-
return undefined;
|
|
328
400
|
const raw = String(id);
|
|
329
401
|
if (!raw)
|
|
330
402
|
return undefined;
|
|
331
|
-
|
|
403
|
+
return joinUnderNamespace(namespace, marker, raw.replace(STRUCTURE_BREAKING, c => PERCENT_ENCODED[c]));
|
|
404
|
+
}
|
|
405
|
+
/** 이미 부호화한 성분 하나를 이름공간 아래 표지 뒤에 붙인다 — 부호화는 부르는 쪽(이 파일 안)이 끝냈다. */
|
|
406
|
+
function joinUnderNamespace(namespace, marker, v) {
|
|
407
|
+
const ns = namespace?.trim();
|
|
408
|
+
if (!ns)
|
|
409
|
+
return undefined;
|
|
332
410
|
if (/^https?:\/\/[^/\s]+/.test(ns))
|
|
333
411
|
return `${ns.replace(/\/+$/, '')}/${marker}/${v}`;
|
|
334
412
|
/*
|
package/dist-cjs/index.cjs
CHANGED
|
@@ -190,6 +190,7 @@ __export(index_exports, {
|
|
|
190
190
|
localDayIndexAt: () => localDayIndexAt,
|
|
191
191
|
localDayStartMs: () => localDayStartMs,
|
|
192
192
|
locationStatusOf: () => locationStatusOf,
|
|
193
|
+
lotClassUri: () => lotClassUri,
|
|
193
194
|
lotFromAttributes: () => lotFromAttributes,
|
|
194
195
|
mapRecord: () => mapRecord,
|
|
195
196
|
mapRecordChecked: () => mapRecordChecked,
|
|
@@ -3014,7 +3015,12 @@ function lgtinClass(companyPrefix, itemRefAndIndicator, lot) {
|
|
|
3014
3015
|
function parseEpc(uri) {
|
|
3015
3016
|
const raw = String(uri ?? "");
|
|
3016
3017
|
if (/(?:\/obj\/|:obj:)[^/:\s]+$/.test(raw)) return { scheme: "unknown", instance: true, uri: raw };
|
|
3017
|
-
|
|
3018
|
+
const inHouseClass = raw.match(/(?:\/class\/|:class:)([^/:\s]+)$/);
|
|
3019
|
+
if (inHouseClass) {
|
|
3020
|
+
const at2 = inHouseClass[1].indexOf(LOT_SEPARATOR);
|
|
3021
|
+
const split = at2 > 0 ? decodedPair(inHouseClass[1].slice(0, at2), inHouseClass[1].slice(at2 + LOT_SEPARATOR.length)) : void 0;
|
|
3022
|
+
return split ? { scheme: "unknown", instance: false, item: split[0], lot: split[1], uri: raw } : { scheme: "unknown", instance: false, uri: raw };
|
|
3023
|
+
}
|
|
3018
3024
|
const cls = raw.match(/^urn:epc:class:lgtin:(.+)$/);
|
|
3019
3025
|
if (cls) {
|
|
3020
3026
|
const seg = cls[1].split(".");
|
|
@@ -3046,6 +3052,14 @@ function parseEpc(uri) {
|
|
|
3046
3052
|
}
|
|
3047
3053
|
return { scheme: "unknown", instance: false, uri: raw };
|
|
3048
3054
|
}
|
|
3055
|
+
function decodedPair(item, lot) {
|
|
3056
|
+
if (!lot) return void 0;
|
|
3057
|
+
try {
|
|
3058
|
+
return [decodeURIComponent(item), decodeURIComponent(lot)];
|
|
3059
|
+
} catch {
|
|
3060
|
+
return void 0;
|
|
3061
|
+
}
|
|
3062
|
+
}
|
|
3049
3063
|
function gdtiUri(companyPrefix, docType, serial) {
|
|
3050
3064
|
return `urn:epc:id:gdti:${companyPrefix}.${docType}.${serial}`;
|
|
3051
3065
|
}
|
|
@@ -3055,6 +3069,26 @@ function objectUri(namespace, objId) {
|
|
|
3055
3069
|
function classUri(namespace, classId) {
|
|
3056
3070
|
return underNamespace(namespace, "class", classId);
|
|
3057
3071
|
}
|
|
3072
|
+
function lotClassUri(input) {
|
|
3073
|
+
const item = String(input.item ?? "");
|
|
3074
|
+
const lot = String(input.lot ?? "");
|
|
3075
|
+
if (!lot) throw new Error(`lotClassUri: \uB85C\uD2B8\uAC00 \uBE44\uC5C8\uB2E4 \u2014 \uB85C\uD2B8 \uC5C6\uB294 \uD488\uBAA9\uC740 classUri \uB85C \uBD80\uB978\uB2E4 (item=${item})`);
|
|
3076
|
+
if (input.gtin !== void 0) {
|
|
3077
|
+
const [prefix, ref, ...rest] = String(input.gtin).split(".");
|
|
3078
|
+
if (!prefix || !ref || rest.length) {
|
|
3079
|
+
throw new Error(`lotClassUri: gtin \uC740 'CompanyPrefix.ItemRefAndIndicator' \uC5EC\uC57C \uD55C\uB2E4: ${input.gtin}`);
|
|
3080
|
+
}
|
|
3081
|
+
const uri = lgtinClass(prefix, ref, lot);
|
|
3082
|
+
const wrong = gs1KeyDigitViolation(uri);
|
|
3083
|
+
if (wrong) throw new Error(`lotClassUri: ${wrong}`);
|
|
3084
|
+
return uri;
|
|
3085
|
+
}
|
|
3086
|
+
if (!item) throw new Error(`lotClassUri: \uD488\uBC88\uC774 \uBE44\uC5C8\uB2E4 (lot=${lot})`);
|
|
3087
|
+
const enc = (v) => v.replace(LOT_COMPONENT_BREAKING, (c) => PERCENT_ENCODED[c]);
|
|
3088
|
+
return joinUnderNamespace(input.namespace, "class", `${enc(item)}${LOT_SEPARATOR}${enc(lot)}`);
|
|
3089
|
+
}
|
|
3090
|
+
var LOT_SEPARATOR = ";lot=";
|
|
3091
|
+
var LOT_COMPONENT_BREAKING = /[%/:?# ;]/g;
|
|
3058
3092
|
function bizTransactionUri(namespace, transId) {
|
|
3059
3093
|
return underNamespace(namespace, "bt", transId);
|
|
3060
3094
|
}
|
|
@@ -3065,14 +3099,18 @@ var PERCENT_ENCODED = {
|
|
|
3065
3099
|
":": "%3A",
|
|
3066
3100
|
"?": "%3F",
|
|
3067
3101
|
"#": "%23",
|
|
3068
|
-
" ": "%20"
|
|
3102
|
+
" ": "%20",
|
|
3103
|
+
/* 로트 클래스의 가르는 글자 — `lotClassUri` 만 쓴다(§`LOT_COMPONENT_BREAKING`). 표는 한 벌이다. */
|
|
3104
|
+
";": "%3B"
|
|
3069
3105
|
};
|
|
3070
3106
|
function underNamespace(namespace, marker, id) {
|
|
3071
|
-
const ns = namespace?.trim();
|
|
3072
|
-
if (!ns) return void 0;
|
|
3073
3107
|
const raw = String(id);
|
|
3074
3108
|
if (!raw) return void 0;
|
|
3075
|
-
|
|
3109
|
+
return joinUnderNamespace(namespace, marker, raw.replace(STRUCTURE_BREAKING, (c) => PERCENT_ENCODED[c]));
|
|
3110
|
+
}
|
|
3111
|
+
function joinUnderNamespace(namespace, marker, v) {
|
|
3112
|
+
const ns = namespace?.trim();
|
|
3113
|
+
if (!ns) return void 0;
|
|
3076
3114
|
if (/^https?:\/\/[^/\s]+/.test(ns)) return `${ns.replace(/\/+$/, "")}/${marker}/${v}`;
|
|
3077
3115
|
if (/^urn:epc(global)?:/.test(ns)) return void 0;
|
|
3078
3116
|
if (/^urn:[^:\s]+/.test(ns)) return `${ns.replace(/:+$/, "")}:${marker}:${v}`;
|
|
@@ -5030,6 +5068,7 @@ function nonEmpty(value) {
|
|
|
5030
5068
|
localDayIndexAt,
|
|
5031
5069
|
localDayStartMs,
|
|
5032
5070
|
locationStatusOf,
|
|
5071
|
+
lotClassUri,
|
|
5033
5072
|
lotFromAttributes,
|
|
5034
5073
|
mapRecord,
|
|
5035
5074
|
mapRecordChecked,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@operato/ops-contract",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.34",
|
|
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",
|