@mcp-z/mcp-sheets 2.6.0 → 2.6.1
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/dist/cjs/mcp/tools/columns-update.js +5 -1
- package/dist/cjs/mcp/tools/columns-update.js.map +1 -1
- package/dist/cjs/mcp/tools/rows-append.js +1 -2
- package/dist/cjs/mcp/tools/rows-append.js.map +1 -1
- package/dist/cjs/mcp/tools/rows-csv-append.js +1 -2
- package/dist/cjs/mcp/tools/rows-csv-append.js.map +1 -1
- package/dist/cjs/spreadsheet/data-operations.d.cts +8 -1
- package/dist/cjs/spreadsheet/data-operations.d.ts +8 -1
- package/dist/cjs/spreadsheet/data-operations.js +79 -101
- package/dist/cjs/spreadsheet/data-operations.js.map +1 -1
- package/dist/cjs/spreadsheet/range-operations.d.cts +0 -67
- package/dist/cjs/spreadsheet/range-operations.d.ts +0 -67
- package/dist/cjs/spreadsheet/range-operations.js +0 -236
- package/dist/cjs/spreadsheet/range-operations.js.map +1 -1
- package/dist/cjs/spreadsheet/sheet-operations.d.cts +4 -17
- package/dist/cjs/spreadsheet/sheet-operations.d.ts +4 -17
- package/dist/cjs/spreadsheet/sheet-operations.js +17 -221
- package/dist/cjs/spreadsheet/sheet-operations.js.map +1 -1
- package/dist/esm/mcp/tools/columns-update.js +5 -1
- package/dist/esm/mcp/tools/columns-update.js.map +1 -1
- package/dist/esm/mcp/tools/rows-append.js +1 -2
- package/dist/esm/mcp/tools/rows-append.js.map +1 -1
- package/dist/esm/mcp/tools/rows-csv-append.js +1 -2
- package/dist/esm/mcp/tools/rows-csv-append.js.map +1 -1
- package/dist/esm/spreadsheet/data-operations.d.ts +8 -1
- package/dist/esm/spreadsheet/data-operations.js +27 -35
- package/dist/esm/spreadsheet/data-operations.js.map +1 -1
- package/dist/esm/spreadsheet/range-operations.d.ts +0 -67
- package/dist/esm/spreadsheet/range-operations.js +0 -227
- package/dist/esm/spreadsheet/range-operations.js.map +1 -1
- package/dist/esm/spreadsheet/sheet-operations.d.ts +4 -17
- package/dist/esm/spreadsheet/sheet-operations.js +7 -115
- package/dist/esm/spreadsheet/sheet-operations.js.map +1 -1
- package/package.json +1 -1
|
@@ -49,15 +49,6 @@ export interface RangeDimensions {
|
|
|
49
49
|
columns: number;
|
|
50
50
|
cells: number;
|
|
51
51
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Represents a range conflict between two ranges
|
|
54
|
-
*/
|
|
55
|
-
export interface RangeConflict {
|
|
56
|
-
range1: string;
|
|
57
|
-
range2: string;
|
|
58
|
-
conflictType: 'overlap' | 'contains' | 'contained' | 'adjacent';
|
|
59
|
-
description: string;
|
|
60
|
-
}
|
|
61
52
|
/**
|
|
62
53
|
* A1 Notation Validation Utilities
|
|
63
54
|
*/
|
|
@@ -103,64 +94,6 @@ export declare function calculateRangeDimensions(notation: string): RangeDimensi
|
|
|
103
94
|
* Counts cells in a finite sheet-local range, rejecting reversed bounds.
|
|
104
95
|
*/
|
|
105
96
|
export declare function calculateFiniteRangeCellCount(notation: string): number;
|
|
106
|
-
export declare function calculateTotalCells(ranges: string[]): number;
|
|
107
|
-
/**
|
|
108
|
-
* Batch Operation Builders for Google API
|
|
109
|
-
*/
|
|
110
|
-
/**
|
|
111
|
-
* Builds a values batch update request for Google Sheets API
|
|
112
|
-
*/
|
|
113
|
-
export declare function buildValuesBatchUpdateRequest(requests: Array<{
|
|
114
|
-
range: string;
|
|
115
|
-
values: (string | number | boolean | null | undefined)[][];
|
|
116
|
-
majorDimension?: 'ROWS' | 'COLUMNS';
|
|
117
|
-
}>, sheetTitle: string, options?: {
|
|
118
|
-
valueInputOption?: 'RAW' | 'USER_ENTERED';
|
|
119
|
-
includeValuesInResponse?: boolean;
|
|
120
|
-
responseDateTimeRenderOption?: 'FORMATTED_STRING' | 'SERIAL_NUMBER';
|
|
121
|
-
responseValueRenderOption?: 'FORMATTED_VALUE' | 'UNFORMATTED_VALUE' | 'FORMULA';
|
|
122
|
-
}): {
|
|
123
|
-
valueInputOption: "RAW" | "USER_ENTERED";
|
|
124
|
-
data: {
|
|
125
|
-
range: string;
|
|
126
|
-
values: (string | number | boolean | null | undefined)[][];
|
|
127
|
-
majorDimension: "ROWS" | "COLUMNS";
|
|
128
|
-
}[];
|
|
129
|
-
includeValuesInResponse: boolean;
|
|
130
|
-
responseDateTimeRenderOption: "FORMATTED_STRING" | "SERIAL_NUMBER";
|
|
131
|
-
responseValueRenderOption: "UNFORMATTED_VALUE" | "FORMATTED_VALUE" | "FORMULA";
|
|
132
|
-
};
|
|
133
|
-
/**
|
|
134
|
-
* Range Conflict Detection
|
|
135
|
-
*/
|
|
136
|
-
/**
|
|
137
|
-
* Checks if two ranges overlap
|
|
138
|
-
*/
|
|
139
|
-
export declare function rangesOverlap(range1: string, range2: string): boolean;
|
|
140
|
-
/**
|
|
141
|
-
* Detects conflicts between multiple ranges
|
|
142
|
-
*/
|
|
143
|
-
export declare function detectRangeConflicts(ranges: string[]): RangeConflict[];
|
|
144
|
-
/**
|
|
145
|
-
* Validates that a batch of ranges doesn't exceed Google Sheets limits
|
|
146
|
-
*/
|
|
147
|
-
export declare function validateBatchRanges(ranges: string[]): {
|
|
148
|
-
valid: boolean;
|
|
149
|
-
errors: string[];
|
|
150
|
-
warnings: string[];
|
|
151
|
-
totalCells: number;
|
|
152
|
-
};
|
|
153
|
-
/**
|
|
154
|
-
* Utility Functions for Common Range Operations
|
|
155
|
-
*/
|
|
156
|
-
/**
|
|
157
|
-
* Expands a range by a specified number of rows and columns
|
|
158
|
-
*/
|
|
159
|
-
export declare function expandRange(notation: string, expandRows: number, expandCols: number): string;
|
|
160
|
-
/**
|
|
161
|
-
* Splits a large range into smaller chunks for batch processing
|
|
162
|
-
*/
|
|
163
|
-
export declare function splitRangeIntoChunks(notation: string, maxCellsPerChunk?: number): string[];
|
|
164
97
|
/**
|
|
165
98
|
* Converts a RangeReference to Google Sheets API GridRange format
|
|
166
99
|
*
|
|
@@ -25,9 +25,6 @@ _export(exports, {
|
|
|
25
25
|
get GOOGLE_SHEETS_LIMITS () {
|
|
26
26
|
return GOOGLE_SHEETS_LIMITS;
|
|
27
27
|
},
|
|
28
|
-
get buildValuesBatchUpdateRequest () {
|
|
29
|
-
return buildValuesBatchUpdateRequest;
|
|
30
|
-
},
|
|
31
28
|
get calculateFiniteRangeCellCount () {
|
|
32
29
|
return calculateFiniteRangeCellCount;
|
|
33
30
|
},
|
|
@@ -37,9 +34,6 @@ _export(exports, {
|
|
|
37
34
|
get calculateRangeDimensions () {
|
|
38
35
|
return calculateRangeDimensions;
|
|
39
36
|
},
|
|
40
|
-
get calculateTotalCells () {
|
|
41
|
-
return calculateTotalCells;
|
|
42
|
-
},
|
|
43
37
|
get cellBlockToA1 () {
|
|
44
38
|
return cellBlockToA1;
|
|
45
39
|
},
|
|
@@ -49,12 +43,6 @@ _export(exports, {
|
|
|
49
43
|
get columnStringToIndex () {
|
|
50
44
|
return columnStringToIndex;
|
|
51
45
|
},
|
|
52
|
-
get detectRangeConflicts () {
|
|
53
|
-
return detectRangeConflicts;
|
|
54
|
-
},
|
|
55
|
-
get expandRange () {
|
|
56
|
-
return expandRange;
|
|
57
|
-
},
|
|
58
46
|
get isValidA1Notation () {
|
|
59
47
|
return isValidA1Notation;
|
|
60
48
|
},
|
|
@@ -73,17 +61,8 @@ _export(exports, {
|
|
|
73
61
|
get rangeToA1Notation () {
|
|
74
62
|
return rangeToA1Notation;
|
|
75
63
|
},
|
|
76
|
-
get rangesOverlap () {
|
|
77
|
-
return rangesOverlap;
|
|
78
|
-
},
|
|
79
|
-
get splitRangeIntoChunks () {
|
|
80
|
-
return splitRangeIntoChunks;
|
|
81
|
-
},
|
|
82
64
|
get validateA1Notation () {
|
|
83
65
|
return validateA1Notation;
|
|
84
|
-
},
|
|
85
|
-
get validateBatchRanges () {
|
|
86
|
-
return validateBatchRanges;
|
|
87
66
|
}
|
|
88
67
|
});
|
|
89
68
|
var _columnutilitiests = require("./column-utilities.js");
|
|
@@ -400,221 +379,6 @@ function calculateFiniteRangeCellCount(notation) {
|
|
|
400
379
|
if (dimensions.rows < 1 || dimensions.columns < 1) throw new Error("Range end must not precede its start: ".concat(notation));
|
|
401
380
|
return dimensions.cells;
|
|
402
381
|
}
|
|
403
|
-
function calculateTotalCells(ranges) {
|
|
404
|
-
return ranges.reduce(function(total, range) {
|
|
405
|
-
var dimensions = calculateRangeDimensions(range);
|
|
406
|
-
return total + dimensions.cells;
|
|
407
|
-
}, 0);
|
|
408
|
-
}
|
|
409
|
-
function buildValuesBatchUpdateRequest(requests, sheetTitle) {
|
|
410
|
-
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
411
|
-
// Validate all ranges first
|
|
412
|
-
requests.forEach(function(req, index) {
|
|
413
|
-
try {
|
|
414
|
-
validateA1Notation(req.range);
|
|
415
|
-
} catch (error) {
|
|
416
|
-
throw new Error("Invalid range in request ".concat(index, ": ").concat(error));
|
|
417
|
-
}
|
|
418
|
-
});
|
|
419
|
-
// Calculate total cells for validation
|
|
420
|
-
var totalCells = calculateTotalCells(requests.map(function(r) {
|
|
421
|
-
return r.range;
|
|
422
|
-
}));
|
|
423
|
-
if (totalCells > GOOGLE_SHEETS_LIMITS.MAX_CELLS) {
|
|
424
|
-
throw new Error("Batch update exceeds maximum cells limit: ".concat(totalCells, " > ").concat(GOOGLE_SHEETS_LIMITS.MAX_CELLS));
|
|
425
|
-
}
|
|
426
|
-
// Build the request
|
|
427
|
-
var data = requests.map(function(req) {
|
|
428
|
-
return {
|
|
429
|
-
range: "".concat(sheetTitle, "!").concat(req.range),
|
|
430
|
-
values: req.values,
|
|
431
|
-
majorDimension: req.majorDimension || 'ROWS'
|
|
432
|
-
};
|
|
433
|
-
});
|
|
434
|
-
return {
|
|
435
|
-
valueInputOption: options.valueInputOption || 'USER_ENTERED',
|
|
436
|
-
data: data,
|
|
437
|
-
includeValuesInResponse: options.includeValuesInResponse || false,
|
|
438
|
-
responseDateTimeRenderOption: options.responseDateTimeRenderOption || 'FORMATTED_STRING',
|
|
439
|
-
responseValueRenderOption: options.responseValueRenderOption || 'FORMATTED_VALUE'
|
|
440
|
-
};
|
|
441
|
-
}
|
|
442
|
-
function rangesOverlap(range1, range2) {
|
|
443
|
-
try {
|
|
444
|
-
var parsed1 = parseA1Notation(range1);
|
|
445
|
-
var parsed2 = parseA1Notation(range2);
|
|
446
|
-
// Different types might still overlap, so we need to normalize to cell ranges
|
|
447
|
-
var normalized1 = normalizeRangeToBounds(parsed1);
|
|
448
|
-
var normalized2 = normalizeRangeToBounds(parsed2);
|
|
449
|
-
// Check for overlap
|
|
450
|
-
return !(normalized1.endRow < normalized2.startRow || normalized2.endRow < normalized1.startRow || normalized1.endCol < normalized2.startCol || normalized2.endCol < normalized1.startCol);
|
|
451
|
-
} catch (unused) {
|
|
452
|
-
// If we can't parse the ranges, assume no overlap
|
|
453
|
-
return false;
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
/**
|
|
457
|
-
* Normalizes a range to bounds for overlap checking
|
|
458
|
-
*/ function normalizeRangeToBounds(range) {
|
|
459
|
-
switch(range.type){
|
|
460
|
-
case 'cell':
|
|
461
|
-
if (!range.startCell) throw new Error('Invalid cell range');
|
|
462
|
-
return {
|
|
463
|
-
startRow: range.startCell.row,
|
|
464
|
-
endRow: range.startCell.row,
|
|
465
|
-
startCol: range.startCell.columnIndex,
|
|
466
|
-
endCol: range.startCell.columnIndex
|
|
467
|
-
};
|
|
468
|
-
case 'range':
|
|
469
|
-
if (!range.startCell || !range.endCell) throw new Error('Invalid range');
|
|
470
|
-
return {
|
|
471
|
-
startRow: range.startCell.row,
|
|
472
|
-
endRow: range.endCell.row,
|
|
473
|
-
startCol: range.startCell.columnIndex,
|
|
474
|
-
endCol: range.endCell.columnIndex
|
|
475
|
-
};
|
|
476
|
-
case 'column':
|
|
477
|
-
if (range.startColumnIndex === undefined || range.endColumnIndex === undefined) {
|
|
478
|
-
throw new Error('Invalid column range');
|
|
479
|
-
}
|
|
480
|
-
return {
|
|
481
|
-
startRow: 1,
|
|
482
|
-
endRow: GOOGLE_SHEETS_LIMITS.MAX_ROWS,
|
|
483
|
-
startCol: range.startColumnIndex,
|
|
484
|
-
endCol: range.endColumnIndex
|
|
485
|
-
};
|
|
486
|
-
case 'row':
|
|
487
|
-
if (range.startRow === undefined || range.endRow === undefined) {
|
|
488
|
-
throw new Error('Invalid row range');
|
|
489
|
-
}
|
|
490
|
-
return {
|
|
491
|
-
startRow: range.startRow,
|
|
492
|
-
endRow: range.endRow,
|
|
493
|
-
startCol: 1,
|
|
494
|
-
endCol: GOOGLE_SHEETS_LIMITS.MAX_COLUMNS
|
|
495
|
-
};
|
|
496
|
-
default:
|
|
497
|
-
throw new Error("Unknown range type: ".concat(range.type));
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
function detectRangeConflicts(ranges) {
|
|
501
|
-
var conflicts = [];
|
|
502
|
-
for(var i = 0; i < ranges.length; i++){
|
|
503
|
-
for(var j = i + 1; j < ranges.length; j++){
|
|
504
|
-
var range1 = ranges[i];
|
|
505
|
-
var range2 = ranges[j];
|
|
506
|
-
if (!range1 || !range2) continue;
|
|
507
|
-
if (rangesOverlap(range1, range2)) {
|
|
508
|
-
conflicts.push({
|
|
509
|
-
range1: range1,
|
|
510
|
-
range2: range2,
|
|
511
|
-
conflictType: 'overlap',
|
|
512
|
-
description: "Ranges ".concat(range1, " and ").concat(range2, " overlap")
|
|
513
|
-
});
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
return conflicts;
|
|
518
|
-
}
|
|
519
|
-
function validateBatchRanges(ranges) {
|
|
520
|
-
var errors = [];
|
|
521
|
-
var warnings = [];
|
|
522
|
-
var totalCells = 0;
|
|
523
|
-
// Validate each range
|
|
524
|
-
ranges.forEach(function(range, index) {
|
|
525
|
-
try {
|
|
526
|
-
validateA1Notation(range);
|
|
527
|
-
var dimensions = calculateRangeDimensions(range);
|
|
528
|
-
totalCells += dimensions.cells;
|
|
529
|
-
// Check for very large ranges that might cause performance issues
|
|
530
|
-
if (dimensions.cells > 1000000) {
|
|
531
|
-
warnings.push("Range ".concat(index + 1, " (").concat(range, ") affects ").concat(dimensions.cells.toLocaleString(), " cells, which may impact performance"));
|
|
532
|
-
}
|
|
533
|
-
} catch (error) {
|
|
534
|
-
errors.push("Range ".concat(index + 1, " (").concat(range, "): ").concat(error));
|
|
535
|
-
}
|
|
536
|
-
});
|
|
537
|
-
// Check batch size limits
|
|
538
|
-
if (ranges.length > GOOGLE_SHEETS_LIMITS.MAX_BATCH_REQUESTS) {
|
|
539
|
-
errors.push("Too many ranges: ".concat(ranges.length, " > ").concat(GOOGLE_SHEETS_LIMITS.MAX_BATCH_REQUESTS));
|
|
540
|
-
}
|
|
541
|
-
// Check total cells limit
|
|
542
|
-
if (totalCells > GOOGLE_SHEETS_LIMITS.MAX_CELLS) {
|
|
543
|
-
errors.push("Total cells exceed limit: ".concat(totalCells.toLocaleString(), " > ").concat(GOOGLE_SHEETS_LIMITS.MAX_CELLS.toLocaleString()));
|
|
544
|
-
}
|
|
545
|
-
// Check for conflicts
|
|
546
|
-
var conflicts = detectRangeConflicts(ranges);
|
|
547
|
-
conflicts.forEach(function(conflict) {
|
|
548
|
-
warnings.push(conflict.description);
|
|
549
|
-
});
|
|
550
|
-
return {
|
|
551
|
-
valid: errors.length === 0,
|
|
552
|
-
errors: errors,
|
|
553
|
-
warnings: warnings,
|
|
554
|
-
totalCells: totalCells
|
|
555
|
-
};
|
|
556
|
-
}
|
|
557
|
-
function expandRange(notation, expandRows, expandCols) {
|
|
558
|
-
var range = parseA1Notation(notation);
|
|
559
|
-
if (range.type === 'cell' && range.startCell) {
|
|
560
|
-
var newEndRow = Math.min(range.startCell.row + expandRows, GOOGLE_SHEETS_LIMITS.MAX_ROWS);
|
|
561
|
-
var newEndCol = Math.min(range.startCell.columnIndex + expandCols, GOOGLE_SHEETS_LIMITS.MAX_COLUMNS);
|
|
562
|
-
var newEndColStr = columnIndexToString(newEndCol);
|
|
563
|
-
if (expandRows === 0 && expandCols === 0) {
|
|
564
|
-
return notation;
|
|
565
|
-
}
|
|
566
|
-
return "".concat(range.startCell.column).concat(range.startCell.row, ":").concat(newEndColStr).concat(newEndRow);
|
|
567
|
-
}
|
|
568
|
-
if (range.type === 'range' && range.startCell && range.endCell) {
|
|
569
|
-
var newEndRow1 = Math.min(range.endCell.row + expandRows, GOOGLE_SHEETS_LIMITS.MAX_ROWS);
|
|
570
|
-
var newEndCol1 = Math.min(range.endCell.columnIndex + expandCols, GOOGLE_SHEETS_LIMITS.MAX_COLUMNS);
|
|
571
|
-
var newEndColStr1 = columnIndexToString(newEndCol1);
|
|
572
|
-
return "".concat(range.startCell.column).concat(range.startCell.row, ":").concat(newEndColStr1).concat(newEndRow1);
|
|
573
|
-
}
|
|
574
|
-
// For row and column ranges, expansion doesn't make sense in the same way
|
|
575
|
-
return notation;
|
|
576
|
-
}
|
|
577
|
-
function splitRangeIntoChunks(notation) {
|
|
578
|
-
var maxCellsPerChunk = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 100000;
|
|
579
|
-
var range = parseA1Notation(notation);
|
|
580
|
-
var dimensions = calculateRangeDimensions(notation);
|
|
581
|
-
if (dimensions.cells <= maxCellsPerChunk) {
|
|
582
|
-
return [
|
|
583
|
-
notation
|
|
584
|
-
];
|
|
585
|
-
}
|
|
586
|
-
var chunks = [];
|
|
587
|
-
if (range.type === 'range' && range.startCell && range.endCell) {
|
|
588
|
-
var totalRows = range.endCell.row - range.startCell.row + 1;
|
|
589
|
-
var totalCols = range.endCell.columnIndex - range.startCell.columnIndex + 1;
|
|
590
|
-
// Calculate chunk size based on max cells
|
|
591
|
-
var cellsPerRow = totalCols;
|
|
592
|
-
var maxRowsPerChunk = Math.floor(maxCellsPerChunk / cellsPerRow);
|
|
593
|
-
if (maxRowsPerChunk >= 1) {
|
|
594
|
-
// Split by rows
|
|
595
|
-
for(var currentRow = range.startCell.row; currentRow <= range.endCell.row; currentRow += maxRowsPerChunk){
|
|
596
|
-
var chunkEndRow = Math.min(currentRow + maxRowsPerChunk - 1, range.endCell.row);
|
|
597
|
-
var chunkRange = "".concat(range.startCell.column).concat(currentRow, ":").concat(range.endCell.column).concat(chunkEndRow);
|
|
598
|
-
chunks.push(chunkRange);
|
|
599
|
-
}
|
|
600
|
-
} else {
|
|
601
|
-
// If even one row is too big, split by columns
|
|
602
|
-
var maxColsPerChunk = Math.floor(maxCellsPerChunk / totalRows);
|
|
603
|
-
for(var currentCol = range.startCell.columnIndex; currentCol <= range.endCell.columnIndex; currentCol += maxColsPerChunk){
|
|
604
|
-
var chunkEndCol = Math.min(currentCol + maxColsPerChunk - 1, range.endCell.columnIndex);
|
|
605
|
-
var startColStr = columnIndexToString(currentCol);
|
|
606
|
-
var endColStr = columnIndexToString(chunkEndCol);
|
|
607
|
-
var chunkRange1 = "".concat(startColStr).concat(range.startCell.row, ":").concat(endColStr).concat(range.endCell.row);
|
|
608
|
-
chunks.push(chunkRange1);
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
} else {
|
|
612
|
-
// For other range types, just return the original range
|
|
613
|
-
// (column and row ranges are already at their limits)
|
|
614
|
-
chunks.push(notation);
|
|
615
|
-
}
|
|
616
|
-
return chunks;
|
|
617
|
-
}
|
|
618
382
|
function rangeReferenceToGridRange(rangeRef, sheetId) {
|
|
619
383
|
if (rangeRef.type === 'cell' || rangeRef.type === 'range') {
|
|
620
384
|
// For cell and range types, extract from startCell/endCell
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-sheets/src/spreadsheet/range-operations.ts"],"sourcesContent":["/**\n * Range Operations Utilities for Google Sheets\n *\n * This module provides comprehensive utilities for working with A1 notation,\n * range parsing, batch operations, and range validation in Google Sheets.\n *\n * Key features:\n * - A1 notation validation and parsing\n * - Range manipulation and calculation utilities\n * - Batch operation builders for Google Sheets API\n * - Cell count and dimension calculations\n * - Range conflict detection for batch operations\n * - Google Sheets limits validation and enforcement\n */\n\nimport { a1Col } from './column-utilities.ts';\n\n// Google Sheets constants and limits\nexport const GOOGLE_SHEETS_LIMITS = {\n MAX_ROWS: 10_000_000,\n MAX_COLUMNS: 18_278, // ZZZ in base-26\n MAX_CELLS: 10_000_000, // Approximate limit for total cells\n MAX_BATCH_REQUESTS: 1000,\n MAX_DIMENSION_BATCH_REQUESTS: 100,\n} as const;\n\n/**\n * Represents a parsed cell reference (e.g., A1, B5)\n */\nexport interface CellReference {\n column: string;\n columnIndex: number; // 1-based\n row: number; // 1-based\n}\n\n/**\n * Represents a parsed range (e.g., A1:B5, A:B, 1:2)\n */\nexport interface RangeReference {\n type: 'cell' | 'row' | 'column' | 'range';\n startCell?: CellReference;\n endCell?: CellReference;\n startRow?: number;\n endRow?: number;\n startColumn?: string;\n endColumn?: string;\n startColumnIndex?: number;\n endColumnIndex?: number;\n}\n\n/**\n * Represents dimensions of a range\n */\nexport interface RangeDimensions {\n rows: number;\n columns: number;\n cells: number;\n}\n\n/**\n * Represents a range conflict between two ranges\n */\nexport interface RangeConflict {\n range1: string;\n range2: string;\n conflictType: 'overlap' | 'contains' | 'contained' | 'adjacent';\n description: string;\n}\n\n/**\n * A1 Notation Validation Utilities\n */\n\n/**\n * Validates if a string is a valid A1 notation\n */\nexport function isValidA1Notation(notation: string): boolean {\n if (!notation || typeof notation !== 'string') {\n return false;\n }\n\n // Use the same regex pattern as in the schema\n const a1Pattern = /^(?:[A-Z]{1,3}(?:[1-9]\\d{0,6}|10000000)(?::[A-Z]{1,3}(?:[1-9]\\d{0,6}|10000000))?|[A-Z]{1,3}:[A-Z]{1,3}|(?:[1-9]\\d{0,6}|10000000):(?:[1-9]\\d{0,6}|10000000))$/;\n\n if (!a1Pattern.test(notation)) {\n return false;\n }\n\n // Additional validation for Google Sheets limits\n const parts = notation.split(':');\n\n for (const part of parts) {\n // Check cell reference\n const cellMatch = part.match(/^([A-Z]{1,3})([1-9]\\d{0,6}|10000000)$/);\n if (cellMatch && cellMatch[1] && cellMatch[2]) {\n const [, colStr, rowStr] = cellMatch;\n\n // Validate column\n const colNum = columnStringToIndex(colStr);\n if (colNum > GOOGLE_SHEETS_LIMITS.MAX_COLUMNS) {\n return false;\n }\n\n // Validate row\n const rowNum = parseInt(rowStr, 10);\n if (rowNum > GOOGLE_SHEETS_LIMITS.MAX_ROWS) {\n return false;\n }\n }\n\n // Check column reference\n const colMatch = part.match(/^([A-Z]{1,3})$/);\n if (colMatch && colMatch[1]) {\n const colNum = columnStringToIndex(colMatch[1]);\n if (colNum > GOOGLE_SHEETS_LIMITS.MAX_COLUMNS) {\n return false;\n }\n }\n\n // Check row reference\n const rowMatch = part.match(/^([1-9]\\d{0,6}|10000000)$/);\n if (rowMatch && rowMatch[1]) {\n const rowNum = parseInt(rowMatch[1], 10);\n if (rowNum > GOOGLE_SHEETS_LIMITS.MAX_ROWS) {\n return false;\n }\n }\n }\n\n return true;\n}\n\n/**\n * Validates A1 notation and throws detailed error if invalid\n */\nexport function validateA1Notation(notation: string): void {\n if (!isValidA1Notation(notation)) {\n throw new Error(`Invalid A1 notation: \"${notation}\". Valid formats: A1, A1:B2, A:B, 1:2`);\n }\n}\n\n/**\n * Range Parsing and Manipulation Functions\n */\n\n/**\n * Converts column string (A, B, AA, etc.) to 1-based index\n */\nexport function columnStringToIndex(colStr: string): number {\n let colNum = 0;\n for (let i = 0; i < colStr.length; i++) {\n colNum = colNum * 26 + (colStr.charCodeAt(i) - 64);\n }\n return colNum;\n}\n\n/**\n * Converts 1-based column index to column string (A, B, AA, etc.)\n */\nexport function columnIndexToString(colIndex: number): string {\n return a1Col(colIndex);\n}\n\n/**\n * Parses a cell reference (e.g., \"A1\", \"Z999\") into its components\n */\nexport function parseCellReference(cellRef: string): CellReference {\n const match = cellRef.match(/^([A-Z]{1,3})([1-9]\\d{0,6}|10000000)$/);\n if (!match || !match[1] || !match[2]) {\n throw new Error(`Invalid cell reference: ${cellRef}`);\n }\n\n const [, column, rowStr] = match;\n const row = parseInt(rowStr, 10);\n const columnIndex = columnStringToIndex(column);\n\n return {\n column,\n columnIndex,\n row,\n };\n}\n\n/**\n * Parses A1 notation into a structured range reference\n */\nexport function parseA1Notation(notation: string): RangeReference {\n validateA1Notation(notation);\n\n const parts = notation.split(':');\n\n if (parts.length === 1) {\n const part = parts[0];\n if (!part) {\n throw new Error('Invalid A1 notation: empty part after split');\n }\n\n // Single cell reference (e.g., A1)\n const cellMatch = part.match(/^([A-Z]{1,3})([1-9]\\d{0,6}|10000000)$/);\n if (cellMatch && cellMatch[1] && cellMatch[2]) {\n const startCell = parseCellReference(part);\n return {\n type: 'cell',\n startCell,\n endCell: startCell,\n };\n }\n\n // Single column reference (e.g., A)\n const colMatch = part.match(/^([A-Z]{1,3})$/);\n if (colMatch && colMatch[1]) {\n const column = colMatch[1];\n const columnIndex = columnStringToIndex(column);\n return {\n type: 'column',\n startColumn: column,\n endColumn: column,\n startColumnIndex: columnIndex,\n endColumnIndex: columnIndex,\n };\n }\n\n // Single row reference (e.g., 1)\n const rowMatch = part.match(/^([1-9]\\d{0,6}|10000000)$/);\n if (rowMatch && rowMatch[1]) {\n const row = parseInt(rowMatch[1], 10);\n return {\n type: 'row',\n startRow: row,\n endRow: row,\n };\n }\n }\n\n if (parts.length === 2 && parts[0] && parts[1]) {\n const [start, end] = parts;\n\n // Cell range (e.g., A1:B5)\n const startCellMatch = start.match(/^([A-Z]{1,3})([1-9]\\d{0,6}|10000000)$/);\n const endCellMatch = end.match(/^([A-Z]{1,3})([1-9]\\d{0,6}|10000000)$/);\n\n if (startCellMatch && endCellMatch && startCellMatch[1] && startCellMatch[2] && endCellMatch[1] && endCellMatch[2]) {\n const startCell = parseCellReference(start);\n const endCell = parseCellReference(end);\n return {\n type: 'range',\n startCell,\n endCell,\n };\n }\n\n // Column range (e.g., A:B)\n const startColMatch = start.match(/^([A-Z]{1,3})$/);\n const endColMatch = end.match(/^([A-Z]{1,3})$/);\n\n if (startColMatch && endColMatch && startColMatch[1] && endColMatch[1]) {\n const startColumn = startColMatch[1];\n const endColumn = endColMatch[1];\n const startColumnIndex = columnStringToIndex(startColumn);\n const endColumnIndex = columnStringToIndex(endColumn);\n return {\n type: 'column',\n startColumn,\n endColumn,\n startColumnIndex,\n endColumnIndex,\n };\n }\n\n // Row range (e.g., 1:5)\n const startRowMatch = start.match(/^([1-9]\\d{0,6}|10000000)$/);\n const endRowMatch = end.match(/^([1-9]\\d{0,6}|10000000)$/);\n\n if (startRowMatch && endRowMatch && startRowMatch[1] && endRowMatch[1]) {\n const startRow = parseInt(startRowMatch[1], 10);\n const endRow = parseInt(endRowMatch[1], 10);\n return {\n type: 'row',\n startRow,\n endRow,\n };\n }\n }\n\n throw new Error(`Unable to parse A1 notation: ${notation}`);\n}\n\n/**\n * Converts a range reference back to A1 notation\n */\nexport function rangeToA1Notation(range: RangeReference): string {\n switch (range.type) {\n case 'cell':\n if (!range.startCell) throw new Error('Invalid cell range: missing startCell');\n return `${range.startCell.column}${range.startCell.row}`;\n\n case 'range':\n if (!range.startCell || !range.endCell) throw new Error('Invalid range: missing start or end cell');\n return `${range.startCell.column}${range.startCell.row}:${range.endCell.column}${range.endCell.row}`;\n\n case 'column':\n if (!range.startColumn || !range.endColumn) throw new Error('Invalid column range: missing start or end column');\n if (range.startColumn === range.endColumn) {\n return range.startColumn;\n }\n return `${range.startColumn}:${range.endColumn}`;\n\n case 'row':\n if (range.startRow === undefined || range.endRow === undefined) throw new Error('Invalid row range: missing start or end row');\n if (range.startRow === range.endRow) {\n return range.startRow.toString();\n }\n return `${range.startRow}:${range.endRow}`;\n\n default:\n throw new Error(`Unknown range type: ${(range as { type: unknown }).type}`);\n }\n}\n\n/**\n * Cell Count and Dimension Calculation Utilities\n */\n\n/**\n * Calculates the dimensions of a range\n */\nexport function calculateRangeDimensions(notation: string): RangeDimensions {\n const range = parseA1Notation(notation);\n\n switch (range.type) {\n case 'cell':\n return { rows: 1, columns: 1, cells: 1 };\n\n case 'range': {\n if (!range.startCell || !range.endCell) throw new Error('Invalid range: missing cells');\n const rows = range.endCell.row - range.startCell.row + 1;\n const columns = range.endCell.columnIndex - range.startCell.columnIndex + 1;\n return { rows, columns, cells: rows * columns };\n }\n\n case 'column': {\n if (range.startColumnIndex === undefined || range.endColumnIndex === undefined) {\n throw new Error('Invalid column range: missing column indices');\n }\n const columnCount = range.endColumnIndex - range.startColumnIndex + 1;\n return {\n rows: GOOGLE_SHEETS_LIMITS.MAX_ROWS,\n columns: columnCount,\n cells: GOOGLE_SHEETS_LIMITS.MAX_ROWS * columnCount,\n };\n }\n\n case 'row': {\n if (range.startRow === undefined || range.endRow === undefined) {\n throw new Error('Invalid row range: missing row numbers');\n }\n const rowCount = range.endRow - range.startRow + 1;\n return {\n rows: rowCount,\n columns: GOOGLE_SHEETS_LIMITS.MAX_COLUMNS,\n cells: rowCount * GOOGLE_SHEETS_LIMITS.MAX_COLUMNS,\n };\n }\n\n default:\n throw new Error(`Unknown range type: ${(range as { type: string }).type}`);\n }\n}\n\n/**\n * Counts cells in a finite sheet-local range, rejecting reversed bounds.\n */\nexport function calculateFiniteRangeCellCount(notation: string): number {\n const range = parseA1Notation(notation);\n if (range.type !== 'cell' && range.type !== 'range') {\n throw new Error(`Range must have finite start and end rows and columns: ${notation}`);\n }\n const dimensions = calculateRangeDimensions(notation);\n if (dimensions.rows < 1 || dimensions.columns < 1) throw new Error(`Range end must not precede its start: ${notation}`);\n return dimensions.cells;\n}\n\nexport function calculateTotalCells(ranges: string[]): number {\n return ranges.reduce((total, range) => {\n const dimensions = calculateRangeDimensions(range);\n return total + dimensions.cells;\n }, 0);\n}\n\n/**\n * Batch Operation Builders for Google API\n */\n\n/**\n * Builds a values batch update request for Google Sheets API\n */\nexport function buildValuesBatchUpdateRequest(\n requests: Array<{\n range: string;\n values: (string | number | boolean | null | undefined)[][];\n majorDimension?: 'ROWS' | 'COLUMNS';\n }>,\n sheetTitle: string,\n options: {\n valueInputOption?: 'RAW' | 'USER_ENTERED';\n includeValuesInResponse?: boolean;\n responseDateTimeRenderOption?: 'FORMATTED_STRING' | 'SERIAL_NUMBER';\n responseValueRenderOption?: 'FORMATTED_VALUE' | 'UNFORMATTED_VALUE' | 'FORMULA';\n } = {}\n) {\n // Validate all ranges first\n requests.forEach((req, index) => {\n try {\n validateA1Notation(req.range);\n } catch (error) {\n throw new Error(`Invalid range in request ${index}: ${error}`);\n }\n });\n\n // Calculate total cells for validation\n const totalCells = calculateTotalCells(requests.map((r) => r.range));\n if (totalCells > GOOGLE_SHEETS_LIMITS.MAX_CELLS) {\n throw new Error(`Batch update exceeds maximum cells limit: ${totalCells} > ${GOOGLE_SHEETS_LIMITS.MAX_CELLS}`);\n }\n\n // Build the request\n const data = requests.map((req) => ({\n range: `${sheetTitle}!${req.range}`,\n values: req.values,\n majorDimension: req.majorDimension || 'ROWS',\n }));\n\n return {\n valueInputOption: options.valueInputOption || 'USER_ENTERED',\n data,\n includeValuesInResponse: options.includeValuesInResponse || false,\n responseDateTimeRenderOption: options.responseDateTimeRenderOption || 'FORMATTED_STRING',\n responseValueRenderOption: options.responseValueRenderOption || 'FORMATTED_VALUE',\n };\n}\n\n/**\n * Range Conflict Detection\n */\n\n/**\n * Checks if two ranges overlap\n */\nexport function rangesOverlap(range1: string, range2: string): boolean {\n try {\n const parsed1 = parseA1Notation(range1);\n const parsed2 = parseA1Notation(range2);\n\n // Different types might still overlap, so we need to normalize to cell ranges\n const normalized1 = normalizeRangeToBounds(parsed1);\n const normalized2 = normalizeRangeToBounds(parsed2);\n\n // Check for overlap\n return !(normalized1.endRow < normalized2.startRow || normalized2.endRow < normalized1.startRow || normalized1.endCol < normalized2.startCol || normalized2.endCol < normalized1.startCol);\n } catch {\n // If we can't parse the ranges, assume no overlap\n return false;\n }\n}\n\n/**\n * Normalizes a range to bounds for overlap checking\n */\nfunction normalizeRangeToBounds(range: RangeReference): {\n startRow: number;\n endRow: number;\n startCol: number;\n endCol: number;\n} {\n switch (range.type) {\n case 'cell':\n if (!range.startCell) throw new Error('Invalid cell range');\n return {\n startRow: range.startCell.row,\n endRow: range.startCell.row,\n startCol: range.startCell.columnIndex,\n endCol: range.startCell.columnIndex,\n };\n\n case 'range':\n if (!range.startCell || !range.endCell) throw new Error('Invalid range');\n return {\n startRow: range.startCell.row,\n endRow: range.endCell.row,\n startCol: range.startCell.columnIndex,\n endCol: range.endCell.columnIndex,\n };\n\n case 'column':\n if (range.startColumnIndex === undefined || range.endColumnIndex === undefined) {\n throw new Error('Invalid column range');\n }\n return {\n startRow: 1,\n endRow: GOOGLE_SHEETS_LIMITS.MAX_ROWS,\n startCol: range.startColumnIndex,\n endCol: range.endColumnIndex,\n };\n\n case 'row':\n if (range.startRow === undefined || range.endRow === undefined) {\n throw new Error('Invalid row range');\n }\n return {\n startRow: range.startRow,\n endRow: range.endRow,\n startCol: 1,\n endCol: GOOGLE_SHEETS_LIMITS.MAX_COLUMNS,\n };\n\n default:\n throw new Error(`Unknown range type: ${(range as { type: unknown }).type}`);\n }\n}\n\n/**\n * Detects conflicts between multiple ranges\n */\nexport function detectRangeConflicts(ranges: string[]): RangeConflict[] {\n const conflicts: RangeConflict[] = [];\n\n for (let i = 0; i < ranges.length; i++) {\n for (let j = i + 1; j < ranges.length; j++) {\n const range1 = ranges[i];\n const range2 = ranges[j];\n\n if (!range1 || !range2) continue;\n\n if (rangesOverlap(range1, range2)) {\n conflicts.push({\n range1,\n range2,\n conflictType: 'overlap',\n description: `Ranges ${range1} and ${range2} overlap`,\n });\n }\n }\n }\n\n return conflicts;\n}\n\n/**\n * Validates that a batch of ranges doesn't exceed Google Sheets limits\n */\nexport function validateBatchRanges(ranges: string[]): {\n valid: boolean;\n errors: string[];\n warnings: string[];\n totalCells: number;\n} {\n const errors: string[] = [];\n const warnings: string[] = [];\n let totalCells = 0;\n\n // Validate each range\n ranges.forEach((range, index) => {\n try {\n validateA1Notation(range);\n const dimensions = calculateRangeDimensions(range);\n totalCells += dimensions.cells;\n\n // Check for very large ranges that might cause performance issues\n if (dimensions.cells > 1_000_000) {\n warnings.push(`Range ${index + 1} (${range}) affects ${dimensions.cells.toLocaleString()} cells, which may impact performance`);\n }\n } catch (error) {\n errors.push(`Range ${index + 1} (${range}): ${error}`);\n }\n });\n\n // Check batch size limits\n if (ranges.length > GOOGLE_SHEETS_LIMITS.MAX_BATCH_REQUESTS) {\n errors.push(`Too many ranges: ${ranges.length} > ${GOOGLE_SHEETS_LIMITS.MAX_BATCH_REQUESTS}`);\n }\n\n // Check total cells limit\n if (totalCells > GOOGLE_SHEETS_LIMITS.MAX_CELLS) {\n errors.push(`Total cells exceed limit: ${totalCells.toLocaleString()} > ${GOOGLE_SHEETS_LIMITS.MAX_CELLS.toLocaleString()}`);\n }\n\n // Check for conflicts\n const conflicts = detectRangeConflicts(ranges);\n conflicts.forEach((conflict) => {\n warnings.push(conflict.description);\n });\n\n return {\n valid: errors.length === 0,\n errors,\n warnings,\n totalCells,\n };\n}\n\n/**\n * Utility Functions for Common Range Operations\n */\n\n/**\n * Expands a range by a specified number of rows and columns\n */\nexport function expandRange(notation: string, expandRows: number, expandCols: number): string {\n const range = parseA1Notation(notation);\n\n if (range.type === 'cell' && range.startCell) {\n const newEndRow = Math.min(range.startCell.row + expandRows, GOOGLE_SHEETS_LIMITS.MAX_ROWS);\n const newEndCol = Math.min(range.startCell.columnIndex + expandCols, GOOGLE_SHEETS_LIMITS.MAX_COLUMNS);\n const newEndColStr = columnIndexToString(newEndCol);\n\n if (expandRows === 0 && expandCols === 0) {\n return notation;\n }\n\n return `${range.startCell.column}${range.startCell.row}:${newEndColStr}${newEndRow}`;\n }\n\n if (range.type === 'range' && range.startCell && range.endCell) {\n const newEndRow = Math.min(range.endCell.row + expandRows, GOOGLE_SHEETS_LIMITS.MAX_ROWS);\n const newEndCol = Math.min(range.endCell.columnIndex + expandCols, GOOGLE_SHEETS_LIMITS.MAX_COLUMNS);\n const newEndColStr = columnIndexToString(newEndCol);\n\n return `${range.startCell.column}${range.startCell.row}:${newEndColStr}${newEndRow}`;\n }\n\n // For row and column ranges, expansion doesn't make sense in the same way\n return notation;\n}\n\n/**\n * Splits a large range into smaller chunks for batch processing\n */\nexport function splitRangeIntoChunks(notation: string, maxCellsPerChunk = 100_000): string[] {\n const range = parseA1Notation(notation);\n const dimensions = calculateRangeDimensions(notation);\n\n if (dimensions.cells <= maxCellsPerChunk) {\n return [notation];\n }\n\n const chunks: string[] = [];\n\n if (range.type === 'range' && range.startCell && range.endCell) {\n const totalRows = range.endCell.row - range.startCell.row + 1;\n const totalCols = range.endCell.columnIndex - range.startCell.columnIndex + 1;\n\n // Calculate chunk size based on max cells\n const cellsPerRow = totalCols;\n const maxRowsPerChunk = Math.floor(maxCellsPerChunk / cellsPerRow);\n\n if (maxRowsPerChunk >= 1) {\n // Split by rows\n for (let currentRow = range.startCell.row; currentRow <= range.endCell.row; currentRow += maxRowsPerChunk) {\n const chunkEndRow = Math.min(currentRow + maxRowsPerChunk - 1, range.endCell.row);\n const chunkRange = `${range.startCell.column}${currentRow}:${range.endCell.column}${chunkEndRow}`;\n chunks.push(chunkRange);\n }\n } else {\n // If even one row is too big, split by columns\n const maxColsPerChunk = Math.floor(maxCellsPerChunk / totalRows);\n\n for (let currentCol = range.startCell.columnIndex; currentCol <= range.endCell.columnIndex; currentCol += maxColsPerChunk) {\n const chunkEndCol = Math.min(currentCol + maxColsPerChunk - 1, range.endCell.columnIndex);\n const startColStr = columnIndexToString(currentCol);\n const endColStr = columnIndexToString(chunkEndCol);\n const chunkRange = `${startColStr}${range.startCell.row}:${endColStr}${range.endCell.row}`;\n chunks.push(chunkRange);\n }\n }\n } else {\n // For other range types, just return the original range\n // (column and row ranges are already at their limits)\n chunks.push(notation);\n }\n\n return chunks;\n}\n\n/**\n * Converts a RangeReference to Google Sheets API GridRange format\n *\n * This handles the different range types correctly:\n * - 'cell' and 'range' types: Extract indices from startCell/endCell\n * - 'row' types: Use startRow/endRow, omit column indices for full row\n * - 'column' types: Use startColumnIndex/endColumnIndex, omit row indices for full column\n *\n * Important: Google Sheets API uses 0-based indices, while A1 notation uses 1-based indices.\n * This function handles the conversion properly for each range type.\n */\nexport function rangeReferenceToGridRange(\n rangeRef: RangeReference,\n sheetId: number\n): {\n sheetId: number;\n startRowIndex?: number;\n endRowIndex?: number;\n startColumnIndex?: number;\n endColumnIndex?: number;\n} {\n if (rangeRef.type === 'cell' || rangeRef.type === 'range') {\n // For cell and range types, extract from startCell/endCell\n if (!rangeRef.startCell || !rangeRef.endCell) {\n throw new Error(`Invalid ${rangeRef.type} range: missing start or end cell`);\n }\n\n return {\n sheetId,\n // Convert 1-based row to 0-based startRowIndex\n startRowIndex: rangeRef.startCell.row - 1,\n // endRowIndex is exclusive (so row 5 becomes endRowIndex 5)\n endRowIndex: rangeRef.endCell.row,\n // Convert 1-based column index to 0-based startColumnIndex\n startColumnIndex: rangeRef.startCell.columnIndex - 1,\n // endColumnIndex is exclusive\n endColumnIndex: rangeRef.endCell.columnIndex,\n };\n }\n if (rangeRef.type === 'row') {\n // For row types, use startRow/endRow and omit column indices for full row width\n if (rangeRef.startRow === undefined || rangeRef.endRow === undefined) {\n throw new Error('Invalid row range: missing start or end row');\n }\n\n return {\n sheetId,\n // Convert 1-based row to 0-based startRowIndex\n startRowIndex: rangeRef.startRow - 1,\n // endRowIndex is exclusive\n endRowIndex: rangeRef.endRow,\n // Omit startColumnIndex and endColumnIndex to apply to all columns\n };\n }\n if (rangeRef.type === 'column') {\n // For column types, use startColumnIndex/endColumnIndex and omit row indices for full column height\n if (rangeRef.startColumnIndex === undefined || rangeRef.endColumnIndex === undefined) {\n throw new Error('Invalid column range: missing start or end column index');\n }\n\n return {\n sheetId,\n // Omit startRowIndex and endRowIndex to apply to all rows\n // Convert 1-based column index to 0-based startColumnIndex\n startColumnIndex: rangeRef.startColumnIndex - 1,\n // endColumnIndex is exclusive\n endColumnIndex: rangeRef.endColumnIndex,\n };\n }\n\n throw new Error(`Unknown range type: ${(rangeRef as { type: unknown }).type}`);\n}\n\n/**\n * A finite, sheet-local block of cells with 1-based inclusive bounds.\n */\nexport interface CellBlock {\n startRow: number;\n endRow: number;\n startColumn: number;\n endColumn: number;\n}\n\n/**\n * Parses a finite sheet-local A1 range (cell or range) into 1-based inclusive bounds.\n * Throws for invalid syntax, whole rows/columns and reversed bounds.\n */\nexport function parseFiniteCellBlock(notation: string): CellBlock {\n const range = parseA1Notation(notation);\n if (range.type !== 'cell' && range.type !== 'range') {\n throw new Error(`Range must have finite start and end rows and columns: ${notation}`);\n }\n calculateFiniteRangeCellCount(notation);\n if (!range.startCell || !range.endCell) throw new Error(`Invalid range: ${notation}`);\n return { startRow: range.startCell.row, endRow: range.endCell.row, startColumn: range.startCell.columnIndex, endColumn: range.endCell.columnIndex };\n}\n\n/**\n * Formats a block as A1 notation (a single cell when it spans one cell).\n */\nexport function cellBlockToA1(block: CellBlock): string {\n const start = `${columnIndexToString(block.startColumn)}${block.startRow}`;\n if (block.startRow === block.endRow && block.startColumn === block.endColumn) return start;\n return `${start}:${columnIndexToString(block.endColumn)}${block.endRow}`;\n}\n\n/**\n * Footprint of a copy-paste: the cells written in the destination.\n *\n * - destination is one cell: the (oriented) source size anchored at that cell\n * - destination is a range whose height and width are whole multiples of the oriented source: the destination itself (the source is tiled)\n * - anything else throws\n */\nexport function calculatePasteRange(source: string, destination: string, orientation: 'NORMAL' | 'TRANSPOSE'): CellBlock {\n const src = parseFiniteCellBlock(source);\n const dest = parseFiniteCellBlock(destination);\n const srcRows = src.endRow - src.startRow + 1;\n const srcColumns = src.endColumn - src.startColumn + 1;\n const rows = orientation === 'TRANSPOSE' ? srcColumns : srcRows;\n const columns = orientation === 'TRANSPOSE' ? srcRows : srcColumns;\n const destRows = dest.endRow - dest.startRow + 1;\n const destColumns = dest.endColumn - dest.startColumn + 1;\n\n if (destRows === 1 && destColumns === 1) {\n return { startRow: dest.startRow, endRow: dest.startRow + rows - 1, startColumn: dest.startColumn, endColumn: dest.startColumn + columns - 1 };\n }\n if (destRows % rows === 0 && destColumns % columns === 0) return dest;\n throw new Error(\n `Destination ${destination} is ${destRows}x${destColumns} cells; the ${orientation === 'TRANSPOSE' ? 'transposed ' : ''}source ${source} is ${rows}x${columns}. Use a single anchor cell (e.g., ${columnIndexToString(dest.startColumn)}${dest.startRow}) or a range whose height and width are whole multiples of ${rows}x${columns}.`\n );\n}\n"],"names":["GOOGLE_SHEETS_LIMITS","buildValuesBatchUpdateRequest","calculateFiniteRangeCellCount","calculatePasteRange","calculateRangeDimensions","calculateTotalCells","cellBlockToA1","columnIndexToString","columnStringToIndex","detectRangeConflicts","expandRange","isValidA1Notation","parseA1Notation","parseCellReference","parseFiniteCellBlock","rangeReferenceToGridRange","rangeToA1Notation","rangesOverlap","splitRangeIntoChunks","validateA1Notation","validateBatchRanges","MAX_ROWS","MAX_COLUMNS","MAX_CELLS","MAX_BATCH_REQUESTS","MAX_DIMENSION_BATCH_REQUESTS","notation","a1Pattern","test","parts","split","part","cellMatch","match","colStr","rowStr","colNum","rowNum","parseInt","colMatch","rowMatch","Error","i","length","charCodeAt","colIndex","a1Col","cellRef","column","row","columnIndex","startCell","type","endCell","startColumn","endColumn","startColumnIndex","endColumnIndex","startRow","endRow","start","end","startCellMatch","endCellMatch","startColMatch","endColMatch","startRowMatch","endRowMatch","range","undefined","toString","rows","columns","cells","columnCount","rowCount","dimensions","ranges","reduce","total","requests","sheetTitle","options","forEach","req","index","error","totalCells","map","r","data","values","majorDimension","valueInputOption","includeValuesInResponse","responseDateTimeRenderOption","responseValueRenderOption","range1","range2","parsed1","parsed2","normalized1","normalizeRangeToBounds","normalized2","endCol","startCol","conflicts","j","push","conflictType","description","errors","warnings","toLocaleString","conflict","valid","expandRows","expandCols","newEndRow","Math","min","newEndCol","newEndColStr","maxCellsPerChunk","chunks","totalRows","totalCols","cellsPerRow","maxRowsPerChunk","floor","currentRow","chunkEndRow","chunkRange","maxColsPerChunk","currentCol","chunkEndCol","startColStr","endColStr","rangeRef","sheetId","startRowIndex","endRowIndex","block","source","destination","orientation","src","dest","srcRows","srcColumns","destRows","destColumns"],"mappings":"AAAA;;;;;;;;;;;;;CAaC;;;;;;;;;;;QAKYA;eAAAA;;QA0XGC;eAAAA;;QAxBAC;eAAAA;;QAwaAC;eAAAA;;QAtdAC;eAAAA;;QAwDAC;eAAAA;;QAiZAC;eAAAA;;QAhnBAC;eAAAA;;QAXAC;eAAAA;;QAuXAC;eAAAA;;QAoFAC;eAAAA;;QAnhBAC;eAAAA;;QA8GAC;eAAAA;;QApBAC;eAAAA;;QA4lBAC;eAAAA;;QA5EAC;eAAAA;;QApZAC;eAAAA;;QA8JAC;eAAAA;;QA6LAC;eAAAA;;QAtfAC;eAAAA;;QA+ZAC;eAAAA;;;iCAvhBM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGf,IAAMpB,uBAAuB;IAClCqB,UAAU;IACVC,aAAa;IACbC,WAAW;IACXC,oBAAoB;IACpBC,8BAA8B;AAChC;AAoDO,SAASd,kBAAkBe,QAAgB;IAChD,IAAI,CAACA,YAAY,OAAOA,aAAa,UAAU;QAC7C,OAAO;IACT;IAEA,8CAA8C;IAC9C,IAAMC,YAAY;IAElB,IAAI,CAACA,UAAUC,IAAI,CAACF,WAAW;QAC7B,OAAO;IACT;IAEA,iDAAiD;IACjD,IAAMG,QAAQH,SAASI,KAAK,CAAC;QAExB,kCAAA,2BAAA;;QAAL,QAAK,YAAcD,0BAAd,SAAA,6BAAA,QAAA,yBAAA,iCAAqB;YAArB,IAAME,OAAN;YACH,uBAAuB;YACvB,IAAMC,YAAYD,KAAKE,KAAK,CAAC;YAC7B,IAAID,aAAaA,SAAS,CAAC,EAAE,IAAIA,SAAS,CAAC,EAAE,EAAE;gBAC7C,IAA2BA,8BAAAA,eAAlBE,SAAkBF,eAAVG,SAAUH;gBAE3B,kBAAkB;gBAClB,IAAMI,SAAS5B,oBAAoB0B;gBACnC,IAAIE,SAASpC,qBAAqBsB,WAAW,EAAE;o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AAMI,OAAOrI,qBAAqBkI;IAClC,IAAMI,UAAUF,IAAIvF,MAAM,GAAGuF,IAAIxF,QAAQ,GAAG;IAC5C,IAAM2F,aAAaH,IAAI3F,SAAS,GAAG2F,IAAI5F,WAAW,GAAG;IACrD,IAAMiB,OAAO0E,gBAAgB,cAAcI,aAAaD;IACxD,IAAM5E,UAAUyE,gBAAgB,cAAcG,UAAUC;IACxD,IAAMC,WAAWH,KAAKxF,MAAM,GAAGwF,KAAKzF,QAAQ,GAAG;IAC/C,IAAM6F,cAAcJ,KAAK5F,SAAS,GAAG4F,KAAK7F,WAAW,GAAG;IAExD,IAAIgG,aAAa,KAAKC,gBAAgB,GAAG;QACvC,OAAO;YAAE7F,UAAUyF,KAAKzF,QAAQ;YAAEC,QAAQwF,KAAKzF,QAAQ,GAAGa,OAAO;YAAGjB,aAAa6F,KAAK7F,WAAW;YAAEC,WAAW4F,KAAK7F,WAAW,GAAGkB,UAAU;QAAE;IAC/I;IACA,IAAI8E,WAAW/E,SAAS,KAAKgF,cAAc/E,YAAY,GAAG,OAAO2E;IACjE,MAAM,IAAI1G,MACR,AAAC,eAAgC6G,OAAlBN,aAAY,QAAkBO,OAAZD,UAAS,KAA6BL,OAA1BM,aAAY,gBAAwER,OAA1DE,gBAAgB,cAAc,gBAAgB,IAAG,WAAsB1E,OAAbwE,QAAO,QAAcvE,OAARD,MAAK,KAA+ChE,OAA5CiE,SAAQ,sCAA4E2E,OAAxC5I,oBAAoB4I,KAAK7F,WAAW,GAA+EiB,OAA3E4E,KAAKzF,QAAQ,EAAC,+DAAqEc,OAARD,MAAK,KAAW,OAARC,SAAQ;AAEzU"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-sheets/src/spreadsheet/range-operations.ts"],"sourcesContent":["/**\n * Range Operations Utilities for Google Sheets\n *\n * This module provides comprehensive utilities for working with A1 notation,\n * range parsing, batch operations, and range validation in Google Sheets.\n *\n * Key features:\n * - A1 notation validation and parsing\n * - Range manipulation and calculation utilities\n * - Batch operation builders for Google Sheets API\n * - Cell count and dimension calculations\n * - Range conflict detection for batch operations\n * - Google Sheets limits validation and enforcement\n */\n\nimport { a1Col } from './column-utilities.ts';\n\n// Google Sheets constants and limits\nexport const GOOGLE_SHEETS_LIMITS = {\n MAX_ROWS: 10_000_000,\n MAX_COLUMNS: 18_278, // ZZZ in base-26\n MAX_CELLS: 10_000_000, // Approximate limit for total cells\n MAX_BATCH_REQUESTS: 1000,\n MAX_DIMENSION_BATCH_REQUESTS: 100,\n} as const;\n\n/**\n * Represents a parsed cell reference (e.g., A1, B5)\n */\nexport interface CellReference {\n column: string;\n columnIndex: number; // 1-based\n row: number; // 1-based\n}\n\n/**\n * Represents a parsed range (e.g., A1:B5, A:B, 1:2)\n */\nexport interface RangeReference {\n type: 'cell' | 'row' | 'column' | 'range';\n startCell?: CellReference;\n endCell?: CellReference;\n startRow?: number;\n endRow?: number;\n startColumn?: string;\n endColumn?: string;\n startColumnIndex?: number;\n endColumnIndex?: number;\n}\n\n/**\n * Represents dimensions of a range\n */\nexport interface RangeDimensions {\n rows: number;\n columns: number;\n cells: number;\n}\n\n/**\n * A1 Notation Validation Utilities\n */\n\n/**\n * Validates if a string is a valid A1 notation\n */\nexport function isValidA1Notation(notation: string): boolean {\n if (!notation || typeof notation !== 'string') {\n return false;\n }\n\n // Use the same regex pattern as in the schema\n const a1Pattern = /^(?:[A-Z]{1,3}(?:[1-9]\\d{0,6}|10000000)(?::[A-Z]{1,3}(?:[1-9]\\d{0,6}|10000000))?|[A-Z]{1,3}:[A-Z]{1,3}|(?:[1-9]\\d{0,6}|10000000):(?:[1-9]\\d{0,6}|10000000))$/;\n\n if (!a1Pattern.test(notation)) {\n return false;\n }\n\n // Additional validation for Google Sheets limits\n const parts = notation.split(':');\n\n for (const part of parts) {\n // Check cell reference\n const cellMatch = part.match(/^([A-Z]{1,3})([1-9]\\d{0,6}|10000000)$/);\n if (cellMatch && cellMatch[1] && cellMatch[2]) {\n const [, colStr, rowStr] = cellMatch;\n\n // Validate column\n const colNum = columnStringToIndex(colStr);\n if (colNum > GOOGLE_SHEETS_LIMITS.MAX_COLUMNS) {\n return false;\n }\n\n // Validate row\n const rowNum = parseInt(rowStr, 10);\n if (rowNum > GOOGLE_SHEETS_LIMITS.MAX_ROWS) {\n return false;\n }\n }\n\n // Check column reference\n const colMatch = part.match(/^([A-Z]{1,3})$/);\n if (colMatch && colMatch[1]) {\n const colNum = columnStringToIndex(colMatch[1]);\n if (colNum > GOOGLE_SHEETS_LIMITS.MAX_COLUMNS) {\n return false;\n }\n }\n\n // Check row reference\n const rowMatch = part.match(/^([1-9]\\d{0,6}|10000000)$/);\n if (rowMatch && rowMatch[1]) {\n const rowNum = parseInt(rowMatch[1], 10);\n if (rowNum > GOOGLE_SHEETS_LIMITS.MAX_ROWS) {\n return false;\n }\n }\n }\n\n return true;\n}\n\n/**\n * Validates A1 notation and throws detailed error if invalid\n */\nexport function validateA1Notation(notation: string): void {\n if (!isValidA1Notation(notation)) {\n throw new Error(`Invalid A1 notation: \"${notation}\". Valid formats: A1, A1:B2, A:B, 1:2`);\n }\n}\n\n/**\n * Range Parsing and Manipulation Functions\n */\n\n/**\n * Converts column string (A, B, AA, etc.) to 1-based index\n */\nexport function columnStringToIndex(colStr: string): number {\n let colNum = 0;\n for (let i = 0; i < colStr.length; i++) {\n colNum = colNum * 26 + (colStr.charCodeAt(i) - 64);\n }\n return colNum;\n}\n\n/**\n * Converts 1-based column index to column string (A, B, AA, etc.)\n */\nexport function columnIndexToString(colIndex: number): string {\n return a1Col(colIndex);\n}\n\n/**\n * Parses a cell reference (e.g., \"A1\", \"Z999\") into its components\n */\nexport function parseCellReference(cellRef: string): CellReference {\n const match = cellRef.match(/^([A-Z]{1,3})([1-9]\\d{0,6}|10000000)$/);\n if (!match || !match[1] || !match[2]) {\n throw new Error(`Invalid cell reference: ${cellRef}`);\n }\n\n const [, column, rowStr] = match;\n const row = parseInt(rowStr, 10);\n const columnIndex = columnStringToIndex(column);\n\n return {\n column,\n columnIndex,\n row,\n };\n}\n\n/**\n * Parses A1 notation into a structured range reference\n */\nexport function parseA1Notation(notation: string): RangeReference {\n validateA1Notation(notation);\n\n const parts = notation.split(':');\n\n if (parts.length === 1) {\n const part = parts[0];\n if (!part) {\n throw new Error('Invalid A1 notation: empty part after split');\n }\n\n // Single cell reference (e.g., A1)\n const cellMatch = part.match(/^([A-Z]{1,3})([1-9]\\d{0,6}|10000000)$/);\n if (cellMatch && cellMatch[1] && cellMatch[2]) {\n const startCell = parseCellReference(part);\n return {\n type: 'cell',\n startCell,\n endCell: startCell,\n };\n }\n\n // Single column reference (e.g., A)\n const colMatch = part.match(/^([A-Z]{1,3})$/);\n if (colMatch && colMatch[1]) {\n const column = colMatch[1];\n const columnIndex = columnStringToIndex(column);\n return {\n type: 'column',\n startColumn: column,\n endColumn: column,\n startColumnIndex: columnIndex,\n endColumnIndex: columnIndex,\n };\n }\n\n // Single row reference (e.g., 1)\n const rowMatch = part.match(/^([1-9]\\d{0,6}|10000000)$/);\n if (rowMatch && rowMatch[1]) {\n const row = parseInt(rowMatch[1], 10);\n return {\n type: 'row',\n startRow: row,\n endRow: row,\n };\n }\n }\n\n if (parts.length === 2 && parts[0] && parts[1]) {\n const [start, end] = parts;\n\n // Cell range (e.g., A1:B5)\n const startCellMatch = start.match(/^([A-Z]{1,3})([1-9]\\d{0,6}|10000000)$/);\n const endCellMatch = end.match(/^([A-Z]{1,3})([1-9]\\d{0,6}|10000000)$/);\n\n if (startCellMatch && endCellMatch && startCellMatch[1] && startCellMatch[2] && endCellMatch[1] && endCellMatch[2]) {\n const startCell = parseCellReference(start);\n const endCell = parseCellReference(end);\n return {\n type: 'range',\n startCell,\n endCell,\n };\n }\n\n // Column range (e.g., A:B)\n const startColMatch = start.match(/^([A-Z]{1,3})$/);\n const endColMatch = end.match(/^([A-Z]{1,3})$/);\n\n if (startColMatch && endColMatch && startColMatch[1] && endColMatch[1]) {\n const startColumn = startColMatch[1];\n const endColumn = endColMatch[1];\n const startColumnIndex = columnStringToIndex(startColumn);\n const endColumnIndex = columnStringToIndex(endColumn);\n return {\n type: 'column',\n startColumn,\n endColumn,\n startColumnIndex,\n endColumnIndex,\n };\n }\n\n // Row range (e.g., 1:5)\n const startRowMatch = start.match(/^([1-9]\\d{0,6}|10000000)$/);\n const endRowMatch = end.match(/^([1-9]\\d{0,6}|10000000)$/);\n\n if (startRowMatch && endRowMatch && startRowMatch[1] && endRowMatch[1]) {\n const startRow = parseInt(startRowMatch[1], 10);\n const endRow = parseInt(endRowMatch[1], 10);\n return {\n type: 'row',\n startRow,\n endRow,\n };\n }\n }\n\n throw new Error(`Unable to parse A1 notation: ${notation}`);\n}\n\n/**\n * Converts a range reference back to A1 notation\n */\nexport function rangeToA1Notation(range: RangeReference): string {\n switch (range.type) {\n case 'cell':\n if (!range.startCell) throw new Error('Invalid cell range: missing startCell');\n return `${range.startCell.column}${range.startCell.row}`;\n\n case 'range':\n if (!range.startCell || !range.endCell) throw new Error('Invalid range: missing start or end cell');\n return `${range.startCell.column}${range.startCell.row}:${range.endCell.column}${range.endCell.row}`;\n\n case 'column':\n if (!range.startColumn || !range.endColumn) throw new Error('Invalid column range: missing start or end column');\n if (range.startColumn === range.endColumn) {\n return range.startColumn;\n }\n return `${range.startColumn}:${range.endColumn}`;\n\n case 'row':\n if (range.startRow === undefined || range.endRow === undefined) throw new Error('Invalid row range: missing start or end row');\n if (range.startRow === range.endRow) {\n return range.startRow.toString();\n }\n return `${range.startRow}:${range.endRow}`;\n\n default:\n throw new Error(`Unknown range type: ${(range as { type: unknown }).type}`);\n }\n}\n\n/**\n * Cell Count and Dimension Calculation Utilities\n */\n\n/**\n * Calculates the dimensions of a range\n */\nexport function calculateRangeDimensions(notation: string): RangeDimensions {\n const range = parseA1Notation(notation);\n\n switch (range.type) {\n case 'cell':\n return { rows: 1, columns: 1, cells: 1 };\n\n case 'range': {\n if (!range.startCell || !range.endCell) throw new Error('Invalid range: missing cells');\n const rows = range.endCell.row - range.startCell.row + 1;\n const columns = range.endCell.columnIndex - range.startCell.columnIndex + 1;\n return { rows, columns, cells: rows * columns };\n }\n\n case 'column': {\n if (range.startColumnIndex === undefined || range.endColumnIndex === undefined) {\n throw new Error('Invalid column range: missing column indices');\n }\n const columnCount = range.endColumnIndex - range.startColumnIndex + 1;\n return {\n rows: GOOGLE_SHEETS_LIMITS.MAX_ROWS,\n columns: columnCount,\n cells: GOOGLE_SHEETS_LIMITS.MAX_ROWS * columnCount,\n };\n }\n\n case 'row': {\n if (range.startRow === undefined || range.endRow === undefined) {\n throw new Error('Invalid row range: missing row numbers');\n }\n const rowCount = range.endRow - range.startRow + 1;\n return {\n rows: rowCount,\n columns: GOOGLE_SHEETS_LIMITS.MAX_COLUMNS,\n cells: rowCount * GOOGLE_SHEETS_LIMITS.MAX_COLUMNS,\n };\n }\n\n default:\n throw new Error(`Unknown range type: ${(range as { type: string }).type}`);\n }\n}\n\n/**\n * Counts cells in a finite sheet-local range, rejecting reversed bounds.\n */\nexport function calculateFiniteRangeCellCount(notation: string): number {\n const range = parseA1Notation(notation);\n if (range.type !== 'cell' && range.type !== 'range') {\n throw new Error(`Range must have finite start and end rows and columns: ${notation}`);\n }\n const dimensions = calculateRangeDimensions(notation);\n if (dimensions.rows < 1 || dimensions.columns < 1) throw new Error(`Range end must not precede its start: ${notation}`);\n return dimensions.cells;\n}\n\n/**\n * Converts a RangeReference to Google Sheets API GridRange format\n *\n * This handles the different range types correctly:\n * - 'cell' and 'range' types: Extract indices from startCell/endCell\n * - 'row' types: Use startRow/endRow, omit column indices for full row\n * - 'column' types: Use startColumnIndex/endColumnIndex, omit row indices for full column\n *\n * Important: Google Sheets API uses 0-based indices, while A1 notation uses 1-based indices.\n * This function handles the conversion properly for each range type.\n */\nexport function rangeReferenceToGridRange(\n rangeRef: RangeReference,\n sheetId: number\n): {\n sheetId: number;\n startRowIndex?: number;\n endRowIndex?: number;\n startColumnIndex?: number;\n endColumnIndex?: number;\n} {\n if (rangeRef.type === 'cell' || rangeRef.type === 'range') {\n // For cell and range types, extract from startCell/endCell\n if (!rangeRef.startCell || !rangeRef.endCell) {\n throw new Error(`Invalid ${rangeRef.type} range: missing start or end cell`);\n }\n\n return {\n sheetId,\n // Convert 1-based row to 0-based startRowIndex\n startRowIndex: rangeRef.startCell.row - 1,\n // endRowIndex is exclusive (so row 5 becomes endRowIndex 5)\n endRowIndex: rangeRef.endCell.row,\n // Convert 1-based column index to 0-based startColumnIndex\n startColumnIndex: rangeRef.startCell.columnIndex - 1,\n // endColumnIndex is exclusive\n endColumnIndex: rangeRef.endCell.columnIndex,\n };\n }\n if (rangeRef.type === 'row') {\n // For row types, use startRow/endRow and omit column indices for full row width\n if (rangeRef.startRow === undefined || rangeRef.endRow === undefined) {\n throw new Error('Invalid row range: missing start or end row');\n }\n\n return {\n sheetId,\n // Convert 1-based row to 0-based startRowIndex\n startRowIndex: rangeRef.startRow - 1,\n // endRowIndex is exclusive\n endRowIndex: rangeRef.endRow,\n // Omit startColumnIndex and endColumnIndex to apply to all columns\n };\n }\n if (rangeRef.type === 'column') {\n // For column types, use startColumnIndex/endColumnIndex and omit row indices for full column height\n if (rangeRef.startColumnIndex === undefined || rangeRef.endColumnIndex === undefined) {\n throw new Error('Invalid column range: missing start or end column index');\n }\n\n return {\n sheetId,\n // Omit startRowIndex and endRowIndex to apply to all rows\n // Convert 1-based column index to 0-based startColumnIndex\n startColumnIndex: rangeRef.startColumnIndex - 1,\n // endColumnIndex is exclusive\n endColumnIndex: rangeRef.endColumnIndex,\n };\n }\n\n throw new Error(`Unknown range type: ${(rangeRef as { type: unknown }).type}`);\n}\n\n/**\n * A finite, sheet-local block of cells with 1-based inclusive bounds.\n */\nexport interface CellBlock {\n startRow: number;\n endRow: number;\n startColumn: number;\n endColumn: number;\n}\n\n/**\n * Parses a finite sheet-local A1 range (cell or range) into 1-based inclusive bounds.\n * Throws for invalid syntax, whole rows/columns and reversed bounds.\n */\nexport function parseFiniteCellBlock(notation: string): CellBlock {\n const range = parseA1Notation(notation);\n if (range.type !== 'cell' && range.type !== 'range') {\n throw new Error(`Range must have finite start and end rows and columns: ${notation}`);\n }\n calculateFiniteRangeCellCount(notation);\n if (!range.startCell || !range.endCell) throw new Error(`Invalid range: ${notation}`);\n return { startRow: range.startCell.row, endRow: range.endCell.row, startColumn: range.startCell.columnIndex, endColumn: range.endCell.columnIndex };\n}\n\n/**\n * Formats a block as A1 notation (a single cell when it spans one cell).\n */\nexport function cellBlockToA1(block: CellBlock): string {\n const start = `${columnIndexToString(block.startColumn)}${block.startRow}`;\n if (block.startRow === block.endRow && block.startColumn === block.endColumn) return start;\n return `${start}:${columnIndexToString(block.endColumn)}${block.endRow}`;\n}\n\n/**\n * Footprint of a copy-paste: the cells written in the destination.\n *\n * - destination is one cell: the (oriented) source size anchored at that cell\n * - destination is a range whose height and width are whole multiples of the oriented source: the destination itself (the source is tiled)\n * - anything else throws\n */\nexport function calculatePasteRange(source: string, destination: string, orientation: 'NORMAL' | 'TRANSPOSE'): CellBlock {\n const src = parseFiniteCellBlock(source);\n const dest = parseFiniteCellBlock(destination);\n const srcRows = src.endRow - src.startRow + 1;\n const srcColumns = src.endColumn - src.startColumn + 1;\n const rows = orientation === 'TRANSPOSE' ? srcColumns : srcRows;\n const columns = orientation === 'TRANSPOSE' ? srcRows : srcColumns;\n const destRows = dest.endRow - dest.startRow + 1;\n const destColumns = dest.endColumn - dest.startColumn + 1;\n\n if (destRows === 1 && destColumns === 1) {\n return { startRow: dest.startRow, endRow: dest.startRow + rows - 1, startColumn: dest.startColumn, endColumn: dest.startColumn + columns - 1 };\n }\n if (destRows % rows === 0 && destColumns % columns === 0) return dest;\n throw new Error(\n `Destination ${destination} is ${destRows}x${destColumns} cells; the ${orientation === 'TRANSPOSE' ? 'transposed ' : ''}source ${source} is ${rows}x${columns}. Use a single anchor cell (e.g., ${columnIndexToString(dest.startColumn)}${dest.startRow}) or a range whose height and width are whole multiples of ${rows}x${columns}.`\n );\n}\n"],"names":["GOOGLE_SHEETS_LIMITS","calculateFiniteRangeCellCount","calculatePasteRange","calculateRangeDimensions","cellBlockToA1","columnIndexToString","columnStringToIndex","isValidA1Notation","parseA1Notation","parseCellReference","parseFiniteCellBlock","rangeReferenceToGridRange","rangeToA1Notation","validateA1Notation","MAX_ROWS","MAX_COLUMNS","MAX_CELLS","MAX_BATCH_REQUESTS","MAX_DIMENSION_BATCH_REQUESTS","notation","a1Pattern","test","parts","split","part","cellMatch","match","colStr","rowStr","colNum","rowNum","parseInt","colMatch","rowMatch","Error","i","length","charCodeAt","colIndex","a1Col","cellRef","column","row","columnIndex","startCell","type","endCell","startColumn","endColumn","startColumnIndex","endColumnIndex","startRow","endRow","start","end","startCellMatch","endCellMatch","startColMatch","endColMatch","startRowMatch","endRowMatch","range","undefined","toString","rows","columns","cells","columnCount","rowCount","dimensions","rangeRef","sheetId","startRowIndex","endRowIndex","block","source","destination","orientation","src","dest","srcRows","srcColumns","destRows","destColumns"],"mappings":"AAAA;;;;;;;;;;;;;CAaC;;;;;;;;;;;QAKYA;eAAAA;;QAwVGC;eAAAA;;QA2HAC;eAAAA;;QAzKAC;eAAAA;;QA4JAC;eAAAA;;QAnUAC;eAAAA;;QAXAC;eAAAA;;QAxEAC;eAAAA;;QA8GAC;eAAAA;;QApBAC;eAAAA;;QA+SAC;eAAAA;;QA5EAC;eAAAA;;QAvGAC;eAAAA;;QA3JAC;eAAAA;;;iCA9GM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGf,IAAMb,uBAAuB;IAClCc,UAAU;IACVC,aAAa;IACbC,WAAW;IACXC,oBAAoB;IACpBC,8BAA8B;AAChC;AA0CO,SAASX,kBAAkBY,QAAgB;IAChD,IAAI,CAACA,YAAY,OAAOA,aAAa,UAAU;QAC7C,OAAO;IACT;IAEA,8CAA8C;IAC9C,IAAMC,YAAY;IAElB,IAAI,CAACA,UAAUC,IAAI,CAACF,WAAW;QAC7B,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lBN,aAAY,QAAkBO,OAAZD,UAAS,KAA6BL,OAA1BM,aAAY,gBAAwER,OAA1DE,gBAAgB,cAAc,gBAAgB,IAAG,WAAsBb,OAAbW,QAAO,QAAcV,OAARD,MAAK,KAA+C3D,OAA5C4D,SAAQ,sCAA4Ec,OAAxC1E,oBAAoB0E,KAAKhC,WAAW,GAA+EiB,OAA3Ee,KAAK5B,QAAQ,EAAC,+DAAqEc,OAARD,MAAK,KAAW,OAARC,SAAQ;AAEzU"}
|
|
@@ -6,31 +6,18 @@ import type { Logger } from '../types.js';
|
|
|
6
6
|
* and a failed read throws `Failed to read key columns from <range>: <message>` with the original as cause. Errors thrown by onRow are not wrapped.
|
|
7
7
|
*/
|
|
8
8
|
export declare function scanKeyColumnRows(sheets: sheets_v4.Sheets, spreadsheetId: string, sheetTitle: string, startCol: string, endCol: string, onRow: (cells: string[], rowNumber: number) => void): Promise<void>;
|
|
9
|
-
export declare function ensureSheetIfNeeded(sheets: sheets_v4.Sheets, id: string, sheetTitle: string, ensureSheet: boolean, headers: string[] | undefined, logger: Logger): Promise<{
|
|
10
|
-
sheetCreated: boolean;
|
|
11
|
-
sheetGUID?: string;
|
|
12
|
-
headersEnsured?: boolean;
|
|
13
|
-
}>;
|
|
14
9
|
export declare function findSheetByRef(client: sheets_v4.Sheets, spreadsheetId: string, sheetRef: string, logger: Logger): Promise<sheets_v4.Schema$Sheet | null>;
|
|
15
|
-
export declare function ensureTabAndHeaders(sheets: sheets_v4.Sheets,
|
|
10
|
+
export declare function ensureTabAndHeaders(sheets: sheets_v4.Sheets, { spreadsheetId, sheetTitle, requiredHeader, keyColumns, }: {
|
|
16
11
|
spreadsheetId: string;
|
|
17
12
|
sheetTitle: string;
|
|
18
13
|
requiredHeader?: string[] | null;
|
|
19
14
|
keyColumns?: string[];
|
|
20
|
-
logger: Logger;
|
|
21
15
|
}): Promise<{
|
|
22
16
|
header: string[];
|
|
23
17
|
keySet: Set<string>;
|
|
24
|
-
keyColumnsIdx?:
|
|
25
|
-
}
|
|
26
|
-
export declare function ensureTabAndHeaders(sheets: sheets_v4.Sheets, params: {
|
|
27
|
-
spreadsheetId: string;
|
|
28
|
-
sheetRef: string;
|
|
29
|
-
requiredHeader?: string[] | null;
|
|
30
|
-
keyColumns?: string[];
|
|
31
|
-
logger: Logger;
|
|
32
|
-
}): Promise<{
|
|
18
|
+
keyColumnsIdx?: undefined;
|
|
19
|
+
} | {
|
|
33
20
|
header: string[];
|
|
34
21
|
keySet: Set<string>;
|
|
35
|
-
keyColumnsIdx
|
|
22
|
+
keyColumnsIdx: number[];
|
|
36
23
|
}>;
|
|
@@ -6,31 +6,18 @@ import type { Logger } from '../types.js';
|
|
|
6
6
|
* and a failed read throws `Failed to read key columns from <range>: <message>` with the original as cause. Errors thrown by onRow are not wrapped.
|
|
7
7
|
*/
|
|
8
8
|
export declare function scanKeyColumnRows(sheets: sheets_v4.Sheets, spreadsheetId: string, sheetTitle: string, startCol: string, endCol: string, onRow: (cells: string[], rowNumber: number) => void): Promise<void>;
|
|
9
|
-
export declare function ensureSheetIfNeeded(sheets: sheets_v4.Sheets, id: string, sheetTitle: string, ensureSheet: boolean, headers: string[] | undefined, logger: Logger): Promise<{
|
|
10
|
-
sheetCreated: boolean;
|
|
11
|
-
sheetGUID?: string;
|
|
12
|
-
headersEnsured?: boolean;
|
|
13
|
-
}>;
|
|
14
9
|
export declare function findSheetByRef(client: sheets_v4.Sheets, spreadsheetId: string, sheetRef: string, logger: Logger): Promise<sheets_v4.Schema$Sheet | null>;
|
|
15
|
-
export declare function ensureTabAndHeaders(sheets: sheets_v4.Sheets,
|
|
10
|
+
export declare function ensureTabAndHeaders(sheets: sheets_v4.Sheets, { spreadsheetId, sheetTitle, requiredHeader, keyColumns, }: {
|
|
16
11
|
spreadsheetId: string;
|
|
17
12
|
sheetTitle: string;
|
|
18
13
|
requiredHeader?: string[] | null;
|
|
19
14
|
keyColumns?: string[];
|
|
20
|
-
logger: Logger;
|
|
21
15
|
}): Promise<{
|
|
22
16
|
header: string[];
|
|
23
17
|
keySet: Set<string>;
|
|
24
|
-
keyColumnsIdx?:
|
|
25
|
-
}
|
|
26
|
-
export declare function ensureTabAndHeaders(sheets: sheets_v4.Sheets, params: {
|
|
27
|
-
spreadsheetId: string;
|
|
28
|
-
sheetRef: string;
|
|
29
|
-
requiredHeader?: string[] | null;
|
|
30
|
-
keyColumns?: string[];
|
|
31
|
-
logger: Logger;
|
|
32
|
-
}): Promise<{
|
|
18
|
+
keyColumnsIdx?: undefined;
|
|
19
|
+
} | {
|
|
33
20
|
header: string[];
|
|
34
21
|
keySet: Set<string>;
|
|
35
|
-
keyColumnsIdx
|
|
22
|
+
keyColumnsIdx: number[];
|
|
36
23
|
}>;
|