@aigne/afs-compute-abstraction 1.11.0-beta.6
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/LICENSE.md +26 -0
- package/dist/src/index.d.ts +30 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +30 -0
- package/dist/src/instance-mapper.d.ts +35 -0
- package/dist/src/instance-mapper.d.ts.map +1 -0
- package/dist/src/instance-mapper.js +66 -0
- package/dist/src/providers/ec2.d.ts +15 -0
- package/dist/src/providers/ec2.d.ts.map +1 -0
- package/dist/src/providers/ec2.js +78 -0
- package/dist/src/providers/gce.d.ts +15 -0
- package/dist/src/providers/gce.d.ts.map +1 -0
- package/dist/src/providers/gce.js +74 -0
- package/dist/src/types.d.ts +142 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +70 -0
- package/dist/test/index.test.d.ts +5 -0
- package/dist/test/index.test.d.ts.map +1 -0
- package/dist/test/index.test.js +94 -0
- package/dist/test/instance-mapper.test.d.ts +5 -0
- package/dist/test/instance-mapper.test.d.ts.map +1 -0
- package/dist/test/instance-mapper.test.js +118 -0
- package/dist/test/providers/ec2.test.d.ts +5 -0
- package/dist/test/providers/ec2.test.d.ts.map +1 -0
- package/dist/test/providers/ec2.test.js +166 -0
- package/dist/test/providers/gce.test.d.ts +5 -0
- package/dist/test/providers/gce.test.d.ts.map +1 -0
- package/dist/test/providers/gce.test.js +188 -0
- package/dist/test/types.test.d.ts +5 -0
- package/dist/test/types.test.d.ts.map +1 -0
- package/dist/test/types.test.js +96 -0
- package/package.json +66 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Proprietary License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2025 ArcBlock, Inc. All Rights Reserved.
|
|
4
|
+
|
|
5
|
+
This software and associated documentation files (the "Software") are proprietary
|
|
6
|
+
and confidential. Unauthorized copying, modification, distribution, or use of
|
|
7
|
+
this Software, via any medium, is strictly prohibited.
|
|
8
|
+
|
|
9
|
+
The Software is provided for internal use only within ArcBlock, Inc. and its
|
|
10
|
+
authorized affiliates.
|
|
11
|
+
|
|
12
|
+
## No License Granted
|
|
13
|
+
|
|
14
|
+
No license, express or implied, is granted to any party for any purpose.
|
|
15
|
+
All rights are reserved by ArcBlock, Inc.
|
|
16
|
+
|
|
17
|
+
## Public Artifact Distribution
|
|
18
|
+
|
|
19
|
+
Portions of this Software may be released publicly under separate open-source
|
|
20
|
+
licenses (such as MIT License) through designated public repositories. Such
|
|
21
|
+
public releases are governed by their respective licenses and do not affect
|
|
22
|
+
the proprietary nature of this repository.
|
|
23
|
+
|
|
24
|
+
## Contact
|
|
25
|
+
|
|
26
|
+
For licensing inquiries, contact: legal@arcblock.io
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AFS Compute Abstraction
|
|
3
|
+
*
|
|
4
|
+
* Provides a unified interface for compute instances across cloud providers (EC2, GCE).
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { mapInstances, isInstance } from "@aigne/afs-compute-abstraction";
|
|
9
|
+
*
|
|
10
|
+
* // Get entries from AFS (EC2 or GCE providers)
|
|
11
|
+
* const entries = await afs.list("/modules/ec2/instances");
|
|
12
|
+
*
|
|
13
|
+
* // Filter to instances only
|
|
14
|
+
* const instanceEntries = entries.data.filter(isInstance);
|
|
15
|
+
*
|
|
16
|
+
* // Map to unified ComputeInstance format
|
|
17
|
+
* const instances = mapInstances(instanceEntries);
|
|
18
|
+
*
|
|
19
|
+
* // Now you can work with instances in a provider-agnostic way
|
|
20
|
+
* for (const instance of instances) {
|
|
21
|
+
* console.log(`${instance.name}: ${instance.state} (${instance.provider})`);
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export { isInstance, type MapInstancesOptions, mapInstance, mapInstances, } from "./instance-mapper.js";
|
|
26
|
+
export { mapEC2Instance } from "./providers/ec2.js";
|
|
27
|
+
export { mapGCEInstance } from "./providers/gce.js";
|
|
28
|
+
export type { ComputeInstance, ComputeInstanceState, ComputePlatformRef, ComputeProvider, } from "./types.js";
|
|
29
|
+
export { COMPUTE_PROVIDERS, COMPUTE_STATES, computeInstanceSchema, computePlatformRefSchema, EC2_STATE_MAP, GCE_STATE_MAP, } from "./types.js";
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,EACL,UAAU,EACV,KAAK,mBAAmB,EACxB,WAAW,EACX,YAAY,GACb,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,YAAY,EACV,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EACrB,wBAAwB,EACxB,aAAa,EACb,aAAa,GACd,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AFS Compute Abstraction
|
|
3
|
+
*
|
|
4
|
+
* Provides a unified interface for compute instances across cloud providers (EC2, GCE).
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { mapInstances, isInstance } from "@aigne/afs-compute-abstraction";
|
|
9
|
+
*
|
|
10
|
+
* // Get entries from AFS (EC2 or GCE providers)
|
|
11
|
+
* const entries = await afs.list("/modules/ec2/instances");
|
|
12
|
+
*
|
|
13
|
+
* // Filter to instances only
|
|
14
|
+
* const instanceEntries = entries.data.filter(isInstance);
|
|
15
|
+
*
|
|
16
|
+
* // Map to unified ComputeInstance format
|
|
17
|
+
* const instances = mapInstances(instanceEntries);
|
|
18
|
+
*
|
|
19
|
+
* // Now you can work with instances in a provider-agnostic way
|
|
20
|
+
* for (const instance of instances) {
|
|
21
|
+
* console.log(`${instance.name}: ${instance.state} (${instance.provider})`);
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
// Re-export mapper functions
|
|
26
|
+
export { isInstance, mapInstance, mapInstances, } from "./instance-mapper.js";
|
|
27
|
+
// Re-export provider-specific mappers
|
|
28
|
+
export { mapEC2Instance } from "./providers/ec2.js";
|
|
29
|
+
export { mapGCEInstance } from "./providers/gce.js";
|
|
30
|
+
export { COMPUTE_PROVIDERS, COMPUTE_STATES, computeInstanceSchema, computePlatformRefSchema, EC2_STATE_MAP, GCE_STATE_MAP, } from "./types.js";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Instance Mapper
|
|
3
|
+
*
|
|
4
|
+
* Maps AFS entries to unified ComputeInstance format based on their kind.
|
|
5
|
+
*/
|
|
6
|
+
import type { AFSEntry } from "@aigne/afs";
|
|
7
|
+
import type { ComputeInstance } from "./types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Options for mapping instances
|
|
10
|
+
*/
|
|
11
|
+
export interface MapInstancesOptions {
|
|
12
|
+
/** Skip unknown kinds instead of throwing errors */
|
|
13
|
+
skipUnknown?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Check if entry is any supported instance type
|
|
17
|
+
*/
|
|
18
|
+
export declare function isInstance(entry: AFSEntry): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Map a single AFS entry to ComputeInstance
|
|
21
|
+
*
|
|
22
|
+
* @param entry - AFS entry from any compute provider
|
|
23
|
+
* @returns Unified ComputeInstance
|
|
24
|
+
* @throws Error if the entry kind is not supported
|
|
25
|
+
*/
|
|
26
|
+
export declare function mapInstance(entry: AFSEntry): ComputeInstance;
|
|
27
|
+
/**
|
|
28
|
+
* Map multiple AFS entries to ComputeInstances
|
|
29
|
+
*
|
|
30
|
+
* @param entries - AFS entries from compute providers
|
|
31
|
+
* @param options - Mapping options
|
|
32
|
+
* @returns Array of unified ComputeInstances
|
|
33
|
+
*/
|
|
34
|
+
export declare function mapInstances(entries: AFSEntry[], options?: MapInstancesOptions): ComputeInstance[];
|
|
35
|
+
//# sourceMappingURL=instance-mapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instance-mapper.d.ts","sourceRoot":"","sources":["../../src/instance-mapper.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAG3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,oDAAoD;IACpD,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAgBD;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAEnD;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAG,eAAe,CAU5D;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,QAAQ,EAAE,EACnB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,eAAe,EAAE,CAmBnB"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Instance Mapper
|
|
3
|
+
*
|
|
4
|
+
* Maps AFS entries to unified ComputeInstance format based on their kind.
|
|
5
|
+
*/
|
|
6
|
+
import { mapEC2Instance } from "./providers/ec2.js";
|
|
7
|
+
import { mapGCEInstance } from "./providers/gce.js";
|
|
8
|
+
/**
|
|
9
|
+
* Check if entry is an EC2 instance
|
|
10
|
+
*/
|
|
11
|
+
function isEC2Instance(entry) {
|
|
12
|
+
return entry.metadata?.kind === "ec2:instance";
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Check if entry is a GCE instance
|
|
16
|
+
*/
|
|
17
|
+
function isGCEInstance(entry) {
|
|
18
|
+
return entry.metadata?.kind === "gce:instance";
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Check if entry is any supported instance type
|
|
22
|
+
*/
|
|
23
|
+
export function isInstance(entry) {
|
|
24
|
+
return isEC2Instance(entry) || isGCEInstance(entry);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Map a single AFS entry to ComputeInstance
|
|
28
|
+
*
|
|
29
|
+
* @param entry - AFS entry from any compute provider
|
|
30
|
+
* @returns Unified ComputeInstance
|
|
31
|
+
* @throws Error if the entry kind is not supported
|
|
32
|
+
*/
|
|
33
|
+
export function mapInstance(entry) {
|
|
34
|
+
if (isEC2Instance(entry)) {
|
|
35
|
+
return mapEC2Instance(entry);
|
|
36
|
+
}
|
|
37
|
+
if (isGCEInstance(entry)) {
|
|
38
|
+
return mapGCEInstance(entry);
|
|
39
|
+
}
|
|
40
|
+
throw new Error(`Unsupported instance kind: ${entry.metadata?.kind}`);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Map multiple AFS entries to ComputeInstances
|
|
44
|
+
*
|
|
45
|
+
* @param entries - AFS entries from compute providers
|
|
46
|
+
* @param options - Mapping options
|
|
47
|
+
* @returns Array of unified ComputeInstances
|
|
48
|
+
*/
|
|
49
|
+
export function mapInstances(entries, options) {
|
|
50
|
+
const result = [];
|
|
51
|
+
for (const entry of entries) {
|
|
52
|
+
if (options?.skipUnknown && !isInstance(entry)) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
result.push(mapInstance(entry));
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (!options?.skipUnknown) {
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
// Skip unknown kinds when skipUnknown is true
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EC2 Adapter
|
|
3
|
+
*
|
|
4
|
+
* Maps EC2 instance entries to unified ComputeInstance format.
|
|
5
|
+
*/
|
|
6
|
+
import type { AFSEntry } from "@aigne/afs";
|
|
7
|
+
import type { ComputeInstance } from "../types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Map EC2 instance entry to ComputeInstance
|
|
10
|
+
*
|
|
11
|
+
* @param entry - AFS entry from EC2 provider
|
|
12
|
+
* @returns Unified ComputeInstance
|
|
13
|
+
*/
|
|
14
|
+
export declare function mapEC2Instance(entry: AFSEntry): ComputeInstance;
|
|
15
|
+
//# sourceMappingURL=ec2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ec2.d.ts","sourceRoot":"","sources":["../../../src/providers/ec2.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAwB,MAAM,aAAa,CAAC;AAqBzE;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,QAAQ,GAAG,eAAe,CAoD/D"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EC2 Adapter
|
|
3
|
+
*
|
|
4
|
+
* Maps EC2 instance entries to unified ComputeInstance format.
|
|
5
|
+
*/
|
|
6
|
+
import { EC2_STATE_MAP } from "../types.js";
|
|
7
|
+
/**
|
|
8
|
+
* Extract instance name from path
|
|
9
|
+
*
|
|
10
|
+
* Path format: /instances/{name}
|
|
11
|
+
*/
|
|
12
|
+
function extractInstanceName(path) {
|
|
13
|
+
const segments = path.split("/").filter(Boolean);
|
|
14
|
+
return segments[segments.length - 1] || "unknown";
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Map EC2 state to unified state
|
|
18
|
+
*/
|
|
19
|
+
function mapState(ec2State) {
|
|
20
|
+
if (!ec2State)
|
|
21
|
+
return "unknown";
|
|
22
|
+
return EC2_STATE_MAP[ec2State] || "unknown";
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Map EC2 instance entry to ComputeInstance
|
|
26
|
+
*
|
|
27
|
+
* @param entry - AFS entry from EC2 provider
|
|
28
|
+
* @returns Unified ComputeInstance
|
|
29
|
+
*/
|
|
30
|
+
export function mapEC2Instance(entry) {
|
|
31
|
+
const metadata = entry.metadata || {};
|
|
32
|
+
// Extract AWS-specific metadata for passthrough
|
|
33
|
+
const aws = {};
|
|
34
|
+
const awsFields = [
|
|
35
|
+
"instanceId",
|
|
36
|
+
"availabilityZone",
|
|
37
|
+
"vpcId",
|
|
38
|
+
"subnetId",
|
|
39
|
+
"tags",
|
|
40
|
+
"securityGroups",
|
|
41
|
+
"iamInstanceProfile",
|
|
42
|
+
"ebsOptimized",
|
|
43
|
+
"architecture",
|
|
44
|
+
"hypervisor",
|
|
45
|
+
"rootDeviceType",
|
|
46
|
+
"rootDeviceName",
|
|
47
|
+
"blockDeviceMappings",
|
|
48
|
+
"networkInterfaces",
|
|
49
|
+
"placement",
|
|
50
|
+
];
|
|
51
|
+
for (const field of awsFields) {
|
|
52
|
+
if (metadata[field] !== undefined) {
|
|
53
|
+
aws[field] = metadata[field];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// Parse launch time if present
|
|
57
|
+
let launchTime;
|
|
58
|
+
if (metadata.launchTime) {
|
|
59
|
+
launchTime = new Date(metadata.launchTime);
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
id: metadata.instanceId || entry.id,
|
|
63
|
+
name: extractInstanceName(entry.path),
|
|
64
|
+
state: mapState(metadata.state),
|
|
65
|
+
provider: "ec2",
|
|
66
|
+
instanceType: metadata.instanceType || "unknown",
|
|
67
|
+
vcpus: metadata.vcpus,
|
|
68
|
+
memoryGb: metadata.memoryGb,
|
|
69
|
+
publicIp: metadata.publicIp,
|
|
70
|
+
privateIp: metadata.privateIp,
|
|
71
|
+
launchTime,
|
|
72
|
+
platformRef: {
|
|
73
|
+
consoleUrl: metadata.platformRef?.consoleUrl || "",
|
|
74
|
+
afsPath: entry.path,
|
|
75
|
+
},
|
|
76
|
+
aws: Object.keys(aws).length > 0 ? aws : undefined,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GCE Adapter
|
|
3
|
+
*
|
|
4
|
+
* Maps GCE instance entries to unified ComputeInstance format.
|
|
5
|
+
*/
|
|
6
|
+
import type { AFSEntry } from "@aigne/afs";
|
|
7
|
+
import type { ComputeInstance } from "../types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Map GCE instance entry to ComputeInstance
|
|
10
|
+
*
|
|
11
|
+
* @param entry - AFS entry from GCE provider
|
|
12
|
+
* @returns Unified ComputeInstance
|
|
13
|
+
*/
|
|
14
|
+
export declare function mapGCEInstance(entry: AFSEntry): ComputeInstance;
|
|
15
|
+
//# sourceMappingURL=gce.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gce.d.ts","sourceRoot":"","sources":["../../../src/providers/gce.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAwB,MAAM,aAAa,CAAC;AAqBzE;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,QAAQ,GAAG,eAAe,CAgD/D"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GCE Adapter
|
|
3
|
+
*
|
|
4
|
+
* Maps GCE instance entries to unified ComputeInstance format.
|
|
5
|
+
*/
|
|
6
|
+
import { GCE_STATE_MAP } from "../types.js";
|
|
7
|
+
/**
|
|
8
|
+
* Extract instance name from path
|
|
9
|
+
*
|
|
10
|
+
* Path format: /instances/{name}
|
|
11
|
+
*/
|
|
12
|
+
function extractInstanceName(path) {
|
|
13
|
+
const segments = path.split("/").filter(Boolean);
|
|
14
|
+
return segments[segments.length - 1] || "unknown";
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Map GCE status to unified state
|
|
18
|
+
*/
|
|
19
|
+
function mapState(gceStatus) {
|
|
20
|
+
if (!gceStatus)
|
|
21
|
+
return "unknown";
|
|
22
|
+
return GCE_STATE_MAP[gceStatus] || "unknown";
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Map GCE instance entry to ComputeInstance
|
|
26
|
+
*
|
|
27
|
+
* @param entry - AFS entry from GCE provider
|
|
28
|
+
* @returns Unified ComputeInstance
|
|
29
|
+
*/
|
|
30
|
+
export function mapGCEInstance(entry) {
|
|
31
|
+
const metadata = entry.metadata || {};
|
|
32
|
+
// Extract GCP-specific metadata for passthrough
|
|
33
|
+
const gcp = {};
|
|
34
|
+
const gcpFields = [
|
|
35
|
+
"zone",
|
|
36
|
+
"labels",
|
|
37
|
+
"networkInterfaces",
|
|
38
|
+
"disks",
|
|
39
|
+
"serviceAccounts",
|
|
40
|
+
"scheduling",
|
|
41
|
+
"metadata",
|
|
42
|
+
"tags",
|
|
43
|
+
"canIpForward",
|
|
44
|
+
"startRestricted",
|
|
45
|
+
"deletionProtection",
|
|
46
|
+
];
|
|
47
|
+
for (const field of gcpFields) {
|
|
48
|
+
if (metadata[field] !== undefined) {
|
|
49
|
+
gcp[field] = metadata[field];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// Parse creation time if present
|
|
53
|
+
let launchTime;
|
|
54
|
+
if (metadata.createdAt) {
|
|
55
|
+
launchTime = new Date(metadata.createdAt);
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
id: entry.id,
|
|
59
|
+
name: extractInstanceName(entry.path),
|
|
60
|
+
state: mapState(metadata.status),
|
|
61
|
+
provider: "gce",
|
|
62
|
+
instanceType: metadata.machineType || "unknown",
|
|
63
|
+
vcpus: metadata.vcpus,
|
|
64
|
+
memoryGb: metadata.memoryGb,
|
|
65
|
+
publicIp: metadata.publicIp,
|
|
66
|
+
privateIp: metadata.privateIp,
|
|
67
|
+
launchTime,
|
|
68
|
+
platformRef: {
|
|
69
|
+
consoleUrl: metadata.platformRef?.consoleUrl || "",
|
|
70
|
+
afsPath: entry.path,
|
|
71
|
+
},
|
|
72
|
+
gcp: Object.keys(gcp).length > 0 ? gcp : undefined,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compute Abstraction Types
|
|
3
|
+
*
|
|
4
|
+
* Unified types for compute instances across cloud providers.
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
/**
|
|
8
|
+
* Supported cloud providers
|
|
9
|
+
*/
|
|
10
|
+
export declare const COMPUTE_PROVIDERS: readonly ["ec2", "gce"];
|
|
11
|
+
export type ComputeProvider = (typeof COMPUTE_PROVIDERS)[number];
|
|
12
|
+
/**
|
|
13
|
+
* Unified instance states
|
|
14
|
+
*/
|
|
15
|
+
export declare const COMPUTE_STATES: readonly ["running", "stopped", "pending", "terminated", "stopping", "unknown"];
|
|
16
|
+
export type ComputeInstanceState = (typeof COMPUTE_STATES)[number];
|
|
17
|
+
/**
|
|
18
|
+
* Platform reference for the original resource
|
|
19
|
+
*/
|
|
20
|
+
export interface ComputePlatformRef {
|
|
21
|
+
/** URL to the cloud console for this resource */
|
|
22
|
+
consoleUrl: string;
|
|
23
|
+
/** Original AFS path in the provider */
|
|
24
|
+
afsPath: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Unified compute instance type
|
|
28
|
+
*
|
|
29
|
+
* Represents a compute instance from any supported cloud provider
|
|
30
|
+
* with normalized fields for easy comparison and manipulation.
|
|
31
|
+
*/
|
|
32
|
+
export interface ComputeInstance {
|
|
33
|
+
/** Unique identifier (provider-specific) */
|
|
34
|
+
id: string;
|
|
35
|
+
/** Instance name */
|
|
36
|
+
name: string;
|
|
37
|
+
/** Normalized instance state */
|
|
38
|
+
state: ComputeInstanceState;
|
|
39
|
+
/** Source provider */
|
|
40
|
+
provider: ComputeProvider;
|
|
41
|
+
/** Instance type (original name, e.g., "t2.micro", "n1-standard-1") */
|
|
42
|
+
instanceType: string;
|
|
43
|
+
/** Number of vCPUs (if available) */
|
|
44
|
+
vcpus?: number;
|
|
45
|
+
/** Memory in GB (if available) */
|
|
46
|
+
memoryGb?: number;
|
|
47
|
+
/** Public IP address (if assigned) */
|
|
48
|
+
publicIp?: string;
|
|
49
|
+
/** Private IP address */
|
|
50
|
+
privateIp?: string;
|
|
51
|
+
/** Instance launch time */
|
|
52
|
+
launchTime?: Date;
|
|
53
|
+
/** Platform reference for console URL and original path */
|
|
54
|
+
platformRef: ComputePlatformRef;
|
|
55
|
+
/** AWS-specific metadata (passthrough) */
|
|
56
|
+
aws?: Record<string, unknown>;
|
|
57
|
+
/** GCP-specific metadata (passthrough) */
|
|
58
|
+
gcp?: Record<string, unknown>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Zod schema for platform reference
|
|
62
|
+
*/
|
|
63
|
+
export declare const computePlatformRefSchema: z.ZodObject<{
|
|
64
|
+
consoleUrl: z.ZodString;
|
|
65
|
+
afsPath: z.ZodString;
|
|
66
|
+
}, "strip", z.ZodTypeAny, {
|
|
67
|
+
consoleUrl: string;
|
|
68
|
+
afsPath: string;
|
|
69
|
+
}, {
|
|
70
|
+
consoleUrl: string;
|
|
71
|
+
afsPath: string;
|
|
72
|
+
}>;
|
|
73
|
+
/**
|
|
74
|
+
* Zod schema for compute instance validation
|
|
75
|
+
*/
|
|
76
|
+
export declare const computeInstanceSchema: z.ZodObject<{
|
|
77
|
+
id: z.ZodString;
|
|
78
|
+
name: z.ZodString;
|
|
79
|
+
state: z.ZodEnum<["running", "stopped", "pending", "terminated", "stopping", "unknown"]>;
|
|
80
|
+
provider: z.ZodEnum<["ec2", "gce"]>;
|
|
81
|
+
instanceType: z.ZodString;
|
|
82
|
+
vcpus: z.ZodOptional<z.ZodNumber>;
|
|
83
|
+
memoryGb: z.ZodOptional<z.ZodNumber>;
|
|
84
|
+
publicIp: z.ZodOptional<z.ZodString>;
|
|
85
|
+
privateIp: z.ZodOptional<z.ZodString>;
|
|
86
|
+
launchTime: z.ZodOptional<z.ZodDate>;
|
|
87
|
+
platformRef: z.ZodObject<{
|
|
88
|
+
consoleUrl: z.ZodString;
|
|
89
|
+
afsPath: z.ZodString;
|
|
90
|
+
}, "strip", z.ZodTypeAny, {
|
|
91
|
+
consoleUrl: string;
|
|
92
|
+
afsPath: string;
|
|
93
|
+
}, {
|
|
94
|
+
consoleUrl: string;
|
|
95
|
+
afsPath: string;
|
|
96
|
+
}>;
|
|
97
|
+
aws: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
98
|
+
gcp: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
99
|
+
}, "strip", z.ZodTypeAny, {
|
|
100
|
+
id: string;
|
|
101
|
+
name: string;
|
|
102
|
+
state: "running" | "stopped" | "pending" | "terminated" | "stopping" | "unknown";
|
|
103
|
+
provider: "ec2" | "gce";
|
|
104
|
+
instanceType: string;
|
|
105
|
+
platformRef: {
|
|
106
|
+
consoleUrl: string;
|
|
107
|
+
afsPath: string;
|
|
108
|
+
};
|
|
109
|
+
vcpus?: number | undefined;
|
|
110
|
+
memoryGb?: number | undefined;
|
|
111
|
+
publicIp?: string | undefined;
|
|
112
|
+
privateIp?: string | undefined;
|
|
113
|
+
launchTime?: Date | undefined;
|
|
114
|
+
aws?: Record<string, unknown> | undefined;
|
|
115
|
+
gcp?: Record<string, unknown> | undefined;
|
|
116
|
+
}, {
|
|
117
|
+
id: string;
|
|
118
|
+
name: string;
|
|
119
|
+
state: "running" | "stopped" | "pending" | "terminated" | "stopping" | "unknown";
|
|
120
|
+
provider: "ec2" | "gce";
|
|
121
|
+
instanceType: string;
|
|
122
|
+
platformRef: {
|
|
123
|
+
consoleUrl: string;
|
|
124
|
+
afsPath: string;
|
|
125
|
+
};
|
|
126
|
+
vcpus?: number | undefined;
|
|
127
|
+
memoryGb?: number | undefined;
|
|
128
|
+
publicIp?: string | undefined;
|
|
129
|
+
privateIp?: string | undefined;
|
|
130
|
+
launchTime?: Date | undefined;
|
|
131
|
+
aws?: Record<string, unknown> | undefined;
|
|
132
|
+
gcp?: Record<string, unknown> | undefined;
|
|
133
|
+
}>;
|
|
134
|
+
/**
|
|
135
|
+
* State mapping from EC2 states to unified states
|
|
136
|
+
*/
|
|
137
|
+
export declare const EC2_STATE_MAP: Record<string, ComputeInstanceState>;
|
|
138
|
+
/**
|
|
139
|
+
* State mapping from GCE states to unified states
|
|
140
|
+
*/
|
|
141
|
+
export declare const GCE_STATE_MAP: Record<string, ComputeInstanceState>;
|
|
142
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AACH,eAAO,MAAM,iBAAiB,yBAA0B,CAAC;AACzD,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjE;;GAEG;AACH,eAAO,MAAM,cAAc,iFAOjB,CAAC;AACX,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,iDAAiD;IACjD,UAAU,EAAE,MAAM,CAAC;IACnB,wCAAwC;IACxC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,4CAA4C;IAC5C,EAAE,EAAE,MAAM,CAAC;IAEX,oBAAoB;IACpB,IAAI,EAAE,MAAM,CAAC;IAEb,gCAAgC;IAChC,KAAK,EAAE,oBAAoB,CAAC;IAE5B,sBAAsB;IACtB,QAAQ,EAAE,eAAe,CAAC;IAE1B,uEAAuE;IACvE,YAAY,EAAE,MAAM,CAAC;IAErB,qCAAqC;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,kCAAkC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,sCAAsC;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,yBAAyB;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,2BAA2B;IAC3B,UAAU,CAAC,EAAE,IAAI,CAAC;IAElB,2DAA2D;IAC3D,WAAW,EAAE,kBAAkB,CAAC;IAEhC,0CAA0C;IAC1C,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE9B,0CAA0C;IAC1C,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED;;GAEG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;EAGnC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAchC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAO9D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAS9D,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compute Abstraction Types
|
|
3
|
+
*
|
|
4
|
+
* Unified types for compute instances across cloud providers.
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
/**
|
|
8
|
+
* Supported cloud providers
|
|
9
|
+
*/
|
|
10
|
+
export const COMPUTE_PROVIDERS = ["ec2", "gce"];
|
|
11
|
+
/**
|
|
12
|
+
* Unified instance states
|
|
13
|
+
*/
|
|
14
|
+
export const COMPUTE_STATES = [
|
|
15
|
+
"running",
|
|
16
|
+
"stopped",
|
|
17
|
+
"pending",
|
|
18
|
+
"terminated",
|
|
19
|
+
"stopping",
|
|
20
|
+
"unknown",
|
|
21
|
+
];
|
|
22
|
+
/**
|
|
23
|
+
* Zod schema for platform reference
|
|
24
|
+
*/
|
|
25
|
+
export const computePlatformRefSchema = z.object({
|
|
26
|
+
consoleUrl: z.string(),
|
|
27
|
+
afsPath: z.string(),
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* Zod schema for compute instance validation
|
|
31
|
+
*/
|
|
32
|
+
export const computeInstanceSchema = z.object({
|
|
33
|
+
id: z.string(),
|
|
34
|
+
name: z.string(),
|
|
35
|
+
state: z.enum(COMPUTE_STATES),
|
|
36
|
+
provider: z.enum(COMPUTE_PROVIDERS),
|
|
37
|
+
instanceType: z.string(),
|
|
38
|
+
vcpus: z.number().int().positive().optional(),
|
|
39
|
+
memoryGb: z.number().positive().optional(),
|
|
40
|
+
publicIp: z.string().optional(),
|
|
41
|
+
privateIp: z.string().optional(),
|
|
42
|
+
launchTime: z.date().optional(),
|
|
43
|
+
platformRef: computePlatformRefSchema,
|
|
44
|
+
aws: z.record(z.unknown()).optional(),
|
|
45
|
+
gcp: z.record(z.unknown()).optional(),
|
|
46
|
+
});
|
|
47
|
+
/**
|
|
48
|
+
* State mapping from EC2 states to unified states
|
|
49
|
+
*/
|
|
50
|
+
export const EC2_STATE_MAP = {
|
|
51
|
+
running: "running",
|
|
52
|
+
stopped: "stopped",
|
|
53
|
+
pending: "pending",
|
|
54
|
+
terminated: "terminated",
|
|
55
|
+
stopping: "stopping",
|
|
56
|
+
"shutting-down": "stopping",
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* State mapping from GCE states to unified states
|
|
60
|
+
*/
|
|
61
|
+
export const GCE_STATE_MAP = {
|
|
62
|
+
RUNNING: "running",
|
|
63
|
+
STOPPED: "stopped",
|
|
64
|
+
TERMINATED: "terminated",
|
|
65
|
+
PROVISIONING: "pending",
|
|
66
|
+
STAGING: "pending",
|
|
67
|
+
STOPPING: "stopping",
|
|
68
|
+
SUSPENDING: "stopping",
|
|
69
|
+
SUSPENDED: "stopped",
|
|
70
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../test/index.test.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|