@operato/ops-contract 0.9.30 → 0.9.32

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.
@@ -405,6 +405,15 @@ export type TestSpecificationRefs = string[];
405
405
  * 개명이 사는 값은 이 주석이 대신 낸다).
406
406
  */
407
407
  export interface TestResult {
408
+ /** Source-pinned execution evidence, not a lookup of the current master. */
409
+ specificationBasis?: {
410
+ id: string;
411
+ revisionId: string;
412
+ planId: string;
413
+ contentHash: string;
414
+ businessTime: ISOTime;
415
+ criteria: TestSpecificationCriterion[];
416
+ };
408
417
  /** 어느 시험인가 — `TestSpecification.id` 를 가리킨다. */
409
418
  specId: string;
410
419
  /**
@@ -749,7 +758,9 @@ export declare function testEvidenceGaps(spec: Pick<TestSpecification, 'criteria
749
758
  *
750
759
  * 커널은 `Expression` 을 **읽지 않는다**(문법이 정의되지 않은 자유 문자열). 판정은 숫자 한계로만 한다.
751
760
  */
752
- export declare function judgeAgainstSpec(spec: Pick<TestSpecification, 'criteria'> | undefined, result: Pick<TestResult, 'propertyMeasurements'> | undefined): 'pass' | 'fail' | undefined;
761
+ /** Validate carried evidence before either ingestion or replay; malformed evidence is not a current-master lookup. */
762
+ export declare function isTestSpecificationBasis(value: unknown): value is NonNullable<TestResult['specificationBasis']>;
763
+ export declare function judgeAgainstSpec(spec: Pick<TestSpecification, 'criteria'> | undefined, result: Pick<TestResult, 'propertyMeasurements' | 'specificationBasis'> | undefined): 'pass' | 'fail' | undefined;
753
764
  /**
754
765
  * 유효 기간 — **ISA-95 `EffectiveStartDate` / `EffectiveEndDate`.**
755
766
  *
@@ -2012,7 +2023,36 @@ export interface TaskState {
2012
2023
  * 실적 쪽 대응은 `TaskState`(`SegmentResponse`) 다 — 요구와 응답을 한 짝으로 읽어야 "얼마나 시켰고
2013
2024
  * 얼마나 됐나" 가 나온다.
2014
2025
  */
2026
+ /** Source-selected recipe evidence. Digests refer to source records; the reduced payload is not their full signed encoding. */
2027
+ export interface RecipeExecutionBasis {
2028
+ basisId: string;
2029
+ recipeId: string;
2030
+ revisionId: string;
2031
+ planId: string;
2032
+ contentHash: string;
2033
+ businessTime: ISOTime;
2034
+ recipe: {
2035
+ key: string;
2036
+ label: string;
2037
+ inputs: {
2038
+ material: string;
2039
+ qty: number;
2040
+ operation?: string;
2041
+ }[];
2042
+ outputs: {
2043
+ material: string;
2044
+ qty: number;
2045
+ }[];
2046
+ route?: string;
2047
+ };
2048
+ route?: {
2049
+ key: string;
2050
+ steps: string[];
2051
+ };
2052
+ }
2053
+ export declare function isRecipeExecutionBasis(value: unknown): value is RecipeExecutionBasis;
2015
2054
  export interface OrderState {
2055
+ recipeBasis?: RecipeExecutionBasis;
2016
2056
  id: string;
2017
2057
  kind: string;
2018
2058
  status: string;
@@ -3655,6 +3695,7 @@ export interface ObservedOrderLine {
3655
3695
  allocated?: number;
3656
3696
  }
3657
3697
  export interface OrderStatusDelta {
3698
+ recipeBasis?: RecipeExecutionBasis;
3658
3699
  orderId: string;
3659
3700
  kind: string;
3660
3701
  status: string;
package/dist/contract.js CHANGED
@@ -28,7 +28,7 @@
28
28
  * **「원본이 말하는 이 사실을 커널의 어휘로 어떻게 옮기나」**다. 컬럼 단위로 물으면 원본이 열이면
29
29
  * 축도 열이 된다 — 2026-08-23 에 축 다섯을 열었다가 그 이유로 되돌렸다.
30
30
  *
31
- * 열지 않기로 한 것과 그 조건은 `design/04-decisions.md` ADR-0039 에 있다. 넓히기 전에 그 표를 본다.
31
+ * 열지 않기로 한 것과 그 조건은 `operato-application/adr/ADR-0039.md` 에 있다. 넓히기 전에 그 표를 본다.
32
32
  * 지키는 하네스: `derived-not-input` · `actuals-come-from-transitions` · `accumulators-survive-restart` ·
33
33
  * `purpose-conformance`.
34
34
  */
@@ -407,9 +407,39 @@ export function testEvidenceGaps(spec, result) {
407
407
  *
408
408
  * 커널은 `Expression` 을 **읽지 않는다**(문법이 정의되지 않은 자유 문자열). 판정은 숫자 한계로만 한다.
409
409
  */
410
+ /** Validate carried evidence before either ingestion or replay; malformed evidence is not a current-master lookup. */
411
+ export function isTestSpecificationBasis(value) {
412
+ if (!value || typeof value !== 'object' || Array.isArray(value))
413
+ return false;
414
+ const basis = value;
415
+ if (!['id', 'revisionId', 'planId', 'contentHash', 'businessTime'].every(key => typeof basis[key] === 'string' && basis[key].trim()))
416
+ return false;
417
+ if (!Number.isFinite(Date.parse(basis.businessTime)))
418
+ return false;
419
+ return Array.isArray(basis.criteria) && basis.criteria.every(c => {
420
+ if (!c || typeof c !== 'object' || Array.isArray(c) || typeof c.id !== 'string' || !c.id.trim())
421
+ return false;
422
+ if (['description', 'expression', 'evaluatedPropertyId'].some(key => c[key] !== undefined && typeof c[key] !== 'string'))
423
+ return false;
424
+ if (c.limit === undefined)
425
+ return true;
426
+ const limit = c.limit;
427
+ if (!limit || typeof limit !== 'object' || Array.isArray(limit))
428
+ return false;
429
+ if (['minimum', 'maximum'].some(key => limit[key] !== undefined && (typeof limit[key] !== 'number' || !Number.isFinite(limit[key]))))
430
+ return false;
431
+ if (limit.uom !== undefined && typeof limit.uom !== 'string')
432
+ return false;
433
+ return !(limit.minimum !== undefined && limit.maximum !== undefined && limit.minimum > limit.maximum);
434
+ });
435
+ }
410
436
  export function judgeAgainstSpec(spec, result) {
411
437
  /* 판정할 기준만 남긴다 — 말하지 않는 기준은 이 답에 관여하지 않는다. */
412
- const criteria = (spec?.criteria ?? []).filter(c => !criterionSaysNothing(c));
438
+ const basis = result?.specificationBasis;
439
+ // A malformed carried basis is unknown. Never replace it with today's criteria.
440
+ if (basis !== undefined && !isTestSpecificationBasis(basis))
441
+ return undefined;
442
+ const criteria = (basis ? basis.criteria : spec?.criteria ?? []).filter(c => !criterionSaysNothing(c));
413
443
  if (!criteria.length)
414
444
  return undefined;
415
445
  const measurements = result?.propertyMeasurements ?? [];
@@ -1055,6 +1085,20 @@ export function homeOf(e) {
1055
1085
  const id = e?.homeLocation;
1056
1086
  return id ? { id, kind: e?.homeLocationKind ?? 'location' } : undefined;
1057
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
+ }
1058
1102
  // ── 운영 델타(비-EPCIS) — State 채널의 나머지 절반 ──────────────────────────
1059
1103
  // EPCIS 이벤트는 재고/위치만 재구성 가능. tasks·equipment·orders 의 운영 상태는
1060
1104
  // 이 델타로 미러한다. envelope.eventType = 'task.status' | 'equipment.status' | 'order.status'.
@@ -34,7 +34,7 @@
34
34
  * 모르는 필드는 **조용히 버리지 않고 거부한다.** `taskID` 처럼 한 글자 틀린 이름은 통과시키면 영원히
35
35
  * 보이지 않는 손실이 된다(이 문에는 아직 옛 발신자가 없어 호환 부담도 없다).
36
36
  */
37
- import { OP_EVENT, DISPOSITION_DECISION, MATERIAL_ACTUAL_USE, MATERIAL_LOT_USE } from "./contract.js";
37
+ import { OP_EVENT, DISPOSITION_DECISION, MATERIAL_ACTUAL_USE, MATERIAL_LOT_USE, isTestSpecificationBasis, isRecipeExecutionBasis } from "./contract.js";
38
38
  /**
39
39
  * 객체 한 줄이 선언된 안쪽 모양을 지키나 — **선언하지 않은 자리는 보지 않는다.**
40
40
  *
@@ -224,13 +224,18 @@ const SPECS = {
224
224
  *
225
225
  * 새 어휘가 아니다 — 계약이 `recipeKey` 를 네 자리에서 이미 쓴다. 오더 관측에만 자리가 없었다.
226
226
  */
227
- recipeKey: 'string'
227
+ recipeKey: 'string', recipeBasis: 'object'
228
228
  },
229
229
  /*
230
230
  * 확보분의 안쪽을 본다 — 열쇠와 수 둘이다(§`AllocatedQuantity`). 안 보면 틀린 이름이 조용히
231
231
  * 지나가고(`epcs`·`quantity` 따위), 미러는 잡힌 수를 0 으로 읽는다.
232
232
  */
233
233
  shapes: {
234
+ recipeBasis: {
235
+ required: ['basisId', 'recipeId', 'revisionId', 'planId', 'contentHash', 'businessTime', 'recipe'],
236
+ fields: { basisId: 'string', recipeId: 'string', revisionId: 'string', planId: 'string', contentHash: 'string', businessTime: 'string' }
237
+ // Owned composition and captured route are additionally checked by isRecipeExecutionBasis below.
238
+ },
234
239
  allocated: {
235
240
  required: ['epc', 'qty'],
236
241
  fields: { epc: 'string', qty: 'number' },
@@ -370,7 +375,13 @@ const SPECS = {
370
375
  required: ['testableObjectId', 'specId'],
371
376
  fields: {
372
377
  testableObjectId: 'string', specId: 'string', result: 'string', at: 'string', expiresAt: 'string',
373
- derived: 'boolean', propertyMeasurements: 'object[]', recordTime: 'string'
378
+ derived: 'boolean', propertyMeasurements: 'object[]', specificationBasis: 'object', recordTime: 'string'
379
+ },
380
+ shapes: {
381
+ specificationBasis: {
382
+ required: ['id', 'revisionId', 'planId', 'contentHash', 'businessTime', 'criteria'],
383
+ fields: { id: 'string', revisionId: 'string', planId: 'string', contentHash: 'string', businessTime: 'string' }
384
+ }
374
385
  },
375
386
  enums: { result: ['pass', 'fail'] }
376
387
  },
@@ -611,6 +622,13 @@ export function ingestOperationalRecords(records, opts) {
611
622
  * 사건 시각이 되고, 그러면 어제 있었던 정지가 오늘 일어난 것으로 저널에 적힌다. 적은 때는
612
623
  * `recordTime` 에 남는다.
613
624
  */
625
+ if (kind === 'test' && r.specificationBasis !== undefined && !isTestSpecificationBasis(r.specificationBasis)) {
626
+ errors.push('test.specificationBasis: invalid pinned specification evidence');
627
+ }
628
+ if (kind === 'order' && r.recipeBasis !== undefined && (!isRecipeExecutionBasis(r.recipeBasis) ||
629
+ (r.recipeKey !== undefined && r.recipeKey !== r.recipeBasis.recipe.key))) {
630
+ errors.push('order.recipeBasis: invalid pinned recipe evidence');
631
+ }
614
632
  const closedPeriodEnd = kind === 'equipment-period' ? String(r.to ?? '').trim() : '';
615
633
  const at = closedPeriodEnd || String(r.at ?? '').trim() || opts.defaultEventTime;
616
634
  const atMs = at ? Date.parse(at) : Number.NaN;
@@ -174,7 +174,9 @@ __export(index_exports, {
174
174
  isOperationalRecord: () => isOperationalRecord,
175
175
  isOrderTerminal: () => isOrderTerminal,
176
176
  isPlannedStopStatus: () => isPlannedStopStatus,
177
+ isRecipeExecutionBasis: () => isRecipeExecutionBasis,
177
178
  isResourceKind: () => isResourceKind,
179
+ isTestSpecificationBasis: () => isTestSpecificationBasis,
178
180
  isTransformationRecord: () => isTransformationRecord,
179
181
  isWebhookDeliveryCode: () => isWebhookDeliveryCode,
180
182
  isWebhookSecretSegment: () => isWebhookSecretSegment,
@@ -588,8 +590,26 @@ function testEvidenceGaps(spec, result) {
588
590
  unmatched: measurements.map((m) => m.testableObjectPropertyId).filter((k) => !!k && !wanted.has(k))
589
591
  };
590
592
  }
593
+ function isTestSpecificationBasis(value) {
594
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
595
+ const basis = value;
596
+ if (!["id", "revisionId", "planId", "contentHash", "businessTime"].every((key) => typeof basis[key] === "string" && basis[key].trim())) return false;
597
+ if (!Number.isFinite(Date.parse(basis.businessTime))) return false;
598
+ return Array.isArray(basis.criteria) && basis.criteria.every((c) => {
599
+ if (!c || typeof c !== "object" || Array.isArray(c) || typeof c.id !== "string" || !c.id.trim()) return false;
600
+ if (["description", "expression", "evaluatedPropertyId"].some((key) => c[key] !== void 0 && typeof c[key] !== "string")) return false;
601
+ if (c.limit === void 0) return true;
602
+ const limit = c.limit;
603
+ if (!limit || typeof limit !== "object" || Array.isArray(limit)) return false;
604
+ if (["minimum", "maximum"].some((key) => limit[key] !== void 0 && (typeof limit[key] !== "number" || !Number.isFinite(limit[key])))) return false;
605
+ if (limit.uom !== void 0 && typeof limit.uom !== "string") return false;
606
+ return !(limit.minimum !== void 0 && limit.maximum !== void 0 && limit.minimum > limit.maximum);
607
+ });
608
+ }
591
609
  function judgeAgainstSpec(spec, result) {
592
- const criteria = (spec?.criteria ?? []).filter((c) => !criterionSaysNothing(c));
610
+ const basis = result?.specificationBasis;
611
+ if (basis !== void 0 && !isTestSpecificationBasis(basis)) return void 0;
612
+ const criteria = (basis ? basis.criteria : spec?.criteria ?? []).filter((c) => !criterionSaysNothing(c));
593
613
  if (!criteria.length) return void 0;
594
614
  const measurements = result?.propertyMeasurements ?? [];
595
615
  let allJudged = true;
@@ -871,6 +891,13 @@ function homeOf(e) {
871
891
  const id = e?.homeLocation;
872
892
  return id ? { id, kind: e?.homeLocationKind ?? "location" } : void 0;
873
893
  }
894
+ function isRecipeExecutionBasis(value) {
895
+ if (!value || typeof value !== "object") return false;
896
+ const v = value;
897
+ const text = (x) => typeof x === "string" && x.trim().length > 0;
898
+ 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)));
899
+ 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)));
900
+ }
874
901
  var OP_EVENT = {
875
902
  task: "task.status",
876
903
  equipment: "equipment.status",
@@ -3717,13 +3744,19 @@ var SPECS = {
3717
3744
  *
3718
3745
  * 새 어휘가 아니다 — 계약이 `recipeKey` 를 네 자리에서 이미 쓴다. 오더 관측에만 자리가 없었다.
3719
3746
  */
3720
- recipeKey: "string"
3747
+ recipeKey: "string",
3748
+ recipeBasis: "object"
3721
3749
  },
3722
3750
  /*
3723
3751
  * 확보분의 안쪽을 본다 — 열쇠와 수 둘이다(§`AllocatedQuantity`). 안 보면 틀린 이름이 조용히
3724
3752
  * 지나가고(`epcs`·`quantity` 따위), 미러는 잡힌 수를 0 으로 읽는다.
3725
3753
  */
3726
3754
  shapes: {
3755
+ recipeBasis: {
3756
+ required: ["basisId", "recipeId", "revisionId", "planId", "contentHash", "businessTime", "recipe"],
3757
+ fields: { basisId: "string", recipeId: "string", revisionId: "string", planId: "string", contentHash: "string", businessTime: "string" }
3758
+ // Owned composition and captured route are additionally checked by isRecipeExecutionBasis below.
3759
+ },
3727
3760
  allocated: {
3728
3761
  required: ["epc", "qty"],
3729
3762
  fields: { epc: "string", qty: "number" },
@@ -3887,8 +3920,15 @@ var SPECS = {
3887
3920
  expiresAt: "string",
3888
3921
  derived: "boolean",
3889
3922
  propertyMeasurements: "object[]",
3923
+ specificationBasis: "object",
3890
3924
  recordTime: "string"
3891
3925
  },
3926
+ shapes: {
3927
+ specificationBasis: {
3928
+ required: ["id", "revisionId", "planId", "contentHash", "businessTime", "criteria"],
3929
+ fields: { id: "string", revisionId: "string", planId: "string", contentHash: "string", businessTime: "string" }
3930
+ }
3931
+ },
3892
3932
  enums: { result: ["pass", "fail"] }
3893
3933
  },
3894
3934
  /*
@@ -4063,6 +4103,12 @@ function ingestOperationalRecords(records, opts) {
4063
4103
  }
4064
4104
  }
4065
4105
  }
4106
+ if (kind === "test" && r.specificationBasis !== void 0 && !isTestSpecificationBasis(r.specificationBasis)) {
4107
+ errors.push("test.specificationBasis: invalid pinned specification evidence");
4108
+ }
4109
+ if (kind === "order" && r.recipeBasis !== void 0 && (!isRecipeExecutionBasis(r.recipeBasis) || r.recipeKey !== void 0 && r.recipeKey !== r.recipeBasis.recipe.key)) {
4110
+ errors.push("order.recipeBasis: invalid pinned recipe evidence");
4111
+ }
4066
4112
  const closedPeriodEnd = kind === "equipment-period" ? String(r.to ?? "").trim() : "";
4067
4113
  const at2 = closedPeriodEnd || String(r.at ?? "").trim() || opts.defaultEventTime;
4068
4114
  const atMs = at2 ? Date.parse(at2) : Number.NaN;
@@ -4885,7 +4931,9 @@ function nonEmpty(value) {
4885
4931
  isOperationalRecord,
4886
4932
  isOrderTerminal,
4887
4933
  isPlannedStopStatus,
4934
+ isRecipeExecutionBasis,
4888
4935
  isResourceKind,
4936
+ isTestSpecificationBasis,
4889
4937
  isTransformationRecord,
4890
4938
  isWebhookDeliveryCode,
4891
4939
  isWebhookSecretSegment,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@operato/ops-contract",
3
- "version": "0.9.30",
3
+ "version": "0.9.32",
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",