farseer-cli 1.3.0 → 1.5.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 +102 -30
- package/dist/commands/checkout.js +3 -8
- package/dist/commands/checkout.js.map +2 -2
- package/dist/commands/dimensions.js +8 -8
- package/dist/commands/dimensions.js.map +2 -2
- package/dist/commands/model.js +29 -13
- package/dist/commands/model.js.map +2 -2
- package/dist/commands/pull.js +159 -46
- package/dist/commands/pull.js.map +2 -2
- package/dist/commands/push.js +185 -75
- package/dist/commands/push.js.map +2 -2
- package/dist/commands/run.js +31 -30
- package/dist/commands/run.js.map +2 -2
- package/dist/commands/status.js +26 -33
- package/dist/commands/status.js.map +2 -2
- package/dist/commands/variables.js +2 -2
- package/dist/commands/variables.js.map +2 -2
- package/dist/index.js +5 -3
- package/dist/index.js.map +2 -2
- package/dist/mcp/tools/appTools.js +6 -20
- package/dist/mcp/tools/appTools.js.map +2 -2
- package/dist/mcp/tools/authTools.js +2 -1
- package/dist/mcp/tools/authTools.js.map +2 -2
- package/dist/mcp/tools/cellTools.js +2 -10
- package/dist/mcp/tools/cellTools.js.map +2 -2
- package/dist/mcp/tools/dashboardTools.js +12 -23
- package/dist/mcp/tools/dashboardTools.js.map +2 -2
- package/dist/mcp/tools/dataTools.js +5 -16
- package/dist/mcp/tools/dataTools.js.map +2 -2
- package/dist/mcp/tools/folderTools.js +3 -11
- package/dist/mcp/tools/folderTools.js.map +2 -2
- package/dist/mcp/tools/modelTools.js +61 -69
- package/dist/mcp/tools/modelTools.js.map +2 -2
- package/dist/mcp/tools/runTools.js +3 -8
- package/dist/mcp/tools/runTools.js.map +2 -2
- package/dist/mcp/tools/sheetTools.js +11 -22
- package/dist/mcp/tools/sheetTools.js.map +2 -2
- package/dist/mcp/tools/syncTools.js +132 -47
- package/dist/mcp/tools/syncTools.js.map +2 -2
- package/dist/mcp/utils/helpers.js +2 -2
- package/dist/mcp/utils/helpers.js.map +2 -2
- package/dist/services/appSyncService.js +3 -2
- package/dist/services/appSyncService.js.map +2 -2
- package/dist/services/farseerApi.js +120 -72
- package/dist/services/farseerApi.js.map +2 -2
- package/dist/services/farseerFactory.js +1 -1
- package/dist/services/farseerFactory.js.map +2 -2
- package/dist/services/farseerService.js +87 -47
- package/dist/services/farseerService.js.map +2 -2
- package/dist/services/syncService.js +322 -182
- package/dist/services/syncService.js.map +3 -3
- package/dist/utils/cliOptions.js +36 -0
- package/dist/utils/cliOptions.js.map +7 -0
- package/dist/utils/errorFormatter.js +152 -0
- package/dist/utils/errorFormatter.js.map +7 -0
- package/dist/utils/fileLogger.js +13 -0
- package/dist/utils/fileLogger.js.map +2 -2
- package/dist/utils/fileValidation.js +180 -0
- package/dist/utils/fileValidation.js.map +7 -0
- package/dist/utils/helpers.js +85 -14
- package/dist/utils/helpers.js.map +2 -2
- package/docs/cli-guide.md +49 -4
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/services/appSyncService.ts"],
|
|
4
|
-
"sourcesContent": ["import * as fs from 'fs';\nimport * as path from 'path';\nimport { RemoteApp, AppArgument } from './farseerApi';\nimport { IFarseerClient } from './farseerFactory';\nimport { getTenantAppsDir, ensureDirectoryExists, fetchWithConcurrency } from '../utils/helpers';\nimport { logger } from '../utils/logger';\n\n// Local app config format (stored in apps/*.json)\nexport interface LocalAppConfig {\n name: string;\n description: string;\n entrypoint: string | null; // Script filename (e.g., \"index.ts\")\n scripts: string[]; // List of script filenames\n arguments: {\n name: string;\n defaultValue: string;\n }[];\n _remote?: {\n id: number;\n reference: string;\n };\n}\n\nexport interface AppSyncResult {\n created: string[];\n updated: string[];\n deleted: string[];\n unchanged: string[];\n}\n\nexport interface AppSyncStatus {\n newLocal: string[]; // Local apps not on remote\n newRemote: string[]; // Remote apps not locally\n modified: string[]; // Apps that differ\n synced: string[]; // Apps in sync\n}\n\n/**\n * Sanitize Croatian diacritics and other special characters to ASCII equivalents\n */\nfunction sanitizeDiacritics(text: string): string {\n const diacriticMap: Record<string, string> = {\n // Croatian\n \u010D: 'c',\n \u010C: 'C',\n \u0107: 'c',\n \u0106: 'C',\n \u0161: 's',\n \u0160: 'S',\n \u017E: 'z',\n \u017D: 'Z',\n \u0111: 'd',\n \u0110: 'D',\n // German/Other common\n \u00E4: 'a',\n \u00C4: 'A',\n \u00F6: 'o',\n \u00D6: 'O',\n \u00FC: 'u',\n \u00DC: 'U',\n \u00DF: 'ss',\n // Polish\n \u0105: 'a',\n \u0104: 'A',\n \u0119: 'e',\n \u0118: 'E',\n \u0142: 'l',\n \u0141: 'L',\n \u0144: 'n',\n \u0143: 'N',\n \u00F3: 'o',\n \u00D3: 'O',\n \u015B: 's',\n \u015A: 'S',\n \u017A: 'z',\n \u0179: 'Z',\n \u017C: 'z',\n \u017B: 'Z',\n // French/Spanish\n \u00E0: 'a',\n \u00E1: 'a',\n \u00E2: 'a',\n \u00E8: 'e',\n \u00E9: 'e',\n \u00EA: 'e',\n \u00EB: 'e',\n \u00EC: 'i',\n \u00ED: 'i',\n \u00EE: 'i',\n \u00EF: 'i',\n \u00F2: 'o',\n \u00F4: 'o',\n \u00F9: 'u',\n \u00FA: 'u',\n \u00FB: 'u',\n \u00F1: 'n',\n \u00D1: 'N',\n \u00E7: 'c',\n \u00C7: 'C',\n };\n\n return text\n .split('')\n .map((char) => diacriticMap[char] || char)\n .join('');\n}\n\n/**\n * Service for syncing app configurations between local JSON files and remote Farseer instance\n */\nexport class AppSyncService {\n private api: IFarseerClient;\n private appsDir: string;\n\n constructor(tenant: string, api: IFarseerClient) {\n this.api = api;\n this.appsDir = getTenantAppsDir(tenant);\n }\n\n /**\n * Get filename for an app (keep original name, just sanitize for filesystem)\n */\n private getAppFilename(name: string): string {\n return (\n sanitizeDiacritics(name)\n .replace(/[<>:\"/\\\\|?*]/g, '') // Remove invalid filename characters\n .trim() + '.json'\n );\n }\n\n /**\n * Load all local app configs\n */\n loadLocalApps(): Map<string, LocalAppConfig> {\n const apps = new Map<string, LocalAppConfig>();\n\n if (!fs.existsSync(this.appsDir)) {\n return apps;\n }\n\n const files = fs.readdirSync(this.appsDir).filter((f) => f.endsWith('.json'));\n\n for (const file of files) {\n try {\n const content = fs.readFileSync(path.join(this.appsDir, file), 'utf-8');\n const config = JSON.parse(content) as LocalAppConfig;\n apps.set(config.name.toLowerCase(), config);\n } catch {\n // Skip invalid files\n }\n }\n\n return apps;\n }\n\n /**\n * Save a local app config\n */\n saveLocalApp(config: LocalAppConfig): void {\n ensureDirectoryExists(this.appsDir);\n const filename = this.getAppFilename(config.name);\n const filePath = path.join(this.appsDir, filename);\n fs.writeFileSync(filePath, JSON.stringify(config, null, 2), 'utf-8');\n }\n\n /**\n * Delete a local app config\n */\n deleteLocalApp(name: string): boolean {\n const filename = this.getAppFilename(name);\n const filePath = path.join(this.appsDir, filename);\n\n if (fs.existsSync(filePath)) {\n fs.unlinkSync(filePath);\n return true;\n }\n return false;\n }\n\n /**\n * Convert remote app to local config format\n */\n private remoteToLocal(remote: RemoteApp, reference: string): LocalAppConfig {\n const scriptFiles = remote.scriptFiles ?? [];\n const mainScript = scriptFiles.find((s) => s.id === remote.mainScriptFileId);\n\n return {\n name: remote.name,\n description: remote.description || '',\n entrypoint: mainScript?.name || null,\n scripts: scriptFiles.map((s) => s.name),\n arguments: remote.expectedArguments.map((a) => ({\n name: a.name,\n defaultValue: a.defaultValue,\n })),\n _remote: {\n id: remote.id,\n reference: reference,\n },\n };\n }\n\n /**\n * Check if local and remote app configs are equivalent\n */\n private areAppsEqual(local: LocalAppConfig, remote: RemoteApp): boolean {\n // Compare name\n if (local.name !== remote.name) return false;\n\n // Compare description\n if ((local.description || '') !== (remote.description || '')) return false;\n\n // Compare entrypoint\n const remoteScriptFiles = remote.scriptFiles ?? [];\n const remoteEntrypoint = remoteScriptFiles.find((s) => s.id === remote.mainScriptFileId)?.name || null;\n if (local.entrypoint !== remoteEntrypoint) return false;\n\n // Compare scripts\n const localScripts = [...local.scripts].sort();\n const remoteScripts = [...remoteScriptFiles.map((s) => s.name)].sort();\n if (JSON.stringify(localScripts) !== JSON.stringify(remoteScripts)) return false;\n\n // Compare arguments\n const localArgs = local.arguments.map((a) => `${a.name}=${a.defaultValue}`).sort();\n const remoteArgs = remote.expectedArguments.map((a) => `${a.name}=${a.defaultValue}`).sort();\n if (JSON.stringify(localArgs) !== JSON.stringify(remoteArgs)) return false;\n\n return true;\n }\n\n /**\n * Pull apps from remote and save locally\n */\n async pull(): Promise<AppSyncResult> {\n const result: AppSyncResult = {\n created: [],\n updated: [],\n deleted: [],\n unchanged: [],\n };\n\n // Load local apps\n const localApps = this.loadLocalApps();\n\n // Fetch remote apps\n const remoteAppList = await this.api.listApps();\n const remoteApps = new Map<string, { app: RemoteApp; reference: string }>();\n\n // Fetch app details in parallel with concurrency limit\n logger.dim(`Fetching ${remoteAppList.length} apps in parallel...`);\n const appDetails = await fetchWithConcurrency(\n remoteAppList,\n async (item, index) => {\n const app = await this.api.getApp(item.reference);\n // Show progress every 10 apps\n if ((index + 1) % 10 === 0 || index === remoteAppList.length - 1) {\n const stream = process.env.FARSEER_MCP === '1' ? process.stderr : process.stdout;\n stream.write(`\\r Progress: ${index + 1}/${remoteAppList.length} apps`);\n }\n return { app, reference: item.reference };\n },\n 15,\n );\n // Clear progress line\n if (remoteAppList.length > 0) {\n const stream = process.env.FARSEER_MCP === '1' ? process.stderr : process.stdout;\n stream.write('\\r' + ' '.repeat(50) + '\\r');\n }\n\n for (const { app, reference } of appDetails) {\n if (app) {\n remoteApps.set(app.name.toLowerCase(), { app, reference });\n }\n }\n\n // Process remote apps\n for (const [key, { app, reference }] of remoteApps) {\n const localConfig = this.remoteToLocal(app, reference);\n const existingLocal = localApps.get(key);\n\n if (!existingLocal) {\n // New app from remote\n this.saveLocalApp(localConfig);\n result.created.push(app.name);\n } else if (!this.areAppsEqual(existingLocal, app)) {\n // App changed on remote - update local\n this.saveLocalApp(localConfig);\n result.updated.push(app.name);\n } else {\n result.unchanged.push(app.name);\n }\n }\n\n // Check for apps deleted on remote\n for (const [key, local] of localApps) {\n if (!remoteApps.has(key) && local._remote) {\n // App was synced before but now deleted on remote\n this.deleteLocalApp(local.name);\n result.deleted.push(local.name);\n }\n }\n\n return result;\n }\n\n /**\n * Push local apps to remote\n */\n async push(): Promise<AppSyncResult> {\n const result: AppSyncResult = {\n created: [],\n updated: [],\n deleted: [],\n unchanged: [],\n };\n\n // Load local apps\n const localApps = this.loadLocalApps();\n\n // Fetch remote apps\n const remoteAppList = await this.api.listApps();\n const remoteApps = new Map<string, { app: RemoteApp; reference: string }>();\n\n // Fetch app details in parallel with concurrency limit\n const appDetails = await fetchWithConcurrency(\n remoteAppList,\n async (item) => {\n const app = await this.api.getApp(item.reference);\n return { app, reference: item.reference };\n },\n 15,\n );\n\n for (const { app, reference } of appDetails) {\n if (app) {\n remoteApps.set(app.name.toLowerCase(), { app, reference });\n }\n }\n\n // Get available scripts for ID lookup\n // Build maps for both path-based and filename-based lookup (backward compatibility)\n const availableScripts = await this.api.getScriptFiles();\n const scriptIdByPath = new Map<string, string>();\n const scriptIdByName = new Map<string, string>();\n\n for (const s of availableScripts) {\n // s.name now contains full path (e.g., \"Scripts/test.ts\")\n const pathKey = s.name.toLowerCase();\n const filenameKey = s.name.split('/').pop()?.toLowerCase() || pathKey;\n\n scriptIdByPath.set(pathKey, s.id);\n // For filename lookup, only set if not already set (first match wins for ambiguous names)\n if (!scriptIdByName.has(filenameKey)) {\n scriptIdByName.set(filenameKey, s.id);\n }\n }\n\n // Helper to find script ID by path or filename\n const findScriptId = (scriptRef: string): string | undefined => {\n const key = scriptRef.toLowerCase();\n // Try exact path match first\n const byPath = scriptIdByPath.get(key);\n if (byPath) return byPath;\n // Try with Scripts/ prefix\n const withPrefix = scriptIdByPath.get(`scripts/${key}`);\n if (withPrefix) return withPrefix;\n // Fall back to filename match\n return scriptIdByName.get(key.split('/').pop() || key);\n };\n\n // Process local apps\n for (const [key, local] of localApps) {\n const remote = remoteApps.get(key);\n\n if (!remote) {\n // New local app - create on remote\n try {\n const created = await this.api.createApp(local.name);\n\n // Update with config (API requires name and description)\n const update = this.buildUpdatePayload(local, findScriptId);\n update.name = local.name;\n update.description = local.description;\n await this.api.updateApp(created.id.toString(), update);\n\n // Update local with remote ID\n local._remote = {\n id: created.id,\n reference: created.id.toString(),\n };\n this.saveLocalApp(local);\n\n result.created.push(local.name);\n } catch (error) {\n console.error(`Failed to create app ${local.name}:`, error);\n }\n } else if (!this.areAppsEqual(local, remote.app)) {\n // App differs - update remote\n try {\n const update = this.buildUpdatePayload(local, findScriptId);\n update.name = local.name;\n update.description = local.description;\n\n await this.api.updateApp(remote.reference, update);\n result.updated.push(local.name);\n } catch (error) {\n console.error(`Failed to update app ${local.name}:`, error);\n }\n } else {\n result.unchanged.push(local.name);\n }\n }\n\n // Note: We don't auto-delete remote apps when deleted locally\n // User must use \"farseer app delete\" explicitly\n\n return result;\n }\n\n /**\n * Build update payload for API\n */\n private buildUpdatePayload(\n local: LocalAppConfig,\n findScriptId: (scriptRef: string) => string | undefined,\n ): {\n name?: string;\n description?: string;\n expectedArguments?: AppArgument[];\n mainScriptFileId?: string | null;\n scriptFileIds?: string[];\n } {\n const update: {\n name?: string;\n description?: string;\n expectedArguments?: AppArgument[];\n mainScriptFileId?: string | null;\n scriptFileIds?: string[];\n } = {};\n\n // Arguments\n if (local.arguments.length > 0) {\n update.expectedArguments = local.arguments.map((a) => ({\n name: a.name,\n type: 'variable' as const,\n defaultValue: a.defaultValue,\n }));\n }\n\n // Scripts - lookup by path or filename\n if (local.scripts.length > 0) {\n const scriptIds: string[] = [];\n for (const scriptRef of local.scripts) {\n const id = findScriptId(scriptRef);\n if (id) {\n scriptIds.push(id);\n }\n }\n if (scriptIds.length > 0) {\n update.scriptFileIds = scriptIds;\n }\n }\n\n // Entrypoint - lookup by path or filename\n if (local.entrypoint) {\n const entrypointId = findScriptId(local.entrypoint);\n if (entrypointId) {\n update.mainScriptFileId = entrypointId;\n }\n }\n\n return update;\n }\n\n /**\n * Get sync status without making changes\n */\n async getStatus(): Promise<AppSyncStatus> {\n const status: AppSyncStatus = {\n newLocal: [],\n newRemote: [],\n modified: [],\n synced: [],\n };\n\n // Load local apps\n const localApps = this.loadLocalApps();\n\n // Fetch remote apps\n const remoteAppList = await this.api.listApps();\n const remoteApps = new Map<string, { app: RemoteApp; reference: string }>();\n\n // Fetch app details in parallel with concurrency limit\n const appDetails = await fetchWithConcurrency(\n remoteAppList,\n async (item) => {\n const app = await this.api.getApp(item.reference);\n return { app, reference: item.reference };\n },\n 15,\n );\n\n for (const { app, reference } of appDetails) {\n if (app) {\n remoteApps.set(app.name.toLowerCase(), { app, reference });\n }\n }\n\n // Check local apps\n for (const [key, local] of localApps) {\n const remote = remoteApps.get(key);\n\n if (!remote) {\n status.newLocal.push(local.name);\n } else if (!this.areAppsEqual(local, remote.app)) {\n status.modified.push(local.name);\n } else {\n status.synced.push(local.name);\n }\n }\n\n // Check for new remote apps\n for (const [key, { app }] of remoteApps) {\n if (!localApps.has(key)) {\n status.newRemote.push(app.name);\n }\n }\n\n return status;\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAoB;AACpB,WAAsB;AAGtB,qBAA8E;AAC9E,oBAAuB;
|
|
4
|
+
"sourcesContent": ["import * as fs from 'fs';\nimport * as path from 'path';\nimport { RemoteApp, AppArgument } from './farseerApi';\nimport { IFarseerClient } from './farseerFactory';\nimport { getTenantAppsDir, ensureDirectoryExists, fetchWithConcurrency } from '../utils/helpers';\nimport { logger } from '../utils/logger';\nimport { formatClientError } from '../utils/errorFormatter';\n\n// Local app config format (stored in apps/*.json)\nexport interface LocalAppConfig {\n name: string;\n description: string;\n entrypoint: string | null; // Script filename (e.g., \"index.ts\")\n scripts: string[]; // List of script filenames\n arguments: {\n name: string;\n defaultValue: string;\n }[];\n _remote?: {\n id: number;\n reference: string;\n };\n}\n\nexport interface AppSyncResult {\n created: string[];\n updated: string[];\n deleted: string[];\n unchanged: string[];\n}\n\nexport interface AppSyncStatus {\n newLocal: string[]; // Local apps not on remote\n newRemote: string[]; // Remote apps not locally\n modified: string[]; // Apps that differ\n synced: string[]; // Apps in sync\n}\n\n/**\n * Sanitize Croatian diacritics and other special characters to ASCII equivalents\n */\nfunction sanitizeDiacritics(text: string): string {\n const diacriticMap: Record<string, string> = {\n // Croatian\n \u010D: 'c',\n \u010C: 'C',\n \u0107: 'c',\n \u0106: 'C',\n \u0161: 's',\n \u0160: 'S',\n \u017E: 'z',\n \u017D: 'Z',\n \u0111: 'd',\n \u0110: 'D',\n // German/Other common\n \u00E4: 'a',\n \u00C4: 'A',\n \u00F6: 'o',\n \u00D6: 'O',\n \u00FC: 'u',\n \u00DC: 'U',\n \u00DF: 'ss',\n // Polish\n \u0105: 'a',\n \u0104: 'A',\n \u0119: 'e',\n \u0118: 'E',\n \u0142: 'l',\n \u0141: 'L',\n \u0144: 'n',\n \u0143: 'N',\n \u00F3: 'o',\n \u00D3: 'O',\n \u015B: 's',\n \u015A: 'S',\n \u017A: 'z',\n \u0179: 'Z',\n \u017C: 'z',\n \u017B: 'Z',\n // French/Spanish\n \u00E0: 'a',\n \u00E1: 'a',\n \u00E2: 'a',\n \u00E8: 'e',\n \u00E9: 'e',\n \u00EA: 'e',\n \u00EB: 'e',\n \u00EC: 'i',\n \u00ED: 'i',\n \u00EE: 'i',\n \u00EF: 'i',\n \u00F2: 'o',\n \u00F4: 'o',\n \u00F9: 'u',\n \u00FA: 'u',\n \u00FB: 'u',\n \u00F1: 'n',\n \u00D1: 'N',\n \u00E7: 'c',\n \u00C7: 'C',\n };\n\n return text\n .split('')\n .map((char) => diacriticMap[char] || char)\n .join('');\n}\n\n/**\n * Service for syncing app configurations between local JSON files and remote Farseer instance\n */\nexport class AppSyncService {\n private api: IFarseerClient;\n private appsDir: string;\n\n constructor(tenant: string, api: IFarseerClient) {\n this.api = api;\n this.appsDir = getTenantAppsDir(tenant);\n }\n\n /**\n * Get filename for an app (keep original name, just sanitize for filesystem)\n */\n private getAppFilename(name: string): string {\n return (\n sanitizeDiacritics(name)\n .replace(/[<>:\"/\\\\|?*]/g, '') // Remove invalid filename characters\n .trim() + '.json'\n );\n }\n\n /**\n * Load all local app configs\n */\n loadLocalApps(): Map<string, LocalAppConfig> {\n const apps = new Map<string, LocalAppConfig>();\n\n if (!fs.existsSync(this.appsDir)) {\n return apps;\n }\n\n const files = fs.readdirSync(this.appsDir).filter((f) => f.endsWith('.json'));\n\n for (const file of files) {\n try {\n const content = fs.readFileSync(path.join(this.appsDir, file), 'utf-8');\n const config = JSON.parse(content) as LocalAppConfig;\n apps.set(config.name.toLowerCase(), config);\n } catch {\n // Skip invalid files\n }\n }\n\n return apps;\n }\n\n /**\n * Save a local app config\n */\n saveLocalApp(config: LocalAppConfig): void {\n ensureDirectoryExists(this.appsDir);\n const filename = this.getAppFilename(config.name);\n const filePath = path.join(this.appsDir, filename);\n fs.writeFileSync(filePath, JSON.stringify(config, null, 2), 'utf-8');\n }\n\n /**\n * Delete a local app config\n */\n deleteLocalApp(name: string): boolean {\n const filename = this.getAppFilename(name);\n const filePath = path.join(this.appsDir, filename);\n\n if (fs.existsSync(filePath)) {\n fs.unlinkSync(filePath);\n return true;\n }\n return false;\n }\n\n /**\n * Convert remote app to local config format\n */\n private remoteToLocal(remote: RemoteApp, reference: string): LocalAppConfig {\n const scriptFiles = remote.scriptFiles ?? [];\n const mainScript = scriptFiles.find((s) => s.id === remote.mainScriptFileId);\n\n return {\n name: remote.name,\n description: remote.description || '',\n entrypoint: mainScript?.name || null,\n scripts: scriptFiles.map((s) => s.name),\n arguments: remote.expectedArguments.map((a) => ({\n name: a.name,\n defaultValue: a.defaultValue,\n })),\n _remote: {\n id: remote.id,\n reference: reference,\n },\n };\n }\n\n /**\n * Check if local and remote app configs are equivalent\n */\n private areAppsEqual(local: LocalAppConfig, remote: RemoteApp): boolean {\n // Compare name\n if (local.name !== remote.name) return false;\n\n // Compare description\n if ((local.description || '') !== (remote.description || '')) return false;\n\n // Compare entrypoint\n const remoteScriptFiles = remote.scriptFiles ?? [];\n const remoteEntrypoint = remoteScriptFiles.find((s) => s.id === remote.mainScriptFileId)?.name || null;\n if (local.entrypoint !== remoteEntrypoint) return false;\n\n // Compare scripts\n const localScripts = [...local.scripts].sort();\n const remoteScripts = [...remoteScriptFiles.map((s) => s.name)].sort();\n if (JSON.stringify(localScripts) !== JSON.stringify(remoteScripts)) return false;\n\n // Compare arguments\n const localArgs = local.arguments.map((a) => `${a.name}=${a.defaultValue}`).sort();\n const remoteArgs = remote.expectedArguments.map((a) => `${a.name}=${a.defaultValue}`).sort();\n if (JSON.stringify(localArgs) !== JSON.stringify(remoteArgs)) return false;\n\n return true;\n }\n\n /**\n * Pull apps from remote and save locally\n */\n async pull(): Promise<AppSyncResult> {\n const result: AppSyncResult = {\n created: [],\n updated: [],\n deleted: [],\n unchanged: [],\n };\n\n // Load local apps\n const localApps = this.loadLocalApps();\n\n // Fetch remote apps\n const remoteAppList = await this.api.listApps();\n const remoteApps = new Map<string, { app: RemoteApp; reference: string }>();\n\n // Fetch app details in parallel with concurrency limit\n logger.dim(`Fetching ${remoteAppList.length} apps in parallel...`);\n const appDetails = await fetchWithConcurrency(\n remoteAppList,\n async (item, index) => {\n const app = await this.api.getApp(item.reference);\n // Show progress every 10 apps\n if ((index + 1) % 10 === 0 || index === remoteAppList.length - 1) {\n const stream = process.env.FARSEER_MCP === '1' ? process.stderr : process.stdout;\n stream.write(`\\r Progress: ${index + 1}/${remoteAppList.length} apps`);\n }\n return { app, reference: item.reference };\n },\n 15,\n );\n // Clear progress line\n if (remoteAppList.length > 0) {\n const stream = process.env.FARSEER_MCP === '1' ? process.stderr : process.stdout;\n stream.write('\\r' + ' '.repeat(50) + '\\r');\n }\n\n for (const { app, reference } of appDetails) {\n if (app) {\n remoteApps.set(app.name.toLowerCase(), { app, reference });\n }\n }\n\n // Process remote apps\n for (const [key, { app, reference }] of remoteApps) {\n const localConfig = this.remoteToLocal(app, reference);\n const existingLocal = localApps.get(key);\n\n if (!existingLocal) {\n // New app from remote\n this.saveLocalApp(localConfig);\n result.created.push(app.name);\n } else if (!this.areAppsEqual(existingLocal, app)) {\n // App changed on remote - update local\n this.saveLocalApp(localConfig);\n result.updated.push(app.name);\n } else {\n result.unchanged.push(app.name);\n }\n }\n\n // Check for apps deleted on remote\n for (const [key, local] of localApps) {\n if (!remoteApps.has(key) && local._remote) {\n // App was synced before but now deleted on remote\n this.deleteLocalApp(local.name);\n result.deleted.push(local.name);\n }\n }\n\n return result;\n }\n\n /**\n * Push local apps to remote\n */\n async push(): Promise<AppSyncResult> {\n const result: AppSyncResult = {\n created: [],\n updated: [],\n deleted: [],\n unchanged: [],\n };\n\n // Load local apps\n const localApps = this.loadLocalApps();\n\n // Fetch remote apps\n const remoteAppList = await this.api.listApps();\n const remoteApps = new Map<string, { app: RemoteApp; reference: string }>();\n\n // Fetch app details in parallel with concurrency limit\n const appDetails = await fetchWithConcurrency(\n remoteAppList,\n async (item) => {\n const app = await this.api.getApp(item.reference);\n return { app, reference: item.reference };\n },\n 15,\n );\n\n for (const { app, reference } of appDetails) {\n if (app) {\n remoteApps.set(app.name.toLowerCase(), { app, reference });\n }\n }\n\n // Get available scripts for ID lookup\n // Build maps for both path-based and filename-based lookup (backward compatibility)\n const availableScripts = await this.api.getScriptFiles();\n const scriptIdByPath = new Map<string, string>();\n const scriptIdByName = new Map<string, string>();\n\n for (const s of availableScripts) {\n // s.name now contains full path (e.g., \"Scripts/test.ts\")\n const pathKey = s.name.toLowerCase();\n const filenameKey = s.name.split('/').pop()?.toLowerCase() || pathKey;\n\n scriptIdByPath.set(pathKey, s.id);\n // For filename lookup, only set if not already set (first match wins for ambiguous names)\n if (!scriptIdByName.has(filenameKey)) {\n scriptIdByName.set(filenameKey, s.id);\n }\n }\n\n // Helper to find script ID by path or filename\n const findScriptId = (scriptRef: string): string | undefined => {\n const key = scriptRef.toLowerCase();\n // Try exact path match first\n const byPath = scriptIdByPath.get(key);\n if (byPath) return byPath;\n // Try with Scripts/ prefix\n const withPrefix = scriptIdByPath.get(`scripts/${key}`);\n if (withPrefix) return withPrefix;\n // Fall back to filename match\n return scriptIdByName.get(key.split('/').pop() || key);\n };\n\n // Process local apps\n for (const [key, local] of localApps) {\n const remote = remoteApps.get(key);\n\n if (!remote) {\n // New local app - create on remote\n try {\n const created = await this.api.createApp(local.name);\n\n // Update with config (API requires name and description)\n const update = this.buildUpdatePayload(local, findScriptId);\n update.name = local.name;\n update.description = local.description;\n await this.api.updateApp(created.id.toString(), update);\n\n // Update local with remote ID\n local._remote = {\n id: created.id,\n reference: created.id.toString(),\n };\n this.saveLocalApp(local);\n\n result.created.push(local.name);\n } catch (error) {\n logger.error(`Failed to create app ${local.name}: ${await formatClientError(error)}`);\n }\n } else if (!this.areAppsEqual(local, remote.app)) {\n // App differs - update remote\n try {\n const update = this.buildUpdatePayload(local, findScriptId);\n update.name = local.name;\n update.description = local.description;\n\n await this.api.updateApp(remote.reference, update);\n result.updated.push(local.name);\n } catch (error) {\n logger.error(`Failed to update app ${local.name}: ${await formatClientError(error)}`);\n }\n } else {\n result.unchanged.push(local.name);\n }\n }\n\n // Note: We don't auto-delete remote apps when deleted locally\n // User must use \"farseer app delete\" explicitly\n\n return result;\n }\n\n /**\n * Build update payload for API\n */\n private buildUpdatePayload(\n local: LocalAppConfig,\n findScriptId: (scriptRef: string) => string | undefined,\n ): {\n name?: string;\n description?: string;\n expectedArguments?: AppArgument[];\n mainScriptFileId?: string | null;\n scriptFileIds?: string[];\n } {\n const update: {\n name?: string;\n description?: string;\n expectedArguments?: AppArgument[];\n mainScriptFileId?: string | null;\n scriptFileIds?: string[];\n } = {};\n\n // Arguments\n if (local.arguments.length > 0) {\n update.expectedArguments = local.arguments.map((a) => ({\n name: a.name,\n type: 'variable' as const,\n defaultValue: a.defaultValue,\n }));\n }\n\n // Scripts - lookup by path or filename\n if (local.scripts.length > 0) {\n const scriptIds: string[] = [];\n for (const scriptRef of local.scripts) {\n const id = findScriptId(scriptRef);\n if (id) {\n scriptIds.push(id);\n }\n }\n if (scriptIds.length > 0) {\n update.scriptFileIds = scriptIds;\n }\n }\n\n // Entrypoint - lookup by path or filename\n if (local.entrypoint) {\n const entrypointId = findScriptId(local.entrypoint);\n if (entrypointId) {\n update.mainScriptFileId = entrypointId;\n }\n }\n\n return update;\n }\n\n /**\n * Get sync status without making changes\n */\n async getStatus(): Promise<AppSyncStatus> {\n const status: AppSyncStatus = {\n newLocal: [],\n newRemote: [],\n modified: [],\n synced: [],\n };\n\n // Load local apps\n const localApps = this.loadLocalApps();\n\n // Fetch remote apps\n const remoteAppList = await this.api.listApps();\n const remoteApps = new Map<string, { app: RemoteApp; reference: string }>();\n\n // Fetch app details in parallel with concurrency limit\n const appDetails = await fetchWithConcurrency(\n remoteAppList,\n async (item) => {\n const app = await this.api.getApp(item.reference);\n return { app, reference: item.reference };\n },\n 15,\n );\n\n for (const { app, reference } of appDetails) {\n if (app) {\n remoteApps.set(app.name.toLowerCase(), { app, reference });\n }\n }\n\n // Check local apps\n for (const [key, local] of localApps) {\n const remote = remoteApps.get(key);\n\n if (!remote) {\n status.newLocal.push(local.name);\n } else if (!this.areAppsEqual(local, remote.app)) {\n status.modified.push(local.name);\n } else {\n status.synced.push(local.name);\n }\n }\n\n // Check for new remote apps\n for (const [key, { app }] of remoteApps) {\n if (!localApps.has(key)) {\n status.newRemote.push(app.name);\n }\n }\n\n return status;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAoB;AACpB,WAAsB;AAGtB,qBAA8E;AAC9E,oBAAuB;AACvB,4BAAkC;AAmClC,SAAS,mBAAmB,MAAsB;AAC9C,QAAM,eAAuC;AAAA;AAAA,IAEzC,QAAG;AAAA,IACH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cAAM,MAAM,MAAM,KAAK,IAAI,OAAO,KAAK,SAAS;AAChD,eAAO,EAAE,KAAK,WAAW,KAAK,UAAU;AAAA,MAC5C;AAAA,MACA;AAAA,IACJ;AAEA,eAAW,EAAE,KAAK,UAAU,KAAK,YAAY;AACzC,UAAI,KAAK;AACL,mBAAW,IAAI,IAAI,KAAK,YAAY,GAAG,EAAE,KAAK,UAAU,CAAC;AAAA,MAC7D;AAAA,IACJ;AAGA,eAAW,CAAC,KAAK,KAAK,KAAK,WAAW;AAClC,YAAM,SAAS,WAAW,IAAI,GAAG;AAEjC,UAAI,CAAC,QAAQ;AACT,eAAO,SAAS,KAAK,MAAM,IAAI;AAAA,MACnC,WAAW,CAAC,KAAK,aAAa,OAAO,OAAO,GAAG,GAAG;AAC9C,eAAO,SAAS,KAAK,MAAM,IAAI;AAAA,MACnC,OAAO;AACH,eAAO,OAAO,KAAK,MAAM,IAAI;AAAA,MACjC;AAAA,IACJ;AAGA,eAAW,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,YAAY;AACrC,UAAI,CAAC,UAAU,IAAI,GAAG,GAAG;AACrB,eAAO,UAAU,KAAK,IAAI,IAAI;AAAA,MAClC;AAAA,IACJ;AAEA,WAAO;AAAA,EACX;AACJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -28,31 +28,16 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var farseerApi_exports = {};
|
|
30
30
|
__export(farseerApi_exports, {
|
|
31
|
-
FarseerApi: () => FarseerApi
|
|
31
|
+
FarseerApi: () => FarseerApi,
|
|
32
|
+
loadDimensionTableViaEntitiesApi: () => loadDimensionTableViaEntitiesApi
|
|
32
33
|
});
|
|
33
34
|
module.exports = __toCommonJS(farseerApi_exports);
|
|
34
35
|
var import_axios = __toESM(require("axios"));
|
|
35
36
|
var farseer = __toESM(require("farseer-client"));
|
|
36
37
|
var import_configService = require("./configService");
|
|
37
38
|
var import_farseerService = require("./farseerService");
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const status = error.response?.status;
|
|
41
|
-
const statusText = error.response?.statusText;
|
|
42
|
-
const data = error.response?.data;
|
|
43
|
-
const parts = [];
|
|
44
|
-
if (status) parts.push(`HTTP ${status}`);
|
|
45
|
-
if (statusText) parts.push(statusText);
|
|
46
|
-
if (data) {
|
|
47
|
-
const body = typeof data === "string" ? data : JSON.stringify(data);
|
|
48
|
-
if (body && body !== "{}") parts.push(body);
|
|
49
|
-
}
|
|
50
|
-
if (parts.length > 0) return parts.join(" \u2014 ");
|
|
51
|
-
return error.message || "Unknown axios error";
|
|
52
|
-
}
|
|
53
|
-
if (error instanceof Error) return error.message;
|
|
54
|
-
return String(error);
|
|
55
|
-
}
|
|
39
|
+
var import_errorFormatter = require("../utils/errorFormatter");
|
|
40
|
+
var import_logger = require("../utils/logger");
|
|
56
41
|
class FarseerApi {
|
|
57
42
|
constructor(accessToken, tenant, tenantId) {
|
|
58
43
|
this.isRefreshing = false;
|
|
@@ -190,20 +175,14 @@ class FarseerApi {
|
|
|
190
175
|
}
|
|
191
176
|
}
|
|
192
177
|
} catch (error) {
|
|
193
|
-
if (import_axios.default.isAxiosError(error)) {
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
console.error(`API Error: ${status} "${message}" (path: ${folderPath.join("/")})`);
|
|
198
|
-
if (data?.code === "Forbidden") {
|
|
199
|
-
const errorMessage = data?.message || "Access denied";
|
|
200
|
-
throw new Error(
|
|
201
|
-
`Access denied: ${errorMessage}
|
|
178
|
+
if (import_axios.default.isAxiosError(error) && error.response?.data?.code === "Forbidden") {
|
|
179
|
+
const errorMessage = error.response.data?.message || "Access denied";
|
|
180
|
+
throw new Error(
|
|
181
|
+
`Access denied: ${errorMessage}
|
|
202
182
|
You may need to use --tenant-id to specify a different tenant ID.`
|
|
203
|
-
|
|
204
|
-
}
|
|
183
|
+
);
|
|
205
184
|
}
|
|
206
|
-
|
|
185
|
+
throw await (0, import_errorFormatter.toError)(error, `Failed to list files in ${folderPath.join("/") || "root"}`);
|
|
207
186
|
}
|
|
208
187
|
return files;
|
|
209
188
|
}
|
|
@@ -223,7 +202,7 @@ You may need to use --tenant-id to specify a different tenant ID.`
|
|
|
223
202
|
await this.ensureFolderPath(folderPath);
|
|
224
203
|
const folder = await this.getItemByPath(folderPath);
|
|
225
204
|
const formData = new FormData();
|
|
226
|
-
const blob =
|
|
205
|
+
const blob = new Blob([content], { type: "application/octet-stream" });
|
|
227
206
|
formData.append("file", blob, fileName);
|
|
228
207
|
formData.append("category", "GENERAL");
|
|
229
208
|
formData.append("folderId", folder.id.toString());
|
|
@@ -234,12 +213,12 @@ You may need to use --tenant-id to specify a different tenant ID.`
|
|
|
234
213
|
}
|
|
235
214
|
});
|
|
236
215
|
} catch (error) {
|
|
237
|
-
throw
|
|
216
|
+
throw await (0, import_errorFormatter.toError)(error, `Failed to create file "${fileName}"`);
|
|
238
217
|
}
|
|
239
218
|
}
|
|
240
219
|
async updateFile(reference, content, fileName) {
|
|
241
220
|
const formData = new FormData();
|
|
242
|
-
const blob =
|
|
221
|
+
const blob = new Blob([content], { type: "application/octet-stream" });
|
|
243
222
|
formData.append("file", blob, fileName);
|
|
244
223
|
try {
|
|
245
224
|
await this.client.put(`/farseerFiles/${reference}`, formData, {
|
|
@@ -248,14 +227,14 @@ You may need to use --tenant-id to specify a different tenant ID.`
|
|
|
248
227
|
}
|
|
249
228
|
});
|
|
250
229
|
} catch (error) {
|
|
251
|
-
throw
|
|
230
|
+
throw await (0, import_errorFormatter.toError)(error, `Failed to update file "${fileName}" (ref: ${reference})`);
|
|
252
231
|
}
|
|
253
232
|
}
|
|
254
233
|
async deleteFile(reference) {
|
|
255
234
|
try {
|
|
256
235
|
await this.client.delete(`/farseerFiles/${reference}`);
|
|
257
236
|
} catch (error) {
|
|
258
|
-
throw
|
|
237
|
+
throw await (0, import_errorFormatter.toError)(error, `Failed to delete file (ref: ${reference})`);
|
|
259
238
|
}
|
|
260
239
|
}
|
|
261
240
|
async ensureFolderPath(folderPath) {
|
|
@@ -271,7 +250,7 @@ You may need to use --tenant-id to specify a different tenant ID.`
|
|
|
271
250
|
await this.client.post("/folders", {
|
|
272
251
|
parentId: parent.id,
|
|
273
252
|
name: segment,
|
|
274
|
-
allowedTypes:
|
|
253
|
+
allowedTypes: null
|
|
275
254
|
});
|
|
276
255
|
}
|
|
277
256
|
}
|
|
@@ -472,27 +451,66 @@ You may need to use --tenant-id to specify a different tenant ID.`
|
|
|
472
451
|
}
|
|
473
452
|
// ==================== Model Export API ====================
|
|
474
453
|
/**
|
|
475
|
-
* Export the
|
|
476
|
-
*
|
|
454
|
+
* Export the model structure. By default returns tables (without
|
|
455
|
+
* members) and variables — enough for `farseer variables list` /
|
|
456
|
+
* `farseer tables list` without dragging the full member matrix.
|
|
457
|
+
*
|
|
458
|
+
* Pass `types` to scope further. Pass `tableGids` / `variableGids`
|
|
459
|
+
* to limit member/variable expansion to specific objects (used by
|
|
460
|
+
* `dimension details <name>` so we hit one table's members instead
|
|
461
|
+
* of all of them).
|
|
462
|
+
*
|
|
463
|
+
* Why this matters: an unscoped `['DTAB','DMEM','VAR']` export
|
|
464
|
+
* pulls every member of every dimension over the wire. On larger
|
|
465
|
+
* tenants the JSON gets big enough to exceed Cloud Run / proxy
|
|
466
|
+
* response limits, so the client sees "socket hang up" before any
|
|
467
|
+
* data arrives. The server-side filter is honoured all the way down
|
|
468
|
+
* to rama (modelMapping.ts → modelService2.modelExport), so a
|
|
469
|
+
* scoped request is cheap.
|
|
477
470
|
*/
|
|
478
|
-
async exportModel() {
|
|
471
|
+
async exportModel(options = {}) {
|
|
472
|
+
const types = options.types ?? ["DTAB", "VAR"];
|
|
473
|
+
const requestBody = { types };
|
|
474
|
+
if (options.tableGids && options.tableGids.length > 0) {
|
|
475
|
+
requestBody.tableGids = options.tableGids;
|
|
476
|
+
}
|
|
477
|
+
if (options.variableGids && options.variableGids.length > 0) {
|
|
478
|
+
requestBody.variableGids = options.variableGids;
|
|
479
|
+
}
|
|
479
480
|
try {
|
|
480
|
-
const response = await this.client.post("/model/export",
|
|
481
|
-
types: ["DTAB", "DMEM", "VAR"]
|
|
482
|
-
});
|
|
481
|
+
const response = await this.client.post("/model/export", requestBody);
|
|
483
482
|
return response.data;
|
|
484
|
-
} catch {
|
|
485
|
-
|
|
483
|
+
} catch (err) {
|
|
484
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
485
|
+
import_logger.logger.dim(`/model/export failed (${message}); falling back to initTagMap.`);
|
|
486
|
+
return this.buildModelFromTagMaps(options);
|
|
486
487
|
}
|
|
487
488
|
}
|
|
488
|
-
|
|
489
|
-
|
|
489
|
+
/**
|
|
490
|
+
* Fetch one dimension table with its members through the
|
|
491
|
+
* entities API (search → getRelations → getMany). This stays
|
|
492
|
+
* scoped to a single table, unlike `/model/export` with
|
|
493
|
+
* `tableGids` filter which currently 500s for some tables on
|
|
494
|
+
* large tenants (rama-side scoping bug, tracked separately).
|
|
495
|
+
*/
|
|
496
|
+
async loadDimensionTableWithMembers(name) {
|
|
497
|
+
return loadDimensionTableViaEntitiesApi(this.makeNativeClient(), name);
|
|
498
|
+
}
|
|
499
|
+
makeNativeClient() {
|
|
500
|
+
return new farseer.FarseerClient({
|
|
490
501
|
basePath: this.basePath,
|
|
491
502
|
headers: {
|
|
492
503
|
"X-TENANT-ID": this.tenantId,
|
|
493
504
|
Authorization: `Bearer ${this.accessToken}`
|
|
494
505
|
}
|
|
495
506
|
});
|
|
507
|
+
}
|
|
508
|
+
async buildModelFromTagMaps(options = {}) {
|
|
509
|
+
const types = options.types ?? ["DTAB", "VAR"];
|
|
510
|
+
const wantTables = types.includes("DTAB");
|
|
511
|
+
const wantMembers = types.includes("DMEM");
|
|
512
|
+
const wantVariables = types.includes("VAR");
|
|
513
|
+
const nativeClient = this.makeNativeClient();
|
|
496
514
|
let tagMaps;
|
|
497
515
|
try {
|
|
498
516
|
tagMaps = await nativeClient.initTagMap();
|
|
@@ -504,38 +522,68 @@ You may need to use --tenant-id to specify a different tenant ID.`
|
|
|
504
522
|
throw err;
|
|
505
523
|
}
|
|
506
524
|
const tables = [];
|
|
507
|
-
|
|
508
|
-
const
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
525
|
+
if (wantTables) {
|
|
526
|
+
const tableGidFilter = options.tableGids && options.tableGids.length > 0 ? new Set(options.tableGids) : null;
|
|
527
|
+
for (const [name, tag] of tagMaps.dimensionTableMapByName) {
|
|
528
|
+
if (tableGidFilter && !tableGidFilter.has(tag.id)) continue;
|
|
529
|
+
const members = wantMembers ? tagMaps.dimensionMemberMapsByTableId.get(tag.id) : void 0;
|
|
530
|
+
tables.push({
|
|
531
|
+
gid: tag.id,
|
|
532
|
+
name,
|
|
533
|
+
columns: tag.columns?.map((c) => ({
|
|
534
|
+
name: c.name,
|
|
535
|
+
type: c.foreignKey ? "FOREIGN_KEY" : c.primaryKey ? "PRIMARY_KEY" : String(c.type),
|
|
536
|
+
foreignKeyTableName: c.foreignKey ? tagMaps.mapById.get(c.refTableGid)?.name : void 0
|
|
537
|
+
})) ?? [],
|
|
538
|
+
rows: members ? Array.from(members.values()).map((m) => [m.name]) : []
|
|
539
|
+
});
|
|
540
|
+
}
|
|
518
541
|
}
|
|
519
542
|
const variables = [];
|
|
520
|
-
|
|
521
|
-
const
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
543
|
+
if (wantVariables) {
|
|
544
|
+
const variableGidFilter = options.variableGids && options.variableGids.length > 0 ? new Set(options.variableGids) : null;
|
|
545
|
+
for (const [name, tag] of tagMaps.variableMapByName) {
|
|
546
|
+
if (variableGidFilter && !variableGidFilter.has(tag.id)) continue;
|
|
547
|
+
const dimNames = (tag.dimensionTagIds ?? []).map((id) => tagMaps.mapById.get(id)?.name).filter((n) => Boolean(n));
|
|
548
|
+
variables.push({
|
|
549
|
+
gid: tag.id,
|
|
550
|
+
name,
|
|
551
|
+
tables: dimNames,
|
|
552
|
+
members: [],
|
|
553
|
+
rollupType: tag.rollupType ?? "SUM",
|
|
554
|
+
dataType: tag.dataType ?? "DECIMAL",
|
|
555
|
+
readonly: tag.readonly ?? false,
|
|
556
|
+
calculateOnDemand: tag.calculateOnDemand ?? false,
|
|
557
|
+
formula: tag.expression ?? null,
|
|
558
|
+
description: tag.description ?? null
|
|
559
|
+
});
|
|
560
|
+
}
|
|
533
561
|
}
|
|
534
562
|
return { tables, variables, dependencies: { tables: [], members: [], variables: [] } };
|
|
535
563
|
}
|
|
536
564
|
}
|
|
565
|
+
async function loadDimensionTableViaEntitiesApi(nativeClient, name) {
|
|
566
|
+
const searchResult = await nativeClient.entities.search({
|
|
567
|
+
name,
|
|
568
|
+
types: [farseer.EntityType.DimensionTable],
|
|
569
|
+
limit: 1
|
|
570
|
+
});
|
|
571
|
+
if (searchResult.length < 1) {
|
|
572
|
+
return null;
|
|
573
|
+
}
|
|
574
|
+
const loaded = await nativeClient.data.loadFarseerDimensionTable(name);
|
|
575
|
+
const objects = loaded.table.objects();
|
|
576
|
+
const columns = loaded.metadata.map((c) => ({
|
|
577
|
+
name: c.name,
|
|
578
|
+
type: c.type,
|
|
579
|
+
foreignKeyTableName: c.foreignKeyTableName
|
|
580
|
+
}));
|
|
581
|
+
const rows = objects.map((obj) => columns.map((col) => obj[col.name ?? ""]));
|
|
582
|
+
return { name, columns, rows };
|
|
583
|
+
}
|
|
537
584
|
// Annotate the CommonJS export names for ESM import in node:
|
|
538
585
|
0 && (module.exports = {
|
|
539
|
-
FarseerApi
|
|
586
|
+
FarseerApi,
|
|
587
|
+
loadDimensionTableViaEntitiesApi
|
|
540
588
|
});
|
|
541
589
|
//# sourceMappingURL=farseerApi.js.map
|