@operato/ops-contract 0.9.48 → 0.9.50
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/README.md +12 -5
- package/dist/asset-acceptance.d.ts +27 -0
- package/dist/asset-acceptance.js +33 -0
- package/dist/capability.d.ts +1 -1
- package/dist/capability.js +16 -1
- package/dist/contract.d.ts +61 -3
- package/dist/contract.js +59 -4
- package/dist/domain-catalog.d.ts +9 -2
- package/dist/domain-catalog.js +36 -4
- package/dist/energy-ingest.js +4 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/intralogistics-profile.d.ts +114 -0
- package/dist/intralogistics-profile.js +149 -0
- package/dist/operational-ingest.d.ts +4 -2
- package/dist/operational-ingest.js +78 -4
- package/dist/route-network.d.ts +84 -0
- package/dist/route-network.js +132 -0
- package/dist/transport-policy.d.ts +79 -0
- package/dist/transport-policy.js +68 -0
- package/dist/travel.d.ts +83 -0
- package/dist/travel.js +32 -0
- package/dist/yms-profile.d.ts +1 -1
- package/dist/yms-profile.js +1 -1
- package/dist-cjs/index.cjs +2392 -1889
- package/package.json +1 -1
package/dist-cjs/index.cjs
CHANGED
|
@@ -34,7 +34,10 @@ __export(index_exports, {
|
|
|
34
34
|
COMMAND_EVENT: () => COMMAND_EVENT,
|
|
35
35
|
COMMAND_ORIGIN: () => COMMAND_ORIGIN,
|
|
36
36
|
COMMAND_STATE: () => COMMAND_STATE,
|
|
37
|
+
CONNECTION_DIRECTION: () => CONNECTION_DIRECTION,
|
|
38
|
+
DEFAULT_CONNECTION_CAPACITY: () => DEFAULT_CONNECTION_CAPACITY,
|
|
37
39
|
DISP: () => DISP,
|
|
40
|
+
DISPATCH_RULE: () => DISPATCH_RULE,
|
|
38
41
|
DISPOSITION_DECISION: () => DISPOSITION_DECISION,
|
|
39
42
|
DOCK_DOOR_STATUS: () => DOCK_DOOR_STATUS,
|
|
40
43
|
DOCK_FACT_KIND: () => DOCK_FACT_KIND,
|
|
@@ -50,14 +53,24 @@ __export(index_exports, {
|
|
|
50
53
|
EPCIS_CONTEXT: () => EPCIS_CONTEXT,
|
|
51
54
|
EPCIS_EVENT: () => EPCIS_EVENT,
|
|
52
55
|
EQUIPMENT_LEVEL: () => EQUIPMENT_LEVEL,
|
|
56
|
+
EQUIPMENT_PROPERTY: () => EQUIPMENT_PROPERTY,
|
|
53
57
|
EQUIPMENT_STATUS: () => EQUIPMENT_STATUS,
|
|
54
58
|
ERP_CAPABILITY: () => ERP_CAPABILITY,
|
|
55
59
|
ERP_MASTER_AXIS: () => ERP_MASTER_AXIS,
|
|
56
60
|
FIELDS_NOT_CARRIED: () => FIELDS_NOT_CARRIED,
|
|
57
61
|
FIRST_PASS_RULE: () => FIRST_PASS_RULE,
|
|
62
|
+
FIXED_ROUTE_BINDING: () => FIXED_ROUTE_BINDING,
|
|
58
63
|
GUARD_PRAGMA: () => GUARD_PRAGMA,
|
|
59
64
|
HATIOLAB_VOCABULARY: () => HATIOLAB_VOCABULARY,
|
|
60
65
|
HEADER_FIELDS_PARTITIONED: () => HEADER_FIELDS_PARTITIONED,
|
|
66
|
+
ILG_ATTENTION_KIND: () => ILG_ATTENTION_KIND,
|
|
67
|
+
ILG_BIZSTEP: () => ILG_BIZSTEP,
|
|
68
|
+
ILG_EQUIPMENT_PROPERTY: () => ILG_EQUIPMENT_PROPERTY,
|
|
69
|
+
ILG_LOCATION_TYPES: () => ILG_LOCATION_TYPES,
|
|
70
|
+
ILG_ORDER_KIND: () => ILG_ORDER_KIND,
|
|
71
|
+
ILG_ROBOT_IDENTITY_PROPERTY: () => ILG_ROBOT_IDENTITY_PROPERTY,
|
|
72
|
+
ILG_TASK_KIND: () => ILG_TASK_KIND,
|
|
73
|
+
ILG_TYPES: () => ILG_TYPES,
|
|
61
74
|
ILMD_ATTR: () => ILMD_ATTR,
|
|
62
75
|
LOCATION_SATURATION_NEAR: () => LOCATION_SATURATION_NEAR,
|
|
63
76
|
MATERIAL_ACTUAL_USE: () => MATERIAL_ACTUAL_USE,
|
|
@@ -82,6 +95,7 @@ __export(index_exports, {
|
|
|
82
95
|
PARTY_ROLE: () => PARTY_ROLE,
|
|
83
96
|
PARTY_URI_MAX_LENGTH: () => PARTY_URI_MAX_LENGTH,
|
|
84
97
|
PARTY_URI_RECOMMENDED_LENGTH: () => PARTY_URI_RECOMMENDED_LENGTH,
|
|
98
|
+
PERCENT_UOM: () => PERCENT_UOM,
|
|
85
99
|
PERSON_STATUS: () => PERSON_STATUS,
|
|
86
100
|
PRIORITY_UNSET: () => PRIORITY_UNSET,
|
|
87
101
|
PRIVATE_BIZSTEP: () => PRIVATE_BIZSTEP,
|
|
@@ -91,15 +105,23 @@ __export(index_exports, {
|
|
|
91
105
|
RESOURCE_KIND: () => RESOURCE_KIND,
|
|
92
106
|
RETIRED_VOCABULARY: () => RETIRED_VOCABULARY,
|
|
93
107
|
RETURN_TO_SUPPLIER: () => RETURN_TO_SUPPLIER,
|
|
108
|
+
ROUTE_NETWORK_ISSUE: () => ROUTE_NETWORK_ISSUE,
|
|
109
|
+
ROUTING_RULE: () => ROUTING_RULE,
|
|
94
110
|
SCHEDULE_STATUS: () => SCHEDULE_STATUS,
|
|
95
111
|
SIGNATURE_REJECTED_REASONS: () => SIGNATURE_REJECTED_REASONS,
|
|
96
112
|
SOURCE_DEST_PARTY_TYPE: () => SOURCE_DEST_PARTY_TYPE,
|
|
113
|
+
SPEED_TO_MPS: () => SPEED_TO_MPS,
|
|
97
114
|
TARIFF_DAY_KINDS: () => TARIFF_DAY_KINDS,
|
|
98
115
|
TARIFF_ISSUE_CODES: () => TARIFF_ISSUE_CODES,
|
|
99
116
|
TARIFF_LOAD_CLASSES: () => TARIFF_LOAD_CLASSES,
|
|
100
117
|
TASK_STATUS: () => TASK_STATUS,
|
|
101
118
|
TASK_TERMINAL_STATUS: () => TASK_TERMINAL_STATUS,
|
|
119
|
+
TRAFFIC_CONFLICT_ACTION: () => TRAFFIC_CONFLICT_ACTION,
|
|
102
120
|
TRAILER_LOAD: () => TRAILER_LOAD,
|
|
121
|
+
TRANSPORT_FAILURE_REASON: () => TRANSPORT_FAILURE_REASON,
|
|
122
|
+
TRANSPORT_POLICY_ISSUE: () => TRANSPORT_POLICY_ISSUE,
|
|
123
|
+
TRAVEL_LINK_JUDGED_BY: () => TRAVEL_LINK_JUDGED_BY,
|
|
124
|
+
TRAVEL_LINK_STATE: () => TRAVEL_LINK_STATE,
|
|
103
125
|
TWIN_AXES: () => TWIN_AXES,
|
|
104
126
|
TWIN_PROPERTIES: () => TWIN_PROPERTIES,
|
|
105
127
|
TWIN_RELATIONS: () => TWIN_RELATIONS,
|
|
@@ -126,6 +148,7 @@ __export(index_exports, {
|
|
|
126
148
|
YMS_ORDER_KIND: () => YMS_ORDER_KIND,
|
|
127
149
|
YMS_TASK_KIND: () => YMS_TASK_KIND,
|
|
128
150
|
YMS_TYPES: () => YMS_TYPES,
|
|
151
|
+
acceptsMaterial: () => acceptsMaterial,
|
|
129
152
|
acceptsPerformance: () => acceptsPerformance,
|
|
130
153
|
activeBands: () => activeBands,
|
|
131
154
|
activeShiftAt: () => activeShiftAt,
|
|
@@ -157,6 +180,7 @@ __export(index_exports, {
|
|
|
157
180
|
computeMtbf: () => computeMtbf,
|
|
158
181
|
computeMttr: () => computeMttr,
|
|
159
182
|
computeOee: () => computeOee,
|
|
183
|
+
connectionAdmits: () => connectionAdmits,
|
|
160
184
|
conversionFactorOf: () => conversionFactorOf,
|
|
161
185
|
criterionSaysNothing: () => criterionSaysNothing,
|
|
162
186
|
dayOfYearOf: () => dayOfYearOf,
|
|
@@ -202,6 +226,7 @@ __export(index_exports, {
|
|
|
202
226
|
ingestOperationalRecords: () => ingestOperationalRecords,
|
|
203
227
|
inheritedExpiry: () => inheritedExpiry,
|
|
204
228
|
inheritedLotUse: () => inheritedLotUse,
|
|
229
|
+
intralogisticsTypeOf: () => intralogisticsTypeOf,
|
|
205
230
|
isAggregationRecord: () => isAggregationRecord,
|
|
206
231
|
isAppointmentClosed: () => isAppointmentClosed,
|
|
207
232
|
isCacheableTense: () => isCacheableTense,
|
|
@@ -221,6 +246,8 @@ __export(index_exports, {
|
|
|
221
246
|
isEquipmentStatus: () => isEquipmentStatus,
|
|
222
247
|
isFailureStatus: () => isFailureStatus,
|
|
223
248
|
isFlowOrder: () => isFlowOrder,
|
|
249
|
+
isGuidedType: () => isGuidedType,
|
|
250
|
+
isHeading: () => isHeading,
|
|
224
251
|
isIso4217Code: () => isIso4217Code,
|
|
225
252
|
isIsoDateTime: () => isIsoDateTime,
|
|
226
253
|
isMasterDataRecord: () => isMasterDataRecord,
|
|
@@ -239,6 +266,8 @@ __export(index_exports, {
|
|
|
239
266
|
isTaskTerminal: () => isTaskTerminal,
|
|
240
267
|
isTestSpecificationBasis: () => isTestSpecificationBasis,
|
|
241
268
|
isTransformationRecord: () => isTransformationRecord,
|
|
269
|
+
isTransportFailureReason: () => isTransportFailureReason,
|
|
270
|
+
isTravelRecord: () => isTravelRecord,
|
|
242
271
|
isWebhookDeliveryCode: () => isWebhookDeliveryCode,
|
|
243
272
|
isWebhookSecretSegment: () => isWebhookSecretSegment,
|
|
244
273
|
isWorkShiftExecutionBasis: () => isWorkShiftExecutionBasis,
|
|
@@ -252,6 +281,7 @@ __export(index_exports, {
|
|
|
252
281
|
judgeAgainstSpec: () => judgeAgainstSpec,
|
|
253
282
|
levelOfLocationType: () => levelOfLocationType,
|
|
254
283
|
lgtinClass: () => lgtinClass,
|
|
284
|
+
linkStateAt: () => linkStateAt,
|
|
255
285
|
localDayIndexAt: () => localDayIndexAt,
|
|
256
286
|
localDayStartMs: () => localDayStartMs,
|
|
257
287
|
locationStatusOf: () => locationStatusOf,
|
|
@@ -317,6 +347,7 @@ __export(index_exports, {
|
|
|
317
347
|
sameItemClass: () => sameItemClass,
|
|
318
348
|
sgtinClass: () => sgtinClass,
|
|
319
349
|
sgtinUri: () => sgtinUri,
|
|
350
|
+
speedMpsOf: () => speedMpsOf,
|
|
320
351
|
splitFlowOrders: () => splitFlowOrders,
|
|
321
352
|
splitRelationIds: () => splitRelationIds,
|
|
322
353
|
ssccDigitsOf: () => ssccDigitsOf,
|
|
@@ -338,7 +369,9 @@ __export(index_exports, {
|
|
|
338
369
|
validateDomainDefinition: () => validateDomainDefinition,
|
|
339
370
|
validateEpcisEvent: () => validateEpcisEvent,
|
|
340
371
|
validatePerformance: () => validatePerformance,
|
|
372
|
+
validateRouteNetwork: () => validateRouteNetwork,
|
|
341
373
|
validateScenario: () => validateScenario,
|
|
374
|
+
validateTransportPolicy: () => validateTransportPolicy,
|
|
342
375
|
verdictOfAck: () => verdictOfAck,
|
|
343
376
|
webhookLaneOf: () => webhookLaneOf,
|
|
344
377
|
webhookSecretCandidates: () => webhookSecretCandidates,
|
|
@@ -477,9 +510,29 @@ var CAPABILITIES = {
|
|
|
477
510
|
models: ["StoringState"],
|
|
478
511
|
invariants: ["0 <= soc <= 100"],
|
|
479
512
|
results: ["stored", "discharged"]
|
|
513
|
+
},
|
|
514
|
+
/*
|
|
515
|
+
* ── Guided — travels the route network under transport control (2026-12-03, operato-application ADR-0266) ──────────────
|
|
516
|
+
*
|
|
517
|
+
* `mobile` says a resource moves between locations; a forklift a person drives has it. Last location passed, reserved
|
|
518
|
+
* connections and link state mean something only for equipment under transport control, so they are a capability of their
|
|
519
|
+
* own, declared together with `mobile`. Battery is not repeated here: guided equipment declares `energyStoring` as well.
|
|
520
|
+
*
|
|
521
|
+
* No commands. The twin does not drive robots: dispatch, pause and resume are the transport control product's instructions
|
|
522
|
+
* to its equipment (VDA 5050 instant actions), not stimuli inside the kernel, so they do not belong in `CMD`.
|
|
523
|
+
*/
|
|
524
|
+
guided: {
|
|
525
|
+
key: "guided",
|
|
526
|
+
label: "twin.capability.guided",
|
|
527
|
+
semantics: "\uACBD\uB85C\uB9DD \uC704\uB97C \uAD00\uC81C\uC5D0 \uB530\uB77C \uB2E4\uB2C8\uB294 \uC7A5\uBE44 \u2014 \uB9C8\uC9C0\uB9C9\uC73C\uB85C \uC9C0\uB09C \uC790\uB9AC \xB7 \uC9C4\uD589 \uBC29\uD5A5 \xB7 \uC608\uC57D \uAD6C\uAC04 \xB7 \uD1B5\uC2E0 \uC0C1\uD0DC \xB7 \uCE21\uC815 \uC704\uCE58. mobile \uACFC \uD568\uAED8 \uC120\uC5B8\uD55C\uB2E4.",
|
|
528
|
+
commands: [],
|
|
529
|
+
stateFields: ["travel"],
|
|
530
|
+
models: ["TravelState"],
|
|
531
|
+
invariants: ["guided => mobile", "0 <= heading < 360"],
|
|
532
|
+
results: ["passed", "reserved", "linkChanged", "poseReported"]
|
|
480
533
|
}
|
|
481
534
|
};
|
|
482
|
-
var CAPABILITY_KEYS = ["operable", "storable", "mobile", "processable", "trackable", "switching", "metered", "curtailable", "energyGenerating", "energyStoring"];
|
|
535
|
+
var CAPABILITY_KEYS = ["operable", "storable", "mobile", "processable", "trackable", "switching", "metered", "curtailable", "energyGenerating", "energyStoring", "guided"];
|
|
483
536
|
function stateFieldsOf(caps) {
|
|
484
537
|
const out = /* @__PURE__ */ new Set();
|
|
485
538
|
for (const c of caps) for (const f of CAPABILITIES[c]?.stateFields ?? []) out.add(f);
|
|
@@ -528,7 +581,7 @@ var TASK_TERMINAL_STATUS = ["completed", "cancelled"];
|
|
|
528
581
|
function isTaskTerminal(t) {
|
|
529
582
|
return TASK_TERMINAL_STATUS.includes(String(t?.status ?? ""));
|
|
530
583
|
}
|
|
531
|
-
var ORDER_TERMINAL_STATUS = ["completed", "cancelled"];
|
|
584
|
+
var ORDER_TERMINAL_STATUS = ["completed", "cancelled", "failed"];
|
|
532
585
|
function isOrderTerminal(o) {
|
|
533
586
|
const status = String(o?.status ?? "").trim().toLowerCase();
|
|
534
587
|
if (ORDER_TERMINAL_STATUS.includes(status)) return true;
|
|
@@ -804,6 +857,27 @@ var MATERIAL_PROPERTY = {
|
|
|
804
857
|
/** 기준 단위 하나당 이 단위의 양. `uom` 이 대상 단위. */
|
|
805
858
|
perBaseUnit: "perBaseUnit"
|
|
806
859
|
};
|
|
860
|
+
var EQUIPMENT_PROPERTY = {
|
|
861
|
+
/** 설비의 빠르기 — `uom` 이 `SPEED_TO_MPS` 의 코드. */
|
|
862
|
+
speed: "speed"
|
|
863
|
+
};
|
|
864
|
+
var SPEED_TO_MPS = {
|
|
865
|
+
/** metre per second */
|
|
866
|
+
MTS: 1,
|
|
867
|
+
/** kilometre per hour */
|
|
868
|
+
KMH: 1e3 / 3600,
|
|
869
|
+
/** foot per second */
|
|
870
|
+
"2M": 0.3048,
|
|
871
|
+
/** mile per hour */
|
|
872
|
+
HM: 0.44704
|
|
873
|
+
};
|
|
874
|
+
function speedMpsOf(properties) {
|
|
875
|
+
const speed = (properties ?? []).find((one) => one?.id === EQUIPMENT_PROPERTY.speed);
|
|
876
|
+
if (!speed) return void 0;
|
|
877
|
+
const value = typeof speed.value === "number" ? speed.value : Number(speed.value);
|
|
878
|
+
const factor = speed.uom ? SPEED_TO_MPS[speed.uom] : void 0;
|
|
879
|
+
return Number.isFinite(value) && value > 0 && factor !== void 0 ? value * factor : void 0;
|
|
880
|
+
}
|
|
807
881
|
function conversionFactorOf(def, uom) {
|
|
808
882
|
if (!def || !uom) return void 0;
|
|
809
883
|
for (const p of def.properties ?? []) {
|
|
@@ -1132,7 +1206,20 @@ var OP_EVENT = {
|
|
|
1132
1206
|
* 이름을 `energy.measured` 와 같은 결로 둔다 — 그쪽이 에너지 계량의 도착이고 이쪽이 그 일반형이다.
|
|
1133
1207
|
* 두 채널을 합치지 않는 이유는 에너지 쪽이 **구간에 누적되는 표본**이라 처리가 다르기 때문이다.
|
|
1134
1208
|
*/
|
|
1135
|
-
observation: "location.measured"
|
|
1209
|
+
observation: "location.measured",
|
|
1210
|
+
/*
|
|
1211
|
+
* ── Travel of guided equipment (2026-12-03, operato-application ADR-0266 decision 8 ②, `travel.ts`) ────────────────────
|
|
1212
|
+
*
|
|
1213
|
+
* The four facts that carry `EquipmentState.travel` into the journal (state ⊆ events). Sent on change, never per tick.
|
|
1214
|
+
* Payloads: `TravelPassedFact` · `TravelReservationFact` · `TravelLinkFact` · `TravelPoseFact`.
|
|
1215
|
+
*
|
|
1216
|
+
* The transport control product sends them as operational records (`operational-ingest` kinds `travel-passed`,
|
|
1217
|
+
* `travel-reservation`, `travel-link`, `travel-pose`, 2026-12-04); the observed reducer folds them into `EquipmentState.travel`.
|
|
1218
|
+
*/
|
|
1219
|
+
travelPassed: "equipment.passed",
|
|
1220
|
+
travelReservation: "equipment.reservation",
|
|
1221
|
+
travelLink: "equipment.link",
|
|
1222
|
+
travelPose: "equipment.pose"
|
|
1136
1223
|
};
|
|
1137
1224
|
var ENERGY_EVENT = {
|
|
1138
1225
|
/** 계량 도착 — 그 시점의 유효전력·누적량. 15분 수요 구간에 누적된다. */
|
|
@@ -2372,6 +2459,92 @@ function isElectricalLocationType(type) {
|
|
|
2372
2459
|
return EMS_LOCATION_TYPES.includes(type);
|
|
2373
2460
|
}
|
|
2374
2461
|
|
|
2462
|
+
// src/intralogistics-profile.ts
|
|
2463
|
+
var ILG_BIZSTEP = {
|
|
2464
|
+
/** The carrier left a port. */
|
|
2465
|
+
departing: "urn:epcglobal:cbv:bizstep:departing",
|
|
2466
|
+
/** The carrier reached a port. */
|
|
2467
|
+
arriving: "urn:epcglobal:cbv:bizstep:arriving",
|
|
2468
|
+
/** The carrier is on its way. */
|
|
2469
|
+
transporting: "urn:epcglobal:cbv:bizstep:transporting"
|
|
2470
|
+
};
|
|
2471
|
+
var ILG_LOCATION_TYPES = ["waypoint", "port", "charger", "parking"];
|
|
2472
|
+
var ILG_LOCATION_LEVEL = {
|
|
2473
|
+
waypoint: "Other",
|
|
2474
|
+
port: "StorageUnit",
|
|
2475
|
+
charger: "Other",
|
|
2476
|
+
parking: "Other"
|
|
2477
|
+
};
|
|
2478
|
+
var ILG_LOCATION_CAPABILITIES = {
|
|
2479
|
+
waypoint: [],
|
|
2480
|
+
port: ["storable"],
|
|
2481
|
+
charger: [],
|
|
2482
|
+
parking: []
|
|
2483
|
+
};
|
|
2484
|
+
var ILG_TYPES = [
|
|
2485
|
+
...ILG_LOCATION_TYPES.map((k) => ({
|
|
2486
|
+
key: k,
|
|
2487
|
+
role: "location",
|
|
2488
|
+
label: `twin.type.${k}`,
|
|
2489
|
+
standardClass: { epcis: "bizLocation" },
|
|
2490
|
+
identity: { scheme: "gs1:SGLN" },
|
|
2491
|
+
level: ILG_LOCATION_LEVEL[k],
|
|
2492
|
+
capabilities: ILG_LOCATION_CAPABILITIES[k]
|
|
2493
|
+
})),
|
|
2494
|
+
/* A forklift under transport control keeps the wms `forklift` type and adds `guided` in the site's own declaration. */
|
|
2495
|
+
{ key: "amr", role: "equipment", label: "twin.type.amr", standardClass: { epcis: "object", iso55000: "Asset" }, identity: { scheme: "gs1:GIAI" }, capabilities: ["mobile", "guided", "operable", "energyStoring"] },
|
|
2496
|
+
{ key: "agv", role: "equipment", label: "twin.type.agv", standardClass: { epcis: "object", iso55000: "Asset" }, identity: { scheme: "gs1:GIAI" }, capabilities: ["mobile", "guided", "operable", "energyStoring"] }
|
|
2497
|
+
];
|
|
2498
|
+
function intralogisticsTypeOf(key) {
|
|
2499
|
+
return ILG_TYPES.find((t) => t.key === key);
|
|
2500
|
+
}
|
|
2501
|
+
function isGuidedType(key) {
|
|
2502
|
+
return intralogisticsTypeOf(key)?.capabilities.includes("guided") ?? false;
|
|
2503
|
+
}
|
|
2504
|
+
var ILG_EQUIPMENT_PROPERTY = {
|
|
2505
|
+
/** State of charge when the simulation starts, percent (`P1`). */
|
|
2506
|
+
charge: "charge",
|
|
2507
|
+
/** Charge used per metre travelled, percentage points (`P1`). */
|
|
2508
|
+
chargeUsePerMetre: "chargeUsePerMetre",
|
|
2509
|
+
/** Charge gained per minute on a charger, percentage points (`P1`). */
|
|
2510
|
+
chargeGainPerMinute: "chargeGainPerMinute"
|
|
2511
|
+
};
|
|
2512
|
+
var ILG_ROBOT_IDENTITY_PROPERTY = {
|
|
2513
|
+
manufacturer: "manufacturer",
|
|
2514
|
+
serialNumber: "serialNumber"
|
|
2515
|
+
};
|
|
2516
|
+
var PERCENT_UOM = "P1";
|
|
2517
|
+
var ILG_ORDER_KIND = {
|
|
2518
|
+
transport: "transport"
|
|
2519
|
+
};
|
|
2520
|
+
var ILG_TASK_KIND = {
|
|
2521
|
+
leg: "transport-leg",
|
|
2522
|
+
charge: "charge",
|
|
2523
|
+
park: "park"
|
|
2524
|
+
};
|
|
2525
|
+
var TRANSPORT_FAILURE_REASON = [
|
|
2526
|
+
"no-route",
|
|
2527
|
+
"destination-unavailable",
|
|
2528
|
+
"carrier-not-found",
|
|
2529
|
+
/** The carrier identified at pick-up is not the one the command named. */
|
|
2530
|
+
"carrier-mismatch",
|
|
2531
|
+
"cancelled-by-source",
|
|
2532
|
+
"equipment-fault"
|
|
2533
|
+
];
|
|
2534
|
+
function isTransportFailureReason(v) {
|
|
2535
|
+
return typeof v === "string" && TRANSPORT_FAILURE_REASON.includes(v);
|
|
2536
|
+
}
|
|
2537
|
+
var ILG_ATTENTION_KIND = {
|
|
2538
|
+
deadlock: "intralogic.traffic-deadlock",
|
|
2539
|
+
blocked: "intralogic.traffic-blocked",
|
|
2540
|
+
lowCharge: "intralogic.low-charge",
|
|
2541
|
+
linkLost: "intralogic.link-lost",
|
|
2542
|
+
noRoute: "intralogic.no-route",
|
|
2543
|
+
rerouted: "intralogic.rerouted",
|
|
2544
|
+
carrierUnidentified: "intralogic.carrier-unidentified",
|
|
2545
|
+
carrierDuplicate: "intralogic.carrier-duplicate"
|
|
2546
|
+
};
|
|
2547
|
+
|
|
2375
2548
|
// src/domain-catalog.ts
|
|
2376
2549
|
var locationKeys = (types) => types.filter((t) => t.role === "location").map((t) => t.key);
|
|
2377
2550
|
var DOMAIN_CATALOG = {
|
|
@@ -2650,7 +2823,18 @@ var TWIN_AXES = [
|
|
|
2650
2823
|
historical: true,
|
|
2651
2824
|
standardClass: {},
|
|
2652
2825
|
systems: ["ems"]
|
|
2653
|
-
}
|
|
2826
|
+
},
|
|
2827
|
+
/*
|
|
2828
|
+
* ── Route network (2026-12-03, operato-application ADR-0266 decision 8 ①) ──────────────────────────
|
|
2829
|
+
*
|
|
2830
|
+
* The edges guided equipment travels between locations, and the ordered edge lists some equipment must follow.
|
|
2831
|
+
* No standard names them: ISA-95 and EPCIS have no route network, and VDA 5050 is a protocol, not an ontology this
|
|
2832
|
+
* catalogue projects to. So `standardClass` stays empty rather than borrowing a near name.
|
|
2833
|
+
*
|
|
2834
|
+
* An energy twin has no travelling equipment, so both axes are logistics-only (`LOGISTICS`).
|
|
2835
|
+
*/
|
|
2836
|
+
{ axis: "connections", path: "connections", label: "twin.axis.connections", kind: "instance", standardClass: {}, systems: LOGISTICS },
|
|
2837
|
+
{ axis: "fixedRoutes", path: "fixedRoutes", label: "twin.axis.fixedRoutes", kind: "spec", standardClass: {}, systems: LOGISTICS }
|
|
2654
2838
|
];
|
|
2655
2839
|
function isCacheableTense(t) {
|
|
2656
2840
|
return t === "standing";
|
|
@@ -2749,7 +2933,20 @@ var TWIN_RELATIONS = [
|
|
|
2749
2933
|
{ from: "materialClasses", field: "testSpecificationIds[]", target: { kind: "axis", axis: "testSpecifications" }, via: "ops.rel.test", optional: true, tense: "standing" },
|
|
2750
2934
|
/* 공정이 도는 자리·자원 — 항목이 아니라 **타입**을 가리킨다 */
|
|
2751
2935
|
{ from: "operations", field: "locationType", target: { kind: "type", role: "location" }, via: "ops.rel.at", optional: true, tense: "standing" },
|
|
2752
|
-
{ from: "operations", field: "resourceType", target: { kind: "type", role: "equipment" }, via: "ops.rel.by", optional: true, tense: "standing" }
|
|
2936
|
+
{ from: "operations", field: "resourceType", target: { kind: "type", role: "equipment" }, via: "ops.rel.by", optional: true, tense: "standing" },
|
|
2937
|
+
/*
|
|
2938
|
+
* Route network (ADR-0266). A connection's ends are locations of this lens or referenced ones of another lens
|
|
2939
|
+
* (`referencedLocations`), so the target is the either-kind, like `locations.parentId`. Structure inside a published
|
|
2940
|
+
* edition has no time of its own - it holds for as long as the edition does - so these are `standing`, like a location's parent.
|
|
2941
|
+
*/
|
|
2942
|
+
{ from: "connections", field: "from", target: { kind: "axis-or-external", axis: "locations", entity: "lens.referencedLocation" }, via: "ops.rel.from", tense: "standing" },
|
|
2943
|
+
{ from: "connections", field: "to", target: { kind: "axis-or-external", axis: "locations", entity: "lens.referencedLocation" }, via: "ops.rel.to", tense: "standing" },
|
|
2944
|
+
{ from: "connections", field: "equipmentClassIds[]", target: { kind: "axis", axis: "equipmentClasses" }, via: "ops.rel.allows", optional: true, tense: "standing" },
|
|
2945
|
+
{ from: "fixedRoutes", field: "connectionIds[]", target: { kind: "axis", axis: "connections" }, via: "ops.rel.along", tense: "standing" },
|
|
2946
|
+
{ from: "fixedRoutes", field: "equipmentClassIds[]", target: { kind: "axis", axis: "equipmentClasses" }, via: "ops.rel.allows", optional: true, tense: "standing" },
|
|
2947
|
+
/* What a carrier accepts (ADR-0266 decision 8 ③) - a property of the asset class, so standing like the class itself. */
|
|
2948
|
+
{ from: "assetClasses", field: "accepts.materialDefinitionIds[]", target: { kind: "axis", axis: "materialDefinitions" }, via: "ops.rel.accepts", optional: true, tense: "standing" },
|
|
2949
|
+
{ from: "assetClasses", field: "accepts.materialClassIds[]", target: { kind: "axis", axis: "materialClasses" }, via: "ops.rel.accepts", optional: true, tense: "standing" }
|
|
2753
2950
|
];
|
|
2754
2951
|
var TWIN_PROPERTIES = [
|
|
2755
2952
|
/* 공정 — 선언(ISO 8601 기간)과 관측(저널에서 계산한 분포)이 둘 다 있는 유일한 짝. */
|
|
@@ -2838,7 +3035,7 @@ var levelOfLocationType = (typeKey, system) => {
|
|
|
2838
3035
|
};
|
|
2839
3036
|
var axesOfSystem = (system) => TWIN_AXES.filter((a) => axisAppliesTo(a.axis, system));
|
|
2840
3037
|
function capabilitiesForType(system, typeKey) {
|
|
2841
|
-
return DOMAIN_CATALOG[system]?.types.find((t) => t.key === typeKey)?.capabilities ?? [];
|
|
3038
|
+
return DOMAIN_CATALOG[system]?.types.find((t) => t.key === typeKey)?.capabilities ?? ILG_TYPES.find((t) => t.key === typeKey)?.capabilities ?? [];
|
|
2842
3039
|
}
|
|
2843
3040
|
|
|
2844
3041
|
// src/domain-definition.ts
|
|
@@ -2925,2046 +3122,2319 @@ function validateCatalog(cat) {
|
|
|
2925
3122
|
return v;
|
|
2926
3123
|
}
|
|
2927
3124
|
|
|
2928
|
-
// src/
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
for (const record of arr) {
|
|
2941
|
-
const errors = [];
|
|
2942
|
-
const meterId = String(record?.meterId ?? "").trim();
|
|
2943
|
-
if (!meterId) errors.push("meterId \uC5C6\uC74C \u2014 \uC5B4\uB514\uC758 \uC18C\uBE44\uC778\uC9C0 \uBAA8\uB974\uB294 \uAC12\uC740 \uB204\uC801\uD560 \uC218 \uC5C6\uB2E4");
|
|
2944
|
-
const at2 = String(record?.at ?? "").trim() || opts.defaultEventTime;
|
|
2945
|
-
const atMs = at2 ? Date.parse(at2) : Number.NaN;
|
|
2946
|
-
if (!Number.isFinite(atMs)) errors.push("at \uC5C6\uC74C/\uD615\uC2DD \uC624\uB958 \u2014 \uC9C0\uAE08 \uC2DC\uAC01\uC73C\uB85C \uBA54\uC6B0\uBA74 \uB0A8\uC758 \uC218\uC694 \uAD6C\uAC04\uC5D0 \uC2E4\uB9B0\uB2E4");
|
|
2947
|
-
const num2 = (v, name) => {
|
|
2948
|
-
if (v === void 0 || v === null || v === "") return void 0;
|
|
2949
|
-
const n = Number(v);
|
|
2950
|
-
if (!Number.isFinite(n)) {
|
|
2951
|
-
errors.push(`${name} \uAC00 \uC218\uAC00 \uC544\uB2C8\uB2E4: ${JSON.stringify(v)}`);
|
|
2952
|
-
return void 0;
|
|
2953
|
-
}
|
|
2954
|
-
return n;
|
|
2955
|
-
};
|
|
2956
|
-
const kW = num2(record?.kW, "kW");
|
|
2957
|
-
const kWh = num2(record?.kWh, "kWh");
|
|
2958
|
-
const powerFactor = num2(record?.powerFactor, "powerFactor");
|
|
2959
|
-
if (errors.length) {
|
|
2960
|
-
rejected.push({ record, errors });
|
|
2961
|
-
continue;
|
|
2962
|
-
}
|
|
2963
|
-
const eventTime = new Date(atMs).toISOString();
|
|
2964
|
-
const data = {
|
|
2965
|
-
meterId,
|
|
2966
|
-
/* 계약은 `kW` 를 필수로 두지만 **못 읽은 표본도 사실**이다 — 그 경우 값을 비우고 보낸다.
|
|
2967
|
-
커널이 「받았지만 부하를 못 읽었다」로 세고, 구간 마감에 그 이유를 싣는다. */
|
|
2968
|
-
...kW !== void 0 ? { kW } : {},
|
|
2969
|
-
...kWh !== void 0 ? { kWh } : {},
|
|
2970
|
-
...powerFactor !== void 0 ? { powerFactor } : {},
|
|
2971
|
-
at: eventTime
|
|
2972
|
-
};
|
|
2973
|
-
accepted.push({
|
|
2974
|
-
eventId: `${opts.tenantId}-energy-${++seq}`,
|
|
2975
|
-
eventType: ENERGY_EVENT.measured,
|
|
2976
|
-
eventTime,
|
|
2977
|
-
tenantId: opts.tenantId,
|
|
2978
|
-
data
|
|
2979
|
-
});
|
|
3125
|
+
// src/work-shift-basis.ts
|
|
3126
|
+
var instant = (value) => typeof value === "string" && /(?:Z|[+-]\d{2}:\d{2})$/.test(value) && Number.isFinite(Date.parse(value));
|
|
3127
|
+
var nonempty = (value) => typeof value === "string" && !!value.trim();
|
|
3128
|
+
var clock = (value) => typeof value === "string" && /^(?:[01]\d|2[0-3]):[0-5]\d$/.test(value);
|
|
3129
|
+
function isWorkShiftExecutionBasis(value) {
|
|
3130
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
3131
|
+
const b = value;
|
|
3132
|
+
if (![b.basisId, b.arrangementId, b.revisionId, b.planId, b.contentHash].every(nonempty) || !Number.isSafeInteger(b.revisionNumber) || b.revisionNumber < 1 || !instant(b.businessTime) || !nonempty(b.timezone)) return false;
|
|
3133
|
+
try {
|
|
3134
|
+
new Intl.DateTimeFormat("en", { timeZone: b.timezone }).format(0);
|
|
3135
|
+
} catch {
|
|
3136
|
+
return false;
|
|
2980
3137
|
}
|
|
2981
|
-
|
|
3138
|
+
if (typeof b.workDate !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(b.workDate) || !Number.isFinite(Date.parse(b.workDate)) || new Date(b.workDate).toISOString().slice(0, 10) !== b.workDate) return false;
|
|
3139
|
+
if (!Array.isArray(b.shifts) || !b.shifts.length || b.shifts.length > 64) return false;
|
|
3140
|
+
const names = /* @__PURE__ */ new Set();
|
|
3141
|
+
for (const s of b.shifts) {
|
|
3142
|
+
if (!s || typeof s !== "object" || !nonempty(s.name) || names.has(s.name) || s.description !== void 0 && typeof s.description !== "string" || ![-1, 0, 1].includes(s.fromDate) || ![-1, 0, 1].includes(s.toDate) || !clock(s.fromTime) || !clock(s.toTime) || typeof s.daysOfWeek !== "string" || !/^(?:[0-6](?:,[0-6])*)?$/.test(s.daysOfWeek)) return false;
|
|
3143
|
+
const minutes = (time) => Number(time.slice(0, 2)) * 60 + Number(time.slice(3));
|
|
3144
|
+
const duration = (s.toDate - s.fromDate) * 1440 + minutes(s.toTime) - minutes(s.fromTime);
|
|
3145
|
+
if (duration <= 0 || duration > 1440) return false;
|
|
3146
|
+
names.add(s.name);
|
|
3147
|
+
}
|
|
3148
|
+
if (b.shiftName === void 0) return b.occurrence === void 0;
|
|
3149
|
+
if (!nonempty(b.shiftName) || !names.has(b.shiftName) || !b.occurrence || !instant(b.occurrence.from) || !instant(b.occurrence.to)) return false;
|
|
3150
|
+
const at2 = Date.parse(b.businessTime);
|
|
3151
|
+
return Date.parse(b.occurrence.from) <= at2 && at2 < Date.parse(b.occurrence.to);
|
|
2982
3152
|
}
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
3153
|
+
function workShiftAttribution(value) {
|
|
3154
|
+
if (!isWorkShiftExecutionBasis(value)) throw new Error("Invalid pinned work shift evidence");
|
|
3155
|
+
return {
|
|
3156
|
+
workDate: value.workDate,
|
|
3157
|
+
shiftName: value.shiftName,
|
|
3158
|
+
timezone: value.timezone,
|
|
3159
|
+
revisionNumber: value.revisionNumber,
|
|
3160
|
+
occurrence: value.occurrence ? { ...value.occurrence } : void 0
|
|
3161
|
+
};
|
|
2989
3162
|
}
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
const
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
let curtailable;
|
|
3027
|
-
if (r?.curtailable !== void 0 && r?.curtailable !== null) {
|
|
3028
|
-
if (typeof r.curtailable !== "boolean") errors.push(`curtailable \uAC00 \uCC38/\uAC70\uC9D3\uC774 \uC544\uB2C8\uB2E4: ${JSON.stringify(r.curtailable)}`);
|
|
3029
|
-
else curtailable = r.curtailable;
|
|
3030
|
-
}
|
|
3031
|
-
const dcVoltage = num2(r?.dcVoltage, "dcVoltage", 0);
|
|
3032
|
-
const dcCurrent = num2(r?.dcCurrent, "dcCurrent", 0);
|
|
3033
|
-
const phases = (raw, name) => {
|
|
3034
|
-
if (raw === void 0 || raw === null) return void 0;
|
|
3035
|
-
if (!Array.isArray(raw)) {
|
|
3036
|
-
errors.push(`${name} \uAC00 \uBC30\uC5F4\uC774 \uC544\uB2C8\uB2E4 \u2014 \uC0C1\uBCC4 \uAC12\uC774\uB77C \uBC30\uC5F4\uB85C \uBC1B\uB294\uB2E4(\uB2E8\uC0C1\uC774\uBA74 \uC6D0\uC18C \uD558\uB098): ${JSON.stringify(raw)}`);
|
|
3037
|
-
return void 0;
|
|
3038
|
-
}
|
|
3039
|
-
if (!raw.length) {
|
|
3040
|
-
errors.push(`${name} \uAC00 \uBE48 \uBC30\uC5F4\uC774\uB2E4 \u2014 \uC7B0 \uC0C1\uC774 \uC5C6\uC73C\uBA74 \uADF8 \uCE78\uC744 \uBCF4\uB0B4\uC9C0 \uC54A\uB294\uB2E4`);
|
|
3041
|
-
return void 0;
|
|
3042
|
-
}
|
|
3043
|
-
const out = [];
|
|
3044
|
-
for (const [i, v] of raw.entries()) {
|
|
3045
|
-
const n = Number(v);
|
|
3046
|
-
if (!Number.isFinite(n)) {
|
|
3047
|
-
errors.push(`${name}[${i}] \uB97C \uC218\uB85C \uC77D\uC744 \uC218 \uC5C6\uB2E4: ${JSON.stringify(v)}`);
|
|
3048
|
-
return void 0;
|
|
3049
|
-
}
|
|
3050
|
-
if (n < 0) {
|
|
3051
|
-
errors.push(`${name}[${i}] \uAC00 \uC74C\uC218\uB2E4(${n}) \u2014 \uD06C\uAE30\uB294 \uC74C\uC218\uAC00 \uB418\uC9C0 \uC54A\uB294\uB2E4(\uBC29\uD5A5\uC740 \uB2E4\uB978 \uCD95\uC774 \uB9D0\uD55C\uB2E4)`);
|
|
3052
|
-
return void 0;
|
|
3053
|
-
}
|
|
3054
|
-
out.push(n);
|
|
3055
|
-
}
|
|
3056
|
-
return out;
|
|
3057
|
-
};
|
|
3058
|
-
const acVoltage = phases(r?.acVoltage, "acVoltage");
|
|
3059
|
-
const acCurrent = phases(r?.acCurrent, "acCurrent");
|
|
3060
|
-
if (acVoltage && acCurrent && acVoltage.length !== acCurrent.length) {
|
|
3061
|
-
errors.push(`acVoltage(${acVoltage.length}\uC0C1)\uC640 acCurrent(${acCurrent.length}\uC0C1)\uC758 \uC0C1 \uC218\uAC00 \uB2E4\uB974\uB2E4`);
|
|
3062
|
-
}
|
|
3063
|
-
let position;
|
|
3064
|
-
if (r?.position !== void 0 && r?.position !== null && r?.position !== "") {
|
|
3065
|
-
const p = String(r.position);
|
|
3066
|
-
if (!POSITIONS.has(p)) errors.push(`position \uC774 \uD45C\uC900 \uAC12\uC774 \uC544\uB2C8\uB2E4(open\xB7closed\xB7intermediate\xB7bad): ${JSON.stringify(r.position)}`);
|
|
3067
|
-
else position = p;
|
|
3163
|
+
|
|
3164
|
+
// src/travel.ts
|
|
3165
|
+
var TRAVEL_LINK_STATE = ["online", "stale", "lost"];
|
|
3166
|
+
var TRAVEL_LINK_JUDGED_BY = ["source", "derived"];
|
|
3167
|
+
function linkStateAt(link, nowTime, thresholds) {
|
|
3168
|
+
if (link.judgedBy === "source") return link;
|
|
3169
|
+
if (!nowTime) return void 0;
|
|
3170
|
+
const now = Date.parse(nowTime);
|
|
3171
|
+
const seen = Date.parse(link.lastSeenAt);
|
|
3172
|
+
const { staleAfterMs, lostAfterMs } = thresholds;
|
|
3173
|
+
if (!Number.isFinite(now) || !Number.isFinite(seen)) return void 0;
|
|
3174
|
+
if (!(staleAfterMs >= 0 && lostAfterMs >= staleAfterMs)) return void 0;
|
|
3175
|
+
const silentMs = now - seen;
|
|
3176
|
+
const state = silentMs > lostAfterMs ? "lost" : silentMs > staleAfterMs ? "stale" : "online";
|
|
3177
|
+
return { ...link, state, judgedBy: "derived" };
|
|
3178
|
+
}
|
|
3179
|
+
function isHeading(v) {
|
|
3180
|
+
return typeof v === "number" && Number.isFinite(v) && v >= 0 && v < 360;
|
|
3181
|
+
}
|
|
3182
|
+
|
|
3183
|
+
// src/operational-ingest.ts
|
|
3184
|
+
function shapeErrors(where, row, shape) {
|
|
3185
|
+
if (!shape) return [];
|
|
3186
|
+
const errors = [];
|
|
3187
|
+
for (const f of shape.required ?? []) {
|
|
3188
|
+
const v = row[f];
|
|
3189
|
+
const empty2 = v === void 0 || v === null || typeof v === "string" && !v.trim();
|
|
3190
|
+
if (empty2) errors.push(`${where}.${f}: \uD544\uC218 \uD544\uB4DC \uB204\uB77D`);
|
|
3191
|
+
}
|
|
3192
|
+
for (const [f, t] of Object.entries(shape.fields ?? {})) {
|
|
3193
|
+
const v = row[f];
|
|
3194
|
+
if (v === void 0 || v === null) continue;
|
|
3195
|
+
if (t === "number" && (typeof v !== "number" || !Number.isFinite(v))) {
|
|
3196
|
+
errors.push(`${where}.${f} \uAC12\uC740 \uC720\uD55C\uD55C \uC22B\uC790\uC5EC\uC57C \uD569\uB2C8\uB2E4: ${JSON.stringify(v)}`);
|
|
3197
|
+
} else if (t !== "number" && typeof v !== t) {
|
|
3198
|
+
errors.push(`${where}.${f} \uAC00 ${t} \uAC00 \uC544\uB2C8\uB2E4: ${JSON.stringify(v)}`);
|
|
3068
3199
|
}
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3200
|
+
}
|
|
3201
|
+
for (const [f, allowed] of Object.entries(shape.enums ?? {})) {
|
|
3202
|
+
const v = row[f];
|
|
3203
|
+
if (v === void 0 || v === null) continue;
|
|
3204
|
+
if (!allowed.includes(String(v))) {
|
|
3205
|
+
errors.push(`${where}.${f}\uC5D0 \uD5C8\uC6A9\uB418\uC9C0 \uC54A\uB294 \uAC12\uC774 \uC9C0\uC815\uB418\uC5C8\uC2B5\uB2C8\uB2E4: ${JSON.stringify(v)} (${allowed.join(" \xB7 ")})`);
|
|
3072
3206
|
}
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3207
|
+
}
|
|
3208
|
+
for (const f of shape.positive ?? []) {
|
|
3209
|
+
const v = row[f];
|
|
3210
|
+
if (v === void 0 || v === null) continue;
|
|
3211
|
+
if (typeof v !== "number" || !(v > 0)) {
|
|
3212
|
+
errors.push(`${where}.${f} \uAC00 0 \uC774\uD558\uB2E4: ${JSON.stringify(v)} \u2014 \uC218\uB7C9\uC744 \uC54C \uC218 \uC5C6\uC73C\uBA74 \uAC12\uC744 \uC0DD\uB7B5\uD558\uC138\uC694.`);
|
|
3076
3213
|
}
|
|
3077
|
-
const eventTime = new Date(atMs).toISOString();
|
|
3078
|
-
const data = {
|
|
3079
|
-
equipmentId,
|
|
3080
|
-
at: eventTime,
|
|
3081
|
-
...generatedKW !== void 0 ? { generatedKW } : {},
|
|
3082
|
-
...exportKW !== void 0 ? { exportKW } : {},
|
|
3083
|
-
...soc !== void 0 ? { soc } : {},
|
|
3084
|
-
...chargeKW !== void 0 ? { chargeKW } : {},
|
|
3085
|
-
...dischargeKW !== void 0 ? { dischargeKW } : {},
|
|
3086
|
-
...curtailable !== void 0 ? { curtailable } : {},
|
|
3087
|
-
...minKW !== void 0 ? { minKW } : {},
|
|
3088
|
-
...position !== void 0 ? { position } : {},
|
|
3089
|
-
...dcVoltage !== void 0 ? { dcVoltage } : {},
|
|
3090
|
-
...dcCurrent !== void 0 ? { dcCurrent } : {},
|
|
3091
|
-
...acVoltage !== void 0 ? { acVoltage } : {},
|
|
3092
|
-
...acCurrent !== void 0 ? { acCurrent } : {}
|
|
3093
|
-
};
|
|
3094
|
-
accepted.push({
|
|
3095
|
-
eventId: `${opts.tenantId}-energy-eq-${++seq}`,
|
|
3096
|
-
eventType: ENERGY_EVENT.equipment,
|
|
3097
|
-
eventTime,
|
|
3098
|
-
tenantId: opts.tenantId,
|
|
3099
|
-
data
|
|
3100
|
-
});
|
|
3101
|
-
}
|
|
3102
|
-
return { accepted, rejected };
|
|
3103
|
-
}
|
|
3104
|
-
function isEnergyGenerationRecord(record) {
|
|
3105
|
-
if (record?.from !== void 0 || record?.to !== void 0) return false;
|
|
3106
|
-
if (!record || typeof record !== "object") return false;
|
|
3107
|
-
const r = record;
|
|
3108
|
-
return typeof r.equipmentId === "string" && r.equipmentId.trim().length > 0 && r.kWh !== void 0 && r.meterId === void 0 && r.epc === void 0;
|
|
3109
|
-
}
|
|
3110
|
-
function ingestEnergyGenerationRecords(records, opts) {
|
|
3111
|
-
const list = records === void 0 || records === null ? [] : Array.isArray(records) ? records : [records];
|
|
3112
|
-
const accepted = [];
|
|
3113
|
-
const rejected = [];
|
|
3114
|
-
let seq = 0;
|
|
3115
|
-
for (const r of list) {
|
|
3116
|
-
const errors = [];
|
|
3117
|
-
const equipmentId = String(r?.equipmentId ?? "").trim();
|
|
3118
|
-
if (!equipmentId) errors.push("equipmentId \uAC00 \uC5C6\uB2E4 \u2014 \uC5B4\uB290 \uC124\uBE44\uAC00 \uB9CC\uB4E0 \uAC83\uC778\uC9C0 \uC9C0\uC5B4\uB0BC \uC218 \uC5C6\uB2E4");
|
|
3119
|
-
const STATE_FIELDS = ["generatedKW", "exportKW", "soc", "chargeKW", "dischargeKW", "curtailable", "minKW", "position"];
|
|
3120
|
-
const alsoState = STATE_FIELDS.filter((f) => r?.[f] !== void 0);
|
|
3121
|
-
if (alsoState.length) {
|
|
3122
|
-
errors.push(
|
|
3123
|
-
`\uD55C \uB808\uCF54\uB4DC\uC5D0 \uC801\uC0B0\uAC12\uACFC \uC124\uBE44 \uC0C1\uD0DC\uAC00 \uD568\uAED8 \uB4E4\uC5B4 \uC788\uC2B5\uB2C8\uB2E4(${alsoState.join("\xB7")}) \u2014 \uC774 \uACBD\uB85C\uC5D0\uC11C\uB294 \uC801\uC0B0\uAC12\uB9CC \uCC98\uB9AC\uD569\uB2C8\uB2E4. \uC124\uBE44 \uC0C1\uD0DC\uB294 \uBCC4\uB3C4 \uB808\uCF54\uB4DC\uB85C \uBCF4\uB0B4\uC138\uC694.`
|
|
3124
|
-
);
|
|
3125
|
-
}
|
|
3126
|
-
const raw = r?.kWh;
|
|
3127
|
-
const kWh = Number(raw);
|
|
3128
|
-
if (raw === void 0 || raw === null || !Number.isFinite(kWh)) {
|
|
3129
|
-
errors.push("kWh \uAC00 \uC5C6\uB2E4 \u2014 \uC774 \uBB38\uC774 \uBC1B\uB294 \uAC12\uC740 \uC801\uC0B0 \uD558\uB098\uB2E4(\uC21C\uC2DC \uCD9C\uB825\uC740 \uC124\uBE44 \uC0C1\uD0DC\uB85C \uBCF4\uB0B8\uB2E4)");
|
|
3130
|
-
} else if (kWh < 0) {
|
|
3131
|
-
errors.push(`kWh \uAC00 \uC74C\uC218\uB2E4(${kWh}) \u2014 \uC801\uC0B0\uC740 \uB4A4\uB85C \uAC00\uB354\uB77C\uB3C4 \uC74C\uC218\uAC00 \uB418\uC9C0 \uC54A\uB294\uB2E4`);
|
|
3132
|
-
}
|
|
3133
|
-
const eventTime = String(r?.at ?? "").trim() || opts.defaultEventTime || "";
|
|
3134
|
-
if (!eventTime) errors.push("at \uC774 \uC5C6\uACE0 \uAE30\uBCF8 \uC2DC\uAC01\uB3C4 \uC8FC\uC9C0 \uC54A\uC558\uB2E4 \u2014 \uC5B8\uC81C \uC7B0 \uAC83\uC778\uC9C0 \uC9C0\uC5B4\uB0BC \uC218 \uC5C6\uB2E4");
|
|
3135
|
-
let since;
|
|
3136
|
-
const rawSince = r?.kWhSince;
|
|
3137
|
-
if (rawSince !== void 0 && rawSince !== null && String(rawSince).trim()) {
|
|
3138
|
-
const text = String(rawSince).trim();
|
|
3139
|
-
const at2 = Date.parse(text);
|
|
3140
|
-
if (!Number.isFinite(at2)) errors.push(`kWhSince \uB97C \uC2DC\uAC01\uC73C\uB85C \uC77D\uC744 \uC218 \uC5C6\uB2E4: ${JSON.stringify(rawSince)}`);
|
|
3141
|
-
else if (Number.isFinite(Date.parse(eventTime)) && at2 > Date.parse(eventTime)) {
|
|
3142
|
-
errors.push(`kWhSince(${text}) \uAC00 \uC7B0 \uC2DC\uAC01(${eventTime})\uBCF4\uB2E4 \uB4A4\uB2E4 \u2014 \uB458 \uC911 \uD558\uB098\uAC00 \uD2C0\uB838\uB2E4`);
|
|
3143
|
-
} else since = text;
|
|
3144
|
-
}
|
|
3145
|
-
const ACCUMULATIONS = ["lifetime", "daily", "monthly", "billing", "unknown"];
|
|
3146
|
-
let accumulation;
|
|
3147
|
-
const rawAcc = r?.kWhAccumulation;
|
|
3148
|
-
if (rawAcc !== void 0 && rawAcc !== null && String(rawAcc).trim()) {
|
|
3149
|
-
const text = String(rawAcc).trim();
|
|
3150
|
-
if (!ACCUMULATIONS.includes(text)) {
|
|
3151
|
-
errors.push(`kWhAccumulation \uC774 \uC544\uB294 \uAC12\uC774 \uC544\uB2C8\uB2E4(${ACCUMULATIONS.join("\xB7")}): ${JSON.stringify(rawAcc)}`);
|
|
3152
|
-
} else accumulation = text;
|
|
3153
|
-
}
|
|
3154
|
-
if (errors.length) {
|
|
3155
|
-
rejected.push({ record: r, errors });
|
|
3156
|
-
continue;
|
|
3157
|
-
}
|
|
3158
|
-
const data = {
|
|
3159
|
-
equipmentId,
|
|
3160
|
-
kWh,
|
|
3161
|
-
at: eventTime,
|
|
3162
|
-
...since ? { since } : {},
|
|
3163
|
-
...accumulation ? { accumulation } : {}
|
|
3164
|
-
};
|
|
3165
|
-
accepted.push({
|
|
3166
|
-
eventId: `${opts.tenantId}-generated-${++seq}`,
|
|
3167
|
-
eventType: ENERGY_EVENT.generated,
|
|
3168
|
-
eventTime,
|
|
3169
|
-
tenantId: opts.tenantId,
|
|
3170
|
-
data
|
|
3171
|
-
});
|
|
3172
3214
|
}
|
|
3173
|
-
return
|
|
3174
|
-
}
|
|
3175
|
-
function isEnergyUsagePeriodRecord(record) {
|
|
3176
|
-
const r = record;
|
|
3177
|
-
return !!r && typeof r === "object" && r.meterId !== void 0 && r.from !== void 0 && r.to !== void 0 && r.kWh !== void 0;
|
|
3178
|
-
}
|
|
3179
|
-
function isEnergyGenerationPeriodRecord(record) {
|
|
3180
|
-
const r = record;
|
|
3181
|
-
if (!r || typeof r !== "object") return false;
|
|
3182
|
-
if (r.equipmentId === void 0 || r.from === void 0 || r.to === void 0) return false;
|
|
3183
|
-
return r.kWh !== void 0;
|
|
3215
|
+
return errors;
|
|
3184
3216
|
}
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3217
|
+
var SPECS = {
|
|
3218
|
+
task: {
|
|
3219
|
+
eventType: OP_EVENT.task,
|
|
3220
|
+
match: ["taskId"],
|
|
3221
|
+
matchOrder: 50,
|
|
3222
|
+
identity: "taskId",
|
|
3223
|
+
/* 종류가 없으면 성과를 종류별로 모을 수 없고(선언된 시간·수율이 종류로 붙는다) 지어낼 수도 없다. */
|
|
3224
|
+
required: ["taskId", "kind", "status"],
|
|
3225
|
+
fields: {
|
|
3226
|
+
taskId: "string",
|
|
3227
|
+
kind: "string",
|
|
3228
|
+
status: "string",
|
|
3229
|
+
fromNode: "string",
|
|
3230
|
+
toNode: "string",
|
|
3231
|
+
itemRefs: "string[]",
|
|
3232
|
+
resourceRef: "string",
|
|
3233
|
+
resources: "string[]",
|
|
3234
|
+
personnel: "string[]",
|
|
3235
|
+
assets: "string[]",
|
|
3236
|
+
orderId: "string",
|
|
3237
|
+
intent: "string",
|
|
3238
|
+
progress: "number",
|
|
3239
|
+
remainingMs: "number",
|
|
3240
|
+
durationMs: "number",
|
|
3241
|
+
startedAtSimMs: "number",
|
|
3242
|
+
outcome: "string",
|
|
3243
|
+
priority: "number",
|
|
3244
|
+
startTime: "string",
|
|
3245
|
+
endTime: "string",
|
|
3246
|
+
materialActual: "object[]",
|
|
3247
|
+
recordTime: "string",
|
|
3248
|
+
workShiftBasis: "object"
|
|
3249
|
+
},
|
|
3250
|
+
/*
|
|
3251
|
+
* **자재 줄의 안쪽** — 계약의 `MaterialActual` 그대로다.
|
|
3252
|
+
*
|
|
3253
|
+
* `definitionId` 를 요구하는 이유: 이 이름이 없으면 그 줄이 무엇을 가리키는지 아무도 모른다.
|
|
3254
|
+
* 실제로 `materialDefinitionId` 로 온 줄이 저널에 앉았고, 계약의 타입으로 읽으면 비어 있었다.
|
|
3255
|
+
*
|
|
3256
|
+
* `quantity` 를 `positive` 에 두는 이유: 「모른다」는 **비워서** 말한다. 0 으로 실으면 받는
|
|
3257
|
+
* 쪽에서 「0개」와 구별되지 않고, 소요량 집계가 조용히 틀린다.
|
|
3258
|
+
*
|
|
3259
|
+
* `uom` 은 요구하지 않는다 — 계약에서 선택이다(§`MaterialActual`). ERP 경로는 요구하는데
|
|
3260
|
+
* 그것은 **그 경로의 규칙**이다(정산에 단위 없는 수량을 쓸 수 없다). 커널이 그 규칙을 통째로
|
|
3261
|
+
* 물려받으면 단위를 모르는 현장의 사실이 통째로 거절된다.
|
|
3262
|
+
*/
|
|
3263
|
+
shapes: {
|
|
3264
|
+
workShiftBasis: {
|
|
3265
|
+
required: ["basisId", "arrangementId", "revisionId", "revisionNumber", "planId", "contentHash", "businessTime", "timezone", "shifts", "workDate"],
|
|
3266
|
+
fields: { basisId: "string", arrangementId: "string", revisionId: "string", revisionNumber: "number", planId: "string", contentHash: "string", businessTime: "string", timezone: "string", workDate: "string" }
|
|
3267
|
+
// Full nested content and selected occurrence are checked by isWorkShiftExecutionBasis below.
|
|
3268
|
+
},
|
|
3269
|
+
materialActual: {
|
|
3270
|
+
required: ["definitionId", "use"],
|
|
3271
|
+
fields: { definitionId: "string", lotId: "string", quantity: "number", uom: "string" },
|
|
3272
|
+
enums: { use: MATERIAL_ACTUAL_USE },
|
|
3273
|
+
positive: ["quantity"]
|
|
3211
3274
|
}
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
continue;
|
|
3219
|
-
}
|
|
3220
|
-
const data = {
|
|
3221
|
-
equipmentId,
|
|
3222
|
-
kWh,
|
|
3223
|
-
periodStart: span.from,
|
|
3224
|
-
periodEnd: span.to,
|
|
3225
|
-
/* 관측 구간을 말하지 않으면 기간 전체를 잰 것으로 둔다 — 지난 기록은 그 원본이 하루를 마감해 준 값이다. */
|
|
3226
|
-
observedFrom: observedFrom ?? span.from,
|
|
3227
|
-
observedTo: observedTo ?? span.to,
|
|
3228
|
-
accumulation: accumulation ?? "daily",
|
|
3229
|
-
/* 밖에서 마감되어 온 것이다 — 우리가 시각 기준으로 닫은 것이 아니다. */
|
|
3230
|
-
boundary: "declared"
|
|
3231
|
-
};
|
|
3232
|
-
const subj = resolveSubject("equipment", equipmentId, opts);
|
|
3233
|
-
data.subject = subj.subject;
|
|
3234
|
-
data.subjectBasis = subj.basis;
|
|
3235
|
-
const futureError = futureFactError(span.to, opts);
|
|
3236
|
-
if (futureError) {
|
|
3237
|
-
rejected.push({ record: r, errors: [futureError] });
|
|
3238
|
-
continue;
|
|
3239
|
-
}
|
|
3240
|
-
accepted.push({
|
|
3241
|
-
eventId: periodFactId(opts.tenantId, ENERGY_EVENT.generationPeriod, subj.subject, span.from, span.to),
|
|
3242
|
-
eventType: ENERGY_EVENT.generationPeriod,
|
|
3243
|
-
eventTime: span.to,
|
|
3244
|
-
tenantId: opts.tenantId,
|
|
3245
|
-
data
|
|
3246
|
-
});
|
|
3247
|
-
}
|
|
3248
|
-
return { accepted, rejected };
|
|
3249
|
-
}
|
|
3250
|
-
function isEnergyGenerationPriceRecord(record) {
|
|
3251
|
-
const r = record;
|
|
3252
|
-
if (!r || typeof r !== "object") return false;
|
|
3253
|
-
if (r.from === void 0 || r.to === void 0) return false;
|
|
3254
|
-
if (r.meterId !== void 0 || r.equipmentId !== void 0) return false;
|
|
3255
|
-
return r.unitPrice !== void 0;
|
|
3256
|
-
}
|
|
3257
|
-
function ingestEnergyGenerationPriceRecords(records, opts) {
|
|
3258
|
-
const list = records === void 0 || records === null ? [] : Array.isArray(records) ? records : [records];
|
|
3259
|
-
const accepted = [];
|
|
3260
|
-
const rejected = [];
|
|
3261
|
-
for (const r of list) {
|
|
3262
|
-
const errors = [];
|
|
3263
|
-
const span = readSpan(r, errors);
|
|
3264
|
-
const unitPrice = readAmount(r?.unitPrice, "unitPrice", errors);
|
|
3265
|
-
if (unitPrice === void 0 && !errors.length) errors.push("unitPrice \uAC00 \uC5C6\uB2E4 \u2014 \uC774 \uBB38\uC774 \uBC1B\uB294 \uAC12\uC740 1kWh \uB2F9 \uAC12 \uD558\uB098\uB2E4");
|
|
3266
|
-
const currency = String(r?.currency ?? "").trim();
|
|
3267
|
-
if (!currency) errors.push("currency \uAC00 \uC5C6\uB2E4 \u2014 \uB2E8\uC704 \uC5C6\uB294 \uAC12\uC740 \uB2E4\uB978 \uAE08\uC561\uACFC \uB354\uD560 \uC218 \uC5C6\uB2E4");
|
|
3268
|
-
if (errors.length || !span || unitPrice === void 0) {
|
|
3269
|
-
rejected.push({ record: r, errors });
|
|
3270
|
-
continue;
|
|
3275
|
+
},
|
|
3276
|
+
enums: {
|
|
3277
|
+
status: TASK_STATUS,
|
|
3278
|
+
intent: ["transport", "process", "dwell"],
|
|
3279
|
+
/* 품질 판정은 **있었던 작업만** — 없음은 「양품」이 아니라 「판정하지 않았다」다. */
|
|
3280
|
+
outcome: ["good", "scrap"]
|
|
3271
3281
|
}
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3282
|
+
},
|
|
3283
|
+
equipment: {
|
|
3284
|
+
eventType: OP_EVENT.equipment,
|
|
3285
|
+
match: ["moverId"],
|
|
3286
|
+
matchOrder: 20,
|
|
3287
|
+
identity: "moverId",
|
|
3288
|
+
// vocabulary-guard: allow 저널 와이어 필드(델타의 이름이 계약이다)
|
|
3289
|
+
required: ["moverId", "kind", "status"],
|
|
3290
|
+
// vocabulary-guard: allow 위와 같은 이유
|
|
3291
|
+
fields: {
|
|
3292
|
+
moverId: "string",
|
|
3293
|
+
kind: "string",
|
|
3294
|
+
status: "string",
|
|
3295
|
+
location: "string",
|
|
3296
|
+
homeLocation: "string",
|
|
3297
|
+
// vocabulary-guard: allow
|
|
3298
|
+
taskId: "string",
|
|
3299
|
+
held: "boolean",
|
|
3300
|
+
effectiveStart: "string",
|
|
3301
|
+
effectiveEnd: "string",
|
|
3302
|
+
recordTime: "string",
|
|
3303
|
+
/* 왜 이 상태가 됐나 — 설비가 알려 주면 싣는다. 사람이 나중에 정하는 사유는 구간 사실에 적는다. */
|
|
3304
|
+
reasonCode: "string",
|
|
3305
|
+
/* 이동 구간 — 실 시스템도 줄 수 있는 사실이다(AGV·RTLS 가 출발·도착·소요를 낸다). 안쪽 필드까지
|
|
3306
|
+
재검사하지는 않는다: 그 모양은 `EquipmentMotion` 계약이고, 여기서 두 번 지키면 두 벌이 된다. */
|
|
3307
|
+
motion: "object"
|
|
3308
|
+
},
|
|
3309
|
+
enums: { status: EQUIPMENT_STATUS }
|
|
3310
|
+
},
|
|
3311
|
+
person: {
|
|
3312
|
+
eventType: OP_EVENT.person,
|
|
3313
|
+
match: ["personId"],
|
|
3314
|
+
matchOrder: 30,
|
|
3315
|
+
identity: "personId",
|
|
3316
|
+
required: ["personId", "status"],
|
|
3317
|
+
fields: {
|
|
3318
|
+
personId: "string",
|
|
3319
|
+
status: "string",
|
|
3320
|
+
personnelClassIds: "string[]",
|
|
3321
|
+
taskId: "string",
|
|
3322
|
+
location: "string",
|
|
3323
|
+
offShift: "boolean",
|
|
3324
|
+
effectiveStart: "string",
|
|
3325
|
+
effectiveEnd: "string",
|
|
3326
|
+
recordTime: "string"
|
|
3327
|
+
},
|
|
3328
|
+
enums: { status: PERSON_STATUS }
|
|
3329
|
+
},
|
|
3330
|
+
asset: {
|
|
3331
|
+
eventType: OP_EVENT.asset,
|
|
3332
|
+
match: ["assetId"],
|
|
3333
|
+
matchOrder: 40,
|
|
3334
|
+
identity: "assetId",
|
|
3335
|
+
required: ["assetId", "status"],
|
|
3336
|
+
fields: {
|
|
3337
|
+
assetId: "string",
|
|
3338
|
+
status: "string",
|
|
3339
|
+
assetClassIds: "string[]",
|
|
3340
|
+
location: "string",
|
|
3341
|
+
taskId: "string",
|
|
3342
|
+
carrying: "string",
|
|
3343
|
+
effectiveStart: "string",
|
|
3344
|
+
effectiveEnd: "string",
|
|
3345
|
+
recordTime: "string"
|
|
3346
|
+
},
|
|
3347
|
+
enums: { status: ASSET_STATUS }
|
|
3348
|
+
},
|
|
3349
|
+
order: {
|
|
3350
|
+
eventType: OP_EVENT.order,
|
|
3351
|
+
match: ["orderId"],
|
|
3352
|
+
matchOrder: 60,
|
|
3353
|
+
identity: "orderId",
|
|
3354
|
+
/*
|
|
3355
|
+
* 요청량·이행량을 **함께** 받는다. 없으면 리듀서가 진척을 0 으로 적는데(`requested ? … : 0`),
|
|
3356
|
+
* 그것은 「모른다」가 아니라 「아무것도 안 됐다」로 읽힌다 — 결측을 0 으로 메우지 않는다.
|
|
3357
|
+
*/
|
|
3358
|
+
required: ["orderId", "kind", "status", "requested", "fulfilled"],
|
|
3359
|
+
fields: {
|
|
3360
|
+
orderId: "string",
|
|
3361
|
+
kind: "string",
|
|
3362
|
+
status: "string",
|
|
3363
|
+
requested: "number",
|
|
3364
|
+
fulfilled: "number",
|
|
3365
|
+
gtin: "string",
|
|
3366
|
+
held: "boolean",
|
|
3367
|
+
lines: "object[]",
|
|
3368
|
+
priority: "number",
|
|
3369
|
+
startTime: "string",
|
|
3370
|
+
endTime: "string",
|
|
3371
|
+
/* 확보분은 `{ epc, qty }` 줄이다(2026-09-19, ADR-0076 보탬) — 옛 EPC 목록은 받지 않는다. */
|
|
3372
|
+
allocated: "object[]",
|
|
3373
|
+
bizTransaction: "string",
|
|
3374
|
+
operationsRequestId: "string",
|
|
3375
|
+
dockDoor: "string",
|
|
3376
|
+
windowStartMs: "number",
|
|
3377
|
+
recordTime: "string",
|
|
3378
|
+
/*
|
|
3379
|
+
* 이 오더를 어느 레시피로 돌리나 — 「이 로트를 무엇으로 만들었나」가 이 칸을 지나 답한다.
|
|
3380
|
+
*
|
|
3381
|
+
* ── 왜 뒤늦게 생겼나 (2026-09-07 측정) ─────────────────────────────────
|
|
3382
|
+
* EPCIS 변환 사건에는 레시피 자리가 없다(표준이 그렇다). 그래서 이력추적이 **변환 → 거래
|
|
3383
|
+
* 식별자 → 그 오더의 `recipeKey`** 로 건너간다(`twin-lineage-query.ts:296-315`).
|
|
3384
|
+
*
|
|
3385
|
+
* 변환이 오더를 가리키게 만든 뒤에 재보니, **가리켜진 오더 행에 그 칸이 없었다.** 실으면
|
|
3386
|
+
* 레코드가 통째로 거절됐다 — `order: 계약에 없는 필드 — recipeKey`. 조용히 버리지 않은 것은
|
|
3387
|
+
* 맞지만, 그래서 실 시스템에서는 그 물음이 계속 답이 없었다.
|
|
3388
|
+
*
|
|
3389
|
+
* 값은 원본에 있다: `job_orders.recipe_key` 35개 중 20개 채움
|
|
3390
|
+
* (`WO-ECU-STD-2609A` = `RECIPE-ECU-STD`).
|
|
3391
|
+
*
|
|
3392
|
+
* 새 어휘가 아니다 — 계약이 `recipeKey` 를 네 자리에서 이미 쓴다. 오더 관측에만 자리가 없었다.
|
|
3393
|
+
*/
|
|
3394
|
+
recipeKey: "string",
|
|
3395
|
+
recipeBasis: "object",
|
|
3396
|
+
materialBasis: "object[]",
|
|
3397
|
+
/* 근거 칸이 빈 까닭 — 닫힌 낱말이다(§`BASIS_UNKNOWN`). 투입이 근거 장치보다 먼저였던 오더도 이행은 사실이다. */
|
|
3398
|
+
basisUnknown: "string",
|
|
3399
|
+
/*
|
|
3400
|
+
* 실패 · 취소로 닫힌 까닭 — 열린 낱말이다(도메인이 소유한다. 구내 반송은 `TRANSPORT_FAILURE_REASON`). 2026-12-04: 반송 지시가
|
|
3401
|
+
* 실패로 닫힐 때(`ORDER_TERMINAL_STATUS` 의 `failed`) 그 사유가 오더에 실린다 — 그 작업은 `cancelled` 로 가서 사유를 들 곳이 없다.
|
|
3402
|
+
*/
|
|
3403
|
+
reasonCode: "string"
|
|
3404
|
+
},
|
|
3405
|
+
/* 상태·종류는 도메인이 소유한다 — 닫지 않는다. 근거가 빈 까닭은 커널이 읽으므로 닫는다. */
|
|
3406
|
+
enums: { basisUnknown: BASIS_UNKNOWN },
|
|
3407
|
+
/*
|
|
3408
|
+
* 확보분의 안쪽을 본다 — 열쇠와 수 둘이다(§`AllocatedQuantity`). 안 보면 틀린 이름이 조용히
|
|
3409
|
+
* 지나가고(`epcs`·`quantity` 따위), 미러는 잡힌 수를 0 으로 읽는다.
|
|
3410
|
+
*/
|
|
3411
|
+
shapes: {
|
|
3412
|
+
materialBasis: {
|
|
3413
|
+
required: ["basisId", "materialId", "revisionId", "revisionNumber", "planId", "contentHash", "businessTime", "material"],
|
|
3414
|
+
fields: { basisId: "string", materialId: "string", revisionId: "string", revisionNumber: "number", planId: "string", contentHash: "string", businessTime: "string" }
|
|
3415
|
+
// Recursive material properties and reference lists are checked by isMaterialExecutionBasis.
|
|
3416
|
+
},
|
|
3417
|
+
recipeBasis: {
|
|
3418
|
+
required: ["basisId", "recipeId", "revisionId", "planId", "contentHash", "businessTime", "recipe"],
|
|
3419
|
+
fields: { basisId: "string", recipeId: "string", revisionId: "string", planId: "string", contentHash: "string", businessTime: "string" }
|
|
3420
|
+
// Owned composition and captured route are additionally checked by isRecipeExecutionBasis below.
|
|
3421
|
+
},
|
|
3422
|
+
allocated: {
|
|
3423
|
+
required: ["epc", "qty"],
|
|
3424
|
+
fields: { epc: "string", qty: "number" },
|
|
3425
|
+
positive: ["qty"]
|
|
3426
|
+
}
|
|
3427
|
+
}
|
|
3428
|
+
},
|
|
3429
|
+
quality: {
|
|
3430
|
+
eventType: OP_EVENT.quality,
|
|
3431
|
+
match: ["moverId", "good"],
|
|
3432
|
+
matchOrder: 15,
|
|
3433
|
+
identity: "moverId",
|
|
3434
|
+
// vocabulary-guard: allow 저널 와이어 필드
|
|
3435
|
+
/* 누적 카운터가 없으면 OEE 가 양품률을 못 센다 — 판정 하나만으로는 비율이 나오지 않는다. */
|
|
3436
|
+
required: ["moverId", "good", "goodCount", "nonconformingCount"],
|
|
3437
|
+
// vocabulary-guard: allow
|
|
3438
|
+
/*
|
|
3439
|
+
* `taskId` 는 **귀속**이다 — 이 산출이 어느 작업의 것인가. 수량의 뜻은 바뀌지 않는다(설비 누적).
|
|
3440
|
+
*
|
|
3441
|
+
* 왜 필요한가: 작업자가 올리는 실적은 작업 단위인데 이 갈래의 정체는 설비뿐이라, 두 사실이 만나는
|
|
3442
|
+
* 자리가 없었다. 귀속이 없으면 「이 작업에서 몇 개 나왔나」를 저널에서 되짚을 방법이 없다.
|
|
3443
|
+
*
|
|
3444
|
+
* 정체를 `taskId` 로 바꾸지 않는 이유는 OEE 가 설비 단위여서다. 정체를 옮기면 설비 누적을 셀 수
|
|
3445
|
+
* 없어진다.
|
|
3446
|
+
*/
|
|
3447
|
+
fields: { moverId: "string", good: "boolean", goodCount: "number", nonconformingCount: "number", taskId: "string", recordTime: "string" }
|
|
3448
|
+
// vocabulary-guard: allow
|
|
3449
|
+
},
|
|
3450
|
+
/*
|
|
3451
|
+
* **시험 결과** — 대상을 가리켜 들어온다(표준 `TestResult.TestableObjectID`).
|
|
3452
|
+
*
|
|
3453
|
+
* `result` 를 **요구하지 않는다**: 재기만 하고 판정하지 않는 원천이 정상이고, 요구하면 그 원천의
|
|
3454
|
+
* 사실을 아예 담을 수 없다(§`TestResult.result`). 비어 있으면 커널이 선언된 기준으로 판정하고
|
|
3455
|
+
* `derived` 를 세운다 — 판정하지 못하면 비워 둔다.
|
|
3456
|
+
*
|
|
3457
|
+
* `propertyMeasurements` 안쪽은 재검사하지 않는다 — 그 모양은 `PropertyMeasurement` 계약이고,
|
|
3458
|
+
* 여기서 두 번 지키면 두 벌이 된다(설비 `motion` 과 같은 규율).
|
|
3459
|
+
*/
|
|
3460
|
+
/*
|
|
3461
|
+
* **마감된 설비 상태 구간** — 이 설비가 이 구간 동안 이 상태였다.
|
|
3462
|
+
*
|
|
3463
|
+
* ── 전이만으로는 안 되는 이유 (2026-08-30) ───────────────────────────────
|
|
3464
|
+
* 세 가지다. 셋째가 결정적이다.
|
|
3465
|
+
*
|
|
3466
|
+
* 사유가 붙을 자리가 없다 기계가 서는 순간에는 왜 섰는지 아무도 모른다. 작업자가 라인이 다시
|
|
3467
|
+
* 돈 뒤에 적는다. 그 사이에 전이가 더 있으면 어느 전이에 붙일지 정할 수 없다
|
|
3468
|
+
* 계획·비계획을 나중에 정한다 ISO 22400 은 계획정지를 계획 조업 시간에서 빼고 고장은 빼지 않는다.
|
|
3469
|
+
* 그 분류는 전이가 일어난 순간에 모른다
|
|
3470
|
+
* 전이를 내지 않는 정지가 많다 자재 대기 · 앞 공정 대기 · 작업자 부재. 기계는 전원이 켜진 채 `idle`
|
|
3471
|
+
* 이고 신호가 하나도 안 나온다. OEE 에서 가장 크게 깎이는 것이 보통 이 시간이다
|
|
3472
|
+
*
|
|
3473
|
+
* 마지막이 감시 시스템과 MES 가 갈리는 자리이기도 하다. 설비가 말하는 것만 모으면 감시이고,
|
|
3474
|
+
* **설비가 말하지 못하는 것을 사람이 적어 넣는 자리**가 MES 다.
|
|
3475
|
+
*
|
|
3476
|
+
* ── 이름이 `downtime` 이 아닌 이유 ────────────────────────────────────────
|
|
3477
|
+
* 이 구간은 `setup` 과 `planned-stop` 도 나른다. 그 둘은 정지가 아니다. 담는 것은 **상태 구간**이고,
|
|
3478
|
+
* 어느 상태인지는 `status` 가 말한다.
|
|
3479
|
+
*
|
|
3480
|
+
* ── 되돌아가 적는 사실이다 ───────────────────────────────────────────────
|
|
3481
|
+
* 봉투의 사건 시각은 **구간의 끝**(그때 성립한다)이고, 적은 시각은 `recordTime` 이다. 둘이 갈려 있어야
|
|
3482
|
+
* 「언제 일어났나」와 「언제 알았나」를 구별할 수 있다.
|
|
3483
|
+
*/
|
|
3484
|
+
"equipment-period": {
|
|
3485
|
+
eventType: OP_EVENT.equipmentPeriod,
|
|
3486
|
+
match: ["moverId", "status", "from", "to"],
|
|
3487
|
+
matchOrder: 10,
|
|
3488
|
+
identity: "moverId",
|
|
3489
|
+
// vocabulary-guard: allow 저널 와이어 필드 — 전이와 같은 이름을 쓴다
|
|
3490
|
+
required: ["moverId", "status", "from", "to"],
|
|
3491
|
+
// vocabulary-guard: allow 위와 같은 이유
|
|
3492
|
+
fields: {
|
|
3493
|
+
moverId: "string",
|
|
3494
|
+
status: "string",
|
|
3495
|
+
from: "string",
|
|
3496
|
+
to: "string",
|
|
3497
|
+
// vocabulary-guard: allow
|
|
3498
|
+
/* 사람이 정한 사유 — 없을 수 있다(적지 않은 것과 사유가 없는 것은 다르므로 지어내지 않는다). */
|
|
3499
|
+
reasonCode: "string",
|
|
3500
|
+
decidedBy: "string",
|
|
3501
|
+
recordTime: "string",
|
|
3502
|
+
workShiftBasis: "object"
|
|
3503
|
+
},
|
|
3504
|
+
shapes: {
|
|
3505
|
+
workShiftBasis: {
|
|
3506
|
+
required: ["basisId", "arrangementId", "revisionId", "revisionNumber", "planId", "contentHash", "businessTime", "timezone", "shifts", "workDate"],
|
|
3507
|
+
fields: { basisId: "string", arrangementId: "string", revisionId: "string", revisionNumber: "number", planId: "string", contentHash: "string", businessTime: "string", timezone: "string", workDate: "string" }
|
|
3508
|
+
}
|
|
3509
|
+
},
|
|
3510
|
+
enums: { status: EQUIPMENT_STATUS }
|
|
3511
|
+
},
|
|
3512
|
+
/*
|
|
3513
|
+
* **부적합 처분** — 재고 판정을 받은 것을 어떻게 하기로 정했나.
|
|
3514
|
+
*
|
|
3515
|
+
* ── 이 통이 늦게 생긴 이유 (2026-08-30) ──────────────────────────────────
|
|
3516
|
+
* 사건 이름(`OP_EVENT.disposition`)과 모양(`DispositionFact`)을 먼저 만들고 **여기로 오는 길을
|
|
3517
|
+
* 내지 않았다.** 그래서 처분 사실을 보내면 어느 통도 아니어서 떨어진 목록에도 남지 않고 사라졌다.
|
|
3518
|
+
* MES 전문가가 소스를 읽다 찾았다.
|
|
3519
|
+
*
|
|
3520
|
+
* 이 파일의 위 주석이 말한 부류 그대로다 — `OP_EVENT.test` 와 `OP_EVENT.observation` 이 같은 일을
|
|
3521
|
+
* 겪었고 이번이 셋째다. **계약에 자리를 만드는 것과 그 자리로 가는 길을 내는 것은 다른 일이다.**
|
|
3522
|
+
*
|
|
3523
|
+
* ── 판정과 다른 사실이다 ─────────────────────────────────────────────────
|
|
3524
|
+
* 근거가 된 판정(`specId`)을 가리킬 수 있지만 **필수가 아니다** — 판정 없이 현장 재량으로 빼는 일이
|
|
3525
|
+
* 정상이다. 그래서 정체성은 처분 대상(`subjectId`)이다.
|
|
3526
|
+
*/
|
|
3527
|
+
disposition: {
|
|
3528
|
+
eventType: OP_EVENT.disposition,
|
|
3529
|
+
match: ["subjectId", "decision"],
|
|
3530
|
+
matchOrder: 80,
|
|
3531
|
+
identity: "subjectId",
|
|
3532
|
+
/* 무엇을 어떻게 하기로 했나 — 둘 중 하나가 없으면 그 결정은 아무 데도 붙지 못한다. */
|
|
3533
|
+
required: ["subjectId", "decision"],
|
|
3534
|
+
fields: {
|
|
3535
|
+
subjectId: "string",
|
|
3536
|
+
decision: "string",
|
|
3537
|
+
quantity: "number",
|
|
3538
|
+
uom: "string",
|
|
3539
|
+
specId: "string",
|
|
3540
|
+
decidedBy: "string",
|
|
3541
|
+
reason: "string",
|
|
3542
|
+
decidedAt: "string",
|
|
3543
|
+
recordTime: "string"
|
|
3544
|
+
},
|
|
3545
|
+
enums: { decision: DISPOSITION_DECISION }
|
|
3546
|
+
},
|
|
3547
|
+
/*
|
|
3548
|
+
* **로트 상태** — ISA-95 `MaterialLot.Status`. 출하 승인(batch release)이 들어오는 문(§`OP_EVENT.materialLot`).
|
|
3549
|
+
*
|
|
3550
|
+
* `disposition`(subjectId + decision) 과 필드가 겹치지 않는다 — 여기는 `lotId` + `status`. 정체 이름이 표준
|
|
3551
|
+
* `MaterialLotID` 인 이유가 하나 더 있다: 이 문은 `epc` 를 든 레코드를 EPCIS 어휘로 보고 받지 않는다
|
|
3552
|
+
* (§`operationalKindOf`). 값은 로트의 식별자(`ItemState.epc` 와 같은 값)다. 상태 낱말은 열려 있어 enum 이
|
|
3553
|
+
* 없다(오더 상태와 같은 규율). 로트 전체의 사실이므로 부분(`subLotId`)은 받지 않는다 — 부분마다 다른 상태가
|
|
3554
|
+
* 필요해지면 그것은 다른 사실이다.
|
|
3555
|
+
*
|
|
3556
|
+
* ── 낱말은 열리고 **효과는 닫힌다** (2026-09-19, ADR-0080 결정 2) ────────────
|
|
3557
|
+
* `status` 는 현장의 낱말이다(`on-hold` · `quarantine` · `검사대기` — 도메인이 소유한다). 커널이 그
|
|
3558
|
+
* 낱말을 읽어 「보류면 할당에서 뺀다」를 정하면, 현장이 다른 낱말을 쓰는 날 조용히 샌다.
|
|
3559
|
+
*
|
|
3560
|
+
* 그래서 **효과를 따로 싣는다**: `use` 는 닫힌 둘(`allowed` · `blocked`)이고 기계가 읽는다. 낱말의
|
|
3561
|
+
* 주인이 둘을 같이 정한다 — 자원 속성에서 이미 선 원칙 그대로다(속성은 열리고 효과는 닫힌다).
|
|
3562
|
+
*
|
|
3563
|
+
* **`use` 가 없는 레코드는 `allowed` 가 아니라 「모름」이다.** 그래서 필수로 만들지 않는다: 이 문을
|
|
3564
|
+
* 이미 쓰고 있는 원본이 있으면 그 사실이 통째로 거절되는 것이 더 나쁘다. 모르는 것을 할당이 어떻게
|
|
3565
|
+
* 다루는지는 커널이 한 곳에서 정하고 그 수를 센다.
|
|
3566
|
+
*/
|
|
3567
|
+
"material-lot": {
|
|
3568
|
+
eventType: OP_EVENT.materialLot,
|
|
3569
|
+
match: ["lotId", "status"],
|
|
3570
|
+
matchOrder: 85,
|
|
3571
|
+
identity: "lotId",
|
|
3572
|
+
required: ["lotId", "status"],
|
|
3573
|
+
fields: { lotId: "string", status: "string", use: "string", decidedBy: "string", reason: "string", decidedAt: "string", recordTime: "string" },
|
|
3574
|
+
enums: { use: MATERIAL_LOT_USE }
|
|
3575
|
+
},
|
|
3576
|
+
test: {
|
|
3577
|
+
eventType: OP_EVENT.test,
|
|
3578
|
+
match: ["testableObjectId"],
|
|
3579
|
+
matchOrder: 70,
|
|
3580
|
+
identity: "testableObjectId",
|
|
3581
|
+
/* 무엇을 어느 기준으로 시험했나 — 둘 중 하나가 없으면 그 결과는 아무 데도 붙지 못한다. */
|
|
3582
|
+
required: ["testableObjectId", "specId"],
|
|
3583
|
+
fields: {
|
|
3584
|
+
testableObjectId: "string",
|
|
3585
|
+
specId: "string",
|
|
3586
|
+
result: "string",
|
|
3587
|
+
at: "string",
|
|
3588
|
+
expiresAt: "string",
|
|
3589
|
+
derived: "boolean",
|
|
3590
|
+
propertyMeasurements: "object[]",
|
|
3591
|
+
specificationBasis: "object",
|
|
3592
|
+
recordTime: "string"
|
|
3593
|
+
},
|
|
3594
|
+
shapes: {
|
|
3595
|
+
specificationBasis: {
|
|
3596
|
+
required: ["id", "revisionId", "planId", "contentHash", "businessTime", "criteria"],
|
|
3597
|
+
fields: { id: "string", revisionId: "string", planId: "string", contentHash: "string", businessTime: "string" }
|
|
3598
|
+
}
|
|
3599
|
+
},
|
|
3600
|
+
enums: { result: ["pass", "fail"] }
|
|
3601
|
+
},
|
|
3602
|
+
/*
|
|
3603
|
+
* **자리의 물리 관측** — 어느 자리의 어느 속성을 언제 얼마로 쟀나.
|
|
3604
|
+
*
|
|
3605
|
+
* 값에 **단위를 함께** 받는다(`ValueType`). 단위 없는 물리량은 판정의 재료가 못 된다 — 3 이 섭씨인지
|
|
3606
|
+
* 화씨인지 모르면 어떤 기준으로도 판정할 수 없다. 다만 **요구하지는 않는다**: 단위를 비우는 실 원본이
|
|
3607
|
+
* 흔하고, 요구하면 그 원본의 관측을 아예 담지 못한다(그때 판정은 커널이 거부한다 — `outsideLimit`).
|
|
3608
|
+
*
|
|
3609
|
+
* `effectiveTime` 도 요구하지 않는다. 없으면 봉투의 시각이 그 자리를 대신한다(§`resolve`) — 원본이
|
|
3610
|
+
* 시각을 말하지 않는 수기 점검이 실재하고, 그때 지어낸 시각보다 폴링 시각이 정직하다.
|
|
3611
|
+
*/
|
|
3612
|
+
/*
|
|
3613
|
+
* **이 목록이 전부다** — 연결된 시스템이 현재 목록을 한 바퀴 다 보낸 뒤 알린다.
|
|
3614
|
+
*
|
|
3615
|
+
* 둘 다 요구한다: 어느 목록인지와 그 주기를 **시작한** 시각. 시각이 없으면 무엇을 지울지 가릴 수
|
|
3616
|
+
* 없고, 그때 지우면 전부 지운다 — 받지 않는 것이 옳다.
|
|
3617
|
+
*/
|
|
3618
|
+
complete: {
|
|
3619
|
+
eventType: OP_EVENT.complete,
|
|
3620
|
+
match: ["completeAxis"],
|
|
3621
|
+
matchOrder: 100,
|
|
3622
|
+
identity: "completeAxis",
|
|
3623
|
+
required: ["completeAxis", "since"],
|
|
3624
|
+
fields: { completeAxis: "string", since: "string", recordTime: "string" }
|
|
3625
|
+
},
|
|
3626
|
+
observation: {
|
|
3627
|
+
eventType: OP_EVENT.observation,
|
|
3628
|
+
match: ["locationId", "propertyId"],
|
|
3629
|
+
matchOrder: 90,
|
|
3630
|
+
identity: "locationId",
|
|
3631
|
+
/* 자리와 속성 — 둘 중 하나가 없으면 그 관측은 아무 데도 붙지 못한다. */
|
|
3632
|
+
required: ["locationId", "propertyId"],
|
|
3633
|
+
fields: {
|
|
3634
|
+
locationId: "string",
|
|
3635
|
+
propertyId: "string",
|
|
3636
|
+
value: "string",
|
|
3637
|
+
dataType: "string",
|
|
3638
|
+
uom: "string",
|
|
3639
|
+
effectiveTime: "string",
|
|
3640
|
+
effectiveEndTime: "string",
|
|
3641
|
+
recordTime: "string",
|
|
3642
|
+
source: "string",
|
|
3643
|
+
derived: "boolean"
|
|
3644
|
+
}
|
|
3645
|
+
},
|
|
3646
|
+
/*
|
|
3647
|
+
* ── 경로망 위의 운행 (2026-12-04, operato-application ADR-0266 결정 8 ②, `travel.ts`) ─────────────────────────────────────
|
|
3648
|
+
*
|
|
3649
|
+
* 구내 반송 제품이 보내는 넷. 사건 이름 · 데이터 모양은 이미 있었고(`OP_EVENT.travel*`, 커널의 접기도 섰다) 들어올 문만 없었다 —
|
|
3650
|
+
* 그래서 이 표에 선다(고칠 자리가 셋인 까닭, 위 `match` 의 머리말).
|
|
3651
|
+
*
|
|
3652
|
+
* 장비를 `equipmentId` 로 부른다(`travel.ts` 의 결정 — 옛 와이어 이름이 아니다). 그 이름은 설비 **에너지** 상태의 것이기도 해서,
|
|
3653
|
+
* 갈래는 **함께 오는 칸**으로 가른다: 지난 자리(`location`) · 잡은 구간(`connectionIds`) · 통신(`link`) · 위치(`pose`). 에너지 문은
|
|
3654
|
+
* 이 넷을 밀어낸다(`isEnergyEquipmentRecord` — 판정끼리 배타). 이 갈래들은 다른 어떤 갈래보다 먼저 본다 — 정체 칸이 다른 갈래와
|
|
3655
|
+
* 겹치지 않으므로 순서는 넷 사이의 것이다.
|
|
3656
|
+
*/
|
|
3657
|
+
"travel-passed": {
|
|
3658
|
+
eventType: OP_EVENT.travelPassed,
|
|
3659
|
+
match: ["equipmentId", "location"],
|
|
3660
|
+
matchOrder: 5,
|
|
3661
|
+
identity: "equipmentId",
|
|
3662
|
+
required: ["equipmentId", "location"],
|
|
3663
|
+
fields: { equipmentId: "string", location: "string", heading: "number", recordTime: "string" }
|
|
3664
|
+
},
|
|
3665
|
+
"travel-reservation": {
|
|
3666
|
+
eventType: OP_EVENT.travelReservation,
|
|
3667
|
+
match: ["equipmentId", "connectionIds"],
|
|
3668
|
+
matchOrder: 5,
|
|
3669
|
+
identity: "equipmentId",
|
|
3670
|
+
/* 빈 목록은 「전부 놓았다」는 말이다 — 비어 있어도 받는다(아래 `ingest` 의 빈 값 규칙은 배열을 비었다고 보지 않는다). */
|
|
3671
|
+
required: ["equipmentId", "connectionIds"],
|
|
3672
|
+
fields: { equipmentId: "string", connectionIds: "string[]", recordTime: "string" }
|
|
3673
|
+
},
|
|
3674
|
+
"travel-link": {
|
|
3675
|
+
eventType: OP_EVENT.travelLink,
|
|
3676
|
+
match: ["equipmentId", "link"],
|
|
3677
|
+
matchOrder: 5,
|
|
3678
|
+
identity: "equipmentId",
|
|
3679
|
+
required: ["equipmentId", "link"],
|
|
3680
|
+
fields: { equipmentId: "string", link: "object", recordTime: "string" },
|
|
3681
|
+
shapes: {
|
|
3682
|
+
link: {
|
|
3683
|
+
required: ["state", "lastSeenAt", "judgedBy"],
|
|
3684
|
+
fields: { lastSeenAt: "string", lastLocation: "string" },
|
|
3685
|
+
enums: { state: TRAVEL_LINK_STATE, judgedBy: TRAVEL_LINK_JUDGED_BY }
|
|
3686
|
+
}
|
|
3687
|
+
}
|
|
3688
|
+
},
|
|
3689
|
+
"travel-pose": {
|
|
3690
|
+
eventType: OP_EVENT.travelPose,
|
|
3691
|
+
match: ["equipmentId", "pose"],
|
|
3692
|
+
matchOrder: 5,
|
|
3693
|
+
identity: "equipmentId",
|
|
3694
|
+
required: ["equipmentId", "pose"],
|
|
3695
|
+
fields: { equipmentId: "string", pose: "object", recordTime: "string" },
|
|
3696
|
+
shapes: {
|
|
3697
|
+
pose: {
|
|
3698
|
+
required: ["x", "y", "theta", "networkVersion", "at"],
|
|
3699
|
+
fields: { x: "number", y: "number", theta: "number", networkVersion: "string", at: "string", deviationM: "number" }
|
|
3700
|
+
}
|
|
3701
|
+
}
|
|
3702
|
+
}
|
|
3703
|
+
};
|
|
3704
|
+
var TRAVEL_KINDS = Object.keys(SPECS).filter((kind) => SPECS[kind].identity === "equipmentId");
|
|
3705
|
+
function isTravelRecord(record) {
|
|
3706
|
+
const kind = operationalKindOf(record);
|
|
3707
|
+
return kind !== void 0 && TRAVEL_KINDS.includes(kind);
|
|
3708
|
+
}
|
|
3709
|
+
function operationalKindOf(record) {
|
|
3710
|
+
if (!record || typeof record !== "object") return void 0;
|
|
3711
|
+
const r = record;
|
|
3712
|
+
if (r.epc !== void 0 || r.meterId !== void 0) return void 0;
|
|
3713
|
+
const travelOnly = r.equipmentId !== void 0;
|
|
3714
|
+
const present = (k) => {
|
|
3715
|
+
const v = r[k];
|
|
3716
|
+
if (v === void 0 || v === null) return false;
|
|
3717
|
+
return typeof v === "string" ? v.trim().length > 0 : true;
|
|
3718
|
+
};
|
|
3719
|
+
for (const kind of MATCH_ORDER) {
|
|
3720
|
+
const spec = SPECS[kind];
|
|
3721
|
+
if (travelOnly !== (spec.identity === "equipmentId")) continue;
|
|
3722
|
+
const fields = spec.match ?? [spec.identity];
|
|
3723
|
+
if (fields.every(present)) return kind;
|
|
3724
|
+
}
|
|
3725
|
+
return void 0;
|
|
3726
|
+
}
|
|
3727
|
+
function unknownKindReason() {
|
|
3728
|
+
const shapes = MATCH_ORDER.map((kind) => {
|
|
3729
|
+
const spec = SPECS[kind];
|
|
3730
|
+
const fields = spec.match ?? [spec.identity];
|
|
3731
|
+
return `${kind}: ${fields.join("+")}`;
|
|
3732
|
+
});
|
|
3733
|
+
return `\uC6B4\uC601 \uB808\uCF54\uB4DC\uC758 \uC720\uD615\uC744 \uD310\uBCC4\uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. \uC720\uD615\uC744 \uC2DD\uBCC4\uD560 \uD544\uB4DC\uAC00 \uD544\uC694\uD569\uB2C8\uB2E4(${shapes.join(" \xB7 ")}). epc\uAC00 \uD3EC\uD568\uB41C \uB808\uCF54\uB4DC\uB294 EPCIS \uCC98\uB9AC \uACBD\uB85C\uC5D0 \uC81C\uCD9C\uD558\uC138\uC694.`;
|
|
3734
|
+
}
|
|
3735
|
+
var MATCH_ORDER = Object.keys(SPECS).sort(
|
|
3736
|
+
(a, b) => (SPECS[a].matchOrder ?? 1e3) - (SPECS[b].matchOrder ?? 1e3)
|
|
3737
|
+
);
|
|
3738
|
+
function operationalIdentityField(kind) {
|
|
3739
|
+
return kind ? SPECS[kind]?.identity : void 0;
|
|
3740
|
+
}
|
|
3741
|
+
function isOperationalRecord(record) {
|
|
3742
|
+
return operationalKindOf(record) !== void 0;
|
|
3743
|
+
}
|
|
3744
|
+
function ingestOperationalRecords(records, opts) {
|
|
3745
|
+
const arr = Array.isArray(records) ? records : records ? [records] : [];
|
|
3746
|
+
const accepted = [];
|
|
3747
|
+
const rejected = [];
|
|
3748
|
+
let seq = 0;
|
|
3749
|
+
for (const record of arr) {
|
|
3750
|
+
const kind = operationalKindOf(record);
|
|
3751
|
+
if (!kind) {
|
|
3752
|
+
rejected.push({ record, errors: [unknownKindReason()] });
|
|
3753
|
+
continue;
|
|
3754
|
+
}
|
|
3755
|
+
const spec = SPECS[kind];
|
|
3756
|
+
const r = record;
|
|
3757
|
+
const errors = [];
|
|
3758
|
+
const ENVELOPE_FIELDS = ["at", "description"];
|
|
3759
|
+
const unknown = Object.keys(r).filter((k) => !ENVELOPE_FIELDS.includes(k) && spec.fields[k] === void 0);
|
|
3760
|
+
if (unknown.length) errors.push(`${kind}: \uACC4\uC57D\uC5D0 \uC5C6\uB294 \uD544\uB4DC \u2014 ${unknown.join(", ")}`);
|
|
3761
|
+
for (const name of spec.required) {
|
|
3762
|
+
const v = r[name];
|
|
3763
|
+
if (v === void 0 || v === null || v === "") errors.push(`${kind}: ${name}: \uD544\uC218 \uAC12 \uB204\uB77D`);
|
|
3764
|
+
}
|
|
3765
|
+
const data = {};
|
|
3766
|
+
for (const [name, type] of Object.entries(spec.fields)) {
|
|
3767
|
+
const v = r[name];
|
|
3768
|
+
if (v === void 0 || v === null || v === "") continue;
|
|
3769
|
+
switch (type) {
|
|
3770
|
+
case "string": {
|
|
3771
|
+
if (typeof v !== "string") {
|
|
3772
|
+
errors.push(`${kind}.${name} \uAC12\uC740 \uBB38\uC790\uC5F4\uC774\uC5B4\uC57C \uD569\uB2C8\uB2E4: ${JSON.stringify(v)}`);
|
|
3773
|
+
break;
|
|
3774
|
+
}
|
|
3775
|
+
const allowed = spec.enums?.[name];
|
|
3776
|
+
if (allowed && !allowed.includes(v)) {
|
|
3777
|
+
errors.push(`${kind}.${name}\uC5D0 \uD5C8\uC6A9\uB418\uC9C0 \uC54A\uB294 \uAC12\uC774 \uC9C0\uC815\uB418\uC5C8\uC2B5\uB2C8\uB2E4: ${JSON.stringify(v)} \u2014 \uD5C8\uC6A9 \uAC12: ${allowed.join(" \xB7 ")}`);
|
|
3778
|
+
break;
|
|
3779
|
+
}
|
|
3780
|
+
data[name] = v;
|
|
3781
|
+
break;
|
|
3782
|
+
}
|
|
3783
|
+
case "number": {
|
|
3784
|
+
const n = Number(v);
|
|
3785
|
+
if (typeof v === "boolean" || !Number.isFinite(n)) {
|
|
3786
|
+
errors.push(`${kind}.${name} \uAC12\uC740 \uC720\uD55C\uD55C \uC22B\uC790\uC5EC\uC57C \uD569\uB2C8\uB2E4: ${JSON.stringify(v)}`);
|
|
3787
|
+
break;
|
|
3788
|
+
}
|
|
3789
|
+
if (name === "progress" && (n < 0 || n > 1)) {
|
|
3790
|
+
errors.push(`${kind}.progress \uB294 0~1 \uBE44\uC728\uC774\uB2E4: ${n}`);
|
|
3791
|
+
break;
|
|
3792
|
+
}
|
|
3793
|
+
if ((name === "requested" || name === "fulfilled" || name === "goodCount" || name === "nonconformingCount") && n < 0) {
|
|
3794
|
+
errors.push(`${kind}.${name} \uAC00 \uC74C\uC218\uB2E4: ${n}`);
|
|
3795
|
+
break;
|
|
3796
|
+
}
|
|
3797
|
+
data[name] = n;
|
|
3798
|
+
break;
|
|
3799
|
+
}
|
|
3800
|
+
case "boolean": {
|
|
3801
|
+
if (typeof v !== "boolean") {
|
|
3802
|
+
errors.push(`${kind}.${name} \uAC12\uC740 \uBD88\uB9AC\uC5B8\uC774\uC5B4\uC57C \uD569\uB2C8\uB2E4: ${JSON.stringify(v)}`);
|
|
3803
|
+
break;
|
|
3804
|
+
}
|
|
3805
|
+
data[name] = v;
|
|
3806
|
+
break;
|
|
3807
|
+
}
|
|
3808
|
+
case "string[]": {
|
|
3809
|
+
if (!Array.isArray(v) || v.some((x) => typeof x !== "string")) {
|
|
3810
|
+
errors.push(`${kind}.${name} \uAC12\uC740 \uBB38\uC790\uC5F4 \uBC30\uC5F4\uC774\uC5B4\uC57C \uD569\uB2C8\uB2E4: ${JSON.stringify(v)}`);
|
|
3811
|
+
break;
|
|
3812
|
+
}
|
|
3813
|
+
data[name] = v.slice();
|
|
3814
|
+
break;
|
|
3815
|
+
}
|
|
3816
|
+
case "object": {
|
|
3817
|
+
if (Array.isArray(v) || typeof v !== "object") {
|
|
3818
|
+
errors.push(`${kind}.${name} \uAC12\uC740 \uAC1D\uCCB4\uC5EC\uC57C \uD569\uB2C8\uB2E4: ${JSON.stringify(v)}`);
|
|
3819
|
+
break;
|
|
3820
|
+
}
|
|
3821
|
+
errors.push(...shapeErrors(`${kind}.${name}`, v, spec.shapes?.[name]));
|
|
3822
|
+
data[name] = { ...v };
|
|
3823
|
+
break;
|
|
3824
|
+
}
|
|
3825
|
+
case "object[]": {
|
|
3826
|
+
if (!Array.isArray(v) || v.some((x) => !x || typeof x !== "object")) {
|
|
3827
|
+
errors.push(`${kind}.${name} \uAC12\uC740 \uAC1D\uCCB4 \uBC30\uC5F4\uC774\uC5B4\uC57C \uD569\uB2C8\uB2E4: ${JSON.stringify(v)}`);
|
|
3828
|
+
break;
|
|
3829
|
+
}
|
|
3830
|
+
v.forEach(
|
|
3831
|
+
(x, i) => errors.push(...shapeErrors(`${kind}.${name}[${i}]`, x, spec.shapes?.[name]))
|
|
3832
|
+
);
|
|
3833
|
+
data[name] = v.map((x) => ({ ...x }));
|
|
3834
|
+
break;
|
|
3835
|
+
}
|
|
3836
|
+
}
|
|
3837
|
+
}
|
|
3838
|
+
if ((kind === "task" || kind === "equipment-period") && r.workShiftBasis !== void 0) {
|
|
3839
|
+
if (!isWorkShiftExecutionBasis(r.workShiftBasis) || kind === "equipment-period" && Date.parse(r.workShiftBasis.businessTime) !== Date.parse(String(r.from)) || kind === "task" && (r.startTime ?? r.endTime) !== void 0 && Date.parse(r.workShiftBasis.businessTime) !== Date.parse(String(r.startTime ?? r.endTime))) {
|
|
3840
|
+
errors.push(kind + ".workShiftBasis: invalid pinned shift evidence");
|
|
3841
|
+
} else data.workShiftBasis = structuredClone(r.workShiftBasis);
|
|
3842
|
+
}
|
|
3843
|
+
if (kind === "test" && r.specificationBasis !== void 0 && !isTestSpecificationBasis(r.specificationBasis)) {
|
|
3844
|
+
errors.push("test.specificationBasis: invalid pinned specification evidence");
|
|
3845
|
+
}
|
|
3846
|
+
if (kind === "order" && r.materialBasis !== void 0) {
|
|
3847
|
+
const bases = r.materialBasis;
|
|
3848
|
+
if (!Array.isArray(bases) || !bases.length || bases.length > 1e3 || !bases.every(isMaterialExecutionBasis) || new Set(bases.map((b) => b.material.id)).size !== bases.length || r.gtin !== void 0 && !bases.some((b) => b.material.id === r.gtin) || isRecipeExecutionBasis(r.recipeBasis) && [...r.recipeBasis.recipe.inputs, ...r.recipeBasis.recipe.outputs].some((line) => !bases.some((b) => b.material.id === line.material)))
|
|
3849
|
+
errors.push("order.materialBasis: invalid pinned material evidence");
|
|
3850
|
+
}
|
|
3851
|
+
if (kind === "order" && r.recipeBasis !== void 0 && (!isRecipeExecutionBasis(r.recipeBasis) || r.recipeKey !== void 0 && r.recipeKey !== r.recipeBasis.recipe.key)) {
|
|
3852
|
+
errors.push("order.recipeBasis: invalid pinned recipe evidence");
|
|
3853
|
+
}
|
|
3854
|
+
const closedPeriodEnd = kind === "equipment-period" ? String(r.to ?? "").trim() : "";
|
|
3855
|
+
const at2 = closedPeriodEnd || String(r.at ?? "").trim() || opts.defaultEventTime;
|
|
3856
|
+
const atMs = at2 ? Date.parse(at2) : Number.NaN;
|
|
3857
|
+
if (!Number.isFinite(atMs)) {
|
|
3858
|
+
errors.push(`${kind}: at \uC5C6\uC74C/\uD615\uC2DD \uC624\uB958 \u2014 \uC774\uC804 \uC774\uBCA4\uD2B8\uAC00 \uB4A4\uB2A6\uAC8C \uB3C4\uCC29\uD588\uB294\uC9C0 \uD310\uB2E8\uD558\uB824\uBA74 \uC2DC\uAC01\uC774 \uD544\uC694\uD569\uB2C8\uB2E4.`);
|
|
3859
|
+
}
|
|
3860
|
+
if (closedPeriodEnd && opts.defaultEventTime) {
|
|
3861
|
+
const nowMs = Date.parse(opts.defaultEventTime);
|
|
3862
|
+
if (Number.isFinite(nowMs) && Number.isFinite(atMs) && atMs > nowMs) {
|
|
3863
|
+
errors.push(`${kind}: \uC544\uC9C1 \uC624\uC9C0 \uC54A\uC740 \uC2DC\uAC01\uC758 \uC0AC\uC2E4\uC774\uB2E4(${closedPeriodEnd}) \u2014 \uC885\uB8CC\uB41C \uAD6C\uAC04\uB9CC \uB9C8\uAC10\uD560 \uC218 \uC788\uC2B5\uB2C8\uB2E4.`);
|
|
3864
|
+
}
|
|
3865
|
+
}
|
|
3866
|
+
if (errors.length) {
|
|
3867
|
+
rejected.push({ record, errors });
|
|
3868
|
+
continue;
|
|
3869
|
+
}
|
|
3870
|
+
const note = typeof r.description === "string" ? String(r.description).trim() : "";
|
|
3871
|
+
accepted.push({
|
|
3872
|
+
eventId: `${opts.tenantId}-op-${kind}-${++seq}`,
|
|
3873
|
+
eventType: spec.eventType,
|
|
3874
|
+
eventTime: new Date(atMs).toISOString(),
|
|
3875
|
+
tenantId: opts.tenantId,
|
|
3876
|
+
...note ? { description: note } : {},
|
|
3877
|
+
data
|
|
3878
|
+
});
|
|
3879
|
+
}
|
|
3880
|
+
return { accepted, rejected };
|
|
3289
3881
|
}
|
|
3290
|
-
|
|
3291
|
-
|
|
3882
|
+
|
|
3883
|
+
// src/energy-ingest.ts
|
|
3884
|
+
function isEnergyRecord(record) {
|
|
3885
|
+
if (!record || typeof record !== "object") return false;
|
|
3886
|
+
const r = record;
|
|
3887
|
+
if (!(typeof r.meterId === "string" && r.meterId.trim().length > 0 && r.epc === void 0)) return false;
|
|
3888
|
+
return r.from === void 0 && r.to === void 0;
|
|
3889
|
+
}
|
|
3890
|
+
function ingestEnergyRecords(records, opts) {
|
|
3891
|
+
const arr = Array.isArray(records) ? records : records ? [records] : [];
|
|
3292
3892
|
const accepted = [];
|
|
3293
3893
|
const rejected = [];
|
|
3294
|
-
|
|
3894
|
+
let seq = 0;
|
|
3895
|
+
for (const record of arr) {
|
|
3295
3896
|
const errors = [];
|
|
3296
|
-
const
|
|
3297
|
-
|
|
3298
|
-
const
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3897
|
+
const meterId = String(record?.meterId ?? "").trim();
|
|
3898
|
+
if (!meterId) errors.push("meterId \uC5C6\uC74C \u2014 \uC5B4\uB514\uC758 \uC18C\uBE44\uC778\uC9C0 \uBAA8\uB974\uB294 \uAC12\uC740 \uB204\uC801\uD560 \uC218 \uC5C6\uB2E4");
|
|
3899
|
+
const at2 = String(record?.at ?? "").trim() || opts.defaultEventTime;
|
|
3900
|
+
const atMs = at2 ? Date.parse(at2) : Number.NaN;
|
|
3901
|
+
if (!Number.isFinite(atMs)) errors.push("at \uC5C6\uC74C/\uD615\uC2DD \uC624\uB958 \u2014 \uC9C0\uAE08 \uC2DC\uAC01\uC73C\uB85C \uBA54\uC6B0\uBA74 \uB0A8\uC758 \uC218\uC694 \uAD6C\uAC04\uC5D0 \uC2E4\uB9B0\uB2E4");
|
|
3902
|
+
const num2 = (v, name) => {
|
|
3903
|
+
if (v === void 0 || v === null || v === "") return void 0;
|
|
3904
|
+
const n = Number(v);
|
|
3905
|
+
if (!Number.isFinite(n)) {
|
|
3906
|
+
errors.push(`${name} \uAC00 \uC218\uAC00 \uC544\uB2C8\uB2E4: ${JSON.stringify(v)}`);
|
|
3907
|
+
return void 0;
|
|
3908
|
+
}
|
|
3909
|
+
return n;
|
|
3910
|
+
};
|
|
3911
|
+
const kW = num2(record?.kW, "kW");
|
|
3912
|
+
const kWh = num2(record?.kWh, "kWh");
|
|
3913
|
+
const powerFactor = num2(record?.powerFactor, "powerFactor");
|
|
3914
|
+
if (errors.length) {
|
|
3915
|
+
rejected.push({ record, errors });
|
|
3309
3916
|
continue;
|
|
3310
3917
|
}
|
|
3918
|
+
const eventTime = new Date(atMs).toISOString();
|
|
3311
3919
|
const data = {
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
...
|
|
3316
|
-
...
|
|
3920
|
+
meterId,
|
|
3921
|
+
/* 계약은 `kW` 를 필수로 두지만 **못 읽은 표본도 사실**이다 — 그 경우 값을 비우고 보낸다.
|
|
3922
|
+
커널이 「받았지만 부하를 못 읽었다」로 세고, 구간 마감에 그 이유를 싣는다. */
|
|
3923
|
+
...kW !== void 0 ? { kW } : {},
|
|
3924
|
+
...kWh !== void 0 ? { kWh } : {},
|
|
3925
|
+
...powerFactor !== void 0 ? { powerFactor } : {},
|
|
3926
|
+
at: eventTime
|
|
3317
3927
|
};
|
|
3318
3928
|
accepted.push({
|
|
3319
|
-
eventId:
|
|
3320
|
-
eventType: ENERGY_EVENT.
|
|
3321
|
-
|
|
3322
|
-
eventTime: span.from,
|
|
3929
|
+
eventId: `${opts.tenantId}-energy-${++seq}`,
|
|
3930
|
+
eventType: ENERGY_EVENT.measured,
|
|
3931
|
+
eventTime,
|
|
3323
3932
|
tenantId: opts.tenantId,
|
|
3324
3933
|
data
|
|
3325
3934
|
});
|
|
3326
3935
|
}
|
|
3327
3936
|
return { accepted, rejected };
|
|
3328
3937
|
}
|
|
3329
|
-
|
|
3938
|
+
var POSITIONS = /* @__PURE__ */ new Set(["open", "closed", "intermediate", "bad"]);
|
|
3939
|
+
function isEnergyEquipmentRecord(record) {
|
|
3940
|
+
if (!record || typeof record !== "object") return false;
|
|
3330
3941
|
const r = record;
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
}
|
|
3335
|
-
function futureFactError(eventTime, opts) {
|
|
3336
|
-
const nowText = opts.nowISO ?? opts.defaultEventTime;
|
|
3337
|
-
if (!nowText) return void 0;
|
|
3338
|
-
const nowMs = Date.parse(nowText);
|
|
3339
|
-
const atMs = Date.parse(eventTime);
|
|
3340
|
-
if (!Number.isFinite(nowMs) || !Number.isFinite(atMs) || atMs <= nowMs) return void 0;
|
|
3341
|
-
return `\uC544\uC9C1 \uC624\uC9C0 \uC54A\uC740 \uC2DC\uAC01\uC758 \uC0AC\uC2E4\uC774\uB2E4(${eventTime}) \u2014 \uB05D\uB098\uC9C0 \uC54A\uC740 \uAE30\uAC04\uC740 \uB9C8\uAC10\uB41C \uC0AC\uC2E4\uC774 \uC544\uB2C8\uB2E4`;
|
|
3342
|
-
}
|
|
3343
|
-
function resolveSubject(kind, localId, opts) {
|
|
3344
|
-
const declared = opts.identityOf?.(kind, localId);
|
|
3345
|
-
if (declared) return { subject: declared, basis: "declared" };
|
|
3346
|
-
return { subject: opts.scopeId ? `${opts.scopeId}/${localId}` : localId, basis: "twin-local" };
|
|
3347
|
-
}
|
|
3348
|
-
function periodFactId(tenantId, kind, subject, from, to) {
|
|
3349
|
-
return [tenantId, kind, subject, from, to].join("|");
|
|
3350
|
-
}
|
|
3351
|
-
function readSpan(r, errors) {
|
|
3352
|
-
const from = String(r?.from ?? "").trim();
|
|
3353
|
-
const to = String(r?.to ?? "").trim();
|
|
3354
|
-
const fromMs = Date.parse(from);
|
|
3355
|
-
const toMs = Date.parse(to);
|
|
3356
|
-
if (!from || !Number.isFinite(fromMs)) errors.push(`from \uC744 \uC2DC\uAC01\uC73C\uB85C \uC77D\uC744 \uC218 \uC5C6\uB2E4: ${JSON.stringify(r?.from)}`);
|
|
3357
|
-
if (!to || !Number.isFinite(toMs)) errors.push(`to \uB97C \uC2DC\uAC01\uC73C\uB85C \uC77D\uC744 \uC218 \uC5C6\uB2E4: ${JSON.stringify(r?.to)}`);
|
|
3358
|
-
if (Number.isFinite(fromMs) && Number.isFinite(toMs) && !(toMs > fromMs)) {
|
|
3359
|
-
errors.push(`\uAD6C\uAC04\uC774 \uB4A4\uC9D1\uD614\uAC70\uB098 \uAE38\uC774\uAC00 \uC5C6\uB2E4(${from} \u2192 ${to}) \u2014 \uC5B4\uB290 \uCABD\uC774 \uD2C0\uB838\uB294\uC9C0 \uC6B0\uB9AC\uAC00 \uC815\uD560 \uC218 \uC5C6\uB2E4`);
|
|
3360
|
-
}
|
|
3361
|
-
return errors.length ? void 0 : { from, to };
|
|
3362
|
-
}
|
|
3363
|
-
function readAmount(raw, name, errors) {
|
|
3364
|
-
if (raw === void 0 || raw === null || String(raw).trim() === "") return void 0;
|
|
3365
|
-
const v = Number(raw);
|
|
3366
|
-
if (!Number.isFinite(v)) {
|
|
3367
|
-
errors.push(`${name} \uB97C \uC218\uB85C \uC77D\uC744 \uC218 \uC5C6\uB2E4: ${JSON.stringify(raw)}`);
|
|
3368
|
-
return void 0;
|
|
3369
|
-
}
|
|
3370
|
-
if (v < 0) {
|
|
3371
|
-
errors.push(`${name} \uAC00 \uC74C\uC218\uB2E4(${v})`);
|
|
3372
|
-
return void 0;
|
|
3373
|
-
}
|
|
3374
|
-
return v;
|
|
3942
|
+
return typeof r.equipmentId === "string" && r.equipmentId.trim().length > 0 && r.epc === void 0 && r.meterId === void 0 && /* 적산을 실었으면 발전이다 — 이 문의 값은 상태이고, 적산은 자기 문이 있다. */
|
|
3943
|
+
r.kWh === void 0 && /* 운행 사실(지난 자리 · 잡은 구간 · 통신 · 위치)도 `equipmentId` 를 싣는다 — 그것은 운영 문의 것이다(2026-12-04). */
|
|
3944
|
+
!isTravelRecord(r);
|
|
3375
3945
|
}
|
|
3376
|
-
function
|
|
3377
|
-
const
|
|
3946
|
+
function ingestEnergyEquipmentRecords(records, opts) {
|
|
3947
|
+
const arr = Array.isArray(records) ? records : records ? [records] : [];
|
|
3378
3948
|
const accepted = [];
|
|
3379
3949
|
const rejected = [];
|
|
3380
|
-
|
|
3950
|
+
let seq = 0;
|
|
3951
|
+
for (const record of arr) {
|
|
3381
3952
|
const errors = [];
|
|
3382
|
-
const
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
const
|
|
3386
|
-
|
|
3387
|
-
if (
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3953
|
+
const r = record;
|
|
3954
|
+
const equipmentId = String(r?.equipmentId ?? "").trim();
|
|
3955
|
+
if (!equipmentId) errors.push("equipmentId \uC5C6\uC74C \u2014 \uC5B4\uB290 \uC124\uBE44\uC758 \uC0C1\uD0DC\uC778\uC9C0 \uBAA8\uB974\uB294 \uAC12\uC740 \uC2E4\uC744 \uC218 \uC5C6\uB2E4");
|
|
3956
|
+
const at2 = String(r?.at ?? "").trim() || opts.defaultEventTime;
|
|
3957
|
+
const atMs = at2 ? Date.parse(at2) : Number.NaN;
|
|
3958
|
+
if (!Number.isFinite(atMs)) errors.push("at \uC5C6\uC74C/\uD615\uC2DD \uC624\uB958 \u2014 \uC9C0\uAE08 \uC2DC\uAC01\uC73C\uB85C \uBA54\uC6B0\uBA74 \uC5B8\uC81C\uC758 \uC0C1\uD0DC\uC778\uC9C0 \uC54C \uC218 \uC5C6\uB2E4");
|
|
3959
|
+
const num2 = (v, name, min, max) => {
|
|
3960
|
+
if (v === void 0 || v === null || v === "") return void 0;
|
|
3961
|
+
const n = Number(v);
|
|
3962
|
+
if (!Number.isFinite(n)) {
|
|
3963
|
+
errors.push(`${name} \uAC00 \uC218\uAC00 \uC544\uB2C8\uB2E4: ${JSON.stringify(v)}`);
|
|
3964
|
+
return void 0;
|
|
3965
|
+
}
|
|
3966
|
+
if (min !== void 0 && n < min) {
|
|
3967
|
+
errors.push(`${name} \uAC00 ${min} \uBCF4\uB2E4 \uC791\uB2E4: ${n}`);
|
|
3968
|
+
return void 0;
|
|
3969
|
+
}
|
|
3970
|
+
if (max !== void 0 && n > max) {
|
|
3971
|
+
errors.push(`${name} \uAC00 ${max} \uBCF4\uB2E4 \uD06C\uB2E4: ${n}`);
|
|
3972
|
+
return void 0;
|
|
3973
|
+
}
|
|
3974
|
+
return n;
|
|
3975
|
+
};
|
|
3976
|
+
const generatedKW = num2(r?.generatedKW, "generatedKW", 0);
|
|
3977
|
+
const exportKW = num2(r?.exportKW, "exportKW");
|
|
3978
|
+
const soc = num2(r?.soc, "soc", 0, 100);
|
|
3979
|
+
const chargeKW = num2(r?.chargeKW, "chargeKW", 0);
|
|
3980
|
+
const dischargeKW = num2(r?.dischargeKW, "dischargeKW", 0);
|
|
3981
|
+
const minKW = num2(r?.minKW, "minKW", 0);
|
|
3982
|
+
let curtailable;
|
|
3983
|
+
if (r?.curtailable !== void 0 && r?.curtailable !== null) {
|
|
3984
|
+
if (typeof r.curtailable !== "boolean") errors.push(`curtailable \uAC00 \uCC38/\uAC70\uC9D3\uC774 \uC544\uB2C8\uB2E4: ${JSON.stringify(r.curtailable)}`);
|
|
3985
|
+
else curtailable = r.curtailable;
|
|
3391
3986
|
}
|
|
3392
|
-
const
|
|
3393
|
-
const
|
|
3394
|
-
const
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
if (!
|
|
3401
|
-
errors.push(
|
|
3402
|
-
|
|
3987
|
+
const dcVoltage = num2(r?.dcVoltage, "dcVoltage", 0);
|
|
3988
|
+
const dcCurrent = num2(r?.dcCurrent, "dcCurrent", 0);
|
|
3989
|
+
const phases = (raw, name) => {
|
|
3990
|
+
if (raw === void 0 || raw === null) return void 0;
|
|
3991
|
+
if (!Array.isArray(raw)) {
|
|
3992
|
+
errors.push(`${name} \uAC00 \uBC30\uC5F4\uC774 \uC544\uB2C8\uB2E4 \u2014 \uC0C1\uBCC4 \uAC12\uC774\uB77C \uBC30\uC5F4\uB85C \uBC1B\uB294\uB2E4(\uB2E8\uC0C1\uC774\uBA74 \uC6D0\uC18C \uD558\uB098): ${JSON.stringify(raw)}`);
|
|
3993
|
+
return void 0;
|
|
3994
|
+
}
|
|
3995
|
+
if (!raw.length) {
|
|
3996
|
+
errors.push(`${name} \uAC00 \uBE48 \uBC30\uC5F4\uC774\uB2E4 \u2014 \uC7B0 \uC0C1\uC774 \uC5C6\uC73C\uBA74 \uADF8 \uCE78\uC744 \uBCF4\uB0B4\uC9C0 \uC54A\uB294\uB2E4`);
|
|
3997
|
+
return void 0;
|
|
3998
|
+
}
|
|
3999
|
+
const out = [];
|
|
4000
|
+
for (const [i, v] of raw.entries()) {
|
|
4001
|
+
const n = Number(v);
|
|
4002
|
+
if (!Number.isFinite(n)) {
|
|
4003
|
+
errors.push(`${name}[${i}] \uB97C \uC218\uB85C \uC77D\uC744 \uC218 \uC5C6\uB2E4: ${JSON.stringify(v)}`);
|
|
4004
|
+
return void 0;
|
|
4005
|
+
}
|
|
4006
|
+
if (n < 0) {
|
|
4007
|
+
errors.push(`${name}[${i}] \uAC00 \uC74C\uC218\uB2E4(${n}) \u2014 \uD06C\uAE30\uB294 \uC74C\uC218\uAC00 \uB418\uC9C0 \uC54A\uB294\uB2E4(\uBC29\uD5A5\uC740 \uB2E4\uB978 \uCD95\uC774 \uB9D0\uD55C\uB2E4)`);
|
|
4008
|
+
return void 0;
|
|
4009
|
+
}
|
|
4010
|
+
out.push(n);
|
|
4011
|
+
}
|
|
4012
|
+
return out;
|
|
4013
|
+
};
|
|
4014
|
+
const acVoltage = phases(r?.acVoltage, "acVoltage");
|
|
4015
|
+
const acCurrent = phases(r?.acCurrent, "acCurrent");
|
|
4016
|
+
if (acVoltage && acCurrent && acVoltage.length !== acCurrent.length) {
|
|
4017
|
+
errors.push(`acVoltage(${acVoltage.length}\uC0C1)\uC640 acCurrent(${acCurrent.length}\uC0C1)\uC758 \uC0C1 \uC218\uAC00 \uB2E4\uB974\uB2E4`);
|
|
3403
4018
|
}
|
|
3404
|
-
|
|
3405
|
-
|
|
4019
|
+
let position;
|
|
4020
|
+
if (r?.position !== void 0 && r?.position !== null && r?.position !== "") {
|
|
4021
|
+
const p = String(r.position);
|
|
4022
|
+
if (!POSITIONS.has(p)) errors.push(`position \uC774 \uD45C\uC900 \uAC12\uC774 \uC544\uB2C8\uB2E4(open\xB7closed\xB7intermediate\xB7bad): ${JSON.stringify(r.position)}`);
|
|
4023
|
+
else position = p;
|
|
4024
|
+
}
|
|
4025
|
+
const values = { generatedKW, exportKW, soc, chargeKW, dischargeKW, curtailable, minKW, position, dcVoltage, dcCurrent, acVoltage, acCurrent };
|
|
4026
|
+
if (!errors.length && Object.values(values).every((v) => v === void 0)) {
|
|
4027
|
+
errors.push("\uBC14\uAFC0 \uC0C1\uD0DC\uAC00 \uD558\uB098\uB3C4 \uC5C6\uB2E4 \u2014 \uAC12 \uC5C6\uB294 \uBCF4\uACE0\uB294 \uC0AC\uC2E4\uB85C \uC801\uC744 \uAC83\uC774 \uC5C6\uB2E4");
|
|
4028
|
+
}
|
|
4029
|
+
if (errors.length) {
|
|
4030
|
+
rejected.push({ record, errors });
|
|
3406
4031
|
continue;
|
|
3407
4032
|
}
|
|
3408
|
-
const
|
|
4033
|
+
const eventTime = new Date(atMs).toISOString();
|
|
3409
4034
|
const data = {
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
...
|
|
3417
|
-
...
|
|
3418
|
-
...
|
|
3419
|
-
...
|
|
4035
|
+
equipmentId,
|
|
4036
|
+
at: eventTime,
|
|
4037
|
+
...generatedKW !== void 0 ? { generatedKW } : {},
|
|
4038
|
+
...exportKW !== void 0 ? { exportKW } : {},
|
|
4039
|
+
...soc !== void 0 ? { soc } : {},
|
|
4040
|
+
...chargeKW !== void 0 ? { chargeKW } : {},
|
|
4041
|
+
...dischargeKW !== void 0 ? { dischargeKW } : {},
|
|
4042
|
+
...curtailable !== void 0 ? { curtailable } : {},
|
|
4043
|
+
...minKW !== void 0 ? { minKW } : {},
|
|
4044
|
+
...position !== void 0 ? { position } : {},
|
|
4045
|
+
...dcVoltage !== void 0 ? { dcVoltage } : {},
|
|
4046
|
+
...dcCurrent !== void 0 ? { dcCurrent } : {},
|
|
4047
|
+
...acVoltage !== void 0 ? { acVoltage } : {},
|
|
4048
|
+
...acCurrent !== void 0 ? { acCurrent } : {}
|
|
3420
4049
|
};
|
|
3421
|
-
const futureError = futureFactError(span.to, opts);
|
|
3422
|
-
if (futureError) {
|
|
3423
|
-
rejected.push({ record: r, errors: [futureError] });
|
|
3424
|
-
continue;
|
|
3425
|
-
}
|
|
3426
4050
|
accepted.push({
|
|
3427
|
-
eventId:
|
|
3428
|
-
eventType: ENERGY_EVENT.
|
|
3429
|
-
|
|
3430
|
-
eventTime: span.to,
|
|
4051
|
+
eventId: `${opts.tenantId}-energy-eq-${++seq}`,
|
|
4052
|
+
eventType: ENERGY_EVENT.equipment,
|
|
4053
|
+
eventTime,
|
|
3431
4054
|
tenantId: opts.tenantId,
|
|
3432
4055
|
data
|
|
3433
4056
|
});
|
|
3434
4057
|
}
|
|
3435
4058
|
return { accepted, rejected };
|
|
3436
4059
|
}
|
|
3437
|
-
function
|
|
4060
|
+
function isEnergyGenerationRecord(record) {
|
|
4061
|
+
if (record?.from !== void 0 || record?.to !== void 0) return false;
|
|
4062
|
+
if (!record || typeof record !== "object") return false;
|
|
4063
|
+
const r = record;
|
|
4064
|
+
return typeof r.equipmentId === "string" && r.equipmentId.trim().length > 0 && r.kWh !== void 0 && r.meterId === void 0 && r.epc === void 0;
|
|
4065
|
+
}
|
|
4066
|
+
function ingestEnergyGenerationRecords(records, opts) {
|
|
3438
4067
|
const list = records === void 0 || records === null ? [] : Array.isArray(records) ? records : [records];
|
|
3439
4068
|
const accepted = [];
|
|
3440
4069
|
const rejected = [];
|
|
4070
|
+
let seq = 0;
|
|
3441
4071
|
for (const r of list) {
|
|
3442
4072
|
const errors = [];
|
|
3443
|
-
const
|
|
3444
|
-
|
|
3445
|
-
const
|
|
3446
|
-
const
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
4073
|
+
const equipmentId = String(r?.equipmentId ?? "").trim();
|
|
4074
|
+
if (!equipmentId) errors.push("equipmentId \uAC00 \uC5C6\uB2E4 \u2014 \uC5B4\uB290 \uC124\uBE44\uAC00 \uB9CC\uB4E0 \uAC83\uC778\uC9C0 \uC9C0\uC5B4\uB0BC \uC218 \uC5C6\uB2E4");
|
|
4075
|
+
const STATE_FIELDS = ["generatedKW", "exportKW", "soc", "chargeKW", "dischargeKW", "curtailable", "minKW", "position"];
|
|
4076
|
+
const alsoState = STATE_FIELDS.filter((f) => r?.[f] !== void 0);
|
|
4077
|
+
if (alsoState.length) {
|
|
4078
|
+
errors.push(
|
|
4079
|
+
`\uD55C \uB808\uCF54\uB4DC\uC5D0 \uC801\uC0B0\uAC12\uACFC \uC124\uBE44 \uC0C1\uD0DC\uAC00 \uD568\uAED8 \uB4E4\uC5B4 \uC788\uC2B5\uB2C8\uB2E4(${alsoState.join("\xB7")}) \u2014 \uC774 \uACBD\uB85C\uC5D0\uC11C\uB294 \uC801\uC0B0\uAC12\uB9CC \uCC98\uB9AC\uD569\uB2C8\uB2E4. \uC124\uBE44 \uC0C1\uD0DC\uB294 \uBCC4\uB3C4 \uB808\uCF54\uB4DC\uB85C \uBCF4\uB0B4\uC138\uC694.`
|
|
4080
|
+
);
|
|
3450
4081
|
}
|
|
3451
|
-
const
|
|
3452
|
-
|
|
3453
|
-
if (
|
|
4082
|
+
const raw = r?.kWh;
|
|
4083
|
+
const kWh = Number(raw);
|
|
4084
|
+
if (raw === void 0 || raw === null || !Number.isFinite(kWh)) {
|
|
4085
|
+
errors.push("kWh \uAC00 \uC5C6\uB2E4 \u2014 \uC774 \uBB38\uC774 \uBC1B\uB294 \uAC12\uC740 \uC801\uC0B0 \uD558\uB098\uB2E4(\uC21C\uC2DC \uCD9C\uB825\uC740 \uC124\uBE44 \uC0C1\uD0DC\uB85C \uBCF4\uB0B8\uB2E4)");
|
|
4086
|
+
} else if (kWh < 0) {
|
|
4087
|
+
errors.push(`kWh \uAC00 \uC74C\uC218\uB2E4(${kWh}) \u2014 \uC801\uC0B0\uC740 \uB4A4\uB85C \uAC00\uB354\uB77C\uB3C4 \uC74C\uC218\uAC00 \uB418\uC9C0 \uC54A\uB294\uB2E4`);
|
|
4088
|
+
}
|
|
4089
|
+
const eventTime = String(r?.at ?? "").trim() || opts.defaultEventTime || "";
|
|
4090
|
+
if (!eventTime) errors.push("at \uC774 \uC5C6\uACE0 \uAE30\uBCF8 \uC2DC\uAC01\uB3C4 \uC8FC\uC9C0 \uC54A\uC558\uB2E4 \u2014 \uC5B8\uC81C \uC7B0 \uAC83\uC778\uC9C0 \uC9C0\uC5B4\uB0BC \uC218 \uC5C6\uB2E4");
|
|
4091
|
+
let since;
|
|
4092
|
+
const rawSince = r?.kWhSince;
|
|
4093
|
+
if (rawSince !== void 0 && rawSince !== null && String(rawSince).trim()) {
|
|
4094
|
+
const text = String(rawSince).trim();
|
|
4095
|
+
const at2 = Date.parse(text);
|
|
4096
|
+
if (!Number.isFinite(at2)) errors.push(`kWhSince \uB97C \uC2DC\uAC01\uC73C\uB85C \uC77D\uC744 \uC218 \uC5C6\uB2E4: ${JSON.stringify(rawSince)}`);
|
|
4097
|
+
else if (Number.isFinite(Date.parse(eventTime)) && at2 > Date.parse(eventTime)) {
|
|
4098
|
+
errors.push(`kWhSince(${text}) \uAC00 \uC7B0 \uC2DC\uAC01(${eventTime})\uBCF4\uB2E4 \uB4A4\uB2E4 \u2014 \uB458 \uC911 \uD558\uB098\uAC00 \uD2C0\uB838\uB2E4`);
|
|
4099
|
+
} else since = text;
|
|
4100
|
+
}
|
|
4101
|
+
const ACCUMULATIONS = ["lifetime", "daily", "monthly", "billing", "unknown"];
|
|
4102
|
+
let accumulation;
|
|
4103
|
+
const rawAcc = r?.kWhAccumulation;
|
|
4104
|
+
if (rawAcc !== void 0 && rawAcc !== null && String(rawAcc).trim()) {
|
|
4105
|
+
const text = String(rawAcc).trim();
|
|
4106
|
+
if (!ACCUMULATIONS.includes(text)) {
|
|
4107
|
+
errors.push(`kWhAccumulation \uC774 \uC544\uB294 \uAC12\uC774 \uC544\uB2C8\uB2E4(${ACCUMULATIONS.join("\xB7")}): ${JSON.stringify(rawAcc)}`);
|
|
4108
|
+
} else accumulation = text;
|
|
4109
|
+
}
|
|
4110
|
+
if (errors.length) {
|
|
3454
4111
|
rejected.push({ record: r, errors });
|
|
3455
4112
|
continue;
|
|
3456
4113
|
}
|
|
3457
4114
|
const data = {
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
...
|
|
3462
|
-
...
|
|
3463
|
-
...currency ? { currency } : {},
|
|
3464
|
-
...billingDemandKW !== void 0 ? { billingDemandKW } : {}
|
|
4115
|
+
equipmentId,
|
|
4116
|
+
kWh,
|
|
4117
|
+
at: eventTime,
|
|
4118
|
+
...since ? { since } : {},
|
|
4119
|
+
...accumulation ? { accumulation } : {}
|
|
3465
4120
|
};
|
|
3466
|
-
const futureError = futureFactError(span.to, opts);
|
|
3467
|
-
if (futureError) {
|
|
3468
|
-
rejected.push({ record: r, errors: [futureError] });
|
|
3469
|
-
continue;
|
|
3470
|
-
}
|
|
3471
4121
|
accepted.push({
|
|
3472
|
-
eventId:
|
|
3473
|
-
eventType: ENERGY_EVENT.
|
|
3474
|
-
eventTime
|
|
4122
|
+
eventId: `${opts.tenantId}-generated-${++seq}`,
|
|
4123
|
+
eventType: ENERGY_EVENT.generated,
|
|
4124
|
+
eventTime,
|
|
3475
4125
|
tenantId: opts.tenantId,
|
|
3476
4126
|
data
|
|
3477
4127
|
});
|
|
3478
|
-
}
|
|
3479
|
-
return { accepted, rejected };
|
|
3480
|
-
}
|
|
3481
|
-
|
|
3482
|
-
// src/tariff.ts
|
|
3483
|
-
var TARIFF_LOAD_CLASSES = ["super-off-peak", "off-peak", "mid-peak", "on-peak"];
|
|
3484
|
-
var TARIFF_DAY_KINDS = ["all", "weekday", "saturday", "sunday", "holiday"];
|
|
3485
|
-
var CONCRETE_DAY_KINDS = ["weekday", "saturday", "sunday", "holiday"];
|
|
3486
|
-
var TARIFF_ISSUE_CODES = [
|
|
3487
|
-
/** A required field is empty. */
|
|
3488
|
-
"required",
|
|
3489
|
-
/** An amount is not a number. */
|
|
3490
|
-
"not-a-number",
|
|
3491
|
-
/** An amount is below zero. */
|
|
3492
|
-
"negative",
|
|
3493
|
-
/** A value is outside its vocabulary - `params.allowed`. */
|
|
3494
|
-
"not-in-vocabulary",
|
|
3495
|
-
/** A text is not in its format - `params.format`. */
|
|
3496
|
-
"format",
|
|
3497
|
-
/** An amount is written without a currency. */
|
|
3498
|
-
"currency-required",
|
|
3499
|
-
/** Season start and end must be written together or both left empty. */
|
|
3500
|
-
"season-pair",
|
|
3501
|
-
/** End time is not after the start - a band crossing midnight is two rows. */
|
|
3502
|
-
"end-not-after-start",
|
|
3503
|
-
/** The tariff has bands and a flat energy charge - which one prices an hour cannot be said. */
|
|
3504
|
-
"flat-and-bands",
|
|
3505
|
-
/** `params.count` bands break the row rules and were left out of the coverage check. */
|
|
3506
|
-
"broken-bands",
|
|
3507
|
-
/** No band covers `params.from`..`params.to` on `params.dayKind` days `params.days`. */
|
|
3508
|
-
"gap",
|
|
3509
|
-
/** Bands `params.bands` overlap `params.from`..`params.to` on `params.dayKind` days `params.days`. */
|
|
3510
|
-
"overlap"
|
|
3511
|
-
];
|
|
3512
|
-
function tariffIssueText(issue) {
|
|
3513
|
-
const p = issue.params ?? {};
|
|
3514
|
-
switch (issue.code) {
|
|
3515
|
-
case "required":
|
|
3516
|
-
return `${issue.field}: required${p.because ? ` (${p.because})` : ""}`;
|
|
3517
|
-
case "not-a-number":
|
|
3518
|
-
return `${issue.field}: not a number (${p.value})`;
|
|
3519
|
-
case "negative":
|
|
3520
|
-
return `${issue.field}: must be 0 or more (${p.value})`;
|
|
3521
|
-
case "not-in-vocabulary":
|
|
3522
|
-
return `${issue.field}: must be one of ${p.allowed} ("${p.value}")`;
|
|
3523
|
-
case "format":
|
|
3524
|
-
return `${issue.field}: must be ${p.format} ("${p.value}")`;
|
|
3525
|
-
case "currency-required":
|
|
3526
|
-
return `${issue.field}: required when an amount is written`;
|
|
3527
|
-
case "season-pair":
|
|
3528
|
-
return `${issue.field}: seasonFrom and seasonTo go together, or both empty for all year`;
|
|
3529
|
-
case "end-not-after-start":
|
|
3530
|
-
return `${issue.field}: must be after fromTime (${p.from}~${p.to}); a band crossing midnight is two rows`;
|
|
3531
|
-
case "flat-and-bands":
|
|
3532
|
-
return `${issue.field}: the tariff has bands - leave its flat charge empty`;
|
|
3533
|
-
case "broken-bands":
|
|
3534
|
-
return `${issue.field}: ${p.count} band(s) break the row rules and were left out`;
|
|
3535
|
-
case "gap":
|
|
3536
|
-
return `${issue.field}: ${p.dayKind} ${p.days} - no band ${p.from}~${p.to}`;
|
|
3537
|
-
case "overlap":
|
|
3538
|
-
return `${issue.field}: ${p.dayKind} ${p.days} - ${p.bands} overlap ${p.from}~${p.to}`;
|
|
3539
|
-
}
|
|
3540
|
-
}
|
|
3541
|
-
var empty = (v) => v === void 0 || v === null || typeof v === "string" && v.trim() === "";
|
|
3542
|
-
function isIso4217Code(value) {
|
|
3543
|
-
return typeof value === "string" && /^[A-Z]{3}$/.test(value);
|
|
3544
|
-
}
|
|
3545
|
-
function amountOf(v, field, issues) {
|
|
3546
|
-
if (empty(v)) return void 0;
|
|
3547
|
-
const n = Number(v);
|
|
3548
|
-
if (!Number.isFinite(n)) {
|
|
3549
|
-
issues.push({ field, code: "not-a-number", params: { value: String(v) } });
|
|
3550
|
-
return void 0;
|
|
3551
|
-
}
|
|
3552
|
-
if (n < 0) {
|
|
3553
|
-
issues.push({ field, code: "negative", params: { value: n } });
|
|
3554
|
-
return void 0;
|
|
3555
|
-
}
|
|
3556
|
-
return n;
|
|
3557
|
-
}
|
|
3558
|
-
function minutesOf(text) {
|
|
3559
|
-
const m = /^(\d{2}):(\d{2})$/.exec(String(text ?? "").trim());
|
|
3560
|
-
if (!m) return void 0;
|
|
3561
|
-
const h = Number(m[1]);
|
|
3562
|
-
const min = Number(m[2]);
|
|
3563
|
-
if (min > 59) return void 0;
|
|
3564
|
-
if (h === 24 && min === 0) return 1440;
|
|
3565
|
-
if (h > 23) return void 0;
|
|
3566
|
-
return h * 60 + min;
|
|
3567
|
-
}
|
|
3568
|
-
var DAYS_IN_MONTH = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
3569
|
-
function dayOfYearOf(text) {
|
|
3570
|
-
const m = /^(\d{2})-(\d{2})$/.exec(String(text ?? "").trim());
|
|
3571
|
-
if (!m) return void 0;
|
|
3572
|
-
const month = Number(m[1]);
|
|
3573
|
-
const day = Number(m[2]);
|
|
3574
|
-
if (month < 1 || month > 12 || day < 1 || day > DAYS_IN_MONTH[month - 1]) return void 0;
|
|
3575
|
-
let n = 0;
|
|
3576
|
-
for (let i = 0; i < month - 1; i++) n += DAYS_IN_MONTH[i];
|
|
3577
|
-
return n + day - 1;
|
|
3578
|
-
}
|
|
3579
|
-
function tariffIssues(row) {
|
|
3580
|
-
const issues = [];
|
|
3581
|
-
const d = amountOf(row.demandChargePerKW, "demandChargePerKW", issues);
|
|
3582
|
-
const e = amountOf(row.energyChargePerKWh, "energyChargePerKWh", issues);
|
|
3583
|
-
const currency = String(row.currency ?? "").trim();
|
|
3584
|
-
if ((d !== void 0 || e !== void 0) && !currency) issues.push({ field: "currency", code: "currency-required" });
|
|
3585
|
-
if (currency && !isIso4217Code(currency)) issues.push({ field: "currency", code: "format", params: { format: "ISO 4217 (KRW, USD)", value: currency } });
|
|
3586
|
-
return issues;
|
|
3587
|
-
}
|
|
3588
|
-
function tariffBandIssues(row) {
|
|
3589
|
-
const issues = [];
|
|
3590
|
-
if (empty(row.tariffName)) issues.push({ field: "tariffName", code: "required" });
|
|
3591
|
-
if (empty(row.band)) issues.push({ field: "band", code: "required" });
|
|
3592
|
-
const loadClass = String(row.loadClass ?? "").trim();
|
|
3593
|
-
if (!loadClass) issues.push({ field: "loadClass", code: "required" });
|
|
3594
|
-
else if (!TARIFF_LOAD_CLASSES.includes(loadClass)) {
|
|
3595
|
-
issues.push({ field: "loadClass", code: "not-in-vocabulary", params: { allowed: TARIFF_LOAD_CLASSES.join("|"), value: loadClass } });
|
|
3596
|
-
}
|
|
3597
|
-
const dayKind = empty(row.dayKind) ? "all" : String(row.dayKind).trim();
|
|
3598
|
-
if (!TARIFF_DAY_KINDS.includes(dayKind)) {
|
|
3599
|
-
issues.push({ field: "dayKind", code: "not-in-vocabulary", params: { allowed: TARIFF_DAY_KINDS.join("|"), value: dayKind } });
|
|
3600
|
-
}
|
|
3601
|
-
const sFromEmpty = empty(row.seasonFrom);
|
|
3602
|
-
const sToEmpty = empty(row.seasonTo);
|
|
3603
|
-
if (sFromEmpty !== sToEmpty) issues.push({ field: sFromEmpty ? "seasonFrom" : "seasonTo", code: "season-pair" });
|
|
3604
|
-
if (!sFromEmpty && dayOfYearOf(row.seasonFrom) === void 0) issues.push({ field: "seasonFrom", code: "format", params: { format: "MM-DD", value: String(row.seasonFrom) } });
|
|
3605
|
-
if (!sToEmpty && dayOfYearOf(row.seasonTo) === void 0) issues.push({ field: "seasonTo", code: "format", params: { format: "MM-DD", value: String(row.seasonTo) } });
|
|
3606
|
-
const from = minutesOf(row.fromTime);
|
|
3607
|
-
const to = minutesOf(row.toTime);
|
|
3608
|
-
if (from === void 0 || from === 1440) issues.push({ field: "fromTime", code: "format", params: { format: "HH:mm 00:00..23:59", value: String(row.fromTime ?? "") } });
|
|
3609
|
-
if (to === void 0 || to === 0) issues.push({ field: "toTime", code: "format", params: { format: "HH:mm 00:01..24:00", value: String(row.toTime ?? "") } });
|
|
3610
|
-
if (from !== void 0 && to !== void 0 && from < 1440 && to > 0 && from >= to) {
|
|
3611
|
-
issues.push({ field: "toTime", code: "end-not-after-start", params: { from: String(row.fromTime), to: String(row.toTime) } });
|
|
3612
|
-
}
|
|
3613
|
-
if (empty(row.energyChargePerKWh)) issues.push({ field: "energyChargePerKWh", code: "required" });
|
|
3614
|
-
else amountOf(row.energyChargePerKWh, "energyChargePerKWh", issues);
|
|
3615
|
-
amountOf(row.demandChargePerKW, "demandChargePerKW", issues);
|
|
3616
|
-
return issues;
|
|
3617
|
-
}
|
|
3618
|
-
function seasonHas(band, dayOfYear) {
|
|
3619
|
-
if (empty(band.seasonFrom) && empty(band.seasonTo)) return true;
|
|
3620
|
-
const from = dayOfYearOf(band.seasonFrom);
|
|
3621
|
-
const to = dayOfYearOf(band.seasonTo);
|
|
3622
|
-
if (from === void 0 || to === void 0) return false;
|
|
3623
|
-
return from <= to ? dayOfYear >= from && dayOfYear <= to : dayOfYear >= from || dayOfYear <= to;
|
|
3624
|
-
}
|
|
3625
|
-
function pricesHolidays(bands) {
|
|
3626
|
-
return bands.some((b) => String(b.dayKind ?? "").trim() === "holiday");
|
|
3627
|
-
}
|
|
3628
|
-
function dayKindOf(at2, holidays, isHoliday) {
|
|
3629
|
-
if (holidays && isHoliday?.(at2.month, at2.day)) return "holiday";
|
|
3630
|
-
return at2.weekday === 0 ? "sunday" : at2.weekday === 6 ? "saturday" : "weekday";
|
|
3631
|
-
}
|
|
3632
|
-
function dayKindHas(band, kind) {
|
|
3633
|
-
const k = empty(band.dayKind) ? "all" : String(band.dayKind).trim();
|
|
3634
|
-
return k === "all" || k === kind;
|
|
4128
|
+
}
|
|
4129
|
+
return { accepted, rejected };
|
|
3635
4130
|
}
|
|
3636
|
-
function
|
|
3637
|
-
|
|
4131
|
+
function isEnergyUsagePeriodRecord(record) {
|
|
4132
|
+
const r = record;
|
|
4133
|
+
return !!r && typeof r === "object" && r.meterId !== void 0 && r.from !== void 0 && r.to !== void 0 && r.kWh !== void 0;
|
|
3638
4134
|
}
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
return `${String(month + 1).padStart(2, "0")}-${String(rest + 1).padStart(2, "0")}`;
|
|
4135
|
+
function isEnergyGenerationPeriodRecord(record) {
|
|
4136
|
+
const r = record;
|
|
4137
|
+
if (!r || typeof r !== "object") return false;
|
|
4138
|
+
if (r.equipmentId === void 0 || r.from === void 0 || r.to === void 0) return false;
|
|
4139
|
+
return r.kWh !== void 0;
|
|
3645
4140
|
}
|
|
3646
|
-
function
|
|
3647
|
-
const
|
|
3648
|
-
|
|
3649
|
-
const
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
if (names) params.bands = names;
|
|
3666
|
-
seen.set(key, { problem: { field: "bands", code, params }, days: [day] });
|
|
4141
|
+
function ingestEnergyGenerationPeriodRecords(records, opts) {
|
|
4142
|
+
const list = records === void 0 || records === null ? [] : Array.isArray(records) ? records : [records];
|
|
4143
|
+
const accepted = [];
|
|
4144
|
+
const rejected = [];
|
|
4145
|
+
for (const r of list) {
|
|
4146
|
+
const errors = [];
|
|
4147
|
+
const equipmentId = String(r?.equipmentId ?? "").trim();
|
|
4148
|
+
if (!equipmentId) errors.push("equipmentId \uAC00 \uC5C6\uB2E4 \u2014 \uC5B4\uB290 \uC124\uBE44\uAC00 \uB0B8 \uAC83\uC778\uC9C0 \uC9C0\uC5B4\uB0BC \uC218 \uC5C6\uB2E4");
|
|
4149
|
+
const span = readSpan(r, errors);
|
|
4150
|
+
const kWh = readAmount(r?.kWh, "kWh", errors);
|
|
4151
|
+
if (kWh === void 0 && !errors.length) errors.push("kWh \uAC00 \uC5C6\uB2E4 \u2014 \uC774 \uBB38\uC774 \uBC1B\uB294 \uAC12\uC740 \uADF8 \uAE30\uAC04\uC758 \uBC1C\uC804\uB7C9\uC774\uB2E4");
|
|
4152
|
+
const ACCUMULATIONS = ["lifetime", "daily", "monthly", "billing", "unknown"];
|
|
4153
|
+
let accumulation;
|
|
4154
|
+
const rawAcc = r?.accumulation;
|
|
4155
|
+
if (rawAcc !== void 0 && rawAcc !== null && String(rawAcc).trim()) {
|
|
4156
|
+
const text = String(rawAcc).trim();
|
|
4157
|
+
if (!ACCUMULATIONS.includes(text)) {
|
|
4158
|
+
errors.push(`accumulation \uC774 \uC544\uB294 \uAC12\uC774 \uC544\uB2C8\uB2E4(${ACCUMULATIONS.join("\xB7")}): ${JSON.stringify(rawAcc)}`);
|
|
4159
|
+
} else accumulation = text;
|
|
3667
4160
|
}
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
for (const b of today) {
|
|
3675
|
-
if (b.from > cursor) note(kind, day, "gap", cursor, b.from);
|
|
3676
|
-
if (last && b.from < last.to) note(kind, day, "overlap", b.from, Math.min(last.to, b.to), `${last.name}\xB7${b.name}`);
|
|
3677
|
-
if (b.to > cursor) {
|
|
3678
|
-
cursor = b.to;
|
|
3679
|
-
last = b;
|
|
3680
|
-
}
|
|
4161
|
+
const readAt = (raw, name) => {
|
|
4162
|
+
if (raw === void 0 || raw === null || !String(raw).trim()) return void 0;
|
|
4163
|
+
const text = String(raw).trim();
|
|
4164
|
+
if (!Number.isFinite(Date.parse(text))) {
|
|
4165
|
+
errors.push(`${name} \uB97C \uC2DC\uAC01\uC73C\uB85C \uC77D\uC744 \uC218 \uC5C6\uB2E4: ${JSON.stringify(raw)}`);
|
|
4166
|
+
return void 0;
|
|
3681
4167
|
}
|
|
3682
|
-
|
|
4168
|
+
return text;
|
|
4169
|
+
};
|
|
4170
|
+
const observedFrom = readAt(r?.observedFrom, "observedFrom");
|
|
4171
|
+
const observedTo = readAt(r?.observedTo, "observedTo");
|
|
4172
|
+
if (errors.length || !span || kWh === void 0) {
|
|
4173
|
+
rejected.push({ record: r, errors });
|
|
4174
|
+
continue;
|
|
3683
4175
|
}
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
4176
|
+
const data = {
|
|
4177
|
+
equipmentId,
|
|
4178
|
+
kWh,
|
|
4179
|
+
periodStart: span.from,
|
|
4180
|
+
periodEnd: span.to,
|
|
4181
|
+
/* 관측 구간을 말하지 않으면 기간 전체를 잰 것으로 둔다 — 지난 기록은 그 원본이 하루를 마감해 준 값이다. */
|
|
4182
|
+
observedFrom: observedFrom ?? span.from,
|
|
4183
|
+
observedTo: observedTo ?? span.to,
|
|
4184
|
+
accumulation: accumulation ?? "daily",
|
|
4185
|
+
/* 밖에서 마감되어 온 것이다 — 우리가 시각 기준으로 닫은 것이 아니다. */
|
|
4186
|
+
boundary: "declared"
|
|
4187
|
+
};
|
|
4188
|
+
const subj = resolveSubject("equipment", equipmentId, opts);
|
|
4189
|
+
data.subject = subj.subject;
|
|
4190
|
+
data.subjectBasis = subj.basis;
|
|
4191
|
+
const futureError = futureFactError(span.to, opts);
|
|
4192
|
+
if (futureError) {
|
|
4193
|
+
rejected.push({ record: r, errors: [futureError] });
|
|
4194
|
+
continue;
|
|
3696
4195
|
}
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
if (!usable.length) {
|
|
3705
|
-
const flat = empty(tariff.energyChargePerKWh) ? NaN : Number(tariff.energyChargePerKWh);
|
|
3706
|
-
if (!Number.isFinite(flat)) return { reason: "no-price" };
|
|
3707
|
-
return { energyChargePerKWh: flat, ...currency ? { currency } : {}, holidayKnown: true };
|
|
4196
|
+
accepted.push({
|
|
4197
|
+
eventId: periodFactId(opts.tenantId, ENERGY_EVENT.generationPeriod, subj.subject, span.from, span.to),
|
|
4198
|
+
eventType: ENERGY_EVENT.generationPeriod,
|
|
4199
|
+
eventTime: span.to,
|
|
4200
|
+
tenantId: opts.tenantId,
|
|
4201
|
+
data
|
|
4202
|
+
});
|
|
3708
4203
|
}
|
|
3709
|
-
|
|
3710
|
-
if (day === void 0) return { reason: "no-band" };
|
|
3711
|
-
const holidays = pricesHolidays(usable);
|
|
3712
|
-
const kind = dayKindOf(at2, holidays, isHoliday);
|
|
3713
|
-
const hits = usable.filter(
|
|
3714
|
-
(b) => seasonHas(b, day) && dayKindHas(b, kind) && minutesOf(b.fromTime) <= at2.minutes && at2.minutes < minutesOf(b.toTime)
|
|
3715
|
-
);
|
|
3716
|
-
if (!hits.length) return { reason: "no-band" };
|
|
3717
|
-
if (hits.length > 1) return { reason: "ambiguous", bands: hits.map((b) => String(b.name ?? "")) };
|
|
3718
|
-
const hit = hits[0];
|
|
3719
|
-
const demand = empty(hit.demandChargePerKW) ? void 0 : Number(hit.demandChargePerKW);
|
|
3720
|
-
return {
|
|
3721
|
-
bandName: String(hit.name ?? "") || void 0,
|
|
3722
|
-
band: String(hit.band).trim(),
|
|
3723
|
-
loadClass: String(hit.loadClass).trim(),
|
|
3724
|
-
energyChargePerKWh: Number(hit.energyChargePerKWh),
|
|
3725
|
-
...demand !== void 0 ? { demandChargePerKW: demand } : {},
|
|
3726
|
-
...currency ? { currency } : {},
|
|
3727
|
-
holidayKnown: !holidays || !!isHoliday
|
|
3728
|
-
};
|
|
3729
|
-
}
|
|
3730
|
-
|
|
3731
|
-
// src/gs1.ts
|
|
3732
|
-
var FNC1 = "";
|
|
3733
|
-
var FIXED_LENGTH = {
|
|
3734
|
-
"00": 18,
|
|
3735
|
-
// SSCC
|
|
3736
|
-
"01": 14,
|
|
3737
|
-
// GTIN
|
|
3738
|
-
"02": 14,
|
|
3739
|
-
// 포장 안 품목의 GTIN
|
|
3740
|
-
"11": 6,
|
|
3741
|
-
// 생산일
|
|
3742
|
-
"12": 6,
|
|
3743
|
-
// 지급기일
|
|
3744
|
-
"13": 6,
|
|
3745
|
-
// 포장일
|
|
3746
|
-
"15": 6,
|
|
3747
|
-
// 품질 유지 기한
|
|
3748
|
-
"16": 6,
|
|
3749
|
-
// 판매기한
|
|
3750
|
-
"17": 6,
|
|
3751
|
-
// 사용기한
|
|
3752
|
-
"20": 2,
|
|
3753
|
-
// 제품 변형
|
|
3754
|
-
"414": 13
|
|
3755
|
-
// 물리적 위치의 GLN
|
|
3756
|
-
};
|
|
3757
|
-
var KNOWN_VARIABLE = ["10", "21", "30", "254"];
|
|
3758
|
-
function isBracketed(value) {
|
|
3759
|
-
return /^\(\d{2,4}\)/.test(value);
|
|
4204
|
+
return { accepted, rejected };
|
|
3760
4205
|
}
|
|
3761
|
-
function
|
|
3762
|
-
const
|
|
3763
|
-
if (!
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
if (!parsed.ok) {
|
|
3768
|
-
return parsed;
|
|
3769
|
-
}
|
|
3770
|
-
const found = parsed.elements;
|
|
3771
|
-
const count = found["30"] !== void 0 ? Number(found["30"]) : void 0;
|
|
3772
|
-
return {
|
|
3773
|
-
ok: true,
|
|
3774
|
-
scan: {
|
|
3775
|
-
sscc: found["00"],
|
|
3776
|
-
gln: found["414"],
|
|
3777
|
-
glnExtension: found["254"],
|
|
3778
|
-
gtin: found["01"],
|
|
3779
|
-
lot: found["10"],
|
|
3780
|
-
serial: found["21"],
|
|
3781
|
-
useBy: found["17"],
|
|
3782
|
-
/* 숫자가 아니면 담지 않는다 — `NaN` 을 수량으로 두면 더하는 쪽에서 합계가 통째로 사라진다. */
|
|
3783
|
-
count: count !== void 0 && Number.isFinite(count) ? count : void 0,
|
|
3784
|
-
elements: found,
|
|
3785
|
-
raw
|
|
3786
|
-
}
|
|
3787
|
-
};
|
|
4206
|
+
function isEnergyGenerationPriceRecord(record) {
|
|
4207
|
+
const r = record;
|
|
4208
|
+
if (!r || typeof r !== "object") return false;
|
|
4209
|
+
if (r.from === void 0 || r.to === void 0) return false;
|
|
4210
|
+
if (r.meterId !== void 0 || r.equipmentId !== void 0) return false;
|
|
4211
|
+
return r.unitPrice !== void 0;
|
|
3788
4212
|
}
|
|
3789
|
-
function
|
|
3790
|
-
const
|
|
3791
|
-
const
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
const
|
|
3796
|
-
const
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
|
|
4213
|
+
function ingestEnergyGenerationPriceRecords(records, opts) {
|
|
4214
|
+
const list = records === void 0 || records === null ? [] : Array.isArray(records) ? records : [records];
|
|
4215
|
+
const accepted = [];
|
|
4216
|
+
const rejected = [];
|
|
4217
|
+
for (const r of list) {
|
|
4218
|
+
const errors = [];
|
|
4219
|
+
const span = readSpan(r, errors);
|
|
4220
|
+
const unitPrice = readAmount(r?.unitPrice, "unitPrice", errors);
|
|
4221
|
+
if (unitPrice === void 0 && !errors.length) errors.push("unitPrice \uAC00 \uC5C6\uB2E4 \u2014 \uC774 \uBB38\uC774 \uBC1B\uB294 \uAC12\uC740 1kWh \uB2F9 \uAC12 \uD558\uB098\uB2E4");
|
|
4222
|
+
const currency = String(r?.currency ?? "").trim();
|
|
4223
|
+
if (!currency) errors.push("currency \uAC00 \uC5C6\uB2E4 \u2014 \uB2E8\uC704 \uC5C6\uB294 \uAC12\uC740 \uB2E4\uB978 \uAE08\uC561\uACFC \uB354\uD560 \uC218 \uC5C6\uB2E4");
|
|
4224
|
+
if (errors.length || !span || unitPrice === void 0) {
|
|
4225
|
+
rejected.push({ record: r, errors });
|
|
4226
|
+
continue;
|
|
3800
4227
|
}
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
4228
|
+
const data = { from: span.from, to: span.to, unitPrice, currency };
|
|
4229
|
+
accepted.push({
|
|
4230
|
+
eventId: periodFactId(opts.tenantId, ENERGY_EVENT.generationPrice, "", span.from, span.to),
|
|
4231
|
+
eventType: ENERGY_EVENT.generationPrice,
|
|
4232
|
+
eventTime: span.from,
|
|
4233
|
+
tenantId: opts.tenantId,
|
|
4234
|
+
data
|
|
4235
|
+
});
|
|
3806
4236
|
}
|
|
3807
|
-
return {
|
|
4237
|
+
return { accepted, rejected };
|
|
3808
4238
|
}
|
|
3809
|
-
function
|
|
3810
|
-
const
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
4239
|
+
function isEnergyTariffBasisRecord(record) {
|
|
4240
|
+
const r = record;
|
|
4241
|
+
if (!r || typeof r !== "object") return false;
|
|
4242
|
+
if (r.from === void 0 || r.to === void 0) return false;
|
|
4243
|
+
if (r.energyCharge !== void 0 || r.demandCharge !== void 0 || r.total !== void 0) return false;
|
|
4244
|
+
return r.billingDemandKW !== void 0 || r.demandChargePerKW !== void 0;
|
|
4245
|
+
}
|
|
4246
|
+
function ingestEnergyTariffBasisRecords(records, opts) {
|
|
4247
|
+
const list = records === void 0 || records === null ? [] : Array.isArray(records) ? records : [records];
|
|
4248
|
+
const accepted = [];
|
|
4249
|
+
const rejected = [];
|
|
4250
|
+
for (const r of list) {
|
|
4251
|
+
const errors = [];
|
|
4252
|
+
const span = readSpan(r, errors);
|
|
4253
|
+
const billingDemandKW = readAmount(r?.billingDemandKW, "billingDemandKW", errors);
|
|
4254
|
+
const demandChargePerKW = readAmount(r?.demandChargePerKW, "demandChargePerKW", errors);
|
|
4255
|
+
if (billingDemandKW === void 0 && demandChargePerKW === void 0) {
|
|
4256
|
+
errors.push("\uC694\uAE08 \uAE30\uC900\uC774 \uD558\uB098\uB3C4 \uC5C6\uB2E4 \u2014 \uC801\uC744 \uC0AC\uC2E4\uC774 \uC5C6\uB294 \uAE30\uC900\uC740 \uBC1B\uC9C0 \uC54A\uB294\uB2E4");
|
|
3816
4257
|
}
|
|
3817
|
-
const
|
|
3818
|
-
if (!
|
|
3819
|
-
|
|
4258
|
+
const currency = String(r?.currency ?? "").trim() || void 0;
|
|
4259
|
+
if (demandChargePerKW !== void 0 && !currency) errors.push("demandChargePerKW \uB97C \uC2E4\uC5C8\uB294\uB370 currency \uAC00 \uC5C6\uB2E4");
|
|
4260
|
+
if (r?.demandCharge !== void 0 || r?.total !== void 0) {
|
|
4261
|
+
errors.push("\uAE08\uC561(demandCharge\xB7total)\uC740 \uC774 \uBB38\uC774 \uBC1B\uC9C0 \uC54A\uB294\uB2E4 \u2014 \uC815\uC0B0 \uAE08\uC561\uC740 \uCCAD\uAD6C\uC11C \uBB38\uC73C\uB85C \uBCF4\uB0B8\uB2E4");
|
|
3820
4262
|
}
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
if (fixed !== void 0) {
|
|
3824
|
-
if (rest.length < fixed) {
|
|
3825
|
-
return { ok: false, because: "truncated", raw };
|
|
3826
|
-
}
|
|
3827
|
-
const value = rest.slice(0, fixed);
|
|
3828
|
-
if (value.includes(FNC1)) {
|
|
3829
|
-
return { ok: false, because: "truncated", raw };
|
|
3830
|
-
}
|
|
3831
|
-
elements[ai] = value;
|
|
3832
|
-
rest = rest.slice(fixed);
|
|
4263
|
+
if (errors.length || !span) {
|
|
4264
|
+
rejected.push({ record: r, errors });
|
|
3833
4265
|
continue;
|
|
3834
4266
|
}
|
|
3835
|
-
const
|
|
3836
|
-
|
|
3837
|
-
|
|
4267
|
+
const data = {
|
|
4268
|
+
from: span.from,
|
|
4269
|
+
to: span.to,
|
|
4270
|
+
...billingDemandKW !== void 0 ? { billingDemandKW } : {},
|
|
4271
|
+
...demandChargePerKW !== void 0 ? { demandChargePerKW } : {},
|
|
4272
|
+
...currency ? { currency } : {}
|
|
4273
|
+
};
|
|
4274
|
+
accepted.push({
|
|
4275
|
+
eventId: periodFactId(opts.tenantId, ENERGY_EVENT.tariffBasis, "", span.from, span.to),
|
|
4276
|
+
eventType: ENERGY_EVENT.tariffBasis,
|
|
4277
|
+
/* **시작 시각**이다 — 그때부터 유효하다(§ 위 주석). */
|
|
4278
|
+
eventTime: span.from,
|
|
4279
|
+
tenantId: opts.tenantId,
|
|
4280
|
+
data
|
|
4281
|
+
});
|
|
3838
4282
|
}
|
|
3839
|
-
return
|
|
4283
|
+
return { accepted, rejected };
|
|
3840
4284
|
}
|
|
3841
|
-
function
|
|
3842
|
-
const
|
|
3843
|
-
if (
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
if (FIXED_LENGTH[two] !== void 0 || KNOWN_VARIABLE.includes(two)) {
|
|
3847
|
-
return two;
|
|
3848
|
-
}
|
|
3849
|
-
const three = rest.slice(0, 3);
|
|
3850
|
-
if (/^\d{3}$/.test(three) && (FIXED_LENGTH[three] !== void 0 || KNOWN_VARIABLE.includes(three))) {
|
|
3851
|
-
return three;
|
|
3852
|
-
}
|
|
3853
|
-
const four = rest.slice(0, 4);
|
|
3854
|
-
return /^\d{4}$/.test(four) ? four : two;
|
|
4285
|
+
function isEnergyBillRecord(record) {
|
|
4286
|
+
const r = record;
|
|
4287
|
+
if (!r || typeof r !== "object") return false;
|
|
4288
|
+
if (r.from === void 0 || r.to === void 0) return false;
|
|
4289
|
+
return r.energyCharge !== void 0 || r.demandCharge !== void 0 || r.total !== void 0;
|
|
3855
4290
|
}
|
|
3856
|
-
function
|
|
3857
|
-
const
|
|
3858
|
-
|
|
4291
|
+
function futureFactError(eventTime, opts) {
|
|
4292
|
+
const nowText = opts.nowISO ?? opts.defaultEventTime;
|
|
4293
|
+
if (!nowText) return void 0;
|
|
4294
|
+
const nowMs = Date.parse(nowText);
|
|
4295
|
+
const atMs = Date.parse(eventTime);
|
|
4296
|
+
if (!Number.isFinite(nowMs) || !Number.isFinite(atMs) || atMs <= nowMs) return void 0;
|
|
4297
|
+
return `\uC544\uC9C1 \uC624\uC9C0 \uC54A\uC740 \uC2DC\uAC01\uC758 \uC0AC\uC2E4\uC774\uB2E4(${eventTime}) \u2014 \uB05D\uB098\uC9C0 \uC54A\uC740 \uAE30\uAC04\uC740 \uB9C8\uAC10\uB41C \uC0AC\uC2E4\uC774 \uC544\uB2C8\uB2E4`;
|
|
3859
4298
|
}
|
|
3860
|
-
function
|
|
3861
|
-
|
|
4299
|
+
function resolveSubject(kind, localId, opts) {
|
|
4300
|
+
const declared = opts.identityOf?.(kind, localId);
|
|
4301
|
+
if (declared) return { subject: declared, basis: "declared" };
|
|
4302
|
+
return { subject: opts.scopeId ? `${opts.scopeId}/${localId}` : localId, basis: "twin-local" };
|
|
3862
4303
|
}
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
4304
|
+
function periodFactId(tenantId, kind, subject, from, to) {
|
|
4305
|
+
return [tenantId, kind, subject, from, to].join("|");
|
|
4306
|
+
}
|
|
4307
|
+
function readSpan(r, errors) {
|
|
4308
|
+
const from = String(r?.from ?? "").trim();
|
|
4309
|
+
const to = String(r?.to ?? "").trim();
|
|
4310
|
+
const fromMs = Date.parse(from);
|
|
4311
|
+
const toMs = Date.parse(to);
|
|
4312
|
+
if (!from || !Number.isFinite(fromMs)) errors.push(`from \uC744 \uC2DC\uAC01\uC73C\uB85C \uC77D\uC744 \uC218 \uC5C6\uB2E4: ${JSON.stringify(r?.from)}`);
|
|
4313
|
+
if (!to || !Number.isFinite(toMs)) errors.push(`to \uB97C \uC2DC\uAC01\uC73C\uB85C \uC77D\uC744 \uC218 \uC5C6\uB2E4: ${JSON.stringify(r?.to)}`);
|
|
4314
|
+
if (Number.isFinite(fromMs) && Number.isFinite(toMs) && !(toMs > fromMs)) {
|
|
4315
|
+
errors.push(`\uAD6C\uAC04\uC774 \uB4A4\uC9D1\uD614\uAC70\uB098 \uAE38\uC774\uAC00 \uC5C6\uB2E4(${from} \u2192 ${to}) \u2014 \uC5B4\uB290 \uCABD\uC774 \uD2C0\uB838\uB294\uC9C0 \uC6B0\uB9AC\uAC00 \uC815\uD560 \uC218 \uC5C6\uB2E4`);
|
|
3869
4316
|
}
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
}
|
|
4317
|
+
return errors.length ? void 0 : { from, to };
|
|
4318
|
+
}
|
|
4319
|
+
function readAmount(raw, name, errors) {
|
|
4320
|
+
if (raw === void 0 || raw === null || String(raw).trim() === "") return void 0;
|
|
4321
|
+
const v = Number(raw);
|
|
4322
|
+
if (!Number.isFinite(v)) {
|
|
4323
|
+
errors.push(`${name} \uB97C \uC218\uB85C \uC77D\uC744 \uC218 \uC5C6\uB2E4: ${JSON.stringify(raw)}`);
|
|
4324
|
+
return void 0;
|
|
3877
4325
|
}
|
|
3878
|
-
if (
|
|
3879
|
-
|
|
3880
|
-
|
|
4326
|
+
if (v < 0) {
|
|
4327
|
+
errors.push(`${name} \uAC00 \uC74C\uC218\uB2E4(${v})`);
|
|
4328
|
+
return void 0;
|
|
3881
4329
|
}
|
|
3882
|
-
return
|
|
4330
|
+
return v;
|
|
3883
4331
|
}
|
|
3884
|
-
function
|
|
3885
|
-
const
|
|
3886
|
-
|
|
3887
|
-
const
|
|
3888
|
-
const
|
|
3889
|
-
|
|
3890
|
-
|
|
4332
|
+
function ingestEnergyUsagePeriodRecords(records, opts) {
|
|
4333
|
+
const list = records === void 0 || records === null ? [] : Array.isArray(records) ? records : [records];
|
|
4334
|
+
const accepted = [];
|
|
4335
|
+
const rejected = [];
|
|
4336
|
+
for (const r of list) {
|
|
4337
|
+
const errors = [];
|
|
4338
|
+
const meterId = String(r?.meterId ?? "").trim();
|
|
4339
|
+
if (!meterId) errors.push("meterId \uAC00 \uC5C6\uB2E4 \u2014 \uC5B4\uB290 \uC9C0\uC810\uC774 \uC4F4 \uAC83\uC778\uC9C0 \uC9C0\uC5B4\uB0BC \uC218 \uC5C6\uB2E4");
|
|
4340
|
+
const span = readSpan(r, errors);
|
|
4341
|
+
const rawKWh = r?.kWh;
|
|
4342
|
+
let kWh;
|
|
4343
|
+
if (rawKWh === void 0 || rawKWh === null || String(rawKWh).trim() === "") {
|
|
4344
|
+
errors.push("kWh \uAC00 \uC5C6\uB2E4 \u2014 \uC774 \uBB38\uC774 \uBC1B\uB294 \uAC12\uC740 \uADF8 \uAD6C\uAC04\uC5D0 \uC4F4 \uC591\uC774\uB2E4");
|
|
4345
|
+
} else {
|
|
4346
|
+
kWh = readAmount(rawKWh, "kWh", errors);
|
|
4347
|
+
}
|
|
4348
|
+
const maxKW = readAmount(r?.maxKW, "maxKW", errors);
|
|
4349
|
+
const unitPrice = readAmount(r?.unitPrice, "unitPrice", errors);
|
|
4350
|
+
const currency = String(r?.currency ?? "").trim() || void 0;
|
|
4351
|
+
if (unitPrice !== void 0 && !currency) errors.push("unitPrice \uB97C \uC2E4\uC5C8\uB294\uB370 currency \uAC00 \uC5C6\uB2E4 \u2014 \uB2E8\uC704 \uC5C6\uB294 \uAE08\uC561\uC740 \uB354\uD560 \uC218 \uC5C6\uB2E4");
|
|
4352
|
+
let basis;
|
|
4353
|
+
const rawBasis = r?.basis;
|
|
4354
|
+
if (rawBasis !== void 0 && rawBasis !== null && String(rawBasis).trim()) {
|
|
4355
|
+
const text = String(rawBasis).trim();
|
|
4356
|
+
if (!OBSERVATION_BASIS.includes(text)) {
|
|
4357
|
+
errors.push(`basis \uAC00 \uC544\uB294 \uAC12\uC774 \uC544\uB2C8\uB2E4(${OBSERVATION_BASIS.join("\xB7")}): ${JSON.stringify(rawBasis)}`);
|
|
4358
|
+
} else basis = text;
|
|
4359
|
+
}
|
|
4360
|
+
if (errors.length || !span || kWh === void 0) {
|
|
4361
|
+
rejected.push({ record: r, errors });
|
|
4362
|
+
continue;
|
|
4363
|
+
}
|
|
4364
|
+
const subj = resolveSubject("meter", meterId, opts);
|
|
4365
|
+
const data = {
|
|
4366
|
+
meterId,
|
|
4367
|
+
subject: subj.subject,
|
|
4368
|
+
subjectBasis: subj.basis,
|
|
4369
|
+
from: span.from,
|
|
4370
|
+
to: span.to,
|
|
4371
|
+
kWh,
|
|
4372
|
+
...maxKW !== void 0 ? { maxKW } : {},
|
|
4373
|
+
...unitPrice !== void 0 ? { unitPrice } : {},
|
|
4374
|
+
...currency ? { currency } : {},
|
|
4375
|
+
...basis ? { basis } : {}
|
|
4376
|
+
};
|
|
4377
|
+
const futureError = futureFactError(span.to, opts);
|
|
4378
|
+
if (futureError) {
|
|
4379
|
+
rejected.push({ record: r, errors: [futureError] });
|
|
4380
|
+
continue;
|
|
4381
|
+
}
|
|
4382
|
+
accepted.push({
|
|
4383
|
+
eventId: periodFactId(opts.tenantId, ENERGY_EVENT.usagePeriod, subj.subject, span.from, span.to),
|
|
4384
|
+
eventType: ENERGY_EVENT.usagePeriod,
|
|
4385
|
+
/* 구간의 **끝**이 이 사실이 성립한 시각이다 — 시작으로 달면 저널이 그 구간을 미리 안 것이 된다. */
|
|
4386
|
+
eventTime: span.to,
|
|
4387
|
+
tenantId: opts.tenantId,
|
|
4388
|
+
data
|
|
4389
|
+
});
|
|
4390
|
+
}
|
|
4391
|
+
return { accepted, rejected };
|
|
4392
|
+
}
|
|
4393
|
+
function ingestEnergyBillRecords(records, opts) {
|
|
4394
|
+
const list = records === void 0 || records === null ? [] : Array.isArray(records) ? records : [records];
|
|
4395
|
+
const accepted = [];
|
|
4396
|
+
const rejected = [];
|
|
4397
|
+
for (const r of list) {
|
|
4398
|
+
const errors = [];
|
|
4399
|
+
const span = readSpan(r, errors);
|
|
4400
|
+
const energyCharge = readAmount(r?.energyCharge, "energyCharge", errors);
|
|
4401
|
+
const demandCharge = readAmount(r?.demandCharge, "demandCharge", errors);
|
|
4402
|
+
const total = readAmount(r?.total, "total", errors);
|
|
4403
|
+
const billingDemandKW = readAmount(r?.billingDemandKW, "billingDemandKW", errors);
|
|
4404
|
+
if (energyCharge === void 0 && demandCharge === void 0 && total === void 0) {
|
|
4405
|
+
errors.push("\uAE08\uC561\uC774 \uD558\uB098\uB3C4 \uC5C6\uB2E4 \u2014 \uC801\uC744 \uC0AC\uC2E4\uC774 \uC5C6\uB294 \uCCAD\uAD6C\uC11C\uB294 \uBC1B\uC9C0 \uC54A\uB294\uB2E4");
|
|
4406
|
+
}
|
|
4407
|
+
const currency = String(r?.currency ?? "").trim() || void 0;
|
|
4408
|
+
if (!currency) errors.push("currency \uAC00 \uC5C6\uB2E4 \u2014 \uB2E8\uC704 \uC5C6\uB294 \uAE08\uC561\uC740 \uB2E4\uB978 \uAE08\uC561\uACFC \uB354\uD560 \uC218 \uC5C6\uB2E4");
|
|
4409
|
+
if (errors.length || !span) {
|
|
4410
|
+
rejected.push({ record: r, errors });
|
|
4411
|
+
continue;
|
|
4412
|
+
}
|
|
4413
|
+
const data = {
|
|
4414
|
+
from: span.from,
|
|
4415
|
+
to: span.to,
|
|
4416
|
+
...energyCharge !== void 0 ? { energyCharge } : {},
|
|
4417
|
+
...demandCharge !== void 0 ? { demandCharge } : {},
|
|
4418
|
+
...total !== void 0 ? { total } : {},
|
|
4419
|
+
...currency ? { currency } : {},
|
|
4420
|
+
...billingDemandKW !== void 0 ? { billingDemandKW } : {}
|
|
4421
|
+
};
|
|
4422
|
+
const futureError = futureFactError(span.to, opts);
|
|
4423
|
+
if (futureError) {
|
|
4424
|
+
rejected.push({ record: r, errors: [futureError] });
|
|
4425
|
+
continue;
|
|
4426
|
+
}
|
|
4427
|
+
accepted.push({
|
|
4428
|
+
eventId: periodFactId(opts.tenantId, ENERGY_EVENT.bill, "", span.from, span.to),
|
|
4429
|
+
eventType: ENERGY_EVENT.bill,
|
|
4430
|
+
eventTime: span.to,
|
|
4431
|
+
tenantId: opts.tenantId,
|
|
4432
|
+
data
|
|
4433
|
+
});
|
|
4434
|
+
}
|
|
4435
|
+
return { accepted, rejected };
|
|
3891
4436
|
}
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
4437
|
+
|
|
4438
|
+
// src/tariff.ts
|
|
4439
|
+
var TARIFF_LOAD_CLASSES = ["super-off-peak", "off-peak", "mid-peak", "on-peak"];
|
|
4440
|
+
var TARIFF_DAY_KINDS = ["all", "weekday", "saturday", "sunday", "holiday"];
|
|
4441
|
+
var CONCRETE_DAY_KINDS = ["weekday", "saturday", "sunday", "holiday"];
|
|
4442
|
+
var TARIFF_ISSUE_CODES = [
|
|
4443
|
+
/** A required field is empty. */
|
|
4444
|
+
"required",
|
|
4445
|
+
/** An amount is not a number. */
|
|
4446
|
+
"not-a-number",
|
|
4447
|
+
/** An amount is below zero. */
|
|
4448
|
+
"negative",
|
|
4449
|
+
/** A value is outside its vocabulary - `params.allowed`. */
|
|
4450
|
+
"not-in-vocabulary",
|
|
4451
|
+
/** A text is not in its format - `params.format`. */
|
|
4452
|
+
"format",
|
|
4453
|
+
/** An amount is written without a currency. */
|
|
4454
|
+
"currency-required",
|
|
4455
|
+
/** Season start and end must be written together or both left empty. */
|
|
4456
|
+
"season-pair",
|
|
4457
|
+
/** End time is not after the start - a band crossing midnight is two rows. */
|
|
4458
|
+
"end-not-after-start",
|
|
4459
|
+
/** The tariff has bands and a flat energy charge - which one prices an hour cannot be said. */
|
|
4460
|
+
"flat-and-bands",
|
|
4461
|
+
/** `params.count` bands break the row rules and were left out of the coverage check. */
|
|
4462
|
+
"broken-bands",
|
|
4463
|
+
/** No band covers `params.from`..`params.to` on `params.dayKind` days `params.days`. */
|
|
4464
|
+
"gap",
|
|
4465
|
+
/** Bands `params.bands` overlap `params.from`..`params.to` on `params.dayKind` days `params.days`. */
|
|
4466
|
+
"overlap"
|
|
4467
|
+
];
|
|
4468
|
+
function tariffIssueText(issue) {
|
|
4469
|
+
const p = issue.params ?? {};
|
|
4470
|
+
switch (issue.code) {
|
|
4471
|
+
case "required":
|
|
4472
|
+
return `${issue.field}: required${p.because ? ` (${p.because})` : ""}`;
|
|
4473
|
+
case "not-a-number":
|
|
4474
|
+
return `${issue.field}: not a number (${p.value})`;
|
|
4475
|
+
case "negative":
|
|
4476
|
+
return `${issue.field}: must be 0 or more (${p.value})`;
|
|
4477
|
+
case "not-in-vocabulary":
|
|
4478
|
+
return `${issue.field}: must be one of ${p.allowed} ("${p.value}")`;
|
|
4479
|
+
case "format":
|
|
4480
|
+
return `${issue.field}: must be ${p.format} ("${p.value}")`;
|
|
4481
|
+
case "currency-required":
|
|
4482
|
+
return `${issue.field}: required when an amount is written`;
|
|
4483
|
+
case "season-pair":
|
|
4484
|
+
return `${issue.field}: seasonFrom and seasonTo go together, or both empty for all year`;
|
|
4485
|
+
case "end-not-after-start":
|
|
4486
|
+
return `${issue.field}: must be after fromTime (${p.from}~${p.to}); a band crossing midnight is two rows`;
|
|
4487
|
+
case "flat-and-bands":
|
|
4488
|
+
return `${issue.field}: the tariff has bands - leave its flat charge empty`;
|
|
4489
|
+
case "broken-bands":
|
|
4490
|
+
return `${issue.field}: ${p.count} band(s) break the row rules and were left out`;
|
|
4491
|
+
case "gap":
|
|
4492
|
+
return `${issue.field}: ${p.dayKind} ${p.days} - no band ${p.from}~${p.to}`;
|
|
4493
|
+
case "overlap":
|
|
4494
|
+
return `${issue.field}: ${p.dayKind} ${p.days} - ${p.bands} overlap ${p.from}~${p.to}`;
|
|
4495
|
+
}
|
|
3899
4496
|
}
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
return /^(\d{8}|\d{12,14})$/.test(definitionId ?? "") ? definitionId.padStart(14, "0") : void 0;
|
|
4497
|
+
var empty = (v) => v === void 0 || v === null || typeof v === "string" && v.trim() === "";
|
|
4498
|
+
function isIso4217Code(value) {
|
|
4499
|
+
return typeof value === "string" && /^[A-Z]{3}$/.test(value);
|
|
3904
4500
|
}
|
|
3905
|
-
function
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
if (!gtin) return raw;
|
|
3912
|
-
if (parsed.scheme === "sgtin") return parsed.serial ? `(01)${gtin}(21)${decoded(parsed.serial)}` : raw;
|
|
3913
|
-
if (parsed.scheme === "lgtin") return parsed.lot ? `(01)${gtin}(10)${parsed.lot}` : raw;
|
|
3914
|
-
return `(01)${gtin}`;
|
|
3915
|
-
}
|
|
3916
|
-
if (parsed.scheme === "sscc") {
|
|
3917
|
-
const sscc = ssccDigitsOf(raw);
|
|
3918
|
-
return sscc ? `(00)${sscc}` : raw;
|
|
3919
|
-
}
|
|
3920
|
-
if (parsed.scheme === "sgln") {
|
|
3921
|
-
const m = /^urn:epc:id:sgln:(\d+)\.(\d*)\.(.+)$/.exec(raw);
|
|
3922
|
-
if (!m || m[1].length + m[2].length !== 12) return raw;
|
|
3923
|
-
const body = m[1] + m[2];
|
|
3924
|
-
return `(414)${body}${checkDigitOf(body)}${m[3] === "0" ? "" : `(254)${decoded(m[3])}`}`;
|
|
3925
|
-
}
|
|
3926
|
-
if (parsed.scheme === "grai" || parsed.scheme === "gdti") {
|
|
3927
|
-
const m = new RegExp(`^urn:epc:id:${parsed.scheme}:(\\d+)\\.(\\d*)\\.(.*)$`).exec(raw);
|
|
3928
|
-
if (!m || m[1].length + m[2].length !== 12) return raw;
|
|
3929
|
-
const key = m[1] + m[2] + checkDigitOf(m[1] + m[2]);
|
|
3930
|
-
return parsed.scheme === "grai" ? `(8003)0${key}${decoded(m[3])}` : `(253)${key}${decoded(m[3])}`;
|
|
4501
|
+
function amountOf(v, field, issues) {
|
|
4502
|
+
if (empty(v)) return void 0;
|
|
4503
|
+
const n = Number(v);
|
|
4504
|
+
if (!Number.isFinite(n)) {
|
|
4505
|
+
issues.push({ field, code: "not-a-number", params: { value: String(v) } });
|
|
4506
|
+
return void 0;
|
|
3931
4507
|
}
|
|
3932
|
-
if (
|
|
3933
|
-
|
|
3934
|
-
return
|
|
4508
|
+
if (n < 0) {
|
|
4509
|
+
issues.push({ field, code: "negative", params: { value: n } });
|
|
4510
|
+
return void 0;
|
|
3935
4511
|
}
|
|
3936
|
-
|
|
3937
|
-
const inHouse = /(?:\/(?:obj|class|bt)\/|:(?:obj|class|bt):)([^/:\s]+)$/.exec(raw);
|
|
3938
|
-
return inHouse ? decoded(inHouse[1]) : raw;
|
|
4512
|
+
return n;
|
|
3939
4513
|
}
|
|
3940
|
-
function
|
|
3941
|
-
const m = /^(\d
|
|
4514
|
+
function minutesOf(text) {
|
|
4515
|
+
const m = /^(\d{2}):(\d{2})$/.exec(String(text ?? "").trim());
|
|
3942
4516
|
if (!m) return void 0;
|
|
3943
|
-
const
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
} catch {
|
|
3950
|
-
return part;
|
|
3951
|
-
}
|
|
3952
|
-
}
|
|
3953
|
-
|
|
3954
|
-
// src/order-fold.ts
|
|
3955
|
-
var ORDER_FOLD_HOUR_MS = 60 * 60 * 1e3;
|
|
3956
|
-
var ORDER_FOLD_DEFAULT = Object.freeze({ afterMs: 24 * 60 * 60 * 1e3, maxTerminal: 1e3 });
|
|
3957
|
-
function orderFoldPolicyOf(declared) {
|
|
3958
|
-
const policy = { ...ORDER_FOLD_DEFAULT };
|
|
3959
|
-
for (const key of ["afterMs", "maxTerminal"]) {
|
|
3960
|
-
const v = declared?.[key];
|
|
3961
|
-
if (v === void 0 || v === null) continue;
|
|
3962
|
-
if (typeof v !== "number" || !Number.isFinite(v) || v <= 0) {
|
|
3963
|
-
return { error: `order fold ${key} must be a positive finite number, got ${String(v)} \u2014 a fold that never folds is refused (ADR-0092)` };
|
|
3964
|
-
}
|
|
3965
|
-
policy[key] = key === "maxTerminal" ? Math.floor(v) : v;
|
|
3966
|
-
}
|
|
3967
|
-
if (policy.afterMs % ORDER_FOLD_HOUR_MS !== 0) {
|
|
3968
|
-
return { error: `order fold afterMs must be a whole number of hours, got ${policy.afterMs} ms \u2014 the window is counted in hour slots (ADR-0092)` };
|
|
3969
|
-
}
|
|
3970
|
-
if (policy.maxTerminal < 1) return { error: "order fold maxTerminal must be at least 1 (ADR-0092)" };
|
|
3971
|
-
return { policy };
|
|
4517
|
+
const h = Number(m[1]);
|
|
4518
|
+
const min = Number(m[2]);
|
|
4519
|
+
if (min > 59) return void 0;
|
|
4520
|
+
if (h === 24 && min === 0) return 1440;
|
|
4521
|
+
if (h > 23) return void 0;
|
|
4522
|
+
return h * 60 + min;
|
|
3972
4523
|
}
|
|
3973
|
-
|
|
4524
|
+
var DAYS_IN_MONTH = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
4525
|
+
function dayOfYearOf(text) {
|
|
4526
|
+
const m = /^(\d{2})-(\d{2})$/.exec(String(text ?? "").trim());
|
|
4527
|
+
if (!m) return void 0;
|
|
4528
|
+
const month = Number(m[1]);
|
|
4529
|
+
const day = Number(m[2]);
|
|
4530
|
+
if (month < 1 || month > 12 || day < 1 || day > DAYS_IN_MONTH[month - 1]) return void 0;
|
|
3974
4531
|
let n = 0;
|
|
3975
|
-
for (
|
|
3976
|
-
return n;
|
|
3977
|
-
}
|
|
3978
|
-
function hourStartOf(ms) {
|
|
3979
|
-
return Math.floor(ms / ORDER_FOLD_HOUR_MS) * ORDER_FOLD_HOUR_MS;
|
|
4532
|
+
for (let i = 0; i < month - 1; i++) n += DAYS_IN_MONTH[i];
|
|
4533
|
+
return n + day - 1;
|
|
3980
4534
|
}
|
|
3981
|
-
function
|
|
3982
|
-
|
|
4535
|
+
function tariffIssues(row) {
|
|
4536
|
+
const issues = [];
|
|
4537
|
+
const d = amountOf(row.demandChargePerKW, "demandChargePerKW", issues);
|
|
4538
|
+
const e = amountOf(row.energyChargePerKWh, "energyChargePerKWh", issues);
|
|
4539
|
+
const currency = String(row.currency ?? "").trim();
|
|
4540
|
+
if ((d !== void 0 || e !== void 0) && !currency) issues.push({ field: "currency", code: "currency-required" });
|
|
4541
|
+
if (currency && !isIso4217Code(currency)) issues.push({ field: "currency", code: "format", params: { format: "ISO 4217 (KRW, USD)", value: currency } });
|
|
4542
|
+
return issues;
|
|
3983
4543
|
}
|
|
3984
|
-
function
|
|
3985
|
-
const
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
const
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
};
|
|
3993
|
-
for (const o of hot) {
|
|
3994
|
-
if (!isFlowOrder(o) || !isOrderTerminal(o)) continue;
|
|
3995
|
-
const at2 = o.terminalAtMs;
|
|
3996
|
-
if (typeof at2 === "number" && at2 >= fromMs && at2 <= nowMs) add(o.status, 1);
|
|
4544
|
+
function tariffBandIssues(row) {
|
|
4545
|
+
const issues = [];
|
|
4546
|
+
if (empty(row.tariffName)) issues.push({ field: "tariffName", code: "required" });
|
|
4547
|
+
if (empty(row.band)) issues.push({ field: "band", code: "required" });
|
|
4548
|
+
const loadClass = String(row.loadClass ?? "").trim();
|
|
4549
|
+
if (!loadClass) issues.push({ field: "loadClass", code: "required" });
|
|
4550
|
+
else if (!TARIFF_LOAD_CLASSES.includes(loadClass)) {
|
|
4551
|
+
issues.push({ field: "loadClass", code: "not-in-vocabulary", params: { allowed: TARIFF_LOAD_CLASSES.join("|"), value: loadClass } });
|
|
3997
4552
|
}
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
if (!isFlowOrder({ kind })) continue;
|
|
4002
|
-
for (const [status, c] of Object.entries(statuses)) add(status, c);
|
|
4003
|
-
}
|
|
4553
|
+
const dayKind = empty(row.dayKind) ? "all" : String(row.dayKind).trim();
|
|
4554
|
+
if (!TARIFF_DAY_KINDS.includes(dayKind)) {
|
|
4555
|
+
issues.push({ field: "dayKind", code: "not-in-vocabulary", params: { allowed: TARIFF_DAY_KINDS.join("|"), value: dayKind } });
|
|
4004
4556
|
}
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
const system = typeof l.system === "string" ? l.system.trim() : "";
|
|
4017
|
-
if (system && system !== lensSystem) referenced.push({ id: l.id, system });
|
|
4018
|
-
else own.push(l);
|
|
4557
|
+
const sFromEmpty = empty(row.seasonFrom);
|
|
4558
|
+
const sToEmpty = empty(row.seasonTo);
|
|
4559
|
+
if (sFromEmpty !== sToEmpty) issues.push({ field: sFromEmpty ? "seasonFrom" : "seasonTo", code: "season-pair" });
|
|
4560
|
+
if (!sFromEmpty && dayOfYearOf(row.seasonFrom) === void 0) issues.push({ field: "seasonFrom", code: "format", params: { format: "MM-DD", value: String(row.seasonFrom) } });
|
|
4561
|
+
if (!sToEmpty && dayOfYearOf(row.seasonTo) === void 0) issues.push({ field: "seasonTo", code: "format", params: { format: "MM-DD", value: String(row.seasonTo) } });
|
|
4562
|
+
const from = minutesOf(row.fromTime);
|
|
4563
|
+
const to = minutesOf(row.toTime);
|
|
4564
|
+
if (from === void 0 || from === 1440) issues.push({ field: "fromTime", code: "format", params: { format: "HH:mm 00:00..23:59", value: String(row.fromTime ?? "") } });
|
|
4565
|
+
if (to === void 0 || to === 0) issues.push({ field: "toTime", code: "format", params: { format: "HH:mm 00:01..24:00", value: String(row.toTime ?? "") } });
|
|
4566
|
+
if (from !== void 0 && to !== void 0 && from < 1440 && to > 0 && from >= to) {
|
|
4567
|
+
issues.push({ field: "toTime", code: "end-not-after-start", params: { from: String(row.fromTime), to: String(row.toTime) } });
|
|
4019
4568
|
}
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
function isAggregationRecord(record) {
|
|
4025
|
-
if (!record || typeof record !== "object") return false;
|
|
4026
|
-
const r = record;
|
|
4027
|
-
return typeof r.parentID === "string" && r.parentID.trim().length > 0 && r.epc === void 0;
|
|
4569
|
+
if (empty(row.energyChargePerKWh)) issues.push({ field: "energyChargePerKWh", code: "required" });
|
|
4570
|
+
else amountOf(row.energyChargePerKWh, "energyChargePerKWh", issues);
|
|
4571
|
+
amountOf(row.demandChargePerKW, "demandChargePerKW", issues);
|
|
4572
|
+
return issues;
|
|
4028
4573
|
}
|
|
4029
|
-
function
|
|
4030
|
-
if (
|
|
4031
|
-
const
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
return
|
|
4574
|
+
function seasonHas(band, dayOfYear) {
|
|
4575
|
+
if (empty(band.seasonFrom) && empty(band.seasonTo)) return true;
|
|
4576
|
+
const from = dayOfYearOf(band.seasonFrom);
|
|
4577
|
+
const to = dayOfYearOf(band.seasonTo);
|
|
4578
|
+
if (from === void 0 || to === void 0) return false;
|
|
4579
|
+
return from <= to ? dayOfYear >= from && dayOfYear <= to : dayOfYear >= from || dayOfYear <= to;
|
|
4035
4580
|
}
|
|
4036
|
-
function
|
|
4037
|
-
return
|
|
4581
|
+
function pricesHolidays(bands) {
|
|
4582
|
+
return bands.some((b) => String(b.dayKind ?? "").trim() === "holiday");
|
|
4038
4583
|
}
|
|
4039
|
-
function
|
|
4040
|
-
if (
|
|
4041
|
-
|
|
4042
|
-
const r = get(record, v.slice(2));
|
|
4043
|
-
if (r === void 0 || r === null) return void 0;
|
|
4044
|
-
if (typeof r === "object") {
|
|
4045
|
-
errors.push(`${field} \uAC00 \uAC12\uC774 \uC544\uB2C8\uB77C ${Array.isArray(r) ? "\uBC30\uC5F4" : "\uAC1D\uCCB4"}\uB85C \uC654\uB2E4(${v}) \u2014 \uCEE4\uB125\uD130\uAC00 \uD45C\uC900 \uAD6C\uC870\uB97C \uADF8\uB300\uB85C \uC2E4\uC5C8\uB2E4: ${JSON.stringify(r).slice(0, 80)}`);
|
|
4046
|
-
return void 0;
|
|
4047
|
-
}
|
|
4048
|
-
return String(r);
|
|
4584
|
+
function dayKindOf(at2, holidays, isHoliday) {
|
|
4585
|
+
if (holidays && isHoliday?.(at2.month, at2.day)) return "holiday";
|
|
4586
|
+
return at2.weekday === 0 ? "sunday" : at2.weekday === 6 ? "saturday" : "weekday";
|
|
4049
4587
|
}
|
|
4050
|
-
function
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
if (r === void 0 || r === null) return [];
|
|
4054
|
-
if (!Array.isArray(r) || r.some((x) => typeof x !== "string")) {
|
|
4055
|
-
errors.push(`${field} \uAC00 \uBB38\uC790\uC5F4 \uBC30\uC5F4\uC774 \uC544\uB2C8\uB2E4(${v}): ${JSON.stringify(r).slice(0, 80)}`);
|
|
4056
|
-
return [];
|
|
4057
|
-
}
|
|
4058
|
-
return r.slice();
|
|
4588
|
+
function dayKindHas(band, kind) {
|
|
4589
|
+
const k = empty(band.dayKind) ? "all" : String(band.dayKind).trim();
|
|
4590
|
+
return k === "all" || k === kind;
|
|
4059
4591
|
}
|
|
4060
|
-
function
|
|
4061
|
-
|
|
4062
|
-
const r = get(record, v.startsWith("$.") ? v.slice(2) : v);
|
|
4063
|
-
if (r === void 0 || r === null) return [];
|
|
4064
|
-
if (!Array.isArray(r) || r.some((x) => !x || typeof x !== "object" || Array.isArray(x))) {
|
|
4065
|
-
errors.push(`${field} \uAC00 \uAC1D\uCCB4 \uBC30\uC5F4\uC774 \uC544\uB2C8\uB2E4(${v}): ${JSON.stringify(r).slice(0, 80)}`);
|
|
4066
|
-
return [];
|
|
4067
|
-
}
|
|
4068
|
-
return r.map((x) => ({ ...x }));
|
|
4592
|
+
function activeBands(bands, at2) {
|
|
4593
|
+
return bands.filter((b) => empty(b.effectiveEnd) || new Date(b.effectiveEnd).getTime() > at2.getTime());
|
|
4069
4594
|
}
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4595
|
+
var hhmm = (m) => `${String(Math.floor(m / 60)).padStart(2, "0")}:${String(m % 60).padStart(2, "0")}`;
|
|
4596
|
+
function mmdd(dayOfYear) {
|
|
4597
|
+
let month = 0;
|
|
4598
|
+
let rest = dayOfYear;
|
|
4599
|
+
while (rest >= DAYS_IN_MONTH[month]) rest -= DAYS_IN_MONTH[month++];
|
|
4600
|
+
return `${String(month + 1).padStart(2, "0")}-${String(rest + 1).padStart(2, "0")}`;
|
|
4601
|
+
}
|
|
4602
|
+
function tariffCoverageIssues(tariff, bands) {
|
|
4603
|
+
const issues = [];
|
|
4604
|
+
if (!bands.length) return issues;
|
|
4605
|
+
const usable = bands.filter((b) => tariffBandIssues(b).length === 0);
|
|
4606
|
+
if (!empty(tariff.energyChargePerKWh)) issues.push({ field: "energyChargePerKWh", code: "flat-and-bands" });
|
|
4607
|
+
if (!String(tariff.currency ?? "").trim()) issues.push({ field: "currency", code: "currency-required" });
|
|
4608
|
+
const holidays = pricesHolidays(usable);
|
|
4609
|
+
if (holidays && empty(tariff.holidayCalendar)) {
|
|
4610
|
+
issues.push({ field: "holidayCalendar", code: "required", params: { because: "the tariff has holiday bands" } });
|
|
4077
4611
|
}
|
|
4078
|
-
const
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4612
|
+
const broken = bands.length - usable.length;
|
|
4613
|
+
if (broken) issues.push({ field: "bands", code: "broken-bands", params: { count: broken } });
|
|
4614
|
+
const seen = /* @__PURE__ */ new Map();
|
|
4615
|
+
const note = (kind, day, code, from, to, names) => {
|
|
4616
|
+
const key = [kind, code, from, to, names ?? ""].join("\0");
|
|
4617
|
+
const entry = seen.get(key);
|
|
4618
|
+
if (entry) entry.days.push(day);
|
|
4619
|
+
else {
|
|
4620
|
+
const params = { dayKind: kind, from: hhmm(from), to: hhmm(to) };
|
|
4621
|
+
if (names) params.bands = names;
|
|
4622
|
+
seen.set(key, { problem: { field: "bands", code, params }, days: [day] });
|
|
4623
|
+
}
|
|
4624
|
+
};
|
|
4625
|
+
for (const kind of CONCRETE_DAY_KINDS.filter((k) => k !== "holiday" || holidays)) {
|
|
4626
|
+
for (let day = 0; day < 366; day++) {
|
|
4627
|
+
const today = usable.filter((b) => seasonHas(b, day) && dayKindHas(b, kind)).map((b) => ({ name: String(b.name ?? ""), from: minutesOf(b.fromTime), to: minutesOf(b.toTime) })).sort((a, b) => a.from - b.from || a.to - b.to);
|
|
4628
|
+
let cursor = 0;
|
|
4629
|
+
let last;
|
|
4630
|
+
for (const b of today) {
|
|
4631
|
+
if (b.from > cursor) note(kind, day, "gap", cursor, b.from);
|
|
4632
|
+
if (last && b.from < last.to) note(kind, day, "overlap", b.from, Math.min(last.to, b.to), `${last.name}\xB7${b.name}`);
|
|
4633
|
+
if (b.to > cursor) {
|
|
4634
|
+
cursor = b.to;
|
|
4635
|
+
last = b;
|
|
4636
|
+
}
|
|
4637
|
+
}
|
|
4638
|
+
if (cursor < 1440) note(kind, day, "gap", cursor, 1440);
|
|
4639
|
+
}
|
|
4082
4640
|
}
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4641
|
+
for (const { problem, days } of seen.values()) {
|
|
4642
|
+
const spans = [];
|
|
4643
|
+
let start = days[0];
|
|
4644
|
+
let prev = days[0];
|
|
4645
|
+
for (const d of [...days.slice(1), Infinity]) {
|
|
4646
|
+
if (d === prev + 1) {
|
|
4647
|
+
prev = d;
|
|
4648
|
+
continue;
|
|
4649
|
+
}
|
|
4650
|
+
spans.push(start === prev ? mmdd(start) : `${mmdd(start)}~${mmdd(prev)}`);
|
|
4651
|
+
start = prev = d;
|
|
4652
|
+
}
|
|
4653
|
+
issues.push({ ...problem, params: { ...problem.params, days: spans.join(", ") } });
|
|
4092
4654
|
}
|
|
4093
|
-
|
|
4094
|
-
return Object.keys(o).length ? o : void 0;
|
|
4655
|
+
return issues;
|
|
4095
4656
|
}
|
|
4096
|
-
function
|
|
4097
|
-
|
|
4098
|
-
const
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
errors.push("errorDeclaration\uC5D0 \uC815\uC815 \uC0AC\uC720 \uB610\uB294 \uB300\uC0C1\uC774 \uC788\uC9C0\uB9CC \uC815\uC815 \uC2DC\uAC01(declarationTime)\uC774 \uC5C6\uC2B5\uB2C8\uB2E4.");
|
|
4104
|
-
}
|
|
4105
|
-
return void 0;
|
|
4657
|
+
function bandAt(tariff, bands, at2, isHoliday) {
|
|
4658
|
+
const currency = String(tariff.currency ?? "").trim() || void 0;
|
|
4659
|
+
const usable = bands.filter((b) => tariffBandIssues(b).length === 0);
|
|
4660
|
+
if (!usable.length) {
|
|
4661
|
+
const flat = empty(tariff.energyChargePerKWh) ? NaN : Number(tariff.energyChargePerKWh);
|
|
4662
|
+
if (!Number.isFinite(flat)) return { reason: "no-price" };
|
|
4663
|
+
return { energyChargePerKWh: flat, ...currency ? { currency } : {}, holidayKnown: true };
|
|
4106
4664
|
}
|
|
4665
|
+
const day = dayOfYearOf(`${String(at2.month).padStart(2, "0")}-${String(at2.day).padStart(2, "0")}`);
|
|
4666
|
+
if (day === void 0) return { reason: "no-band" };
|
|
4667
|
+
const holidays = pricesHolidays(usable);
|
|
4668
|
+
const kind = dayKindOf(at2, holidays, isHoliday);
|
|
4669
|
+
const hits = usable.filter(
|
|
4670
|
+
(b) => seasonHas(b, day) && dayKindHas(b, kind) && minutesOf(b.fromTime) <= at2.minutes && at2.minutes < minutesOf(b.toTime)
|
|
4671
|
+
);
|
|
4672
|
+
if (!hits.length) return { reason: "no-band" };
|
|
4673
|
+
if (hits.length > 1) return { reason: "ambiguous", bands: hits.map((b) => String(b.name ?? "")) };
|
|
4674
|
+
const hit = hits[0];
|
|
4675
|
+
const demand = empty(hit.demandChargePerKW) ? void 0 : Number(hit.demandChargePerKW);
|
|
4107
4676
|
return {
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4677
|
+
bandName: String(hit.name ?? "") || void 0,
|
|
4678
|
+
band: String(hit.band).trim(),
|
|
4679
|
+
loadClass: String(hit.loadClass).trim(),
|
|
4680
|
+
energyChargePerKWh: Number(hit.energyChargePerKWh),
|
|
4681
|
+
...demand !== void 0 ? { demandChargePerKW: demand } : {},
|
|
4682
|
+
...currency ? { currency } : {},
|
|
4683
|
+
holidayKnown: !holidays || !!isHoliday
|
|
4111
4684
|
};
|
|
4112
4685
|
}
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
bizLocation
|
|
4149
|
-
}),
|
|
4150
|
-
errors
|
|
4151
|
-
};
|
|
4152
|
-
}
|
|
4153
|
-
if (mapping.type === "AggregationEvent") {
|
|
4154
|
-
const action2 = resolve(mapping.action, record, "action", errors) ?? "";
|
|
4155
|
-
const parentID = resolve(mapping.parentID, record, "parentID", errors) ?? "";
|
|
4156
|
-
const childEPCs = resolveList(mapping.childEPCs, record, "childEPCs", errors);
|
|
4157
|
-
const childQuantityList = resolveQuantityList(mapping.childQuantityList, record, "childQuantityList", errors);
|
|
4158
|
-
return {
|
|
4159
|
-
event: aggregationEvent({
|
|
4160
|
-
eventTime,
|
|
4161
|
-
action: action2,
|
|
4162
|
-
bizStep,
|
|
4163
|
-
disposition,
|
|
4164
|
-
parentID,
|
|
4165
|
-
/* 없는 쪽은 **필드를 만들지 않는다** — 빈 배열을 실으면 「자식이 없다」고 말하는 것이 된다. */
|
|
4166
|
-
...childEPCs.length ? { childEPCs } : {},
|
|
4167
|
-
...childQuantityList.length ? { childQuantityList } : {},
|
|
4168
|
-
...errorDeclaration ? { errorDeclaration } : {},
|
|
4169
|
-
...bizTransactionList.length ? { bizTransactionList } : {},
|
|
4170
|
-
readPoint,
|
|
4171
|
-
bizLocation
|
|
4172
|
-
}),
|
|
4173
|
-
errors
|
|
4174
|
-
};
|
|
4686
|
+
|
|
4687
|
+
// src/gs1.ts
|
|
4688
|
+
var FNC1 = "";
|
|
4689
|
+
var FIXED_LENGTH = {
|
|
4690
|
+
"00": 18,
|
|
4691
|
+
// SSCC
|
|
4692
|
+
"01": 14,
|
|
4693
|
+
// GTIN
|
|
4694
|
+
"02": 14,
|
|
4695
|
+
// 포장 안 품목의 GTIN
|
|
4696
|
+
"11": 6,
|
|
4697
|
+
// 생산일
|
|
4698
|
+
"12": 6,
|
|
4699
|
+
// 지급기일
|
|
4700
|
+
"13": 6,
|
|
4701
|
+
// 포장일
|
|
4702
|
+
"15": 6,
|
|
4703
|
+
// 품질 유지 기한
|
|
4704
|
+
"16": 6,
|
|
4705
|
+
// 판매기한
|
|
4706
|
+
"17": 6,
|
|
4707
|
+
// 사용기한
|
|
4708
|
+
"20": 2,
|
|
4709
|
+
// 제품 변형
|
|
4710
|
+
"414": 13
|
|
4711
|
+
// 물리적 위치의 GLN
|
|
4712
|
+
};
|
|
4713
|
+
var KNOWN_VARIABLE = ["10", "21", "30", "254"];
|
|
4714
|
+
function isBracketed(value) {
|
|
4715
|
+
return /^\(\d{2,4}\)/.test(value);
|
|
4716
|
+
}
|
|
4717
|
+
function parseGs1(value) {
|
|
4718
|
+
const raw = value;
|
|
4719
|
+
if (!raw?.trim()) {
|
|
4720
|
+
return { ok: false, because: "not-gs1", raw };
|
|
4175
4721
|
}
|
|
4176
|
-
const
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
if (!epc && !quantityList.length) {
|
|
4180
|
-
errors.push("epc \uB610\uB294 quantityList\uAC00 \uD544\uC694\uD569\uB2C8\uB2E4. \uAC1C\uCCB4 \uC2DD\uBCC4\uC790\uB098 \uD074\uB798\uC2A4\xB7\uC218\uB7C9\uC744 \uC9C0\uC815\uD558\uC138\uC694.");
|
|
4722
|
+
const parsed = isBracketed(raw) ? fromBracketed(raw) : fromRaw(raw);
|
|
4723
|
+
if (!parsed.ok) {
|
|
4724
|
+
return parsed;
|
|
4181
4725
|
}
|
|
4182
|
-
const
|
|
4726
|
+
const found = parsed.elements;
|
|
4727
|
+
const count = found["30"] !== void 0 ? Number(found["30"]) : void 0;
|
|
4183
4728
|
return {
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4729
|
+
ok: true,
|
|
4730
|
+
scan: {
|
|
4731
|
+
sscc: found["00"],
|
|
4732
|
+
gln: found["414"],
|
|
4733
|
+
glnExtension: found["254"],
|
|
4734
|
+
gtin: found["01"],
|
|
4735
|
+
lot: found["10"],
|
|
4736
|
+
serial: found["21"],
|
|
4737
|
+
useBy: found["17"],
|
|
4738
|
+
/* 숫자가 아니면 담지 않는다 — `NaN` 을 수량으로 두면 더하는 쪽에서 합계가 통째로 사라진다. */
|
|
4739
|
+
count: count !== void 0 && Number.isFinite(count) ? count : void 0,
|
|
4740
|
+
elements: found,
|
|
4741
|
+
raw
|
|
4742
|
+
}
|
|
4198
4743
|
};
|
|
4199
4744
|
}
|
|
4200
|
-
function
|
|
4201
|
-
|
|
4745
|
+
function fromBracketed(raw) {
|
|
4746
|
+
const elements = {};
|
|
4747
|
+
const pattern = /\((\d{2,4})\)([^(]*)/g;
|
|
4748
|
+
let match;
|
|
4749
|
+
let consumed = 0;
|
|
4750
|
+
while ((match = pattern.exec(raw)) !== null) {
|
|
4751
|
+
const ai = match[1];
|
|
4752
|
+
const value = match[2].trim();
|
|
4753
|
+
const fixed = FIXED_LENGTH[ai];
|
|
4754
|
+
if (fixed !== void 0 && value.length !== fixed) {
|
|
4755
|
+
return { ok: false, because: value.length < fixed ? "truncated" : "unterminated", raw };
|
|
4756
|
+
}
|
|
4757
|
+
elements[ai] = value;
|
|
4758
|
+
consumed = match.index + match[0].length;
|
|
4759
|
+
}
|
|
4760
|
+
if (!Object.keys(elements).length || consumed !== raw.length) {
|
|
4761
|
+
return { ok: false, because: "not-gs1", raw };
|
|
4762
|
+
}
|
|
4763
|
+
return { ok: true, elements };
|
|
4202
4764
|
}
|
|
4203
|
-
function
|
|
4204
|
-
const
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
const rule = ruleByType.get(String(record["sourceType"]));
|
|
4210
|
-
if (!rule) {
|
|
4211
|
-
rejected.push({ record, errors: [`\uC77C\uCE58\uD558\uB294 \uB9E4\uD551 \uADDC\uCE59 \uC5C6\uC74C: sourceType=${record["sourceType"]}`] });
|
|
4765
|
+
function fromRaw(raw) {
|
|
4766
|
+
const elements = {};
|
|
4767
|
+
let rest = raw;
|
|
4768
|
+
while (rest.length) {
|
|
4769
|
+
if (rest.startsWith(FNC1)) {
|
|
4770
|
+
rest = rest.slice(1);
|
|
4212
4771
|
continue;
|
|
4213
4772
|
}
|
|
4214
|
-
const
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4773
|
+
const ai = aiAt(rest);
|
|
4774
|
+
if (!ai) {
|
|
4775
|
+
return { ok: false, because: Object.keys(elements).length ? "unterminated" : "not-gs1", raw };
|
|
4776
|
+
}
|
|
4777
|
+
rest = rest.slice(ai.length);
|
|
4778
|
+
const fixed = FIXED_LENGTH[ai];
|
|
4779
|
+
if (fixed !== void 0) {
|
|
4780
|
+
if (rest.length < fixed) {
|
|
4781
|
+
return { ok: false, because: "truncated", raw };
|
|
4782
|
+
}
|
|
4783
|
+
const value = rest.slice(0, fixed);
|
|
4784
|
+
if (value.includes(FNC1)) {
|
|
4785
|
+
return { ok: false, because: "truncated", raw };
|
|
4786
|
+
}
|
|
4787
|
+
elements[ai] = value;
|
|
4788
|
+
rest = rest.slice(fixed);
|
|
4220
4789
|
continue;
|
|
4221
4790
|
}
|
|
4222
|
-
const
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
eventType: `epcis.${ev.type}`,
|
|
4226
|
-
eventTime: ev.eventTime,
|
|
4227
|
-
tenantId: opts.tenantId,
|
|
4228
|
-
...note ? { description: note } : {},
|
|
4229
|
-
data: ev
|
|
4230
|
-
});
|
|
4791
|
+
const end = rest.indexOf(FNC1);
|
|
4792
|
+
elements[ai] = end === -1 ? rest : rest.slice(0, end);
|
|
4793
|
+
rest = end === -1 ? "" : rest.slice(end + 1);
|
|
4231
4794
|
}
|
|
4232
|
-
return {
|
|
4233
|
-
}
|
|
4234
|
-
|
|
4235
|
-
// src/iso-duration.ts
|
|
4236
|
-
var RE = /^(-)?P(?:(\d+(?:\.\d+)?)W)?(?:(\d+(?:\.\d+)?)D)?(?:T(?:(\d+(?:\.\d+)?)H)?(?:(\d+(?:\.\d+)?)M)?(?:(\d+(?:\.\d+)?)S)?)?$/;
|
|
4237
|
-
function parseIsoDuration(text) {
|
|
4238
|
-
if (typeof text !== "string") return void 0;
|
|
4239
|
-
const s = text.trim();
|
|
4240
|
-
if (!s || s === "P" || s === "PT") return void 0;
|
|
4241
|
-
if (/\d+Y/.test(s)) return void 0;
|
|
4242
|
-
const tIdx = s.indexOf("T");
|
|
4243
|
-
const datePart = tIdx === -1 ? s : s.slice(0, tIdx);
|
|
4244
|
-
if (/\d+M/.test(datePart)) return void 0;
|
|
4245
|
-
const m = RE.exec(s);
|
|
4246
|
-
if (!m) return void 0;
|
|
4247
|
-
const [, sign, w, d, h, min, sec] = m;
|
|
4248
|
-
if (!w && !d && !h && !min && !sec) return void 0;
|
|
4249
|
-
const ms = (Number(w ?? 0) * 7 + Number(d ?? 0)) * 864e5 + Number(h ?? 0) * 36e5 + Number(min ?? 0) * 6e4 + Number(sec ?? 0) * 1e3;
|
|
4250
|
-
if (!Number.isFinite(ms)) return void 0;
|
|
4251
|
-
return sign ? -ms : ms;
|
|
4252
|
-
}
|
|
4253
|
-
|
|
4254
|
-
// src/master-data.ts
|
|
4255
|
-
var VOCABULARY_TYPE = {
|
|
4256
|
-
/** 품목·로트 클래스의 속성 — 유통기한·로트번호가 여기 온다. */
|
|
4257
|
-
epcClass: "urn:epcglobal:epcis:vtype:EPCClass",
|
|
4258
|
-
/** 관측 지점의 속성. */
|
|
4259
|
-
readPoint: "urn:epcglobal:epcis:vtype:ReadPoint",
|
|
4260
|
-
/** 업무 자리의 속성. */
|
|
4261
|
-
bizLocation: "urn:epcglobal:epcis:vtype:BizLocation"
|
|
4262
|
-
};
|
|
4263
|
-
function isMasterDataRecord(record) {
|
|
4264
|
-
if (!record || typeof record !== "object") return false;
|
|
4265
|
-
const r = record;
|
|
4266
|
-
return typeof r.vocabularyType === "string" && !!r.vocabularyType && typeof r.id === "string" && !!r.id && isPlainObject(r.attributes);
|
|
4267
|
-
}
|
|
4268
|
-
function isPlainObject(v) {
|
|
4269
|
-
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
4795
|
+
return Object.keys(elements).length ? { ok: true, elements } : { ok: false, because: "not-gs1", raw };
|
|
4270
4796
|
}
|
|
4271
|
-
function
|
|
4272
|
-
const
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
for (const r of arr) {
|
|
4276
|
-
const errors = [];
|
|
4277
|
-
if (!isMasterDataRecord(r)) errors.push("vocabularyType, id, attributes\uB97C \uC9C0\uC815\uD574\uC57C \uD569\uB2C8\uB2E4.");
|
|
4278
|
-
else if (!Object.keys(r.attributes).length) errors.push("attributes\uC5D0 \uC18D\uC131\uC744 \uD558\uB098 \uC774\uC0C1 \uC9C0\uC815\uD574\uC57C \uD569\uB2C8\uB2E4.");
|
|
4279
|
-
if (errors.length) rejected.push({ record: r, errors });
|
|
4280
|
-
else accepted.push({ vocabularyType: r.vocabularyType, id: r.id, attributes: { ...r.attributes } });
|
|
4797
|
+
function aiAt(rest) {
|
|
4798
|
+
const two = rest.slice(0, 2);
|
|
4799
|
+
if (!/^\d{2}$/.test(two)) {
|
|
4800
|
+
return void 0;
|
|
4281
4801
|
}
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
function expiryFromAttributes(attrs) {
|
|
4285
|
-
return readEpochMs(attrs?.[ILMD_ATTR.expiry]);
|
|
4286
|
-
}
|
|
4287
|
-
function lotFromAttributes(attrs) {
|
|
4288
|
-
const v = attrs?.[ILMD_ATTR.lot];
|
|
4289
|
-
return typeof v === "string" && v.trim() ? v.trim() : void 0;
|
|
4290
|
-
}
|
|
4291
|
-
function readEpochMs(raw) {
|
|
4292
|
-
if (typeof raw === "number") return Number.isFinite(raw) ? raw : void 0;
|
|
4293
|
-
if (typeof raw !== "string" || !raw.trim()) return void 0;
|
|
4294
|
-
const at2 = Date.parse(raw);
|
|
4295
|
-
return Number.isNaN(at2) ? void 0 : at2;
|
|
4296
|
-
}
|
|
4297
|
-
|
|
4298
|
-
// src/work-shift-basis.ts
|
|
4299
|
-
var instant = (value) => typeof value === "string" && /(?:Z|[+-]\d{2}:\d{2})$/.test(value) && Number.isFinite(Date.parse(value));
|
|
4300
|
-
var nonempty = (value) => typeof value === "string" && !!value.trim();
|
|
4301
|
-
var clock = (value) => typeof value === "string" && /^(?:[01]\d|2[0-3]):[0-5]\d$/.test(value);
|
|
4302
|
-
function isWorkShiftExecutionBasis(value) {
|
|
4303
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
4304
|
-
const b = value;
|
|
4305
|
-
if (![b.basisId, b.arrangementId, b.revisionId, b.planId, b.contentHash].every(nonempty) || !Number.isSafeInteger(b.revisionNumber) || b.revisionNumber < 1 || !instant(b.businessTime) || !nonempty(b.timezone)) return false;
|
|
4306
|
-
try {
|
|
4307
|
-
new Intl.DateTimeFormat("en", { timeZone: b.timezone }).format(0);
|
|
4308
|
-
} catch {
|
|
4309
|
-
return false;
|
|
4802
|
+
if (FIXED_LENGTH[two] !== void 0 || KNOWN_VARIABLE.includes(two)) {
|
|
4803
|
+
return two;
|
|
4310
4804
|
}
|
|
4311
|
-
|
|
4312
|
-
if (
|
|
4313
|
-
|
|
4314
|
-
for (const s of b.shifts) {
|
|
4315
|
-
if (!s || typeof s !== "object" || !nonempty(s.name) || names.has(s.name) || s.description !== void 0 && typeof s.description !== "string" || ![-1, 0, 1].includes(s.fromDate) || ![-1, 0, 1].includes(s.toDate) || !clock(s.fromTime) || !clock(s.toTime) || typeof s.daysOfWeek !== "string" || !/^(?:[0-6](?:,[0-6])*)?$/.test(s.daysOfWeek)) return false;
|
|
4316
|
-
const minutes = (time) => Number(time.slice(0, 2)) * 60 + Number(time.slice(3));
|
|
4317
|
-
const duration = (s.toDate - s.fromDate) * 1440 + minutes(s.toTime) - minutes(s.fromTime);
|
|
4318
|
-
if (duration <= 0 || duration > 1440) return false;
|
|
4319
|
-
names.add(s.name);
|
|
4805
|
+
const three = rest.slice(0, 3);
|
|
4806
|
+
if (/^\d{3}$/.test(three) && (FIXED_LENGTH[three] !== void 0 || KNOWN_VARIABLE.includes(three))) {
|
|
4807
|
+
return three;
|
|
4320
4808
|
}
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
const at2 = Date.parse(b.businessTime);
|
|
4324
|
-
return Date.parse(b.occurrence.from) <= at2 && at2 < Date.parse(b.occurrence.to);
|
|
4809
|
+
const four = rest.slice(0, 4);
|
|
4810
|
+
return /^\d{4}$/.test(four) ? four : two;
|
|
4325
4811
|
}
|
|
4326
|
-
function
|
|
4327
|
-
|
|
4328
|
-
return
|
|
4329
|
-
workDate: value.workDate,
|
|
4330
|
-
shiftName: value.shiftName,
|
|
4331
|
-
timezone: value.timezone,
|
|
4332
|
-
revisionNumber: value.revisionNumber,
|
|
4333
|
-
occurrence: value.occurrence ? { ...value.occurrence } : void 0
|
|
4334
|
-
};
|
|
4812
|
+
function checkDigitOf(body) {
|
|
4813
|
+
const sum = [...body].reverse().reduce((total, digit, at2) => total + Number(digit) * (at2 % 2 === 0 ? 3 : 1), 0);
|
|
4814
|
+
return String((10 - sum % 10) % 10);
|
|
4335
4815
|
}
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
const
|
|
4344
|
-
|
|
4345
|
-
}
|
|
4346
|
-
for (const [f, t] of Object.entries(shape.fields ?? {})) {
|
|
4347
|
-
const v = row[f];
|
|
4348
|
-
if (v === void 0 || v === null) continue;
|
|
4349
|
-
if (t === "number" && (typeof v !== "number" || !Number.isFinite(v))) {
|
|
4350
|
-
errors.push(`${where}.${f} \uAC12\uC740 \uC720\uD55C\uD55C \uC22B\uC790\uC5EC\uC57C \uD569\uB2C8\uB2E4: ${JSON.stringify(v)}`);
|
|
4351
|
-
} else if (t !== "number" && typeof v !== t) {
|
|
4352
|
-
errors.push(`${where}.${f} \uAC00 ${t} \uAC00 \uC544\uB2C8\uB2E4: ${JSON.stringify(v)}`);
|
|
4353
|
-
}
|
|
4354
|
-
}
|
|
4355
|
-
for (const [f, allowed] of Object.entries(shape.enums ?? {})) {
|
|
4356
|
-
const v = row[f];
|
|
4357
|
-
if (v === void 0 || v === null) continue;
|
|
4358
|
-
if (!allowed.includes(String(v))) {
|
|
4359
|
-
errors.push(`${where}.${f}\uC5D0 \uD5C8\uC6A9\uB418\uC9C0 \uC54A\uB294 \uAC12\uC774 \uC9C0\uC815\uB418\uC5C8\uC2B5\uB2C8\uB2E4: ${JSON.stringify(v)} (${allowed.join(" \xB7 ")})`);
|
|
4360
|
-
}
|
|
4816
|
+
function wellFormed(digits, length) {
|
|
4817
|
+
return !!digits && digits.length === length && /^\d+$/.test(digits) && checkDigitOf(digits.slice(0, -1)) === digits.slice(-1);
|
|
4818
|
+
}
|
|
4819
|
+
var PREFIX_LENGTHS = [6, 7, 8, 9, 10, 11, 12];
|
|
4820
|
+
function epcCandidatesOfGs1(scan) {
|
|
4821
|
+
const out = [];
|
|
4822
|
+
if (wellFormed(scan.sscc, 18)) {
|
|
4823
|
+
const d = scan.sscc;
|
|
4824
|
+
for (const l of PREFIX_LENGTHS) out.push(`urn:epc:id:sscc:${d.slice(1, 1 + l)}.${d[0]}${d.slice(1 + l, 17)}`);
|
|
4361
4825
|
}
|
|
4362
|
-
|
|
4363
|
-
const
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4826
|
+
if (wellFormed(scan.gtin, 14)) {
|
|
4827
|
+
const d = scan.gtin;
|
|
4828
|
+
for (const l of PREFIX_LENGTHS) {
|
|
4829
|
+
const prefix = d.slice(1, 1 + l);
|
|
4830
|
+
const itemRefAndIndicator = d[0] + d.slice(1 + l, 13);
|
|
4831
|
+
out.push(scan.lot ? lgtinClass(prefix, itemRefAndIndicator, scan.lot) : sgtinClass(prefix, itemRefAndIndicator));
|
|
4367
4832
|
}
|
|
4368
4833
|
}
|
|
4369
|
-
|
|
4834
|
+
if (wellFormed(scan.gln, 13)) {
|
|
4835
|
+
const d = scan.gln;
|
|
4836
|
+
for (const l of PREFIX_LENGTHS) out.push(`urn:epc:id:sgln:${d.slice(0, l)}.${d.slice(l, 12)}.${scan.glnExtension || "0"}`);
|
|
4837
|
+
}
|
|
4838
|
+
return out;
|
|
4370
4839
|
}
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
}
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
// vocabulary-guard: allow
|
|
4452
|
-
taskId: "string",
|
|
4453
|
-
held: "boolean",
|
|
4454
|
-
effectiveStart: "string",
|
|
4455
|
-
effectiveEnd: "string",
|
|
4456
|
-
recordTime: "string",
|
|
4457
|
-
/* 왜 이 상태가 됐나 — 설비가 알려 주면 싣는다. 사람이 나중에 정하는 사유는 구간 사실에 적는다. */
|
|
4458
|
-
reasonCode: "string",
|
|
4459
|
-
/* 이동 구간 — 실 시스템도 줄 수 있는 사실이다(AGV·RTLS 가 출발·도착·소요를 낸다). 안쪽 필드까지
|
|
4460
|
-
재검사하지는 않는다: 그 모양은 `EquipmentMotion` 계약이고, 여기서 두 번 지키면 두 벌이 된다. */
|
|
4461
|
-
motion: "object"
|
|
4462
|
-
},
|
|
4463
|
-
enums: { status: EQUIPMENT_STATUS }
|
|
4464
|
-
},
|
|
4465
|
-
person: {
|
|
4466
|
-
eventType: OP_EVENT.person,
|
|
4467
|
-
match: ["personId"],
|
|
4468
|
-
matchOrder: 30,
|
|
4469
|
-
identity: "personId",
|
|
4470
|
-
required: ["personId", "status"],
|
|
4471
|
-
fields: {
|
|
4472
|
-
personId: "string",
|
|
4473
|
-
status: "string",
|
|
4474
|
-
personnelClassIds: "string[]",
|
|
4475
|
-
taskId: "string",
|
|
4476
|
-
location: "string",
|
|
4477
|
-
offShift: "boolean",
|
|
4478
|
-
effectiveStart: "string",
|
|
4479
|
-
effectiveEnd: "string",
|
|
4480
|
-
recordTime: "string"
|
|
4481
|
-
},
|
|
4482
|
-
enums: { status: PERSON_STATUS }
|
|
4483
|
-
},
|
|
4484
|
-
asset: {
|
|
4485
|
-
eventType: OP_EVENT.asset,
|
|
4486
|
-
match: ["assetId"],
|
|
4487
|
-
matchOrder: 40,
|
|
4488
|
-
identity: "assetId",
|
|
4489
|
-
required: ["assetId", "status"],
|
|
4490
|
-
fields: {
|
|
4491
|
-
assetId: "string",
|
|
4492
|
-
status: "string",
|
|
4493
|
-
assetClassIds: "string[]",
|
|
4494
|
-
location: "string",
|
|
4495
|
-
taskId: "string",
|
|
4496
|
-
carrying: "string",
|
|
4497
|
-
effectiveStart: "string",
|
|
4498
|
-
effectiveEnd: "string",
|
|
4499
|
-
recordTime: "string"
|
|
4500
|
-
},
|
|
4501
|
-
enums: { status: ASSET_STATUS }
|
|
4502
|
-
},
|
|
4503
|
-
order: {
|
|
4504
|
-
eventType: OP_EVENT.order,
|
|
4505
|
-
match: ["orderId"],
|
|
4506
|
-
matchOrder: 60,
|
|
4507
|
-
identity: "orderId",
|
|
4508
|
-
/*
|
|
4509
|
-
* 요청량·이행량을 **함께** 받는다. 없으면 리듀서가 진척을 0 으로 적는데(`requested ? … : 0`),
|
|
4510
|
-
* 그것은 「모른다」가 아니라 「아무것도 안 됐다」로 읽힌다 — 결측을 0 으로 메우지 않는다.
|
|
4511
|
-
*/
|
|
4512
|
-
required: ["orderId", "kind", "status", "requested", "fulfilled"],
|
|
4513
|
-
fields: {
|
|
4514
|
-
orderId: "string",
|
|
4515
|
-
kind: "string",
|
|
4516
|
-
status: "string",
|
|
4517
|
-
requested: "number",
|
|
4518
|
-
fulfilled: "number",
|
|
4519
|
-
gtin: "string",
|
|
4520
|
-
held: "boolean",
|
|
4521
|
-
lines: "object[]",
|
|
4522
|
-
priority: "number",
|
|
4523
|
-
startTime: "string",
|
|
4524
|
-
endTime: "string",
|
|
4525
|
-
/* 확보분은 `{ epc, qty }` 줄이다(2026-09-19, ADR-0076 보탬) — 옛 EPC 목록은 받지 않는다. */
|
|
4526
|
-
allocated: "object[]",
|
|
4527
|
-
bizTransaction: "string",
|
|
4528
|
-
operationsRequestId: "string",
|
|
4529
|
-
dockDoor: "string",
|
|
4530
|
-
windowStartMs: "number",
|
|
4531
|
-
recordTime: "string",
|
|
4532
|
-
/*
|
|
4533
|
-
* 이 오더를 어느 레시피로 돌리나 — 「이 로트를 무엇으로 만들었나」가 이 칸을 지나 답한다.
|
|
4534
|
-
*
|
|
4535
|
-
* ── 왜 뒤늦게 생겼나 (2026-09-07 측정) ─────────────────────────────────
|
|
4536
|
-
* EPCIS 변환 사건에는 레시피 자리가 없다(표준이 그렇다). 그래서 이력추적이 **변환 → 거래
|
|
4537
|
-
* 식별자 → 그 오더의 `recipeKey`** 로 건너간다(`twin-lineage-query.ts:296-315`).
|
|
4538
|
-
*
|
|
4539
|
-
* 변환이 오더를 가리키게 만든 뒤에 재보니, **가리켜진 오더 행에 그 칸이 없었다.** 실으면
|
|
4540
|
-
* 레코드가 통째로 거절됐다 — `order: 계약에 없는 필드 — recipeKey`. 조용히 버리지 않은 것은
|
|
4541
|
-
* 맞지만, 그래서 실 시스템에서는 그 물음이 계속 답이 없었다.
|
|
4542
|
-
*
|
|
4543
|
-
* 값은 원본에 있다: `job_orders.recipe_key` 35개 중 20개 채움
|
|
4544
|
-
* (`WO-ECU-STD-2609A` = `RECIPE-ECU-STD`).
|
|
4545
|
-
*
|
|
4546
|
-
* 새 어휘가 아니다 — 계약이 `recipeKey` 를 네 자리에서 이미 쓴다. 오더 관측에만 자리가 없었다.
|
|
4547
|
-
*/
|
|
4548
|
-
recipeKey: "string",
|
|
4549
|
-
recipeBasis: "object",
|
|
4550
|
-
materialBasis: "object[]",
|
|
4551
|
-
/* 근거 칸이 빈 까닭 — 닫힌 낱말이다(§`BASIS_UNKNOWN`). 투입이 근거 장치보다 먼저였던 오더도 이행은 사실이다. */
|
|
4552
|
-
basisUnknown: "string"
|
|
4553
|
-
},
|
|
4554
|
-
/* 상태·종류는 도메인이 소유한다 — 닫지 않는다. 근거가 빈 까닭은 커널이 읽으므로 닫는다. */
|
|
4555
|
-
enums: { basisUnknown: BASIS_UNKNOWN },
|
|
4556
|
-
/*
|
|
4557
|
-
* 확보분의 안쪽을 본다 — 열쇠와 수 둘이다(§`AllocatedQuantity`). 안 보면 틀린 이름이 조용히
|
|
4558
|
-
* 지나가고(`epcs`·`quantity` 따위), 미러는 잡힌 수를 0 으로 읽는다.
|
|
4559
|
-
*/
|
|
4560
|
-
shapes: {
|
|
4561
|
-
materialBasis: {
|
|
4562
|
-
required: ["basisId", "materialId", "revisionId", "revisionNumber", "planId", "contentHash", "businessTime", "material"],
|
|
4563
|
-
fields: { basisId: "string", materialId: "string", revisionId: "string", revisionNumber: "number", planId: "string", contentHash: "string", businessTime: "string" }
|
|
4564
|
-
// Recursive material properties and reference lists are checked by isMaterialExecutionBasis.
|
|
4565
|
-
},
|
|
4566
|
-
recipeBasis: {
|
|
4567
|
-
required: ["basisId", "recipeId", "revisionId", "planId", "contentHash", "businessTime", "recipe"],
|
|
4568
|
-
fields: { basisId: "string", recipeId: "string", revisionId: "string", planId: "string", contentHash: "string", businessTime: "string" }
|
|
4569
|
-
// Owned composition and captured route are additionally checked by isRecipeExecutionBasis below.
|
|
4570
|
-
},
|
|
4571
|
-
allocated: {
|
|
4572
|
-
required: ["epc", "qty"],
|
|
4573
|
-
fields: { epc: "string", qty: "number" },
|
|
4574
|
-
positive: ["qty"]
|
|
4575
|
-
}
|
|
4840
|
+
function ssccDigitsOf(uri) {
|
|
4841
|
+
const match = /^urn:epc:id:sscc:(\d+)\.(\d+)$/.exec(uri ?? "");
|
|
4842
|
+
if (!match) return void 0;
|
|
4843
|
+
const [, prefix, reference] = match;
|
|
4844
|
+
const body = reference[0] + prefix + reference.slice(1);
|
|
4845
|
+
if (body.length !== 17) return void 0;
|
|
4846
|
+
return body + checkDigitOf(body);
|
|
4847
|
+
}
|
|
4848
|
+
function gtin14OfItemClass(definitionId) {
|
|
4849
|
+
const match = /^urn:epc:idpat:sgtin:(\d+)\.(\d+)\.\*$/.exec(definitionId ?? "");
|
|
4850
|
+
if (!match) return void 0;
|
|
4851
|
+
const [, prefix, reference] = match;
|
|
4852
|
+
const body = reference[0] + prefix + reference.slice(1);
|
|
4853
|
+
if (body.length !== 13) return void 0;
|
|
4854
|
+
return body + checkDigitOf(body);
|
|
4855
|
+
}
|
|
4856
|
+
function gtin14OfItem(definitionId) {
|
|
4857
|
+
const byClass = gtin14OfItemClass(definitionId);
|
|
4858
|
+
if (byClass) return byClass;
|
|
4859
|
+
return /^(\d{8}|\d{12,14})$/.test(definitionId ?? "") ? definitionId.padStart(14, "0") : void 0;
|
|
4860
|
+
}
|
|
4861
|
+
function identifierText(uri) {
|
|
4862
|
+
const raw = String(uri ?? "").trim();
|
|
4863
|
+
if (!raw) return "";
|
|
4864
|
+
const parsed = parseEpc(raw);
|
|
4865
|
+
if (parsed.scheme === "sgtin" || parsed.scheme === "lgtin" || parsed.scheme === "idpat") {
|
|
4866
|
+
const gtin = gtin14OfKey(parsed.gtinKey);
|
|
4867
|
+
if (!gtin) return raw;
|
|
4868
|
+
if (parsed.scheme === "sgtin") return parsed.serial ? `(01)${gtin}(21)${decoded(parsed.serial)}` : raw;
|
|
4869
|
+
if (parsed.scheme === "lgtin") return parsed.lot ? `(01)${gtin}(10)${parsed.lot}` : raw;
|
|
4870
|
+
return `(01)${gtin}`;
|
|
4871
|
+
}
|
|
4872
|
+
if (parsed.scheme === "sscc") {
|
|
4873
|
+
const sscc = ssccDigitsOf(raw);
|
|
4874
|
+
return sscc ? `(00)${sscc}` : raw;
|
|
4875
|
+
}
|
|
4876
|
+
if (parsed.scheme === "sgln") {
|
|
4877
|
+
const m = /^urn:epc:id:sgln:(\d+)\.(\d*)\.(.+)$/.exec(raw);
|
|
4878
|
+
if (!m || m[1].length + m[2].length !== 12) return raw;
|
|
4879
|
+
const body = m[1] + m[2];
|
|
4880
|
+
return `(414)${body}${checkDigitOf(body)}${m[3] === "0" ? "" : `(254)${decoded(m[3])}`}`;
|
|
4881
|
+
}
|
|
4882
|
+
if (parsed.scheme === "grai" || parsed.scheme === "gdti") {
|
|
4883
|
+
const m = new RegExp(`^urn:epc:id:${parsed.scheme}:(\\d+)\\.(\\d*)\\.(.*)$`).exec(raw);
|
|
4884
|
+
if (!m || m[1].length + m[2].length !== 12) return raw;
|
|
4885
|
+
const key = m[1] + m[2] + checkDigitOf(m[1] + m[2]);
|
|
4886
|
+
return parsed.scheme === "grai" ? `(8003)0${key}${decoded(m[3])}` : `(253)${key}${decoded(m[3])}`;
|
|
4887
|
+
}
|
|
4888
|
+
if (parsed.scheme === "giai") {
|
|
4889
|
+
const m = /^urn:epc:id:giai:(\d+)\.(.+)$/.exec(raw);
|
|
4890
|
+
return m ? `(8004)${m[1]}${decoded(m[2])}` : raw;
|
|
4891
|
+
}
|
|
4892
|
+
if (parsed.item !== void 0 && parsed.lot !== void 0) return `${parsed.item} \xB7 ${parsed.lot}`;
|
|
4893
|
+
const inHouse = /(?:\/(?:obj|class|bt)\/|:(?:obj|class|bt):)([^/:\s]+)$/.exec(raw);
|
|
4894
|
+
return inHouse ? decoded(inHouse[1]) : raw;
|
|
4895
|
+
}
|
|
4896
|
+
function gtin14OfKey(key) {
|
|
4897
|
+
const m = /^(\d+)\.(\d+)$/.exec(key ?? "");
|
|
4898
|
+
if (!m) return void 0;
|
|
4899
|
+
const body = m[2][0] + m[1] + m[2].slice(1);
|
|
4900
|
+
return body.length === 13 ? body + checkDigitOf(body) : void 0;
|
|
4901
|
+
}
|
|
4902
|
+
function decoded(part) {
|
|
4903
|
+
try {
|
|
4904
|
+
return decodeURIComponent(part);
|
|
4905
|
+
} catch {
|
|
4906
|
+
return part;
|
|
4907
|
+
}
|
|
4908
|
+
}
|
|
4909
|
+
|
|
4910
|
+
// src/order-fold.ts
|
|
4911
|
+
var ORDER_FOLD_HOUR_MS = 60 * 60 * 1e3;
|
|
4912
|
+
var ORDER_FOLD_DEFAULT = Object.freeze({ afterMs: 24 * 60 * 60 * 1e3, maxTerminal: 1e3 });
|
|
4913
|
+
function orderFoldPolicyOf(declared) {
|
|
4914
|
+
const policy = { ...ORDER_FOLD_DEFAULT };
|
|
4915
|
+
for (const key of ["afterMs", "maxTerminal"]) {
|
|
4916
|
+
const v = declared?.[key];
|
|
4917
|
+
if (v === void 0 || v === null) continue;
|
|
4918
|
+
if (typeof v !== "number" || !Number.isFinite(v) || v <= 0) {
|
|
4919
|
+
return { error: `order fold ${key} must be a positive finite number, got ${String(v)} \u2014 a fold that never folds is refused (ADR-0092)` };
|
|
4576
4920
|
}
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
decidedAt: "string",
|
|
4692
|
-
recordTime: "string"
|
|
4693
|
-
},
|
|
4694
|
-
enums: { decision: DISPOSITION_DECISION }
|
|
4695
|
-
},
|
|
4696
|
-
/*
|
|
4697
|
-
* **로트 상태** — ISA-95 `MaterialLot.Status`. 출하 승인(batch release)이 들어오는 문(§`OP_EVENT.materialLot`).
|
|
4698
|
-
*
|
|
4699
|
-
* `disposition`(subjectId + decision) 과 필드가 겹치지 않는다 — 여기는 `lotId` + `status`. 정체 이름이 표준
|
|
4700
|
-
* `MaterialLotID` 인 이유가 하나 더 있다: 이 문은 `epc` 를 든 레코드를 EPCIS 어휘로 보고 받지 않는다
|
|
4701
|
-
* (§`operationalKindOf`). 값은 로트의 식별자(`ItemState.epc` 와 같은 값)다. 상태 낱말은 열려 있어 enum 이
|
|
4702
|
-
* 없다(오더 상태와 같은 규율). 로트 전체의 사실이므로 부분(`subLotId`)은 받지 않는다 — 부분마다 다른 상태가
|
|
4703
|
-
* 필요해지면 그것은 다른 사실이다.
|
|
4704
|
-
*
|
|
4705
|
-
* ── 낱말은 열리고 **효과는 닫힌다** (2026-09-19, ADR-0080 결정 2) ────────────
|
|
4706
|
-
* `status` 는 현장의 낱말이다(`on-hold` · `quarantine` · `검사대기` — 도메인이 소유한다). 커널이 그
|
|
4707
|
-
* 낱말을 읽어 「보류면 할당에서 뺀다」를 정하면, 현장이 다른 낱말을 쓰는 날 조용히 샌다.
|
|
4708
|
-
*
|
|
4709
|
-
* 그래서 **효과를 따로 싣는다**: `use` 는 닫힌 둘(`allowed` · `blocked`)이고 기계가 읽는다. 낱말의
|
|
4710
|
-
* 주인이 둘을 같이 정한다 — 자원 속성에서 이미 선 원칙 그대로다(속성은 열리고 효과는 닫힌다).
|
|
4711
|
-
*
|
|
4712
|
-
* **`use` 가 없는 레코드는 `allowed` 가 아니라 「모름」이다.** 그래서 필수로 만들지 않는다: 이 문을
|
|
4713
|
-
* 이미 쓰고 있는 원본이 있으면 그 사실이 통째로 거절되는 것이 더 나쁘다. 모르는 것을 할당이 어떻게
|
|
4714
|
-
* 다루는지는 커널이 한 곳에서 정하고 그 수를 센다.
|
|
4715
|
-
*/
|
|
4716
|
-
"material-lot": {
|
|
4717
|
-
eventType: OP_EVENT.materialLot,
|
|
4718
|
-
match: ["lotId", "status"],
|
|
4719
|
-
matchOrder: 85,
|
|
4720
|
-
identity: "lotId",
|
|
4721
|
-
required: ["lotId", "status"],
|
|
4722
|
-
fields: { lotId: "string", status: "string", use: "string", decidedBy: "string", reason: "string", decidedAt: "string", recordTime: "string" },
|
|
4723
|
-
enums: { use: MATERIAL_LOT_USE }
|
|
4724
|
-
},
|
|
4725
|
-
test: {
|
|
4726
|
-
eventType: OP_EVENT.test,
|
|
4727
|
-
match: ["testableObjectId"],
|
|
4728
|
-
matchOrder: 70,
|
|
4729
|
-
identity: "testableObjectId",
|
|
4730
|
-
/* 무엇을 어느 기준으로 시험했나 — 둘 중 하나가 없으면 그 결과는 아무 데도 붙지 못한다. */
|
|
4731
|
-
required: ["testableObjectId", "specId"],
|
|
4732
|
-
fields: {
|
|
4733
|
-
testableObjectId: "string",
|
|
4734
|
-
specId: "string",
|
|
4735
|
-
result: "string",
|
|
4736
|
-
at: "string",
|
|
4737
|
-
expiresAt: "string",
|
|
4738
|
-
derived: "boolean",
|
|
4739
|
-
propertyMeasurements: "object[]",
|
|
4740
|
-
specificationBasis: "object",
|
|
4741
|
-
recordTime: "string"
|
|
4742
|
-
},
|
|
4743
|
-
shapes: {
|
|
4744
|
-
specificationBasis: {
|
|
4745
|
-
required: ["id", "revisionId", "planId", "contentHash", "businessTime", "criteria"],
|
|
4746
|
-
fields: { id: "string", revisionId: "string", planId: "string", contentHash: "string", businessTime: "string" }
|
|
4921
|
+
policy[key] = key === "maxTerminal" ? Math.floor(v) : v;
|
|
4922
|
+
}
|
|
4923
|
+
if (policy.afterMs % ORDER_FOLD_HOUR_MS !== 0) {
|
|
4924
|
+
return { error: `order fold afterMs must be a whole number of hours, got ${policy.afterMs} ms \u2014 the window is counted in hour slots (ADR-0092)` };
|
|
4925
|
+
}
|
|
4926
|
+
if (policy.maxTerminal < 1) return { error: "order fold maxTerminal must be at least 1 (ADR-0092)" };
|
|
4927
|
+
return { policy };
|
|
4928
|
+
}
|
|
4929
|
+
function foldedOrderCount(folded) {
|
|
4930
|
+
let n = 0;
|
|
4931
|
+
for (const byStatus of Object.values(folded?.counts ?? {})) for (const c of Object.values(byStatus)) n += c;
|
|
4932
|
+
return n;
|
|
4933
|
+
}
|
|
4934
|
+
function hourStartOf(ms) {
|
|
4935
|
+
return Math.floor(ms / ORDER_FOLD_HOUR_MS) * ORDER_FOLD_HOUR_MS;
|
|
4936
|
+
}
|
|
4937
|
+
function finishedWindowStartMs(nowMs, policy = ORDER_FOLD_DEFAULT) {
|
|
4938
|
+
return hourStartOf(nowMs) - policy.afterMs;
|
|
4939
|
+
}
|
|
4940
|
+
function finishedFlowOrdersWithin(hot, folded, nowMs, policy = ORDER_FOLD_DEFAULT) {
|
|
4941
|
+
const fromMs = finishedWindowStartMs(nowMs, policy);
|
|
4942
|
+
let count = 0;
|
|
4943
|
+
const byStatus = {};
|
|
4944
|
+
const add = (status, n) => {
|
|
4945
|
+
const key = String(status ?? "");
|
|
4946
|
+
byStatus[key] = (byStatus[key] ?? 0) + n;
|
|
4947
|
+
count += n;
|
|
4948
|
+
};
|
|
4949
|
+
for (const o of hot) {
|
|
4950
|
+
if (!isFlowOrder(o) || !isOrderTerminal(o)) continue;
|
|
4951
|
+
const at2 = o.terminalAtMs;
|
|
4952
|
+
if (typeof at2 === "number" && at2 >= fromMs && at2 <= nowMs) add(o.status, 1);
|
|
4953
|
+
}
|
|
4954
|
+
for (const [h, byKind] of Object.entries(folded?.hours ?? {})) {
|
|
4955
|
+
if (Number(h) < fromMs || Number(h) > nowMs) continue;
|
|
4956
|
+
for (const [kind, statuses] of Object.entries(byKind)) {
|
|
4957
|
+
if (!isFlowOrder({ kind })) continue;
|
|
4958
|
+
for (const [status, c] of Object.entries(statuses)) add(status, c);
|
|
4959
|
+
}
|
|
4960
|
+
}
|
|
4961
|
+
return { fromMs, toMs: nowMs, count, byStatus };
|
|
4962
|
+
}
|
|
4963
|
+
|
|
4964
|
+
// src/referenced-location.ts
|
|
4965
|
+
function referencedLocationIds(def) {
|
|
4966
|
+
return new Set((def?.referencedLocations ?? []).map((r) => r.id).filter(Boolean));
|
|
4967
|
+
}
|
|
4968
|
+
function partitionLensLocations(locations, lensSystem) {
|
|
4969
|
+
const own = [];
|
|
4970
|
+
const referenced = [];
|
|
4971
|
+
for (const l of locations) {
|
|
4972
|
+
const system = typeof l.system === "string" ? l.system.trim() : "";
|
|
4973
|
+
if (system && system !== lensSystem) referenced.push({ id: l.id, system });
|
|
4974
|
+
else own.push(l);
|
|
4975
|
+
}
|
|
4976
|
+
return { own, referenced };
|
|
4977
|
+
}
|
|
4978
|
+
|
|
4979
|
+
// src/route-network.ts
|
|
4980
|
+
var CONNECTION_DIRECTION = ["one-way", "two-way"];
|
|
4981
|
+
var FIXED_ROUTE_BINDING = ["mandatory", "preferred"];
|
|
4982
|
+
var DEFAULT_CONNECTION_CAPACITY = 1;
|
|
4983
|
+
var ROUTE_NETWORK_ISSUE = {
|
|
4984
|
+
connectionDangling: "route-connection-dangling",
|
|
4985
|
+
connectionSelf: "route-connection-self",
|
|
4986
|
+
connectionLength: "route-connection-length",
|
|
4987
|
+
connectionSpeed: "route-connection-speed",
|
|
4988
|
+
connectionCapacity: "route-connection-capacity",
|
|
4989
|
+
connectionDirection: "route-connection-direction",
|
|
4990
|
+
connectionDuplicate: "route-connection-duplicate",
|
|
4991
|
+
connectionUnknownClass: "route-connection-unknown-class",
|
|
4992
|
+
fixedEmpty: "route-fixed-empty",
|
|
4993
|
+
fixedUnknownConnection: "route-fixed-unknown-connection",
|
|
4994
|
+
fixedBroken: "route-fixed-broken",
|
|
4995
|
+
fixedClass: "route-fixed-class",
|
|
4996
|
+
fixedBinding: "route-fixed-binding",
|
|
4997
|
+
duplicateId: "route-duplicate-id"
|
|
4998
|
+
};
|
|
4999
|
+
var positiveNumber = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
|
|
5000
|
+
function traversals(c) {
|
|
5001
|
+
return c.direction === "two-way" ? [{ from: c.from, to: c.to }, { from: c.to, to: c.from }] : [{ from: c.from, to: c.to }];
|
|
5002
|
+
}
|
|
5003
|
+
function admits(c, classIds, classes) {
|
|
5004
|
+
if (!c.equipmentClassIds || c.equipmentClassIds.length === 0) return true;
|
|
5005
|
+
const allowed = new Set(c.equipmentClassIds);
|
|
5006
|
+
return classIds.every((id) => [...classClosure([id], classes)].some((k) => allowed.has(k)));
|
|
5007
|
+
}
|
|
5008
|
+
function validateRouteNetwork(def) {
|
|
5009
|
+
const issues = [];
|
|
5010
|
+
const places = new Set([...def.locations ?? [], ...def.referencedLocations ?? []].map((l) => l.id));
|
|
5011
|
+
const connections = def.connections ?? [];
|
|
5012
|
+
const classIds = new Set((def.equipmentClasses ?? []).map((c) => c.id));
|
|
5013
|
+
const byId = /* @__PURE__ */ new Map();
|
|
5014
|
+
const seenEnds = /* @__PURE__ */ new Set();
|
|
5015
|
+
for (const c of connections) {
|
|
5016
|
+
if (byId.has(c.id)) issues.push({ code: ROUTE_NETWORK_ISSUE.duplicateId, subject: c.id, params: { kind: "connection" } });
|
|
5017
|
+
byId.set(c.id, c);
|
|
5018
|
+
for (const end of [c.from, c.to]) {
|
|
5019
|
+
if (!places.has(end)) issues.push({ code: ROUTE_NETWORK_ISSUE.connectionDangling, subject: c.id, params: { location: end } });
|
|
5020
|
+
}
|
|
5021
|
+
if (c.from === c.to) issues.push({ code: ROUTE_NETWORK_ISSUE.connectionSelf, subject: c.id, params: { location: c.from } });
|
|
5022
|
+
if (!CONNECTION_DIRECTION.includes(c.direction)) {
|
|
5023
|
+
issues.push({ code: ROUTE_NETWORK_ISSUE.connectionDirection, subject: c.id, params: { direction: String(c.direction) } });
|
|
5024
|
+
}
|
|
5025
|
+
if (!positiveNumber(c.lengthM)) issues.push({ code: ROUTE_NETWORK_ISSUE.connectionLength, subject: c.id, params: { lengthM: String(c.lengthM) } });
|
|
5026
|
+
if (c.maxSpeedMps !== void 0 && !positiveNumber(c.maxSpeedMps)) {
|
|
5027
|
+
issues.push({ code: ROUTE_NETWORK_ISSUE.connectionSpeed, subject: c.id, params: { maxSpeedMps: String(c.maxSpeedMps) } });
|
|
5028
|
+
}
|
|
5029
|
+
if (c.capacity !== void 0 && !(Number.isInteger(c.capacity) && c.capacity >= 1)) {
|
|
5030
|
+
issues.push({ code: ROUTE_NETWORK_ISSUE.connectionCapacity, subject: c.id, params: { capacity: String(c.capacity) } });
|
|
5031
|
+
}
|
|
5032
|
+
if (classIds.size > 0) {
|
|
5033
|
+
for (const id of c.equipmentClassIds ?? []) {
|
|
5034
|
+
if (!classIds.has(id)) issues.push({ code: ROUTE_NETWORK_ISSUE.connectionUnknownClass, subject: c.id, params: { equipmentClassId: id } });
|
|
4747
5035
|
}
|
|
4748
|
-
},
|
|
4749
|
-
enums: { result: ["pass", "fail"] }
|
|
4750
|
-
},
|
|
4751
|
-
/*
|
|
4752
|
-
* **자리의 물리 관측** — 어느 자리의 어느 속성을 언제 얼마로 쟀나.
|
|
4753
|
-
*
|
|
4754
|
-
* 값에 **단위를 함께** 받는다(`ValueType`). 단위 없는 물리량은 판정의 재료가 못 된다 — 3 이 섭씨인지
|
|
4755
|
-
* 화씨인지 모르면 어떤 기준으로도 판정할 수 없다. 다만 **요구하지는 않는다**: 단위를 비우는 실 원본이
|
|
4756
|
-
* 흔하고, 요구하면 그 원본의 관측을 아예 담지 못한다(그때 판정은 커널이 거부한다 — `outsideLimit`).
|
|
4757
|
-
*
|
|
4758
|
-
* `effectiveTime` 도 요구하지 않는다. 없으면 봉투의 시각이 그 자리를 대신한다(§`resolve`) — 원본이
|
|
4759
|
-
* 시각을 말하지 않는 수기 점검이 실재하고, 그때 지어낸 시각보다 폴링 시각이 정직하다.
|
|
4760
|
-
*/
|
|
4761
|
-
/*
|
|
4762
|
-
* **이 목록이 전부다** — 연결된 시스템이 현재 목록을 한 바퀴 다 보낸 뒤 알린다.
|
|
4763
|
-
*
|
|
4764
|
-
* 둘 다 요구한다: 어느 목록인지와 그 주기를 **시작한** 시각. 시각이 없으면 무엇을 지울지 가릴 수
|
|
4765
|
-
* 없고, 그때 지우면 전부 지운다 — 받지 않는 것이 옳다.
|
|
4766
|
-
*/
|
|
4767
|
-
complete: {
|
|
4768
|
-
eventType: OP_EVENT.complete,
|
|
4769
|
-
match: ["completeAxis"],
|
|
4770
|
-
matchOrder: 100,
|
|
4771
|
-
identity: "completeAxis",
|
|
4772
|
-
required: ["completeAxis", "since"],
|
|
4773
|
-
fields: { completeAxis: "string", since: "string", recordTime: "string" }
|
|
4774
|
-
},
|
|
4775
|
-
observation: {
|
|
4776
|
-
eventType: OP_EVENT.observation,
|
|
4777
|
-
match: ["locationId", "propertyId"],
|
|
4778
|
-
matchOrder: 90,
|
|
4779
|
-
identity: "locationId",
|
|
4780
|
-
/* 자리와 속성 — 둘 중 하나가 없으면 그 관측은 아무 데도 붙지 못한다. */
|
|
4781
|
-
required: ["locationId", "propertyId"],
|
|
4782
|
-
fields: {
|
|
4783
|
-
locationId: "string",
|
|
4784
|
-
propertyId: "string",
|
|
4785
|
-
value: "string",
|
|
4786
|
-
dataType: "string",
|
|
4787
|
-
uom: "string",
|
|
4788
|
-
effectiveTime: "string",
|
|
4789
|
-
effectiveEndTime: "string",
|
|
4790
|
-
recordTime: "string",
|
|
4791
|
-
source: "string",
|
|
4792
|
-
derived: "boolean"
|
|
4793
5036
|
}
|
|
5037
|
+
for (const t of traversals(c)) {
|
|
5038
|
+
const key = `${t.from}\0${t.to}`;
|
|
5039
|
+
if (seenEnds.has(key)) issues.push({ code: ROUTE_NETWORK_ISSUE.connectionDuplicate, subject: c.id, params: { from: t.from, to: t.to } });
|
|
5040
|
+
seenEnds.add(key);
|
|
5041
|
+
}
|
|
5042
|
+
}
|
|
5043
|
+
const routeIds = /* @__PURE__ */ new Set();
|
|
5044
|
+
for (const r of def.fixedRoutes ?? []) {
|
|
5045
|
+
if (routeIds.has(r.id)) issues.push({ code: ROUTE_NETWORK_ISSUE.duplicateId, subject: r.id, params: { kind: "fixed-route" } });
|
|
5046
|
+
routeIds.add(r.id);
|
|
5047
|
+
if (!FIXED_ROUTE_BINDING.includes(r.binding)) {
|
|
5048
|
+
issues.push({ code: ROUTE_NETWORK_ISSUE.fixedBinding, subject: r.id, params: { binding: String(r.binding) } });
|
|
5049
|
+
}
|
|
5050
|
+
if (!r.connectionIds || r.connectionIds.length === 0) {
|
|
5051
|
+
issues.push({ code: ROUTE_NETWORK_ISSUE.fixedEmpty, subject: r.id, params: {} });
|
|
5052
|
+
continue;
|
|
5053
|
+
}
|
|
5054
|
+
const legs = [];
|
|
5055
|
+
for (const id of r.connectionIds) {
|
|
5056
|
+
const c = byId.get(id);
|
|
5057
|
+
if (!c) issues.push({ code: ROUTE_NETWORK_ISSUE.fixedUnknownConnection, subject: r.id, params: { connection: id } });
|
|
5058
|
+
else legs.push(c);
|
|
5059
|
+
}
|
|
5060
|
+
if (legs.length !== r.connectionIds.length) continue;
|
|
5061
|
+
let at2 = new Set(traversals(legs[0]).map((t) => t.to));
|
|
5062
|
+
for (let i = 1; i < legs.length; i++) {
|
|
5063
|
+
const next = new Set(traversals(legs[i]).filter((t) => at2.has(t.from)).map((t) => t.to));
|
|
5064
|
+
if (next.size === 0) {
|
|
5065
|
+
issues.push({ code: ROUTE_NETWORK_ISSUE.fixedBroken, subject: r.id, params: { after: legs[i - 1].id, connection: legs[i].id } });
|
|
5066
|
+
break;
|
|
5067
|
+
}
|
|
5068
|
+
at2 = next;
|
|
5069
|
+
}
|
|
5070
|
+
for (const classId of r.equipmentClassIds ?? []) {
|
|
5071
|
+
const blocked = legs.find((c) => !admits(c, [classId], def.equipmentClasses));
|
|
5072
|
+
if (blocked) issues.push({ code: ROUTE_NETWORK_ISSUE.fixedClass, subject: r.id, params: { equipmentClassId: classId, connection: blocked.id } });
|
|
5073
|
+
}
|
|
5074
|
+
}
|
|
5075
|
+
return issues;
|
|
5076
|
+
}
|
|
5077
|
+
function connectionAdmits(c, equipmentClassIds, classes) {
|
|
5078
|
+
return admits(c, equipmentClassIds, classes);
|
|
5079
|
+
}
|
|
5080
|
+
|
|
5081
|
+
// src/transport-policy.ts
|
|
5082
|
+
var DISPATCH_RULE = {
|
|
5083
|
+
/** The first available machine in the kernel's own order - what its assignment does today. */
|
|
5084
|
+
firstIdle: "firstIdle",
|
|
5085
|
+
/** The machine that reaches the pick-up soonest; ties by id. */
|
|
5086
|
+
minEta: "minEta"
|
|
5087
|
+
};
|
|
5088
|
+
var ROUTING_RULE = {
|
|
5089
|
+
/** Least travel time, reservations not considered. Connection time = length / effective speed. */
|
|
5090
|
+
shortestTime: "shortestTime",
|
|
5091
|
+
/** Least arrival time over time windows: a connection held past its capacity is waited for or avoided. */
|
|
5092
|
+
timeWindow: "timeWindow"
|
|
5093
|
+
};
|
|
5094
|
+
var TRAFFIC_CONFLICT_ACTION = ["wait", "replan", "yield"];
|
|
5095
|
+
var TRANSPORT_POLICY_ISSUE = {
|
|
5096
|
+
ruleMissing: "policy-rule-missing",
|
|
5097
|
+
ruleUnknown: "policy-rule-unknown",
|
|
5098
|
+
conflictAction: "policy-conflict-action",
|
|
5099
|
+
horizon: "policy-horizon",
|
|
5100
|
+
soc: "policy-soc",
|
|
5101
|
+
alternateUnknown: "policy-alternate-unknown",
|
|
5102
|
+
alternateSelf: "policy-alternate-self",
|
|
5103
|
+
alternateDuplicate: "policy-alternate-duplicate"
|
|
5104
|
+
};
|
|
5105
|
+
var isPercent = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0 && v <= 100;
|
|
5106
|
+
function validateTransportPolicy(policy, locationIds) {
|
|
5107
|
+
const issues = [];
|
|
5108
|
+
const known = { dispatch: Object.values(DISPATCH_RULE), routing: Object.values(ROUTING_RULE) };
|
|
5109
|
+
for (const part of ["dispatch", "routing"]) {
|
|
5110
|
+
const rule = policy[part]?.rule;
|
|
5111
|
+
if (typeof rule !== "string" || rule.trim() === "") issues.push({ code: TRANSPORT_POLICY_ISSUE.ruleMissing, params: { part } });
|
|
5112
|
+
else if (!known[part].includes(rule)) issues.push({ code: TRANSPORT_POLICY_ISSUE.ruleUnknown, params: { part, rule } });
|
|
5113
|
+
}
|
|
5114
|
+
if (!TRAFFIC_CONFLICT_ACTION.includes(policy.traffic?.onConflict)) {
|
|
5115
|
+
issues.push({ code: TRANSPORT_POLICY_ISSUE.conflictAction, params: { onConflict: String(policy.traffic?.onConflict) } });
|
|
5116
|
+
}
|
|
5117
|
+
const horizon = policy.traffic?.horizonS;
|
|
5118
|
+
if (horizon !== void 0 && !(typeof horizon === "number" && Number.isFinite(horizon) && horizon > 0)) {
|
|
5119
|
+
issues.push({ code: TRANSPORT_POLICY_ISSUE.horizon, params: { horizonS: String(horizon) } });
|
|
5120
|
+
}
|
|
5121
|
+
const { lowSoc, targetSoc } = policy.charging ?? {};
|
|
5122
|
+
if (!isPercent(lowSoc) || !isPercent(targetSoc) || lowSoc >= targetSoc) {
|
|
5123
|
+
issues.push({ code: TRANSPORT_POLICY_ISSUE.soc, params: { lowSoc: String(lowSoc), targetSoc: String(targetSoc) } });
|
|
5124
|
+
}
|
|
5125
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5126
|
+
for (const a of policy.alternates ?? []) {
|
|
5127
|
+
if (seen.has(a.destination)) issues.push({ code: TRANSPORT_POLICY_ISSUE.alternateDuplicate, params: { destination: a.destination } });
|
|
5128
|
+
seen.add(a.destination);
|
|
5129
|
+
if (a.alternatives.includes(a.destination)) issues.push({ code: TRANSPORT_POLICY_ISSUE.alternateSelf, params: { destination: a.destination } });
|
|
5130
|
+
if (locationIds) {
|
|
5131
|
+
for (const id of [a.destination, ...a.alternatives]) {
|
|
5132
|
+
if (!locationIds.has(id)) issues.push({ code: TRANSPORT_POLICY_ISSUE.alternateUnknown, params: { location: id } });
|
|
5133
|
+
}
|
|
5134
|
+
}
|
|
5135
|
+
}
|
|
5136
|
+
return issues;
|
|
5137
|
+
}
|
|
5138
|
+
|
|
5139
|
+
// src/asset-acceptance.ts
|
|
5140
|
+
function acceptsMaterial(accepts, query) {
|
|
5141
|
+
if (!accepts) return void 0;
|
|
5142
|
+
const defs = accepts.materialDefinitionIds ?? [];
|
|
5143
|
+
const classes = accepts.materialClassIds ?? [];
|
|
5144
|
+
const named = query.materialDefinitionId !== void 0 || (query.materialClassIds?.length ?? 0) > 0;
|
|
5145
|
+
if (!named) return void 0;
|
|
5146
|
+
let material;
|
|
5147
|
+
if (defs.length === 0 && classes.length === 0) material = void 0;
|
|
5148
|
+
else {
|
|
5149
|
+
const byDef = query.materialDefinitionId !== void 0 && defs.includes(query.materialDefinitionId);
|
|
5150
|
+
const byClass = (query.materialClassIds ?? []).some((id) => classes.includes(id));
|
|
5151
|
+
material = byDef || byClass;
|
|
5152
|
+
}
|
|
5153
|
+
if (material === false) return false;
|
|
5154
|
+
let quantity = true;
|
|
5155
|
+
if (query.quantity && accepts.maxQuantity) {
|
|
5156
|
+
quantity = query.quantity.uom === accepts.maxQuantity.uom ? query.quantity.value <= accepts.maxQuantity.value : void 0;
|
|
5157
|
+
}
|
|
5158
|
+
if (quantity === false) return false;
|
|
5159
|
+
if (material === void 0 || quantity === void 0) return void 0;
|
|
5160
|
+
return true;
|
|
5161
|
+
}
|
|
5162
|
+
|
|
5163
|
+
// src/face2-adapter.ts
|
|
5164
|
+
function isAggregationRecord(record) {
|
|
5165
|
+
if (!record || typeof record !== "object") return false;
|
|
5166
|
+
const r = record;
|
|
5167
|
+
return typeof r.parentID === "string" && r.parentID.trim().length > 0 && r.epc === void 0;
|
|
5168
|
+
}
|
|
5169
|
+
function isTransformationRecord(record) {
|
|
5170
|
+
if (!record || typeof record !== "object") return false;
|
|
5171
|
+
const r = record;
|
|
5172
|
+
if (r.epc !== void 0 || r.parentID !== void 0) return false;
|
|
5173
|
+
const has = (k) => Array.isArray(r[k]) && r[k].length > 0;
|
|
5174
|
+
return has("inputEPCList") || has("inputQuantityList") || has("outputEPCList") || has("outputQuantityList");
|
|
5175
|
+
}
|
|
5176
|
+
function get(obj, path) {
|
|
5177
|
+
return path.split(".").reduce((o, k) => o == null ? o : o[k], obj);
|
|
5178
|
+
}
|
|
5179
|
+
function resolve(v, record, field, errors) {
|
|
5180
|
+
if (v === void 0) return void 0;
|
|
5181
|
+
if (!v.startsWith("$.")) return v;
|
|
5182
|
+
const r = get(record, v.slice(2));
|
|
5183
|
+
if (r === void 0 || r === null) return void 0;
|
|
5184
|
+
if (typeof r === "object") {
|
|
5185
|
+
errors.push(`${field} \uAC00 \uAC12\uC774 \uC544\uB2C8\uB77C ${Array.isArray(r) ? "\uBC30\uC5F4" : "\uAC1D\uCCB4"}\uB85C \uC654\uB2E4(${v}) \u2014 \uCEE4\uB125\uD130\uAC00 \uD45C\uC900 \uAD6C\uC870\uB97C \uADF8\uB300\uB85C \uC2E4\uC5C8\uB2E4: ${JSON.stringify(r).slice(0, 80)}`);
|
|
5186
|
+
return void 0;
|
|
5187
|
+
}
|
|
5188
|
+
return String(r);
|
|
5189
|
+
}
|
|
5190
|
+
function resolveList(v, record, field, errors) {
|
|
5191
|
+
if (v === void 0) return [];
|
|
5192
|
+
const r = get(record, v.startsWith("$.") ? v.slice(2) : v);
|
|
5193
|
+
if (r === void 0 || r === null) return [];
|
|
5194
|
+
if (!Array.isArray(r) || r.some((x) => typeof x !== "string")) {
|
|
5195
|
+
errors.push(`${field} \uAC00 \uBB38\uC790\uC5F4 \uBC30\uC5F4\uC774 \uC544\uB2C8\uB2E4(${v}): ${JSON.stringify(r).slice(0, 80)}`);
|
|
5196
|
+
return [];
|
|
5197
|
+
}
|
|
5198
|
+
return r.slice();
|
|
5199
|
+
}
|
|
5200
|
+
function resolveQuantityList(v, record, field, errors) {
|
|
5201
|
+
if (v === void 0) return [];
|
|
5202
|
+
const r = get(record, v.startsWith("$.") ? v.slice(2) : v);
|
|
5203
|
+
if (r === void 0 || r === null) return [];
|
|
5204
|
+
if (!Array.isArray(r) || r.some((x) => !x || typeof x !== "object" || Array.isArray(x))) {
|
|
5205
|
+
errors.push(`${field} \uAC00 \uAC1D\uCCB4 \uBC30\uC5F4\uC774 \uC544\uB2C8\uB2E4(${v}): ${JSON.stringify(r).slice(0, 80)}`);
|
|
5206
|
+
return [];
|
|
5207
|
+
}
|
|
5208
|
+
return r.map((x) => ({ ...x }));
|
|
5209
|
+
}
|
|
5210
|
+
function resolveBizTransactionList(v, record, errors) {
|
|
5211
|
+
if (v === void 0) return [];
|
|
5212
|
+
const r = get(record, v.startsWith("$.") ? v.slice(2) : v);
|
|
5213
|
+
if (r === void 0 || r === null) return [];
|
|
5214
|
+
if (!Array.isArray(r) || r.some((x) => !x || typeof x !== "object" || Array.isArray(x))) {
|
|
5215
|
+
errors.push(`bizTransactionList \uAC00 \uAC1D\uCCB4 \uBC30\uC5F4\uC774 \uC544\uB2C8\uB2E4(${v}): ${JSON.stringify(r).slice(0, 80)}`);
|
|
5216
|
+
return [];
|
|
5217
|
+
}
|
|
5218
|
+
const out = [];
|
|
5219
|
+
for (const x of r) {
|
|
5220
|
+
if (typeof x.bizTransaction === "string" && x.bizTransaction.trim()) out.push({ ...x });
|
|
5221
|
+
else errors.push(`bizTransactionList \uC758 \uC6D0\uC18C\uC5D0 bizTransaction \uC774 \uC5C6\uB2E4: ${JSON.stringify(x).slice(0, 80)}`);
|
|
5222
|
+
}
|
|
5223
|
+
return out;
|
|
5224
|
+
}
|
|
5225
|
+
function resolveObject(v, record, field, errors) {
|
|
5226
|
+
if (v === void 0) return void 0;
|
|
5227
|
+
const r = get(record, v.startsWith("$.") ? v.slice(2) : v);
|
|
5228
|
+
if (r === void 0 || r === null) return void 0;
|
|
5229
|
+
if (typeof r !== "object" || Array.isArray(r)) {
|
|
5230
|
+
errors.push(`${field} \uAC00 \uAC1D\uCCB4\uAC00 \uC544\uB2C8\uB2E4(${v}): ${JSON.stringify(r).slice(0, 80)}`);
|
|
5231
|
+
return void 0;
|
|
5232
|
+
}
|
|
5233
|
+
const o = { ...r };
|
|
5234
|
+
return Object.keys(o).length ? o : void 0;
|
|
5235
|
+
}
|
|
5236
|
+
function resolveErrorDeclaration(spec, record, errors) {
|
|
5237
|
+
if (!spec) return void 0;
|
|
5238
|
+
const declarationTime = resolve(spec.declarationTime, record, "errorDeclaration.declarationTime", errors);
|
|
5239
|
+
const reason = resolve(spec.reason, record, "errorDeclaration.reason", errors);
|
|
5240
|
+
const correctiveEventIDs = resolveList(spec.correctiveEventIDs, record, "errorDeclaration.correctiveEventIDs", errors);
|
|
5241
|
+
if (!declarationTime) {
|
|
5242
|
+
if (reason || correctiveEventIDs.length) {
|
|
5243
|
+
errors.push("errorDeclaration\uC5D0 \uC815\uC815 \uC0AC\uC720 \uB610\uB294 \uB300\uC0C1\uC774 \uC788\uC9C0\uB9CC \uC815\uC815 \uC2DC\uAC01(declarationTime)\uC774 \uC5C6\uC2B5\uB2C8\uB2E4.");
|
|
5244
|
+
}
|
|
5245
|
+
return void 0;
|
|
5246
|
+
}
|
|
5247
|
+
return {
|
|
5248
|
+
declarationTime,
|
|
5249
|
+
...reason ? { reason } : {},
|
|
5250
|
+
...correctiveEventIDs.length ? { correctiveEventIDs } : {}
|
|
5251
|
+
};
|
|
5252
|
+
}
|
|
5253
|
+
function mapRecordChecked(record, mapping, eventTime) {
|
|
5254
|
+
const errors = [];
|
|
5255
|
+
const bizStep = resolve(mapping.bizStep, record, "bizStep", errors) ?? "";
|
|
5256
|
+
const disposition = resolve(mapping.disposition, record, "disposition", errors);
|
|
5257
|
+
const readPoint = resolve(mapping.readPoint, record, "readPoint", errors);
|
|
5258
|
+
const bizLocation = resolve(mapping.bizLocation, record, "bizLocation", errors);
|
|
5259
|
+
const errorDeclaration = resolveErrorDeclaration(mapping.errorDeclaration, record, errors);
|
|
5260
|
+
const bizTransactionList = resolveBizTransactionList(mapping.bizTransactionList, record, errors);
|
|
5261
|
+
if (mapping.type === "TransformationEvent") {
|
|
5262
|
+
const inputEPCList = resolveList(mapping.inputEPCList, record, "inputEPCList", errors);
|
|
5263
|
+
const inputQuantityList = resolveQuantityList(mapping.inputQuantityList, record, "inputQuantityList", errors);
|
|
5264
|
+
const outputEPCList = resolveList(mapping.outputEPCList, record, "outputEPCList", errors);
|
|
5265
|
+
const outputQuantityList = resolveQuantityList(mapping.outputQuantityList, record, "outputQuantityList", errors);
|
|
5266
|
+
const transformationID = resolve(mapping.transformationID, record, "transformationID", errors);
|
|
5267
|
+
if (!inputEPCList.length && !inputQuantityList.length) {
|
|
5268
|
+
errors.push("\uBCC0\uD658 \uC774\uBCA4\uD2B8\uC5D0 \uC785\uB825 \uD56D\uBAA9\uC774 \uD544\uC694\uD569\uB2C8\uB2E4.(EPCIS 2.0 \xA77.4.5)");
|
|
5269
|
+
}
|
|
5270
|
+
if (!outputEPCList.length && !outputQuantityList.length) {
|
|
5271
|
+
errors.push("\uBCC0\uD658 \uC774\uBCA4\uD2B8\uC5D0 \uCD9C\uB825 \uD56D\uBAA9\uC774 \uD544\uC694\uD569\uB2C8\uB2E4.(EPCIS 2.0 \xA77.4.5)");
|
|
5272
|
+
}
|
|
5273
|
+
return {
|
|
5274
|
+
event: transformationEvent({
|
|
5275
|
+
eventTime,
|
|
5276
|
+
bizStep,
|
|
5277
|
+
disposition,
|
|
5278
|
+
/* 없는 쪽은 **필드를 만들지 않는다** — 빈 배열을 실으면 「없다」고 말하는 것이 된다.
|
|
5279
|
+
개체로 말한 쪽과 수량으로 말한 쪽 중 하나만 쓰는 것이 정상이다. */
|
|
5280
|
+
...inputEPCList.length ? { inputEPCList } : {},
|
|
5281
|
+
...inputQuantityList.length ? { inputQuantityList } : {},
|
|
5282
|
+
...outputEPCList.length ? { outputEPCList } : {},
|
|
5283
|
+
...outputQuantityList.length ? { outputQuantityList } : {},
|
|
5284
|
+
...transformationID ? { transformationID } : {},
|
|
5285
|
+
...errorDeclaration ? { errorDeclaration } : {},
|
|
5286
|
+
...bizTransactionList.length ? { bizTransactionList } : {},
|
|
5287
|
+
readPoint,
|
|
5288
|
+
bizLocation
|
|
5289
|
+
}),
|
|
5290
|
+
errors
|
|
5291
|
+
};
|
|
5292
|
+
}
|
|
5293
|
+
if (mapping.type === "AggregationEvent") {
|
|
5294
|
+
const action2 = resolve(mapping.action, record, "action", errors) ?? "";
|
|
5295
|
+
const parentID = resolve(mapping.parentID, record, "parentID", errors) ?? "";
|
|
5296
|
+
const childEPCs = resolveList(mapping.childEPCs, record, "childEPCs", errors);
|
|
5297
|
+
const childQuantityList = resolveQuantityList(mapping.childQuantityList, record, "childQuantityList", errors);
|
|
5298
|
+
return {
|
|
5299
|
+
event: aggregationEvent({
|
|
5300
|
+
eventTime,
|
|
5301
|
+
action: action2,
|
|
5302
|
+
bizStep,
|
|
5303
|
+
disposition,
|
|
5304
|
+
parentID,
|
|
5305
|
+
/* 없는 쪽은 **필드를 만들지 않는다** — 빈 배열을 실으면 「자식이 없다」고 말하는 것이 된다. */
|
|
5306
|
+
...childEPCs.length ? { childEPCs } : {},
|
|
5307
|
+
...childQuantityList.length ? { childQuantityList } : {},
|
|
5308
|
+
...errorDeclaration ? { errorDeclaration } : {},
|
|
5309
|
+
...bizTransactionList.length ? { bizTransactionList } : {},
|
|
5310
|
+
readPoint,
|
|
5311
|
+
bizLocation
|
|
5312
|
+
}),
|
|
5313
|
+
errors
|
|
5314
|
+
};
|
|
4794
5315
|
}
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
const present = (k) => {
|
|
4801
|
-
const v = r[k];
|
|
4802
|
-
if (v === void 0 || v === null) return false;
|
|
4803
|
-
return typeof v === "string" ? v.trim().length > 0 : true;
|
|
4804
|
-
};
|
|
4805
|
-
for (const kind of MATCH_ORDER) {
|
|
4806
|
-
const spec = SPECS[kind];
|
|
4807
|
-
const fields = spec.match ?? [spec.identity];
|
|
4808
|
-
if (fields.every(present)) return kind;
|
|
5316
|
+
const action = resolve(mapping.action, record, "action", errors) ?? "";
|
|
5317
|
+
const epc = resolve(mapping.epc, record, "epc", errors);
|
|
5318
|
+
const quantityList = resolveQuantityList(mapping.quantityList, record, "quantityList", errors);
|
|
5319
|
+
if (!epc && !quantityList.length) {
|
|
5320
|
+
errors.push("epc \uB610\uB294 quantityList\uAC00 \uD544\uC694\uD569\uB2C8\uB2E4. \uAC1C\uCCB4 \uC2DD\uBCC4\uC790\uB098 \uD074\uB798\uC2A4\xB7\uC218\uB7C9\uC744 \uC9C0\uC815\uD558\uC138\uC694.");
|
|
4809
5321
|
}
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
}
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
|
|
4824
|
-
|
|
5322
|
+
const ilmd = resolveObject(mapping.ilmd, record, "ilmd", errors);
|
|
5323
|
+
return {
|
|
5324
|
+
event: objectEvent({
|
|
5325
|
+
eventTime,
|
|
5326
|
+
action,
|
|
5327
|
+
bizStep,
|
|
5328
|
+
disposition,
|
|
5329
|
+
epcList: epc ? [epc] : [],
|
|
5330
|
+
...quantityList.length ? { quantityList } : {},
|
|
5331
|
+
...ilmd ? { ilmd } : {},
|
|
5332
|
+
...errorDeclaration ? { errorDeclaration } : {},
|
|
5333
|
+
...bizTransactionList.length ? { bizTransactionList } : {},
|
|
5334
|
+
readPoint,
|
|
5335
|
+
bizLocation
|
|
5336
|
+
}),
|
|
5337
|
+
errors
|
|
5338
|
+
};
|
|
4825
5339
|
}
|
|
4826
|
-
function
|
|
4827
|
-
return
|
|
5340
|
+
function mapRecord(record, mapping, eventTime) {
|
|
5341
|
+
return mapRecordChecked(record, mapping, eventTime).event;
|
|
4828
5342
|
}
|
|
4829
|
-
function
|
|
4830
|
-
const
|
|
5343
|
+
function ingest(records, rules, opts) {
|
|
5344
|
+
const ruleByType = new Map(rules.map((r) => [r.sourceType, r]));
|
|
4831
5345
|
const accepted = [];
|
|
4832
5346
|
const rejected = [];
|
|
4833
5347
|
let seq = 0;
|
|
4834
|
-
for (const record of
|
|
4835
|
-
const
|
|
4836
|
-
if (!
|
|
4837
|
-
rejected.push({ record, errors: [
|
|
5348
|
+
for (const record of records) {
|
|
5349
|
+
const rule = ruleByType.get(String(record["sourceType"]));
|
|
5350
|
+
if (!rule) {
|
|
5351
|
+
rejected.push({ record, errors: [`\uC77C\uCE58\uD558\uB294 \uB9E4\uD551 \uADDC\uCE59 \uC5C6\uC74C: sourceType=${record["sourceType"]}`] });
|
|
4838
5352
|
continue;
|
|
4839
5353
|
}
|
|
4840
|
-
const
|
|
4841
|
-
const
|
|
4842
|
-
const errors =
|
|
4843
|
-
const
|
|
4844
|
-
const unknown = Object.keys(r).filter((k) => !ENVELOPE_FIELDS.includes(k) && spec.fields[k] === void 0);
|
|
4845
|
-
if (unknown.length) errors.push(`${kind}: \uACC4\uC57D\uC5D0 \uC5C6\uB294 \uD544\uB4DC \u2014 ${unknown.join(", ")}`);
|
|
4846
|
-
for (const name of spec.required) {
|
|
4847
|
-
const v = r[name];
|
|
4848
|
-
if (v === void 0 || v === null || v === "") errors.push(`${kind}: ${name}: \uD544\uC218 \uAC12 \uB204\uB77D`);
|
|
4849
|
-
}
|
|
4850
|
-
const data = {};
|
|
4851
|
-
for (const [name, type] of Object.entries(spec.fields)) {
|
|
4852
|
-
const v = r[name];
|
|
4853
|
-
if (v === void 0 || v === null || v === "") continue;
|
|
4854
|
-
switch (type) {
|
|
4855
|
-
case "string": {
|
|
4856
|
-
if (typeof v !== "string") {
|
|
4857
|
-
errors.push(`${kind}.${name} \uAC12\uC740 \uBB38\uC790\uC5F4\uC774\uC5B4\uC57C \uD569\uB2C8\uB2E4: ${JSON.stringify(v)}`);
|
|
4858
|
-
break;
|
|
4859
|
-
}
|
|
4860
|
-
const allowed = spec.enums?.[name];
|
|
4861
|
-
if (allowed && !allowed.includes(v)) {
|
|
4862
|
-
errors.push(`${kind}.${name}\uC5D0 \uD5C8\uC6A9\uB418\uC9C0 \uC54A\uB294 \uAC12\uC774 \uC9C0\uC815\uB418\uC5C8\uC2B5\uB2C8\uB2E4: ${JSON.stringify(v)} \u2014 \uD5C8\uC6A9 \uAC12: ${allowed.join(" \xB7 ")}`);
|
|
4863
|
-
break;
|
|
4864
|
-
}
|
|
4865
|
-
data[name] = v;
|
|
4866
|
-
break;
|
|
4867
|
-
}
|
|
4868
|
-
case "number": {
|
|
4869
|
-
const n = Number(v);
|
|
4870
|
-
if (typeof v === "boolean" || !Number.isFinite(n)) {
|
|
4871
|
-
errors.push(`${kind}.${name} \uAC12\uC740 \uC720\uD55C\uD55C \uC22B\uC790\uC5EC\uC57C \uD569\uB2C8\uB2E4: ${JSON.stringify(v)}`);
|
|
4872
|
-
break;
|
|
4873
|
-
}
|
|
4874
|
-
if (name === "progress" && (n < 0 || n > 1)) {
|
|
4875
|
-
errors.push(`${kind}.progress \uB294 0~1 \uBE44\uC728\uC774\uB2E4: ${n}`);
|
|
4876
|
-
break;
|
|
4877
|
-
}
|
|
4878
|
-
if ((name === "requested" || name === "fulfilled" || name === "goodCount" || name === "nonconformingCount") && n < 0) {
|
|
4879
|
-
errors.push(`${kind}.${name} \uAC00 \uC74C\uC218\uB2E4: ${n}`);
|
|
4880
|
-
break;
|
|
4881
|
-
}
|
|
4882
|
-
data[name] = n;
|
|
4883
|
-
break;
|
|
4884
|
-
}
|
|
4885
|
-
case "boolean": {
|
|
4886
|
-
if (typeof v !== "boolean") {
|
|
4887
|
-
errors.push(`${kind}.${name} \uAC12\uC740 \uBD88\uB9AC\uC5B8\uC774\uC5B4\uC57C \uD569\uB2C8\uB2E4: ${JSON.stringify(v)}`);
|
|
4888
|
-
break;
|
|
4889
|
-
}
|
|
4890
|
-
data[name] = v;
|
|
4891
|
-
break;
|
|
4892
|
-
}
|
|
4893
|
-
case "string[]": {
|
|
4894
|
-
if (!Array.isArray(v) || v.some((x) => typeof x !== "string")) {
|
|
4895
|
-
errors.push(`${kind}.${name} \uAC12\uC740 \uBB38\uC790\uC5F4 \uBC30\uC5F4\uC774\uC5B4\uC57C \uD569\uB2C8\uB2E4: ${JSON.stringify(v)}`);
|
|
4896
|
-
break;
|
|
4897
|
-
}
|
|
4898
|
-
data[name] = v.slice();
|
|
4899
|
-
break;
|
|
4900
|
-
}
|
|
4901
|
-
case "object": {
|
|
4902
|
-
if (Array.isArray(v) || typeof v !== "object") {
|
|
4903
|
-
errors.push(`${kind}.${name} \uAC12\uC740 \uAC1D\uCCB4\uC5EC\uC57C \uD569\uB2C8\uB2E4: ${JSON.stringify(v)}`);
|
|
4904
|
-
break;
|
|
4905
|
-
}
|
|
4906
|
-
errors.push(...shapeErrors(`${kind}.${name}`, v, spec.shapes?.[name]));
|
|
4907
|
-
data[name] = { ...v };
|
|
4908
|
-
break;
|
|
4909
|
-
}
|
|
4910
|
-
case "object[]": {
|
|
4911
|
-
if (!Array.isArray(v) || v.some((x) => !x || typeof x !== "object")) {
|
|
4912
|
-
errors.push(`${kind}.${name} \uAC12\uC740 \uAC1D\uCCB4 \uBC30\uC5F4\uC774\uC5B4\uC57C \uD569\uB2C8\uB2E4: ${JSON.stringify(v)}`);
|
|
4913
|
-
break;
|
|
4914
|
-
}
|
|
4915
|
-
v.forEach(
|
|
4916
|
-
(x, i) => errors.push(...shapeErrors(`${kind}.${name}[${i}]`, x, spec.shapes?.[name]))
|
|
4917
|
-
);
|
|
4918
|
-
data[name] = v.map((x) => ({ ...x }));
|
|
4919
|
-
break;
|
|
4920
|
-
}
|
|
4921
|
-
}
|
|
4922
|
-
}
|
|
4923
|
-
if ((kind === "task" || kind === "equipment-period") && r.workShiftBasis !== void 0) {
|
|
4924
|
-
if (!isWorkShiftExecutionBasis(r.workShiftBasis) || kind === "equipment-period" && Date.parse(r.workShiftBasis.businessTime) !== Date.parse(String(r.from)) || kind === "task" && (r.startTime ?? r.endTime) !== void 0 && Date.parse(r.workShiftBasis.businessTime) !== Date.parse(String(r.startTime ?? r.endTime))) {
|
|
4925
|
-
errors.push(kind + ".workShiftBasis: invalid pinned shift evidence");
|
|
4926
|
-
} else data.workShiftBasis = structuredClone(r.workShiftBasis);
|
|
4927
|
-
}
|
|
4928
|
-
if (kind === "test" && r.specificationBasis !== void 0 && !isTestSpecificationBasis(r.specificationBasis)) {
|
|
4929
|
-
errors.push("test.specificationBasis: invalid pinned specification evidence");
|
|
4930
|
-
}
|
|
4931
|
-
if (kind === "order" && r.materialBasis !== void 0) {
|
|
4932
|
-
const bases = r.materialBasis;
|
|
4933
|
-
if (!Array.isArray(bases) || !bases.length || bases.length > 1e3 || !bases.every(isMaterialExecutionBasis) || new Set(bases.map((b) => b.material.id)).size !== bases.length || r.gtin !== void 0 && !bases.some((b) => b.material.id === r.gtin) || isRecipeExecutionBasis(r.recipeBasis) && [...r.recipeBasis.recipe.inputs, ...r.recipeBasis.recipe.outputs].some((line) => !bases.some((b) => b.material.id === line.material)))
|
|
4934
|
-
errors.push("order.materialBasis: invalid pinned material evidence");
|
|
4935
|
-
}
|
|
4936
|
-
if (kind === "order" && r.recipeBasis !== void 0 && (!isRecipeExecutionBasis(r.recipeBasis) || r.recipeKey !== void 0 && r.recipeKey !== r.recipeBasis.recipe.key)) {
|
|
4937
|
-
errors.push("order.recipeBasis: invalid pinned recipe evidence");
|
|
4938
|
-
}
|
|
4939
|
-
const closedPeriodEnd = kind === "equipment-period" ? String(r.to ?? "").trim() : "";
|
|
4940
|
-
const at2 = closedPeriodEnd || String(r.at ?? "").trim() || opts.defaultEventTime;
|
|
4941
|
-
const atMs = at2 ? Date.parse(at2) : Number.NaN;
|
|
4942
|
-
if (!Number.isFinite(atMs)) {
|
|
4943
|
-
errors.push(`${kind}: at \uC5C6\uC74C/\uD615\uC2DD \uC624\uB958 \u2014 \uC774\uC804 \uC774\uBCA4\uD2B8\uAC00 \uB4A4\uB2A6\uAC8C \uB3C4\uCC29\uD588\uB294\uC9C0 \uD310\uB2E8\uD558\uB824\uBA74 \uC2DC\uAC01\uC774 \uD544\uC694\uD569\uB2C8\uB2E4.`);
|
|
4944
|
-
}
|
|
4945
|
-
if (closedPeriodEnd && opts.defaultEventTime) {
|
|
4946
|
-
const nowMs = Date.parse(opts.defaultEventTime);
|
|
4947
|
-
if (Number.isFinite(nowMs) && Number.isFinite(atMs) && atMs > nowMs) {
|
|
4948
|
-
errors.push(`${kind}: \uC544\uC9C1 \uC624\uC9C0 \uC54A\uC740 \uC2DC\uAC01\uC758 \uC0AC\uC2E4\uC774\uB2E4(${closedPeriodEnd}) \u2014 \uC885\uB8CC\uB41C \uAD6C\uAC04\uB9CC \uB9C8\uAC10\uD560 \uC218 \uC788\uC2B5\uB2C8\uB2E4.`);
|
|
4949
|
-
}
|
|
4950
|
-
}
|
|
5354
|
+
const timeErrors = [];
|
|
5355
|
+
const eventTime = (opts.eventTimePath ? resolve("$." + opts.eventTimePath, record, "eventTime", timeErrors) : void 0) ?? opts.defaultEventTime;
|
|
5356
|
+
const { event: ev, errors: mapErrors } = mapRecordChecked(record, rule.mapping, eventTime);
|
|
5357
|
+
const errors = [...timeErrors, ...mapErrors, ...validateEpcisEvent(ev)];
|
|
4951
5358
|
if (errors.length) {
|
|
4952
5359
|
rejected.push({ record, errors });
|
|
4953
5360
|
continue;
|
|
4954
5361
|
}
|
|
4955
|
-
const note = typeof
|
|
5362
|
+
const note = typeof record["description"] === "string" ? String(record["description"]).trim() : "";
|
|
4956
5363
|
accepted.push({
|
|
4957
|
-
eventId: `${opts.tenantId}-
|
|
4958
|
-
eventType:
|
|
4959
|
-
eventTime:
|
|
5364
|
+
eventId: `${opts.tenantId}-ingest-${++seq}`,
|
|
5365
|
+
eventType: `epcis.${ev.type}`,
|
|
5366
|
+
eventTime: ev.eventTime,
|
|
4960
5367
|
tenantId: opts.tenantId,
|
|
4961
5368
|
...note ? { description: note } : {},
|
|
4962
|
-
data
|
|
5369
|
+
data: ev
|
|
4963
5370
|
});
|
|
4964
5371
|
}
|
|
4965
5372
|
return { accepted, rejected };
|
|
4966
5373
|
}
|
|
4967
5374
|
|
|
5375
|
+
// src/iso-duration.ts
|
|
5376
|
+
var RE = /^(-)?P(?:(\d+(?:\.\d+)?)W)?(?:(\d+(?:\.\d+)?)D)?(?:T(?:(\d+(?:\.\d+)?)H)?(?:(\d+(?:\.\d+)?)M)?(?:(\d+(?:\.\d+)?)S)?)?$/;
|
|
5377
|
+
function parseIsoDuration(text) {
|
|
5378
|
+
if (typeof text !== "string") return void 0;
|
|
5379
|
+
const s = text.trim();
|
|
5380
|
+
if (!s || s === "P" || s === "PT") return void 0;
|
|
5381
|
+
if (/\d+Y/.test(s)) return void 0;
|
|
5382
|
+
const tIdx = s.indexOf("T");
|
|
5383
|
+
const datePart = tIdx === -1 ? s : s.slice(0, tIdx);
|
|
5384
|
+
if (/\d+M/.test(datePart)) return void 0;
|
|
5385
|
+
const m = RE.exec(s);
|
|
5386
|
+
if (!m) return void 0;
|
|
5387
|
+
const [, sign, w, d, h, min, sec] = m;
|
|
5388
|
+
if (!w && !d && !h && !min && !sec) return void 0;
|
|
5389
|
+
const ms = (Number(w ?? 0) * 7 + Number(d ?? 0)) * 864e5 + Number(h ?? 0) * 36e5 + Number(min ?? 0) * 6e4 + Number(sec ?? 0) * 1e3;
|
|
5390
|
+
if (!Number.isFinite(ms)) return void 0;
|
|
5391
|
+
return sign ? -ms : ms;
|
|
5392
|
+
}
|
|
5393
|
+
|
|
5394
|
+
// src/master-data.ts
|
|
5395
|
+
var VOCABULARY_TYPE = {
|
|
5396
|
+
/** 품목·로트 클래스의 속성 — 유통기한·로트번호가 여기 온다. */
|
|
5397
|
+
epcClass: "urn:epcglobal:epcis:vtype:EPCClass",
|
|
5398
|
+
/** 관측 지점의 속성. */
|
|
5399
|
+
readPoint: "urn:epcglobal:epcis:vtype:ReadPoint",
|
|
5400
|
+
/** 업무 자리의 속성. */
|
|
5401
|
+
bizLocation: "urn:epcglobal:epcis:vtype:BizLocation"
|
|
5402
|
+
};
|
|
5403
|
+
function isMasterDataRecord(record) {
|
|
5404
|
+
if (!record || typeof record !== "object") return false;
|
|
5405
|
+
const r = record;
|
|
5406
|
+
return typeof r.vocabularyType === "string" && !!r.vocabularyType && typeof r.id === "string" && !!r.id && isPlainObject(r.attributes);
|
|
5407
|
+
}
|
|
5408
|
+
function isPlainObject(v) {
|
|
5409
|
+
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
5410
|
+
}
|
|
5411
|
+
function ingestMasterData(records) {
|
|
5412
|
+
const arr = Array.isArray(records) ? records : records ? [records] : [];
|
|
5413
|
+
const accepted = [];
|
|
5414
|
+
const rejected = [];
|
|
5415
|
+
for (const r of arr) {
|
|
5416
|
+
const errors = [];
|
|
5417
|
+
if (!isMasterDataRecord(r)) errors.push("vocabularyType, id, attributes\uB97C \uC9C0\uC815\uD574\uC57C \uD569\uB2C8\uB2E4.");
|
|
5418
|
+
else if (!Object.keys(r.attributes).length) errors.push("attributes\uC5D0 \uC18D\uC131\uC744 \uD558\uB098 \uC774\uC0C1 \uC9C0\uC815\uD574\uC57C \uD569\uB2C8\uB2E4.");
|
|
5419
|
+
if (errors.length) rejected.push({ record: r, errors });
|
|
5420
|
+
else accepted.push({ vocabularyType: r.vocabularyType, id: r.id, attributes: { ...r.attributes } });
|
|
5421
|
+
}
|
|
5422
|
+
return { accepted, rejected };
|
|
5423
|
+
}
|
|
5424
|
+
function expiryFromAttributes(attrs) {
|
|
5425
|
+
return readEpochMs(attrs?.[ILMD_ATTR.expiry]);
|
|
5426
|
+
}
|
|
5427
|
+
function lotFromAttributes(attrs) {
|
|
5428
|
+
const v = attrs?.[ILMD_ATTR.lot];
|
|
5429
|
+
return typeof v === "string" && v.trim() ? v.trim() : void 0;
|
|
5430
|
+
}
|
|
5431
|
+
function readEpochMs(raw) {
|
|
5432
|
+
if (typeof raw === "number") return Number.isFinite(raw) ? raw : void 0;
|
|
5433
|
+
if (typeof raw !== "string" || !raw.trim()) return void 0;
|
|
5434
|
+
const at2 = Date.parse(raw);
|
|
5435
|
+
return Number.isNaN(at2) ? void 0 : at2;
|
|
5436
|
+
}
|
|
5437
|
+
|
|
4968
5438
|
// src/operations-capability.ts
|
|
4969
5439
|
function workingHoursBetween(calendar, fromMs, toMs, utcOffsetMinutes) {
|
|
4970
5440
|
if (!(toMs > fromMs)) return 0;
|
|
@@ -6126,7 +6596,10 @@ function inheritedExpiry(inputExpiries) {
|
|
|
6126
6596
|
COMMAND_EVENT,
|
|
6127
6597
|
COMMAND_ORIGIN,
|
|
6128
6598
|
COMMAND_STATE,
|
|
6599
|
+
CONNECTION_DIRECTION,
|
|
6600
|
+
DEFAULT_CONNECTION_CAPACITY,
|
|
6129
6601
|
DISP,
|
|
6602
|
+
DISPATCH_RULE,
|
|
6130
6603
|
DISPOSITION_DECISION,
|
|
6131
6604
|
DOCK_DOOR_STATUS,
|
|
6132
6605
|
DOCK_FACT_KIND,
|
|
@@ -6142,14 +6615,24 @@ function inheritedExpiry(inputExpiries) {
|
|
|
6142
6615
|
EPCIS_CONTEXT,
|
|
6143
6616
|
EPCIS_EVENT,
|
|
6144
6617
|
EQUIPMENT_LEVEL,
|
|
6618
|
+
EQUIPMENT_PROPERTY,
|
|
6145
6619
|
EQUIPMENT_STATUS,
|
|
6146
6620
|
ERP_CAPABILITY,
|
|
6147
6621
|
ERP_MASTER_AXIS,
|
|
6148
6622
|
FIELDS_NOT_CARRIED,
|
|
6149
6623
|
FIRST_PASS_RULE,
|
|
6624
|
+
FIXED_ROUTE_BINDING,
|
|
6150
6625
|
GUARD_PRAGMA,
|
|
6151
6626
|
HATIOLAB_VOCABULARY,
|
|
6152
6627
|
HEADER_FIELDS_PARTITIONED,
|
|
6628
|
+
ILG_ATTENTION_KIND,
|
|
6629
|
+
ILG_BIZSTEP,
|
|
6630
|
+
ILG_EQUIPMENT_PROPERTY,
|
|
6631
|
+
ILG_LOCATION_TYPES,
|
|
6632
|
+
ILG_ORDER_KIND,
|
|
6633
|
+
ILG_ROBOT_IDENTITY_PROPERTY,
|
|
6634
|
+
ILG_TASK_KIND,
|
|
6635
|
+
ILG_TYPES,
|
|
6153
6636
|
ILMD_ATTR,
|
|
6154
6637
|
LOCATION_SATURATION_NEAR,
|
|
6155
6638
|
MATERIAL_ACTUAL_USE,
|
|
@@ -6174,6 +6657,7 @@ function inheritedExpiry(inputExpiries) {
|
|
|
6174
6657
|
PARTY_ROLE,
|
|
6175
6658
|
PARTY_URI_MAX_LENGTH,
|
|
6176
6659
|
PARTY_URI_RECOMMENDED_LENGTH,
|
|
6660
|
+
PERCENT_UOM,
|
|
6177
6661
|
PERSON_STATUS,
|
|
6178
6662
|
PRIORITY_UNSET,
|
|
6179
6663
|
PRIVATE_BIZSTEP,
|
|
@@ -6183,15 +6667,23 @@ function inheritedExpiry(inputExpiries) {
|
|
|
6183
6667
|
RESOURCE_KIND,
|
|
6184
6668
|
RETIRED_VOCABULARY,
|
|
6185
6669
|
RETURN_TO_SUPPLIER,
|
|
6670
|
+
ROUTE_NETWORK_ISSUE,
|
|
6671
|
+
ROUTING_RULE,
|
|
6186
6672
|
SCHEDULE_STATUS,
|
|
6187
6673
|
SIGNATURE_REJECTED_REASONS,
|
|
6188
6674
|
SOURCE_DEST_PARTY_TYPE,
|
|
6675
|
+
SPEED_TO_MPS,
|
|
6189
6676
|
TARIFF_DAY_KINDS,
|
|
6190
6677
|
TARIFF_ISSUE_CODES,
|
|
6191
6678
|
TARIFF_LOAD_CLASSES,
|
|
6192
6679
|
TASK_STATUS,
|
|
6193
6680
|
TASK_TERMINAL_STATUS,
|
|
6681
|
+
TRAFFIC_CONFLICT_ACTION,
|
|
6194
6682
|
TRAILER_LOAD,
|
|
6683
|
+
TRANSPORT_FAILURE_REASON,
|
|
6684
|
+
TRANSPORT_POLICY_ISSUE,
|
|
6685
|
+
TRAVEL_LINK_JUDGED_BY,
|
|
6686
|
+
TRAVEL_LINK_STATE,
|
|
6195
6687
|
TWIN_AXES,
|
|
6196
6688
|
TWIN_PROPERTIES,
|
|
6197
6689
|
TWIN_RELATIONS,
|
|
@@ -6218,6 +6710,7 @@ function inheritedExpiry(inputExpiries) {
|
|
|
6218
6710
|
YMS_ORDER_KIND,
|
|
6219
6711
|
YMS_TASK_KIND,
|
|
6220
6712
|
YMS_TYPES,
|
|
6713
|
+
acceptsMaterial,
|
|
6221
6714
|
acceptsPerformance,
|
|
6222
6715
|
activeBands,
|
|
6223
6716
|
activeShiftAt,
|
|
@@ -6249,6 +6742,7 @@ function inheritedExpiry(inputExpiries) {
|
|
|
6249
6742
|
computeMtbf,
|
|
6250
6743
|
computeMttr,
|
|
6251
6744
|
computeOee,
|
|
6745
|
+
connectionAdmits,
|
|
6252
6746
|
conversionFactorOf,
|
|
6253
6747
|
criterionSaysNothing,
|
|
6254
6748
|
dayOfYearOf,
|
|
@@ -6294,6 +6788,7 @@ function inheritedExpiry(inputExpiries) {
|
|
|
6294
6788
|
ingestOperationalRecords,
|
|
6295
6789
|
inheritedExpiry,
|
|
6296
6790
|
inheritedLotUse,
|
|
6791
|
+
intralogisticsTypeOf,
|
|
6297
6792
|
isAggregationRecord,
|
|
6298
6793
|
isAppointmentClosed,
|
|
6299
6794
|
isCacheableTense,
|
|
@@ -6313,6 +6808,8 @@ function inheritedExpiry(inputExpiries) {
|
|
|
6313
6808
|
isEquipmentStatus,
|
|
6314
6809
|
isFailureStatus,
|
|
6315
6810
|
isFlowOrder,
|
|
6811
|
+
isGuidedType,
|
|
6812
|
+
isHeading,
|
|
6316
6813
|
isIso4217Code,
|
|
6317
6814
|
isIsoDateTime,
|
|
6318
6815
|
isMasterDataRecord,
|
|
@@ -6331,6 +6828,8 @@ function inheritedExpiry(inputExpiries) {
|
|
|
6331
6828
|
isTaskTerminal,
|
|
6332
6829
|
isTestSpecificationBasis,
|
|
6333
6830
|
isTransformationRecord,
|
|
6831
|
+
isTransportFailureReason,
|
|
6832
|
+
isTravelRecord,
|
|
6334
6833
|
isWebhookDeliveryCode,
|
|
6335
6834
|
isWebhookSecretSegment,
|
|
6336
6835
|
isWorkShiftExecutionBasis,
|
|
@@ -6344,6 +6843,7 @@ function inheritedExpiry(inputExpiries) {
|
|
|
6344
6843
|
judgeAgainstSpec,
|
|
6345
6844
|
levelOfLocationType,
|
|
6346
6845
|
lgtinClass,
|
|
6846
|
+
linkStateAt,
|
|
6347
6847
|
localDayIndexAt,
|
|
6348
6848
|
localDayStartMs,
|
|
6349
6849
|
locationStatusOf,
|
|
@@ -6409,6 +6909,7 @@ function inheritedExpiry(inputExpiries) {
|
|
|
6409
6909
|
sameItemClass,
|
|
6410
6910
|
sgtinClass,
|
|
6411
6911
|
sgtinUri,
|
|
6912
|
+
speedMpsOf,
|
|
6412
6913
|
splitFlowOrders,
|
|
6413
6914
|
splitRelationIds,
|
|
6414
6915
|
ssccDigitsOf,
|
|
@@ -6430,7 +6931,9 @@ function inheritedExpiry(inputExpiries) {
|
|
|
6430
6931
|
validateDomainDefinition,
|
|
6431
6932
|
validateEpcisEvent,
|
|
6432
6933
|
validatePerformance,
|
|
6934
|
+
validateRouteNetwork,
|
|
6433
6935
|
validateScenario,
|
|
6936
|
+
validateTransportPolicy,
|
|
6434
6937
|
verdictOfAck,
|
|
6435
6938
|
webhookLaneOf,
|
|
6436
6939
|
webhookSecretCandidates,
|