farseer-cli 1.19.0 → 1.21.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 +32 -9
- package/dist/commands/app.js +42 -3
- package/dist/commands/app.js.map +1 -1
- package/dist/commands/cells.js +120 -85
- package/dist/commands/cells.js.map +1 -1
- package/dist/commands/dashboards.js +246 -12
- package/dist/commands/dashboards.js.map +1 -1
- package/dist/commands/dimensions.js +72 -31
- package/dist/commands/dimensions.js.map +1 -1
- 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 -2
- 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 -1
- package/dist/commands/install.js +32 -30
- package/dist/commands/install.js.map +2 -2
- package/dist/commands/model.js +30 -5
- package/dist/commands/model.js.map +2 -2
- package/dist/commands/push.js +5 -3
- package/dist/commands/push.js.map +1 -1
- package/dist/commands/sheets.js +474 -52
- package/dist/commands/sheets.js.map +1 -1
- package/dist/commands/skills.js +157 -0
- package/dist/commands/skills.js.map +6 -0
- package/dist/commands/variables.js +246 -82
- package/dist/commands/variables.js.map +1 -1
- package/dist/index.js +102 -13
- package/dist/index.js.map +1 -1
- package/dist/mcp/resources/documentation.js +19 -12
- package/dist/mcp/resources/documentation.js.map +1 -1
- package/dist/mcp/tools/appTools.js +1 -7
- package/dist/mcp/tools/appTools.js.map +1 -1
- package/dist/mcp/tools/cellTools.js +6 -19
- package/dist/mcp/tools/cellTools.js.map +1 -1
- package/dist/mcp/tools/dashboardTools.js +30 -412
- package/dist/mcp/tools/dashboardTools.js.map +2 -2
- package/dist/mcp/tools/dataTools.js +15 -146
- package/dist/mcp/tools/dataTools.js.map +1 -1
- package/dist/mcp/tools/folderTools.js +12 -78
- package/dist/mcp/tools/folderTools.js.map +1 -1
- package/dist/mcp/tools/modelTools.js +33 -371
- package/dist/mcp/tools/modelTools.js.map +1 -1
- package/dist/mcp/tools/pipelineContract.js +5 -1
- package/dist/mcp/tools/pipelineContract.js.map +1 -1
- package/dist/mcp/tools/runTools.js +8 -69
- package/dist/mcp/tools/runTools.js.map +1 -1
- package/dist/mcp/tools/sheetTools.js +14 -264
- package/dist/mcp/tools/sheetTools.js.map +1 -1
- package/dist/mcp/tools/syncTools.js +5 -1
- package/dist/mcp/tools/syncTools.js.map +1 -1
- package/dist/mcp/utils/operationResponse.js +41 -0
- package/dist/mcp/utils/operationResponse.js.map +6 -0
- 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 +275 -0
- package/dist/operations/model.js.map +6 -0
- package/dist/operations/sheets.js +766 -0
- package/dist/operations/sheets.js.map +6 -0
- package/dist/pipeline/failStep.js +43 -0
- package/dist/pipeline/failStep.js.map +6 -0
- package/dist/pipeline/generated-reference.json +11 -11
- package/dist/pipeline/queryWorker.js +3 -1
- package/dist/pipeline/queryWorker.js.map +1 -1
- package/dist/pipeline/requests.js +3 -32
- package/dist/pipeline/requests.js.map +1 -1
- package/dist/pipeline/service.js +46 -2
- package/dist/pipeline/service.js.map +1 -1
- package/dist/services/appSyncService.js +59 -9
- package/dist/services/appSyncService.js.map +1 -1
- package/dist/services/apps.js +10 -0
- package/dist/services/apps.js.map +1 -1
- package/dist/services/farseerService.js +28 -6
- package/dist/services/farseerService.js.map +1 -1
- 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 -1
- package/dist/utils/agentSandbox.js +1 -1
- package/dist/utils/dimensionMembers.js +54 -0
- package/dist/utils/dimensionMembers.js.map +6 -0
- package/dist/utils/entityResolver.js +74 -25
- package/dist/utils/entityResolver.js.map +1 -1
- package/dist/utils/errorFormatter.js +13 -0
- package/dist/utils/errorFormatter.js.map +1 -1
- package/dist/utils/formulaFilters.js +11 -2
- package/dist/utils/formulaFilters.js.map +1 -1
- package/dist/utils/operationCli.js +102 -0
- package/dist/utils/operationCli.js.map +6 -0
- package/docs/cli-guide.md +195 -1
- package/docs/pipeline-reference.md +138 -24
- package/docs/troubleshooting.md +18 -0
- package/package.json +2 -2
- 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 +222 -20
- package/skills/farseer-dashboards/cards.md +59 -0
- package/skills/farseer-dashboards/charts.md +245 -0
- package/skills/farseer-dashboards/check.md +91 -0
- package/skills/farseer-dashboards/measures.md +88 -0
- package/skills/farseer-dashboards/page.md +99 -0
- package/skills/farseer-dashboards/reporting-period.md +82 -0
- package/skills/farseer-dashboards/standard-set.md +182 -0
- package/skills/farseer-dashboards/tables.md +174 -0
- package/skills/farseer-help-center/SKILL.md +66 -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 +4 -4
- package/skills/pipeline-authoring/practices.md +17 -4
- package/dist/services/agentApprovalFetch.js +0 -90
- package/dist/services/agentApprovalFetch.js.map +0 -6
|
@@ -0,0 +1,766 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var sheets_exports = {};
|
|
30
|
+
__export(sheets_exports, {
|
|
31
|
+
createSheet: () => createSheet,
|
|
32
|
+
createSheetLine: () => createSheetLine,
|
|
33
|
+
createSheetLineFromJson: () => createSheetLineFromJson,
|
|
34
|
+
createSheetRow: () => createSheetRow,
|
|
35
|
+
deleteSheetLine: () => deleteSheetLine,
|
|
36
|
+
deleteSheetRow: () => deleteSheetRow,
|
|
37
|
+
describeSheetLineDelete: () => describeSheetLineDelete,
|
|
38
|
+
describeSheetRowDelete: () => describeSheetRowDelete,
|
|
39
|
+
droppedBindings: () => droppedBindings,
|
|
40
|
+
getSheetData: () => getSheetData,
|
|
41
|
+
getSheetLines: () => getSheetLines,
|
|
42
|
+
getSheetRows: () => getSheetRows,
|
|
43
|
+
listSheetsPage: () => listSheetsPage,
|
|
44
|
+
refuseIgnoredColumnChange: () => refuseIgnoredColumnChange,
|
|
45
|
+
resolveSheetOrThrow: () => resolveSheetOrThrow,
|
|
46
|
+
updateSheet: () => updateSheet,
|
|
47
|
+
updateSheetColumns: () => updateSheetColumns,
|
|
48
|
+
updateSheetLine: () => updateSheetLine,
|
|
49
|
+
updateSheetRow: () => updateSheetRow
|
|
50
|
+
});
|
|
51
|
+
module.exports = __toCommonJS(sheets_exports);
|
|
52
|
+
var farseer = __toESM(require("farseer-client"));
|
|
53
|
+
var import_entityResolver = require("../utils/entityResolver");
|
|
54
|
+
var import_errorFormatter = require("../utils/errorFormatter");
|
|
55
|
+
var import_dashboards = require("./dashboards");
|
|
56
|
+
var import_errors = require("./errors");
|
|
57
|
+
var import_folderPath = require("./folderPath");
|
|
58
|
+
async function resolveSheetOrThrow(client, nameOrId) {
|
|
59
|
+
const selection = await (0, import_entityResolver.resolveSheet)(client, nameOrId);
|
|
60
|
+
if (selection.kind === "found") {
|
|
61
|
+
return selection.entity;
|
|
62
|
+
}
|
|
63
|
+
if (selection.kind === "ambiguous") {
|
|
64
|
+
const message = await (0, import_entityResolver.describeAmbiguity)(
|
|
65
|
+
client,
|
|
66
|
+
"sheets",
|
|
67
|
+
nameOrId,
|
|
68
|
+
selection.matches,
|
|
69
|
+
farseer.FolderItemType.Sheet
|
|
70
|
+
);
|
|
71
|
+
throw new import_errors.OperationError(message, "VALIDATION_ERROR");
|
|
72
|
+
}
|
|
73
|
+
throw new import_errors.OperationError(`Sheet "${nameOrId}" not found`, "NOT_FOUND");
|
|
74
|
+
}
|
|
75
|
+
async function listSheetsPage(client, params) {
|
|
76
|
+
const allSheets = await (0, import_entityResolver.listSheets)(client);
|
|
77
|
+
const limit = params.limit ?? 100;
|
|
78
|
+
const offset = params.offset ?? 0;
|
|
79
|
+
const page = allSheets.slice(offset, offset + limit);
|
|
80
|
+
const hasMore = offset + limit < allSheets.length;
|
|
81
|
+
return {
|
|
82
|
+
totalSheets: allSheets.length,
|
|
83
|
+
returned: page.length,
|
|
84
|
+
offset,
|
|
85
|
+
limit,
|
|
86
|
+
hasMore,
|
|
87
|
+
sheets: page,
|
|
88
|
+
...hasMore ? {
|
|
89
|
+
hint: `Showing ${offset + 1}-${offset + page.length} of ${allSheets.length}. Use offset=${offset + limit} to get the next page.`
|
|
90
|
+
} : {}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
async function getSheetData(client, params) {
|
|
94
|
+
const sheet = await resolveSheetOrThrow(client, params.sheetNameOrId);
|
|
95
|
+
const data = await client.sheets.getData({ path: String(sheet.id), includeData: true });
|
|
96
|
+
const rows = data.rows ?? [];
|
|
97
|
+
const kept = params.limit !== void 0 ? rows.slice(0, params.limit) : rows;
|
|
98
|
+
return {
|
|
99
|
+
sheet: { id: sheet.id, name: sheet.name },
|
|
100
|
+
totalRows: rows.length,
|
|
101
|
+
returnedRows: kept.length,
|
|
102
|
+
data: { ...data, rows: kept }
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
async function createSheet(client, params) {
|
|
106
|
+
if (params.folderId !== void 0 && params.folderPath?.length) {
|
|
107
|
+
throw new import_errors.OperationError("Pass a folder id or a folder path, not both", "VALIDATION_ERROR");
|
|
108
|
+
}
|
|
109
|
+
const folder = (0, import_folderPath.requireFolderTakes)(
|
|
110
|
+
params.folderId !== void 0 ? await (0, import_folderPath.folderById)(client, params.folderId) : await (0, import_folderPath.resolveFolderPath)(client, params.folderPath?.length ? params.folderPath : ["Sheets"]),
|
|
111
|
+
farseer.FolderItemType.Sheet
|
|
112
|
+
);
|
|
113
|
+
const result = await client.sheets.create({ name: params.name, folderId: folder.id });
|
|
114
|
+
return {
|
|
115
|
+
sheet: {
|
|
116
|
+
id: result.id,
|
|
117
|
+
name: params.name
|
|
118
|
+
},
|
|
119
|
+
message: `Sheet "${params.name}" created successfully`
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
async function getSheetRows(client, params) {
|
|
123
|
+
const sheet = await resolveSheetOrThrow(client, params.sheetNameOrId);
|
|
124
|
+
const rows = await client.sheetRows.getBySheetId(sheet.id);
|
|
125
|
+
const result = rows.map((r) => ({
|
|
126
|
+
id: r.id,
|
|
127
|
+
name: r.name,
|
|
128
|
+
key: r.key,
|
|
129
|
+
path: r.path,
|
|
130
|
+
parentId: r.parentId,
|
|
131
|
+
order: r.order,
|
|
132
|
+
depth: r.depth,
|
|
133
|
+
readonly: r.readonly,
|
|
134
|
+
hasChildren: r.hasChildren,
|
|
135
|
+
hierarchyFlatten: r.hierarchyFlatten,
|
|
136
|
+
hierarchyMaxDepth: r.hierarchyMaxDepth,
|
|
137
|
+
variable: r.variable ? { id: r.variable.id, name: r.variable.name } : null,
|
|
138
|
+
members: r.members?.map((m) => ({
|
|
139
|
+
id: m.id,
|
|
140
|
+
name: m.name,
|
|
141
|
+
parentId: m.parentId
|
|
142
|
+
})) || [],
|
|
143
|
+
table: r.table ? { id: r.table.id, name: r.table.name } : null
|
|
144
|
+
}));
|
|
145
|
+
return {
|
|
146
|
+
sheet: { id: sheet.id, name: sheet.name },
|
|
147
|
+
totalRows: result.length,
|
|
148
|
+
rows: result
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function missing(sent, stored) {
|
|
152
|
+
const kept = new Set(stored);
|
|
153
|
+
return sent.filter((id) => !kept.has(id));
|
|
154
|
+
}
|
|
155
|
+
function droppedBindings(sent, stored) {
|
|
156
|
+
const dropped = {};
|
|
157
|
+
if (sent.accountTagId !== null && stored.variable?.id !== sent.accountTagId) {
|
|
158
|
+
dropped.accountTagId = sent.accountTagId;
|
|
159
|
+
}
|
|
160
|
+
const members = missing(
|
|
161
|
+
sent.dimensionTagIds,
|
|
162
|
+
(stored.members ?? []).map((m) => m.id)
|
|
163
|
+
);
|
|
164
|
+
if (members.length > 0) {
|
|
165
|
+
dropped.dimensionTagIds = members;
|
|
166
|
+
}
|
|
167
|
+
if (sent.tableTagId !== null && stored.table?.id !== sent.tableTagId) {
|
|
168
|
+
dropped.tableTagId = sent.tableTagId;
|
|
169
|
+
}
|
|
170
|
+
return Object.keys(dropped).length > 0 ? dropped : void 0;
|
|
171
|
+
}
|
|
172
|
+
async function reportDropped(what, readBack, worded = unknownIds) {
|
|
173
|
+
let dropped;
|
|
174
|
+
try {
|
|
175
|
+
dropped = await readBack();
|
|
176
|
+
} catch (error) {
|
|
177
|
+
return {
|
|
178
|
+
warning: `${what} was saved, but reading it back to check its bindings failed: ${await (0, import_errorFormatter.formatClientError)(error)}`
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
if (!dropped) {
|
|
182
|
+
return {};
|
|
183
|
+
}
|
|
184
|
+
return { dropped, warning: worded(what, dropped) };
|
|
185
|
+
}
|
|
186
|
+
function unknownIds(what, dropped) {
|
|
187
|
+
const named = Object.entries(dropped).map(([field, ids]) => `${field} ${[ids].flat().join(", ")}`);
|
|
188
|
+
return `Farseer does not know ${named.join("; ")} and saved ${what.toLowerCase()} without them. Check the ids and update it.`;
|
|
189
|
+
}
|
|
190
|
+
async function createSheetRow(client, params) {
|
|
191
|
+
const sheet = await resolveSheetOrThrow(client, params.sheetNameOrId);
|
|
192
|
+
const createRequest = {
|
|
193
|
+
sheetId: sheet.id,
|
|
194
|
+
parentId: params.parentRowId ?? null,
|
|
195
|
+
name: params.name,
|
|
196
|
+
accountTagId: params.accountTagId ?? null,
|
|
197
|
+
dimensionTagIds: params.dimensionTagIds ?? [],
|
|
198
|
+
tableTagId: params.tableTagId ?? null,
|
|
199
|
+
readonly: params.readonly ?? false,
|
|
200
|
+
withData: params.withData ?? false,
|
|
201
|
+
hierarchyFlatten: params.hierarchyFlatten ?? false,
|
|
202
|
+
hierarchyMaxDepth: params.hierarchyMaxDepth ?? 0
|
|
203
|
+
};
|
|
204
|
+
const result = await client.sheetRows.create(createRequest);
|
|
205
|
+
return {
|
|
206
|
+
sheet: { id: sheet.id, name: sheet.name },
|
|
207
|
+
action: "created",
|
|
208
|
+
row: {
|
|
209
|
+
id: result.id,
|
|
210
|
+
name: params.name,
|
|
211
|
+
parentId: params.parentRowId ?? null
|
|
212
|
+
},
|
|
213
|
+
message: `Row "${params.name}" created in sheet "${sheet.name}"`,
|
|
214
|
+
...await reportDropped(
|
|
215
|
+
`Row ${result.id}`,
|
|
216
|
+
async () => droppedBindings(createRequest, await client.sheetRows.get(result.id))
|
|
217
|
+
)
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
async function updateSheetRow(client, params) {
|
|
221
|
+
const sheet = await resolveSheetOrThrow(client, params.sheetNameOrId);
|
|
222
|
+
const rows = await client.sheetRows.getBySheetId(sheet.id);
|
|
223
|
+
const currentRow = rows.find((r) => r.id === params.rowId);
|
|
224
|
+
if (!currentRow) {
|
|
225
|
+
throw new import_errors.OperationError(`Row ID ${params.rowId} not found in sheet "${sheet.name}"`, "NOT_FOUND");
|
|
226
|
+
}
|
|
227
|
+
const current = currentRow;
|
|
228
|
+
const updateRequest = {
|
|
229
|
+
sheetId: sheet.id,
|
|
230
|
+
name: params.name !== void 0 ? params.name : current.name,
|
|
231
|
+
accountTagId: params.accountTagId !== void 0 ? params.accountTagId : current.variable?.id ?? null,
|
|
232
|
+
dimensionTagIds: params.dimensionTagIds !== void 0 ? params.dimensionTagIds : current.members?.map((m) => m.id) ?? [],
|
|
233
|
+
tableTagId: params.tableTagId !== void 0 ? params.tableTagId : current.table?.id ?? null,
|
|
234
|
+
readonly: params.readonly !== void 0 ? params.readonly : current.readonly,
|
|
235
|
+
withData: true,
|
|
236
|
+
hierarchyFlatten: params.hierarchyFlatten !== void 0 ? params.hierarchyFlatten : current.hierarchyFlatten,
|
|
237
|
+
hierarchyMaxDepth: params.hierarchyMaxDepth !== void 0 ? params.hierarchyMaxDepth : current.hierarchyMaxDepth
|
|
238
|
+
};
|
|
239
|
+
await client.sheetRows.update(params.rowId, updateRequest);
|
|
240
|
+
return {
|
|
241
|
+
sheet: { id: sheet.id, name: sheet.name },
|
|
242
|
+
action: "updated",
|
|
243
|
+
rowId: params.rowId,
|
|
244
|
+
message: `Row ${params.rowId} updated in sheet "${sheet.name}"`,
|
|
245
|
+
...await reportDropped(
|
|
246
|
+
`Row ${params.rowId}`,
|
|
247
|
+
async () => droppedBindings(updateRequest, await client.sheetRows.get(params.rowId))
|
|
248
|
+
)
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
async function deleteSheetRow(client, params) {
|
|
252
|
+
await client.sheetRows._delete(params.rowId);
|
|
253
|
+
return {
|
|
254
|
+
action: "deleted",
|
|
255
|
+
rowId: params.rowId,
|
|
256
|
+
message: `Row ${params.rowId} deleted`
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
function mirroredFrom(stored, axis) {
|
|
260
|
+
const mirrors = axis === "ROW" ? stored.refConfig?.useRows : stored.refConfig?.useColumns;
|
|
261
|
+
return stored.refSheetId != null && mirrors ? stored.refSheetId : void 0;
|
|
262
|
+
}
|
|
263
|
+
async function originSheet(client, id) {
|
|
264
|
+
try {
|
|
265
|
+
return { id, name: (await client.sheets.get(id)).name };
|
|
266
|
+
} catch (error) {
|
|
267
|
+
if (!(0, import_entityResolver.isMissing)(error)) throw error;
|
|
268
|
+
return { id };
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
async function getSheetLines(client, params) {
|
|
272
|
+
const sheet = await resolveSheetOrThrow(client, params.sheetNameOrId);
|
|
273
|
+
const stored = await client.sheets.get(sheet.id);
|
|
274
|
+
const asked = (axis) => params.axis === void 0 || params.axis === axis;
|
|
275
|
+
const rowsFrom = asked("ROW") ? mirroredFrom(stored, "ROW") : void 0;
|
|
276
|
+
const columnsFrom = asked("COLUMN") ? mirroredFrom(stored, "COLUMN") : void 0;
|
|
277
|
+
const originId = rowsFrom ?? columnsFrom;
|
|
278
|
+
const origin = originId !== void 0 ? await originSheet(client, originId) : void 0;
|
|
279
|
+
const lines = await client.sheetLines.getBySheetId(sheet.id, params.axis);
|
|
280
|
+
return {
|
|
281
|
+
sheet: { id: sheet.id, name: sheet.name },
|
|
282
|
+
...origin && rowsFrom !== void 0 ? { rowsFrom: origin } : {},
|
|
283
|
+
...origin && columnsFrom !== void 0 ? { columnsFrom: origin } : {},
|
|
284
|
+
totalLines: lines.length,
|
|
285
|
+
lines
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
async function ownLineOrThrow(client, sheet, lineId, verb) {
|
|
289
|
+
const line = await client.sheetLines.getById(lineId);
|
|
290
|
+
if (line.sheetId === sheet.id) return line;
|
|
291
|
+
const stored = await client.sheets.get(sheet.id);
|
|
292
|
+
if (mirroredFrom(stored, line.axis) === line.sheetId) {
|
|
293
|
+
throw new import_errors.OperationError(
|
|
294
|
+
`Sheet "${sheet.name}" uses the ${line.axis === "ROW" ? "rows" : "columns"} of sheet ${line.sheetId}, and line ${lineId} belongs to that sheet; ${verb} it there`,
|
|
295
|
+
"VALIDATION_ERROR"
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
throw new import_errors.OperationError(
|
|
299
|
+
`Line ${lineId} is not a line of sheet "${sheet.name}" (ID ${sheet.id}); it belongs to sheet ${line.sheetId}`,
|
|
300
|
+
"VALIDATION_ERROR"
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
async function createSheetLine(client, params) {
|
|
304
|
+
const sheet = await resolveSheetOrThrow(client, params.sheetNameOrId);
|
|
305
|
+
const names = params.variable !== void 0 || !!params.tables?.length || !!params.members?.length;
|
|
306
|
+
const tags = names ? await client.initTagMap() : {
|
|
307
|
+
variableMapByName: /* @__PURE__ */ new Map(),
|
|
308
|
+
dimensionTableMapByName: /* @__PURE__ */ new Map(),
|
|
309
|
+
dimensionMemberMapsByTableId: /* @__PURE__ */ new Map(),
|
|
310
|
+
mapById: /* @__PURE__ */ new Map()
|
|
311
|
+
};
|
|
312
|
+
const request = {
|
|
313
|
+
sheetId: sheet.id,
|
|
314
|
+
parentId: params.parentId ?? null,
|
|
315
|
+
axis: params.axis,
|
|
316
|
+
type: farseer.SheetLineType.Number,
|
|
317
|
+
name: params.name ?? null,
|
|
318
|
+
variableGid: params.variable !== void 0 ? resolveTag(tags, "variable", params.variable).id : null,
|
|
319
|
+
memberGids: (params.members ?? []).map((member) => resolveMember(tags, member).id),
|
|
320
|
+
dimensionGenerationOptions: {
|
|
321
|
+
tableGids: (params.tables ?? []).map((table) => resolveTag(tags, "table", table).id),
|
|
322
|
+
hierarchyFlatten: params.hierarchyFlatten ?? false,
|
|
323
|
+
hierarchyMaxDepth: params.hierarchyMaxDepth ?? 0
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
const { id } = await client.sheetLines.create(request);
|
|
327
|
+
return {
|
|
328
|
+
sheet: { id: sheet.id, name: sheet.name },
|
|
329
|
+
action: "created",
|
|
330
|
+
line: createdLine(id, request),
|
|
331
|
+
message: `${params.axis === "ROW" ? "Row" : "Column"} line ${id} created in sheet "${sheet.name}"`,
|
|
332
|
+
...await reportDropped(
|
|
333
|
+
`Line ${id}`,
|
|
334
|
+
async () => droppedLineIds(request, await client.sheetLines.getById(id))
|
|
335
|
+
)
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
function createdLine(id, request) {
|
|
339
|
+
return {
|
|
340
|
+
id,
|
|
341
|
+
axis: request.axis,
|
|
342
|
+
type: request.type,
|
|
343
|
+
name: request.name ?? null,
|
|
344
|
+
parentId: request.parentId,
|
|
345
|
+
variableGid: request.variableGid ?? null,
|
|
346
|
+
memberGids: request.memberGids ?? [],
|
|
347
|
+
tableGids: request.dimensionGenerationOptions?.tableGids ?? []
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
function droppedLineIds(sent, stored) {
|
|
351
|
+
const dropped = {};
|
|
352
|
+
if (sent.variableGid !== null && stored.variableGid !== sent.variableGid) {
|
|
353
|
+
dropped.variableGid = sent.variableGid;
|
|
354
|
+
}
|
|
355
|
+
const members = missing(sent.memberGids, stored.memberGids ?? []);
|
|
356
|
+
if (members.length > 0) {
|
|
357
|
+
dropped.memberGids = members;
|
|
358
|
+
}
|
|
359
|
+
const tables = missing(
|
|
360
|
+
sent.dimensionGenerationOptions.tableGids,
|
|
361
|
+
stored.dimensionGenerationOptions?.tableGids ?? []
|
|
362
|
+
);
|
|
363
|
+
if (tables.length > 0) {
|
|
364
|
+
dropped.tableGids = tables;
|
|
365
|
+
}
|
|
366
|
+
return Object.keys(dropped).length > 0 ? dropped : void 0;
|
|
367
|
+
}
|
|
368
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
369
|
+
function differences(path, sent, stored) {
|
|
370
|
+
if (isObject(sent)) {
|
|
371
|
+
if (!isObject(stored)) return [[path, sent]];
|
|
372
|
+
return Object.entries(sent).flatMap(([key, value]) => differences(`${path}.${key}`, value, stored[key]));
|
|
373
|
+
}
|
|
374
|
+
if (Array.isArray(sent)) {
|
|
375
|
+
if (!Array.isArray(stored)) return [[path, sent]];
|
|
376
|
+
if (sent.every((value) => value === null || typeof value !== "object")) {
|
|
377
|
+
const lacking = sent.filter((value) => !stored.includes(value));
|
|
378
|
+
if (lacking.length > 0) return [[path, lacking]];
|
|
379
|
+
return stored.length === sent.length ? [] : [[path, sent]];
|
|
380
|
+
}
|
|
381
|
+
const same = stored.length === sent.length && sent.every((value, at) => differences(path, value, stored[at]).length === 0);
|
|
382
|
+
return same ? [] : [[path, sent]];
|
|
383
|
+
}
|
|
384
|
+
return sent === (stored ?? null) ? [] : [[path, sent]];
|
|
385
|
+
}
|
|
386
|
+
function notKept(sent, stored) {
|
|
387
|
+
const entries = Object.entries(sent).flatMap(
|
|
388
|
+
([field, value]) => differences(field, value, stored[field])
|
|
389
|
+
);
|
|
390
|
+
if (entries.length === 0) return void 0;
|
|
391
|
+
return Object.fromEntries(
|
|
392
|
+
entries.map(([path, value]) => [path === "dimensionGenerationOptions.tableGids" ? "tableGids" : path, value])
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
function notKeptWarning(what, dropped) {
|
|
396
|
+
const shown = (value) => Array.isArray(value) && value.length > 0 ? value.map((item) => JSON.stringify(item)).join(", ") : JSON.stringify(value);
|
|
397
|
+
const named = Object.entries(dropped).map(([field, value]) => `${field} ${shown(value)}`);
|
|
398
|
+
return `${what} was saved, but Farseer did not keep ${named.join("; ")}. Check them and update the line.`;
|
|
399
|
+
}
|
|
400
|
+
function sendable(what, sent, toJSON) {
|
|
401
|
+
let kept;
|
|
402
|
+
try {
|
|
403
|
+
kept = toJSON(sent);
|
|
404
|
+
} catch (error) {
|
|
405
|
+
if (!(error instanceof TypeError)) throw error;
|
|
406
|
+
throw new import_errors.OperationError(
|
|
407
|
+
`The ${what} is not in the shape the API takes: a list or an object it requires is missing, null or of another type`,
|
|
408
|
+
"VALIDATION_ERROR"
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
const unknown = unknownKeys(sent, kept, "");
|
|
412
|
+
if (unknown.length > 0) {
|
|
413
|
+
const [it, name] = unknown.length === 1 ? ["it", "its name and place"] : ["them", "their names and places"];
|
|
414
|
+
throw new import_errors.OperationError(
|
|
415
|
+
`A ${what} takes no ${unknown.map((path) => `"${path}"`).join(", ")} in this version of the CLI: the write would drop ${it} and still be reported as done. Remove ${it}, or check ${name}.`,
|
|
416
|
+
"VALIDATION_ERROR"
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
return sent;
|
|
420
|
+
}
|
|
421
|
+
function unknownKeys(sent, kept, path) {
|
|
422
|
+
if (sent === kept) return [];
|
|
423
|
+
if (Array.isArray(sent) && Array.isArray(kept)) {
|
|
424
|
+
return sent.flatMap((item, at) => unknownKeys(item, kept[at], `${path}[${at}]`));
|
|
425
|
+
}
|
|
426
|
+
if (isObject(sent) && isObject(kept)) {
|
|
427
|
+
return Object.entries(sent).flatMap(([key, value]) => {
|
|
428
|
+
const at = path ? `${path}.${key}` : key;
|
|
429
|
+
const known = Object.prototype.hasOwnProperty.call(kept, key);
|
|
430
|
+
return known ? unknownKeys(value, kept[key], at) : [at];
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
throw new import_errors.OperationError(`"${path}" must be an object, not ${JSON.stringify(sent)}`, "VALIDATION_ERROR");
|
|
434
|
+
}
|
|
435
|
+
async function createSheetLineFromJson(client, params) {
|
|
436
|
+
const sheet = await resolveSheetOrThrow(client, params.sheetNameOrId);
|
|
437
|
+
const absent = ["axis", "type"].filter((field) => params.line[field] === void 0);
|
|
438
|
+
if (absent.length > 0) {
|
|
439
|
+
throw new import_errors.OperationError(`The line needs ${absent.join(" and ")}`, "VALIDATION_ERROR");
|
|
440
|
+
}
|
|
441
|
+
if (params.line.sheetId !== void 0 && params.line.sheetId !== sheet.id) {
|
|
442
|
+
throw new import_errors.OperationError(
|
|
443
|
+
`The line names sheet ${params.line.sheetId}, not "${sheet.name}" (ID ${sheet.id})`,
|
|
444
|
+
"VALIDATION_ERROR"
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
const request = { parentId: null, ...params.line, sheetId: sheet.id };
|
|
448
|
+
const { id } = await client.sheetLines.create(
|
|
449
|
+
sendable("sheet line", request, farseer.CreateSheetLineRequestToJSON)
|
|
450
|
+
);
|
|
451
|
+
return {
|
|
452
|
+
sheet: { id: sheet.id, name: sheet.name },
|
|
453
|
+
action: "created",
|
|
454
|
+
line: createdLine(id, request),
|
|
455
|
+
message: `${request.axis === "ROW" ? "Row" : "Column"} line ${id} created in sheet "${sheet.name}"`,
|
|
456
|
+
...await reportDropped(
|
|
457
|
+
`Line ${id}`,
|
|
458
|
+
async () => notKept(request, await client.sheetLines.getById(id)),
|
|
459
|
+
notKeptWarning
|
|
460
|
+
)
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
async function updateSheetLine(client, params) {
|
|
464
|
+
const { id, ...fields } = params.line;
|
|
465
|
+
if (id !== void 0 && id !== params.lineId) {
|
|
466
|
+
throw new import_errors.OperationError(`The line given is line ${id}, not line ${params.lineId}`, "VALIDATION_ERROR");
|
|
467
|
+
}
|
|
468
|
+
const updated = Object.keys(fields);
|
|
469
|
+
if (updated.length === 0) {
|
|
470
|
+
throw new import_errors.OperationError("Nothing to change: the line has no fields", "VALIDATION_ERROR");
|
|
471
|
+
}
|
|
472
|
+
const line = sendable("sheet line", fields, farseer.UpdateSheetLineRequestToJSON);
|
|
473
|
+
const sheet = await resolveSheetOrThrow(client, params.sheetNameOrId);
|
|
474
|
+
await ownLineOrThrow(client, sheet, params.lineId, "change");
|
|
475
|
+
await client.sheetLines.updateById(params.lineId, line);
|
|
476
|
+
return {
|
|
477
|
+
sheet: { id: sheet.id, name: sheet.name },
|
|
478
|
+
action: "updated",
|
|
479
|
+
lineId: params.lineId,
|
|
480
|
+
updated,
|
|
481
|
+
message: `Line ${params.lineId} updated in sheet "${sheet.name}"`,
|
|
482
|
+
...await reportDropped(
|
|
483
|
+
`Line ${params.lineId}`,
|
|
484
|
+
async () => notKept(fields, await client.sheetLines.getById(params.lineId)),
|
|
485
|
+
notKeptWarning
|
|
486
|
+
)
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
async function describeSheetLineDelete(client, params) {
|
|
490
|
+
const sheet = await resolveSheetOrThrow(client, params.sheetNameOrId);
|
|
491
|
+
const line = await ownLineOrThrow(client, sheet, params.lineId, "delete");
|
|
492
|
+
const children = /* @__PURE__ */ new Map();
|
|
493
|
+
for (const l of await client.sheetLines.getBySheetId(sheet.id, line.axis)) {
|
|
494
|
+
if (l.parentId !== null) {
|
|
495
|
+
children.set(l.parentId, [...children.get(l.parentId) ?? [], l.id]);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
let descendants = 0;
|
|
499
|
+
for (const queue = [line.id]; queue.length > 0; ) {
|
|
500
|
+
const next = children.get(queue.pop()) ?? [];
|
|
501
|
+
descendants += next.length;
|
|
502
|
+
queue.push(...next);
|
|
503
|
+
}
|
|
504
|
+
return {
|
|
505
|
+
sheet: { id: sheet.id, name: sheet.name },
|
|
506
|
+
line: { id: line.id, name: line.name, axis: line.axis },
|
|
507
|
+
descendants
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
async function deleteSheetLine(client, params) {
|
|
511
|
+
const sheet = await resolveSheetOrThrow(client, params.sheetNameOrId);
|
|
512
|
+
await ownLineOrThrow(client, sheet, params.lineId, "delete");
|
|
513
|
+
await client.sheetLines.deleteById(params.lineId);
|
|
514
|
+
return {
|
|
515
|
+
sheet: { id: sheet.id, name: sheet.name },
|
|
516
|
+
action: "deleted",
|
|
517
|
+
lineId: params.lineId,
|
|
518
|
+
message: `Line ${params.lineId} deleted from sheet "${sheet.name}"`
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
function resolveTag(tags, kind, nameOrId) {
|
|
522
|
+
const [byName, type, label] = kind === "variable" ? [tags.variableMapByName.get(nameOrId), farseer.TagType.Account, "Variable"] : [tags.dimensionTableMapByName.get(nameOrId), farseer.TagType.Table, "Table"];
|
|
523
|
+
const byId = /^\d+$/.test(nameOrId) ? tags.mapById.get(Number(nameOrId)) : void 0;
|
|
524
|
+
return pick(nameOrId, byName, byId?.type === type ? byId : void 0, `${label} "${nameOrId}" not found`);
|
|
525
|
+
}
|
|
526
|
+
function resolveMember(tags, member) {
|
|
527
|
+
const table = resolveTag(tags, "table", member.dimensionTable);
|
|
528
|
+
const value = member.dimensionValue;
|
|
529
|
+
const byName = tags.dimensionMemberMapsByTableId.get(table.id)?.get(value);
|
|
530
|
+
const byId = /^\d+$/.test(value) ? tags.mapById.get(Number(value)) : void 0;
|
|
531
|
+
const notFound = `Member "${value}" not found in table "${table.name}"`;
|
|
532
|
+
return pick(value, byName, byId?.ParentId === table.id ? byId : void 0, notFound);
|
|
533
|
+
}
|
|
534
|
+
function pick(nameOrId, byName, byId, notFound) {
|
|
535
|
+
if (byName && byId && byName.id !== byId.id) {
|
|
536
|
+
throw new import_errors.OperationError(
|
|
537
|
+
`"${nameOrId}" is ambiguous: it is the name of id ${byName.id} and the id of "${byId.name}". Pass ${byName.id} for the first, or "${byId.name}" for the second.`,
|
|
538
|
+
"VALIDATION_ERROR"
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
const tag = byName ?? byId;
|
|
542
|
+
if (!tag) {
|
|
543
|
+
throw new import_errors.OperationError(notFound, "NOT_FOUND");
|
|
544
|
+
}
|
|
545
|
+
return tag;
|
|
546
|
+
}
|
|
547
|
+
async function describeSheetRowDelete(client, rowId) {
|
|
548
|
+
const row = await client.sheetRows.get(rowId);
|
|
549
|
+
const [sheet, rows] = await Promise.all([
|
|
550
|
+
client.sheets.get(row.sheetId),
|
|
551
|
+
client.sheetRows.getBySheetId(row.sheetId)
|
|
552
|
+
]);
|
|
553
|
+
const children = /* @__PURE__ */ new Map();
|
|
554
|
+
for (const r of rows) {
|
|
555
|
+
if (r.parentId !== null) {
|
|
556
|
+
children.set(r.parentId, [...children.get(r.parentId) ?? [], r.id]);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
let descendants = 0;
|
|
560
|
+
for (const queue = [rowId]; queue.length > 0; ) {
|
|
561
|
+
const next = children.get(queue.pop()) ?? [];
|
|
562
|
+
descendants += next.length;
|
|
563
|
+
queue.push(...next);
|
|
564
|
+
}
|
|
565
|
+
return { sheet: { id: sheet.id, name: sheet.name }, row: { id: row.id, name: row.name }, descendants };
|
|
566
|
+
}
|
|
567
|
+
function refuseIgnoredColumnChange(sheetName, current, columns) {
|
|
568
|
+
if (current.refSheetId == null || !current.refConfig?.useColumns) return;
|
|
569
|
+
const sent = farseer.SheetConfigColumnsWithOptionalCustomFromJSON({ ...current.columns, ...columns });
|
|
570
|
+
const changed = (key) => columns[key] !== void 0 && canonical(sent[key]) !== canonical(current.columns[key]);
|
|
571
|
+
if (changed("standard") || changed("custom")) {
|
|
572
|
+
throw new import_errors.OperationError(
|
|
573
|
+
`Sheet "${sheetName}" uses the columns of sheet ${current.refSheetId}; change its standard and custom columns there`,
|
|
574
|
+
"VALIDATION_ERROR"
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
function canonical(value) {
|
|
579
|
+
return JSON.stringify(
|
|
580
|
+
value,
|
|
581
|
+
(_key, v) => v && typeof v === "object" && !Array.isArray(v) ? Object.fromEntries(
|
|
582
|
+
Object.keys(v).sort().map((k) => [k, v[k]])
|
|
583
|
+
) : v
|
|
584
|
+
);
|
|
585
|
+
}
|
|
586
|
+
async function updateSheetColumns(client, params) {
|
|
587
|
+
const sheet = await resolveSheetOrThrow(client, params.sheetNameOrId);
|
|
588
|
+
const config = client.dashboards?.configuration || client._configuration;
|
|
589
|
+
const basePath = config?.basePath || "";
|
|
590
|
+
const rawHeaders = { ...config?.headers, "Content-Type": "application/json" };
|
|
591
|
+
const current = await client.sheets.get(sheet.id);
|
|
592
|
+
refuseIgnoredColumnChange(sheet.name, current, params.columns);
|
|
593
|
+
const updatePayload = { name: current.name, columns: params.columns };
|
|
594
|
+
const resp = await fetch(`${basePath}/sheets/${sheet.id}`, {
|
|
595
|
+
method: "PUT",
|
|
596
|
+
headers: rawHeaders,
|
|
597
|
+
body: JSON.stringify(updatePayload)
|
|
598
|
+
});
|
|
599
|
+
if (!resp.ok) {
|
|
600
|
+
throw resp;
|
|
601
|
+
}
|
|
602
|
+
return {
|
|
603
|
+
sheet: { id: sheet.id, name: sheet.name },
|
|
604
|
+
action: "updated",
|
|
605
|
+
columnKeys: Object.keys(params.columns),
|
|
606
|
+
message: `Sheet "${sheet.name}" columns updated`
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
const SHEET_SETTINGS = {
|
|
610
|
+
name: "string",
|
|
611
|
+
stacked: "boolean",
|
|
612
|
+
rows: "object",
|
|
613
|
+
display: "object"
|
|
614
|
+
};
|
|
615
|
+
const SHEET_SETTING_NAMES = Object.keys(SHEET_SETTINGS);
|
|
616
|
+
function requireSettingTypes(change) {
|
|
617
|
+
const worded = {
|
|
618
|
+
string: "a string",
|
|
619
|
+
boolean: "true or false",
|
|
620
|
+
object: "an object",
|
|
621
|
+
array: "an array",
|
|
622
|
+
number: "a number"
|
|
623
|
+
};
|
|
624
|
+
for (const [key, value] of Object.entries(change)) {
|
|
625
|
+
if (value === null) {
|
|
626
|
+
throw new import_errors.OperationError(`"${key}" is null: a setting cannot be removed, only changed`, "VALIDATION_ERROR");
|
|
627
|
+
}
|
|
628
|
+
const type = Array.isArray(value) ? "array" : typeof value;
|
|
629
|
+
if (type !== SHEET_SETTINGS[key]) {
|
|
630
|
+
throw new import_errors.OperationError(
|
|
631
|
+
`"${key}" must be ${worded[SHEET_SETTINGS[key]]}, not ${worded[type]}`,
|
|
632
|
+
"VALIDATION_ERROR"
|
|
633
|
+
);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
function withColumnConfig(merged, read, sent) {
|
|
638
|
+
if (!Array.isArray(sent.columnConfig)) return merged;
|
|
639
|
+
const asRead = new Map((read?.columnConfig ?? []).map((entry) => [entry.key, entry]));
|
|
640
|
+
const keyed = { ...merged.keyedColumnConfig };
|
|
641
|
+
for (const entry of sent.columnConfig) {
|
|
642
|
+
if (typeof entry?.key !== "string" || sent.keyedColumnConfig?.[entry.key] !== void 0) continue;
|
|
643
|
+
for (const field of ["width", "order"]) {
|
|
644
|
+
if (entry[field] !== void 0 && entry[field] !== asRead.get(entry.key)?.[field]) {
|
|
645
|
+
keyed[entry.key] = { ...keyed[entry.key], [field]: entry[field] };
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
return { ...merged, keyedColumnConfig: keyed };
|
|
650
|
+
}
|
|
651
|
+
const LINE_COLUMN_KEY = /^\d+_(\d+)([^_]*_\d)?/;
|
|
652
|
+
function refuseLineColumnOrder(sheetId, read, sent) {
|
|
653
|
+
const asRead = new Map((read?.columnConfig ?? []).map((entry) => [entry.key, entry]));
|
|
654
|
+
const inArray = Array.isArray(sent?.columnConfig) ? sent.columnConfig : [];
|
|
655
|
+
const sentEntries = [
|
|
656
|
+
...inArray.map((entry) => ({ key: entry?.key, entry, keyed: false })),
|
|
657
|
+
...Object.entries(sent?.keyedColumnConfig ?? {}).map(([key, entry]) => ({ key, entry, keyed: true }))
|
|
658
|
+
];
|
|
659
|
+
for (const { key, entry, keyed } of sentEntries) {
|
|
660
|
+
const [, lineId, nested] = LINE_COLUMN_KEY.exec(key) ?? [];
|
|
661
|
+
const was = asRead.get(key);
|
|
662
|
+
if (lineId === void 0 || entry?.order == null || entry.order === was?.order) continue;
|
|
663
|
+
const refusal = [
|
|
664
|
+
`Column "${key}" takes its place from the order of line ${lineId}: the server ignores an order set for it in the display.`,
|
|
665
|
+
`Change the line's order with "farseer sheets update-line ${sheetId} ${lineId} --input <file>", the file holding {"order": N}.`
|
|
666
|
+
];
|
|
667
|
+
if (nested) {
|
|
668
|
+
refusal.push(
|
|
669
|
+
`The lines nested under line ${lineId} are placed among themselves by their own order, changed the same way.`
|
|
670
|
+
);
|
|
671
|
+
}
|
|
672
|
+
if (!keyed && typeof entry.width === "number" && entry.width !== was?.width) {
|
|
673
|
+
refusal.push(
|
|
674
|
+
`To change only the width, send it keyed, where an entry needs no order: {"display": {"keyedColumnConfig": {"${key}": {"width": ${entry.width}}}}}.`
|
|
675
|
+
);
|
|
676
|
+
}
|
|
677
|
+
throw new import_errors.OperationError(refusal.join(" "), "VALIDATION_ERROR");
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
function refuseIgnoredMirrorChange(sheetName, current, update) {
|
|
681
|
+
if (current.refSheetId == null) return;
|
|
682
|
+
const mirrored = [
|
|
683
|
+
{ flag: "useFilters", uses: "filters", change: "its filters (rows.filters)", at: ["rows", "filters"] },
|
|
684
|
+
{ flag: "useSort", uses: "ranking", change: "its ranking (rows.sort)", at: ["rows", "sort"] },
|
|
685
|
+
{ flag: "useRows", uses: "rows", change: "its row heights (display.rowConfig)", at: ["display", "rowConfig"] },
|
|
686
|
+
{
|
|
687
|
+
flag: "useColumns",
|
|
688
|
+
uses: "columns",
|
|
689
|
+
change: "its column widths and order (display.columnConfig)",
|
|
690
|
+
at: ["display", "keyedColumnConfig"]
|
|
691
|
+
}
|
|
692
|
+
];
|
|
693
|
+
for (const { flag, uses, change, at } of mirrored) {
|
|
694
|
+
const [setting, key] = at;
|
|
695
|
+
const sent = update[setting];
|
|
696
|
+
if (!current.refConfig?.[flag] || sent === void 0) continue;
|
|
697
|
+
if (canonical(sent[key]) !== canonical(current[setting]?.[key])) {
|
|
698
|
+
throw new import_errors.OperationError(
|
|
699
|
+
`Sheet "${sheetName}" uses the ${uses} of sheet ${current.refSheetId}; change ${change} there`,
|
|
700
|
+
"VALIDATION_ERROR"
|
|
701
|
+
);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
async function updateSheet(client, params) {
|
|
706
|
+
const changed = Object.keys(params.sheet);
|
|
707
|
+
if (changed.includes("columns")) {
|
|
708
|
+
throw new import_errors.OperationError('Columns are replaced whole: use "farseer sheets set-columns"', "VALIDATION_ERROR");
|
|
709
|
+
}
|
|
710
|
+
const unknown = changed.filter((key) => !SHEET_SETTING_NAMES.includes(key));
|
|
711
|
+
if (unknown.length > 0) {
|
|
712
|
+
throw new import_errors.OperationError(
|
|
713
|
+
`A sheet update takes ${SHEET_SETTING_NAMES.join(", ")}, not ${unknown.join(", ")}`,
|
|
714
|
+
"VALIDATION_ERROR"
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
if (changed.length === 0) {
|
|
718
|
+
throw new import_errors.OperationError(
|
|
719
|
+
`Nothing to change: pass any of ${SHEET_SETTING_NAMES.join(", ")}`,
|
|
720
|
+
"VALIDATION_ERROR"
|
|
721
|
+
);
|
|
722
|
+
}
|
|
723
|
+
requireSettingTypes(params.sheet);
|
|
724
|
+
const sheet = await resolveSheetOrThrow(client, params.sheetNameOrId);
|
|
725
|
+
const current = await client.sheets.get(sheet.id);
|
|
726
|
+
const update = { name: current.name };
|
|
727
|
+
for (const key of changed) {
|
|
728
|
+
update[key] = (0, import_dashboards.deepMerge)(current[key], params.sheet[key]);
|
|
729
|
+
}
|
|
730
|
+
update.name = update.name.trim();
|
|
731
|
+
if (update.display !== void 0) {
|
|
732
|
+
update.display = withColumnConfig(update.display, current.display, params.sheet.display);
|
|
733
|
+
}
|
|
734
|
+
refuseIgnoredMirrorChange(sheet.name, current, update);
|
|
735
|
+
refuseLineColumnOrder(sheet.id, current.display, params.sheet.display);
|
|
736
|
+
await client.sheets.update(sheet.id, sendable("sheet update", update, farseer.UpdateSheetRequestToJSON));
|
|
737
|
+
return {
|
|
738
|
+
sheet: { id: sheet.id, name: update.name },
|
|
739
|
+
action: "updated",
|
|
740
|
+
updated: changed,
|
|
741
|
+
message: `Sheet "${update.name}" updated (${changed.join(", ")})`
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
745
|
+
0 && (module.exports = {
|
|
746
|
+
createSheet,
|
|
747
|
+
createSheetLine,
|
|
748
|
+
createSheetLineFromJson,
|
|
749
|
+
createSheetRow,
|
|
750
|
+
deleteSheetLine,
|
|
751
|
+
deleteSheetRow,
|
|
752
|
+
describeSheetLineDelete,
|
|
753
|
+
describeSheetRowDelete,
|
|
754
|
+
droppedBindings,
|
|
755
|
+
getSheetData,
|
|
756
|
+
getSheetLines,
|
|
757
|
+
getSheetRows,
|
|
758
|
+
listSheetsPage,
|
|
759
|
+
refuseIgnoredColumnChange,
|
|
760
|
+
resolveSheetOrThrow,
|
|
761
|
+
updateSheet,
|
|
762
|
+
updateSheetColumns,
|
|
763
|
+
updateSheetLine,
|
|
764
|
+
updateSheetRow
|
|
765
|
+
});
|
|
766
|
+
//# sourceMappingURL=sheets.js.map
|