farseer-cli 1.18.0 → 1.20.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/README.md +33 -10
- package/dist/commands/app.js +42 -3
- package/dist/commands/app.js.map +1 -2
- package/dist/commands/apps.js.map +0 -1
- package/dist/commands/cells.js +120 -85
- package/dist/commands/cells.js.map +1 -2
- package/dist/commands/code.js.map +0 -1
- package/dist/commands/config.js.map +0 -1
- package/dist/commands/dashboards.js +246 -12
- package/dist/commands/dashboards.js.map +1 -2
- package/dist/commands/diff.js.map +0 -1
- package/dist/commands/dimensions.js +52 -27
- package/dist/commands/dimensions.js.map +1 -2
- package/dist/commands/docs.js +82 -0
- package/dist/commands/docs.js.map +6 -0
- package/dist/commands/files.js +49 -0
- package/dist/commands/files.js.map +2 -3
- package/dist/commands/folders.js +76 -0
- package/dist/commands/folders.js.map +6 -0
- package/dist/commands/formula.js +38 -30
- package/dist/commands/formula.js.map +1 -2
- package/dist/commands/install.js +32 -30
- package/dist/commands/install.js.map +2 -3
- package/dist/commands/list.js.map +0 -1
- package/dist/commands/login.js +3 -3
- package/dist/commands/login.js.map +1 -2
- package/dist/commands/logout.js.map +0 -1
- package/dist/commands/mcp-server.js.map +0 -1
- package/dist/commands/model.js +30 -5
- package/dist/commands/model.js.map +2 -3
- package/dist/commands/pipeline.js.map +0 -1
- package/dist/commands/pull.js +1 -1
- package/dist/commands/pull.js.map +1 -2
- package/dist/commands/push.js +6 -4
- package/dist/commands/push.js.map +1 -2
- package/dist/commands/refresh.js.map +0 -1
- package/dist/commands/run.js.map +0 -1
- package/dist/commands/sheets.js +289 -52
- package/dist/commands/sheets.js.map +1 -2
- package/dist/commands/skills.js +157 -0
- package/dist/commands/skills.js.map +6 -0
- package/dist/commands/status.js.map +0 -1
- package/dist/commands/tool.js.map +0 -1
- package/dist/commands/variables.js +246 -82
- package/dist/commands/variables.js.map +1 -2
- package/dist/commands/whoami.js.map +0 -1
- package/dist/index.js +117 -23
- package/dist/index.js.map +1 -2
- package/dist/mcp/index.js.map +0 -1
- package/dist/mcp/prompts/workflows.js.map +0 -1
- package/dist/mcp/resources/documentation.js +19 -12
- package/dist/mcp/resources/documentation.js.map +1 -2
- package/dist/mcp/server.js.map +0 -1
- package/dist/mcp/skills.js.map +0 -1
- package/dist/mcp/tools/appTools.js +1 -7
- package/dist/mcp/tools/appTools.js.map +1 -2
- package/dist/mcp/tools/authTools.js +1 -1
- package/dist/mcp/tools/authTools.js.map +1 -2
- package/dist/mcp/tools/cellTools.js +6 -19
- package/dist/mcp/tools/cellTools.js.map +1 -2
- package/dist/mcp/tools/dashboardTools.js +30 -412
- package/dist/mcp/tools/dashboardTools.js.map +2 -3
- package/dist/mcp/tools/dataTools.js +15 -146
- package/dist/mcp/tools/dataTools.js.map +1 -2
- package/dist/mcp/tools/folderTools.js +12 -78
- package/dist/mcp/tools/folderTools.js.map +1 -2
- package/dist/mcp/tools/modelTools.js +23 -372
- package/dist/mcp/tools/modelTools.js.map +1 -2
- package/dist/mcp/tools/pipelineContract.js +5 -1
- package/dist/mcp/tools/pipelineContract.js.map +1 -2
- package/dist/mcp/tools/pipelineTools.js.map +0 -1
- package/dist/mcp/tools/runTools.js +8 -69
- package/dist/mcp/tools/runTools.js.map +1 -2
- package/dist/mcp/tools/sheetTools.js +14 -264
- package/dist/mcp/tools/sheetTools.js.map +1 -2
- package/dist/mcp/tools/syncTools.js +7 -3
- package/dist/mcp/tools/syncTools.js.map +1 -2
- package/dist/mcp/utils/helpers.js.map +0 -1
- package/dist/mcp/utils/launchPin.js.map +0 -1
- package/dist/mcp/utils/operationResponse.js +41 -0
- package/dist/mcp/utils/operationResponse.js.map +6 -0
- package/dist/mcp/utils/registerTool.js.map +0 -1
- package/dist/mcp/utils/session.js.map +0 -1
- package/dist/mcp/utils/tenantPin.js.map +0 -1
- package/dist/operations/cells.js +444 -0
- package/dist/operations/cells.js.map +6 -0
- package/dist/operations/dashboards.js +357 -0
- package/dist/operations/dashboards.js.map +6 -0
- package/dist/operations/data.js +206 -0
- package/dist/operations/data.js.map +6 -0
- package/dist/operations/errors.js +64 -0
- package/dist/operations/errors.js.map +6 -0
- package/dist/operations/exportModel.js +59 -0
- package/dist/operations/exportModel.js.map +6 -0
- package/dist/operations/folderPath.js +128 -0
- package/dist/operations/folderPath.js.map +6 -0
- package/dist/operations/folders.js +80 -0
- package/dist/operations/folders.js.map +6 -0
- package/dist/operations/install.js +109 -0
- package/dist/operations/install.js.map +6 -0
- package/dist/operations/model.js +271 -0
- package/dist/operations/model.js.map +6 -0
- package/dist/operations/sheets.js +428 -0
- package/dist/operations/sheets.js.map +6 -0
- package/dist/pipeline/compatibility.js.map +0 -1
- package/dist/pipeline/connect.js.map +0 -1
- package/dist/pipeline/create.js.map +0 -1
- package/dist/pipeline/errors.js.map +0 -1
- package/dist/pipeline/failStep.js +43 -0
- package/dist/pipeline/failStep.js.map +6 -0
- package/dist/pipeline/generated-reference.json +25 -13
- package/dist/pipeline/guide.js.map +0 -1
- package/dist/pipeline/init.js.map +0 -1
- package/dist/pipeline/operations.js.map +0 -1
- package/dist/pipeline/query.js.map +0 -1
- package/dist/pipeline/queryDownloads.js.map +0 -1
- package/dist/pipeline/queryWorker.js +3 -1
- package/dist/pipeline/queryWorker.js.map +1 -2
- package/dist/pipeline/readiness.js.map +0 -1
- package/dist/pipeline/reference.js.map +0 -1
- package/dist/pipeline/requests.js +3 -32
- package/dist/pipeline/requests.js.map +1 -2
- package/dist/pipeline/runArguments.js.map +0 -1
- package/dist/pipeline/runtime.js.map +0 -1
- package/dist/pipeline/service.js +46 -2
- package/dist/pipeline/service.js.map +1 -2
- package/dist/services/appSyncService.js +59 -9
- package/dist/services/appSyncService.js.map +1 -2
- package/dist/services/apps.js +10 -0
- package/dist/services/apps.js.map +1 -2
- package/dist/services/authErrors.js.map +0 -1
- package/dist/services/codefirst/api.js +38 -5
- package/dist/services/codefirst/api.js.map +1 -2
- package/dist/services/codefirst/binaryDisk.js.map +0 -1
- package/dist/services/codefirst/byteHashes.js +5 -0
- package/dist/services/codefirst/byteHashes.js.map +1 -2
- package/dist/services/codefirst/documents.js +41 -15
- package/dist/services/codefirst/documents.js.map +1 -2
- package/dist/services/codefirst/layoutBinaryProjection.js +24 -13
- package/dist/services/codefirst/layoutBinaryProjection.js.map +1 -2
- package/dist/services/codefirst/layoutCompose.js +44 -38
- package/dist/services/codefirst/layoutCompose.js.map +1 -2
- package/dist/services/codefirst/layoutCore.js +14 -1
- package/dist/services/codefirst/layoutCore.js.map +1 -2
- package/dist/services/codefirst/layoutPaths.js +80 -4
- package/dist/services/codefirst/layoutPaths.js.map +1 -2
- package/dist/services/codefirst/layoutProjection.js +73 -39
- package/dist/services/codefirst/layoutProjection.js.map +1 -2
- package/dist/services/codefirst/layoutReadback.js +357 -130
- package/dist/services/codefirst/layoutReadback.js.map +2 -3
- package/dist/services/codefirst/layoutReadbackPlacement.js +94 -57
- package/dist/services/codefirst/layoutReadbackPlacement.js.map +2 -3
- package/dist/services/codefirst/layoutReceipt.js +283 -243
- package/dist/services/codefirst/layoutReceipt.js.map +2 -3
- package/dist/services/codefirst/layoutScan.js +208 -110
- package/dist/services/codefirst/layoutScan.js.map +1 -2
- package/dist/services/codefirst/output.js +76 -10
- package/dist/services/codefirst/output.js.map +1 -2
- package/dist/services/codefirst/types.js.map +0 -1
- package/dist/services/codefirst/workflow.js +65 -29
- package/dist/services/codefirst/workflow.js.map +2 -3
- package/dist/services/codefirst/workspace.js.map +0 -1
- package/dist/services/codefirst/workspaceLock.js.map +0 -1
- package/dist/services/codefirst/workspaceRoot.js +2 -1
- package/dist/services/codefirst/workspaceRoot.js.map +1 -2
- package/dist/services/configService.js.map +0 -1
- package/dist/services/credentials.js.map +0 -1
- package/dist/services/farseerService.js +31 -7
- package/dist/services/farseerService.js.map +1 -2
- package/dist/services/httpError.js.map +0 -1
- package/dist/services/modelExport.js.map +0 -1
- package/dist/services/organisation.js.map +0 -1
- package/dist/services/preflight.js.map +0 -1
- package/dist/services/realms.js.map +0 -1
- package/dist/services/syncService.js +3 -3
- package/dist/services/syncService.js.map +1 -2
- package/dist/skills/bundled.js +106 -0
- package/dist/skills/bundled.js.map +6 -0
- package/dist/skills/install.js +257 -0
- package/dist/skills/install.js.map +6 -0
- package/dist/skills/pipeline.js +10 -18
- package/dist/skills/pipeline.js.map +1 -2
- package/dist/utils/agentSandbox.js +1 -1
- package/dist/utils/agentSandbox.js.map +0 -1
- package/dist/utils/cliOptions.js.map +0 -1
- package/dist/utils/constants.js.map +0 -1
- package/dist/utils/entityResolver.js +72 -25
- package/dist/utils/entityResolver.js.map +1 -2
- package/dist/utils/errorFormatter.js +72 -11
- package/dist/utils/errorFormatter.js.map +1 -2
- package/dist/utils/fileLogger.js.map +0 -1
- package/dist/utils/fileValidation.js.map +0 -1
- package/dist/utils/folderMatch.js.map +0 -1
- package/dist/utils/formulaFilters.js +11 -2
- package/dist/utils/formulaFilters.js.map +1 -2
- package/dist/utils/helpers.js.map +0 -1
- package/dist/utils/logger.js.map +0 -1
- package/dist/utils/nameResolver.js.map +0 -1
- package/dist/utils/operationCli.js +102 -0
- package/dist/utils/operationCli.js.map +6 -0
- package/dist/utils/packageManager.js.map +0 -1
- package/dist/utils/syncReporting.js.map +0 -1
- package/dist/utils/syncScope.js.map +0 -1
- package/dist/utils/updateCheck.js.map +0 -1
- package/dist/utils/variableValues.js.map +0 -1
- package/dist/utils/workspace.js.map +0 -1
- package/docs/cli-guide.md +182 -2
- package/docs/import-workflows.md +14 -14
- package/docs/new-app-template.md +1 -1
- package/docs/pipeline-client-guide.md +1 -1
- package/docs/pipeline-reference.md +304 -9
- package/docs/troubleshooting.md +18 -0
- package/package.json +2 -2
- package/skills/farseer-analysis/SKILL.md +132 -0
- package/skills/farseer-app-dev/SKILL.md +131 -0
- package/skills/farseer-app-dev/assignments.md +185 -0
- package/skills/farseer-app-dev/farseer-client-api-guide.md +907 -0
- package/skills/farseer-app-dev/farseer-client-release-notes.md +212 -0
- package/skills/farseer-app-dev/working-patterns.md +876 -0
- package/skills/farseer-authenticate-to-tenant/SKILL.md +60 -0
- package/skills/farseer-authenticate-to-tenant/app-authentication.md +91 -0
- package/skills/farseer-author-import-job/SKILL.md +114 -0
- package/skills/farseer-author-import-job/cell-writes.md +530 -0
- package/skills/farseer-author-import-job/deploying-a-farseer-app.md +383 -0
- package/skills/farseer-author-import-job/import-job-pattern.md +232 -0
- package/skills/farseer-build-model/SKILL.md +122 -0
- package/skills/farseer-build-model/formula-grain-alignment.md +612 -0
- package/skills/farseer-build-model/naming-conventions.md +435 -0
- package/skills/farseer-build-model/sparse-formulas-pattern.md +330 -0
- package/skills/farseer-build-pipeline/SKILL.md +190 -0
- package/skills/farseer-build-pipeline/erp-sales/README.md +108 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_invoice_lines.yaml +23 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_invoice_lines_raw.yaml +23 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_item_product_map.yaml +17 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_item_product_map_raw.yaml +11 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/gold/erp_sales_cells.yaml +40 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/silver/erp_sales_lines.yaml +35 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/silver/erp_sales_recon.yaml +43 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/silver/erp_sales_unmapped_items.yaml +28 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/main.py +49 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/Models/in/erp_sales_cells.yaml +17 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/Models/in/erp_sales_cells_raw.yaml +14 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/Models/load/erp_sales_to_model.yaml +47 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/main.py +44 -0
- package/skills/farseer-build-pipeline/erp-sales/item_to_product.csv +5 -0
- package/skills/farseer-build-pipeline/pipeline-app-failure-report-pattern.md +103 -0
- package/skills/farseer-build-pipeline/pipeline-source-encoding.md +68 -0
- package/skills/farseer-dashboards/SKILL.md +40 -0
- package/skills/farseer-formulas/SKILL.md +165 -0
- package/skills/farseer-help-center/SKILL.md +66 -0
- package/skills/farseer-model/SKILL.md +119 -0
- package/skills/farseer-modify-model/SKILL.md +158 -0
- package/skills/farseer-modify-model/model-validation-pattern.md +251 -0
- package/skills/farseer-optimize-model/SKILL.md +314 -0
- package/skills/farseer-optimize-model/stats-dump.ts +139 -0
- package/skills/farseer-pnl/SKILL.md +220 -0
- package/skills/farseer-review-model/SKILL.md +172 -0
- package/skills/farseer-run-apps/SKILL.md +102 -0
- package/skills/pipeline-authoring/SKILL.md +7 -5
- package/skills/pipeline-authoring/practices.md +21 -8
- package/dist/services/agentApprovalFetch.js +0 -86
- package/dist/services/agentApprovalFetch.js.map +0 -7
|
@@ -0,0 +1,907 @@
|
|
|
1
|
+
# Farseer API System Prompt for Claude
|
|
2
|
+
|
|
3
|
+
**Purpose**: Include this file in any project using Farseer. Tell Claude to read it first, then provide project-specific tasks.
|
|
4
|
+
|
|
5
|
+
**Usage**: In a new conversation, say:
|
|
6
|
+
> "Read [path to this file] first. This contains everything you need to know about the Farseer API. After reading it, I'll give you the project-specific requirements."
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# FARSEER API COMPLETE GUIDE
|
|
11
|
+
|
|
12
|
+
You are helping with a project that uses the Farseer financial planning platform. This guide contains everything you need to know about the Farseer Client API, learned through extensive trial and error. Follow these patterns exactly.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## 1. INITIAL SETUP
|
|
17
|
+
|
|
18
|
+
### Installing the Client
|
|
19
|
+
```bash
|
|
20
|
+
npm install farseer-client@npm:@farseerdev/farseer-client@1.18.1
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The client is published on npm as `@farseerdev/farseer-client`; the alias keeps
|
|
24
|
+
the import name `farseer-client`. Never `npm install farseer-client` on its own:
|
|
25
|
+
that name on npm is an empty placeholder, and every import then fails. On
|
|
26
|
+
pnpm 11 add `--config.block-exotic-subdeps=false` (the SDK pulls `xlsx` from a
|
|
27
|
+
URL). An
|
|
28
|
+
existing app still pinned to the old storage-bucket tarball or to `"*"` —
|
|
29
|
+
fix it as in
|
|
30
|
+
[`farseer-client-release-notes.md`](farseer-client-release-notes.md#an-existing-app-still-on-the-bucket-or-on---fixing-it).
|
|
31
|
+
|
|
32
|
+
### Environment Variables
|
|
33
|
+
```bash
|
|
34
|
+
TENANT_ID=your_tenant_name
|
|
35
|
+
FARSEER_URL=https://your-instance.farseer.io/api/v3
|
|
36
|
+
# plus the API-key variable, set to your API key
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Basic Script Structure
|
|
40
|
+
```typescript
|
|
41
|
+
import * as farseer from 'farseer-client';
|
|
42
|
+
|
|
43
|
+
async function main() {
|
|
44
|
+
const client = new farseer.FarseerClient();
|
|
45
|
+
// Your code here
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
main().catch(async (error) => {
|
|
49
|
+
if (typeof error.text === 'function') {
|
|
50
|
+
console.error(await error.text());
|
|
51
|
+
} else {
|
|
52
|
+
console.error(error);
|
|
53
|
+
}
|
|
54
|
+
process.exit(1);
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Running Scripts
|
|
59
|
+
```bash
|
|
60
|
+
# with the variables above set in the environment
|
|
61
|
+
npx tsx src/your-script.ts
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## 2. FINDING API SPECIFICATION
|
|
67
|
+
|
|
68
|
+
**IMPORTANT**: When unsure about API methods, look at the TypeScript definitions:
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
node_modules/farseer-client/dist/generated/apis/
|
|
72
|
+
node_modules/farseer-client/dist/FarseerClient.d.ts
|
|
73
|
+
node_modules/farseer-client/src/generated/apis/
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**Key files to examine**:
|
|
77
|
+
- `FarseerClient.d.ts` - Main client methods
|
|
78
|
+
- `ModelApi.ts` - Model operations (load, export)
|
|
79
|
+
- `RemoteJobsApi.ts` - Remote job operations
|
|
80
|
+
- `ImportJobsApi.ts` - Import job operations
|
|
81
|
+
|
|
82
|
+
**DO NOT GUESS API METHODS**. If uncertain, read the type definitions or ask the user for a working example.
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## 3. EXPORTING MODEL (READ CURRENT STATE)
|
|
87
|
+
|
|
88
|
+
### Basic Export
|
|
89
|
+
```typescript
|
|
90
|
+
const model = await client.model.exportModel();
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### CRITICAL: For Large Models - Exclude Cell Data!
|
|
94
|
+
```typescript
|
|
95
|
+
// Use this for models with significant data to avoid "Invalid string length" error
|
|
96
|
+
const model = await client.model.exportModel({
|
|
97
|
+
types: ['DTAB', 'DMEM', 'VAR'] as any // Excludes CELL data
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Export types**:
|
|
102
|
+
- `DTAB` - Dimension tables (structure)
|
|
103
|
+
- `DMEM` - Dimension members (values in dimensions)
|
|
104
|
+
- `VAR` - Variables (structure and properties)
|
|
105
|
+
- `CELL` - Cell data (actual values) - EXCLUDE FOR LARGE MODELS!
|
|
106
|
+
|
|
107
|
+
### What You Get Back
|
|
108
|
+
```typescript
|
|
109
|
+
interface ModelRepresentation {
|
|
110
|
+
tables?: DimensionTable[]; // All dimension tables
|
|
111
|
+
variables?: Variable[]; // All variables
|
|
112
|
+
// ... other properties
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
interface DimensionTable {
|
|
116
|
+
name: string;
|
|
117
|
+
description?: string;
|
|
118
|
+
rows?: DimensionMember[]; // Members of this dimension
|
|
119
|
+
columns?: DimensionColumn[]; // Attributes/columns
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
interface Variable {
|
|
123
|
+
name: string;
|
|
124
|
+
description?: string;
|
|
125
|
+
notes?: string;
|
|
126
|
+
formula?: string | null;
|
|
127
|
+
tables: string[]; // Which dimensions this variable uses
|
|
128
|
+
members: any[]; // Fixed dimension members
|
|
129
|
+
rollupType: string; // SUM, AVERAGE, etc.
|
|
130
|
+
dataType: string; // NUMBER, TEXT, etc.
|
|
131
|
+
numberFormat?: string;
|
|
132
|
+
folderPath?: string;
|
|
133
|
+
// ... other properties
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Common Uses for Model Export
|
|
138
|
+
```typescript
|
|
139
|
+
// Check if a dimension exists
|
|
140
|
+
const dimension = model.tables?.find(t => t.name === 'Product Type');
|
|
141
|
+
|
|
142
|
+
// Check if a variable exists
|
|
143
|
+
const variable = model.variables?.find(v => v.name === 'Revenue');
|
|
144
|
+
|
|
145
|
+
// Get all dimension members
|
|
146
|
+
const members = dimension?.rows?.map(r => r.name) || [];
|
|
147
|
+
|
|
148
|
+
// Get variable's dimensions
|
|
149
|
+
const varDimensions = variable?.tables || [];
|
|
150
|
+
|
|
151
|
+
// Check exact member names (for dimension discrimination)
|
|
152
|
+
const memberExists = dimension?.rows?.some(r => r.name === 'Air Ticket');
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## 4. CREATING DIMENSIONS
|
|
158
|
+
|
|
159
|
+
### Create a Dimension Table with Members
|
|
160
|
+
```typescript
|
|
161
|
+
await client.model.load({
|
|
162
|
+
model: {
|
|
163
|
+
tables: [{
|
|
164
|
+
name: 'Product Type',
|
|
165
|
+
description: 'Types of products',
|
|
166
|
+
rows: [
|
|
167
|
+
{ name: 'Product A' },
|
|
168
|
+
{ name: 'Product B' },
|
|
169
|
+
{ name: 'Product C' },
|
|
170
|
+
{ name: 'Unknown' } // Always include for data quality
|
|
171
|
+
]
|
|
172
|
+
}],
|
|
173
|
+
variables: [],
|
|
174
|
+
dependencies: { tables: [], members: [], variables: [] }
|
|
175
|
+
},
|
|
176
|
+
options: {
|
|
177
|
+
clear: false,
|
|
178
|
+
dryRun: false,
|
|
179
|
+
deleteEnabled: {
|
|
180
|
+
tables: false,
|
|
181
|
+
rows: false,
|
|
182
|
+
columns: false,
|
|
183
|
+
variables: false,
|
|
184
|
+
cells: false
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Adding Members to Existing Dimension
|
|
191
|
+
```typescript
|
|
192
|
+
// First, get existing members
|
|
193
|
+
const model = await client.model.exportModel({ types: ['DTAB', 'DMEM', 'VAR'] as any });
|
|
194
|
+
const dimension = model.tables?.find(t => t.name === 'Product Type');
|
|
195
|
+
const existingMembers = dimension?.rows || [];
|
|
196
|
+
|
|
197
|
+
// Add new members (preserving existing)
|
|
198
|
+
const newMembers = ['New Product 1', 'New Product 2'];
|
|
199
|
+
const allMembers = [
|
|
200
|
+
...existingMembers,
|
|
201
|
+
...newMembers.map(name => ({ name }))
|
|
202
|
+
];
|
|
203
|
+
|
|
204
|
+
await client.model.load({
|
|
205
|
+
model: {
|
|
206
|
+
tables: [{
|
|
207
|
+
name: 'Product Type',
|
|
208
|
+
rows: allMembers
|
|
209
|
+
}],
|
|
210
|
+
variables: [],
|
|
211
|
+
dependencies: { tables: [], members: [], variables: [] }
|
|
212
|
+
},
|
|
213
|
+
options: {
|
|
214
|
+
clear: false,
|
|
215
|
+
dryRun: false,
|
|
216
|
+
deleteEnabled: { tables: false, rows: false, columns: false, variables: false, cells: false }
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Auto-Discover Dimension Members from Data
|
|
222
|
+
```typescript
|
|
223
|
+
// Collect unique values from your data source
|
|
224
|
+
const uniqueValues = new Set<string>();
|
|
225
|
+
for (const row of sourceData) {
|
|
226
|
+
if (row.dimension_column !== null && row.dimension_column !== undefined) {
|
|
227
|
+
uniqueValues.add(String(row.dimension_column));
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Compare with existing
|
|
232
|
+
const model = await client.model.exportModel({ types: ['DTAB', 'DMEM', 'VAR'] as any });
|
|
233
|
+
const dimension = model.tables?.find(t => t.name === 'My Dimension');
|
|
234
|
+
const existingNames = new Set(dimension?.rows?.map(r => r.name) || []);
|
|
235
|
+
|
|
236
|
+
// Find missing
|
|
237
|
+
const missingMembers = [...uniqueValues].filter(v => !existingNames.has(v));
|
|
238
|
+
|
|
239
|
+
// Add missing members
|
|
240
|
+
if (missingMembers.length > 0) {
|
|
241
|
+
console.log(`Adding ${missingMembers.length} new members:`, missingMembers);
|
|
242
|
+
// ... use model.load to add them
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## 5. CREATING VARIABLES
|
|
249
|
+
|
|
250
|
+
### Basic Variable Creation
|
|
251
|
+
```typescript
|
|
252
|
+
await client.model.load({
|
|
253
|
+
model: {
|
|
254
|
+
tables: [],
|
|
255
|
+
variables: [{
|
|
256
|
+
name: 'Revenue',
|
|
257
|
+
description: 'Total revenue',
|
|
258
|
+
notes: 'Source: BigQuery table xyz',
|
|
259
|
+
formula: null, // null for imported data, string for calculated
|
|
260
|
+
tables: ['Date', 'Product Type'], // Dimensions this variable uses
|
|
261
|
+
members: [], // Fixed members (usually empty)
|
|
262
|
+
rollupType: 'SUM', // NONE, SUM, AVERAGE, CLOSING STATE, BEGINNING STATE, FORMULA, MAX, MIN
|
|
263
|
+
dataType: 'NUMBER', // NUMBER, TEXT, DATE, etc.
|
|
264
|
+
numberFormat: '#,##0.00', // Excel-style format
|
|
265
|
+
numberValidation: null,
|
|
266
|
+
topDownMapping: null,
|
|
267
|
+
readonly: false,
|
|
268
|
+
calculateOnDemand: false,
|
|
269
|
+
zConstraint: null,
|
|
270
|
+
active: true,
|
|
271
|
+
optimizeCalculation: false,
|
|
272
|
+
folderPath: '/Variables/Revenue', // Folder in Farseer UI
|
|
273
|
+
cells: []
|
|
274
|
+
}],
|
|
275
|
+
dependencies: { tables: [], members: [], variables: [] }
|
|
276
|
+
},
|
|
277
|
+
options: {
|
|
278
|
+
clear: false,
|
|
279
|
+
dryRun: false,
|
|
280
|
+
deleteEnabled: { tables: false, rows: false, columns: false, variables: false, cells: false }
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Copying Variable Structure from Existing Variable
|
|
286
|
+
```typescript
|
|
287
|
+
// Export model to get existing variable structure
|
|
288
|
+
const model = await client.model.exportModel({ types: ['DTAB', 'DMEM', 'VAR'] as any });
|
|
289
|
+
const templateVar = model.variables?.find(v => v.name === 'Existing Variable');
|
|
290
|
+
|
|
291
|
+
if (templateVar) {
|
|
292
|
+
// Create new variable based on template
|
|
293
|
+
const newVariable = {
|
|
294
|
+
...templateVar,
|
|
295
|
+
name: 'New Variable Name',
|
|
296
|
+
description: 'New description',
|
|
297
|
+
notes: 'New notes',
|
|
298
|
+
cells: [] // Always clear cells for new variable
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
await client.model.load({
|
|
302
|
+
model: {
|
|
303
|
+
tables: [],
|
|
304
|
+
variables: [newVariable],
|
|
305
|
+
dependencies: { tables: [], members: [], variables: [] }
|
|
306
|
+
},
|
|
307
|
+
options: {
|
|
308
|
+
clear: false,
|
|
309
|
+
dryRun: false,
|
|
310
|
+
deleteEnabled: { tables: false, rows: false, columns: false, variables: false, cells: false }
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### Calculated Variables (Formulas)
|
|
317
|
+
```typescript
|
|
318
|
+
await client.model.load({
|
|
319
|
+
model: {
|
|
320
|
+
tables: [],
|
|
321
|
+
variables: [{
|
|
322
|
+
name: 'Gross Profit',
|
|
323
|
+
description: 'Revenue minus Cost',
|
|
324
|
+
formula: '[Revenue] - [Cost of Sales]', // Reference other variables with []
|
|
325
|
+
tables: ['Date', 'Product Type'],
|
|
326
|
+
// ... other properties
|
|
327
|
+
}],
|
|
328
|
+
// ...
|
|
329
|
+
},
|
|
330
|
+
// ...
|
|
331
|
+
});
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
---
|
|
335
|
+
|
|
336
|
+
## 6. IMPORT JOBS (IMPORTING DATA)
|
|
337
|
+
|
|
338
|
+
### Basic Import Job
|
|
339
|
+
```typescript
|
|
340
|
+
const importJob = await client.createImportJob({
|
|
341
|
+
title: 'My Import - ' + new Date().toISOString(),
|
|
342
|
+
description: 'Importing data from source X',
|
|
343
|
+
columns: [
|
|
344
|
+
// Dimension columns first
|
|
345
|
+
{ type: 'DIMENSION_TABLE', dimensionTableName: 'Date', columnName: 'Date' },
|
|
346
|
+
{ type: 'DIMENSION_TABLE', dimensionTableName: 'Product Type', columnName: 'Product' },
|
|
347
|
+
|
|
348
|
+
// Then variable columns
|
|
349
|
+
{ type: 'VARIABLE', variableName: 'Revenue' },
|
|
350
|
+
{ type: 'VARIABLE', variableName: 'Cost' }
|
|
351
|
+
],
|
|
352
|
+
labels: ['automated', 'source-name']
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
// Add rows - ORDER MUST MATCH COLUMNS ARRAY!
|
|
356
|
+
for (const row of sourceData) {
|
|
357
|
+
await importJob.addRow([
|
|
358
|
+
row.date, // Date dimension
|
|
359
|
+
row.product, // Product Type dimension
|
|
360
|
+
row.revenue, // Revenue variable
|
|
361
|
+
row.cost // Cost variable
|
|
362
|
+
]);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// Commit the import
|
|
366
|
+
await importJob.commit();
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
### DIMENSION DISCRIMINATION (Critical Concept!)
|
|
370
|
+
|
|
371
|
+
When multiple source columns map to the SAME variable but different dimension values:
|
|
372
|
+
|
|
373
|
+
**Example**:
|
|
374
|
+
- `revenue_product_a` → "Revenue" variable, Product Type = "Product A"
|
|
375
|
+
- `revenue_product_b` → "Revenue" variable, Product Type = "Product B"
|
|
376
|
+
|
|
377
|
+
```typescript
|
|
378
|
+
const importJob = await client.createImportJob({
|
|
379
|
+
title: 'Import with Dimension Discrimination',
|
|
380
|
+
columns: [
|
|
381
|
+
// Dimension columns (not discriminated)
|
|
382
|
+
{ type: 'DIMENSION_TABLE', dimensionTableName: 'Date', columnName: 'Date' },
|
|
383
|
+
|
|
384
|
+
// Variable columns WITH dimension discrimination
|
|
385
|
+
{
|
|
386
|
+
type: 'VARIABLE',
|
|
387
|
+
variableName: 'Revenue',
|
|
388
|
+
dimensionsNames: [{ tableName: 'Product Type', memberName: 'Product A' }] // <-- This is dimension discrimination!
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
type: 'VARIABLE',
|
|
392
|
+
variableName: 'Revenue',
|
|
393
|
+
dimensionsNames: [{ tableName: 'Product Type', memberName: 'Product B' }]
|
|
394
|
+
},
|
|
395
|
+
{
|
|
396
|
+
type: 'VARIABLE',
|
|
397
|
+
variableName: 'Revenue',
|
|
398
|
+
dimensionsNames: [{ tableName: 'Product Type', memberName: 'Product C' }]
|
|
399
|
+
}
|
|
400
|
+
]
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
// Add rows - each value goes to the correct product type
|
|
404
|
+
for (const row of sourceData) {
|
|
405
|
+
await importJob.addRow([
|
|
406
|
+
row.date,
|
|
407
|
+
row.revenue_product_a, // Goes to Revenue + Product A
|
|
408
|
+
row.revenue_product_b, // Goes to Revenue + Product B
|
|
409
|
+
row.revenue_product_c // Goes to Revenue + Product C
|
|
410
|
+
]);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
await importJob.commit();
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
### Scalar Variables (No Dimensions)
|
|
417
|
+
```typescript
|
|
418
|
+
// For variables without dimensions (like "Last Updated Date")
|
|
419
|
+
const importJob = await client.createImportJob({
|
|
420
|
+
title: 'Update Scalar',
|
|
421
|
+
columns: [
|
|
422
|
+
{ type: 'VARIABLE', variableName: 'Last Updated Date' }
|
|
423
|
+
]
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
await importJob.addRow(['2024-12-31']);
|
|
427
|
+
await importJob.commit();
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
### Large Data Imports - Best Practices
|
|
431
|
+
|
|
432
|
+
```typescript
|
|
433
|
+
// For large datasets, log progress
|
|
434
|
+
let rowCount = 0;
|
|
435
|
+
const totalRows = sourceData.length;
|
|
436
|
+
|
|
437
|
+
for (const row of sourceData) {
|
|
438
|
+
await importJob.addRow([...]);
|
|
439
|
+
rowCount++;
|
|
440
|
+
|
|
441
|
+
if (rowCount % 10000 === 0) {
|
|
442
|
+
console.log(`Progress: ${rowCount}/${totalRows} rows (${Math.round(rowCount/totalRows*100)}%)`);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
console.log(`Adding all ${rowCount} rows complete. Committing...`);
|
|
447
|
+
await importJob.commit();
|
|
448
|
+
console.log('✓ Import committed successfully');
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
---
|
|
452
|
+
|
|
453
|
+
## 7. REMOTE JOBS (Scripts Running on Farseer Servers)
|
|
454
|
+
|
|
455
|
+
### Creating a Remote Job Script
|
|
456
|
+
```typescript
|
|
457
|
+
// src/remoteJobMyFeature.ts
|
|
458
|
+
import * as farseer from 'farseer-client';
|
|
459
|
+
|
|
460
|
+
async function main() {
|
|
461
|
+
console.log('=== Starting Remote Job ===\n');
|
|
462
|
+
const client = new farseer.FarseerClient();
|
|
463
|
+
|
|
464
|
+
// Step 1: Export model
|
|
465
|
+
console.log('Step 1: Exporting model...');
|
|
466
|
+
const model = await client.model.exportModel({
|
|
467
|
+
types: ['DTAB', 'DMEM', 'VAR'] as any
|
|
468
|
+
});
|
|
469
|
+
console.log('✓ Model exported\n');
|
|
470
|
+
|
|
471
|
+
// Step 2: Your logic
|
|
472
|
+
console.log('Step 2: Processing...');
|
|
473
|
+
// ... your code ...
|
|
474
|
+
console.log('✓ Processing complete\n');
|
|
475
|
+
|
|
476
|
+
console.log('=== Job Complete ===');
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
main().catch(async (error) => {
|
|
480
|
+
console.error('=== JOB FAILED ===');
|
|
481
|
+
if (typeof error.text === 'function') {
|
|
482
|
+
console.error(await error.text());
|
|
483
|
+
} else {
|
|
484
|
+
console.error(error);
|
|
485
|
+
}
|
|
486
|
+
process.exit(1);
|
|
487
|
+
});
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
### Deploying Remote Job to Farseer
|
|
491
|
+
```typescript
|
|
492
|
+
// src/uploadMyFeatureScript.ts
|
|
493
|
+
import * as farseer from 'farseer-client';
|
|
494
|
+
import * as fs from 'fs';
|
|
495
|
+
import * as path from 'path';
|
|
496
|
+
|
|
497
|
+
async function upload() {
|
|
498
|
+
const client = new farseer.FarseerClient();
|
|
499
|
+
|
|
500
|
+
const scriptContent = fs.readFileSync(
|
|
501
|
+
path.join(__dirname, 'remoteJobMyFeature.ts'),
|
|
502
|
+
'utf-8'
|
|
503
|
+
);
|
|
504
|
+
|
|
505
|
+
await client.createOrUpdateFarseerFile(
|
|
506
|
+
{ name: 'my-feature-job.ts', folderId: YOUR_FOLDER_ID },
|
|
507
|
+
scriptContent
|
|
508
|
+
);
|
|
509
|
+
|
|
510
|
+
console.log('✓ Script deployed to Farseer');
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
upload().catch(console.error);
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
### Reading Configuration Files in Remote Jobs
|
|
517
|
+
```typescript
|
|
518
|
+
// Read a config file stored in Farseer
|
|
519
|
+
const configContent = await client.getFarseerFileContent({
|
|
520
|
+
name: 'MyConfig.txt',
|
|
521
|
+
folderId: 155
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
// Parse and use the configuration
|
|
525
|
+
const lines = configContent.split('\n');
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
### CRITICAL: Deploying Updates
|
|
529
|
+
**Editing the local file is NOT enough!** You must run the upload script to deploy changes:
|
|
530
|
+
|
|
531
|
+
```bash
|
|
532
|
+
# After editing src/remoteJobMyFeature.ts, run (with the §1 variables set):
|
|
533
|
+
npx tsx src/uploadMyFeatureScript.ts
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
---
|
|
537
|
+
|
|
538
|
+
## 8. COMMON ERRORS AND SOLUTIONS
|
|
539
|
+
|
|
540
|
+
### Error: "Invalid string length"
|
|
541
|
+
**Cause**: Model too large to serialize with cell data
|
|
542
|
+
**Solution**:
|
|
543
|
+
```typescript
|
|
544
|
+
// Always use this for large models:
|
|
545
|
+
const model = await client.model.exportModel({
|
|
546
|
+
types: ['DTAB', 'DMEM', 'VAR'] as any
|
|
547
|
+
});
|
|
548
|
+
```
|
|
549
|
+
|
|
550
|
+
### Error: "Variable not found"
|
|
551
|
+
**Cause**: Variable name doesn't match exactly (case-sensitive!)
|
|
552
|
+
**Solution**:
|
|
553
|
+
```typescript
|
|
554
|
+
// Check exact variable name:
|
|
555
|
+
const model = await client.model.exportModel({ types: ['DTAB', 'DMEM', 'VAR'] as any });
|
|
556
|
+
const variable = model.variables?.find(v => v.name === 'Expected Name');
|
|
557
|
+
console.log('Actual variable name:', variable?.name);
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
### Error: "Dimension member not found"
|
|
561
|
+
**Cause**: Member name doesn't match exactly
|
|
562
|
+
**Solution**:
|
|
563
|
+
```typescript
|
|
564
|
+
// Check exact member names:
|
|
565
|
+
const dimension = model.tables?.find(t => t.name === 'Product Type');
|
|
566
|
+
console.log('Available members:', dimension?.rows?.map(r => r.name));
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
### Import Succeeds but Data Missing/Wrong
|
|
570
|
+
**Cause**: Column order mismatch between `columns` array and `addRow()` values
|
|
571
|
+
**Solution**: Ensure values in `addRow([...])` match exact order of `columns` array
|
|
572
|
+
|
|
573
|
+
### Remote Job Not Updating
|
|
574
|
+
**Cause**: Forgot to run upload script after editing
|
|
575
|
+
**Solution**: Always run upload script after local changes
|
|
576
|
+
|
|
577
|
+
### API Method Not Found
|
|
578
|
+
**Cause**: Guessing at API methods that don't exist
|
|
579
|
+
**Solution**: Check TypeScript definitions in `node_modules/farseer-client/`
|
|
580
|
+
|
|
581
|
+
---
|
|
582
|
+
|
|
583
|
+
## 9. VALIDATION PATTERNS (Always Use These!)
|
|
584
|
+
|
|
585
|
+
### Before Creating Variables
|
|
586
|
+
```typescript
|
|
587
|
+
// Validate all dimensions exist
|
|
588
|
+
const model = await client.model.exportModel({ types: ['DTAB', 'DMEM', 'VAR'] as any });
|
|
589
|
+
const requiredDimensions = ['Date', 'Product Type', 'Region'];
|
|
590
|
+
|
|
591
|
+
for (const dimName of requiredDimensions) {
|
|
592
|
+
const dim = model.tables?.find(t => t.name === dimName);
|
|
593
|
+
if (!dim) {
|
|
594
|
+
throw new Error(`Required dimension '${dimName}' not found! Create it first.`);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
```
|
|
598
|
+
|
|
599
|
+
### Before Import with Dimension Discrimination
|
|
600
|
+
```typescript
|
|
601
|
+
// Validate all dimension members exist
|
|
602
|
+
const productDim = model.tables?.find(t => t.name === 'Product Type');
|
|
603
|
+
const existingMembers = new Set(productDim?.rows?.map(r => r.name) || []);
|
|
604
|
+
|
|
605
|
+
const requiredMembers = ['Product A', 'Product B', 'Product C'];
|
|
606
|
+
const missing = requiredMembers.filter(m => !existingMembers.has(m));
|
|
607
|
+
|
|
608
|
+
if (missing.length > 0) {
|
|
609
|
+
console.log('Missing members:', missing);
|
|
610
|
+
// Either throw error or auto-create them
|
|
611
|
+
}
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
### Before Import - Check Variable Exists
|
|
615
|
+
```typescript
|
|
616
|
+
const variable = model.variables?.find(v => v.name === 'Revenue');
|
|
617
|
+
if (!variable) {
|
|
618
|
+
throw new Error(`Variable 'Revenue' not found! Create it first.`);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
// Also verify it has the expected dimensions
|
|
622
|
+
const expectedDims = ['Date', 'Product Type'];
|
|
623
|
+
const actualDims = variable.tables || [];
|
|
624
|
+
const missingDims = expectedDims.filter(d => !actualDims.includes(d));
|
|
625
|
+
if (missingDims.length > 0) {
|
|
626
|
+
throw new Error(`Variable missing dimensions: ${missingDims.join(', ')}`);
|
|
627
|
+
}
|
|
628
|
+
```
|
|
629
|
+
|
|
630
|
+
---
|
|
631
|
+
|
|
632
|
+
## 10. DATA TRANSFORMATION PATTERNS
|
|
633
|
+
|
|
634
|
+
### Boolean to String
|
|
635
|
+
```typescript
|
|
636
|
+
// Farseer often needs strings, not booleans
|
|
637
|
+
const transformBoolean = (value: boolean | null): string => {
|
|
638
|
+
if (value === null || value === undefined) return 'Unknown';
|
|
639
|
+
return value ? 'true' : 'false';
|
|
640
|
+
};
|
|
641
|
+
|
|
642
|
+
// Or custom transformations:
|
|
643
|
+
const transformIsVI = (value: boolean | null): string => {
|
|
644
|
+
if (value === null || value === undefined) return 'Unknown';
|
|
645
|
+
return value ? 'vi' : 'nonvi';
|
|
646
|
+
};
|
|
647
|
+
```
|
|
648
|
+
|
|
649
|
+
### Date Handling
|
|
650
|
+
```typescript
|
|
651
|
+
// Ensure consistent date format
|
|
652
|
+
const formatDate = (date: Date | string | null): string => {
|
|
653
|
+
if (!date) return 'Unknown';
|
|
654
|
+
if (typeof date === 'string') return date;
|
|
655
|
+
return date.toISOString().split('T')[0]; // YYYY-MM-DD
|
|
656
|
+
};
|
|
657
|
+
```
|
|
658
|
+
|
|
659
|
+
### NULL Handling
|
|
660
|
+
```typescript
|
|
661
|
+
// Replace nulls with default or 'Unknown'
|
|
662
|
+
const handleNull = (value: any, defaultValue: string = 'Unknown'): string => {
|
|
663
|
+
if (value === null || value === undefined || value === '') {
|
|
664
|
+
return defaultValue;
|
|
665
|
+
}
|
|
666
|
+
return String(value);
|
|
667
|
+
};
|
|
668
|
+
```
|
|
669
|
+
|
|
670
|
+
### Numeric Handling
|
|
671
|
+
```typescript
|
|
672
|
+
// Ensure numbers are actually numbers
|
|
673
|
+
const handleNumeric = (value: any): number | null => {
|
|
674
|
+
if (value === null || value === undefined) return null;
|
|
675
|
+
const num = Number(value);
|
|
676
|
+
return isNaN(num) ? null : num;
|
|
677
|
+
};
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
---
|
|
681
|
+
|
|
682
|
+
## 11. CONFIGURATION-DRIVEN IMPORTS
|
|
683
|
+
|
|
684
|
+
### Using a Text File for Mapping
|
|
685
|
+
Create a human-readable configuration file:
|
|
686
|
+
|
|
687
|
+
```
|
|
688
|
+
# MyMappingConfig.txt
|
|
689
|
+
# Format: source_column | farseer_variable | dimension_discrimination
|
|
690
|
+
|
|
691
|
+
DIMENSIONS
|
|
692
|
+
date_column | Date
|
|
693
|
+
product_column | Product Type
|
|
694
|
+
|
|
695
|
+
VARIABLES
|
|
696
|
+
revenue_product_a | Revenue | Product Type => Product A
|
|
697
|
+
revenue_product_b | Revenue | Product Type => Product B
|
|
698
|
+
cost_total | Cost |
|
|
699
|
+
```
|
|
700
|
+
|
|
701
|
+
### Parsing the Configuration
|
|
702
|
+
```typescript
|
|
703
|
+
function parseMappingFile(content: string) {
|
|
704
|
+
const lines = content.split('\n');
|
|
705
|
+
const dimensions: { source: string; target: string }[] = [];
|
|
706
|
+
const variables: { source: string; variable: string; discrimination?: { dim: string; member: string } }[] = [];
|
|
707
|
+
|
|
708
|
+
let section = '';
|
|
709
|
+
|
|
710
|
+
for (const line of lines) {
|
|
711
|
+
const trimmed = line.trim();
|
|
712
|
+
if (!trimmed || trimmed.startsWith('#')) continue;
|
|
713
|
+
|
|
714
|
+
if (trimmed === 'DIMENSIONS') { section = 'dim'; continue; }
|
|
715
|
+
if (trimmed === 'VARIABLES') { section = 'var'; continue; }
|
|
716
|
+
|
|
717
|
+
const parts = trimmed.split('|').map(p => p.trim());
|
|
718
|
+
|
|
719
|
+
if (section === 'dim' && parts.length >= 2) {
|
|
720
|
+
dimensions.push({ source: parts[0], target: parts[1] });
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
if (section === 'var' && parts.length >= 2) {
|
|
724
|
+
const mapping: any = { source: parts[0], variable: parts[1] };
|
|
725
|
+
if (parts[2]) {
|
|
726
|
+
const [dim, member] = parts[2].split('=>').map(p => p.trim());
|
|
727
|
+
mapping.discrimination = { dim, member };
|
|
728
|
+
}
|
|
729
|
+
variables.push(mapping);
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
return { dimensions, variables };
|
|
734
|
+
}
|
|
735
|
+
```
|
|
736
|
+
|
|
737
|
+
---
|
|
738
|
+
|
|
739
|
+
## 12. LOGGING BEST PRACTICES
|
|
740
|
+
|
|
741
|
+
### Use Clear Step-Based Logging
|
|
742
|
+
```typescript
|
|
743
|
+
console.log('=== Starting Import Process ===\n');
|
|
744
|
+
|
|
745
|
+
console.log('Step 1: Connecting to data source...');
|
|
746
|
+
// ... code ...
|
|
747
|
+
console.log('✓ Connected\n');
|
|
748
|
+
|
|
749
|
+
console.log('Step 2: Exporting Farseer model...');
|
|
750
|
+
// ... code ...
|
|
751
|
+
console.log('✓ Model exported\n');
|
|
752
|
+
|
|
753
|
+
console.log('Step 3: Validating dimensions...');
|
|
754
|
+
// ... code ...
|
|
755
|
+
console.log('✓ All dimensions validated\n');
|
|
756
|
+
|
|
757
|
+
console.log('=== Import Complete ===');
|
|
758
|
+
```
|
|
759
|
+
|
|
760
|
+
### Log Counts and Progress
|
|
761
|
+
```typescript
|
|
762
|
+
console.log(`Found ${rows.length} rows to import`);
|
|
763
|
+
console.log(`Processing ${variables.length} variables`);
|
|
764
|
+
console.log(`Dimension has ${members.length} members`);
|
|
765
|
+
```
|
|
766
|
+
|
|
767
|
+
### Log Errors with Context
|
|
768
|
+
```typescript
|
|
769
|
+
try {
|
|
770
|
+
await importJob.commit();
|
|
771
|
+
} catch (error) {
|
|
772
|
+
console.error('Import failed!');
|
|
773
|
+
console.error('Job title:', importJob.title);
|
|
774
|
+
console.error('Row count:', rowCount);
|
|
775
|
+
console.error('Error:', error);
|
|
776
|
+
if (typeof error.text === 'function') {
|
|
777
|
+
console.error('API response:', await error.text());
|
|
778
|
+
}
|
|
779
|
+
throw error;
|
|
780
|
+
}
|
|
781
|
+
```
|
|
782
|
+
|
|
783
|
+
---
|
|
784
|
+
|
|
785
|
+
## 13. TESTING STRATEGY
|
|
786
|
+
|
|
787
|
+
### Always Test Incrementally
|
|
788
|
+
```typescript
|
|
789
|
+
// Phase 1: Test with 10 rows
|
|
790
|
+
const testRows = sourceData.slice(0, 10);
|
|
791
|
+
|
|
792
|
+
// Phase 2: Test with 100 rows
|
|
793
|
+
const testRows = sourceData.slice(0, 100);
|
|
794
|
+
|
|
795
|
+
// Phase 3: Test with 1000 rows
|
|
796
|
+
const testRows = sourceData.slice(0, 1000);
|
|
797
|
+
|
|
798
|
+
// Phase 4: Full dataset
|
|
799
|
+
const allRows = sourceData;
|
|
800
|
+
```
|
|
801
|
+
|
|
802
|
+
### Dry Run Pattern
|
|
803
|
+
```typescript
|
|
804
|
+
const DRY_RUN = process.env.DRY_RUN !== 'false'; // writes only on an explicit 'false'
|
|
805
|
+
|
|
806
|
+
if (DRY_RUN) {
|
|
807
|
+
console.log('DRY RUN - would create import job with:');
|
|
808
|
+
console.log('Columns:', columns);
|
|
809
|
+
console.log('Sample row:', sampleRow);
|
|
810
|
+
console.log('Total rows:', rowCount);
|
|
811
|
+
} else {
|
|
812
|
+
const importJob = await client.createImportJob({ ... });
|
|
813
|
+
// ... actual import
|
|
814
|
+
}
|
|
815
|
+
```
|
|
816
|
+
|
|
817
|
+
### Validation-Only Mode
|
|
818
|
+
```typescript
|
|
819
|
+
// First run: just validate, don't import
|
|
820
|
+
console.log('Running validation only...');
|
|
821
|
+
|
|
822
|
+
// Check dimensions
|
|
823
|
+
// Check members
|
|
824
|
+
// Check variables
|
|
825
|
+
// Check data format
|
|
826
|
+
|
|
827
|
+
console.log('✓ Validation passed. Run with --import flag to actually import.');
|
|
828
|
+
```
|
|
829
|
+
|
|
830
|
+
---
|
|
831
|
+
|
|
832
|
+
## 14. PROJECT STRUCTURE RECOMMENDATION
|
|
833
|
+
|
|
834
|
+
```
|
|
835
|
+
src/
|
|
836
|
+
├── config/
|
|
837
|
+
│ └── mappings.txt # Human-editable configuration
|
|
838
|
+
├── utils/
|
|
839
|
+
│ ├── farseerHelpers.ts # Reusable Farseer utilities
|
|
840
|
+
│ └── dataTransforms.ts # Data transformation functions
|
|
841
|
+
├── jobs/
|
|
842
|
+
│ ├── remoteJobImport.ts # Main import job
|
|
843
|
+
│ └── remoteJobValidate.ts # Validation job
|
|
844
|
+
├── setup/
|
|
845
|
+
│ ├── createDimensions.ts # Initial dimension setup
|
|
846
|
+
│ └── createVariables.ts # Initial variable setup
|
|
847
|
+
├── deploy/
|
|
848
|
+
│ └── uploadScripts.ts # Deploy to Farseer
|
|
849
|
+
└── explore/
|
|
850
|
+
├── exportModel.ts # Export and examine model
|
|
851
|
+
└── checkData.ts # Explore source data
|
|
852
|
+
```
|
|
853
|
+
|
|
854
|
+
---
|
|
855
|
+
|
|
856
|
+
## 15. QUICK REFERENCE
|
|
857
|
+
|
|
858
|
+
### Must-Know Patterns
|
|
859
|
+
```typescript
|
|
860
|
+
// 1. Create client
|
|
861
|
+
const client = new farseer.FarseerClient();
|
|
862
|
+
|
|
863
|
+
// 2. Export model (ALWAYS exclude CELL for large models!)
|
|
864
|
+
const model = await client.model.exportModel({ types: ['DTAB', 'DMEM', 'VAR'] as any });
|
|
865
|
+
|
|
866
|
+
// 3. Create/update model objects
|
|
867
|
+
await client.model.load({ model: {...}, options: {...} });
|
|
868
|
+
|
|
869
|
+
// 4. Create import job
|
|
870
|
+
const importJob = await client.createImportJob({ title, columns, ... });
|
|
871
|
+
await importJob.addRow([...]);
|
|
872
|
+
await importJob.commit();
|
|
873
|
+
|
|
874
|
+
// 5. Deploy to Farseer
|
|
875
|
+
await client.createOrUpdateFarseerFile({ name, folderId }, content);
|
|
876
|
+
```
|
|
877
|
+
|
|
878
|
+
### Environment Setup
|
|
879
|
+
```bash
|
|
880
|
+
# TENANT_ID, FARSEER_URL and the API-key variable set (see §1)
|
|
881
|
+
npx tsx src/script.ts
|
|
882
|
+
```
|
|
883
|
+
|
|
884
|
+
### Common Column Types
|
|
885
|
+
```typescript
|
|
886
|
+
{ type: 'DIMENSION_TABLE', dimensionTableName: 'DimName', columnName: 'ColName' }
|
|
887
|
+
{ type: 'VARIABLE', variableName: 'VarName' }
|
|
888
|
+
{ type: 'VARIABLE', variableName: 'VarName', dimensionsNames: [{ tableName: 'DimName', memberName: 'MemberName' }] } // With discrimination
|
|
889
|
+
```
|
|
890
|
+
|
|
891
|
+
---
|
|
892
|
+
|
|
893
|
+
## FINAL NOTES FOR CLAUDE
|
|
894
|
+
|
|
895
|
+
1. **Never guess at API methods** - Check type definitions or ask for examples
|
|
896
|
+
2. **Always validate before modifying** - Export model, check existence, then proceed
|
|
897
|
+
3. **Always exclude CELL data** when exporting large models
|
|
898
|
+
4. **Member names must match exactly** - Case-sensitive!
|
|
899
|
+
5. **Column order matters** in import jobs - addRow() must match columns array
|
|
900
|
+
6. **Local edits ≠ deployed code** - Must run upload script for remote jobs
|
|
901
|
+
7. **Log comprehensively** - You can't debug what you can't see
|
|
902
|
+
8. **Test incrementally** - 10 rows → 100 rows → 1000 rows → full dataset
|
|
903
|
+
9. **Ask the user** for working examples when documentation isn't clear
|
|
904
|
+
|
|
905
|
+
---
|
|
906
|
+
|
|
907
|
+
**Ready to help with Farseer projects. What are we building?**
|