@fleettools/core 0.1.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/dist/constants.d.ts +62 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/ids.d.ts +71 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +238 -0
- package/dist/timestamps.d.ts +13 -0
- package/dist/timestamps.d.ts.map +1 -0
- package/dist/types.d.ts +83 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils.d.ts +50 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +32 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export declare const VERSION = "0.1.0";
|
|
2
|
+
export declare const TTL: {
|
|
3
|
+
readonly RESERVATION: number;
|
|
4
|
+
readonly LOCK: number;
|
|
5
|
+
readonly SESSION: number;
|
|
6
|
+
readonly OPERATION: number;
|
|
7
|
+
};
|
|
8
|
+
export declare const IMPORTANCE: {
|
|
9
|
+
readonly LOW: "low";
|
|
10
|
+
readonly NORMAL: "normal";
|
|
11
|
+
readonly HIGH: "high";
|
|
12
|
+
readonly URGENT: "urgent";
|
|
13
|
+
};
|
|
14
|
+
export type Importance = typeof IMPORTANCE[keyof typeof IMPORTANCE];
|
|
15
|
+
export declare const SORTIE_STATUS: {
|
|
16
|
+
readonly OPEN: "open";
|
|
17
|
+
readonly IN_PROGRESS: "in_progress";
|
|
18
|
+
readonly BLOCKED: "blocked";
|
|
19
|
+
readonly CLOSED: "closed";
|
|
20
|
+
};
|
|
21
|
+
export type SortieStatus = typeof SORTIE_STATUS[keyof typeof SORTIE_STATUS];
|
|
22
|
+
export declare const MISSION_STATUS: {
|
|
23
|
+
readonly PENDING: "pending";
|
|
24
|
+
readonly IN_PROGRESS: "in_progress";
|
|
25
|
+
readonly COMPLETED: "completed";
|
|
26
|
+
};
|
|
27
|
+
export type MissionStatus = typeof MISSION_STATUS[keyof typeof MISSION_STATUS];
|
|
28
|
+
export declare const PRIORITY: {
|
|
29
|
+
readonly CRITICAL: 0;
|
|
30
|
+
readonly HIGH: 1;
|
|
31
|
+
readonly MEDIUM: 2;
|
|
32
|
+
readonly LOW: 3;
|
|
33
|
+
};
|
|
34
|
+
export type Priority = typeof PRIORITY[keyof typeof PRIORITY];
|
|
35
|
+
export declare const EVENT_CATEGORIES: {
|
|
36
|
+
readonly PILOT: readonly ["pilot_registered", "pilot_active", "pilot_deregistered"];
|
|
37
|
+
readonly MESSAGE: readonly ["message_sent", "message_read", "message_acked", "thread_created", "thread_activity"];
|
|
38
|
+
readonly RESERVATION: readonly ["file_reserved", "file_released", "file_conflict"];
|
|
39
|
+
readonly SORTIE: readonly ["sortie_created", "sortie_started", "sortie_progress", "sortie_completed", "sortie_blocked", "sortie_status_changed"];
|
|
40
|
+
readonly MISSION: readonly ["mission_created", "mission_started", "mission_completed", "mission_synced"];
|
|
41
|
+
readonly CHECKPOINT: readonly ["checkpoint_created", "context_compacted", "fleet_recovered", "context_injected"];
|
|
42
|
+
readonly COORDINATION: readonly ["coordinator_decision", "coordinator_violation", "pilot_spawned", "pilot_completed", "review_started", "review_completed"];
|
|
43
|
+
};
|
|
44
|
+
export declare const PROGRAM_TYPE: {
|
|
45
|
+
readonly OPENCODE: "opencode";
|
|
46
|
+
readonly CLAUDE: "claude";
|
|
47
|
+
readonly STANDALONE: "standalone";
|
|
48
|
+
readonly UNKNOWN: "unknown";
|
|
49
|
+
};
|
|
50
|
+
export type ProgramType = typeof PROGRAM_TYPE[keyof typeof PROGRAM_TYPE];
|
|
51
|
+
export declare const DB_FILENAME = "fleet.db";
|
|
52
|
+
export declare const FLEET_DIR = ".fleet";
|
|
53
|
+
export declare const MAX_QUERY_RESULTS = 1000;
|
|
54
|
+
export declare const COMPACTION_THRESHOLD = 10000;
|
|
55
|
+
export declare const CHECKPOINT_TRIGGER: {
|
|
56
|
+
readonly AUTO: "auto";
|
|
57
|
+
readonly MANUAL: "manual";
|
|
58
|
+
readonly ERROR: "error";
|
|
59
|
+
readonly CONTEXT_LIMIT: "context_limit";
|
|
60
|
+
};
|
|
61
|
+
export type CheckpointTrigger = typeof CHECKPOINT_TRIGGER[keyof typeof CHECKPOINT_TRIGGER];
|
|
62
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,UAAU,CAAC;AAE/B,eAAO,MAAM,GAAG;;;;;CAKN,CAAC;AAEX,eAAO,MAAM,UAAU;;;;;CAKb,CAAC;AAEX,MAAM,MAAM,UAAU,GAAG,OAAO,UAAU,CAAC,MAAM,OAAO,UAAU,CAAC,CAAC;AAEpE,eAAO,MAAM,aAAa;;;;;CAKhB,CAAC;AAEX,MAAM,MAAM,YAAY,GAAG,OAAO,aAAa,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC;AAE5E,eAAO,MAAM,cAAc;;;;CAIjB,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,OAAO,cAAc,CAAC,MAAM,OAAO,cAAc,CAAC,CAAC;AAE/E,eAAO,MAAM,QAAQ;;;;;CAKX,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAC;AAE9D,eAAO,MAAM,gBAAgB;;;;;;;;CAQnB,CAAC;AAEX,eAAO,MAAM,YAAY;;;;;CAKf,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,OAAO,YAAY,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC;AAEzE,eAAO,MAAM,WAAW,aAAa,CAAC;AAEtC,eAAO,MAAM,SAAS,WAAW,CAAC;AAElC,eAAO,MAAM,iBAAiB,OAAO,CAAC;AAEtC,eAAO,MAAM,oBAAoB,QAAQ,CAAC;AAE1C,eAAO,MAAM,kBAAkB;;;;;CAKrB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,OAAO,kBAAkB,CAAC,MAAM,OAAO,kBAAkB,CAAC,CAAC"}
|
package/dist/ids.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FleetTools ID Generators
|
|
3
|
+
*
|
|
4
|
+
* Generates prefixed UUIDs for different entity types.
|
|
5
|
+
* All IDs follow the pattern: {prefix}-{uuid}
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* FleetTools ID prefixes
|
|
9
|
+
*/
|
|
10
|
+
export declare const ID_PREFIXES: {
|
|
11
|
+
readonly MISSION: "msn-";
|
|
12
|
+
readonly WORK_ORDER: "wo-";
|
|
13
|
+
readonly CHECKPOINT: "chk-";
|
|
14
|
+
readonly EVENT: "evt-";
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* FleetTools version
|
|
18
|
+
*/
|
|
19
|
+
export declare const FLEETTOOLS_VERSION = "0.1.0";
|
|
20
|
+
/**
|
|
21
|
+
* Branded ID types for compile-time safety
|
|
22
|
+
*/
|
|
23
|
+
export type MissionId = `msn-${string}`;
|
|
24
|
+
export type WorkOrderId = `wo-${string}`;
|
|
25
|
+
export type CheckpointId = `chk-${string}`;
|
|
26
|
+
export type EventId = `evt-${string}`;
|
|
27
|
+
/**
|
|
28
|
+
* Extract prefix from an ID
|
|
29
|
+
*/
|
|
30
|
+
export declare function extractPrefix(id: string): string | null;
|
|
31
|
+
/**
|
|
32
|
+
* Check if an ID has a valid prefix
|
|
33
|
+
*/
|
|
34
|
+
export declare function isValidPrefixId(id: string, prefix: string): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Generate a mission ID (msn-{uuid})
|
|
37
|
+
*/
|
|
38
|
+
export declare function generateMissionId(): MissionId;
|
|
39
|
+
/**
|
|
40
|
+
* Generate a work order ID (wo-{uuid})
|
|
41
|
+
*/
|
|
42
|
+
export declare function generateWorkOrderId(): WorkOrderId;
|
|
43
|
+
/**
|
|
44
|
+
* Generate a checkpoint ID (chk-{uuid})
|
|
45
|
+
*/
|
|
46
|
+
export declare function generateCheckpointId(): CheckpointId;
|
|
47
|
+
/**
|
|
48
|
+
* Generate an event ID (evt-{uuid})
|
|
49
|
+
*/
|
|
50
|
+
export declare function generateEventId(): EventId;
|
|
51
|
+
/**
|
|
52
|
+
* Generate an ISO 8601 timestamp
|
|
53
|
+
*/
|
|
54
|
+
export declare function generateTimestamp(): string;
|
|
55
|
+
/**
|
|
56
|
+
* Type guard for MissionId
|
|
57
|
+
*/
|
|
58
|
+
export declare function isMissionId(id: string): id is MissionId;
|
|
59
|
+
/**
|
|
60
|
+
* Type guard for WorkOrderId
|
|
61
|
+
*/
|
|
62
|
+
export declare function isWorkOrderId(id: string): id is WorkOrderId;
|
|
63
|
+
/**
|
|
64
|
+
* Type guard for CheckpointId
|
|
65
|
+
*/
|
|
66
|
+
export declare function isCheckpointId(id: string): id is CheckpointId;
|
|
67
|
+
/**
|
|
68
|
+
* Type guard for EventId
|
|
69
|
+
*/
|
|
70
|
+
export declare function isEventId(id: string): id is EventId;
|
|
71
|
+
//# sourceMappingURL=ids.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../src/ids.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;GAEG;AACH,eAAO,MAAM,WAAW;;;;;CAKd,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,kBAAkB,UAAU,CAAC;AAE1C;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,MAAM,EAAE,CAAC;AACxC,MAAM,MAAM,WAAW,GAAG,MAAM,MAAM,EAAE,CAAC;AACzC,MAAM,MAAM,YAAY,GAAG,OAAO,MAAM,EAAE,CAAC;AAC3C,MAAM,MAAM,OAAO,GAAG,OAAO,MAAM,EAAE,CAAC;AAEtC;;GAEG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGvD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAEnE;AASD;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,SAAS,CAE7C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,WAAW,CAEjD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,YAAY,CAEnD;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAEzC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,EAAE,IAAI,SAAS,CAEvD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,EAAE,IAAI,WAAW,CAE3D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,EAAE,IAAI,YAAY,CAE7D;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,EAAE,IAAI,OAAO,CAEnD"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FleetTools Core Package
|
|
3
|
+
*
|
|
4
|
+
* Core utilities, ID generators, and shared types for FleetTools.
|
|
5
|
+
*/
|
|
6
|
+
export { ID_PREFIXES, FLEETTOOLS_VERSION, generateMissionId, generateWorkOrderId, generateCheckpointId, generateEventId, generateTimestamp, extractPrefix, isValidPrefixId, isMissionId, isWorkOrderId, isCheckpointId, isEventId, } from './ids.js';
|
|
7
|
+
export { nowIso, toIso, fromUnixMs, fromIso, toUnixMs, nowUnixMs, formatDuration, durationBetween, addDuration, isPast, isFuture, formatDisplay, } from './timestamps.js';
|
|
8
|
+
export type { MissionStatus, WorkOrderStatus, CheckpointStatus, Priority, AggregateType, EventMetadata, BaseEvent, Snapshot, PaginationOptions, TimeRange, DatabaseConfig, Result, } from './types.js';
|
|
9
|
+
export { sleep, retry, deepClone, isValidJSON, safeJSONStringify, isValidFleetToolsId, extractUUIDFromId, generateSafeFilename, formatBytes, debounce, throttle, } from './utils.js';
|
|
10
|
+
export type { MissionId, WorkOrderId, CheckpointId, EventId, } from './ids.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,WAAW,EACX,aAAa,EACb,cAAc,EACd,SAAS,GACV,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,MAAM,EACN,KAAK,EACL,UAAU,EACV,OAAO,EACP,QAAQ,EACR,SAAS,EACT,cAAc,EACd,eAAe,EACf,WAAW,EACX,MAAM,EACN,QAAQ,EACR,aAAa,GACd,MAAM,iBAAiB,CAAC;AAGzB,YAAY,EACV,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,QAAQ,EACR,aAAa,EACb,aAAa,EACb,SAAS,EACT,QAAQ,EACR,iBAAiB,EACjB,SAAS,EACT,cAAc,EACd,MAAM,GACP,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,KAAK,EACL,KAAK,EACL,SAAS,EACT,WAAW,EACX,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,WAAW,EACX,QAAQ,EACR,QAAQ,GACT,MAAM,YAAY,CAAC;AAGpB,YAAY,EACV,SAAS,EACT,WAAW,EACX,YAAY,EACZ,OAAO,GACR,MAAM,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/ids.ts
|
|
3
|
+
import { randomUUID } from "crypto";
|
|
4
|
+
var ID_PREFIXES = {
|
|
5
|
+
MISSION: "msn-",
|
|
6
|
+
WORK_ORDER: "wo-",
|
|
7
|
+
CHECKPOINT: "chk-",
|
|
8
|
+
EVENT: "evt-"
|
|
9
|
+
};
|
|
10
|
+
var FLEETTOOLS_VERSION = "0.1.0";
|
|
11
|
+
function extractPrefix(id) {
|
|
12
|
+
const match = id.match(/^([a-z]{2,4}-)/);
|
|
13
|
+
return match?.[1] ?? null;
|
|
14
|
+
}
|
|
15
|
+
function isValidPrefixId(id, prefix) {
|
|
16
|
+
return id.startsWith(prefix) && extractPrefix(id) === prefix;
|
|
17
|
+
}
|
|
18
|
+
function generateUUID() {
|
|
19
|
+
return randomUUID();
|
|
20
|
+
}
|
|
21
|
+
function generateMissionId() {
|
|
22
|
+
return `msn-${generateUUID()}`;
|
|
23
|
+
}
|
|
24
|
+
function generateWorkOrderId() {
|
|
25
|
+
return `wo-${generateUUID()}`;
|
|
26
|
+
}
|
|
27
|
+
function generateCheckpointId() {
|
|
28
|
+
return `chk-${generateUUID()}`;
|
|
29
|
+
}
|
|
30
|
+
function generateEventId() {
|
|
31
|
+
return `evt-${generateUUID()}`;
|
|
32
|
+
}
|
|
33
|
+
function generateTimestamp() {
|
|
34
|
+
return new Date().toISOString();
|
|
35
|
+
}
|
|
36
|
+
function isMissionId(id) {
|
|
37
|
+
return isValidPrefixId(id, ID_PREFIXES.MISSION);
|
|
38
|
+
}
|
|
39
|
+
function isWorkOrderId(id) {
|
|
40
|
+
return isValidPrefixId(id, ID_PREFIXES.WORK_ORDER);
|
|
41
|
+
}
|
|
42
|
+
function isCheckpointId(id) {
|
|
43
|
+
return isValidPrefixId(id, ID_PREFIXES.CHECKPOINT);
|
|
44
|
+
}
|
|
45
|
+
function isEventId(id) {
|
|
46
|
+
return isValidPrefixId(id, ID_PREFIXES.EVENT);
|
|
47
|
+
}
|
|
48
|
+
// src/timestamps.ts
|
|
49
|
+
function nowIso() {
|
|
50
|
+
return new Date().toISOString();
|
|
51
|
+
}
|
|
52
|
+
function toIso(date) {
|
|
53
|
+
return date.toISOString();
|
|
54
|
+
}
|
|
55
|
+
function fromUnixMs(ms) {
|
|
56
|
+
return new Date(ms).toISOString();
|
|
57
|
+
}
|
|
58
|
+
function fromIso(iso) {
|
|
59
|
+
return new Date(iso);
|
|
60
|
+
}
|
|
61
|
+
function toUnixMs(date) {
|
|
62
|
+
return date.getTime();
|
|
63
|
+
}
|
|
64
|
+
function nowUnixMs() {
|
|
65
|
+
return Date.now();
|
|
66
|
+
}
|
|
67
|
+
function formatDuration(ms) {
|
|
68
|
+
const seconds = Math.floor(ms / 1000);
|
|
69
|
+
const minutes = Math.floor(seconds / 60);
|
|
70
|
+
const hours = Math.floor(minutes / 60);
|
|
71
|
+
const h = hours;
|
|
72
|
+
const m = minutes % 60;
|
|
73
|
+
const s = seconds % 60;
|
|
74
|
+
if (h > 0) {
|
|
75
|
+
return `${h}h ${m}m ${s}s`;
|
|
76
|
+
}
|
|
77
|
+
if (m > 0) {
|
|
78
|
+
return `${m}m ${s}s`;
|
|
79
|
+
}
|
|
80
|
+
return `${s}s`;
|
|
81
|
+
}
|
|
82
|
+
function durationBetween(startIso, endIso) {
|
|
83
|
+
const start = fromIso(startIso);
|
|
84
|
+
const end = fromIso(endIso);
|
|
85
|
+
return end.getTime() - start.getTime();
|
|
86
|
+
}
|
|
87
|
+
function addDuration(iso, ms) {
|
|
88
|
+
const date = fromIso(iso);
|
|
89
|
+
date.setTime(date.getTime() + ms);
|
|
90
|
+
return toIso(date);
|
|
91
|
+
}
|
|
92
|
+
function isPast(iso) {
|
|
93
|
+
return fromIso(iso).getTime() < Date.now();
|
|
94
|
+
}
|
|
95
|
+
function isFuture(iso) {
|
|
96
|
+
return fromIso(iso).getTime() > Date.now();
|
|
97
|
+
}
|
|
98
|
+
function formatDisplay(iso) {
|
|
99
|
+
return iso.replace("T", " ").replace(/\.\d+Z$/, "");
|
|
100
|
+
}
|
|
101
|
+
// src/utils.ts
|
|
102
|
+
function sleep(ms) {
|
|
103
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
104
|
+
}
|
|
105
|
+
async function retry(fn, maxAttempts = 3, baseDelay = 1000) {
|
|
106
|
+
let lastError;
|
|
107
|
+
for (let attempt = 1;attempt <= maxAttempts; attempt++) {
|
|
108
|
+
try {
|
|
109
|
+
const result = await fn();
|
|
110
|
+
return { success: true, data: result };
|
|
111
|
+
} catch (error) {
|
|
112
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
113
|
+
if (attempt === maxAttempts) {
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
const delay = baseDelay * Math.pow(2, attempt - 1);
|
|
117
|
+
await sleep(delay);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return { success: false, error: lastError };
|
|
121
|
+
}
|
|
122
|
+
function deepClone(obj) {
|
|
123
|
+
if (obj === null || typeof obj !== "object") {
|
|
124
|
+
return obj;
|
|
125
|
+
}
|
|
126
|
+
if (obj instanceof Date) {
|
|
127
|
+
return new Date(obj.getTime());
|
|
128
|
+
}
|
|
129
|
+
if (obj instanceof Array) {
|
|
130
|
+
return obj.map((item) => deepClone(item));
|
|
131
|
+
}
|
|
132
|
+
if (typeof obj === "object") {
|
|
133
|
+
const cloned = {};
|
|
134
|
+
for (const key in obj) {
|
|
135
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
136
|
+
cloned[key] = deepClone(obj[key]);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return cloned;
|
|
140
|
+
}
|
|
141
|
+
return obj;
|
|
142
|
+
}
|
|
143
|
+
function isValidJSON(str) {
|
|
144
|
+
try {
|
|
145
|
+
JSON.parse(str);
|
|
146
|
+
return true;
|
|
147
|
+
} catch {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function safeJSONStringify(obj, space) {
|
|
152
|
+
const seen = new WeakSet;
|
|
153
|
+
return JSON.stringify(obj, (key, value) => {
|
|
154
|
+
if (typeof value === "object" && value !== null) {
|
|
155
|
+
if (seen.has(value)) {
|
|
156
|
+
return "[Circular]";
|
|
157
|
+
}
|
|
158
|
+
seen.add(value);
|
|
159
|
+
}
|
|
160
|
+
return value;
|
|
161
|
+
}, space);
|
|
162
|
+
}
|
|
163
|
+
function isValidFleetToolsId(id) {
|
|
164
|
+
const validPrefixes = ["msn-", "wo-", "chk-", "evt-"];
|
|
165
|
+
const prefix = id.match(/^([a-z]{2,4}-)/);
|
|
166
|
+
return prefix ? validPrefixes.includes(prefix[1] || "") : false;
|
|
167
|
+
}
|
|
168
|
+
function extractUUIDFromId(id) {
|
|
169
|
+
const match = id.match(/^[a-z]{2,4}-(.+)$/);
|
|
170
|
+
return match?.[1] ?? null;
|
|
171
|
+
}
|
|
172
|
+
function generateSafeFilename(str) {
|
|
173
|
+
return str.toLowerCase().replace(/[^a-z0-9]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
174
|
+
}
|
|
175
|
+
function formatBytes(bytes, decimals = 2) {
|
|
176
|
+
if (bytes === 0)
|
|
177
|
+
return "0 Bytes";
|
|
178
|
+
const k = 1024;
|
|
179
|
+
const dm = decimals < 0 ? 0 : decimals;
|
|
180
|
+
const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
181
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
182
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
|
|
183
|
+
}
|
|
184
|
+
function debounce(fn, delay) {
|
|
185
|
+
let timeoutId;
|
|
186
|
+
return (...args) => {
|
|
187
|
+
clearTimeout(timeoutId);
|
|
188
|
+
timeoutId = setTimeout(() => fn(...args), delay);
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
function throttle(fn, delay) {
|
|
192
|
+
let lastCall = 0;
|
|
193
|
+
return (...args) => {
|
|
194
|
+
const now = Date.now();
|
|
195
|
+
if (now - lastCall >= delay) {
|
|
196
|
+
lastCall = now;
|
|
197
|
+
fn(...args);
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
export {
|
|
202
|
+
toUnixMs,
|
|
203
|
+
toIso,
|
|
204
|
+
throttle,
|
|
205
|
+
sleep,
|
|
206
|
+
safeJSONStringify,
|
|
207
|
+
retry,
|
|
208
|
+
nowUnixMs,
|
|
209
|
+
nowIso,
|
|
210
|
+
isWorkOrderId,
|
|
211
|
+
isValidPrefixId,
|
|
212
|
+
isValidJSON,
|
|
213
|
+
isValidFleetToolsId,
|
|
214
|
+
isPast,
|
|
215
|
+
isMissionId,
|
|
216
|
+
isFuture,
|
|
217
|
+
isEventId,
|
|
218
|
+
isCheckpointId,
|
|
219
|
+
generateWorkOrderId,
|
|
220
|
+
generateTimestamp,
|
|
221
|
+
generateSafeFilename,
|
|
222
|
+
generateMissionId,
|
|
223
|
+
generateEventId,
|
|
224
|
+
generateCheckpointId,
|
|
225
|
+
fromUnixMs,
|
|
226
|
+
fromIso,
|
|
227
|
+
formatDuration,
|
|
228
|
+
formatDisplay,
|
|
229
|
+
formatBytes,
|
|
230
|
+
extractUUIDFromId,
|
|
231
|
+
extractPrefix,
|
|
232
|
+
durationBetween,
|
|
233
|
+
deepClone,
|
|
234
|
+
debounce,
|
|
235
|
+
addDuration,
|
|
236
|
+
ID_PREFIXES,
|
|
237
|
+
FLEETTOOLS_VERSION
|
|
238
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function nowIso(): string;
|
|
2
|
+
export declare function toIso(date: Date): string;
|
|
3
|
+
export declare function fromUnixMs(ms: number): string;
|
|
4
|
+
export declare function fromIso(iso: string): Date;
|
|
5
|
+
export declare function toUnixMs(date: Date): number;
|
|
6
|
+
export declare function nowUnixMs(): number;
|
|
7
|
+
export declare function formatDuration(ms: number): string;
|
|
8
|
+
export declare function durationBetween(startIso: string, endIso: string): number;
|
|
9
|
+
export declare function addDuration(iso: string, ms: number): string;
|
|
10
|
+
export declare function isPast(iso: string): boolean;
|
|
11
|
+
export declare function isFuture(iso: string): boolean;
|
|
12
|
+
export declare function formatDisplay(iso: string): string;
|
|
13
|
+
//# sourceMappingURL=timestamps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timestamps.d.ts","sourceRoot":"","sources":["../src/timestamps.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,IAAI,MAAM,CAE/B;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAExC;AAED,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEzC;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE3C;AAED,wBAAgB,SAAS,IAAI,MAAM,CAElC;AAED,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAgBjD;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAIxE;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAI3D;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE3C;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE7C;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEjD"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FleetTools Core Types
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Status types for various entities
|
|
6
|
+
*/
|
|
7
|
+
export type MissionStatus = 'draft' | 'active' | 'in_progress' | 'completed' | 'cancelled' | 'archived';
|
|
8
|
+
export type WorkOrderStatus = 'pending' | 'in_progress' | 'completed' | 'failed' | 'cancelled';
|
|
9
|
+
export type CheckpointStatus = 'pending' | 'in_progress' | 'completed' | 'failed' | 'skipped';
|
|
10
|
+
/**
|
|
11
|
+
* Priority levels
|
|
12
|
+
*/
|
|
13
|
+
export type Priority = 'low' | 'medium' | 'high' | 'critical';
|
|
14
|
+
/**
|
|
15
|
+
* Aggregate types for event sourcing
|
|
16
|
+
*/
|
|
17
|
+
export type AggregateType = 'mission' | 'workorder' | 'checkpoint';
|
|
18
|
+
/**
|
|
19
|
+
* Event metadata for correlation and causation
|
|
20
|
+
*/
|
|
21
|
+
export interface EventMetadata {
|
|
22
|
+
correlationId?: string;
|
|
23
|
+
causationId?: string;
|
|
24
|
+
userId?: string;
|
|
25
|
+
sessionId?: string;
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Base event interface
|
|
30
|
+
*/
|
|
31
|
+
export interface BaseEvent {
|
|
32
|
+
id: string;
|
|
33
|
+
type: string;
|
|
34
|
+
aggregateId: string;
|
|
35
|
+
aggregateType: AggregateType;
|
|
36
|
+
timestamp: string;
|
|
37
|
+
version: number;
|
|
38
|
+
data: unknown;
|
|
39
|
+
metadata?: EventMetadata;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Snapshot interface for event store
|
|
43
|
+
*/
|
|
44
|
+
export interface Snapshot {
|
|
45
|
+
id: string;
|
|
46
|
+
aggregateId: string;
|
|
47
|
+
aggregateType: AggregateType;
|
|
48
|
+
data: unknown;
|
|
49
|
+
version: number;
|
|
50
|
+
timestamp: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Pagination options
|
|
54
|
+
*/
|
|
55
|
+
export interface PaginationOptions {
|
|
56
|
+
limit?: number;
|
|
57
|
+
offset?: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Time range options
|
|
61
|
+
*/
|
|
62
|
+
export interface TimeRange {
|
|
63
|
+
from: string;
|
|
64
|
+
to: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Database configuration
|
|
68
|
+
*/
|
|
69
|
+
export interface DatabaseConfig {
|
|
70
|
+
path?: string;
|
|
71
|
+
readonly?: boolean;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Result type for operations that may fail
|
|
75
|
+
*/
|
|
76
|
+
export type Result<T, E = Error> = {
|
|
77
|
+
success: true;
|
|
78
|
+
data: T;
|
|
79
|
+
} | {
|
|
80
|
+
success: false;
|
|
81
|
+
error: E;
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,MAAM,aAAa,GACrB,OAAO,GACP,QAAQ,GACR,aAAa,GACb,WAAW,GACX,WAAW,GACX,UAAU,CAAC;AAEf,MAAM,MAAM,eAAe,GACvB,SAAS,GACT,aAAa,GACb,WAAW,GACX,QAAQ,GACR,WAAW,CAAC;AAEhB,MAAM,MAAM,gBAAgB,GACxB,SAAS,GACT,aAAa,GACb,WAAW,GACX,QAAQ,GACR,SAAS,CAAC;AAEd;;GAEG;AACH,MAAM,MAAM,QAAQ,GAChB,KAAK,GACL,QAAQ,GACR,MAAM,GACN,UAAU,CAAC;AAEf;;GAEG;AACH,MAAM,MAAM,aAAa,GACrB,SAAS,GACT,WAAW,GACX,YAAY,CAAC;AAEjB;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,aAAa,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,CAAC,EAAE,aAAa,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,aAAa,CAAC;IAC7B,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAC3B;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GAC1B;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FleetTools Utility Functions
|
|
3
|
+
*/
|
|
4
|
+
import type { MissionId, WorkOrderId, CheckpointId, EventId } from './ids.js';
|
|
5
|
+
import type { Result } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Sleep function for async delays
|
|
8
|
+
*/
|
|
9
|
+
export declare function sleep(ms: number): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Retry function with exponential backoff
|
|
12
|
+
*/
|
|
13
|
+
export declare function retry<T>(fn: () => Promise<T>, maxAttempts?: number, baseDelay?: number): Promise<Result<T>>;
|
|
14
|
+
/**
|
|
15
|
+
* Deep clone function
|
|
16
|
+
*/
|
|
17
|
+
export declare function deepClone<T>(obj: T): T;
|
|
18
|
+
/**
|
|
19
|
+
* Validate JSON string
|
|
20
|
+
*/
|
|
21
|
+
export declare function isValidJSON(str: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Safe JSON stringify with circular reference protection
|
|
24
|
+
*/
|
|
25
|
+
export declare function safeJSONStringify(obj: unknown, space?: number): string;
|
|
26
|
+
/**
|
|
27
|
+
* Validate FleetTools ID format
|
|
28
|
+
*/
|
|
29
|
+
export declare function isValidFleetToolsId(id: string): id is MissionId | WorkOrderId | CheckpointId | EventId;
|
|
30
|
+
/**
|
|
31
|
+
* Extract UUID from FleetTools ID
|
|
32
|
+
*/
|
|
33
|
+
export declare function extractUUIDFromId(id: string): string | null;
|
|
34
|
+
/**
|
|
35
|
+
* Generate a safe filename from a string
|
|
36
|
+
*/
|
|
37
|
+
export declare function generateSafeFilename(str: string): string;
|
|
38
|
+
/**
|
|
39
|
+
* Convert bytes to human readable format
|
|
40
|
+
*/
|
|
41
|
+
export declare function formatBytes(bytes: number, decimals?: number): string;
|
|
42
|
+
/**
|
|
43
|
+
* Debounce function
|
|
44
|
+
*/
|
|
45
|
+
export declare function debounce<T extends (...args: any[]) => any>(fn: T, delay: number): (...args: Parameters<T>) => void;
|
|
46
|
+
/**
|
|
47
|
+
* Throttle function
|
|
48
|
+
*/
|
|
49
|
+
export declare function throttle<T extends (...args: any[]) => any>(fn: T, delay: number): (...args: Parameters<T>) => void;
|
|
50
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAC9E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC;;GAEG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C;AAED;;GAEG;AACH,wBAAsB,KAAK,CAAC,CAAC,EAC3B,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,WAAW,GAAE,MAAU,EACvB,SAAS,GAAE,MAAa,GACvB,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAoBpB;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAwBtC;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAOhD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAWtE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,MAAM,GAAG,EAAE,IAAI,SAAS,GAAG,WAAW,GAAG,YAAY,GAAG,OAAO,CAItG;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAG3D;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAMxD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAU,GAAG,MAAM,CAUvE;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACxD,EAAE,EAAE,CAAC,EACL,KAAK,EAAE,MAAM,GACZ,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAOlC;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACxD,EAAE,EAAE,CAAC,EACL,KAAK,EAAE,MAAM,GACZ,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAUlC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fleettools/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Core utilities and types for FleetTools",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "bun build src/index.ts --outdir dist --target bun --format esm && bun run build:types",
|
|
15
|
+
"build:types": "tsc --emitDeclarationOnly",
|
|
16
|
+
"dev": "bun --watch src/index.ts",
|
|
17
|
+
"test": "bun test",
|
|
18
|
+
"test:watch": "bun test --watch",
|
|
19
|
+
"test:coverage": "bun test --coverage"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"typescript": "^5.9.3",
|
|
23
|
+
"@types/bun": "^1.3.5"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"README.md"
|
|
28
|
+
],
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
}
|
|
32
|
+
}
|