@operato/ops-contract 0.9.31 → 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.
@@ -2023,7 +2023,36 @@ export interface TaskState {
2023
2023
  * 실적 쪽 대응은 `TaskState`(`SegmentResponse`) 다 — 요구와 응답을 한 짝으로 읽어야 "얼마나 시켰고
2024
2024
  * 얼마나 됐나" 가 나온다.
2025
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;
2026
2054
  export interface OrderState {
2055
+ recipeBasis?: RecipeExecutionBasis;
2027
2056
  id: string;
2028
2057
  kind: string;
2029
2058
  status: string;
@@ -3666,6 +3695,7 @@ export interface ObservedOrderLine {
3666
3695
  allocated?: number;
3667
3696
  }
3668
3697
  export interface OrderStatusDelta {
3698
+ recipeBasis?: RecipeExecutionBasis;
3669
3699
  orderId: string;
3670
3700
  kind: string;
3671
3701
  status: string;
package/dist/contract.js CHANGED
@@ -1085,6 +1085,20 @@ export function homeOf(e) {
1085
1085
  const id = e?.homeLocation;
1086
1086
  return id ? { id, kind: e?.homeLocationKind ?? 'location' } : undefined;
1087
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
+ }
1088
1102
  // ── 운영 델타(비-EPCIS) — State 채널의 나머지 절반 ──────────────────────────
1089
1103
  // EPCIS 이벤트는 재고/위치만 재구성 가능. tasks·equipment·orders 의 운영 상태는
1090
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, isTestSpecificationBasis } 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' },
@@ -620,6 +625,10 @@ export function ingestOperationalRecords(records, opts) {
620
625
  if (kind === 'test' && r.specificationBasis !== undefined && !isTestSpecificationBasis(r.specificationBasis)) {
621
626
  errors.push('test.specificationBasis: invalid pinned specification evidence');
622
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
+ }
623
632
  const closedPeriodEnd = kind === 'equipment-period' ? String(r.to ?? '').trim() : '';
624
633
  const at = closedPeriodEnd || String(r.at ?? '').trim() || opts.defaultEventTime;
625
634
  const atMs = at ? Date.parse(at) : Number.NaN;
@@ -174,6 +174,7 @@ __export(index_exports, {
174
174
  isOperationalRecord: () => isOperationalRecord,
175
175
  isOrderTerminal: () => isOrderTerminal,
176
176
  isPlannedStopStatus: () => isPlannedStopStatus,
177
+ isRecipeExecutionBasis: () => isRecipeExecutionBasis,
177
178
  isResourceKind: () => isResourceKind,
178
179
  isTestSpecificationBasis: () => isTestSpecificationBasis,
179
180
  isTransformationRecord: () => isTransformationRecord,
@@ -890,6 +891,13 @@ function homeOf(e) {
890
891
  const id = e?.homeLocation;
891
892
  return id ? { id, kind: e?.homeLocationKind ?? "location" } : void 0;
892
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
+ }
893
901
  var OP_EVENT = {
894
902
  task: "task.status",
895
903
  equipment: "equipment.status",
@@ -3736,13 +3744,19 @@ var SPECS = {
3736
3744
  *
3737
3745
  * 새 어휘가 아니다 — 계약이 `recipeKey` 를 네 자리에서 이미 쓴다. 오더 관측에만 자리가 없었다.
3738
3746
  */
3739
- recipeKey: "string"
3747
+ recipeKey: "string",
3748
+ recipeBasis: "object"
3740
3749
  },
3741
3750
  /*
3742
3751
  * 확보분의 안쪽을 본다 — 열쇠와 수 둘이다(§`AllocatedQuantity`). 안 보면 틀린 이름이 조용히
3743
3752
  * 지나가고(`epcs`·`quantity` 따위), 미러는 잡힌 수를 0 으로 읽는다.
3744
3753
  */
3745
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
+ },
3746
3760
  allocated: {
3747
3761
  required: ["epc", "qty"],
3748
3762
  fields: { epc: "string", qty: "number" },
@@ -4092,6 +4106,9 @@ function ingestOperationalRecords(records, opts) {
4092
4106
  if (kind === "test" && r.specificationBasis !== void 0 && !isTestSpecificationBasis(r.specificationBasis)) {
4093
4107
  errors.push("test.specificationBasis: invalid pinned specification evidence");
4094
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
+ }
4095
4112
  const closedPeriodEnd = kind === "equipment-period" ? String(r.to ?? "").trim() : "";
4096
4113
  const at2 = closedPeriodEnd || String(r.at ?? "").trim() || opts.defaultEventTime;
4097
4114
  const atMs = at2 ? Date.parse(at2) : Number.NaN;
@@ -4914,6 +4931,7 @@ function nonEmpty(value) {
4914
4931
  isOperationalRecord,
4915
4932
  isOrderTerminal,
4916
4933
  isPlannedStopStatus,
4934
+ isRecipeExecutionBasis,
4917
4935
  isResourceKind,
4918
4936
  isTestSpecificationBasis,
4919
4937
  isTransformationRecord,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@operato/ops-contract",
3
- "version": "0.9.31",
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",