farseer-cli 1.0.6 → 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 +2 -1
- 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 -141
- 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 -212
- package/dist/commands/pull.js.map +0 -7
- package/dist/commands/push.js +0 -201
- 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 -164
- 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 -329
- 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 -381
- package/dist/mcp/tools/syncTools.js.map +0 -7
- package/dist/mcp/utils/helpers.js +0 -135
- 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/syncService.js +0 -415
- package/dist/services/syncService.js.map +0 -7
- package/dist/utils/constants.js +0 -46
- package/dist/utils/constants.js.map +0 -7
- package/dist/utils/helpers.js +0 -413
- 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,372 @@
|
|
|
1
|
+
# Farseer Client API Reference
|
|
2
|
+
|
|
3
|
+
## Core API Reference
|
|
4
|
+
|
|
5
|
+
### Getting Variable Data
|
|
6
|
+
|
|
7
|
+
#### `export.exportFormula(config): Promise<Blob>`
|
|
8
|
+
|
|
9
|
+
**This is the primary method for retrieving variable data from Farseer.** Exports variable values using formula expressions.
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
import { ExportRequestFormatEnum } from 'farseer-client';
|
|
13
|
+
import * as aq from 'arquero';
|
|
14
|
+
|
|
15
|
+
// Export variable data as CSV
|
|
16
|
+
const blob = await client.export.exportFormula({
|
|
17
|
+
format: ExportRequestFormatEnum.Csv,
|
|
18
|
+
formula: 'sum("Revenue", "Y2024", "Plan")'
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Parse CSV to Arquero table
|
|
22
|
+
const csvText = await blob.text();
|
|
23
|
+
const data = aq.fromCSV(csvText);
|
|
24
|
+
|
|
25
|
+
data.print();
|
|
26
|
+
// Displays: Revenue data for 2024 Plan version with all dimensions
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
#### Formula Syntax
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
// Basic: sum(variable, dimension1, dimension2, ...)
|
|
33
|
+
formula: 'sum("Revenue", "Y2024", "John")'
|
|
34
|
+
|
|
35
|
+
// With version/scenario
|
|
36
|
+
formula: 'sum("Cost", "Y2024", "Actual")'
|
|
37
|
+
|
|
38
|
+
// Multiple dimensions
|
|
39
|
+
formula: 'sum("Sales", "Y2024", "Q1", "North Region", "Product A")'
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
### Dimension Management
|
|
45
|
+
|
|
46
|
+
#### `getDimensionTable(name: string): Promise<TagRepresentation>`
|
|
47
|
+
|
|
48
|
+
Retrieves dimension table metadata.
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
const productTable = await client.getDimensionTable('Product');
|
|
52
|
+
console.log(productTable.id, productTable.name);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
#### `getVariable(name: string): Promise<TagRepresentation>`
|
|
56
|
+
|
|
57
|
+
Gets variable metadata (ID, dimensionTagIds, formula). **For variable data, use `export.exportFormula()` instead.**
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
// Use when you need variable ID for import metadata
|
|
61
|
+
const revenue = await client.getVariable('Revenue');
|
|
62
|
+
const variableId = revenue.id; // Use in import job metadata
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
#### `data.loadFarseerDimensionTable(name: string, ...dimensions: string[]): Promise<ExportedTableWithConfig>`
|
|
66
|
+
|
|
67
|
+
Loads a dimension table as an Arquero table for analysis/transformation.
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
const productTable = await client.data.loadFarseerDimensionTable('Product');
|
|
71
|
+
|
|
72
|
+
productTable.table.print();
|
|
73
|
+
// Displays table with columns: Name, Description, Category, etc.
|
|
74
|
+
|
|
75
|
+
// Filter with Arquero
|
|
76
|
+
const electronics = productTable.table.filter(d => d?.['Category'][0] === 'Electronics');
|
|
77
|
+
|
|
78
|
+
// Transform
|
|
79
|
+
const enriched = productTable.table.derive({
|
|
80
|
+
FullName: d => `${d.Name} - ${d.Description}`
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
### On-Demand Cell Calculation
|
|
87
|
+
|
|
88
|
+
#### `cells.calculateOnDemandCells(initOverrides?: RequestInit): Promise<void>`
|
|
89
|
+
|
|
90
|
+
Triggers calculation of on-demand cells. Often called at the start of workflows with a timeout wrapper.
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
// Calculate on-demand cells with timeout
|
|
94
|
+
console.log('Starting calculate ondemand cells');
|
|
95
|
+
const ondemandCalculation = client.cells.calculateOnDemandCells();
|
|
96
|
+
const timeout = new Promise(resolve =>
|
|
97
|
+
setTimeout(() => resolve('timeout'), 10 * 60 * 1000) // 10 minutes
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const result = await Promise.race([ondemandCalculation, timeout]);
|
|
101
|
+
if (result === 'timeout') {
|
|
102
|
+
console.log('Ondemand calculation timed out after 10 minutes, continuing...');
|
|
103
|
+
} else {
|
|
104
|
+
console.log('Calculate ondemand cells finished successfully');
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**When to use:** At the beginning of data processing workflows to ensure all calculated fields are up-to-date before exporting or importing data.
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
### File Operations
|
|
113
|
+
|
|
114
|
+
#### `getItemByPath(path: string[]): Promise<FolderItemRepresentation>`
|
|
115
|
+
|
|
116
|
+
Navigates the folder structure and retrieves an item by path.
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
// Get the "Reports" folder in "Finance"
|
|
120
|
+
const item = await client.getItemByPath(['Finance', 'Reports']);
|
|
121
|
+
console.log(item.id);
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
#### `farseerFiles.get(farseerFileId: string, initOverrides?: RequestInit): Promise<Blob>`
|
|
125
|
+
|
|
126
|
+
Downloads a file by its reference.
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
const fileItem = await client.getItemByPath(['Finance', 'data.xlsx']);
|
|
130
|
+
const fileBlob = await client.farseerFiles.get(fileItem.reference);
|
|
131
|
+
|
|
132
|
+
// Convert to buffer
|
|
133
|
+
const buffer = Buffer.from(await fileBlob.arrayBuffer());
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
#### `farseerFiles.create(file: Blob, category: string, folderId?: string, initOverrides?: RequestInit): Promise<FarseerFileRepresentation>`
|
|
137
|
+
|
|
138
|
+
Uploads a file to Farseer.
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
const folder = await client.getItemByPath(['Finance', 'Reports']);
|
|
142
|
+
|
|
143
|
+
await client.farseerFiles.create(
|
|
144
|
+
csvBlob,
|
|
145
|
+
'GENERAL',
|
|
146
|
+
folder.id,
|
|
147
|
+
);
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
#### `folders.listItemsBatch(getItemsFolderRequest: Array<GetItemsFolderRequest>, initOverrides?: RequestInit): Promise<Array<GetItemsFolderResultRepresentation>>`
|
|
151
|
+
|
|
152
|
+
Lists items in folders (batch operation).
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
// List root folder items
|
|
156
|
+
const rootItems = await client.folders.listItemsBatch([{ id: null }]);
|
|
157
|
+
const filesFolder = rootItems[0].items?.find(f => f.name === "Files");
|
|
158
|
+
|
|
159
|
+
// List items in specific folder
|
|
160
|
+
const items = await client.folders.listItemsBatch([{ id: folderId }]);
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
#### `folders.deleteItemsBatch(deleteItemFolderRequest: Array<DeleteItemFolderRequest>, initOverrides?: RequestInit): Promise<void>`
|
|
164
|
+
|
|
165
|
+
Deletes files or folders.
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
const file = await client.getItemByPath(['Finance', 'Temp', 'old.csv']);
|
|
169
|
+
await client.folders.deleteItemsBatch([{ id: file.id }]);
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
### Model Management
|
|
175
|
+
|
|
176
|
+
#### `model.load(modelLoadRequest: ModelLoadRequest, initOverrides?: RequestInit): Promise<ModelLoadResponse>`
|
|
177
|
+
|
|
178
|
+
Loads dimension table structure and data. Primary method for syncing dimension tables.
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
import { ModelTableColumnType } from 'farseer-client';
|
|
182
|
+
|
|
183
|
+
await client.model.load({
|
|
184
|
+
model: {
|
|
185
|
+
tables: [{
|
|
186
|
+
name: 'Product',
|
|
187
|
+
columns: [
|
|
188
|
+
{ name: 'Name', type: ModelTableColumnType.PrimaryKey },
|
|
189
|
+
{ name: 'Description', type: ModelTableColumnType.Description },
|
|
190
|
+
{ name: 'Category', type: ModelTableColumnType.ForeignKey, foreignKeyTableName: 'Category' }
|
|
191
|
+
],
|
|
192
|
+
rows: [
|
|
193
|
+
['Product A', 'Description A', 'Electronics'],
|
|
194
|
+
['Product B', 'Description B', 'Furniture']
|
|
195
|
+
]
|
|
196
|
+
}],
|
|
197
|
+
variables: [],
|
|
198
|
+
dependencies: {
|
|
199
|
+
tables: [],
|
|
200
|
+
members: [],
|
|
201
|
+
variables: []
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
options: {
|
|
205
|
+
clear: false,
|
|
206
|
+
deleteEnabled: {
|
|
207
|
+
rows: false,
|
|
208
|
+
tables: false,
|
|
209
|
+
variables: false,
|
|
210
|
+
columns: false,
|
|
211
|
+
cells: false
|
|
212
|
+
},
|
|
213
|
+
dryRun: false
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
#### Column Types
|
|
219
|
+
|
|
220
|
+
| Type | Purpose | Example |
|
|
221
|
+
|------|---------|---------|
|
|
222
|
+
| `PrimaryKey` | Unique identifier | Product name |
|
|
223
|
+
| `Description` | Display description | Product details |
|
|
224
|
+
| `ForeignKey` | Reference to another table | Category |
|
|
225
|
+
| `Formula` | Formula expression | sum(...) |
|
|
226
|
+
| `Number` | Numerical value | 10 |
|
|
227
|
+
| `Text` | Text value | "Farseer" |
|
|
228
|
+
| `Date` | Date value | 01.01.1970. |
|
|
229
|
+
|
|
230
|
+
#### For other column types check `ModelTableColumnType`.
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
### Arquero Data Operations (client.data.*)
|
|
235
|
+
|
|
236
|
+
#### `data.loadXlsxFile(fileItem: FolderItemRepresentation): Promise<aq.internal.ColumnTable>`
|
|
237
|
+
|
|
238
|
+
Loads an Excel file as Arquero tables (one per worksheet).
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
const fileItem = await client.getItemByPath(['Finance', 'data.xlsx']);
|
|
242
|
+
const sheets = await client.data.loadXlsxFile(fileItem);
|
|
243
|
+
|
|
244
|
+
const sheet1 = sheets['Sheet1'];
|
|
245
|
+
sheet1.print();
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
#### `data.saveToCsvFarseerFile(table: aq.internal.ColumnTable, fileName: string, folderId: number): Promise<void> (+1 overload)`
|
|
249
|
+
|
|
250
|
+
Saves an Arquero table as a CSV file in Farseer.
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
const data = aq.table({ A: [1, 2, 3], B: [4, 5, 6] });
|
|
254
|
+
const folder = await client.getItemByPath(['Finance']);
|
|
255
|
+
|
|
256
|
+
await client.data.saveToCsvFarseerFile(data, 'output.csv', folder.id);
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## Type Reference
|
|
262
|
+
|
|
263
|
+
### TagRepresentation
|
|
264
|
+
|
|
265
|
+
Core data structure representing variables, dimension tables, and dimension members:
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
interface TagRepresentation {
|
|
269
|
+
id: number;
|
|
270
|
+
name: string;
|
|
271
|
+
type: TagType;
|
|
272
|
+
topDownMapping?: string | null;
|
|
273
|
+
internalType?: InternalTagType | null;
|
|
274
|
+
rollupType?: RollupType;
|
|
275
|
+
description: string | null;
|
|
276
|
+
jsonData: object | null;
|
|
277
|
+
expression?: string | null;
|
|
278
|
+
ParentId: number | null;
|
|
279
|
+
connectedTagIds?: Array<number>;
|
|
280
|
+
dimensionTagIds?: Array<number>;
|
|
281
|
+
active: boolean;
|
|
282
|
+
order: number;
|
|
283
|
+
numberFormat?: NumberFormatComponent | null;
|
|
284
|
+
dataType?: VariableDataType;
|
|
285
|
+
numberValidation?: NumberValidationComponent | null;
|
|
286
|
+
defaultValue?: number | null;
|
|
287
|
+
optimizeCalculation?: boolean;
|
|
288
|
+
readonly?: boolean;
|
|
289
|
+
calculateOnDemand?: boolean;
|
|
290
|
+
zConstraint?: boolean;
|
|
291
|
+
usedInTagIds?: Array<number>;
|
|
292
|
+
fromVersionTagId?: number | null;
|
|
293
|
+
toAccountTagId?: number | null;
|
|
294
|
+
toVersionTagId?: number | null;
|
|
295
|
+
autoIncrementTemplate?: string | null;
|
|
296
|
+
canEdit: boolean;
|
|
297
|
+
columns?: Array<DimensionTableColumn>;
|
|
298
|
+
}
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### ImportActions
|
|
302
|
+
|
|
303
|
+
```typescript
|
|
304
|
+
interface ImportActions {
|
|
305
|
+
addRow: (row: ImportJobRowDataCell[]) => Promise<void>;
|
|
306
|
+
addRows: (rows: ImportJobRowDataCell[][]) => Promise<void>;
|
|
307
|
+
flushRows: () => Promise<void>;
|
|
308
|
+
importDimensions: (replaceAll?: boolean) => Promise<void>;
|
|
309
|
+
detectDimensions: () => Promise<void>;
|
|
310
|
+
commit: () => Promise<ImportCommitReport>;
|
|
311
|
+
undoPrevious: () => Promise<void>;
|
|
312
|
+
delete: () => Promise<void>;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
type ImportJobRowDataCell = string | number | null;
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### ModelTableRepresentation
|
|
319
|
+
|
|
320
|
+
```typescript
|
|
321
|
+
interface ModelTableRepresentation {
|
|
322
|
+
name: string;
|
|
323
|
+
autoIncrementTemplate?: string | null;
|
|
324
|
+
columns: Array<ModelTableColumnRepresentation>;
|
|
325
|
+
defaultMember?: string | null;
|
|
326
|
+
folderPath?: Array<string>;
|
|
327
|
+
rows: Array<Array<any>>;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
interface ModelTableColumnRepresentation {
|
|
331
|
+
name?: string;
|
|
332
|
+
type: ModelTableColumnType;
|
|
333
|
+
foreignKeyTableName?: string;
|
|
334
|
+
}
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
---
|
|
338
|
+
|
|
339
|
+
## Quick Reference Card
|
|
340
|
+
|
|
341
|
+
```typescript
|
|
342
|
+
// Initialize
|
|
343
|
+
const client = new FarseerClient();
|
|
344
|
+
await client.initTagMap();
|
|
345
|
+
|
|
346
|
+
// Get variable DATA (not metadata!)
|
|
347
|
+
const blob = await client.export.exportFormula({
|
|
348
|
+
format: ExportRequestFormatEnum.Csv,
|
|
349
|
+
formula: 'sum("Revenue", "Y2024", "Plan")'
|
|
350
|
+
});
|
|
351
|
+
const data = aq.fromCSV(await blob.text());
|
|
352
|
+
|
|
353
|
+
// Get dimension data
|
|
354
|
+
const members = client.getDimensionMembersForTable('Product');
|
|
355
|
+
|
|
356
|
+
// Import job
|
|
357
|
+
const job = await client.createImportJob({ title, columns, labels });
|
|
358
|
+
await job.addRows(data);
|
|
359
|
+
await job.flushRows();
|
|
360
|
+
await job.undoPrevious();
|
|
361
|
+
await job.commit();
|
|
362
|
+
|
|
363
|
+
// Sync dimensions
|
|
364
|
+
await client.model.load({ model: { tables: [...] }, options: {...} });
|
|
365
|
+
|
|
366
|
+
// Calculate on-demand
|
|
367
|
+
await client.cells.calculateOnDemandCells();
|
|
368
|
+
|
|
369
|
+
// File operations
|
|
370
|
+
const file = await client.getItemByPath(['Finance', 'data.xlsx']);
|
|
371
|
+
const blob = await client.farseerFiles.get(file.reference);
|
|
372
|
+
```
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# Arquero Patterns & Best Practices
|
|
2
|
+
|
|
3
|
+
This document covers best practices for working with Arquero in farseer-client applications.
|
|
4
|
+
|
|
5
|
+
## Best Practices
|
|
6
|
+
|
|
7
|
+
### 1. Use export.exportFormula for Variable Data
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
// Good - Using export.exportFormula
|
|
11
|
+
const blob = await client.export.exportFormula({
|
|
12
|
+
format: ExportRequestFormatEnum.Csv,
|
|
13
|
+
formula: 'sum("Revenue", "Y2024")'
|
|
14
|
+
});
|
|
15
|
+
const data = aq.fromCSV(await blob.text());
|
|
16
|
+
|
|
17
|
+
// getVariable() is only for metadata (ID, dimensionTagIds)
|
|
18
|
+
const variable = client.getVariable('Revenue');
|
|
19
|
+
console.log(variable.id); // Just the ID
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### 2. Calculate On-Demand Cells Before Exporting
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
// Good - Calculate first
|
|
26
|
+
await client.cells.calculateOnDemandCells();
|
|
27
|
+
const data = await client.export.exportFormula({...});
|
|
28
|
+
|
|
29
|
+
// Or with timeout
|
|
30
|
+
const calc = client.cells.calculateOnDemandCells();
|
|
31
|
+
const timeout = new Promise(r => setTimeout(r, 10 * 60 * 1000));
|
|
32
|
+
await Promise.race([calc, timeout]);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 3. Use Batch Processing for Large Imports
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
// Good - batch processing for import jobs
|
|
39
|
+
const batchSize = 1000;
|
|
40
|
+
for (let i = 0; i < largeDataset.length; i += batchSize) {
|
|
41
|
+
const batch = largeDataset.slice(i, i + batchSize);
|
|
42
|
+
await importJob.addRows(batch);
|
|
43
|
+
}
|
|
44
|
+
await importJob.flushRows();
|
|
45
|
+
|
|
46
|
+
// Good - batch processing for model.load (dimension sync)
|
|
47
|
+
const allDimensionRows = [...]; // e.g., 10,000 dimension members
|
|
48
|
+
const batchSize = 5000;
|
|
49
|
+
|
|
50
|
+
for (let i = 0; i < allDimensionRows.length; i += batchSize) {
|
|
51
|
+
const batchRows = allDimensionRows.slice(i, i + batchSize);
|
|
52
|
+
|
|
53
|
+
await client.model.load({
|
|
54
|
+
model: {
|
|
55
|
+
tables: [{
|
|
56
|
+
name: 'Product',
|
|
57
|
+
columns: [
|
|
58
|
+
{ name: 'Name', type: ModelTableColumnType.PrimaryKey },
|
|
59
|
+
{ name: 'Description', type: ModelTableColumnType.Description },
|
|
60
|
+
],
|
|
61
|
+
rows: batchRows
|
|
62
|
+
}],
|
|
63
|
+
variables: [],
|
|
64
|
+
dependencies: { tables: [], members: [], variables: [] }
|
|
65
|
+
},
|
|
66
|
+
options: {
|
|
67
|
+
clear: i === 0, // Only clear on first batch
|
|
68
|
+
deleteEnabled: { rows: false, tables: false, variables: false, columns: false, cells: false },
|
|
69
|
+
dryRun: false
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
console.log(`Synced ${Math.min(i + batchSize, allDimensionRows.length)} / ${allDimensionRows.length} members`);
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### 4. Use Labels for Import Job Management
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
// Good - descriptive labels with versioning
|
|
81
|
+
const labels = [
|
|
82
|
+
'auto',
|
|
83
|
+
'sales-import',
|
|
84
|
+
`sales-import_${year}-${month}`,
|
|
85
|
+
'source:erp'
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
// Use labels to find and manage previous imports
|
|
89
|
+
const existing = await client.importJobs.list(labels);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### 5. Clean Up Previous Imports with undoPrevious()
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
// Always call undoPrevious() before commit
|
|
96
|
+
await importJob.flushRows();
|
|
97
|
+
await importJob.undoPrevious(); // Undoes previous commit with same labels
|
|
98
|
+
await importJob.commit();
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### 6. Validate Data Before Import
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
await client.initTagMap();
|
|
105
|
+
|
|
106
|
+
// Load valid dimension members
|
|
107
|
+
const products = client.getDimensionMembersForTable('Product');
|
|
108
|
+
const validProducts = Array.from(products.keys());
|
|
109
|
+
|
|
110
|
+
// Validate data
|
|
111
|
+
const validData = data.filter(row => validProducts.includes(row.product));
|
|
112
|
+
console.log(`${data.length - validData.length} invalid rows removed`);
|
|
113
|
+
|
|
114
|
+
// Import only valid data
|
|
115
|
+
await importJob.addRows(validData);
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## Common Patterns
|
|
121
|
+
|
|
122
|
+
### Pattern 1: Dimension Member Lookup Map
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
async function getDimensionTableMap(
|
|
126
|
+
client: FarseerClient,
|
|
127
|
+
dimensionTableName: string
|
|
128
|
+
): Promise<Map<string, TagRepresentation>> {
|
|
129
|
+
const map = new Map<string, TagRepresentation>();
|
|
130
|
+
const members = await client.getDimensionMembersForTable(dimensionTableName);
|
|
131
|
+
members.forEach(m => map.set(m.name, m));
|
|
132
|
+
return map;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Usage
|
|
136
|
+
const companiesMap = await getDimensionTableMap(client, 'Companies');
|
|
137
|
+
if (!companiesMap.has('Company A')) {
|
|
138
|
+
console.log('Company A does not exist, will be created on import');
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Pattern 2: Tag Navigation
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
await client.initTagMap();
|
|
146
|
+
|
|
147
|
+
// Get dimension name from table ID
|
|
148
|
+
const tableName = Array.from(client.tagMaps.dimensionTableMapByName.values())
|
|
149
|
+
.find(t => t.id === tableTagId)?.name ?? '';
|
|
150
|
+
|
|
151
|
+
// Get dimension names from variable's dimension tag IDs
|
|
152
|
+
const variable = client.getVariable('Revenue');
|
|
153
|
+
const dimensionNames = variable.dimensionTagIds?.map(dimId =>
|
|
154
|
+
client.tagMaps?.mapById.get(dimId)?.name
|
|
155
|
+
).filter(Boolean);
|
|
156
|
+
|
|
157
|
+
console.log(`Revenue has dimensions: ${dimensionNames.join(', ')}`);
|
|
158
|
+
```
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# Farseer CLI Guide
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The Farseer CLI syncs scripts and apps between your local filesystem and Farseer instances. It manages authentication, file synchronization, app configuration, and local execution.
|
|
6
|
+
|
|
7
|
+
## Getting Started
|
|
8
|
+
|
|
9
|
+
### 1. Login
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# Browser login (OAuth) - recommended, gives access to all tenants you have permissions for
|
|
13
|
+
farseer login
|
|
14
|
+
|
|
15
|
+
# API key login (per-tenant)
|
|
16
|
+
farseer login --api-key
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### 2. Checkout a Tenant
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# First time: specify organisation and tenant
|
|
23
|
+
farseer checkout myorg mytenant
|
|
24
|
+
|
|
25
|
+
# The CLI remembers the org-tenant mapping, so next time:
|
|
26
|
+
farseer checkout mytenant
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Checkout sets a default tenant so you don't need to specify it in every command. It also verifies auth and pulls the latest files/apps.
|
|
30
|
+
|
|
31
|
+
### 3. Pull Files and Apps
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# Pull scripts (.ts/.js files) and app configs
|
|
35
|
+
farseer pull
|
|
36
|
+
|
|
37
|
+
# Pull all files (not just scripts)
|
|
38
|
+
farseer pull --all
|
|
39
|
+
|
|
40
|
+
# Force overwrite local changes
|
|
41
|
+
farseer pull --force
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 4. Install Dependencies
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
farseer install
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
This runs `npm install` in the tenant directory (`farseer-apps/<tenant>/`).
|
|
51
|
+
|
|
52
|
+
### 5. Work with Files
|
|
53
|
+
|
|
54
|
+
Edit scripts in `farseer-apps/<tenant>/files/Scripts/`. Check status and push:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# See what changed
|
|
58
|
+
farseer status
|
|
59
|
+
|
|
60
|
+
# See diffs
|
|
61
|
+
farseer diff
|
|
62
|
+
|
|
63
|
+
# Push changes to remote
|
|
64
|
+
farseer push
|
|
65
|
+
|
|
66
|
+
# Push without confirmation
|
|
67
|
+
farseer push -y
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## App Management
|
|
71
|
+
|
|
72
|
+
### Creating an App
|
|
73
|
+
|
|
74
|
+
1. Write your script in `farseer-apps/<tenant>/files/Scripts/myScript.ts`
|
|
75
|
+
2. Push: `farseer push`
|
|
76
|
+
3. Create: `farseer app create "My App"`
|
|
77
|
+
4. Configure: `farseer app configure "My App" --entrypoint myScript.ts --scripts myScript.ts`
|
|
78
|
+
|
|
79
|
+
### Running Apps
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# Run with default arguments
|
|
83
|
+
farseer run "My App"
|
|
84
|
+
|
|
85
|
+
# Override arguments
|
|
86
|
+
farseer run "My App" --arg "Year=2026" --arg "Version=Plan"
|
|
87
|
+
|
|
88
|
+
# Run a script directly (without app wrapper)
|
|
89
|
+
farseer run-script myScript.ts
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Listing and Inspecting Apps
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
farseer app list
|
|
96
|
+
farseer app list --details
|
|
97
|
+
farseer app show "My App"
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Model Inspection
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
# Show model overview (dimensions + variables summary)
|
|
104
|
+
farseer model
|
|
105
|
+
|
|
106
|
+
# List all variables
|
|
107
|
+
farseer variables list
|
|
108
|
+
|
|
109
|
+
# Variable details
|
|
110
|
+
farseer variable details "Revenue"
|
|
111
|
+
|
|
112
|
+
# Export variable data
|
|
113
|
+
farseer variable export "Revenue" --format csv --output revenue.csv
|
|
114
|
+
|
|
115
|
+
# List dimension tables
|
|
116
|
+
farseer dimensions list
|
|
117
|
+
|
|
118
|
+
# Dimension details with sample members
|
|
119
|
+
farseer dimension details "Product" --members 20
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Tenant Resolution
|
|
123
|
+
|
|
124
|
+
Most commands accept optional `[org] [tenant]` arguments. The CLI resolves tenant in this order:
|
|
125
|
+
|
|
126
|
+
1. **Explicit args**: `farseer pull myorg mytenant`
|
|
127
|
+
2. **Tenant with saved org mapping**: `farseer pull mytenant` (org remembered from checkout)
|
|
128
|
+
3. **Checked-out tenant**: `farseer pull` (uses current checkout)
|
|
129
|
+
|
|
130
|
+
## Configuration
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
# Set API key for a tenant
|
|
134
|
+
farseer config set mytenant --api-key YOUR_KEY
|
|
135
|
+
|
|
136
|
+
# Set API key with org
|
|
137
|
+
farseer config set mytenant --api-key YOUR_KEY --org myorg
|
|
138
|
+
|
|
139
|
+
# List configured tenants
|
|
140
|
+
farseer config list
|
|
141
|
+
|
|
142
|
+
# Test connection
|
|
143
|
+
farseer config test mytenant
|
|
144
|
+
|
|
145
|
+
# Show credentials
|
|
146
|
+
farseer config show mytenant
|
|
147
|
+
|
|
148
|
+
# Remove credentials
|
|
149
|
+
farseer config remove mytenant
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## MCP Server
|
|
153
|
+
|
|
154
|
+
Start the MCP server for AI assistant integration (Claude, Cursor, etc.):
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
farseer mcp-server
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
This exposes all CLI functionality as MCP tools that AI agents can use.
|