@aigne/afs-cost-base 1.11.0-beta.12
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/_virtual/_@oxc-project_runtime@0.108.0/helpers/decorate.cjs +11 -0
- package/dist/_virtual/_@oxc-project_runtime@0.108.0/helpers/decorate.mjs +10 -0
- package/dist/annotations.cjs +61 -0
- package/dist/annotations.d.cts +22 -0
- package/dist/annotations.d.cts.map +1 -0
- package/dist/annotations.d.mts +22 -0
- package/dist/annotations.d.mts.map +1 -0
- package/dist/annotations.mjs +62 -0
- package/dist/annotations.mjs.map +1 -0
- package/dist/base-provider.cjs +431 -0
- package/dist/base-provider.d.cts +77 -0
- package/dist/base-provider.d.cts.map +1 -0
- package/dist/base-provider.d.mts +77 -0
- package/dist/base-provider.d.mts.map +1 -0
- package/dist/base-provider.mjs +432 -0
- package/dist/base-provider.mjs.map +1 -0
- package/dist/cache.cjs +43 -0
- package/dist/cache.d.cts +22 -0
- package/dist/cache.d.cts.map +1 -0
- package/dist/cache.d.mts +22 -0
- package/dist/cache.d.mts.map +1 -0
- package/dist/cache.mjs +43 -0
- package/dist/cache.mjs.map +1 -0
- package/dist/index.cjs +9 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.mjs +6 -0
- package/dist/mock-adapter.cjs +38 -0
- package/dist/mock-adapter.d.cts +25 -0
- package/dist/mock-adapter.d.cts.map +1 -0
- package/dist/mock-adapter.d.mts +25 -0
- package/dist/mock-adapter.d.mts.map +1 -0
- package/dist/mock-adapter.mjs +38 -0
- package/dist/mock-adapter.mjs.map +1 -0
- package/dist/types.d.cts +37 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +37 -0
- package/dist/types.d.mts.map +1 -0
- package/package.json +57 -0
package/dist/cache.cjs
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/cache.ts
|
|
3
|
+
/**
|
|
4
|
+
* In-memory TTL cache for cost records.
|
|
5
|
+
* Keys are formatted as `{cloud}:{startDate}:{endDate}`.
|
|
6
|
+
*/
|
|
7
|
+
var CostCache = class {
|
|
8
|
+
entries = /* @__PURE__ */ new Map();
|
|
9
|
+
ttl;
|
|
10
|
+
/** @param ttl Time-to-live in milliseconds. 0 = never cache. */
|
|
11
|
+
constructor(ttl) {
|
|
12
|
+
this.ttl = ttl;
|
|
13
|
+
}
|
|
14
|
+
get(key) {
|
|
15
|
+
if (this.ttl <= 0) return void 0;
|
|
16
|
+
const entry = this.entries.get(key);
|
|
17
|
+
if (!entry) return void 0;
|
|
18
|
+
if (Date.now() - entry.timestamp >= this.ttl) {
|
|
19
|
+
this.entries.delete(key);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
return entry.records;
|
|
23
|
+
}
|
|
24
|
+
set(key, records) {
|
|
25
|
+
if (this.ttl <= 0) return;
|
|
26
|
+
this.entries.set(key, {
|
|
27
|
+
records,
|
|
28
|
+
timestamp: Date.now()
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/** Invalidate a specific key, or all entries if no key given. */
|
|
32
|
+
invalidate(key) {
|
|
33
|
+
if (key !== void 0) this.entries.delete(key);
|
|
34
|
+
else this.entries.clear();
|
|
35
|
+
}
|
|
36
|
+
/** Build a cache key from cloud + date range. */
|
|
37
|
+
static key(cloud, startDate, endDate) {
|
|
38
|
+
return `${cloud}:${startDate}:${endDate}`;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
exports.CostCache = CostCache;
|
package/dist/cache.d.cts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CostRecord } from "./types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/cache.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* In-memory TTL cache for cost records.
|
|
6
|
+
* Keys are formatted as `{cloud}:{startDate}:{endDate}`.
|
|
7
|
+
*/
|
|
8
|
+
declare class CostCache {
|
|
9
|
+
private entries;
|
|
10
|
+
private ttl;
|
|
11
|
+
/** @param ttl Time-to-live in milliseconds. 0 = never cache. */
|
|
12
|
+
constructor(ttl: number);
|
|
13
|
+
get(key: string): CostRecord[] | undefined;
|
|
14
|
+
set(key: string, records: CostRecord[]): void;
|
|
15
|
+
/** Invalidate a specific key, or all entries if no key given. */
|
|
16
|
+
invalidate(key?: string): void;
|
|
17
|
+
/** Build a cache key from cloud + date range. */
|
|
18
|
+
static key(cloud: string, startDate: string, endDate: string): string;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { CostCache };
|
|
22
|
+
//# sourceMappingURL=cache.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.cts","names":[],"sources":["../src/cache.ts"],"mappings":";;;;;AAWA;;cAAa,SAAA;EAAA,QACH,OAAA;EAAA,QACA,GAAA;EAAA;cAGI,GAAA;EAIZ,GAAA,CAAI,GAAA,WAAc,UAAA;EAclB,GAAA,CAAI,GAAA,UAAa,OAAA,EAAS,UAAA;EAdtB;EAoBJ,UAAA,CAAW,GAAA;EANX;EAAA,OAeO,GAAA,CAAI,KAAA,UAAe,SAAA,UAAmB,OAAA;AAAA"}
|
package/dist/cache.d.mts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CostRecord } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/cache.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* In-memory TTL cache for cost records.
|
|
6
|
+
* Keys are formatted as `{cloud}:{startDate}:{endDate}`.
|
|
7
|
+
*/
|
|
8
|
+
declare class CostCache {
|
|
9
|
+
private entries;
|
|
10
|
+
private ttl;
|
|
11
|
+
/** @param ttl Time-to-live in milliseconds. 0 = never cache. */
|
|
12
|
+
constructor(ttl: number);
|
|
13
|
+
get(key: string): CostRecord[] | undefined;
|
|
14
|
+
set(key: string, records: CostRecord[]): void;
|
|
15
|
+
/** Invalidate a specific key, or all entries if no key given. */
|
|
16
|
+
invalidate(key?: string): void;
|
|
17
|
+
/** Build a cache key from cloud + date range. */
|
|
18
|
+
static key(cloud: string, startDate: string, endDate: string): string;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { CostCache };
|
|
22
|
+
//# sourceMappingURL=cache.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.mts","names":[],"sources":["../src/cache.ts"],"mappings":";;;;;AAWA;;cAAa,SAAA;EAAA,QACH,OAAA;EAAA,QACA,GAAA;EAAA;cAGI,GAAA;EAIZ,GAAA,CAAI,GAAA,WAAc,UAAA;EAclB,GAAA,CAAI,GAAA,UAAa,OAAA,EAAS,UAAA;EAdtB;EAoBJ,UAAA,CAAW,GAAA;EANX;EAAA,OAeO,GAAA,CAAI,KAAA,UAAe,SAAA,UAAmB,OAAA;AAAA"}
|
package/dist/cache.mjs
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
//#region src/cache.ts
|
|
2
|
+
/**
|
|
3
|
+
* In-memory TTL cache for cost records.
|
|
4
|
+
* Keys are formatted as `{cloud}:{startDate}:{endDate}`.
|
|
5
|
+
*/
|
|
6
|
+
var CostCache = class {
|
|
7
|
+
entries = /* @__PURE__ */ new Map();
|
|
8
|
+
ttl;
|
|
9
|
+
/** @param ttl Time-to-live in milliseconds. 0 = never cache. */
|
|
10
|
+
constructor(ttl) {
|
|
11
|
+
this.ttl = ttl;
|
|
12
|
+
}
|
|
13
|
+
get(key) {
|
|
14
|
+
if (this.ttl <= 0) return void 0;
|
|
15
|
+
const entry = this.entries.get(key);
|
|
16
|
+
if (!entry) return void 0;
|
|
17
|
+
if (Date.now() - entry.timestamp >= this.ttl) {
|
|
18
|
+
this.entries.delete(key);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
return entry.records;
|
|
22
|
+
}
|
|
23
|
+
set(key, records) {
|
|
24
|
+
if (this.ttl <= 0) return;
|
|
25
|
+
this.entries.set(key, {
|
|
26
|
+
records,
|
|
27
|
+
timestamp: Date.now()
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/** Invalidate a specific key, or all entries if no key given. */
|
|
31
|
+
invalidate(key) {
|
|
32
|
+
if (key !== void 0) this.entries.delete(key);
|
|
33
|
+
else this.entries.clear();
|
|
34
|
+
}
|
|
35
|
+
/** Build a cache key from cloud + date range. */
|
|
36
|
+
static key(cloud, startDate, endDate) {
|
|
37
|
+
return `${cloud}:${startDate}:${endDate}`;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { CostCache };
|
|
43
|
+
//# sourceMappingURL=cache.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.mjs","names":[],"sources":["../src/cache.ts"],"sourcesContent":["import type { CostRecord } from \"./types.js\";\n\ninterface CacheEntry {\n records: CostRecord[];\n timestamp: number;\n}\n\n/**\n * In-memory TTL cache for cost records.\n * Keys are formatted as `{cloud}:{startDate}:{endDate}`.\n */\nexport class CostCache {\n private entries = new Map<string, CacheEntry>();\n private ttl: number;\n\n /** @param ttl Time-to-live in milliseconds. 0 = never cache. */\n constructor(ttl: number) {\n this.ttl = ttl;\n }\n\n get(key: string): CostRecord[] | undefined {\n if (this.ttl <= 0) return undefined;\n\n const entry = this.entries.get(key);\n if (!entry) return undefined;\n\n if (Date.now() - entry.timestamp >= this.ttl) {\n this.entries.delete(key);\n return undefined;\n }\n\n return entry.records;\n }\n\n set(key: string, records: CostRecord[]): void {\n if (this.ttl <= 0) return;\n this.entries.set(key, { records, timestamp: Date.now() });\n }\n\n /** Invalidate a specific key, or all entries if no key given. */\n invalidate(key?: string): void {\n if (key !== undefined) {\n this.entries.delete(key);\n } else {\n this.entries.clear();\n }\n }\n\n /** Build a cache key from cloud + date range. */\n static key(cloud: string, startDate: string, endDate: string): string {\n return `${cloud}:${startDate}:${endDate}`;\n }\n}\n"],"mappings":";;;;;AAWA,IAAa,YAAb,MAAuB;CACrB,AAAQ,0BAAU,IAAI,KAAyB;CAC/C,AAAQ;;CAGR,YAAY,KAAa;AACvB,OAAK,MAAM;;CAGb,IAAI,KAAuC;AACzC,MAAI,KAAK,OAAO,EAAG,QAAO;EAE1B,MAAM,QAAQ,KAAK,QAAQ,IAAI,IAAI;AACnC,MAAI,CAAC,MAAO,QAAO;AAEnB,MAAI,KAAK,KAAK,GAAG,MAAM,aAAa,KAAK,KAAK;AAC5C,QAAK,QAAQ,OAAO,IAAI;AACxB;;AAGF,SAAO,MAAM;;CAGf,IAAI,KAAa,SAA6B;AAC5C,MAAI,KAAK,OAAO,EAAG;AACnB,OAAK,QAAQ,IAAI,KAAK;GAAE;GAAS,WAAW,KAAK,KAAK;GAAE,CAAC;;;CAI3D,WAAW,KAAoB;AAC7B,MAAI,QAAQ,OACV,MAAK,QAAQ,OAAO,IAAI;MAExB,MAAK,QAAQ,OAAO;;;CAKxB,OAAO,IAAI,OAAe,WAAmB,SAAyB;AACpE,SAAO,GAAG,MAAM,GAAG,UAAU,GAAG"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const require_annotations = require('./annotations.cjs');
|
|
2
|
+
const require_cache = require('./cache.cjs');
|
|
3
|
+
const require_base_provider = require('./base-provider.cjs');
|
|
4
|
+
const require_mock_adapter = require('./mock-adapter.cjs');
|
|
5
|
+
|
|
6
|
+
exports.AFSCostBaseProvider = require_base_provider.AFSCostBaseProvider;
|
|
7
|
+
exports.AnnotationStore = require_annotations.AnnotationStore;
|
|
8
|
+
exports.CostCache = require_cache.CostCache;
|
|
9
|
+
exports.MockCostAdapter = require_mock_adapter.MockCostAdapter;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AnnotationStore } from "./annotations.cjs";
|
|
2
|
+
import { AdapterCapabilities, CostAdapter, CostRecord } from "./types.cjs";
|
|
3
|
+
import { CostCache } from "./cache.cjs";
|
|
4
|
+
import { AFSCostBaseOptions, AFSCostBaseProvider } from "./base-provider.cjs";
|
|
5
|
+
import { MockCostAdapter } from "./mock-adapter.cjs";
|
|
6
|
+
export { type AFSCostBaseOptions, AFSCostBaseProvider, AdapterCapabilities, AnnotationStore, CostAdapter, CostCache, CostRecord, MockCostAdapter };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AnnotationStore } from "./annotations.mjs";
|
|
2
|
+
import { AdapterCapabilities, CostAdapter, CostRecord } from "./types.mjs";
|
|
3
|
+
import { CostCache } from "./cache.mjs";
|
|
4
|
+
import { AFSCostBaseOptions, AFSCostBaseProvider } from "./base-provider.mjs";
|
|
5
|
+
import { MockCostAdapter } from "./mock-adapter.mjs";
|
|
6
|
+
export { type AFSCostBaseOptions, AFSCostBaseProvider, AdapterCapabilities, AnnotationStore, CostAdapter, CostCache, CostRecord, MockCostAdapter };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AnnotationStore } from "./annotations.mjs";
|
|
2
|
+
import { CostCache } from "./cache.mjs";
|
|
3
|
+
import { AFSCostBaseProvider } from "./base-provider.mjs";
|
|
4
|
+
import { MockCostAdapter } from "./mock-adapter.mjs";
|
|
5
|
+
|
|
6
|
+
export { AFSCostBaseProvider, AnnotationStore, CostCache, MockCostAdapter };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/mock-adapter.ts
|
|
3
|
+
/**
|
|
4
|
+
* Mock cost adapter for testing.
|
|
5
|
+
* Returns deterministic, pre-configured cost records.
|
|
6
|
+
*/
|
|
7
|
+
var MockCostAdapter = class {
|
|
8
|
+
cloud;
|
|
9
|
+
records;
|
|
10
|
+
_supportsAmount;
|
|
11
|
+
constructor(cloud, records, options) {
|
|
12
|
+
this.cloud = cloud;
|
|
13
|
+
this.records = records;
|
|
14
|
+
this._supportsAmount = options?.supportsAmount ?? true;
|
|
15
|
+
}
|
|
16
|
+
async isAvailable() {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
async fetchCosts(options) {
|
|
20
|
+
return this.records.filter((r) => r.date >= options.startDate && r.date <= options.endDate);
|
|
21
|
+
}
|
|
22
|
+
async listServices() {
|
|
23
|
+
return [...new Set(this.records.map((r) => r.service))];
|
|
24
|
+
}
|
|
25
|
+
capabilities() {
|
|
26
|
+
return {
|
|
27
|
+
supportsAmount: this._supportsAmount,
|
|
28
|
+
supportsUsage: true,
|
|
29
|
+
supportsTags: true,
|
|
30
|
+
supportsRegion: true,
|
|
31
|
+
supportsAccount: true,
|
|
32
|
+
supportsForecast: false
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
exports.MockCostAdapter = MockCostAdapter;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AdapterCapabilities, CostAdapter, CostRecord } from "./types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/mock-adapter.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Mock cost adapter for testing.
|
|
6
|
+
* Returns deterministic, pre-configured cost records.
|
|
7
|
+
*/
|
|
8
|
+
declare class MockCostAdapter implements CostAdapter {
|
|
9
|
+
readonly cloud: string;
|
|
10
|
+
private records;
|
|
11
|
+
private _supportsAmount;
|
|
12
|
+
constructor(cloud: string, records: CostRecord[], options?: {
|
|
13
|
+
supportsAmount?: boolean;
|
|
14
|
+
});
|
|
15
|
+
isAvailable(): Promise<boolean>;
|
|
16
|
+
fetchCosts(options: {
|
|
17
|
+
startDate: string;
|
|
18
|
+
endDate: string;
|
|
19
|
+
}): Promise<CostRecord[]>;
|
|
20
|
+
listServices(): Promise<string[]>;
|
|
21
|
+
capabilities(): AdapterCapabilities;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { MockCostAdapter };
|
|
25
|
+
//# sourceMappingURL=mock-adapter.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-adapter.d.cts","names":[],"sources":["../src/mock-adapter.ts"],"mappings":";;;;;AAMA;;cAAa,eAAA,YAA2B,WAAA;EAAA,SAC7B,KAAA;EAAA,QACD,OAAA;EAAA,QACA,eAAA;cAEI,KAAA,UAAe,OAAA,EAAS,UAAA,IAAc,OAAA;IAAY,cAAA;EAAA;EAMxD,WAAA,CAAA,GAAe,OAAA;EAIf,UAAA,CAAW,OAAA;IAAW,SAAA;IAAmB,OAAA;EAAA,IAAoB,OAAA,CAAQ,UAAA;EAIrE,YAAA,CAAA,GAAgB,OAAA;EAItB,YAAA,CAAA,GAAgB,mBAAA;AAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AdapterCapabilities, CostAdapter, CostRecord } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/mock-adapter.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Mock cost adapter for testing.
|
|
6
|
+
* Returns deterministic, pre-configured cost records.
|
|
7
|
+
*/
|
|
8
|
+
declare class MockCostAdapter implements CostAdapter {
|
|
9
|
+
readonly cloud: string;
|
|
10
|
+
private records;
|
|
11
|
+
private _supportsAmount;
|
|
12
|
+
constructor(cloud: string, records: CostRecord[], options?: {
|
|
13
|
+
supportsAmount?: boolean;
|
|
14
|
+
});
|
|
15
|
+
isAvailable(): Promise<boolean>;
|
|
16
|
+
fetchCosts(options: {
|
|
17
|
+
startDate: string;
|
|
18
|
+
endDate: string;
|
|
19
|
+
}): Promise<CostRecord[]>;
|
|
20
|
+
listServices(): Promise<string[]>;
|
|
21
|
+
capabilities(): AdapterCapabilities;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { MockCostAdapter };
|
|
25
|
+
//# sourceMappingURL=mock-adapter.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-adapter.d.mts","names":[],"sources":["../src/mock-adapter.ts"],"mappings":";;;;;AAMA;;cAAa,eAAA,YAA2B,WAAA;EAAA,SAC7B,KAAA;EAAA,QACD,OAAA;EAAA,QACA,eAAA;cAEI,KAAA,UAAe,OAAA,EAAS,UAAA,IAAc,OAAA;IAAY,cAAA;EAAA;EAMxD,WAAA,CAAA,GAAe,OAAA;EAIf,UAAA,CAAW,OAAA;IAAW,SAAA;IAAmB,OAAA;EAAA,IAAoB,OAAA,CAAQ,UAAA;EAIrE,YAAA,CAAA,GAAgB,OAAA;EAItB,YAAA,CAAA,GAAgB,mBAAA;AAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//#region src/mock-adapter.ts
|
|
2
|
+
/**
|
|
3
|
+
* Mock cost adapter for testing.
|
|
4
|
+
* Returns deterministic, pre-configured cost records.
|
|
5
|
+
*/
|
|
6
|
+
var MockCostAdapter = class {
|
|
7
|
+
cloud;
|
|
8
|
+
records;
|
|
9
|
+
_supportsAmount;
|
|
10
|
+
constructor(cloud, records, options) {
|
|
11
|
+
this.cloud = cloud;
|
|
12
|
+
this.records = records;
|
|
13
|
+
this._supportsAmount = options?.supportsAmount ?? true;
|
|
14
|
+
}
|
|
15
|
+
async isAvailable() {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
async fetchCosts(options) {
|
|
19
|
+
return this.records.filter((r) => r.date >= options.startDate && r.date <= options.endDate);
|
|
20
|
+
}
|
|
21
|
+
async listServices() {
|
|
22
|
+
return [...new Set(this.records.map((r) => r.service))];
|
|
23
|
+
}
|
|
24
|
+
capabilities() {
|
|
25
|
+
return {
|
|
26
|
+
supportsAmount: this._supportsAmount,
|
|
27
|
+
supportsUsage: true,
|
|
28
|
+
supportsTags: true,
|
|
29
|
+
supportsRegion: true,
|
|
30
|
+
supportsAccount: true,
|
|
31
|
+
supportsForecast: false
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { MockCostAdapter };
|
|
38
|
+
//# sourceMappingURL=mock-adapter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-adapter.mjs","names":[],"sources":["../src/mock-adapter.ts"],"sourcesContent":["import type { AdapterCapabilities, CostAdapter, CostRecord } from \"./types.js\";\n\n/**\n * Mock cost adapter for testing.\n * Returns deterministic, pre-configured cost records.\n */\nexport class MockCostAdapter implements CostAdapter {\n readonly cloud: string;\n private records: CostRecord[];\n private _supportsAmount: boolean;\n\n constructor(cloud: string, records: CostRecord[], options?: { supportsAmount?: boolean }) {\n this.cloud = cloud;\n this.records = records;\n this._supportsAmount = options?.supportsAmount ?? true;\n }\n\n async isAvailable(): Promise<boolean> {\n return true;\n }\n\n async fetchCosts(options: { startDate: string; endDate: string }): Promise<CostRecord[]> {\n return this.records.filter((r) => r.date >= options.startDate && r.date <= options.endDate);\n }\n\n async listServices(): Promise<string[]> {\n return [...new Set(this.records.map((r) => r.service))];\n }\n\n capabilities(): AdapterCapabilities {\n return {\n supportsAmount: this._supportsAmount,\n supportsUsage: true,\n supportsTags: true,\n supportsRegion: true,\n supportsAccount: true,\n supportsForecast: false,\n };\n }\n}\n"],"mappings":";;;;;AAMA,IAAa,kBAAb,MAAoD;CAClD,AAAS;CACT,AAAQ;CACR,AAAQ;CAER,YAAY,OAAe,SAAuB,SAAwC;AACxF,OAAK,QAAQ;AACb,OAAK,UAAU;AACf,OAAK,kBAAkB,SAAS,kBAAkB;;CAGpD,MAAM,cAAgC;AACpC,SAAO;;CAGT,MAAM,WAAW,SAAwE;AACvF,SAAO,KAAK,QAAQ,QAAQ,MAAM,EAAE,QAAQ,QAAQ,aAAa,EAAE,QAAQ,QAAQ,QAAQ;;CAG7F,MAAM,eAAkC;AACtC,SAAO,CAAC,GAAG,IAAI,IAAI,KAAK,QAAQ,KAAK,MAAM,EAAE,QAAQ,CAAC,CAAC;;CAGzD,eAAoC;AAClC,SAAO;GACL,gBAAgB,KAAK;GACrB,eAAe;GACf,cAAc;GACd,gBAAgB;GAChB,iBAAiB;GACjB,kBAAkB;GACnB"}
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
interface CostRecord {
|
|
3
|
+
cloud: string;
|
|
4
|
+
service: string;
|
|
5
|
+
date: string;
|
|
6
|
+
amount?: number;
|
|
7
|
+
currency?: string;
|
|
8
|
+
usage?: {
|
|
9
|
+
value: number;
|
|
10
|
+
unit: string;
|
|
11
|
+
};
|
|
12
|
+
tags?: Record<string, string>;
|
|
13
|
+
region?: string;
|
|
14
|
+
account?: string;
|
|
15
|
+
isEstimate?: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface AdapterCapabilities {
|
|
18
|
+
supportsAmount: boolean;
|
|
19
|
+
supportsUsage: boolean;
|
|
20
|
+
supportsTags: boolean;
|
|
21
|
+
supportsRegion: boolean;
|
|
22
|
+
supportsAccount: boolean;
|
|
23
|
+
supportsForecast: boolean;
|
|
24
|
+
}
|
|
25
|
+
interface CostAdapter {
|
|
26
|
+
readonly cloud: string;
|
|
27
|
+
isAvailable(): Promise<boolean>;
|
|
28
|
+
fetchCosts(options: {
|
|
29
|
+
startDate: string;
|
|
30
|
+
endDate: string;
|
|
31
|
+
}): Promise<CostRecord[]>;
|
|
32
|
+
listServices(): Promise<string[]>;
|
|
33
|
+
capabilities(): AdapterCapabilities;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { AdapterCapabilities, CostAdapter, CostRecord };
|
|
37
|
+
//# sourceMappingURL=types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.ts"],"mappings":";UAIiB,UAAA;EACf,KAAA;EACA,OAAA;EACA,IAAA;EACA,MAAA;EACA,QAAA;EAEA,KAAA;IACE,KAAA;IACA,IAAA;EAAA;EAGF,IAAA,GAAO,MAAA;EACP,MAAA;EACA,OAAA;EACA,UAAA;AAAA;AAAA,UAOe,mBAAA;EACf,cAAA;EACA,aAAA;EACA,YAAA;EACA,cAAA;EACA,eAAA;EACA,gBAAA;AAAA;AAAA,UAGe,WAAA;EAAA,SACN,KAAA;EAET,WAAA,IAAe,OAAA;EAEf,UAAA,CAAW,OAAA;IAAW,SAAA;IAAmB,OAAA;EAAA,IAAoB,OAAA,CAAQ,UAAA;EAErE,YAAA,IAAgB,OAAA;EAEhB,YAAA,IAAgB,mBAAA;AAAA"}
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
interface CostRecord {
|
|
3
|
+
cloud: string;
|
|
4
|
+
service: string;
|
|
5
|
+
date: string;
|
|
6
|
+
amount?: number;
|
|
7
|
+
currency?: string;
|
|
8
|
+
usage?: {
|
|
9
|
+
value: number;
|
|
10
|
+
unit: string;
|
|
11
|
+
};
|
|
12
|
+
tags?: Record<string, string>;
|
|
13
|
+
region?: string;
|
|
14
|
+
account?: string;
|
|
15
|
+
isEstimate?: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface AdapterCapabilities {
|
|
18
|
+
supportsAmount: boolean;
|
|
19
|
+
supportsUsage: boolean;
|
|
20
|
+
supportsTags: boolean;
|
|
21
|
+
supportsRegion: boolean;
|
|
22
|
+
supportsAccount: boolean;
|
|
23
|
+
supportsForecast: boolean;
|
|
24
|
+
}
|
|
25
|
+
interface CostAdapter {
|
|
26
|
+
readonly cloud: string;
|
|
27
|
+
isAvailable(): Promise<boolean>;
|
|
28
|
+
fetchCosts(options: {
|
|
29
|
+
startDate: string;
|
|
30
|
+
endDate: string;
|
|
31
|
+
}): Promise<CostRecord[]>;
|
|
32
|
+
listServices(): Promise<string[]>;
|
|
33
|
+
capabilities(): AdapterCapabilities;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { AdapterCapabilities, CostAdapter, CostRecord };
|
|
37
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";UAIiB,UAAA;EACf,KAAA;EACA,OAAA;EACA,IAAA;EACA,MAAA;EACA,QAAA;EAEA,KAAA;IACE,KAAA;IACA,IAAA;EAAA;EAGF,IAAA,GAAO,MAAA;EACP,MAAA;EACA,OAAA;EACA,UAAA;AAAA;AAAA,UAOe,mBAAA;EACf,cAAA;EACA,aAAA;EACA,YAAA;EACA,cAAA;EACA,eAAA;EACA,gBAAA;AAAA;AAAA,UAGe,WAAA;EAAA,SACN,KAAA;EAET,WAAA,IAAe,OAAA;EAEf,UAAA,CAAW,OAAA;IAAW,SAAA;IAAmB,OAAA;EAAA,IAAoB,OAAA,CAAQ,UAAA;EAErE,YAAA,IAAgB,OAAA;EAEhB,YAAA,IAAgB,mBAAA;AAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aigne/afs-cost-base",
|
|
3
|
+
"version": "1.11.0-beta.12",
|
|
4
|
+
"description": "Shared base provider and utilities for AFS cloud cost providers",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"author": "Arcblock <blocklet@arcblock.io> https://github.com/arcblock",
|
|
10
|
+
"homepage": "https://github.com/arcblock/afs",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/arcblock/afs"
|
|
14
|
+
},
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/arcblock/afs/issues"
|
|
17
|
+
},
|
|
18
|
+
"type": "module",
|
|
19
|
+
"main": "./dist/index.cjs",
|
|
20
|
+
"module": "./dist/index.mjs",
|
|
21
|
+
"types": "./dist/index.d.cts",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"require": "./dist/index.cjs",
|
|
25
|
+
"import": "./dist/index.mjs"
|
|
26
|
+
},
|
|
27
|
+
"./*": "./*"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"LICENSE",
|
|
32
|
+
"README.md",
|
|
33
|
+
"CHANGELOG.md"
|
|
34
|
+
],
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"ufo": "^1.6.3",
|
|
37
|
+
"zod": "^4.0.0",
|
|
38
|
+
"@aigne/afs": "^1.11.0-beta.12"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/bun": "latest",
|
|
42
|
+
"npm-run-all": "^4.1.5",
|
|
43
|
+
"rimraf": "^6.1.2",
|
|
44
|
+
"tsdown": "0.20.0-beta.3",
|
|
45
|
+
"typescript": "5.9.2",
|
|
46
|
+
"@aigne/afs-testing": "1.11.0-beta.12",
|
|
47
|
+
"@aigne/scripts": "0.0.0",
|
|
48
|
+
"@aigne/typescript-config": "0.0.0"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsdown",
|
|
52
|
+
"check-types": "tsc --noEmit",
|
|
53
|
+
"clean": "rimraf dist coverage",
|
|
54
|
+
"test": "bun test",
|
|
55
|
+
"test:coverage": "bun test --coverage --coverage-reporter=lcov --coverage-reporter=text"
|
|
56
|
+
}
|
|
57
|
+
}
|