@interlogic/engine
v0.3.0
Published
Types and validation logic
Readme
@interlogic/engine
Lightweight transport planning types and validation for TypeScript.
What it is
This package defines the domain model for transport planning:
TruckandTrailerobjects with live locationShipmentobjects with a pickup and delivery stopPlanthat assigns shipments to trucks, with built-in validation
Install
npm installBuild
npm run buildTest
npm testUsage
Fetch your vehicles and shipments, assign them, and validate the plan:
import { createPlan, type Truck, type Trailer, type Shipment } from "@interlogic/engine";
// GET /vehicles
const trucks: Truck[] = [
{ license: "BK-001-L", location: { latitude: 51.9225, longitude: 4.4792 } },
{ license: "BK-002-L", location: { latitude: 51.9225, longitude: 4.4792 } },
];
const trailers: Trailer[] = [
{ license: "YZ-001-T", location: { latitude: 51.9225, longitude: 4.4792 } },
];
// GET /shipments
const shipments: Shipment[] = [
{
id: "SHP-001",
pickup: {
location: { latitude: 51.9225, longitude: 4.4792, address: "Port of Rotterdam" },
window: { start: 1745056800000, end: 1745060400000 },
mass: { weight: 24000 },
},
delivery: {
location: { latitude: 52.2434, longitude: 6.1551, address: "Distribution Center Deventer" },
window: { start: 1745064000000, end: 1745067600000 },
mass: { weight: 24000 },
},
},
];
// GET /plan (AI decides the assignments)
const plan = createPlan({
entries: [
{ truck: trucks[0], trailer: trailers[0], shipments: [shipments[0]] },
{ truck: trucks[1], shipments: [shipments[1]] },
],
});
console.log(plan.validate()); // trueCustom properties
All objects support custom properties without modifying the type definitions:
const truck: Truck = {
license: "BK-001-L",
location: { latitude: 51.9225, longitude: 4.4792 },
driver: "Piet de Vries", // custom
brand: "Volvo", // custom
};
const shipment: Shipment = {
id: "SHP-001",
client: "ACME", // custom
priority: "high", // custom
pickup: { ... },
delivery: { ... },
};Plan.validate()
Returns true when all shipments in the plan satisfy:
- pickup and delivery windows have
start <= end - all locations are valid Earth coordinates
- pickup mass equals delivery mass
Project structure
src/— source TypeScript filestests/— unit testsdist/— compiled output
