farseer-cli 1.0.5 → 1.0.8
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/docs/api-reference.md +372 -0
- package/docs/arquero-patterns.md +158 -0
- package/docs/cli-guide.md +160 -0
- package/docs/how-farseer-works.md +113 -0
- package/docs/import-workflows.md +306 -0
- package/docs/model-export.md +95 -0
- package/docs/new-app-template.md +240 -0
- package/docs/query-formulas.md +97 -0
- package/docs/troubleshooting.md +140 -0
- package/package.json +3 -3
- package/dist/commands/app.js +0 -349
- package/dist/commands/app.js.map +0 -7
- package/dist/commands/apps.js +0 -111
- package/dist/commands/apps.js.map +0 -7
- package/dist/commands/checkout.js +0 -166
- package/dist/commands/checkout.js.map +0 -7
- package/dist/commands/config.js +0 -139
- package/dist/commands/config.js.map +0 -7
- package/dist/commands/diff.js +0 -183
- package/dist/commands/diff.js.map +0 -7
- package/dist/commands/dimensions.js +0 -145
- package/dist/commands/dimensions.js.map +0 -7
- package/dist/commands/files.js +0 -99
- package/dist/commands/files.js.map +0 -7
- package/dist/commands/install.js +0 -79
- package/dist/commands/install.js.map +0 -7
- package/dist/commands/list.js +0 -92
- package/dist/commands/list.js.map +0 -7
- package/dist/commands/login.js +0 -134
- package/dist/commands/login.js.map +0 -7
- package/dist/commands/logout.js +0 -59
- package/dist/commands/logout.js.map +0 -7
- package/dist/commands/mcp-server.js +0 -41
- package/dist/commands/mcp-server.js.map +0 -7
- package/dist/commands/model.js +0 -189
- package/dist/commands/model.js.map +0 -7
- package/dist/commands/pull.js +0 -287
- package/dist/commands/pull.js.map +0 -7
- package/dist/commands/push.js +0 -251
- package/dist/commands/push.js.map +0 -7
- package/dist/commands/run.js +0 -288
- package/dist/commands/run.js.map +0 -7
- package/dist/commands/status.js +0 -145
- package/dist/commands/status.js.map +0 -7
- package/dist/commands/variables.js +0 -176
- package/dist/commands/variables.js.map +0 -7
- package/dist/commands/whoami.js +0 -63
- package/dist/commands/whoami.js.map +0 -7
- package/dist/index.js +0 -153
- package/dist/index.js.map +0 -7
- package/dist/mcp/index.js +0 -35
- package/dist/mcp/index.js.map +0 -7
- package/dist/mcp/prompts/workflows.js +0 -437
- package/dist/mcp/prompts/workflows.js.map +0 -7
- package/dist/mcp/resources/documentation.js +0 -167
- package/dist/mcp/resources/documentation.js.map +0 -7
- package/dist/mcp/server.js +0 -52
- package/dist/mcp/server.js.map +0 -7
- package/dist/mcp/tools/appTools.js +0 -377
- package/dist/mcp/tools/appTools.js.map +0 -7
- package/dist/mcp/tools/authTools.js +0 -158
- package/dist/mcp/tools/authTools.js.map +0 -7
- package/dist/mcp/tools/dataTools.js +0 -366
- package/dist/mcp/tools/dataTools.js.map +0 -7
- package/dist/mcp/tools/modelTools.js +0 -331
- package/dist/mcp/tools/modelTools.js.map +0 -7
- package/dist/mcp/tools/runTools.js +0 -231
- package/dist/mcp/tools/runTools.js.map +0 -7
- package/dist/mcp/tools/syncTools.js +0 -382
- package/dist/mcp/tools/syncTools.js.map +0 -7
- package/dist/mcp/utils/helpers.js +0 -113
- package/dist/mcp/utils/helpers.js.map +0 -7
- package/dist/services/appSyncService.js +0 -399
- package/dist/services/appSyncService.js.map +0 -7
- package/dist/services/configService.js +0 -196
- package/dist/services/configService.js.map +0 -7
- package/dist/services/farseerApi.js +0 -426
- package/dist/services/farseerApi.js.map +0 -7
- package/dist/services/farseerFactory.js +0 -231
- package/dist/services/farseerFactory.js.map +0 -7
- package/dist/services/farseerService.js +0 -614
- package/dist/services/farseerService.js.map +0 -7
- package/dist/services/gitService.js +0 -134
- package/dist/services/gitService.js.map +0 -7
- package/dist/services/syncService.js +0 -415
- package/dist/services/syncService.js.map +0 -7
- package/dist/utils/constants.js +0 -49
- package/dist/utils/constants.js.map +0 -7
- package/dist/utils/helpers.js +0 -433
- package/dist/utils/helpers.js.map +0 -7
- package/dist/utils/logger.js +0 -76
- package/dist/utils/logger.js.map +0 -7
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# How Farseer Works
|
|
2
|
+
|
|
3
|
+
## Core Concepts
|
|
4
|
+
|
|
5
|
+
Farseer is a financial planning and data management platform. It organizes data using **dimensions**, **variables**, and **formulas**.
|
|
6
|
+
|
|
7
|
+
### Dimensions
|
|
8
|
+
|
|
9
|
+
Dimensions are categories that structure your data. Think of them as the axes of a multi-dimensional spreadsheet.
|
|
10
|
+
|
|
11
|
+
Common dimensions:
|
|
12
|
+
- **Time**: Months (M1-M12), Years (Y2024, Y2025), Quarters
|
|
13
|
+
- **Versions**: Plan, Actual, Forecast, Budget
|
|
14
|
+
- **Products**: Product A, Product B, ...
|
|
15
|
+
- **Regions**: North, South, East, West
|
|
16
|
+
- **Entities**: Company divisions, cost centers
|
|
17
|
+
|
|
18
|
+
Each dimension is stored as a **Dimension Table** with members (rows). Tables can have multiple columns:
|
|
19
|
+
- **Primary Key**: The unique member name
|
|
20
|
+
- **Description**: Display label
|
|
21
|
+
- **Foreign Key**: Reference to another table (creates hierarchy)
|
|
22
|
+
|
|
23
|
+
### Variables
|
|
24
|
+
|
|
25
|
+
Variables store numeric values at the intersection of dimensions. For example:
|
|
26
|
+
- **Revenue** might span: Products x Months x Years x Versions
|
|
27
|
+
- A single cell: Revenue for "Product A" in "January 2025" for "Plan" = 10,000
|
|
28
|
+
|
|
29
|
+
Variables have properties:
|
|
30
|
+
- **Dimensions**: Which dimension tables it spans
|
|
31
|
+
- **Roll-up type**: How values aggregate (SUM, AVERAGE, LAST, etc.)
|
|
32
|
+
- **Data type**: NUMBER, PERCENTAGE, TEXT
|
|
33
|
+
- **Formula**: Optional calculation expression
|
|
34
|
+
|
|
35
|
+
### Formulas
|
|
36
|
+
|
|
37
|
+
Some variables are calculated from other variables using formulas:
|
|
38
|
+
- `Profit = Revenue - Costs`
|
|
39
|
+
- `Margin = Profit / Revenue * 100`
|
|
40
|
+
|
|
41
|
+
Formula variables are read-only - their values are computed automatically.
|
|
42
|
+
|
|
43
|
+
### Versions
|
|
44
|
+
|
|
45
|
+
Versions represent different scenarios of data:
|
|
46
|
+
- **Actual**: Real historical data
|
|
47
|
+
- **Plan**: Planned/budgeted figures
|
|
48
|
+
- **Forecast**: Updated projections
|
|
49
|
+
|
|
50
|
+
You can import data into specific versions and compare across versions.
|
|
51
|
+
|
|
52
|
+
## Data Flow
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
External Data Sources (APIs, CSV, Excel)
|
|
56
|
+
↓
|
|
57
|
+
Farseer App (TypeScript script)
|
|
58
|
+
↓
|
|
59
|
+
Import Job (batch data upload)
|
|
60
|
+
↓
|
|
61
|
+
Farseer Variables (stored values)
|
|
62
|
+
↓
|
|
63
|
+
Formulas (auto-calculated)
|
|
64
|
+
↓
|
|
65
|
+
Sheets/Dashboards (visualization)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Sheets
|
|
69
|
+
|
|
70
|
+
Sheets are spreadsheet-like views in Farseer that display variable data organized by dimensions. They have:
|
|
71
|
+
- **Columns**: Defined by dimension tables or variables
|
|
72
|
+
- **Rows**: Data entries with dimension member values
|
|
73
|
+
- **Cells**: Values at row-column intersections
|
|
74
|
+
|
|
75
|
+
Sheets can be read and manipulated via the `client.sheets` API.
|
|
76
|
+
|
|
77
|
+
## Working with farseer-client
|
|
78
|
+
|
|
79
|
+
The `farseer-client` library provides a TypeScript API to interact with Farseer:
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import * as farseer from 'farseer-client';
|
|
83
|
+
|
|
84
|
+
const client = new farseer.FarseerClient();
|
|
85
|
+
await client.initTagMap(); // Load metadata
|
|
86
|
+
|
|
87
|
+
// Read data
|
|
88
|
+
const blob = await client.export.exportFormula({
|
|
89
|
+
format: farseer.ExportRequestFormatEnum.Csv,
|
|
90
|
+
formula: 'sum("Revenue", "Y2025", "Plan")',
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Write data
|
|
94
|
+
const job = await client.createImportJob({
|
|
95
|
+
title: 'Import Revenue',
|
|
96
|
+
columns: [...],
|
|
97
|
+
labels: ['auto'],
|
|
98
|
+
});
|
|
99
|
+
await job.addRows([...]);
|
|
100
|
+
await job.commit();
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Tag System
|
|
104
|
+
|
|
105
|
+
Internally, Farseer uses a **tag system**. Everything is a tag with an ID:
|
|
106
|
+
- Dimension tables are tags
|
|
107
|
+
- Dimension members are tags
|
|
108
|
+
- Variables are tags
|
|
109
|
+
|
|
110
|
+
The `TagMap` (loaded via `initTagMap()`) provides lookups:
|
|
111
|
+
- `tagMap.variableMapByName` - variables by name
|
|
112
|
+
- `tagMap.dimensionTableMapByName` - dimension tables by name
|
|
113
|
+
- `tagMap.mapById` - any tag by ID
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
# Import Workflows
|
|
2
|
+
|
|
3
|
+
This document covers import job operations and real-world workflow patterns.
|
|
4
|
+
|
|
5
|
+
## Import Job Operations
|
|
6
|
+
|
|
7
|
+
Import jobs are the primary mechanism for loading data into Farseer variables.
|
|
8
|
+
|
|
9
|
+
### `createImportJob(config: { title: string, metadata: farseer.ImportJobMetadata, description?: string, labels?: string[] }): Promise<ImportActions>`
|
|
10
|
+
|
|
11
|
+
Creates an import job and returns an `ImportActions` object with methods for adding data.
|
|
12
|
+
|
|
13
|
+
**Two configuration styles:**
|
|
14
|
+
|
|
15
|
+
**Style 1: Simple Columns (Newer, Recommended)**
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
const importJob = await client.createImportJob({
|
|
19
|
+
title: 'Rebooked OPEX KEYS ${year} ${version}',
|
|
20
|
+
description: 'Rebooked OPEX KEYS',
|
|
21
|
+
columns: [
|
|
22
|
+
{ type: 'DIMENSION_TABLE', dimensionTableName: 'OPEX KEY' },
|
|
23
|
+
{ type: 'DIMENSION_TABLE', dimensionTableName: 'Entities' },
|
|
24
|
+
{ type: 'DIMENSION_TABLE', dimensionTableName: 'Years' },
|
|
25
|
+
{ type: 'DIMENSION_TABLE', dimensionTableName: 'Months' },
|
|
26
|
+
{ type: 'DIMENSION_TABLE', dimensionTableName: 'Versions' },
|
|
27
|
+
{ type: 'VARIABLE', variableName: 'OPEX PLAN Rebooked' },
|
|
28
|
+
],
|
|
29
|
+
labels: ['opex plan rebooked', year, version]
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**Style 2: Manual Metadata (Older, More Control)**
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
async function getImportMetadata(client: FarseerClient) {
|
|
37
|
+
// DIMENSIONS
|
|
38
|
+
const VersionsTable = await client.getDimensionTable('Versions');
|
|
39
|
+
const YearsTable = await client.getDimensionTable('Years');
|
|
40
|
+
const MonthsTable = await client.getDimensionTable('Months');
|
|
41
|
+
const EntitiesTable = await client.getDimensionTable('Entities');
|
|
42
|
+
const OpexKeyTable = await client.getDimensionTable('OPEX KEY');
|
|
43
|
+
|
|
44
|
+
// VARIABLES
|
|
45
|
+
const OpexPlanRebookedVar = await client.getVariable('OPEX PLAN Rebooked');
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
handleMissingTags: HandleMissingTags.SKIP_ROW,
|
|
49
|
+
importZeros: true,
|
|
50
|
+
overwriteCells: true,
|
|
51
|
+
columnMetas: [
|
|
52
|
+
{
|
|
53
|
+
name: 'Versions',
|
|
54
|
+
dataContext: farseer.ColumnMetaDataContext.IDENTIFIER,
|
|
55
|
+
tableTagId: VersionsTable.id,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: 'Years',
|
|
59
|
+
dataContext: farseer.ColumnMetaDataContext.IDENTIFIER,
|
|
60
|
+
tableTagId: YearsTable.id,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: 'Months',
|
|
64
|
+
dataContext: farseer.ColumnMetaDataContext.IDENTIFIER,
|
|
65
|
+
tableTagId: MonthsTable.id,
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: 'Entities',
|
|
69
|
+
dataContext: farseer.ColumnMetaDataContext.IDENTIFIER,
|
|
70
|
+
tableTagId: EntitiesTable.id,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: 'OPEX KEY',
|
|
74
|
+
dataContext: farseer.ColumnMetaDataContext.IDENTIFIER,
|
|
75
|
+
tableTagId: OpexKeyTable.id,
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: 'OPEX PLAN Rebooked',
|
|
79
|
+
dataContext: farseer.ColumnMetaDataContext.VALUES,
|
|
80
|
+
applyTagsIds: [OpexPlanRebookedVar.id],
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const importJob = await client.createImportJob({
|
|
87
|
+
title: 'Rebook opex keys',
|
|
88
|
+
description: 'Rebook opex keys',
|
|
89
|
+
metadata: await getImportMetadata(client),
|
|
90
|
+
labels: ['auto', 'opex keys rebook']
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### ImportActions Interface
|
|
95
|
+
|
|
96
|
+
The object returned by `createImportJob()` provides these methods:
|
|
97
|
+
|
|
98
|
+
**`addRow(row: ImportJobRowDataCell[]): Promise<void>`**
|
|
99
|
+
Adds a single row to the import job.
|
|
100
|
+
|
|
101
|
+
**`addRows(rows: ImportJobRowDataCell[][]): Promise<void>`**
|
|
102
|
+
Adds multiple rows. Auto-batches at 500 rows (configurable via `FarseerClient.IMPORT_JOB_ROW_BATCH_SIZE`).
|
|
103
|
+
|
|
104
|
+
**`flushRows(): Promise<void>`**
|
|
105
|
+
Flushes any remaining rows in the buffer. Always call before `commit()`.
|
|
106
|
+
|
|
107
|
+
**`undoPrevious(): Promise<void>`**
|
|
108
|
+
Undoes the previous commit of this import job (based on matching labels).
|
|
109
|
+
|
|
110
|
+
**`commit(): Promise<ImportCommitReport>`**
|
|
111
|
+
Commits the import job and processes the data. Returns a report with success/failure details.
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## Real-World Workflows
|
|
116
|
+
|
|
117
|
+
### Workflow 1: Export -> Transform -> Import
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import * as aq from 'arquero';
|
|
121
|
+
import { op } from 'arquero';
|
|
122
|
+
import { ExportRequestFormatEnum } from 'farseer-client';
|
|
123
|
+
|
|
124
|
+
async function exportTransformImport(client: FarseerClient, year: string) {
|
|
125
|
+
// 1. Calculate on-demand cells first
|
|
126
|
+
console.log('Calculating on-demand cells...');
|
|
127
|
+
const calc = client.cells.calculateOnDemandCells();
|
|
128
|
+
const timeout = new Promise(r => setTimeout(r, 10 * 60 * 1000));
|
|
129
|
+
await Promise.race([calc, timeout]);
|
|
130
|
+
|
|
131
|
+
// 2. Export variable data
|
|
132
|
+
const blob = await client.export.exportFormula({
|
|
133
|
+
format: ExportRequestFormatEnum.Csv,
|
|
134
|
+
formula: `sum("Revenue", "Y${year}", "Actual")`
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// 3. Parse and transform with Arquero
|
|
138
|
+
const data = aq.fromCSV(await blob.text());
|
|
139
|
+
const transformed = data
|
|
140
|
+
.filter(d => d?.['Amount'] > 0)
|
|
141
|
+
.derive({
|
|
142
|
+
Forecast: d => d?.['Amount'] * 1.05, // 5% growth
|
|
143
|
+
Year: aq.escape((d: any) => {
|
|
144
|
+
return `Y${parseInt(year) + 1}`
|
|
145
|
+
})
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// 4. Import transformed data
|
|
149
|
+
const importJob = await client.createImportJob({
|
|
150
|
+
title: `Forecast Import ${year}`,
|
|
151
|
+
columns: [
|
|
152
|
+
{ type: 'DIMENSION_TABLE', dimensionTableName: 'Product' },
|
|
153
|
+
{ type: 'DIMENSION_TABLE', dimensionTableName: 'Years' },
|
|
154
|
+
{ type: 'VARIABLE', variableName: 'Revenue' },
|
|
155
|
+
],
|
|
156
|
+
labels: ['auto', 'forecast', `forecast_${year}`]
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
const rows = transformed.objects().map(r => [
|
|
160
|
+
r['Product'],
|
|
161
|
+
r['Year'],
|
|
162
|
+
r['Forecast']
|
|
163
|
+
]);
|
|
164
|
+
|
|
165
|
+
await importJob.addRows(rows);
|
|
166
|
+
await importJob.flushRows();
|
|
167
|
+
await importJob.undoPrevious();
|
|
168
|
+
await importJob.commit();
|
|
169
|
+
|
|
170
|
+
console.log('Import completed successfully');
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Workflow 2: Sync Dimensions from External Source
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
async function syncDimensionsFromDB(client: FarseerClient, sqlData: any[]) {
|
|
178
|
+
// Load existing dimension data
|
|
179
|
+
const existing = await client.data.loadFarseerDimensionTable('Product');
|
|
180
|
+
const existingMap = new Map();
|
|
181
|
+
existing.table.objects().forEach(row => existingMap.set(row.Name, row));
|
|
182
|
+
|
|
183
|
+
// Prepare new/updated data
|
|
184
|
+
const rows = sqlData.map(item => [
|
|
185
|
+
item.ProductCode,
|
|
186
|
+
item.ProductName,
|
|
187
|
+
item.Category
|
|
188
|
+
]);
|
|
189
|
+
|
|
190
|
+
// Sync using model.load
|
|
191
|
+
await client.model.load({
|
|
192
|
+
model: {
|
|
193
|
+
tables: [{
|
|
194
|
+
name: 'Product',
|
|
195
|
+
columns: [
|
|
196
|
+
{ name: 'Name', type: ModelTableColumnType.PrimaryKey },
|
|
197
|
+
{ name: 'Description', type: ModelTableColumnType.Description },
|
|
198
|
+
{ name: 'Category', type: ModelTableColumnType.ForeignKey, foreignKeyTableName: 'Category' }
|
|
199
|
+
],
|
|
200
|
+
rows
|
|
201
|
+
}],
|
|
202
|
+
variables: [],
|
|
203
|
+
dependencies: { tables: [], members: [], variables: [] }
|
|
204
|
+
},
|
|
205
|
+
options: {
|
|
206
|
+
clear: false,
|
|
207
|
+
deleteEnabled: { rows: false, tables: false, variables: false, columns: false, cells: false },
|
|
208
|
+
dryRun: false
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
console.log(`Synced ${rows.length} products`);
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Workflow 3: File-Based Import with Validation
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
async function importFromExcel(client: FarseerClient, filePath: string[]) {
|
|
220
|
+
// 1. Load Excel file
|
|
221
|
+
const fileItem = await client.getItemByPath(filePath);
|
|
222
|
+
const sheets = await client.data.loadXlsxFile(fileItem);
|
|
223
|
+
const data = sheets['Data'];
|
|
224
|
+
|
|
225
|
+
// 2. Validate against dimension members
|
|
226
|
+
const products = client.getDimensionMembersForTable('Product');
|
|
227
|
+
const productNames = Array.from(products.keys());
|
|
228
|
+
|
|
229
|
+
const validated = data.filter(d => productNames.includes(d.Product));
|
|
230
|
+
const invalid = data.numRows() - validated.numRows();
|
|
231
|
+
|
|
232
|
+
if (invalid > 0) {
|
|
233
|
+
console.log(`Warning: ${invalid} rows with invalid products were skipped`);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// 3. Import validated data
|
|
237
|
+
const importJob = await client.createImportJob({
|
|
238
|
+
title: `Excel import`,
|
|
239
|
+
columns: [
|
|
240
|
+
{ type: 'DIMENSION_TABLE', dimensionTableName: 'Product' },
|
|
241
|
+
{ type: 'DIMENSION_TABLE', dimensionTableName: 'Years' },
|
|
242
|
+
{ type: 'VARIABLE', variableName: 'Revenue' },
|
|
243
|
+
],
|
|
244
|
+
labels: ['auto', 'excel import']
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
const rows = data.objects().map(r => [
|
|
248
|
+
r['Product'],
|
|
249
|
+
r['Year'],
|
|
250
|
+
r['Forecast']
|
|
251
|
+
]);
|
|
252
|
+
|
|
253
|
+
await importJob.addRows(rows);
|
|
254
|
+
await importJob.flushRows();
|
|
255
|
+
await importJob.undoPrevious();
|
|
256
|
+
await importJob.commit();
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## Complete Example: Export -> Transform -> Import
|
|
263
|
+
|
|
264
|
+
```typescript
|
|
265
|
+
import * as aq from 'arquero';
|
|
266
|
+
import { op } from 'arquero';
|
|
267
|
+
|
|
268
|
+
// 1. Export variable data
|
|
269
|
+
const blob = await client.export.exportFormula({
|
|
270
|
+
format: ExportRequestFormatEnum.Csv,
|
|
271
|
+
formula: 'sum("Revenue", "Y2024", "Actual")'
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
// 2. Parse to Arquero
|
|
275
|
+
const data = aq.fromCSV(await blob.text());
|
|
276
|
+
|
|
277
|
+
// 3. Transform
|
|
278
|
+
const transformed = data
|
|
279
|
+
.filter(d => d?.['value'] > 0)
|
|
280
|
+
.derive({
|
|
281
|
+
AdjustedValue: d => d?.['value'] * 1.1 // 10% increase
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
// 4. Import back to Farseer
|
|
285
|
+
const importJob = await client.createImportJob({
|
|
286
|
+
title: 'Adjusted Revenue Import',
|
|
287
|
+
columns: [
|
|
288
|
+
{ type: 'DIMENSION_TABLE', dimensionTableName: 'Years' },
|
|
289
|
+
{ type: 'DIMENSION_TABLE', dimensionTableName: 'Months' },
|
|
290
|
+
{ type: 'DIMENSION_TABLE', dimensionTableName: 'Versions' },
|
|
291
|
+
{ type: 'VARIABLE', variableName: 'Revenue' },
|
|
292
|
+
],
|
|
293
|
+
labels: ['auto', 'revenue-adjustment', 'Y2024', 'Actual']
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
const rows = transformed.objects().map(row => [
|
|
297
|
+
row['Years'],
|
|
298
|
+
row['Months'],
|
|
299
|
+
row['Versions'],
|
|
300
|
+
row['AdjustedValue'],
|
|
301
|
+
]);
|
|
302
|
+
|
|
303
|
+
await importJob.addRows(rows);
|
|
304
|
+
await importJob.flushRows();
|
|
305
|
+
await importJob.commit();
|
|
306
|
+
```
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Model Export Guide
|
|
2
|
+
|
|
3
|
+
## Exporting the Full Model
|
|
4
|
+
|
|
5
|
+
The model export gives you a complete picture of a tenant's data structure.
|
|
6
|
+
|
|
7
|
+
### Via CLI
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
farseer model # Overview summary
|
|
11
|
+
farseer model --variables # List all variables
|
|
12
|
+
farseer model --tables # List all dimension tables
|
|
13
|
+
farseer model --variable "Revenue" # Show dimensions for a variable
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Via MCP
|
|
17
|
+
|
|
18
|
+
Use `farseer_export_model` to get the full model as JSON.
|
|
19
|
+
|
|
20
|
+
### Via farseer-client
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
await client.initTagMap();
|
|
24
|
+
const tagMap = client.getTagMap();
|
|
25
|
+
|
|
26
|
+
// All dimension tables
|
|
27
|
+
const tables = Array.from(tagMap.dimensionTableMapByName.values());
|
|
28
|
+
for (const table of tables) {
|
|
29
|
+
console.log(`Table: ${table.name} (ID: ${table.id})`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// All variables
|
|
33
|
+
const variables = Array.from(tagMap.variableMapByName.values());
|
|
34
|
+
for (const v of variables) {
|
|
35
|
+
console.log(`Variable: ${v.name}`);
|
|
36
|
+
console.log(` Dimensions: ${v.dimensionTagIds?.length || 0}`);
|
|
37
|
+
console.log(` Roll-up: ${v.rollupType}`);
|
|
38
|
+
console.log(` Formula: ${v.expression || 'none'}`);
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Model Structure
|
|
43
|
+
|
|
44
|
+
The model consists of:
|
|
45
|
+
|
|
46
|
+
### Dimension Tables
|
|
47
|
+
|
|
48
|
+
Each table has:
|
|
49
|
+
- **Name**: e.g., "Product", "Years", "Months"
|
|
50
|
+
- **Columns**: PrimaryKey, Description, ForeignKey, Number, Text, etc.
|
|
51
|
+
- **Members**: Rows in the table (e.g., "Product A", "Product B")
|
|
52
|
+
- **Hierarchy**: Tables can reference other tables via ForeignKey columns
|
|
53
|
+
|
|
54
|
+
### Variables
|
|
55
|
+
|
|
56
|
+
Each variable has:
|
|
57
|
+
- **Name**: e.g., "Revenue", "Costs"
|
|
58
|
+
- **Dimensions**: Which dimension tables it spans
|
|
59
|
+
- **Roll-up type**: SUM, AVERAGE, LAST, FORMULA, etc.
|
|
60
|
+
- **Formula**: Expression if it's a calculated variable
|
|
61
|
+
- **Data type**: NUMBER, PERCENTAGE, TEXT
|
|
62
|
+
|
|
63
|
+
### Relationships
|
|
64
|
+
|
|
65
|
+
- Variables reference dimension tables via `dimensionTagIds`
|
|
66
|
+
- Dimension tables reference other tables via ForeignKey columns
|
|
67
|
+
- This creates a hierarchical data model
|
|
68
|
+
|
|
69
|
+
## Syncing Dimensions
|
|
70
|
+
|
|
71
|
+
To add/update dimension table members:
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
await client.model.load({
|
|
75
|
+
model: {
|
|
76
|
+
tables: [{
|
|
77
|
+
name: 'Product',
|
|
78
|
+
columns: [
|
|
79
|
+
{ name: 'Name', type: ModelTableColumnType.PrimaryKey },
|
|
80
|
+
{ name: 'Category', type: ModelTableColumnType.ForeignKey, foreignKeyTableName: 'Category' },
|
|
81
|
+
],
|
|
82
|
+
rows: [
|
|
83
|
+
['New Product', 'Electronics'],
|
|
84
|
+
],
|
|
85
|
+
}],
|
|
86
|
+
variables: [],
|
|
87
|
+
dependencies: { tables: [], members: [], variables: [] },
|
|
88
|
+
},
|
|
89
|
+
options: {
|
|
90
|
+
clear: false,
|
|
91
|
+
deleteEnabled: { rows: false, tables: false, variables: false, columns: false, cells: false },
|
|
92
|
+
dryRun: false,
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
```
|