@kuriousdesign/machine-sdk 1.0.0
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 +37 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +23 -0
- package/package.json +25 -0
- package/src/index.ts +34 -0
- package/tsconfig.json +14 -0
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
@kuriousdesign/machine-sdk
|
|
2
|
+
A shared SDK for data types and helper functions used in machine-related repositories.
|
|
3
|
+
Installation
|
|
4
|
+
npm install @kuriousdesign/machine-sdk
|
|
5
|
+
|
|
6
|
+
Usage
|
|
7
|
+
import { Machine, formatTimestamp, isMachineActive } from '@kuriousdesign/machine-sdk';
|
|
8
|
+
|
|
9
|
+
// Example: Machine data
|
|
10
|
+
const machine: Machine = {
|
|
11
|
+
id: 'M001',
|
|
12
|
+
name: 'Conveyor',
|
|
13
|
+
status: 'running',
|
|
14
|
+
lastUpdated: new Date()
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// Format timestamp
|
|
18
|
+
console.log(formatTimestamp(machine.lastUpdated)); // e.g., "2025-08-15T22:23:00.000Z"
|
|
19
|
+
|
|
20
|
+
// Check if machine is active
|
|
21
|
+
console.log(isMachineActive(machine)); // true
|
|
22
|
+
|
|
23
|
+
API
|
|
24
|
+
Data Types
|
|
25
|
+
|
|
26
|
+
Machine: Represents a machine with id, name, status, and lastUpdated.
|
|
27
|
+
SensorData: Represents sensor readings with machineId, temperature, pressure, and timestamp.
|
|
28
|
+
|
|
29
|
+
Helper Functions
|
|
30
|
+
|
|
31
|
+
formatTimestamp(date: Date): string: Formats a Date to ISO string.
|
|
32
|
+
isMachineActive(machine: Machine): boolean: Checks if a machine is running.
|
|
33
|
+
calculateAverageTemperature(data: SensorData[]): number: Computes average temperature.
|
|
34
|
+
validateMachineId(id: string): boolean: Validates a machine ID format.
|
|
35
|
+
|
|
36
|
+
License
|
|
37
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface Machine {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
status: 'idle' | 'running' | 'stopped' | 'error';
|
|
5
|
+
lastUpdated: Date;
|
|
6
|
+
}
|
|
7
|
+
export interface SensorData {
|
|
8
|
+
machineId: string;
|
|
9
|
+
temperature: number;
|
|
10
|
+
pressure: number;
|
|
11
|
+
timestamp: Date;
|
|
12
|
+
}
|
|
13
|
+
export declare function formatTimestamp(timestamp: Date): string;
|
|
14
|
+
export declare function isMachineActive(machine: Machine): boolean;
|
|
15
|
+
export declare function calculateAverageTemperature(data: SensorData[]): number;
|
|
16
|
+
export declare function validateMachineId(id: string): boolean;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatTimestamp = formatTimestamp;
|
|
4
|
+
exports.isMachineActive = isMachineActive;
|
|
5
|
+
exports.calculateAverageTemperature = calculateAverageTemperature;
|
|
6
|
+
exports.validateMachineId = validateMachineId;
|
|
7
|
+
// Helper Functions
|
|
8
|
+
function formatTimestamp(timestamp) {
|
|
9
|
+
return timestamp.toISOString();
|
|
10
|
+
}
|
|
11
|
+
function isMachineActive(machine) {
|
|
12
|
+
return machine.status === 'running';
|
|
13
|
+
}
|
|
14
|
+
function calculateAverageTemperature(data) {
|
|
15
|
+
if (data.length === 0)
|
|
16
|
+
return 0;
|
|
17
|
+
const total = data.reduce((sum, reading) => sum + reading.temperature, 0);
|
|
18
|
+
return Number((total / data.length).toFixed(2));
|
|
19
|
+
}
|
|
20
|
+
function validateMachineId(id) {
|
|
21
|
+
const idRegex = /^[A-Za-z0-9-_]{1,36}$/;
|
|
22
|
+
return idRegex.test(id);
|
|
23
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kuriousdesign/machine-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Shared data types and helpers for machine-related repositories",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
10
|
+
},
|
|
11
|
+
"keywords": ["machine", "sdk", "data-types", "helpers"],
|
|
12
|
+
"author": "kuriousdesign (https://github.com/kuriousDesign)",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"typescript": "^5.6.3"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/kuriousDesign/machine-sdk.git"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/kuriousDesign/machine-sdk/issues"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/kuriousDesign/machine-sdk#readme"
|
|
25
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Data Types
|
|
2
|
+
export interface Machine {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
status: 'idle' | 'running' | 'stopped' | 'error';
|
|
6
|
+
lastUpdated: Date;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface SensorData {
|
|
10
|
+
machineId: string;
|
|
11
|
+
temperature: number;
|
|
12
|
+
pressure: number;
|
|
13
|
+
timestamp: Date;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Helper Functions
|
|
17
|
+
export function formatTimestamp(timestamp: Date): string {
|
|
18
|
+
return timestamp.toISOString();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function isMachineActive(machine: Machine): boolean {
|
|
22
|
+
return machine.status === 'running';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function calculateAverageTemperature(data: SensorData[]): number {
|
|
26
|
+
if (data.length === 0) return 0;
|
|
27
|
+
const total = data.reduce((sum, reading) => sum + reading.temperature, 0);
|
|
28
|
+
return Number((total / data.length).toFixed(2));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function validateMachineId(id: string): boolean {
|
|
32
|
+
const idRegex = /^[A-Za-z0-9-_]{1,36}$/;
|
|
33
|
+
return idRegex.test(id);
|
|
34
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"outDir": "./dist",
|
|
6
|
+
"rootDir": "./src",
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true
|
|
11
|
+
},
|
|
12
|
+
"include": ["src/**/*"],
|
|
13
|
+
"exclude": ["node_modules", "dist"]
|
|
14
|
+
}
|