@lssm/lib.cost-tracking 3.0.0 → 3.0.1
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/budget-alert-manager.d.ts +1 -2
- package/dist/budget-alert-manager.js +1 -2
- package/dist/cost-model.d.ts +1 -2
- package/dist/cost-model.js +1 -2
- package/dist/cost-tracker.d.ts +1 -2
- package/dist/cost-tracker.js +1 -2
- package/dist/optimization-recommender.d.ts +1 -2
- package/dist/optimization-recommender.js +1 -2
- package/dist/types.d.ts +1 -2
- package/package.json +4 -4
- package/dist/budget-alert-manager.d.ts.map +0 -1
- package/dist/budget-alert-manager.js.map +0 -1
- package/dist/cost-model.d.ts.map +0 -1
- package/dist/cost-model.js.map +0 -1
- package/dist/cost-tracker.d.ts.map +0 -1
- package/dist/cost-tracker.js.map +0 -1
- package/dist/optimization-recommender.d.ts.map +0 -1
- package/dist/optimization-recommender.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
|
@@ -19,5 +19,4 @@ declare class BudgetAlertManager {
|
|
|
19
19
|
getSpend(tenantId: string): number;
|
|
20
20
|
}
|
|
21
21
|
//#endregion
|
|
22
|
-
export { BudgetAlertManager, BudgetAlertManagerOptions };
|
|
23
|
-
//# sourceMappingURL=budget-alert-manager.d.ts.map
|
|
22
|
+
export { BudgetAlertManager, BudgetAlertManagerOptions };
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
var e=class{limits=new Map;spend=new Map;constructor(e){this.options=e;for(let t of e.budgets)this.limits.set(t.tenantId,t),this.spend.set(t.tenantId,0)}track(e){if(!e.tenantId)return;let t=(this.spend.get(e.tenantId)??0)+e.total;this.spend.set(e.tenantId,t);let n=this.limits.get(e.tenantId);if(!n)return;let r=n.alertThreshold??.8;t>=n.monthlyLimit*r&&this.options.onAlert?.({tenantId:e.tenantId,limit:n.monthlyLimit,total:t,summary:e})}getSpend(e){return this.spend.get(e)??0}};export{e as BudgetAlertManager};
|
|
2
|
-
//# sourceMappingURL=budget-alert-manager.js.map
|
|
1
|
+
var e=class{limits=new Map;spend=new Map;constructor(e){this.options=e;for(let t of e.budgets)this.limits.set(t.tenantId,t),this.spend.set(t.tenantId,0)}track(e){if(!e.tenantId)return;let t=(this.spend.get(e.tenantId)??0)+e.total;this.spend.set(e.tenantId,t);let n=this.limits.get(e.tenantId);if(!n)return;let r=n.alertThreshold??.8;t>=n.monthlyLimit*r&&this.options.onAlert?.({tenantId:e.tenantId,limit:n.monthlyLimit,total:t,summary:e})}getSpend(e){return this.spend.get(e)??0}};export{e as BudgetAlertManager};
|
package/dist/cost-model.d.ts
CHANGED
|
@@ -11,5 +11,4 @@ declare function calculateSampleCost(sample: CostSample, model: CostModel): {
|
|
|
11
11
|
custom: number;
|
|
12
12
|
};
|
|
13
13
|
//#endregion
|
|
14
|
-
export { calculateSampleCost, defaultCostModel };
|
|
15
|
-
//# sourceMappingURL=cost-model.d.ts.map
|
|
14
|
+
export { calculateSampleCost, defaultCostModel };
|
package/dist/cost-model.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
const e={dbReadCost:2e-6,dbWriteCost:1e-5,computeMsCost:15e-8,memoryMbMsCost:2e-8};function t(e,t){let n=(e.externalCalls??[]).reduce((e,t)=>e+(t.cost??0),0);return{dbReads:(e.dbReads??0)*t.dbReadCost,dbWrites:(e.dbWrites??0)*t.dbWriteCost,compute:(e.computeMs??0)*t.computeMsCost,memory:(e.memoryMbMs??0)*t.memoryMbMsCost,external:n,custom:e.customCost??0}}export{t as calculateSampleCost,e as defaultCostModel};
|
|
2
|
-
//# sourceMappingURL=cost-model.js.map
|
|
1
|
+
const e={dbReadCost:2e-6,dbWriteCost:1e-5,computeMsCost:15e-8,memoryMbMsCost:2e-8};function t(e,t){let n=(e.externalCalls??[]).reduce((e,t)=>e+(t.cost??0),0);return{dbReads:(e.dbReads??0)*t.dbReadCost,dbWrites:(e.dbWrites??0)*t.dbWriteCost,compute:(e.computeMs??0)*t.computeMsCost,memory:(e.memoryMbMs??0)*t.memoryMbMsCost,external:n,custom:e.customCost??0}}export{t as calculateSampleCost,e as defaultCostModel};
|
package/dist/cost-tracker.d.ts
CHANGED
package/dist/cost-tracker.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import{calculateSampleCost as e,defaultCostModel as t}from"./cost-model.js";var n=class{totals=new Map;costModel;constructor(e={}){this.options=e,this.costModel=e.costModel??t}recordSample(t){let n=e(t,this.costModel),r=n.dbReads+n.dbWrites+n.compute+n.memory+n.external+n.custom,i=this.buildKey(t.operation,t.tenantId),a=this.totals.get(i),o=a?{...a,total:a.total+r,breakdown:{dbReads:a.breakdown.dbReads+n.dbReads,dbWrites:a.breakdown.dbWrites+n.dbWrites,compute:a.breakdown.compute+n.compute,memory:a.breakdown.memory+n.memory,external:a.breakdown.external+n.external,custom:a.breakdown.custom+n.custom},samples:a.samples+1}:{operation:t.operation,tenantId:t.tenantId,total:r,breakdown:{dbReads:n.dbReads,dbWrites:n.dbWrites,compute:n.compute,memory:n.memory,external:n.external,custom:n.custom},samples:1};return this.totals.set(i,o),this.options.onSampleRecorded?.(t,r),o}getTotals(e){let t=Array.from(this.totals.values());return e?.tenantId?t.filter(t=>t.tenantId===e.tenantId):t}reset(){this.totals.clear()}buildKey(e,t){return t?`${t}:${e}`:e}};export{n as CostTracker};
|
|
2
|
-
//# sourceMappingURL=cost-tracker.js.map
|
|
1
|
+
import{calculateSampleCost as e,defaultCostModel as t}from"./cost-model.js";var n=class{totals=new Map;costModel;constructor(e={}){this.options=e,this.costModel=e.costModel??t}recordSample(t){let n=e(t,this.costModel),r=n.dbReads+n.dbWrites+n.compute+n.memory+n.external+n.custom,i=this.buildKey(t.operation,t.tenantId),a=this.totals.get(i),o=a?{...a,total:a.total+r,breakdown:{dbReads:a.breakdown.dbReads+n.dbReads,dbWrites:a.breakdown.dbWrites+n.dbWrites,compute:a.breakdown.compute+n.compute,memory:a.breakdown.memory+n.memory,external:a.breakdown.external+n.external,custom:a.breakdown.custom+n.custom},samples:a.samples+1}:{operation:t.operation,tenantId:t.tenantId,total:r,breakdown:{dbReads:n.dbReads,dbWrites:n.dbWrites,compute:n.compute,memory:n.memory,external:n.external,custom:n.custom},samples:1};return this.totals.set(i,o),this.options.onSampleRecorded?.(t,r),o}getTotals(e){let t=Array.from(this.totals.values());return e?.tenantId?t.filter(t=>t.tenantId===e.tenantId):t}reset(){this.totals.clear()}buildKey(e,t){return t?`${t}:${e}`:e}};export{n as CostTracker};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
var e=class{generate(e){let t=[],n=e.total/e.samples;return e.breakdown.dbReads/e.samples>1e3&&t.push({operation:e.operation,tenantId:e.tenantId,category:`n_plus_one`,message:`High average DB read count detected. Consider batching queries or adding pagination.`,evidence:{avgReads:e.breakdown.dbReads/e.samples}}),e.breakdown.compute/e.total>.6&&t.push({operation:e.operation,tenantId:e.tenantId,category:`batching`,message:`Compute dominates cost. Investigate hot loops or move heavy logic to background jobs.`,evidence:{computeShare:e.breakdown.compute/e.total}}),e.breakdown.external>n*.5&&t.push({operation:e.operation,tenantId:e.tenantId,category:`external`,message:`External provider spend is high. Reuse results or enable caching.`,evidence:{externalCost:e.breakdown.external}}),e.breakdown.memory>e.breakdown.compute*1.2&&t.push({operation:e.operation,tenantId:e.tenantId,category:`caching`,message:`Memory utilization suggests cached payloads linger. Tune TTL or stream responses.`,evidence:{memoryCost:e.breakdown.memory}}),t}};export{e as OptimizationRecommender};
|
|
2
|
-
//# sourceMappingURL=optimization-recommender.js.map
|
|
1
|
+
var e=class{generate(e){let t=[],n=e.total/e.samples;return e.breakdown.dbReads/e.samples>1e3&&t.push({operation:e.operation,tenantId:e.tenantId,category:`n_plus_one`,message:`High average DB read count detected. Consider batching queries or adding pagination.`,evidence:{avgReads:e.breakdown.dbReads/e.samples}}),e.breakdown.compute/e.total>.6&&t.push({operation:e.operation,tenantId:e.tenantId,category:`batching`,message:`Compute dominates cost. Investigate hot loops or move heavy logic to background jobs.`,evidence:{computeShare:e.breakdown.compute/e.total}}),e.breakdown.external>n*.5&&t.push({operation:e.operation,tenantId:e.tenantId,category:`external`,message:`External provider spend is high. Reuse results or enable caching.`,evidence:{externalCost:e.breakdown.external}}),e.breakdown.memory>e.breakdown.compute*1.2&&t.push({operation:e.operation,tenantId:e.tenantId,category:`caching`,message:`Memory utilization suggests cached payloads linger. Tune TTL or stream responses.`,evidence:{memoryCost:e.breakdown.memory}}),t}};export{e as OptimizationRecommender};
|
package/dist/types.d.ts
CHANGED
|
@@ -59,5 +59,4 @@ interface BudgetAlert {
|
|
|
59
59
|
triggeredAt: Date;
|
|
60
60
|
}
|
|
61
61
|
//#endregion
|
|
62
|
-
export { BudgetAlert, CostModel, CostSample, ExternalCallCost, OperationCostSummary, OptimizationSuggestion, TenantBudget };
|
|
63
|
-
//# sourceMappingURL=types.d.ts.map
|
|
62
|
+
export { BudgetAlert, CostModel, CostSample, ExternalCallCost, OperationCostSummary, OptimizationSuggestion, TenantBudget };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lssm/lib.cost-tracking",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"test": "bun run"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@lssm/lib.observability": "0.4.
|
|
25
|
+
"@lssm/lib.observability": "0.4.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@lssm/tool.tsdown": "0.12.
|
|
29
|
-
"@lssm/tool.typescript": "0.11.
|
|
28
|
+
"@lssm/tool.tsdown": "0.12.1",
|
|
29
|
+
"@lssm/tool.typescript": "0.11.1",
|
|
30
30
|
"tsdown": "^0.16.6",
|
|
31
31
|
"typescript": "^5.9.3"
|
|
32
32
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"budget-alert-manager.d.ts","names":[],"sources":["../src/budget-alert-manager.ts"],"sourcesContent":[],"mappings":";;;UAEiB,yBAAA;WACN;EADM,OAAA,CAAA,EAAA,CAAA,OAAA,EAAA;IAUJ,QAAA,EAAA,MAAA;;;aAJA;;;cAIA,kBAAA;;;;uBAI2B;iBAOvB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"budget-alert-manager.js","names":["options: BudgetAlertManagerOptions"],"sources":["../src/budget-alert-manager.ts"],"sourcesContent":["import type { OperationCostSummary, TenantBudget } from './types';\n\nexport interface BudgetAlertManagerOptions {\n budgets: TenantBudget[];\n onAlert?: (payload: {\n tenantId: string;\n limit: number;\n total: number;\n summary: OperationCostSummary;\n }) => void;\n}\n\nexport class BudgetAlertManager {\n private readonly limits = new Map<string, TenantBudget>();\n private readonly spend = new Map<string, number>();\n\n constructor(private readonly options: BudgetAlertManagerOptions) {\n for (const budget of options.budgets) {\n this.limits.set(budget.tenantId, budget);\n this.spend.set(budget.tenantId, 0);\n }\n }\n\n track(summary: OperationCostSummary) {\n if (!summary.tenantId) {\n return;\n }\n\n const current = (this.spend.get(summary.tenantId) ?? 0) + summary.total;\n this.spend.set(summary.tenantId, current);\n\n const budget = this.limits.get(summary.tenantId);\n if (!budget) {\n return;\n }\n\n const threshold = budget.alertThreshold ?? 0.8;\n if (current >= budget.monthlyLimit * threshold) {\n this.options.onAlert?.({\n tenantId: summary.tenantId,\n limit: budget.monthlyLimit,\n total: current,\n summary,\n });\n }\n }\n\n getSpend(tenantId: string) {\n return this.spend.get(tenantId) ?? 0;\n }\n}\n"],"mappings":"AAYA,IAAa,EAAb,KAAgC,CAC9B,OAA0B,IAAI,IAC9B,MAAyB,IAAI,IAE7B,YAAY,EAAqD,CAApC,KAAA,QAAA,EAC3B,IAAK,IAAM,KAAU,EAAQ,QAC3B,KAAK,OAAO,IAAI,EAAO,SAAU,EAAO,CACxC,KAAK,MAAM,IAAI,EAAO,SAAU,EAAE,CAItC,MAAM,EAA+B,CACnC,GAAI,CAAC,EAAQ,SACX,OAGF,IAAM,GAAW,KAAK,MAAM,IAAI,EAAQ,SAAS,EAAI,GAAK,EAAQ,MAClE,KAAK,MAAM,IAAI,EAAQ,SAAU,EAAQ,CAEzC,IAAM,EAAS,KAAK,OAAO,IAAI,EAAQ,SAAS,CAChD,GAAI,CAAC,EACH,OAGF,IAAM,EAAY,EAAO,gBAAkB,GACvC,GAAW,EAAO,aAAe,GACnC,KAAK,QAAQ,UAAU,CACrB,SAAU,EAAQ,SAClB,MAAO,EAAO,aACd,MAAO,EACP,UACD,CAAC,CAIN,SAAS,EAAkB,CACzB,OAAO,KAAK,MAAM,IAAI,EAAS,EAAI"}
|
package/dist/cost-model.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cost-model.d.ts","names":[],"sources":["../src/cost-model.ts"],"sourcesContent":[],"mappings":";;;cAEa,kBAAkB;iBAOf,mBAAA,SAA4B,mBAAmB;EAPlD,OAAA,EAAA,MAAA;EAOG,QAAA,EAAA,MAAA"}
|
package/dist/cost-model.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cost-model.js","names":["defaultCostModel: CostModel"],"sources":["../src/cost-model.ts"],"sourcesContent":["import type { CostModel, CostSample } from './types';\n\nexport const defaultCostModel: CostModel = {\n dbReadCost: 0.000002,\n dbWriteCost: 0.00001,\n computeMsCost: 0.00000015,\n memoryMbMsCost: 0.00000002,\n};\n\nexport function calculateSampleCost(sample: CostSample, model: CostModel) {\n const external = (sample.externalCalls ?? []).reduce(\n (sum, call) => sum + (call.cost ?? 0),\n 0\n );\n\n return {\n dbReads: (sample.dbReads ?? 0) * model.dbReadCost,\n dbWrites: (sample.dbWrites ?? 0) * model.dbWriteCost,\n compute: (sample.computeMs ?? 0) * model.computeMsCost,\n memory: (sample.memoryMbMs ?? 0) * model.memoryMbMsCost,\n external,\n custom: sample.customCost ?? 0,\n };\n}\n"],"mappings":"AAEA,MAAaA,EAA8B,CACzC,WAAY,KACZ,YAAa,KACb,cAAe,MACf,eAAgB,KACjB,CAED,SAAgB,EAAoB,EAAoB,EAAkB,CACxE,IAAM,GAAY,EAAO,eAAiB,EAAE,EAAE,QAC3C,EAAK,IAAS,GAAO,EAAK,MAAQ,GACnC,EACD,CAED,MAAO,CACL,SAAU,EAAO,SAAW,GAAK,EAAM,WACvC,UAAW,EAAO,UAAY,GAAK,EAAM,YACzC,SAAU,EAAO,WAAa,GAAK,EAAM,cACzC,QAAS,EAAO,YAAc,GAAK,EAAM,eACzC,WACA,OAAQ,EAAO,YAAc,EAC9B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cost-tracker.d.ts","names":[],"sources":["../src/cost-tracker.ts"],"sourcesContent":[],"mappings":";;;UAGiB,kBAAA;cACH;EADG,gBAAA,CAAA,EAAA,CAAA,MAAkB,EAEL,UADhB,EAAA,KACgB,EAAA,MAAA,EAAU,GAAA,IAAA;AAGxC;AAIwC,cAJ3B,WAAA,CAI2B;EAIjB,iBAAA,OAAA;EAAa,iBAAA,MAAA;EA+CM,iBAAA,SAAA;EAAA,WAAA,CAAA,OAAA,CAAA,EAnDF,kBAmDE;uBA/CnB,aAAa;;;MA+CM"}
|
package/dist/cost-tracker.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cost-tracker.js","names":["options: CostTrackerOptions","summary: OperationCostSummary"],"sources":["../src/cost-tracker.ts"],"sourcesContent":["import { calculateSampleCost, defaultCostModel } from './cost-model';\nimport type { CostModel, CostSample, OperationCostSummary } from './types';\n\nexport interface CostTrackerOptions {\n costModel?: CostModel;\n onSampleRecorded?: (sample: CostSample, total: number) => void;\n}\n\nexport class CostTracker {\n private readonly totals = new Map<string, OperationCostSummary>();\n private readonly costModel: CostModel;\n\n constructor(private readonly options: CostTrackerOptions = {}) {\n this.costModel = options.costModel ?? defaultCostModel;\n }\n\n recordSample(sample: CostSample): OperationCostSummary {\n const breakdown = calculateSampleCost(sample, this.costModel);\n const total =\n breakdown.dbReads +\n breakdown.dbWrites +\n breakdown.compute +\n breakdown.memory +\n breakdown.external +\n breakdown.custom;\n\n const key = this.buildKey(sample.operation, sample.tenantId);\n const existing = this.totals.get(key);\n\n const summary: OperationCostSummary = existing\n ? {\n ...existing,\n total: existing.total + total,\n breakdown: {\n dbReads: existing.breakdown.dbReads + breakdown.dbReads,\n dbWrites: existing.breakdown.dbWrites + breakdown.dbWrites,\n compute: existing.breakdown.compute + breakdown.compute,\n memory: existing.breakdown.memory + breakdown.memory,\n external: existing.breakdown.external + breakdown.external,\n custom: existing.breakdown.custom + breakdown.custom,\n },\n samples: existing.samples + 1,\n }\n : {\n operation: sample.operation,\n tenantId: sample.tenantId,\n total,\n breakdown: {\n dbReads: breakdown.dbReads,\n dbWrites: breakdown.dbWrites,\n compute: breakdown.compute,\n memory: breakdown.memory,\n external: breakdown.external,\n custom: breakdown.custom,\n },\n samples: 1,\n };\n\n this.totals.set(key, summary);\n this.options.onSampleRecorded?.(sample, total);\n return summary;\n }\n\n getTotals(filter?: { tenantId?: string }) {\n const items = Array.from(this.totals.values());\n if (!filter?.tenantId) {\n return items;\n }\n return items.filter((item) => item.tenantId === filter.tenantId);\n }\n\n reset() {\n this.totals.clear();\n }\n\n private buildKey(operation: string, tenantId?: string) {\n return tenantId ? `${tenantId}:${operation}` : operation;\n }\n}\n"],"mappings":"4EAQA,IAAa,EAAb,KAAyB,CACvB,OAA0B,IAAI,IAC9B,UAEA,YAAY,EAA+C,EAAE,CAAE,CAAlC,KAAA,QAAA,EAC3B,KAAK,UAAY,EAAQ,WAAa,EAGxC,aAAa,EAA0C,CACrD,IAAM,EAAY,EAAoB,EAAQ,KAAK,UAAU,CACvD,EACJ,EAAU,QACV,EAAU,SACV,EAAU,QACV,EAAU,OACV,EAAU,SACV,EAAU,OAEN,EAAM,KAAK,SAAS,EAAO,UAAW,EAAO,SAAS,CACtD,EAAW,KAAK,OAAO,IAAI,EAAI,CAE/BC,EAAgC,EAClC,CACE,GAAG,EACH,MAAO,EAAS,MAAQ,EACxB,UAAW,CACT,QAAS,EAAS,UAAU,QAAU,EAAU,QAChD,SAAU,EAAS,UAAU,SAAW,EAAU,SAClD,QAAS,EAAS,UAAU,QAAU,EAAU,QAChD,OAAQ,EAAS,UAAU,OAAS,EAAU,OAC9C,SAAU,EAAS,UAAU,SAAW,EAAU,SAClD,OAAQ,EAAS,UAAU,OAAS,EAAU,OAC/C,CACD,QAAS,EAAS,QAAU,EAC7B,CACD,CACE,UAAW,EAAO,UAClB,SAAU,EAAO,SACjB,QACA,UAAW,CACT,QAAS,EAAU,QACnB,SAAU,EAAU,SACpB,QAAS,EAAU,QACnB,OAAQ,EAAU,OAClB,SAAU,EAAU,SACpB,OAAQ,EAAU,OACnB,CACD,QAAS,EACV,CAIL,OAFA,KAAK,OAAO,IAAI,EAAK,EAAQ,CAC7B,KAAK,QAAQ,mBAAmB,EAAQ,EAAM,CACvC,EAGT,UAAU,EAAgC,CACxC,IAAM,EAAQ,MAAM,KAAK,KAAK,OAAO,QAAQ,CAAC,CAI9C,OAHK,GAAQ,SAGN,EAAM,OAAQ,GAAS,EAAK,WAAa,EAAO,SAAS,CAFvD,EAKX,OAAQ,CACN,KAAK,OAAO,OAAO,CAGrB,SAAiB,EAAmB,EAAmB,CACrD,OAAO,EAAW,GAAG,EAAS,GAAG,IAAc"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"optimization-recommender.d.ts","names":[],"sources":["../src/optimization-recommender.ts"],"sourcesContent":[],"mappings":";;;cAEa,uBAAA;oBACO,uBAAuB;AAD3C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"optimization-recommender.js","names":["suggestions: OptimizationSuggestion[]"],"sources":["../src/optimization-recommender.ts"],"sourcesContent":["import type { OperationCostSummary, OptimizationSuggestion } from './types';\n\nexport class OptimizationRecommender {\n generate(summary: OperationCostSummary): OptimizationSuggestion[] {\n const suggestions: OptimizationSuggestion[] = [];\n const avgCost = summary.total / summary.samples;\n\n if (summary.breakdown.dbReads / summary.samples > 1000) {\n suggestions.push({\n operation: summary.operation,\n tenantId: summary.tenantId,\n category: 'n_plus_one',\n message:\n 'High average DB read count detected. Consider batching queries or adding pagination.',\n evidence: { avgReads: summary.breakdown.dbReads / summary.samples },\n });\n }\n\n if (summary.breakdown.compute / summary.total > 0.6) {\n suggestions.push({\n operation: summary.operation,\n tenantId: summary.tenantId,\n category: 'batching',\n message:\n 'Compute dominates cost. Investigate hot loops or move heavy logic to background jobs.',\n evidence: { computeShare: summary.breakdown.compute / summary.total },\n });\n }\n\n if (summary.breakdown.external > avgCost * 0.5) {\n suggestions.push({\n operation: summary.operation,\n tenantId: summary.tenantId,\n category: 'external',\n message:\n 'External provider spend is high. Reuse results or enable caching.',\n evidence: { externalCost: summary.breakdown.external },\n });\n }\n\n if (summary.breakdown.memory > summary.breakdown.compute * 1.2) {\n suggestions.push({\n operation: summary.operation,\n tenantId: summary.tenantId,\n category: 'caching',\n message:\n 'Memory utilization suggests cached payloads linger. Tune TTL or stream responses.',\n evidence: { memoryCost: summary.breakdown.memory },\n });\n }\n\n return suggestions;\n }\n}\n"],"mappings":"AAEA,IAAa,EAAb,KAAqC,CACnC,SAAS,EAAyD,CAChE,IAAMA,EAAwC,EAAE,CAC1C,EAAU,EAAQ,MAAQ,EAAQ,QA8CxC,OA5CI,EAAQ,UAAU,QAAU,EAAQ,QAAU,KAChD,EAAY,KAAK,CACf,UAAW,EAAQ,UACnB,SAAU,EAAQ,SAClB,SAAU,aACV,QACE,uFACF,SAAU,CAAE,SAAU,EAAQ,UAAU,QAAU,EAAQ,QAAS,CACpE,CAAC,CAGA,EAAQ,UAAU,QAAU,EAAQ,MAAQ,IAC9C,EAAY,KAAK,CACf,UAAW,EAAQ,UACnB,SAAU,EAAQ,SAClB,SAAU,WACV,QACE,wFACF,SAAU,CAAE,aAAc,EAAQ,UAAU,QAAU,EAAQ,MAAO,CACtE,CAAC,CAGA,EAAQ,UAAU,SAAW,EAAU,IACzC,EAAY,KAAK,CACf,UAAW,EAAQ,UACnB,SAAU,EAAQ,SAClB,SAAU,WACV,QACE,oEACF,SAAU,CAAE,aAAc,EAAQ,UAAU,SAAU,CACvD,CAAC,CAGA,EAAQ,UAAU,OAAS,EAAQ,UAAU,QAAU,KACzD,EAAY,KAAK,CACf,UAAW,EAAQ,UACnB,SAAU,EAAQ,SAClB,SAAU,UACV,QACE,oFACF,SAAU,CAAE,WAAY,EAAQ,UAAU,OAAQ,CACnD,CAAC,CAGG"}
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";UAAiB,gBAAA;EAAA,QAAA,EAAA,MAAA;EAOA,IAAA,CAAA,EAAA,MAAU;EAQT,UAAA,CAAA,EAAA,MAAA;EAEJ,YAAA,CAAA,EAAA,MAAA;;AACK,UAXF,UAAA,CAWE;EAGF,SAAA,EAAA,MAAS;EAOT,QAAA,CAAA,EAAA,MAAA;EAeA,WAAA,CAAA,EAAA,KAAY,GAAA,SAAA,GAAA,MAAA;EAQZ,OAAA,CAAA,EAAA,MAAA;EAQA,QAAA,CAAA,EAAA,MAAW;;;kBA5CV;;cAEJ;aACD;;UAGI,SAAA;;;;;;UAOA,oBAAA;;;;;;;;;;;;;;UAeA,YAAA;;;;;;;UAQA,sBAAA;;;;;YAKL;;UAGK,WAAA;;;;eAIF"}
|