business-as-code 2.3.0 → 2.4.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/.turbo/turbo-build.log +4 -0
- package/CHANGELOG.md +43 -0
- package/dist/business.d.ts +62 -0
- package/dist/business.d.ts.map +1 -0
- package/dist/business.js +109 -0
- package/dist/business.js.map +1 -0
- package/dist/dollar.d.ts +60 -0
- package/dist/dollar.d.ts.map +1 -0
- package/dist/dollar.js +107 -0
- package/dist/dollar.js.map +1 -0
- package/dist/entities/assets.d.ts +21 -0
- package/dist/entities/assets.d.ts.map +1 -0
- package/dist/entities/assets.js +323 -0
- package/dist/entities/assets.js.map +1 -0
- package/dist/entities/business.d.ts +36 -0
- package/dist/entities/business.d.ts.map +1 -0
- package/dist/entities/business.js +370 -0
- package/dist/entities/business.js.map +1 -0
- package/dist/entities/communication.d.ts +21 -0
- package/dist/entities/communication.d.ts.map +1 -0
- package/dist/entities/communication.js +255 -0
- package/dist/entities/communication.js.map +1 -0
- package/dist/entities/customers.d.ts +58 -0
- package/dist/entities/customers.d.ts.map +1 -0
- package/dist/entities/customers.js +989 -0
- package/dist/entities/customers.js.map +1 -0
- package/dist/entities/financials.d.ts +59 -0
- package/dist/entities/financials.d.ts.map +1 -0
- package/dist/entities/financials.js +932 -0
- package/dist/entities/financials.js.map +1 -0
- package/dist/entities/goals.d.ts +58 -0
- package/dist/entities/goals.d.ts.map +1 -0
- package/dist/entities/goals.js +800 -0
- package/dist/entities/goals.js.map +1 -0
- package/dist/entities/index.d.ts +299 -0
- package/dist/entities/index.d.ts.map +1 -0
- package/dist/entities/index.js +198 -0
- package/dist/entities/index.js.map +1 -0
- package/dist/entities/legal.d.ts +21 -0
- package/dist/entities/legal.d.ts.map +1 -0
- package/dist/entities/legal.js +301 -0
- package/dist/entities/legal.js.map +1 -0
- package/dist/entities/market.d.ts +21 -0
- package/dist/entities/market.d.ts.map +1 -0
- package/dist/entities/market.js +301 -0
- package/dist/entities/market.js.map +1 -0
- package/dist/entities/marketing.d.ts +67 -0
- package/dist/entities/marketing.d.ts.map +1 -0
- package/dist/entities/marketing.js +1157 -0
- package/dist/entities/marketing.js.map +1 -0
- package/dist/entities/offerings.d.ts +51 -0
- package/dist/entities/offerings.d.ts.map +1 -0
- package/dist/entities/offerings.js +727 -0
- package/dist/entities/offerings.js.map +1 -0
- package/dist/entities/operations.d.ts +58 -0
- package/dist/entities/operations.d.ts.map +1 -0
- package/dist/entities/operations.js +787 -0
- package/dist/entities/operations.js.map +1 -0
- package/dist/entities/organization.d.ts +61 -0
- package/dist/entities/organization.d.ts.map +1 -0
- package/dist/entities/organization.js +816 -0
- package/dist/entities/organization.js.map +1 -0
- package/dist/entities/partnerships.d.ts +21 -0
- package/dist/entities/partnerships.d.ts.map +1 -0
- package/dist/entities/partnerships.js +300 -0
- package/dist/entities/partnerships.js.map +1 -0
- package/dist/entities/planning.d.ts +87 -0
- package/dist/entities/planning.d.ts.map +1 -0
- package/dist/entities/planning.js +271 -0
- package/dist/entities/planning.js.map +1 -0
- package/dist/entities/projects.d.ts +25 -0
- package/dist/entities/projects.d.ts.map +1 -0
- package/dist/entities/projects.js +349 -0
- package/dist/entities/projects.js.map +1 -0
- package/dist/entities/risk.d.ts +21 -0
- package/dist/entities/risk.d.ts.map +1 -0
- package/dist/entities/risk.js +293 -0
- package/dist/entities/risk.js.map +1 -0
- package/dist/entities/sales.d.ts +72 -0
- package/dist/entities/sales.d.ts.map +1 -0
- package/dist/entities/sales.js +1248 -0
- package/dist/entities/sales.js.map +1 -0
- package/dist/finance/account.d.ts +44 -0
- package/dist/finance/account.d.ts.map +1 -0
- package/dist/finance/account.js +6 -0
- package/dist/finance/account.js.map +1 -0
- package/dist/finance/authority.d.ts +78 -0
- package/dist/finance/authority.d.ts.map +1 -0
- package/dist/finance/authority.js +27 -0
- package/dist/finance/authority.js.map +1 -0
- package/dist/finance/card.d.ts +36 -0
- package/dist/finance/card.d.ts.map +1 -0
- package/dist/finance/card.js +6 -0
- package/dist/finance/card.js.map +1 -0
- package/dist/finance/identity.d.ts +30 -0
- package/dist/finance/identity.d.ts.map +1 -0
- package/dist/finance/identity.js +8 -0
- package/dist/finance/identity.js.map +1 -0
- package/dist/finance/index.d.ts +36 -0
- package/dist/finance/index.d.ts.map +1 -0
- package/dist/finance/index.js +22 -0
- package/dist/finance/index.js.map +1 -0
- package/dist/finance/ledger.d.ts +24 -0
- package/dist/finance/ledger.d.ts.map +1 -0
- package/dist/finance/ledger.js +8 -0
- package/dist/finance/ledger.js.map +1 -0
- package/dist/finance/merchant.d.ts +129 -0
- package/dist/finance/merchant.d.ts.map +1 -0
- package/dist/finance/merchant.js +21 -0
- package/dist/finance/merchant.js.map +1 -0
- package/dist/finance/outcome-contract.d.ts +139 -0
- package/dist/finance/outcome-contract.d.ts.map +1 -0
- package/dist/finance/outcome-contract.js +27 -0
- package/dist/finance/outcome-contract.js.map +1 -0
- package/dist/finance/port.d.ts +121 -0
- package/dist/finance/port.d.ts.map +1 -0
- package/dist/finance/port.js +10 -0
- package/dist/finance/port.js.map +1 -0
- package/dist/finance/pricing.d.ts +154 -0
- package/dist/finance/pricing.d.ts.map +1 -0
- package/dist/finance/pricing.js +79 -0
- package/dist/finance/pricing.js.map +1 -0
- package/dist/finance/proof-predicate.d.ts +92 -0
- package/dist/finance/proof-predicate.d.ts.map +1 -0
- package/dist/finance/proof-predicate.js +80 -0
- package/dist/finance/proof-predicate.js.map +1 -0
- package/dist/finance/refund.d.ts +44 -0
- package/dist/finance/refund.d.ts.map +1 -0
- package/dist/finance/refund.js +41 -0
- package/dist/finance/refund.js.map +1 -0
- package/dist/finance/sla.d.ts +25 -0
- package/dist/finance/sla.d.ts.map +1 -0
- package/dist/finance/sla.js +7 -0
- package/dist/finance/sla.js.map +1 -0
- package/dist/finance/types.d.ts +79 -0
- package/dist/finance/types.d.ts.map +1 -0
- package/dist/finance/types.js +8 -0
- package/dist/finance/types.js.map +1 -0
- package/dist/financials.d.ts +130 -0
- package/dist/financials.d.ts.map +1 -0
- package/dist/financials.js +297 -0
- package/dist/financials.js.map +1 -0
- package/dist/goals.d.ts +106 -0
- package/dist/goals.d.ts.map +1 -0
- package/dist/goals.js +284 -0
- package/dist/goals.js.map +1 -0
- package/dist/index.d.ts +101 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +144 -0
- package/dist/index.js.map +1 -0
- package/dist/kpis.d.ts +137 -0
- package/dist/kpis.d.ts.map +1 -0
- package/dist/kpis.js +297 -0
- package/dist/kpis.js.map +1 -0
- package/dist/metrics.d.ts +448 -0
- package/dist/metrics.d.ts.map +1 -0
- package/dist/metrics.js +330 -0
- package/dist/metrics.js.map +1 -0
- package/dist/okrs.d.ts +157 -0
- package/dist/okrs.d.ts.map +1 -0
- package/dist/okrs.js +391 -0
- package/dist/okrs.js.map +1 -0
- package/dist/organization.d.ts +585 -0
- package/dist/organization.d.ts.map +1 -0
- package/dist/organization.js +173 -0
- package/dist/organization.js.map +1 -0
- package/dist/process.d.ts +112 -0
- package/dist/process.d.ts.map +1 -0
- package/dist/process.js +242 -0
- package/dist/process.js.map +1 -0
- package/dist/product.d.ts +85 -0
- package/dist/product.d.ts.map +1 -0
- package/dist/product.js +145 -0
- package/dist/product.js.map +1 -0
- package/dist/queries.d.ts +304 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +577 -0
- package/dist/queries.js.map +1 -0
- package/dist/roles.d.ts +334 -0
- package/dist/roles.d.ts.map +1 -0
- package/dist/roles.js +282 -0
- package/dist/roles.js.map +1 -0
- package/dist/service.d.ts +61 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +140 -0
- package/dist/service.js.map +1 -0
- package/dist/types.d.ts +459 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/vision.d.ts +38 -0
- package/dist/vision.d.ts.map +1 -0
- package/dist/vision.js +68 -0
- package/dist/vision.js.map +1 -0
- package/dist/workflow.d.ts +115 -0
- package/dist/workflow.d.ts.map +1 -0
- package/dist/workflow.js +248 -0
- package/dist/workflow.js.map +1 -0
- package/package.json +8 -4
- package/src/finance/account.ts +48 -0
- package/src/finance/authority.ts +42 -0
- package/src/finance/card.ts +38 -0
- package/src/finance/identity.ts +31 -0
- package/src/finance/index.ts +117 -0
- package/src/finance/ledger.ts +26 -0
- package/src/finance/merchant.ts +127 -0
- package/src/finance/outcome-contract.ts +157 -0
- package/src/finance/port.ts +144 -0
- package/src/finance/pricing.ts +197 -0
- package/src/finance/proof-predicate.ts +106 -0
- package/src/finance/refund.ts +52 -0
- package/src/finance/sla.ts +33 -0
- package/src/finance/types.ts +75 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Financial metrics and calculations
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Calculate financial metrics from basic inputs
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const metrics = financials({
|
|
10
|
+
* revenue: 1000000,
|
|
11
|
+
* cogs: 300000,
|
|
12
|
+
* operatingExpenses: 500000,
|
|
13
|
+
* currency: 'USD',
|
|
14
|
+
* period: 'monthly',
|
|
15
|
+
* })
|
|
16
|
+
*
|
|
17
|
+
* console.log(metrics.grossMargin) // 70%
|
|
18
|
+
* console.log(metrics.operatingMargin) // 20%
|
|
19
|
+
* console.log(metrics.netMargin) // 20%
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function financials(metrics) {
|
|
23
|
+
const revenue = metrics.revenue || 0;
|
|
24
|
+
const cogs = metrics.cogs || 0;
|
|
25
|
+
const operatingExpenses = metrics.operatingExpenses || 0;
|
|
26
|
+
// Calculate derived metrics
|
|
27
|
+
const grossProfit = revenue - cogs;
|
|
28
|
+
const grossMargin = revenue > 0 ? (grossProfit / revenue) * 100 : 0;
|
|
29
|
+
const operatingIncome = grossProfit - operatingExpenses;
|
|
30
|
+
const operatingMargin = revenue > 0 ? (operatingIncome / revenue) * 100 : 0;
|
|
31
|
+
const netIncome = metrics.netIncome ?? operatingIncome;
|
|
32
|
+
const netMargin = revenue > 0 ? (netIncome / revenue) * 100 : 0;
|
|
33
|
+
// EBITDA (simplified - would need D&A for accurate calculation)
|
|
34
|
+
const ebitda = metrics.ebitda ?? operatingIncome;
|
|
35
|
+
const ebitdaMargin = revenue > 0 ? (ebitda / revenue) * 100 : 0;
|
|
36
|
+
return {
|
|
37
|
+
...metrics,
|
|
38
|
+
revenue,
|
|
39
|
+
cogs,
|
|
40
|
+
grossProfit,
|
|
41
|
+
grossMargin,
|
|
42
|
+
operatingExpenses,
|
|
43
|
+
operatingIncome,
|
|
44
|
+
operatingMargin,
|
|
45
|
+
netIncome,
|
|
46
|
+
netMargin,
|
|
47
|
+
ebitda,
|
|
48
|
+
ebitdaMargin,
|
|
49
|
+
currency: metrics.currency || 'USD',
|
|
50
|
+
period: metrics.period || 'monthly',
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Calculate gross margin
|
|
55
|
+
*/
|
|
56
|
+
export function calculateGrossMargin(revenue, cogs) {
|
|
57
|
+
if (revenue === 0)
|
|
58
|
+
return 0;
|
|
59
|
+
return ((revenue - cogs) / revenue) * 100;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Calculate operating margin
|
|
63
|
+
*/
|
|
64
|
+
export function calculateOperatingMargin(revenue, cogs, operatingExpenses) {
|
|
65
|
+
if (revenue === 0)
|
|
66
|
+
return 0;
|
|
67
|
+
const operatingIncome = revenue - cogs - operatingExpenses;
|
|
68
|
+
return (operatingIncome / revenue) * 100;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Calculate net margin
|
|
72
|
+
*/
|
|
73
|
+
export function calculateNetMargin(revenue, netIncome) {
|
|
74
|
+
if (revenue === 0)
|
|
75
|
+
return 0;
|
|
76
|
+
return (netIncome / revenue) * 100;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Calculate EBITDA margin
|
|
80
|
+
*/
|
|
81
|
+
export function calculateEBITDAMargin(revenue, ebitda) {
|
|
82
|
+
if (revenue === 0)
|
|
83
|
+
return 0;
|
|
84
|
+
return (ebitda / revenue) * 100;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Calculate burn rate (monthly cash burn)
|
|
88
|
+
*/
|
|
89
|
+
export function calculateBurnRate(cashStart, cashEnd, months) {
|
|
90
|
+
if (months === 0)
|
|
91
|
+
return 0;
|
|
92
|
+
return (cashStart - cashEnd) / months;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Calculate runway (months until cash runs out)
|
|
96
|
+
*/
|
|
97
|
+
export function calculateRunway(cash, monthlyBurnRate) {
|
|
98
|
+
if (monthlyBurnRate === 0)
|
|
99
|
+
return Infinity;
|
|
100
|
+
if (monthlyBurnRate < 0)
|
|
101
|
+
return Infinity; // Company is profitable
|
|
102
|
+
return cash / monthlyBurnRate;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Calculate customer acquisition cost (CAC)
|
|
106
|
+
*/
|
|
107
|
+
export function calculateCAC(marketingSpend, newCustomers) {
|
|
108
|
+
if (newCustomers === 0)
|
|
109
|
+
return 0;
|
|
110
|
+
return marketingSpend / newCustomers;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Calculate customer lifetime value (LTV)
|
|
114
|
+
*/
|
|
115
|
+
export function calculateLTV(averageRevenuePerCustomer, averageCustomerLifetimeMonths, grossMarginPercent) {
|
|
116
|
+
return averageRevenuePerCustomer * averageCustomerLifetimeMonths * (grossMarginPercent / 100);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Calculate LTV:CAC ratio
|
|
120
|
+
*/
|
|
121
|
+
export function calculateLTVtoCAC(ltv, cac) {
|
|
122
|
+
if (cac === 0)
|
|
123
|
+
return 0;
|
|
124
|
+
return ltv / cac;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Calculate payback period (months to recover CAC)
|
|
128
|
+
*/
|
|
129
|
+
export function calculatePaybackPeriod(cac, monthlyRevPerCustomer) {
|
|
130
|
+
if (monthlyRevPerCustomer === 0)
|
|
131
|
+
return 0;
|
|
132
|
+
return cac / monthlyRevPerCustomer;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Calculate annual recurring revenue (ARR)
|
|
136
|
+
*/
|
|
137
|
+
export function calculateARR(mrr) {
|
|
138
|
+
return mrr * 12;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Calculate monthly recurring revenue (MRR)
|
|
142
|
+
*/
|
|
143
|
+
export function calculateMRR(arr) {
|
|
144
|
+
return arr / 12;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Calculate revenue growth rate
|
|
148
|
+
*/
|
|
149
|
+
export function calculateGrowthRate(currentRevenue, previousRevenue) {
|
|
150
|
+
if (previousRevenue === 0)
|
|
151
|
+
return 0;
|
|
152
|
+
return ((currentRevenue - previousRevenue) / previousRevenue) * 100;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Calculate compound annual growth rate (CAGR)
|
|
156
|
+
*/
|
|
157
|
+
export function calculateCAGR(beginningValue, endingValue, years) {
|
|
158
|
+
if (beginningValue === 0 || years === 0)
|
|
159
|
+
return 0;
|
|
160
|
+
return (Math.pow(endingValue / beginningValue, 1 / years) - 1) * 100;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Calculate return on investment (ROI)
|
|
164
|
+
*/
|
|
165
|
+
export function calculateROI(gain, cost) {
|
|
166
|
+
if (cost === 0)
|
|
167
|
+
return 0;
|
|
168
|
+
return ((gain - cost) / cost) * 100;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Calculate return on equity (ROE)
|
|
172
|
+
*/
|
|
173
|
+
export function calculateROE(netIncome, shareholderEquity) {
|
|
174
|
+
if (shareholderEquity === 0)
|
|
175
|
+
return 0;
|
|
176
|
+
return (netIncome / shareholderEquity) * 100;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Calculate return on assets (ROA)
|
|
180
|
+
*/
|
|
181
|
+
export function calculateROA(netIncome, totalAssets) {
|
|
182
|
+
if (totalAssets === 0)
|
|
183
|
+
return 0;
|
|
184
|
+
return (netIncome / totalAssets) * 100;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Calculate quick ratio (liquidity)
|
|
188
|
+
*/
|
|
189
|
+
export function calculateQuickRatio(currentAssets, inventory, currentLiabilities) {
|
|
190
|
+
if (currentLiabilities === 0)
|
|
191
|
+
return 0;
|
|
192
|
+
return (currentAssets - inventory) / currentLiabilities;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Calculate current ratio (liquidity)
|
|
196
|
+
*/
|
|
197
|
+
export function calculateCurrentRatio(currentAssets, currentLiabilities) {
|
|
198
|
+
if (currentLiabilities === 0)
|
|
199
|
+
return 0;
|
|
200
|
+
return currentAssets / currentLiabilities;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Calculate debt-to-equity ratio
|
|
204
|
+
*/
|
|
205
|
+
export function calculateDebtToEquity(totalDebt, totalEquity) {
|
|
206
|
+
if (totalEquity === 0)
|
|
207
|
+
return 0;
|
|
208
|
+
return totalDebt / totalEquity;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Format currency value
|
|
212
|
+
*/
|
|
213
|
+
export function formatCurrency(amount, currency = 'USD') {
|
|
214
|
+
const symbol = getCurrencySymbol(currency);
|
|
215
|
+
const formatted = Math.abs(amount).toLocaleString(undefined, {
|
|
216
|
+
minimumFractionDigits: 0,
|
|
217
|
+
maximumFractionDigits: 2,
|
|
218
|
+
});
|
|
219
|
+
const sign = amount < 0 ? '-' : '';
|
|
220
|
+
return `${sign}${symbol}${formatted}`;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Get currency symbol
|
|
224
|
+
*/
|
|
225
|
+
function getCurrencySymbol(currency) {
|
|
226
|
+
const symbols = {
|
|
227
|
+
USD: '$',
|
|
228
|
+
EUR: '€',
|
|
229
|
+
GBP: '£',
|
|
230
|
+
JPY: '¥',
|
|
231
|
+
CNY: '¥',
|
|
232
|
+
CAD: 'C$',
|
|
233
|
+
AUD: 'A$',
|
|
234
|
+
};
|
|
235
|
+
return symbols[currency] || currency + ' ';
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Create a financial statement
|
|
239
|
+
*/
|
|
240
|
+
export function createStatement(type, period, lineItems, currency = 'USD') {
|
|
241
|
+
return {
|
|
242
|
+
type,
|
|
243
|
+
period,
|
|
244
|
+
lineItems,
|
|
245
|
+
currency,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Get line item from financial statement
|
|
250
|
+
*/
|
|
251
|
+
export function getLineItem(statement, name) {
|
|
252
|
+
return statement.lineItems[name] || 0;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Compare financial metrics between periods
|
|
256
|
+
*/
|
|
257
|
+
export function compareMetrics(current, previous) {
|
|
258
|
+
const comparison = {};
|
|
259
|
+
const keys = [
|
|
260
|
+
'revenue',
|
|
261
|
+
'grossProfit',
|
|
262
|
+
'operatingIncome',
|
|
263
|
+
'netIncome',
|
|
264
|
+
'ebitda',
|
|
265
|
+
];
|
|
266
|
+
for (const key of keys) {
|
|
267
|
+
const currentVal = current[key] || 0;
|
|
268
|
+
const previousVal = previous[key] || 0;
|
|
269
|
+
const change = currentVal - previousVal;
|
|
270
|
+
const changePercent = previousVal !== 0 ? (change / previousVal) * 100 : 0;
|
|
271
|
+
comparison[key] = { change, changePercent };
|
|
272
|
+
}
|
|
273
|
+
return comparison;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Validate financial metrics
|
|
277
|
+
*/
|
|
278
|
+
export function validateFinancials(metrics) {
|
|
279
|
+
const errors = [];
|
|
280
|
+
if (metrics.revenue && metrics.revenue < 0) {
|
|
281
|
+
errors.push('Revenue cannot be negative');
|
|
282
|
+
}
|
|
283
|
+
if (metrics.cogs && metrics.cogs < 0) {
|
|
284
|
+
errors.push('COGS cannot be negative');
|
|
285
|
+
}
|
|
286
|
+
if (metrics.operatingExpenses && metrics.operatingExpenses < 0) {
|
|
287
|
+
errors.push('Operating expenses cannot be negative');
|
|
288
|
+
}
|
|
289
|
+
if (metrics.revenue && metrics.cogs && metrics.cogs > metrics.revenue) {
|
|
290
|
+
errors.push('COGS cannot exceed revenue');
|
|
291
|
+
}
|
|
292
|
+
return {
|
|
293
|
+
valid: errors.length === 0,
|
|
294
|
+
errors,
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
//# sourceMappingURL=financials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"financials.js","sourceRoot":"","sources":["../src/financials.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,UAAU,CAAC,OAAkC;IAC3D,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,CAAC,CAAA;IACpC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,CAAC,CAAA;IAC9B,MAAM,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,IAAI,CAAC,CAAA;IAExD,4BAA4B;IAC5B,MAAM,WAAW,GAAG,OAAO,GAAG,IAAI,CAAA;IAClC,MAAM,WAAW,GAAG,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,GAAG,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;IAEnE,MAAM,eAAe,GAAG,WAAW,GAAG,iBAAiB,CAAA;IACvD,MAAM,eAAe,GAAG,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,GAAG,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC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,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE,CAAA;IAC7C,CAAC;IAED,OAAO,UAAU,CAAA;AACnB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAAyB;IAEzB,MAAM,MAAM,GAAa,EAAE,CAAA;IAE3B,IAAI,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,GAAG,CAAC,EAAE,CAAC;QAC3C,MAAM,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAA;IAC3C,CAAC;IAED,IAAI,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;QACrC,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAA;IACxC,CAAC;IAED,IAAI,OAAO,CAAC,iBAAiB,IAAI,OAAO,CAAC,iBAAiB,GAAG,CAAC,EAAE,CAAC;QAC/D,MAAM,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAA;IACtD,CAAC;IAED,IAAI,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;QACtE,MAAM,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAA;IAC3C,CAAC;IAED,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;QAC1B,MAAM;KACP,CAAA;AACH,CAAC"}
|
package/dist/goals.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Business goals definition and tracking
|
|
3
|
+
*
|
|
4
|
+
* Uses org.ai Goal types for standardized goal definitions across the ecosystem.
|
|
5
|
+
*/
|
|
6
|
+
import type { GoalDefinition } from './types.js';
|
|
7
|
+
import type { Goal as OrgGoal, Goals as OrgGoals, GoalStatus, GoalCategory, GoalPriority } from 'org.ai';
|
|
8
|
+
export type { OrgGoal, OrgGoals, GoalStatus, GoalCategory, GoalPriority };
|
|
9
|
+
/**
|
|
10
|
+
* Convert a business-as-code GoalDefinition to an org.ai Goal
|
|
11
|
+
*
|
|
12
|
+
* @param definition - Business goal definition
|
|
13
|
+
* @param id - Unique identifier for the goal
|
|
14
|
+
* @returns org.ai Goal object
|
|
15
|
+
*/
|
|
16
|
+
export declare function toOrgGoal(definition: GoalDefinition, id: string): OrgGoal;
|
|
17
|
+
/**
|
|
18
|
+
* Convert an org.ai Goal to a business-as-code GoalDefinition
|
|
19
|
+
*
|
|
20
|
+
* @param goal - org.ai Goal object
|
|
21
|
+
* @returns Business goal definition
|
|
22
|
+
*/
|
|
23
|
+
export declare function fromOrgGoal(goal: OrgGoal): GoalDefinition;
|
|
24
|
+
/**
|
|
25
|
+
* Define a business goal with metrics and tracking
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const goals = Goals([
|
|
30
|
+
* {
|
|
31
|
+
* name: 'Launch MVP',
|
|
32
|
+
* description: 'Ship minimum viable product to early customers',
|
|
33
|
+
* category: 'strategic',
|
|
34
|
+
* targetDate: new Date('2024-06-30'),
|
|
35
|
+
* owner: 'Product Team',
|
|
36
|
+
* metrics: ['User signups', 'Feature completion rate'],
|
|
37
|
+
* status: 'in-progress',
|
|
38
|
+
* progress: 65,
|
|
39
|
+
* },
|
|
40
|
+
* {
|
|
41
|
+
* name: 'Achieve Product-Market Fit',
|
|
42
|
+
* description: 'Validate product value with target customers',
|
|
43
|
+
* category: 'strategic',
|
|
44
|
+
* targetDate: new Date('2024-12-31'),
|
|
45
|
+
* owner: 'CEO',
|
|
46
|
+
* metrics: ['NPS > 50', 'Churn < 5%', '100+ paying customers'],
|
|
47
|
+
* status: 'in-progress',
|
|
48
|
+
* progress: 30,
|
|
49
|
+
* dependencies: ['Launch MVP'],
|
|
50
|
+
* },
|
|
51
|
+
* ])
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function Goals(definitions: GoalDefinition[]): GoalDefinition[];
|
|
55
|
+
/**
|
|
56
|
+
* Define a single goal
|
|
57
|
+
*/
|
|
58
|
+
export declare function Goal(definition: GoalDefinition): GoalDefinition;
|
|
59
|
+
/**
|
|
60
|
+
* Update goal progress
|
|
61
|
+
*/
|
|
62
|
+
export declare function updateProgress(goal: GoalDefinition, progress: number): GoalDefinition;
|
|
63
|
+
/**
|
|
64
|
+
* Mark goal as at-risk
|
|
65
|
+
*/
|
|
66
|
+
export declare function markAtRisk(goal: GoalDefinition): GoalDefinition;
|
|
67
|
+
/**
|
|
68
|
+
* Mark goal as completed
|
|
69
|
+
*/
|
|
70
|
+
export declare function complete(goal: GoalDefinition): GoalDefinition;
|
|
71
|
+
/**
|
|
72
|
+
* Check if goal is overdue
|
|
73
|
+
*/
|
|
74
|
+
export declare function isOverdue(goal: GoalDefinition): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Get goals by category
|
|
77
|
+
*/
|
|
78
|
+
export declare function getGoalsByCategory(goals: GoalDefinition[], category: GoalDefinition['category']): GoalDefinition[];
|
|
79
|
+
/**
|
|
80
|
+
* Get goals by status
|
|
81
|
+
*/
|
|
82
|
+
export declare function getGoalsByStatus(goals: GoalDefinition[], status: GoalDefinition['status']): GoalDefinition[];
|
|
83
|
+
/**
|
|
84
|
+
* Get goals by owner
|
|
85
|
+
*/
|
|
86
|
+
export declare function getGoalsByOwner(goals: GoalDefinition[], owner: string): GoalDefinition[];
|
|
87
|
+
/**
|
|
88
|
+
* Calculate overall progress across all goals
|
|
89
|
+
*/
|
|
90
|
+
export declare function calculateOverallProgress(goals: GoalDefinition[]): number;
|
|
91
|
+
/**
|
|
92
|
+
* Check for circular dependencies
|
|
93
|
+
*/
|
|
94
|
+
export declare function hasCircularDependencies(goals: GoalDefinition[]): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Get goals in dependency order
|
|
97
|
+
*/
|
|
98
|
+
export declare function sortByDependencies(goals: GoalDefinition[]): GoalDefinition[];
|
|
99
|
+
/**
|
|
100
|
+
* Validate goals
|
|
101
|
+
*/
|
|
102
|
+
export declare function validateGoals(goals: GoalDefinition[]): {
|
|
103
|
+
valid: boolean;
|
|
104
|
+
errors: string[];
|
|
105
|
+
};
|
|
106
|
+
//# sourceMappingURL=goals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"goals.d.ts","sourceRoot":"","sources":["../src/goals.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,KAAK,EACV,IAAI,IAAI,OAAO,EACf,KAAK,IAAI,QAAQ,EACjB,UAAU,EACV,YAAY,EACZ,YAAY,EACb,MAAM,QAAQ,CAAA;AAGf,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,CAAA;AAEzE;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAmBzE;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,cAAc,CAiBzD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,KAAK,CAAC,WAAW,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE,CAErE;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,UAAU,EAAE,cAAc,GAAG,cAAc,CAE/D;AAqBD;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,GAAG,cAAc,CAqBrF;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,cAAc,CAK/D;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,cAAc,GAAG,cAAc,CAM7D;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAGvD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,cAAc,EAAE,EACvB,QAAQ,EAAE,cAAc,CAAC,UAAU,CAAC,GACnC,cAAc,EAAE,CAElB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,cAAc,EAAE,EACvB,MAAM,EAAE,cAAc,CAAC,QAAQ,CAAC,GAC/B,cAAc,EAAE,CAElB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,cAAc,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,cAAc,EAAE,CAExF;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,MAAM,CAKxE;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,OAAO,CAqBxE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE,CA4B5E;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CA8B3F"}
|
package/dist/goals.js
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Business goals definition and tracking
|
|
3
|
+
*
|
|
4
|
+
* Uses org.ai Goal types for standardized goal definitions across the ecosystem.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Convert a business-as-code GoalDefinition to an org.ai Goal
|
|
8
|
+
*
|
|
9
|
+
* @param definition - Business goal definition
|
|
10
|
+
* @param id - Unique identifier for the goal
|
|
11
|
+
* @returns org.ai Goal object
|
|
12
|
+
*/
|
|
13
|
+
export function toOrgGoal(definition, id) {
|
|
14
|
+
const result = {
|
|
15
|
+
id,
|
|
16
|
+
name: definition.name,
|
|
17
|
+
description: definition.description || definition.name,
|
|
18
|
+
target: 100,
|
|
19
|
+
progress: definition.progress || 0,
|
|
20
|
+
status: definition.status || 'not-started',
|
|
21
|
+
};
|
|
22
|
+
if (definition.targetDate) {
|
|
23
|
+
result.targetDate = definition.targetDate;
|
|
24
|
+
result.deadline = definition.targetDate;
|
|
25
|
+
}
|
|
26
|
+
if (definition.owner)
|
|
27
|
+
result.owner = definition.owner;
|
|
28
|
+
if (definition.category)
|
|
29
|
+
result.category = definition.category;
|
|
30
|
+
if (definition.metrics)
|
|
31
|
+
result.metrics = definition.metrics;
|
|
32
|
+
if (definition.dependencies)
|
|
33
|
+
result.dependencies = definition.dependencies;
|
|
34
|
+
if (definition.metadata)
|
|
35
|
+
result.metadata = definition.metadata;
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Convert an org.ai Goal to a business-as-code GoalDefinition
|
|
40
|
+
*
|
|
41
|
+
* @param goal - org.ai Goal object
|
|
42
|
+
* @returns Business goal definition
|
|
43
|
+
*/
|
|
44
|
+
export function fromOrgGoal(goal) {
|
|
45
|
+
const result = {
|
|
46
|
+
name: goal.name,
|
|
47
|
+
progress: typeof goal.progress === 'number' ? goal.progress : 0,
|
|
48
|
+
};
|
|
49
|
+
if (goal.description)
|
|
50
|
+
result.description = goal.description;
|
|
51
|
+
const cat = goal.category;
|
|
52
|
+
if (cat)
|
|
53
|
+
result.category = cat;
|
|
54
|
+
if (goal.targetDate)
|
|
55
|
+
result.targetDate = goal.targetDate;
|
|
56
|
+
else if (goal.deadline)
|
|
57
|
+
result.targetDate = goal.deadline;
|
|
58
|
+
if (goal.owner)
|
|
59
|
+
result.owner = goal.owner;
|
|
60
|
+
if (goal.metrics)
|
|
61
|
+
result.metrics = goal.metrics;
|
|
62
|
+
const st = goal.status;
|
|
63
|
+
if (st)
|
|
64
|
+
result.status = st;
|
|
65
|
+
if (goal.dependencies)
|
|
66
|
+
result.dependencies = goal.dependencies;
|
|
67
|
+
if (goal.metadata)
|
|
68
|
+
result.metadata = goal.metadata;
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Define a business goal with metrics and tracking
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* const goals = Goals([
|
|
77
|
+
* {
|
|
78
|
+
* name: 'Launch MVP',
|
|
79
|
+
* description: 'Ship minimum viable product to early customers',
|
|
80
|
+
* category: 'strategic',
|
|
81
|
+
* targetDate: new Date('2024-06-30'),
|
|
82
|
+
* owner: 'Product Team',
|
|
83
|
+
* metrics: ['User signups', 'Feature completion rate'],
|
|
84
|
+
* status: 'in-progress',
|
|
85
|
+
* progress: 65,
|
|
86
|
+
* },
|
|
87
|
+
* {
|
|
88
|
+
* name: 'Achieve Product-Market Fit',
|
|
89
|
+
* description: 'Validate product value with target customers',
|
|
90
|
+
* category: 'strategic',
|
|
91
|
+
* targetDate: new Date('2024-12-31'),
|
|
92
|
+
* owner: 'CEO',
|
|
93
|
+
* metrics: ['NPS > 50', 'Churn < 5%', '100+ paying customers'],
|
|
94
|
+
* status: 'in-progress',
|
|
95
|
+
* progress: 30,
|
|
96
|
+
* dependencies: ['Launch MVP'],
|
|
97
|
+
* },
|
|
98
|
+
* ])
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export function Goals(definitions) {
|
|
102
|
+
return definitions.map((goal) => validateAndNormalizeGoal(goal));
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Define a single goal
|
|
106
|
+
*/
|
|
107
|
+
export function Goal(definition) {
|
|
108
|
+
return validateAndNormalizeGoal(definition);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Validate and normalize a goal definition
|
|
112
|
+
*/
|
|
113
|
+
function validateAndNormalizeGoal(goal) {
|
|
114
|
+
if (!goal.name) {
|
|
115
|
+
throw new Error('Goal name is required');
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
...goal,
|
|
119
|
+
category: goal.category || 'operational',
|
|
120
|
+
status: goal.status || 'not-started',
|
|
121
|
+
progress: goal.progress || 0,
|
|
122
|
+
metrics: goal.metrics || [],
|
|
123
|
+
dependencies: goal.dependencies || [],
|
|
124
|
+
metadata: goal.metadata || {},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Update goal progress
|
|
129
|
+
*/
|
|
130
|
+
export function updateProgress(goal, progress) {
|
|
131
|
+
if (progress < 0 || progress > 100) {
|
|
132
|
+
throw new Error('Progress must be between 0 and 100');
|
|
133
|
+
}
|
|
134
|
+
// Auto-update status based on progress
|
|
135
|
+
let status;
|
|
136
|
+
if (progress === 0) {
|
|
137
|
+
status = 'not-started';
|
|
138
|
+
}
|
|
139
|
+
else if (progress === 100) {
|
|
140
|
+
status = 'completed';
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
status = 'in-progress';
|
|
144
|
+
}
|
|
145
|
+
const result = {
|
|
146
|
+
...goal,
|
|
147
|
+
progress,
|
|
148
|
+
};
|
|
149
|
+
if (status !== undefined)
|
|
150
|
+
result.status = status;
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Mark goal as at-risk
|
|
155
|
+
*/
|
|
156
|
+
export function markAtRisk(goal) {
|
|
157
|
+
return {
|
|
158
|
+
...goal,
|
|
159
|
+
status: 'at-risk',
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Mark goal as completed
|
|
164
|
+
*/
|
|
165
|
+
export function complete(goal) {
|
|
166
|
+
return {
|
|
167
|
+
...goal,
|
|
168
|
+
status: 'completed',
|
|
169
|
+
progress: 100,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Check if goal is overdue
|
|
174
|
+
*/
|
|
175
|
+
export function isOverdue(goal) {
|
|
176
|
+
if (!goal.targetDate)
|
|
177
|
+
return false;
|
|
178
|
+
return new Date() > goal.targetDate && goal.status !== 'completed';
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Get goals by category
|
|
182
|
+
*/
|
|
183
|
+
export function getGoalsByCategory(goals, category) {
|
|
184
|
+
return goals.filter((g) => g.category === category);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Get goals by status
|
|
188
|
+
*/
|
|
189
|
+
export function getGoalsByStatus(goals, status) {
|
|
190
|
+
return goals.filter((g) => g.status === status);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Get goals by owner
|
|
194
|
+
*/
|
|
195
|
+
export function getGoalsByOwner(goals, owner) {
|
|
196
|
+
return goals.filter((g) => g.owner === owner);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Calculate overall progress across all goals
|
|
200
|
+
*/
|
|
201
|
+
export function calculateOverallProgress(goals) {
|
|
202
|
+
if (goals.length === 0)
|
|
203
|
+
return 0;
|
|
204
|
+
const totalProgress = goals.reduce((sum, goal) => sum + (goal.progress || 0), 0);
|
|
205
|
+
return totalProgress / goals.length;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Check for circular dependencies
|
|
209
|
+
*/
|
|
210
|
+
export function hasCircularDependencies(goals) {
|
|
211
|
+
const goalMap = new Map(goals.map((g) => [g.name, g]));
|
|
212
|
+
function checkCircular(goalName, visited = new Set()) {
|
|
213
|
+
if (visited.has(goalName))
|
|
214
|
+
return true;
|
|
215
|
+
const goal = goalMap.get(goalName);
|
|
216
|
+
if (!goal || !goal.dependencies)
|
|
217
|
+
return false;
|
|
218
|
+
visited.add(goalName);
|
|
219
|
+
for (const dep of goal.dependencies) {
|
|
220
|
+
if (checkCircular(dep, new Set(visited))) {
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
return goals.some((goal) => checkCircular(goal.name));
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Get goals in dependency order
|
|
230
|
+
*/
|
|
231
|
+
export function sortByDependencies(goals) {
|
|
232
|
+
const goalMap = new Map(goals.map((g) => [g.name, g]));
|
|
233
|
+
const sorted = [];
|
|
234
|
+
const visited = new Set();
|
|
235
|
+
function visit(goalName) {
|
|
236
|
+
if (visited.has(goalName))
|
|
237
|
+
return;
|
|
238
|
+
const goal = goalMap.get(goalName);
|
|
239
|
+
if (!goal)
|
|
240
|
+
return;
|
|
241
|
+
visited.add(goalName);
|
|
242
|
+
// Visit dependencies first
|
|
243
|
+
if (goal.dependencies) {
|
|
244
|
+
for (const dep of goal.dependencies) {
|
|
245
|
+
visit(dep);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
sorted.push(goal);
|
|
249
|
+
}
|
|
250
|
+
for (const goal of goals) {
|
|
251
|
+
visit(goal.name);
|
|
252
|
+
}
|
|
253
|
+
return sorted;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Validate goals
|
|
257
|
+
*/
|
|
258
|
+
export function validateGoals(goals) {
|
|
259
|
+
const errors = [];
|
|
260
|
+
for (const goal of goals) {
|
|
261
|
+
if (!goal.name) {
|
|
262
|
+
errors.push('Goal name is required');
|
|
263
|
+
}
|
|
264
|
+
if (goal.progress && (goal.progress < 0 || goal.progress > 100)) {
|
|
265
|
+
errors.push(`Goal ${goal.name} progress must be between 0 and 100`);
|
|
266
|
+
}
|
|
267
|
+
if (goal.dependencies) {
|
|
268
|
+
const goalNames = new Set(goals.map((g) => g.name));
|
|
269
|
+
for (const dep of goal.dependencies) {
|
|
270
|
+
if (!goalNames.has(dep)) {
|
|
271
|
+
errors.push(`Goal ${goal.name} depends on unknown goal: ${dep}`);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (hasCircularDependencies(goals)) {
|
|
277
|
+
errors.push('Circular dependencies detected in goals');
|
|
278
|
+
}
|
|
279
|
+
return {
|
|
280
|
+
valid: errors.length === 0,
|
|
281
|
+
errors,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
//# sourceMappingURL=goals.js.map
|