@operato/ops-contract 0.9.47 → 0.9.49
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 +20 -1
- 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/capacity.d.ts +1 -36
- package/dist/capacity.js +0 -80
- package/dist/contract.d.ts +26 -0
- package/dist/contract.js +15 -1
- package/dist/domain-catalog.d.ts +1 -1
- package/dist/domain-catalog.js +26 -2
- package/dist/epcis.d.ts +4 -2
- package/dist/epcis.js +12 -10
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/intralogistics-profile.d.ts +80 -0
- package/dist/intralogistics-profile.js +113 -0
- package/dist/mes-profile.js +5 -1
- package/dist/records-of-event.d.ts +1 -1
- package/dist/records-of-event.js +5 -0
- package/dist/route-network.d.ts +84 -0
- package/dist/route-network.js +132 -0
- package/dist/tariff.d.ts +163 -0
- package/dist/tariff.js +376 -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-cjs/index.cjs +679 -49
- package/package.json +1 -1
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* **Intralogistics vocabulary** - transport control inside a plant or warehouse (operato-application ADR-0266 decision 8 ④).
|
|
3
|
+
*
|
|
4
|
+
* Not a new twin area (ADR-0266 decision 5): transport crosses wms, mes and yms (warehouse to line, dock to warehouse), and a fact
|
|
5
|
+
* goes to the area its location declares (ADR-0081). This file names the words those facts use, the way the wms and yms profiles
|
|
6
|
+
* do, so the transport control product and the twin spell them once.
|
|
7
|
+
*
|
|
8
|
+
* Semiconductor MCS words map onto existing axes: a carrier is an asset (GS1 GRAI), a port is a location whose parent is its
|
|
9
|
+
* machine's location, a transport command is an order and a transport job is a task.
|
|
10
|
+
*
|
|
11
|
+
* The types here are not entries of `DOMAIN_CATALOG`. That catalogue gives every equipment type one owning area and every logistics
|
|
12
|
+
* location type `storable`; guided equipment works in several areas, and a waypoint holds nothing. How a host resolves these types
|
|
13
|
+
* next to an area's own is the kernel stage's decision (ADR-0266 §5 stage 6) - `intralogisticsTypeOf` answers for this list.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* CBV steps for a carrier moving between ports. All three are CBV's own (ref.gs1.org/cbv) - checked by the CBV bizStep test.
|
|
17
|
+
*
|
|
18
|
+
* The transport control product speaks only of the carrier (GRAI). Stock moving in or out is the warehouse's and the plant's to say
|
|
19
|
+
* (ADR-0266 decision 9) - items in the carrier follow through `carriedBy`.
|
|
20
|
+
*/
|
|
21
|
+
export const ILG_BIZSTEP = {
|
|
22
|
+
/** The carrier left a port. */
|
|
23
|
+
departing: 'urn:epcglobal:cbv:bizstep:departing',
|
|
24
|
+
/** The carrier reached a port. */
|
|
25
|
+
arriving: 'urn:epcglobal:cbv:bizstep:arriving',
|
|
26
|
+
/** The carrier is on its way. */
|
|
27
|
+
transporting: 'urn:epcglobal:cbv:bizstep:transporting'
|
|
28
|
+
};
|
|
29
|
+
/** Location types of the route network. */
|
|
30
|
+
export const ILG_LOCATION_TYPES = ['waypoint', 'port', 'charger', 'parking'];
|
|
31
|
+
/**
|
|
32
|
+
* ISA-95 level of each location type.
|
|
33
|
+
*
|
|
34
|
+
* · `port` - one carrier stays there for a while: `StorageUnit`.
|
|
35
|
+
* · `waypoint` - neither storage nor work, a point passed through. The standard's escape is `Other`; writing `StorageUnit` would
|
|
36
|
+
* make a roll-up count waypoints as storage and the occupancy rate false (the same judgement as the yard's `gate`).
|
|
37
|
+
* · `charger` · `parking` - equipment stands there, not goods: `Other`.
|
|
38
|
+
*/
|
|
39
|
+
const ILG_LOCATION_LEVEL = {
|
|
40
|
+
waypoint: 'Other',
|
|
41
|
+
port: 'StorageUnit',
|
|
42
|
+
charger: 'Other',
|
|
43
|
+
parking: 'Other'
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Only the port holds goods (`storable`). A waypoint, a charger and a parking spot declare no capability of their own: a charger's
|
|
47
|
+
* metering belongs to the energy twin's segment that shares its location id.
|
|
48
|
+
*/
|
|
49
|
+
const ILG_LOCATION_CAPABILITIES = {
|
|
50
|
+
waypoint: [],
|
|
51
|
+
port: ['storable'],
|
|
52
|
+
charger: [],
|
|
53
|
+
parking: []
|
|
54
|
+
};
|
|
55
|
+
export const ILG_TYPES = [
|
|
56
|
+
...ILG_LOCATION_TYPES.map((k) => ({
|
|
57
|
+
key: k, role: 'location', label: `twin.type.${k}`, standardClass: { epcis: 'bizLocation' }, identity: { scheme: 'gs1:SGLN' },
|
|
58
|
+
level: ILG_LOCATION_LEVEL[k], capabilities: ILG_LOCATION_CAPABILITIES[k]
|
|
59
|
+
})),
|
|
60
|
+
/* A forklift under transport control keeps the wms `forklift` type and adds `guided` in the site's own declaration. */
|
|
61
|
+
{ key: 'amr', role: 'equipment', label: 'twin.type.amr', standardClass: { epcis: 'object', iso55000: 'Asset' }, identity: { scheme: 'gs1:GIAI' }, capabilities: ['mobile', 'guided', 'operable', 'energyStoring'] },
|
|
62
|
+
{ key: 'agv', role: 'equipment', label: 'twin.type.agv', standardClass: { epcis: 'object', iso55000: 'Asset' }, identity: { scheme: 'gs1:GIAI' }, capabilities: ['mobile', 'guided', 'operable', 'energyStoring'] }
|
|
63
|
+
];
|
|
64
|
+
/** This list's entry for a type key, or `undefined`. */
|
|
65
|
+
export function intralogisticsTypeOf(key) {
|
|
66
|
+
return ILG_TYPES.find(t => t.key === key);
|
|
67
|
+
}
|
|
68
|
+
/** A transport command (MCS) - `OrderState.kind`. */
|
|
69
|
+
export const ILG_ORDER_KIND = {
|
|
70
|
+
transport: 'transport'
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Transport jobs (MCS) - `TaskState.kind`.
|
|
74
|
+
*
|
|
75
|
+
* · `transport-leg` - one leg, port to port. A command can split into several legs (a stop on the way, an alternate destination).
|
|
76
|
+
* · `charge` - occupies a charger. Charging takes a place, so it is a task.
|
|
77
|
+
* · `park` - to a parking spot.
|
|
78
|
+
*/
|
|
79
|
+
export const ILG_TASK_KIND = {
|
|
80
|
+
leg: 'transport-leg',
|
|
81
|
+
charge: 'charge',
|
|
82
|
+
park: 'park'
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Why a transport command failed. Closed: a reason the receiver does not know cannot be shown or counted. Values are refusal codes
|
|
86
|
+
* (kebab-case); wording is the presentation layer's.
|
|
87
|
+
*/
|
|
88
|
+
export const TRANSPORT_FAILURE_REASON = [
|
|
89
|
+
'no-route',
|
|
90
|
+
'destination-unavailable',
|
|
91
|
+
'carrier-not-found',
|
|
92
|
+
/** The carrier identified at pick-up is not the one the command named. */
|
|
93
|
+
'carrier-mismatch',
|
|
94
|
+
'cancelled-by-source',
|
|
95
|
+
'equipment-fault'
|
|
96
|
+
];
|
|
97
|
+
export function isTransportFailureReason(v) {
|
|
98
|
+
return typeof v === 'string' && TRANSPORT_FAILURE_REASON.includes(v);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Operational attention kinds the transport control product raises - `<product>.<code>` (`operational-attention.ts`).
|
|
102
|
+
* Keys and values only; no sentences (the kernel's rule for attentions).
|
|
103
|
+
*/
|
|
104
|
+
export const ILG_ATTENTION_KIND = {
|
|
105
|
+
deadlock: 'intralogic.traffic-deadlock',
|
|
106
|
+
blocked: 'intralogic.traffic-blocked',
|
|
107
|
+
lowCharge: 'intralogic.low-charge',
|
|
108
|
+
linkLost: 'intralogic.link-lost',
|
|
109
|
+
noRoute: 'intralogic.no-route',
|
|
110
|
+
rerouted: 'intralogic.rerouted',
|
|
111
|
+
carrierUnidentified: 'intralogic.carrier-unidentified',
|
|
112
|
+
carrierDuplicate: 'intralogic.carrier-duplicate'
|
|
113
|
+
};
|
package/dist/mes-profile.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { CBV_BIZSTEP } from "./epcis.js";
|
|
1
2
|
// MES bizStep — CBV 재사용. producing = commissioning(신규 제품 커미셔닝).
|
|
3
|
+
// producing 은 코어의 CBV_BIZSTEP.commissioning 을 가리킨다(값을 두 번 적지 않는다, 2026-11-27).
|
|
4
|
+
// receiving · storing 은 창고 프로파일(BIZSTEP)과 같은 CBV 값이지만 그쪽을 가져오지 않는다 — 프로파일끼리 기대면
|
|
5
|
+
// 한 업종의 어휘가 다른 업종에 새어 든다(§CBV_BIZSTEP 머리 주석). 철자는 cbv-bizstep-values-exist 시험이 지킨다.
|
|
2
6
|
export const MES_BIZSTEP = {
|
|
3
7
|
receiving: 'urn:epcglobal:cbv:bizstep:receiving', // 원자재 수령
|
|
4
|
-
producing:
|
|
8
|
+
producing: CBV_BIZSTEP.commissioning, // 생산(제품 최초 생성)
|
|
5
9
|
storing: 'urn:epcglobal:cbv:bizstep:storing' // 완제품 저장
|
|
6
10
|
};
|
|
7
11
|
/** 작업지시(Work Order) = 생산 오더 거래 유형. */
|
|
@@ -36,7 +36,7 @@ export interface RecordsOfEvent {
|
|
|
36
36
|
/** The fields this event carried that the records leave out - absent when none. */
|
|
37
37
|
notCarried?: FieldNotCarried[];
|
|
38
38
|
}
|
|
39
|
-
export type RecordShapeRefusal = 'nothing-observed' | 'quantity-across-many-units' | 'event-type-not-shaped' | 'correction-not-shaped' | 'event-invalid';
|
|
39
|
+
export type RecordShapeRefusal = 'nothing-observed' | 'aggregation-no-parent' | 'quantity-across-many-units' | 'event-type-not-shaped' | 'correction-not-shaped' | 'event-invalid';
|
|
40
40
|
/** Why an event cannot be shaped - an `Error` with a `code` and its `params`. A product turns it into its own refusal. */
|
|
41
41
|
export interface RecordShapeError extends Error {
|
|
42
42
|
code: RecordShapeRefusal;
|
package/dist/records-of-event.js
CHANGED
|
@@ -79,6 +79,11 @@ function shapedRecordsOf(event) {
|
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
case 'AggregationEvent':
|
|
82
|
+
/* EPCIS 2.0 lets an OBSERVE leave the parent unsaid (§7.4.3); the canonical aggregation record is keyed by its parent, so
|
|
83
|
+
* without one it would not read back as an aggregation - refused, not sent half-shaped. */
|
|
84
|
+
if (!event.parentID) {
|
|
85
|
+
throw shapeError('aggregation-no-parent', { event: event.eventID }, 'the aggregation names no parent: the canonical record is keyed by its parent');
|
|
86
|
+
}
|
|
82
87
|
return {
|
|
83
88
|
records: [
|
|
84
89
|
{
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { EffectivePeriod, ISOTime, RefusalParams, ResourceClassDef, ResourceProperty } from './contract.ts';
|
|
2
|
+
/** A path from one location to another. VDA 5050 `edge`. */
|
|
3
|
+
export interface LocationConnection extends EffectivePeriod {
|
|
4
|
+
id: string;
|
|
5
|
+
/** `locations.id` (or a referenced location of another lens). */
|
|
6
|
+
from: string;
|
|
7
|
+
to: string;
|
|
8
|
+
/** `one-way` = from -> to only. */
|
|
9
|
+
direction: ConnectionDirection;
|
|
10
|
+
/** Metres, > 0. The basis of travel time. Never computed from coordinates here. */
|
|
11
|
+
lengthM: number;
|
|
12
|
+
/** Metres per second, > 0. Absent = the equipment's own speed. */
|
|
13
|
+
maxSpeedMps?: number;
|
|
14
|
+
/** How many machines may be on this connection at once. Absent = 1 (exclusive). */
|
|
15
|
+
capacity?: number;
|
|
16
|
+
/** Equipment classes allowed to pass. Absent = no restriction. */
|
|
17
|
+
equipmentClassIds?: string[];
|
|
18
|
+
properties?: ResourceProperty[];
|
|
19
|
+
}
|
|
20
|
+
export declare const CONNECTION_DIRECTION: readonly ["one-way", "two-way"];
|
|
21
|
+
export type ConnectionDirection = (typeof CONNECTION_DIRECTION)[number];
|
|
22
|
+
/** An ordered list of connections - "this equipment goes this way". */
|
|
23
|
+
export interface FixedRoute extends EffectivePeriod {
|
|
24
|
+
id: string;
|
|
25
|
+
/** In travel order; each must start where the previous one ended. */
|
|
26
|
+
connectionIds: string[];
|
|
27
|
+
/** Equipment bound to this route. Absent = advisory for all. */
|
|
28
|
+
equipmentClassIds?: string[];
|
|
29
|
+
binding: FixedRouteBinding;
|
|
30
|
+
}
|
|
31
|
+
export declare const FIXED_ROUTE_BINDING: readonly ["mandatory", "preferred"];
|
|
32
|
+
export type FixedRouteBinding = (typeof FIXED_ROUTE_BINDING)[number];
|
|
33
|
+
/** One published edition of the network. A published edition is never edited; a change is a new version. */
|
|
34
|
+
export interface RouteNetworkEdition {
|
|
35
|
+
id: string;
|
|
36
|
+
version: string;
|
|
37
|
+
publishedAt: ISOTime;
|
|
38
|
+
publishedBy?: string;
|
|
39
|
+
}
|
|
40
|
+
/** Default capacity of a connection when none is declared. */
|
|
41
|
+
export declare const DEFAULT_CONNECTION_CAPACITY = 1;
|
|
42
|
+
export declare const ROUTE_NETWORK_ISSUE: {
|
|
43
|
+
readonly connectionDangling: "route-connection-dangling";
|
|
44
|
+
readonly connectionSelf: "route-connection-self";
|
|
45
|
+
readonly connectionLength: "route-connection-length";
|
|
46
|
+
readonly connectionSpeed: "route-connection-speed";
|
|
47
|
+
readonly connectionCapacity: "route-connection-capacity";
|
|
48
|
+
readonly connectionDirection: "route-connection-direction";
|
|
49
|
+
readonly connectionDuplicate: "route-connection-duplicate";
|
|
50
|
+
readonly connectionUnknownClass: "route-connection-unknown-class";
|
|
51
|
+
readonly fixedEmpty: "route-fixed-empty";
|
|
52
|
+
readonly fixedUnknownConnection: "route-fixed-unknown-connection";
|
|
53
|
+
readonly fixedBroken: "route-fixed-broken";
|
|
54
|
+
readonly fixedClass: "route-fixed-class";
|
|
55
|
+
readonly fixedBinding: "route-fixed-binding";
|
|
56
|
+
readonly duplicateId: "route-duplicate-id";
|
|
57
|
+
};
|
|
58
|
+
export type RouteNetworkIssueCode = (typeof ROUTE_NETWORK_ISSUE)[keyof typeof ROUTE_NETWORK_ISSUE];
|
|
59
|
+
export interface RouteNetworkIssue {
|
|
60
|
+
code: RouteNetworkIssueCode;
|
|
61
|
+
/** The connection or fixed route the issue is about. */
|
|
62
|
+
subject: string;
|
|
63
|
+
params: RefusalParams;
|
|
64
|
+
}
|
|
65
|
+
export interface RouteNetworkInput {
|
|
66
|
+
locations?: readonly {
|
|
67
|
+
id: string;
|
|
68
|
+
}[];
|
|
69
|
+
referencedLocations?: readonly {
|
|
70
|
+
id: string;
|
|
71
|
+
}[];
|
|
72
|
+
connections?: readonly LocationConnection[];
|
|
73
|
+
fixedRoutes?: readonly FixedRoute[];
|
|
74
|
+
equipmentClasses?: readonly ResourceClassDef[];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Checks the structure of a route network. Returns every issue found (empty = structurally sound).
|
|
78
|
+
*
|
|
79
|
+
* Not checked here: whether a port can be reached, dead ends, deadlock risk. Those need graph search and belong to the deciders
|
|
80
|
+
* (the app's rules, the kernel's execution policy).
|
|
81
|
+
*/
|
|
82
|
+
export declare function validateRouteNetwork(def: RouteNetworkInput): RouteNetworkIssue[];
|
|
83
|
+
/** Whether equipment of these classes may pass this connection (class closure included). */
|
|
84
|
+
export declare function connectionAdmits(c: LocationConnection, equipmentClassIds: readonly string[], classes?: readonly ResourceClassDef[]): boolean;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { classClosure } from "./contract.js";
|
|
2
|
+
export const CONNECTION_DIRECTION = ['one-way', 'two-way'];
|
|
3
|
+
export const FIXED_ROUTE_BINDING = ['mandatory', 'preferred'];
|
|
4
|
+
/** Default capacity of a connection when none is declared. */
|
|
5
|
+
export const DEFAULT_CONNECTION_CAPACITY = 1;
|
|
6
|
+
export const ROUTE_NETWORK_ISSUE = {
|
|
7
|
+
connectionDangling: 'route-connection-dangling',
|
|
8
|
+
connectionSelf: 'route-connection-self',
|
|
9
|
+
connectionLength: 'route-connection-length',
|
|
10
|
+
connectionSpeed: 'route-connection-speed',
|
|
11
|
+
connectionCapacity: 'route-connection-capacity',
|
|
12
|
+
connectionDirection: 'route-connection-direction',
|
|
13
|
+
connectionDuplicate: 'route-connection-duplicate',
|
|
14
|
+
connectionUnknownClass: 'route-connection-unknown-class',
|
|
15
|
+
fixedEmpty: 'route-fixed-empty',
|
|
16
|
+
fixedUnknownConnection: 'route-fixed-unknown-connection',
|
|
17
|
+
fixedBroken: 'route-fixed-broken',
|
|
18
|
+
fixedClass: 'route-fixed-class',
|
|
19
|
+
fixedBinding: 'route-fixed-binding',
|
|
20
|
+
duplicateId: 'route-duplicate-id'
|
|
21
|
+
};
|
|
22
|
+
const positiveNumber = (v) => typeof v === 'number' && Number.isFinite(v) && v > 0;
|
|
23
|
+
/** The two ends a connection can be entered from, in its allowed directions. */
|
|
24
|
+
function traversals(c) {
|
|
25
|
+
return c.direction === 'two-way' ? [{ from: c.from, to: c.to }, { from: c.to, to: c.from }] : [{ from: c.from, to: c.to }];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Whether equipment of `classIds` may pass `c`. A connection without a class list admits everyone; with one, the equipment's class
|
|
29
|
+
* closure (base classes included) must meet it - an `amr-small` derived from `amr` passes an `amr` connection.
|
|
30
|
+
*/
|
|
31
|
+
function admits(c, classIds, classes) {
|
|
32
|
+
if (!c.equipmentClassIds || c.equipmentClassIds.length === 0)
|
|
33
|
+
return true;
|
|
34
|
+
const allowed = new Set(c.equipmentClassIds);
|
|
35
|
+
return classIds.every(id => [...classClosure([id], classes)].some(k => allowed.has(k)));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Checks the structure of a route network. Returns every issue found (empty = structurally sound).
|
|
39
|
+
*
|
|
40
|
+
* Not checked here: whether a port can be reached, dead ends, deadlock risk. Those need graph search and belong to the deciders
|
|
41
|
+
* (the app's rules, the kernel's execution policy).
|
|
42
|
+
*/
|
|
43
|
+
export function validateRouteNetwork(def) {
|
|
44
|
+
const issues = [];
|
|
45
|
+
const places = new Set([...(def.locations ?? []), ...(def.referencedLocations ?? [])].map(l => l.id));
|
|
46
|
+
const connections = def.connections ?? [];
|
|
47
|
+
const classIds = new Set((def.equipmentClasses ?? []).map(c => c.id));
|
|
48
|
+
const byId = new Map();
|
|
49
|
+
const seenEnds = new Set();
|
|
50
|
+
for (const c of connections) {
|
|
51
|
+
if (byId.has(c.id))
|
|
52
|
+
issues.push({ code: ROUTE_NETWORK_ISSUE.duplicateId, subject: c.id, params: { kind: 'connection' } });
|
|
53
|
+
byId.set(c.id, c);
|
|
54
|
+
for (const end of [c.from, c.to]) {
|
|
55
|
+
if (!places.has(end))
|
|
56
|
+
issues.push({ code: ROUTE_NETWORK_ISSUE.connectionDangling, subject: c.id, params: { location: end } });
|
|
57
|
+
}
|
|
58
|
+
if (c.from === c.to)
|
|
59
|
+
issues.push({ code: ROUTE_NETWORK_ISSUE.connectionSelf, subject: c.id, params: { location: c.from } });
|
|
60
|
+
if (!CONNECTION_DIRECTION.includes(c.direction)) {
|
|
61
|
+
issues.push({ code: ROUTE_NETWORK_ISSUE.connectionDirection, subject: c.id, params: { direction: String(c.direction) } });
|
|
62
|
+
}
|
|
63
|
+
if (!positiveNumber(c.lengthM))
|
|
64
|
+
issues.push({ code: ROUTE_NETWORK_ISSUE.connectionLength, subject: c.id, params: { lengthM: String(c.lengthM) } });
|
|
65
|
+
if (c.maxSpeedMps !== undefined && !positiveNumber(c.maxSpeedMps)) {
|
|
66
|
+
issues.push({ code: ROUTE_NETWORK_ISSUE.connectionSpeed, subject: c.id, params: { maxSpeedMps: String(c.maxSpeedMps) } });
|
|
67
|
+
}
|
|
68
|
+
if (c.capacity !== undefined && !(Number.isInteger(c.capacity) && c.capacity >= 1)) {
|
|
69
|
+
issues.push({ code: ROUTE_NETWORK_ISSUE.connectionCapacity, subject: c.id, params: { capacity: String(c.capacity) } });
|
|
70
|
+
}
|
|
71
|
+
/* A class list may only name declared classes - but only when the twin declares classes at all. A twin without class
|
|
72
|
+
definitions still names classes by id (classClosure takes the ids as they are), so absence of definitions is not an error. */
|
|
73
|
+
if (classIds.size > 0) {
|
|
74
|
+
for (const id of c.equipmentClassIds ?? []) {
|
|
75
|
+
if (!classIds.has(id))
|
|
76
|
+
issues.push({ code: ROUTE_NETWORK_ISSUE.connectionUnknownClass, subject: c.id, params: { equipmentClassId: id } });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/* Two connections over the same ends in the same direction are one path declared twice; a reader would not know which
|
|
80
|
+
length or speed holds. A one-way pair in opposite directions is two paths, not a duplicate. */
|
|
81
|
+
for (const t of traversals(c)) {
|
|
82
|
+
const key = `${t.from}\u0000${t.to}`;
|
|
83
|
+
if (seenEnds.has(key))
|
|
84
|
+
issues.push({ code: ROUTE_NETWORK_ISSUE.connectionDuplicate, subject: c.id, params: { from: t.from, to: t.to } });
|
|
85
|
+
seenEnds.add(key);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const routeIds = new Set();
|
|
89
|
+
for (const r of def.fixedRoutes ?? []) {
|
|
90
|
+
if (routeIds.has(r.id))
|
|
91
|
+
issues.push({ code: ROUTE_NETWORK_ISSUE.duplicateId, subject: r.id, params: { kind: 'fixed-route' } });
|
|
92
|
+
routeIds.add(r.id);
|
|
93
|
+
if (!FIXED_ROUTE_BINDING.includes(r.binding)) {
|
|
94
|
+
issues.push({ code: ROUTE_NETWORK_ISSUE.fixedBinding, subject: r.id, params: { binding: String(r.binding) } });
|
|
95
|
+
}
|
|
96
|
+
if (!r.connectionIds || r.connectionIds.length === 0) {
|
|
97
|
+
issues.push({ code: ROUTE_NETWORK_ISSUE.fixedEmpty, subject: r.id, params: {} });
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const legs = [];
|
|
101
|
+
for (const id of r.connectionIds) {
|
|
102
|
+
const c = byId.get(id);
|
|
103
|
+
if (!c)
|
|
104
|
+
issues.push({ code: ROUTE_NETWORK_ISSUE.fixedUnknownConnection, subject: r.id, params: { connection: id } });
|
|
105
|
+
else
|
|
106
|
+
legs.push(c);
|
|
107
|
+
}
|
|
108
|
+
if (legs.length !== r.connectionIds.length)
|
|
109
|
+
continue;
|
|
110
|
+
/* Walk the route: the first leg may be entered from either end it allows; every later leg must be entered where the
|
|
111
|
+
previous one left off, in a direction it allows. */
|
|
112
|
+
let at = new Set(traversals(legs[0]).map(t => t.to));
|
|
113
|
+
for (let i = 1; i < legs.length; i++) {
|
|
114
|
+
const next = new Set(traversals(legs[i]).filter(t => at.has(t.from)).map(t => t.to));
|
|
115
|
+
if (next.size === 0) {
|
|
116
|
+
issues.push({ code: ROUTE_NETWORK_ISSUE.fixedBroken, subject: r.id, params: { after: legs[i - 1].id, connection: legs[i].id } });
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
at = next;
|
|
120
|
+
}
|
|
121
|
+
for (const classId of r.equipmentClassIds ?? []) {
|
|
122
|
+
const blocked = legs.find(c => !admits(c, [classId], def.equipmentClasses));
|
|
123
|
+
if (blocked)
|
|
124
|
+
issues.push({ code: ROUTE_NETWORK_ISSUE.fixedClass, subject: r.id, params: { equipmentClassId: classId, connection: blocked.id } });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return issues;
|
|
128
|
+
}
|
|
129
|
+
/** Whether equipment of these classes may pass this connection (class closure included). */
|
|
130
|
+
export function connectionAdmits(c, equipmentClassIds, classes) {
|
|
131
|
+
return admits(c, equipmentClassIds, classes);
|
|
132
|
+
}
|
package/dist/tariff.d.ts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* **Electricity tariff rules** — the words of a time-of-use tariff and how to read it.
|
|
3
|
+
*
|
|
4
|
+
* ── Why this is in the contract (2026-11-27) ────────────────────────────────────────────────────────────────────
|
|
5
|
+
* The tariff is site master data and is stored by ops-master (`ElectricityTariff` · `ElectricityTariffBand`). What
|
|
6
|
+
* lives here is the reading: which band applies at a moment, and whether a tariff's bands cover every day. Once the
|
|
7
|
+
* twin prices usage per band (the kernel's `electricityCost({ energyChargeFromPeriods })`), ops-master's screen and the
|
|
8
|
+
* twin must give the same answer for the same moment - a rule two implementations share belongs to the contract.
|
|
9
|
+
* Storage, approval and screens stay with ops-master.
|
|
10
|
+
*
|
|
11
|
+
* Field names are the declaration's (`EMS_DECLARATION` `tariff.*`): `demandChargePerKW`, `energyChargePerKWh`,
|
|
12
|
+
* `currency`. The contract power (`contract.kW`) and billing demand (`tariff.billingDemandKW`) are not tariff rows -
|
|
13
|
+
* one is a property of the supply point, the other a per-cycle fact from the supplier.
|
|
14
|
+
*
|
|
15
|
+
* ── Which price wins ────────────────────────────────────────────────────────────────────────────────────────────
|
|
16
|
+
* A source fact's own price (`EnergyUsagePeriodData.unitPrice`) is what was charged; it wins. A band price from the
|
|
17
|
+
* master is used only for a period whose fact carries no price. The master is a declaration, the fact an observation.
|
|
18
|
+
*
|
|
19
|
+
* ── Times are the site's wall clock ─────────────────────────────────────────────────────────────────────────────
|
|
20
|
+
* Bands are set in local time ("weekdays 09:00-10:00 are on-peak"). These functions do not know time zones: the
|
|
21
|
+
* caller converts an instant to the site's month, day, weekday and minute (`LocalMoment`). Cutting in UTC would make
|
|
22
|
+
* Seoul's 09:00 into 00:00.
|
|
23
|
+
*
|
|
24
|
+
* ── A band does not cross midnight ──────────────────────────────────────────────────────────────────────────────
|
|
25
|
+
* "22:00-08:00 off-peak" is written as two rows (22:00-24:00, 00:00-08:00). A single row would have to say which day
|
|
26
|
+
* it belongs to (does Saturday night run into Sunday morning?), and tariffs answer that differently.
|
|
27
|
+
*
|
|
28
|
+
* ── A new country is rows, not code (2026-11-27) ───────────────────────────────────────────────────────────────
|
|
29
|
+
* Tariff systems differ by country and supplier: how many bands and what they are called, whether a holiday is priced
|
|
30
|
+
* like Sunday, whether demand is charged per band, which days are holidays. A new country must be written as tariff,
|
|
31
|
+
* band and calendar rows - never as a change here, in the kernel or on a screen. So:
|
|
32
|
+
* · the band **code** is the tariff's own (`base` · `intermedia` · `punta`, `super-off-peak` …); only its
|
|
33
|
+
* **load class** - for comparing across tariffs - is a closed, ordered vocabulary (`TARIFF_LOAD_CLASSES`);
|
|
34
|
+
* · `sunday` and `holiday` are separate day kinds; a tariff pricing them alike writes two rows;
|
|
35
|
+
* · the tariff's `demandChargePerKW` is the facility demand charge (any time); a band may carry its own
|
|
36
|
+
* time-of-use `demandChargePerKW`;
|
|
37
|
+
* · the tariff names its holiday calendar (`holidayCalendar`); the calendar's days are not in the contract - the
|
|
38
|
+
* caller passes `isHoliday`.
|
|
39
|
+
* Season bounds are fixed `MM-DD`. A tariff whose season moves each year ("from the first Sunday of April") is written
|
|
40
|
+
* as one tariff per year with its effective dates - not yet seen to need more (to check against CFE tariffs).
|
|
41
|
+
*
|
|
42
|
+
* ── Issues are structured ───────────────────────────────────────────────────────────────────────────────────────
|
|
43
|
+
* Checks return `{ field, code, params }`, not sentences: a screen turns the code into its own language, and
|
|
44
|
+
* `tariffIssueText` gives the one-line English `field: reason` other contract checks use.
|
|
45
|
+
*/
|
|
46
|
+
/**
|
|
47
|
+
* Load class of a band - **ordered from lightest to heaviest load**, for comparing bands across tariffs
|
|
48
|
+
* ("how much is shifted out of the heaviest hours"). The band's own code is the tariff's: Mexico's `base` ·
|
|
49
|
+
* `intermedia` · `punta` are classed `off-peak` · `mid-peak` · `on-peak`; a US `super-off-peak` band is that class.
|
|
50
|
+
*/
|
|
51
|
+
export declare const TARIFF_LOAD_CLASSES: readonly ["super-off-peak", "off-peak", "mid-peak", "on-peak"];
|
|
52
|
+
export type TariffLoadClass = (typeof TARIFF_LOAD_CLASSES)[number];
|
|
53
|
+
/**
|
|
54
|
+
* Which days a band applies to. `all` ignores the day.
|
|
55
|
+
*
|
|
56
|
+
* `holiday` is a day of the tariff's holiday calendar (`holidayCalendar`) and **comes before the weekday**: a holiday
|
|
57
|
+
* falling on a Saturday is a holiday. A tariff that prices holidays like Sundays writes a `sunday` row and a `holiday`
|
|
58
|
+
* row. A tariff with no `holiday` row does not price holidays apart - its holidays are read as their weekday.
|
|
59
|
+
*/
|
|
60
|
+
export declare const TARIFF_DAY_KINDS: readonly ["all", "weekday", "saturday", "sunday", "holiday"];
|
|
61
|
+
export type TariffDayKind = (typeof TARIFF_DAY_KINDS)[number];
|
|
62
|
+
export interface TariffLike {
|
|
63
|
+
name?: string;
|
|
64
|
+
currency?: string | null;
|
|
65
|
+
/** Facility demand charge per kW of billing demand - whatever the hour. */
|
|
66
|
+
demandChargePerKW?: number | string | null;
|
|
67
|
+
/** Flat energy charge - only for a tariff without bands. */
|
|
68
|
+
energyChargePerKWh?: number | string | null;
|
|
69
|
+
/** The holiday calendar this tariff's `holiday` bands follow - a name; the days are the caller's. */
|
|
70
|
+
holidayCalendar?: string | null;
|
|
71
|
+
}
|
|
72
|
+
export interface TariffBandLike {
|
|
73
|
+
name?: string;
|
|
74
|
+
tariffName?: string;
|
|
75
|
+
/** The tariff's own band code (`punta`, `on-peak`, `super-off-peak` …). */
|
|
76
|
+
band?: string | null;
|
|
77
|
+
/** `TARIFF_LOAD_CLASSES` - for comparing across tariffs. */
|
|
78
|
+
loadClass?: string | null;
|
|
79
|
+
/** Season start `MM-DD`; empty together with `seasonTo` means all year. May wrap the year (11-01..02-28). */
|
|
80
|
+
seasonFrom?: string | null;
|
|
81
|
+
/** Season end `MM-DD`, inclusive. */
|
|
82
|
+
seasonTo?: string | null;
|
|
83
|
+
dayKind?: string | null;
|
|
84
|
+
/** `HH:mm`, inclusive. */
|
|
85
|
+
fromTime?: string | null;
|
|
86
|
+
/** `HH:mm`, exclusive; `24:00` ends the day. */
|
|
87
|
+
toTime?: string | null;
|
|
88
|
+
energyChargePerKWh?: number | string | null;
|
|
89
|
+
/** Time-of-use demand charge per kW in this band, on top of the tariff's facility charge. Optional. */
|
|
90
|
+
demandChargePerKW?: number | string | null;
|
|
91
|
+
effectiveEnd?: Date | string | null;
|
|
92
|
+
}
|
|
93
|
+
export declare const TARIFF_ISSUE_CODES: readonly ["required", "not-a-number", "negative", "not-in-vocabulary", "format", "currency-required", "season-pair", "end-not-after-start", "flat-and-bands", "broken-bands", "gap", "overlap"];
|
|
94
|
+
export type TariffIssueCode = (typeof TARIFF_ISSUE_CODES)[number];
|
|
95
|
+
export interface TariffIssue {
|
|
96
|
+
/** The field the issue is about (`currency`, `fromTime`, `bands` …). */
|
|
97
|
+
field: string;
|
|
98
|
+
code: TariffIssueCode;
|
|
99
|
+
params?: Record<string, string | number>;
|
|
100
|
+
}
|
|
101
|
+
/** One English line, `field: reason` - the form other contract checks use. */
|
|
102
|
+
export declare function tariffIssueText(issue: TariffIssue): string;
|
|
103
|
+
/** An ISO 4217 code - three upper-case letters (KRW, USD). */
|
|
104
|
+
export declare function isIso4217Code(value: unknown): value is string;
|
|
105
|
+
/** `HH:mm` → minutes from midnight. `24:00` is 1440 and is only an end. */
|
|
106
|
+
export declare function minutesOf(text: unknown): number | undefined;
|
|
107
|
+
/** `MM-DD` → day of a leap year (0..365). Takes 02-29 - that day too must fall in some season. */
|
|
108
|
+
export declare function dayOfYearOf(text: unknown): number | undefined;
|
|
109
|
+
/** One tariff row, before it is saved. Empty when it is sound. */
|
|
110
|
+
export declare function tariffIssues(row: TariffLike): TariffIssue[];
|
|
111
|
+
/** One band row, before it is saved. Whether bands cover the day cannot be seen from one row - `tariffCoverageIssues`. */
|
|
112
|
+
export declare function tariffBandIssues(row: TariffBandLike): TariffIssue[];
|
|
113
|
+
/** Bands still in force at `at` - a band whose end has passed was retired (rows are ended, not deleted). */
|
|
114
|
+
export declare function activeBands<T extends TariffBandLike>(bands: readonly T[], at: Date): T[];
|
|
115
|
+
/**
|
|
116
|
+
* Whether one tariff's bands cover **every minute of every day, once**.
|
|
117
|
+
*
|
|
118
|
+
* Looks at all 366 days of a leap year × the concrete day kinds (weekday, saturday, sunday, and holiday when the tariff
|
|
119
|
+
* prices holidays apart). An uncovered hour cannot be priced; an hour
|
|
120
|
+
* covered twice has two prices - either way its charge would be invented. The same problem over consecutive days is
|
|
121
|
+
* one issue (`params.days` like `06-01~08-31`).
|
|
122
|
+
*
|
|
123
|
+
* No bands is not an issue - it is a flat tariff (the tariff row's `energyChargePerKWh`). A tariff passes through
|
|
124
|
+
* wrong states while it is edited, so a screen shows this rather than refusing to save.
|
|
125
|
+
*/
|
|
126
|
+
export declare function tariffCoverageIssues(tariff: TariffLike, bands: readonly TariffBandLike[]): TariffIssue[];
|
|
127
|
+
/** A moment on the site's wall clock - the caller converts to the site's time zone. */
|
|
128
|
+
export interface LocalMoment {
|
|
129
|
+
/** 1..12 */
|
|
130
|
+
month: number;
|
|
131
|
+
/** 1..31 */
|
|
132
|
+
day: number;
|
|
133
|
+
/** 0 = Sunday … 6 = Saturday (as `Date.getDay`) */
|
|
134
|
+
weekday: number;
|
|
135
|
+
/** Minutes from midnight (0..1439) */
|
|
136
|
+
minutes: number;
|
|
137
|
+
}
|
|
138
|
+
export type BandAt = {
|
|
139
|
+
/** Band row name - absent for a flat tariff. */
|
|
140
|
+
bandName?: string;
|
|
141
|
+
/** The tariff's band code. */
|
|
142
|
+
band?: string;
|
|
143
|
+
loadClass?: TariffLoadClass;
|
|
144
|
+
energyChargePerKWh: number;
|
|
145
|
+
/** Time-of-use demand charge of the band, when it has one. The tariff's facility charge is not repeated here. */
|
|
146
|
+
demandChargePerKW?: number;
|
|
147
|
+
currency?: string;
|
|
148
|
+
/**
|
|
149
|
+
* False only when the tariff prices holidays apart and no `isHoliday` was given - a holiday may then have been
|
|
150
|
+
* priced as its weekday.
|
|
151
|
+
*/
|
|
152
|
+
holidayKnown: boolean;
|
|
153
|
+
} | {
|
|
154
|
+
reason: 'no-price' | 'no-band' | 'ambiguous';
|
|
155
|
+
bands?: string[];
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* The energy charge at this moment.
|
|
159
|
+
*
|
|
160
|
+
* Without bands the tariff's flat charge applies. With bands **exactly one** must match - none is `no-band`, more than
|
|
161
|
+
* one is `ambiguous`, and no price is picked (taking the first written would be chance).
|
|
162
|
+
*/
|
|
163
|
+
export declare function bandAt(tariff: TariffLike, bands: readonly TariffBandLike[], at: LocalMoment, isHoliday?: (month: number, day: number) => boolean): BandAt;
|