@mshindi-labs/google 1.2.1 → 1.3.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 +4 -2
- package/dist/calendar.cjs +114 -162
- package/dist/calendar.cjs.map +1 -1
- package/dist/calendar.d.cts +1 -1
- package/dist/calendar.d.ts +1 -1
- package/dist/calendar.js +45 -93
- package/dist/calendar.js.map +1 -1
- package/dist/chunk-2MJE3WQ5.js +63 -0
- package/dist/chunk-2MJE3WQ5.js.map +1 -0
- package/dist/chunk-4UEM6VO4.cjs +119 -0
- package/dist/chunk-4UEM6VO4.cjs.map +1 -0
- package/dist/{chunk-FCHXM22B.js → chunk-6VGR73PY.js} +45 -2
- package/dist/{chunk-FCHXM22B.js.map → chunk-6VGR73PY.js.map} +1 -1
- package/dist/{chunk-6RDWEYXZ.js → chunk-7YVRJ3GY.js} +5 -4
- package/dist/chunk-7YVRJ3GY.js.map +1 -0
- package/dist/chunk-7ZLAL7UY.cjs +63 -0
- package/dist/chunk-7ZLAL7UY.cjs.map +1 -0
- package/dist/chunk-BYHOVCN3.cjs +20 -0
- package/dist/chunk-BYHOVCN3.cjs.map +1 -0
- package/dist/chunk-FPEP5FL5.js +87 -0
- package/dist/chunk-FPEP5FL5.js.map +1 -0
- package/dist/chunk-JA2JLBNN.js +119 -0
- package/dist/chunk-JA2JLBNN.js.map +1 -0
- package/dist/{chunk-DPAPYMB3.cjs → chunk-KFQ4O6MT.cjs} +57 -56
- package/dist/chunk-KFQ4O6MT.cjs.map +1 -0
- package/dist/chunk-LWCB3V7V.js +20 -0
- package/dist/chunk-LWCB3V7V.js.map +1 -0
- package/dist/{chunk-6PMJ6VB6.cjs → chunk-RWRVNSQG.cjs} +6 -6
- package/dist/{chunk-6PMJ6VB6.cjs.map → chunk-RWRVNSQG.cjs.map} +1 -1
- package/dist/{chunk-SXD5K23S.js → chunk-UR3KSPDZ.js} +2 -2
- package/dist/{chunk-JZVDD4DL.cjs → chunk-UUXXCUIB.cjs} +45 -2
- package/dist/chunk-UUXXCUIB.cjs.map +1 -0
- package/dist/{chunk-JDA3ZRUY.cjs → chunk-V5Q6XSYZ.cjs} +3 -3
- package/dist/{chunk-JDA3ZRUY.cjs.map → chunk-V5Q6XSYZ.cjs.map} +1 -1
- package/dist/{chunk-S357VL5V.cjs → chunk-X7QL7AQ6.cjs} +48 -17
- package/dist/chunk-X7QL7AQ6.cjs.map +1 -0
- package/dist/{chunk-4V5ZJNPI.js → chunk-ZPDFK5VR.js} +2 -2
- package/dist/core.cjs +28 -18
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +19 -2
- package/dist/core.d.ts +19 -2
- package/dist/core.js +14 -4
- package/dist/core.js.map +1 -1
- package/dist/{create-google-Bo8_Nc1C.d.cts → create-google-B0fX1ixG.d.cts} +1 -0
- package/dist/{create-google-snvkHaEk.d.ts → create-google-CjsKhktN.d.ts} +1 -0
- package/dist/gmail.cjs +43 -41
- package/dist/gmail.cjs.map +1 -1
- package/dist/gmail.d.cts +1 -1
- package/dist/gmail.d.ts +1 -1
- package/dist/gmail.js +9 -7
- package/dist/gmail.js.map +1 -1
- package/dist/postgres.cjs +8 -8
- package/dist/postgres.js +1 -1
- package/dist/sheets.cjs +1317 -0
- package/dist/sheets.cjs.map +1 -0
- package/dist/sheets.d.cts +292 -0
- package/dist/sheets.d.ts +292 -0
- package/dist/sheets.js +1317 -0
- package/dist/sheets.js.map +1 -0
- package/dist/testing.cjs +905 -38
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +133 -1
- package/dist/testing.d.ts +133 -1
- package/dist/testing.js +897 -30
- package/dist/testing.js.map +1 -1
- package/dist/transport-uuotQ13Y.d.cts +137 -0
- package/dist/transport-uuotQ13Y.d.ts +137 -0
- package/package.json +17 -1
- package/dist/chunk-6RDWEYXZ.js.map +0 -1
- package/dist/chunk-AMBBE4TW.js +0 -56
- package/dist/chunk-AMBBE4TW.js.map +0 -1
- package/dist/chunk-DPAPYMB3.cjs.map +0 -1
- package/dist/chunk-JZVDD4DL.cjs.map +0 -1
- package/dist/chunk-S357VL5V.cjs.map +0 -1
- /package/dist/{chunk-SXD5K23S.js.map → chunk-UR3KSPDZ.js.map} +0 -0
- /package/dist/{chunk-4V5ZJNPI.js.map → chunk-ZPDFK5VR.js.map} +0 -0
package/dist/sheets.cjs
ADDED
|
@@ -0,0 +1,1317 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunk7ZLAL7UYcjs = require('./chunk-7ZLAL7UY.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var _chunkX7QL7AQ6cjs = require('./chunk-X7QL7AQ6.cjs');
|
|
14
|
+
require('./chunk-KFQ4O6MT.cjs');
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
var _chunk4UEM6VO4cjs = require('./chunk-4UEM6VO4.cjs');
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
var _chunkV5Q6XSYZcjs = require('./chunk-V5Q6XSYZ.cjs');
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
var _chunkUUXXCUIBcjs = require('./chunk-UUXXCUIB.cjs');
|
|
31
|
+
|
|
32
|
+
// src/sheets/cells.ts
|
|
33
|
+
function isFormula(cell) {
|
|
34
|
+
return typeof cell === "object" && cell !== null && !Array.isArray(cell) && Object.keys(cell).length === 1 && typeof cell.formula === "string" && cell.formula.startsWith("=") && cell.formula.slice(1).trim() !== "";
|
|
35
|
+
}
|
|
36
|
+
function encodeRows(rows, mode, field = "values") {
|
|
37
|
+
if (mode !== "raw" && mode !== "user_entered") {
|
|
38
|
+
throw new (0, _chunkUUXXCUIBcjs.InvalidSheetsInputError)(
|
|
39
|
+
"input",
|
|
40
|
+
'Invalid input mode: expected "raw" or "user_entered"'
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
const invalid = (detail) => new (0, _chunkUUXXCUIBcjs.InvalidSheetsInputError)(field, `Invalid ${field}: ${detail}`);
|
|
44
|
+
if (!Array.isArray(rows) || rows.length === 0) {
|
|
45
|
+
throw invalid("expected a non-empty array of rows");
|
|
46
|
+
}
|
|
47
|
+
let hasFormula = false;
|
|
48
|
+
for (const row of rows) {
|
|
49
|
+
if (!Array.isArray(row) || row.length === 0) {
|
|
50
|
+
throw invalid("every row must be a non-empty array");
|
|
51
|
+
}
|
|
52
|
+
for (const cell of row) {
|
|
53
|
+
if (isFormula(cell)) hasFormula = true;
|
|
54
|
+
else if (cell !== null && typeof cell !== "string" && typeof cell !== "boolean" && !(typeof cell === "number" && Number.isFinite(cell))) {
|
|
55
|
+
throw invalid(
|
|
56
|
+
"cells must be string, finite number, boolean, null, or { formula: '=...' }"
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const userEntered = mode === "user_entered" || hasFormula;
|
|
62
|
+
const prefix = mode === "raw" && hasFormula;
|
|
63
|
+
const values = rows.map(
|
|
64
|
+
(row) => row.map((cell) => {
|
|
65
|
+
if (cell === null) return "";
|
|
66
|
+
if (typeof cell === "object") return cell.formula;
|
|
67
|
+
if (prefix && typeof cell === "string" && cell !== "") return `'${cell}`;
|
|
68
|
+
return cell;
|
|
69
|
+
})
|
|
70
|
+
);
|
|
71
|
+
return {
|
|
72
|
+
valueInputOption: userEntered ? "USER_ENTERED" : "RAW",
|
|
73
|
+
values
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/sheets/transport.ts
|
|
78
|
+
var _googleauthlibrary = require('google-auth-library');
|
|
79
|
+
var INFO_FIELDS = "spreadsheetId,properties(title,locale,timeZone),sheets(properties(sheetId,title,index,hidden,gridProperties(rowCount,columnCount,frozenRowCount,frozenColumnCount)),protectedRanges(protectedRangeId,range,description,warningOnly)),namedRanges(namedRangeId,name,range)";
|
|
80
|
+
var TAB_FIELDS = "sheets.properties(sheetId,title)";
|
|
81
|
+
var SheetsClientInitError = class extends Error {
|
|
82
|
+
constructor(cause) {
|
|
83
|
+
super("Could not create the Google Sheets client", { cause });
|
|
84
|
+
this.name = "SheetsClientInitError";
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
function createSheetsApiTransport() {
|
|
88
|
+
const client = async (accessToken) => {
|
|
89
|
+
try {
|
|
90
|
+
const mod = await _chunkV5Q6XSYZcjs.loadPeer.call(void 0, "@googleapis/sheets");
|
|
91
|
+
const { sheets } = mod.sheets ? mod : mod.default;
|
|
92
|
+
const auth = new (0, _googleauthlibrary.OAuth2Client)();
|
|
93
|
+
auth.setCredentials({ access_token: accessToken });
|
|
94
|
+
return sheets({ version: "v4", auth });
|
|
95
|
+
} catch (err) {
|
|
96
|
+
if (err instanceof _chunkUUXXCUIBcjs.GoogleLibError) throw err;
|
|
97
|
+
throw new SheetsClientInitError(err);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
return {
|
|
101
|
+
async getSpreadsheet({ accessToken, spreadsheetId, fields }) {
|
|
102
|
+
const api = await client(accessToken);
|
|
103
|
+
const { data } = await api.spreadsheets.get({
|
|
104
|
+
spreadsheetId,
|
|
105
|
+
fields,
|
|
106
|
+
includeGridData: false
|
|
107
|
+
});
|
|
108
|
+
return data;
|
|
109
|
+
},
|
|
110
|
+
async valuesGet({ accessToken, spreadsheetId, range, valueRenderOption }) {
|
|
111
|
+
const api = await client(accessToken);
|
|
112
|
+
const { data } = await api.spreadsheets.values.get({
|
|
113
|
+
spreadsheetId,
|
|
114
|
+
range,
|
|
115
|
+
valueRenderOption
|
|
116
|
+
});
|
|
117
|
+
return data;
|
|
118
|
+
},
|
|
119
|
+
async valuesBatchGet({
|
|
120
|
+
accessToken,
|
|
121
|
+
spreadsheetId,
|
|
122
|
+
ranges,
|
|
123
|
+
valueRenderOption
|
|
124
|
+
}) {
|
|
125
|
+
const api = await client(accessToken);
|
|
126
|
+
const { data } = await api.spreadsheets.values.batchGet({
|
|
127
|
+
spreadsheetId,
|
|
128
|
+
ranges,
|
|
129
|
+
valueRenderOption
|
|
130
|
+
});
|
|
131
|
+
return data;
|
|
132
|
+
},
|
|
133
|
+
async valuesUpdate({
|
|
134
|
+
accessToken,
|
|
135
|
+
spreadsheetId,
|
|
136
|
+
range,
|
|
137
|
+
values,
|
|
138
|
+
valueInputOption
|
|
139
|
+
}) {
|
|
140
|
+
const api = await client(accessToken);
|
|
141
|
+
const { data } = await api.spreadsheets.values.update({
|
|
142
|
+
spreadsheetId,
|
|
143
|
+
range,
|
|
144
|
+
valueInputOption,
|
|
145
|
+
requestBody: { values }
|
|
146
|
+
});
|
|
147
|
+
return data;
|
|
148
|
+
},
|
|
149
|
+
async valuesBatchUpdate({
|
|
150
|
+
accessToken,
|
|
151
|
+
spreadsheetId,
|
|
152
|
+
data: rows,
|
|
153
|
+
valueInputOption
|
|
154
|
+
}) {
|
|
155
|
+
const api = await client(accessToken);
|
|
156
|
+
const { data } = await api.spreadsheets.values.batchUpdate({
|
|
157
|
+
spreadsheetId,
|
|
158
|
+
requestBody: { valueInputOption, data: rows }
|
|
159
|
+
});
|
|
160
|
+
return data;
|
|
161
|
+
},
|
|
162
|
+
async valuesAppend({
|
|
163
|
+
accessToken,
|
|
164
|
+
spreadsheetId,
|
|
165
|
+
range,
|
|
166
|
+
values,
|
|
167
|
+
valueInputOption,
|
|
168
|
+
insertDataOption
|
|
169
|
+
}) {
|
|
170
|
+
const api = await client(accessToken);
|
|
171
|
+
const { data } = await api.spreadsheets.values.append({
|
|
172
|
+
spreadsheetId,
|
|
173
|
+
range,
|
|
174
|
+
valueInputOption,
|
|
175
|
+
insertDataOption,
|
|
176
|
+
requestBody: { values }
|
|
177
|
+
});
|
|
178
|
+
return data;
|
|
179
|
+
},
|
|
180
|
+
async valuesBatchClear({ accessToken, spreadsheetId, ranges }) {
|
|
181
|
+
const api = await client(accessToken);
|
|
182
|
+
await api.spreadsheets.values.batchClear({
|
|
183
|
+
spreadsheetId,
|
|
184
|
+
requestBody: { ranges }
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
async batchUpdate({ accessToken, spreadsheetId, requests }) {
|
|
188
|
+
const api = await client(accessToken);
|
|
189
|
+
const { data } = await api.spreadsheets.batchUpdate({
|
|
190
|
+
spreadsheetId,
|
|
191
|
+
requestBody: { requests, includeSpreadsheetInResponse: false }
|
|
192
|
+
});
|
|
193
|
+
return data;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// src/sheets/retry.ts
|
|
199
|
+
var SheetsUnauthorizedSignal = class extends Error {
|
|
200
|
+
constructor() {
|
|
201
|
+
super("Google rejected the access token (401)");
|
|
202
|
+
this.name = "SheetsUnauthorizedSignal";
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
var PRE_SEND_CODES = /* @__PURE__ */ new Set(["ENOTFOUND", "EAI_AGAIN", "ECONNREFUSED"]);
|
|
206
|
+
var isPreSend = (code) => PRE_SEND_CODES.has(code) || code.startsWith("ERR_TLS_") || code.startsWith("CERT_");
|
|
207
|
+
var AMBIGUOUS_CODES = /* @__PURE__ */ new Set(["ECONNRESET", "ETIMEDOUT", "ESOCKETTIMEDOUT"]);
|
|
208
|
+
var PARSE_RANGE = /Unable to parse range:?\s*(.*)$/i;
|
|
209
|
+
var NO_GRID = /\bNo grid with id:\s*(\d+)/i;
|
|
210
|
+
var API_DISABLED_REASONS = /* @__PURE__ */ new Set([
|
|
211
|
+
"accessNotConfigured",
|
|
212
|
+
"SERVICE_DISABLED"
|
|
213
|
+
]);
|
|
214
|
+
function apiDisabledReason(e) {
|
|
215
|
+
const error = _optionalChain([e, 'access', _2 => _2.response, 'optionalAccess', _3 => _3.data, 'optionalAccess', _4 => _4.error]);
|
|
216
|
+
const entries = [e.errors, _optionalChain([error, 'optionalAccess', _5 => _5.errors]), _optionalChain([error, 'optionalAccess', _6 => _6.details])].flatMap(
|
|
217
|
+
(list) => Array.isArray(list) ? list : []
|
|
218
|
+
);
|
|
219
|
+
for (const entry of entries) {
|
|
220
|
+
const r = _optionalChain([entry, 'optionalAccess', _7 => _7.reason]);
|
|
221
|
+
if (typeof r === "string" && API_DISABLED_REASONS.has(r)) return r;
|
|
222
|
+
}
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
var QUOTED_TAB = /^'((?:[^']|'')*)'(?:!|$)/;
|
|
226
|
+
function tabFromParseError(e) {
|
|
227
|
+
const sources = [_optionalChain([e, 'access', _8 => _8.response, 'optionalAccess', _9 => _9.data, 'optionalAccess', _10 => _10.error, 'optionalAccess', _11 => _11.message]), e.message];
|
|
228
|
+
for (const s of sources) {
|
|
229
|
+
if (typeof s !== "string") continue;
|
|
230
|
+
const range = _optionalChain([PARSE_RANGE, 'access', _12 => _12.exec, 'call', _13 => _13(s), 'optionalAccess', _14 => _14[1], 'optionalAccess', _15 => _15.trim, 'call', _16 => _16()]);
|
|
231
|
+
if (!range) continue;
|
|
232
|
+
const quoted = _optionalChain([QUOTED_TAB, 'access', _17 => _17.exec, 'call', _18 => _18(range), 'optionalAccess', _19 => _19[1]]);
|
|
233
|
+
if (quoted !== void 0) return _chunkUUXXCUIBcjs.redact.call(void 0, quoted.replace(/''/g, "'"));
|
|
234
|
+
const bang = range.lastIndexOf("!");
|
|
235
|
+
return _chunkUUXXCUIBcjs.redact.call(void 0, bang === -1 ? range : range.slice(0, bang));
|
|
236
|
+
}
|
|
237
|
+
return "";
|
|
238
|
+
}
|
|
239
|
+
function classify(err, idempotent, ids) {
|
|
240
|
+
if (err instanceof _chunkUUXXCUIBcjs.GoogleLibError) return { kind: "fail", error: err };
|
|
241
|
+
if (err instanceof SheetsClientInitError) {
|
|
242
|
+
return {
|
|
243
|
+
kind: "fail",
|
|
244
|
+
error: new (0, _chunkUUXXCUIBcjs.GoogleApiError)(0, "client_init_failed", {
|
|
245
|
+
...ids,
|
|
246
|
+
cause: err.cause
|
|
247
|
+
})
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
const e = _chunkX7QL7AQ6cjs.asErr.call(void 0, err);
|
|
251
|
+
const status = _chunkX7QL7AQ6cjs.readStatus.call(void 0, e);
|
|
252
|
+
const reason = _chunkX7QL7AQ6cjs.readReason.call(void 0, e);
|
|
253
|
+
const code = _chunkX7QL7AQ6cjs.readNetCode.call(void 0, e);
|
|
254
|
+
const opts = { ...ids, cause: err };
|
|
255
|
+
const unknown = () => ({
|
|
256
|
+
kind: "fail",
|
|
257
|
+
error: new (0, _chunkUUXXCUIBcjs.SheetsWriteOutcomeUnknownError)(void 0, opts)
|
|
258
|
+
});
|
|
259
|
+
if (status === 429 || status === 403 && reason !== null && _chunkX7QL7AQ6cjs.RATE_REASONS.has(reason)) {
|
|
260
|
+
return { kind: "retry", delayMs: _chunkX7QL7AQ6cjs.readRetryAfterMs.call(void 0, e) };
|
|
261
|
+
}
|
|
262
|
+
if (status === 401) return { kind: "unauthorized" };
|
|
263
|
+
if (status === 404) {
|
|
264
|
+
return {
|
|
265
|
+
kind: "fail",
|
|
266
|
+
error: new (0, _chunkUUXXCUIBcjs.SpreadsheetNotFoundError)(void 0, opts)
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
const disabled = status === 403 ? apiDisabledReason(e) : null;
|
|
270
|
+
if (disabled !== null) {
|
|
271
|
+
return { kind: "fail", error: new (0, _chunkUUXXCUIBcjs.GoogleApiError)(403, disabled, opts) };
|
|
272
|
+
}
|
|
273
|
+
if (status === 403) {
|
|
274
|
+
return {
|
|
275
|
+
kind: "fail",
|
|
276
|
+
error: new (0, _chunkUUXXCUIBcjs.SpreadsheetAccessDeniedError)(void 0, opts)
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
if (status === 400 && PARSE_RANGE.test(_chunkX7QL7AQ6cjs.readMessages.call(void 0, e))) {
|
|
280
|
+
return {
|
|
281
|
+
kind: "fail",
|
|
282
|
+
error: new (0, _chunkUUXXCUIBcjs.SheetTabNotFoundError)(tabFromParseError(e), void 0, opts)
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
const noGrid = status === 400 ? NO_GRID.exec(_chunkX7QL7AQ6cjs.readMessages.call(void 0, e)) : null;
|
|
286
|
+
if (noGrid) {
|
|
287
|
+
const id = noGrid[1];
|
|
288
|
+
return {
|
|
289
|
+
kind: "fail",
|
|
290
|
+
error: new (0, _chunkUUXXCUIBcjs.SheetTabNotFoundError)(
|
|
291
|
+
id,
|
|
292
|
+
`Sheet tab not found: sheetId ${id}`,
|
|
293
|
+
opts
|
|
294
|
+
)
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
if (status !== null && status >= 500) {
|
|
298
|
+
return idempotent ? { kind: "retry", delayMs: null } : unknown();
|
|
299
|
+
}
|
|
300
|
+
if (status !== null) {
|
|
301
|
+
return { kind: "fail", error: new (0, _chunkUUXXCUIBcjs.GoogleApiError)(status, reason, opts) };
|
|
302
|
+
}
|
|
303
|
+
if (code !== null && isPreSend(code)) {
|
|
304
|
+
return { kind: "retry", delayMs: null };
|
|
305
|
+
}
|
|
306
|
+
if (code !== null && (AMBIGUOUS_CODES.has(code) || code === "ABORT_ERR") || e.name === "AbortError" || /socket hang up/i.test(_chunkX7QL7AQ6cjs.readMessages.call(void 0, e))) {
|
|
307
|
+
return idempotent ? { kind: "retry", delayMs: null } : unknown();
|
|
308
|
+
}
|
|
309
|
+
if (!idempotent) return unknown();
|
|
310
|
+
return { kind: "fail", error: new (0, _chunkUUXXCUIBcjs.GoogleApiError)(0, code, opts) };
|
|
311
|
+
}
|
|
312
|
+
function withSheetsRetry(fn, opts) {
|
|
313
|
+
const { idempotent, ids = {}, ...retry } = opts;
|
|
314
|
+
return _chunkX7QL7AQ6cjs.runWithRetry.call(void 0, fn, {
|
|
315
|
+
...retry,
|
|
316
|
+
ids,
|
|
317
|
+
classify: (err) => {
|
|
318
|
+
const c = classify(err, idempotent, ids);
|
|
319
|
+
if (c.kind === "retry") return c;
|
|
320
|
+
if (c.kind === "unauthorized") {
|
|
321
|
+
return { kind: "throw", error: new SheetsUnauthorizedSignal() };
|
|
322
|
+
}
|
|
323
|
+
return { kind: "throw", error: c.error };
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// src/sheets/types.ts
|
|
329
|
+
var SHEETS_REQUEST = /* @__PURE__ */ Symbol.for(
|
|
330
|
+
"mshindi-google.sheets-request"
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
// src/sheets/view.ts
|
|
334
|
+
var isEmpty = (v) => v === void 0 || v === null || v === "";
|
|
335
|
+
var headerText = (v) => isEmpty(v) ? "" : String(v).trim();
|
|
336
|
+
function headerKeys(header, width, first) {
|
|
337
|
+
const used = /* @__PURE__ */ new Set();
|
|
338
|
+
const keys = [];
|
|
339
|
+
for (let j = 0; j < width; j++) {
|
|
340
|
+
const text = headerText(header[j]);
|
|
341
|
+
const base = text === "" ? `column_${_chunk4UEM6VO4cjs.a1.indexToColumn(first + j)}` : text;
|
|
342
|
+
let key = base;
|
|
343
|
+
for (let n = 2; used.has(key); n++) key = `${base}_${String(n)}`;
|
|
344
|
+
used.add(key);
|
|
345
|
+
keys.push(key);
|
|
346
|
+
}
|
|
347
|
+
return keys;
|
|
348
|
+
}
|
|
349
|
+
function pad(row, width) {
|
|
350
|
+
return Array.from({ length: width }, (_, j) => _nullishCoalesce(_optionalChain([row, 'optionalAccess', _20 => _20[j]]), () => ( null)));
|
|
351
|
+
}
|
|
352
|
+
var widest = (rows) => rows.reduce((w, r) => Math.max(w, r.length), 0);
|
|
353
|
+
function gridToA1(g, tab) {
|
|
354
|
+
const r0 = _nullishCoalesce(_optionalChain([g, 'optionalAccess', _21 => _21.startRowIndex]), () => ( null));
|
|
355
|
+
const r1 = _nullishCoalesce(_optionalChain([g, 'optionalAccess', _22 => _22.endRowIndex]), () => ( null));
|
|
356
|
+
const c0 = _nullishCoalesce(_optionalChain([g, 'optionalAccess', _23 => _23.startColumnIndex]), () => ( null));
|
|
357
|
+
const c1 = _nullishCoalesce(_optionalChain([g, 'optionalAccess', _24 => _24.endColumnIndex]), () => ( null));
|
|
358
|
+
const rowsOpen = r0 === null && r1 === null;
|
|
359
|
+
const colsOpen = c0 === null && c1 === null;
|
|
360
|
+
if (rowsOpen && colsOpen) return _chunk4UEM6VO4cjs.a1.range(tab.title);
|
|
361
|
+
const col = (i) => _chunk4UEM6VO4cjs.a1.indexToColumn(i);
|
|
362
|
+
const sc = (_nullishCoalesce(c0, () => ( 0))) + 1;
|
|
363
|
+
const ec = _nullishCoalesce(c1, () => ( tab.columnCount));
|
|
364
|
+
const sr = (_nullishCoalesce(r0, () => ( 0))) + 1;
|
|
365
|
+
const er = _nullishCoalesce(r1, () => ( tab.rowCount));
|
|
366
|
+
if (rowsOpen) return _chunk4UEM6VO4cjs.a1.range(tab.title, `${col(sc)}:${col(ec)}`);
|
|
367
|
+
if (colsOpen) return _chunk4UEM6VO4cjs.a1.range(tab.title, `${String(sr)}:${String(er)}`);
|
|
368
|
+
return _chunk4UEM6VO4cjs.a1.range(tab.title, `${col(sc)}${String(sr)}:${col(ec)}${String(er)}`);
|
|
369
|
+
}
|
|
370
|
+
function toInfo(s, spreadsheetId) {
|
|
371
|
+
const sheets = _nullishCoalesce(s.sheets, () => ( []));
|
|
372
|
+
const tabs = sheets.map((sh) => {
|
|
373
|
+
const p = _nullishCoalesce(sh.properties, () => ( {}));
|
|
374
|
+
const g = _nullishCoalesce(p.gridProperties, () => ( {}));
|
|
375
|
+
return {
|
|
376
|
+
sheetId: _nullishCoalesce(p.sheetId, () => ( 0)),
|
|
377
|
+
title: _nullishCoalesce(p.title, () => ( "")),
|
|
378
|
+
index: _nullishCoalesce(p.index, () => ( 0)),
|
|
379
|
+
hidden: _nullishCoalesce(p.hidden, () => ( false)),
|
|
380
|
+
rowCount: _nullishCoalesce(g.rowCount, () => ( 0)),
|
|
381
|
+
columnCount: _nullishCoalesce(g.columnCount, () => ( 0)),
|
|
382
|
+
frozenRows: _nullishCoalesce(g.frozenRowCount, () => ( 0)),
|
|
383
|
+
frozenColumns: _nullishCoalesce(g.frozenColumnCount, () => ( 0))
|
|
384
|
+
};
|
|
385
|
+
});
|
|
386
|
+
const byId = new Map(tabs.map((t) => [t.sheetId, t]));
|
|
387
|
+
return {
|
|
388
|
+
spreadsheetId: _nullishCoalesce(s.spreadsheetId, () => ( spreadsheetId)),
|
|
389
|
+
title: _nullishCoalesce(_optionalChain([s, 'access', _25 => _25.properties, 'optionalAccess', _26 => _26.title]), () => ( "")),
|
|
390
|
+
locale: _nullishCoalesce(_optionalChain([s, 'access', _27 => _27.properties, 'optionalAccess', _28 => _28.locale]), () => ( null)),
|
|
391
|
+
timeZone: _nullishCoalesce(_optionalChain([s, 'access', _29 => _29.properties, 'optionalAccess', _30 => _30.timeZone]), () => ( null)),
|
|
392
|
+
tabs,
|
|
393
|
+
namedRanges: (_nullishCoalesce(s.namedRanges, () => ( []))).map((n) => {
|
|
394
|
+
const tab = byId.get(_nullishCoalesce(_optionalChain([n, 'access', _31 => _31.range, 'optionalAccess', _32 => _32.sheetId]), () => ( 0)));
|
|
395
|
+
return {
|
|
396
|
+
namedRangeId: _nullishCoalesce(n.namedRangeId, () => ( "")),
|
|
397
|
+
name: _nullishCoalesce(n.name, () => ( "")),
|
|
398
|
+
range: tab ? gridToA1(n.range, tab) : ""
|
|
399
|
+
};
|
|
400
|
+
}),
|
|
401
|
+
protectedRanges: sheets.flatMap(
|
|
402
|
+
(sh, i) => (_nullishCoalesce(sh.protectedRanges, () => ( []))).map((pr) => ({
|
|
403
|
+
protectedRangeId: _nullishCoalesce(pr.protectedRangeId, () => ( 0)),
|
|
404
|
+
range: gridToA1(pr.range, tabs[i]),
|
|
405
|
+
description: _nullishCoalesce(pr.description, () => ( null)),
|
|
406
|
+
warningOnly: _nullishCoalesce(pr.warningOnly, () => ( false))
|
|
407
|
+
}))
|
|
408
|
+
)
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
function appendResult(updatedRange) {
|
|
412
|
+
const range = _nullishCoalesce(updatedRange, () => ( ""));
|
|
413
|
+
try {
|
|
414
|
+
const part = _chunk4UEM6VO4cjs.a1.split(range).range;
|
|
415
|
+
const b = part === null ? null : _chunk4UEM6VO4cjs.a1.parse(part);
|
|
416
|
+
const firstRow = _nullishCoalesce(_optionalChain([b, 'optionalAccess', _33 => _33.startRow]), () => ( 0));
|
|
417
|
+
return { range, firstRow, lastRow: _nullishCoalesce(_optionalChain([b, 'optionalAccess', _34 => _34.endRow]), () => ( firstRow)) };
|
|
418
|
+
} catch (err) {
|
|
419
|
+
if (!(err instanceof _chunkUUXXCUIBcjs.InvalidSheetsInputError)) throw err;
|
|
420
|
+
return { range, firstRow: 0, lastRow: 0 };
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// src/sheets/service.ts
|
|
425
|
+
var RENDER = {
|
|
426
|
+
formatted: "FORMATTED_VALUE",
|
|
427
|
+
unformatted: "UNFORMATTED_VALUE",
|
|
428
|
+
formula: "FORMULA"
|
|
429
|
+
};
|
|
430
|
+
var INSERT = {
|
|
431
|
+
insert_rows: "INSERT_ROWS",
|
|
432
|
+
overwrite: "OVERWRITE"
|
|
433
|
+
};
|
|
434
|
+
var COLUMN_LETTERS = /^[A-Za-z]{1,3}$/;
|
|
435
|
+
function bad(field, message) {
|
|
436
|
+
return new (0, _chunkUUXXCUIBcjs.InvalidSheetsInputError)(field, message);
|
|
437
|
+
}
|
|
438
|
+
function asField(field, fn) {
|
|
439
|
+
try {
|
|
440
|
+
return fn();
|
|
441
|
+
} catch (err) {
|
|
442
|
+
if (err instanceof _chunkUUXXCUIBcjs.InvalidSheetsInputError && err.field !== field) {
|
|
443
|
+
throw bad(field, err.message);
|
|
444
|
+
}
|
|
445
|
+
throw err;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
function requireId(input, field) {
|
|
449
|
+
const v = _optionalChain([input, 'optionalAccess', _35 => _35[field]]);
|
|
450
|
+
if (typeof v !== "string" || v === "") {
|
|
451
|
+
throw bad(field, `${field} must be a non-empty string`);
|
|
452
|
+
}
|
|
453
|
+
return v;
|
|
454
|
+
}
|
|
455
|
+
function parseRender(v) {
|
|
456
|
+
if (v === void 0) return RENDER.formatted;
|
|
457
|
+
if (typeof v !== "string" || !Object.hasOwn(RENDER, v)) {
|
|
458
|
+
throw bad(
|
|
459
|
+
"valueRender",
|
|
460
|
+
'valueRender must be "formatted", "unformatted" or "formula"'
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
return RENDER[v];
|
|
464
|
+
}
|
|
465
|
+
function parseTab(tab, field = "tab") {
|
|
466
|
+
if (typeof tab === "string") {
|
|
467
|
+
if (tab === "") throw bad(field, `${field} must not be empty`);
|
|
468
|
+
return tab;
|
|
469
|
+
}
|
|
470
|
+
const id = _optionalChain([tab, 'optionalAccess', _36 => _36.sheetId]);
|
|
471
|
+
if (typeof tab !== "object" || tab === null || typeof id !== "number" || !Number.isInteger(id) || id < 0) {
|
|
472
|
+
throw bad(field, `${field} must be a title or { sheetId: integer >= 0 }`);
|
|
473
|
+
}
|
|
474
|
+
return { sheetId: id };
|
|
475
|
+
}
|
|
476
|
+
function parseRange(ref) {
|
|
477
|
+
if (typeof ref === "string") {
|
|
478
|
+
const { tab: tab2, range: range2 } = _chunk4UEM6VO4cjs.a1.split(ref);
|
|
479
|
+
if (range2 !== null) _chunk4UEM6VO4cjs.a1.parse(range2);
|
|
480
|
+
return { tab: tab2, range: range2 };
|
|
481
|
+
}
|
|
482
|
+
if (typeof ref !== "object" || ref === null) {
|
|
483
|
+
throw bad("range", "range must be an A1 string or { tab, range? }");
|
|
484
|
+
}
|
|
485
|
+
const { tab, range } = ref;
|
|
486
|
+
const t = parseTab(tab);
|
|
487
|
+
if (range === void 0) return { tab: t, range: null };
|
|
488
|
+
if (typeof range !== "string") throw bad("range", "range must be a string");
|
|
489
|
+
_chunk4UEM6VO4cjs.a1.parse(range);
|
|
490
|
+
return { tab: t, range };
|
|
491
|
+
}
|
|
492
|
+
function parseRangeList(list, field) {
|
|
493
|
+
if (!Array.isArray(list) || list.length === 0) {
|
|
494
|
+
throw bad(field, `${field} must be a non-empty array`);
|
|
495
|
+
}
|
|
496
|
+
return list.map(parseRange);
|
|
497
|
+
}
|
|
498
|
+
function parseHeaderRow(v, min, fallback) {
|
|
499
|
+
if (v === void 0) return fallback;
|
|
500
|
+
if (typeof v !== "number" || !Number.isInteger(v) || v < min) {
|
|
501
|
+
throw bad("headerRow", `headerRow must be an integer >= ${String(min)}`);
|
|
502
|
+
}
|
|
503
|
+
return v;
|
|
504
|
+
}
|
|
505
|
+
function parseColumns(v) {
|
|
506
|
+
const b = asField("columns", () => {
|
|
507
|
+
if (typeof v !== "string") throw bad("columns");
|
|
508
|
+
return _chunk4UEM6VO4cjs.a1.parse(v);
|
|
509
|
+
});
|
|
510
|
+
if (b.startRow !== null || b.endRow !== null || b.startColumn === null || b.endColumn === null) {
|
|
511
|
+
throw bad("columns", 'columns must look like "B:F"');
|
|
512
|
+
}
|
|
513
|
+
return {
|
|
514
|
+
first: b.startColumn,
|
|
515
|
+
text: `${_chunk4UEM6VO4cjs.a1.indexToColumn(b.startColumn)}:${_chunk4UEM6VO4cjs.a1.indexToColumn(b.endColumn)}`
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
function parseColumn(column2) {
|
|
519
|
+
if (typeof column2 === "string") {
|
|
520
|
+
if (!COLUMN_LETTERS.test(column2)) {
|
|
521
|
+
throw bad("column", "column must be a letter such as C, or { header }");
|
|
522
|
+
}
|
|
523
|
+
return _chunk4UEM6VO4cjs.a1.columnToIndex(column2);
|
|
524
|
+
}
|
|
525
|
+
const header = _optionalChain([column2, 'optionalAccess', _37 => _37.header]);
|
|
526
|
+
if (typeof header !== "string" || header.trim() === "") {
|
|
527
|
+
throw bad("column", "column must be a letter such as C, or { header }");
|
|
528
|
+
}
|
|
529
|
+
return { header: header.trim() };
|
|
530
|
+
}
|
|
531
|
+
var lower = (s) => s.toLowerCase();
|
|
532
|
+
function isSheetsRequest(r) {
|
|
533
|
+
return typeof r === "object" && r !== null && r[SHEETS_REQUEST] === true;
|
|
534
|
+
}
|
|
535
|
+
function createSheets(google, opts = {}) {
|
|
536
|
+
const transport = _nullishCoalesce(opts.transport, () => ( createSheetsApiTransport()));
|
|
537
|
+
const retryOpts = {
|
|
538
|
+
...opts.sleep ? { sleep: opts.sleep } : {},
|
|
539
|
+
...opts.random ? { random: opts.random } : {},
|
|
540
|
+
...opts.maxAttempts !== void 0 ? { maxAttempts: opts.maxAttempts } : {}
|
|
541
|
+
};
|
|
542
|
+
function open(input) {
|
|
543
|
+
const tenantId = requireId(input, "tenantId");
|
|
544
|
+
const connectionId = requireId(input, "connectionId");
|
|
545
|
+
const spreadsheetId = requireId(input, "spreadsheetId");
|
|
546
|
+
const ids = { tenantId, connectionId };
|
|
547
|
+
const session = (fn) => _chunk7ZLAL7UYcjs.withConnectionToken.call(void 0,
|
|
548
|
+
google,
|
|
549
|
+
{
|
|
550
|
+
tenantId,
|
|
551
|
+
connectionId,
|
|
552
|
+
service: "sheets",
|
|
553
|
+
isUnauthorized: (e) => e instanceof SheetsUnauthorizedSignal
|
|
554
|
+
},
|
|
555
|
+
(accessToken) => fn(
|
|
556
|
+
(op, idempotent) => withSheetsRetry(() => op({ accessToken, spreadsheetId }), {
|
|
557
|
+
...retryOpts,
|
|
558
|
+
idempotent,
|
|
559
|
+
ids
|
|
560
|
+
})
|
|
561
|
+
)
|
|
562
|
+
);
|
|
563
|
+
const tabNotFound = (tab) => typeof tab === "string" ? new (0, _chunkUUXXCUIBcjs.SheetTabNotFoundError)(tab, void 0, ids) : new (0, _chunkUUXXCUIBcjs.SheetTabNotFoundError)(
|
|
564
|
+
String(tab.sheetId),
|
|
565
|
+
`Sheet tab not found: sheetId ${String(tab.sheetId)}`,
|
|
566
|
+
ids
|
|
567
|
+
);
|
|
568
|
+
const listTabs = async (send) => {
|
|
569
|
+
const s = await send(
|
|
570
|
+
(t) => transport.getSpreadsheet({ ...t, fields: TAB_FIELDS }),
|
|
571
|
+
true
|
|
572
|
+
);
|
|
573
|
+
return (_nullishCoalesce(s.sheets, () => ( []))).map((sh) => ({
|
|
574
|
+
sheetId: _nullishCoalesce(_optionalChain([sh, 'access', _38 => _38.properties, 'optionalAccess', _39 => _39.sheetId]), () => ( 0)),
|
|
575
|
+
title: _nullishCoalesce(_optionalChain([sh, 'access', _40 => _40.properties, 'optionalAccess', _41 => _41.title]), () => ( ""))
|
|
576
|
+
}));
|
|
577
|
+
};
|
|
578
|
+
const toRefs = async (send, ranges) => {
|
|
579
|
+
const needIds = ranges.some((r) => typeof r.tab !== "string");
|
|
580
|
+
const tabs = needIds ? await listTabs(send) : [];
|
|
581
|
+
return ranges.map(({ tab, range }) => {
|
|
582
|
+
let title2;
|
|
583
|
+
if (typeof tab === "string") title2 = tab;
|
|
584
|
+
else {
|
|
585
|
+
const found = tabs.find((t) => t.sheetId === tab.sheetId);
|
|
586
|
+
if (!found) throw tabNotFound(tab);
|
|
587
|
+
title2 = found.title;
|
|
588
|
+
}
|
|
589
|
+
return _chunk4UEM6VO4cjs.a1.range(title2, _nullishCoalesce(range, () => ( void 0)));
|
|
590
|
+
});
|
|
591
|
+
};
|
|
592
|
+
const readValues = async (send, range, render) => {
|
|
593
|
+
const [ref] = await toRefs(send, [range]);
|
|
594
|
+
const res = await send(
|
|
595
|
+
(t) => transport.valuesGet({ ...t, range: ref, valueRenderOption: render }),
|
|
596
|
+
true
|
|
597
|
+
);
|
|
598
|
+
return _nullishCoalesce(res.values, () => ( []));
|
|
599
|
+
};
|
|
600
|
+
return {
|
|
601
|
+
spreadsheetId,
|
|
602
|
+
async getInfo() {
|
|
603
|
+
const s = await session(
|
|
604
|
+
(send) => send(
|
|
605
|
+
(t) => transport.getSpreadsheet({ ...t, fields: INFO_FIELDS }),
|
|
606
|
+
true
|
|
607
|
+
)
|
|
608
|
+
);
|
|
609
|
+
return toInfo(s, spreadsheetId);
|
|
610
|
+
},
|
|
611
|
+
async getValues(range, o = {}) {
|
|
612
|
+
const r = parseRange(range);
|
|
613
|
+
const render = parseRender(o.valueRender);
|
|
614
|
+
return session((send) => readValues(send, r, render));
|
|
615
|
+
},
|
|
616
|
+
async getValuesBatch(ranges, o = {}) {
|
|
617
|
+
const rs = parseRangeList(ranges, "ranges");
|
|
618
|
+
const render = parseRender(o.valueRender);
|
|
619
|
+
const res = await session(async (send) => {
|
|
620
|
+
const refs = await toRefs(send, rs);
|
|
621
|
+
return send(
|
|
622
|
+
(t) => transport.valuesBatchGet({
|
|
623
|
+
...t,
|
|
624
|
+
ranges: refs,
|
|
625
|
+
valueRenderOption: render
|
|
626
|
+
}),
|
|
627
|
+
true
|
|
628
|
+
);
|
|
629
|
+
});
|
|
630
|
+
const out = _nullishCoalesce(res.valueRanges, () => ( []));
|
|
631
|
+
return rs.map((_, i) => _nullishCoalesce(_optionalChain([out, 'access', _42 => _42[i], 'optionalAccess', _43 => _43.values]), () => ( [])));
|
|
632
|
+
},
|
|
633
|
+
async getRows(tab, o = {}) {
|
|
634
|
+
const t = parseTab(tab);
|
|
635
|
+
const headerRow = parseHeaderRow(o.headerRow, 1, 1);
|
|
636
|
+
const columns = o.columns === void 0 ? null : parseColumns(o.columns);
|
|
637
|
+
const render = parseRender(o.valueRender);
|
|
638
|
+
const rows = await session(
|
|
639
|
+
(send) => readValues(send, { tab: t, range: _nullishCoalesce(_optionalChain([columns, 'optionalAccess', _44 => _44.text]), () => ( null)) }, render)
|
|
640
|
+
);
|
|
641
|
+
const header = _nullishCoalesce(rows[headerRow - 1], () => ( []));
|
|
642
|
+
const body = rows.slice(headerRow);
|
|
643
|
+
const keys = headerKeys(
|
|
644
|
+
header,
|
|
645
|
+
Math.max(header.length, widest(body)),
|
|
646
|
+
_nullishCoalesce(_optionalChain([columns, 'optionalAccess', _45 => _45.first]), () => ( 1))
|
|
647
|
+
);
|
|
648
|
+
const out = [];
|
|
649
|
+
body.forEach((row, i) => {
|
|
650
|
+
if (row.every(isEmpty)) return;
|
|
651
|
+
out.push({
|
|
652
|
+
rowNumber: headerRow + 1 + i,
|
|
653
|
+
// fromEntries keeps a header such as "__proto__" as an own key.
|
|
654
|
+
data: Object.fromEntries(keys.map((k, j) => [k, _nullishCoalesce(row[j], () => ( null))]))
|
|
655
|
+
});
|
|
656
|
+
});
|
|
657
|
+
return out;
|
|
658
|
+
},
|
|
659
|
+
async findRows(tab, o) {
|
|
660
|
+
const t = parseTab(tab);
|
|
661
|
+
const column2 = parseColumn(_optionalChain([o, 'optionalAccess', _46 => _46.column]));
|
|
662
|
+
const headerRow = parseHeaderRow(_optionalChain([o, 'optionalAccess', _47 => _47.headerRow]), 0, 1);
|
|
663
|
+
const where = _optionalChain([o, 'optionalAccess', _48 => _48.where]);
|
|
664
|
+
if (typeof where !== "function") {
|
|
665
|
+
throw bad("where", "where must be a function");
|
|
666
|
+
}
|
|
667
|
+
if (typeof column2 !== "number" && headerRow === 0) {
|
|
668
|
+
throw bad("column", "{ header } needs a header row (headerRow >= 1)");
|
|
669
|
+
}
|
|
670
|
+
const render = parseRender(o.valueRender);
|
|
671
|
+
const rows = await session(
|
|
672
|
+
(send) => readValues(send, { tab: t, range: null }, render)
|
|
673
|
+
);
|
|
674
|
+
if (rows.length === 0) return [];
|
|
675
|
+
let index;
|
|
676
|
+
if (typeof column2 === "number") index = column2 - 1;
|
|
677
|
+
else {
|
|
678
|
+
const header = _nullishCoalesce(rows[headerRow - 1], () => ( []));
|
|
679
|
+
index = header.findIndex((h) => headerText(h) === column2.header);
|
|
680
|
+
if (index === -1) {
|
|
681
|
+
throw bad(
|
|
682
|
+
"column",
|
|
683
|
+
`No header ${JSON.stringify(column2.header).slice(0, 64)} in row ${String(headerRow)}`
|
|
684
|
+
);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
const width = widest(rows);
|
|
688
|
+
const out = [];
|
|
689
|
+
for (let i = headerRow; i < rows.length; i++) {
|
|
690
|
+
const values = pad(rows[i], width);
|
|
691
|
+
if (where(_nullishCoalesce(values[index], () => ( null)), values)) {
|
|
692
|
+
out.push({ rowNumber: i + 1, values });
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
return out;
|
|
696
|
+
},
|
|
697
|
+
async update(range, values, o = {}) {
|
|
698
|
+
const r = parseRange(range);
|
|
699
|
+
const enc = encodeRows(values, _nullishCoalesce(o.input, () => ( "raw")));
|
|
700
|
+
const res = await session(async (send) => {
|
|
701
|
+
const [ref] = await toRefs(send, [r]);
|
|
702
|
+
return send(
|
|
703
|
+
(t) => transport.valuesUpdate({
|
|
704
|
+
...t,
|
|
705
|
+
range: ref,
|
|
706
|
+
values: enc.values,
|
|
707
|
+
valueInputOption: enc.valueInputOption
|
|
708
|
+
}),
|
|
709
|
+
true
|
|
710
|
+
);
|
|
711
|
+
});
|
|
712
|
+
return {
|
|
713
|
+
updatedRange: _nullishCoalesce(res.updatedRange, () => ( "")),
|
|
714
|
+
updatedCells: _nullishCoalesce(res.updatedCells, () => ( 0))
|
|
715
|
+
};
|
|
716
|
+
},
|
|
717
|
+
async updateBatch(entries, o = {}) {
|
|
718
|
+
if (!Array.isArray(entries) || entries.length === 0) {
|
|
719
|
+
throw bad("entries", "entries must be a non-empty array");
|
|
720
|
+
}
|
|
721
|
+
const mode = _nullishCoalesce(o.input, () => ( "raw"));
|
|
722
|
+
const ranges = entries.map((e) => {
|
|
723
|
+
const r = parseRange(_optionalChain([e, 'optionalAccess', _49 => _49.range]));
|
|
724
|
+
encodeRows(e.values, mode);
|
|
725
|
+
return r;
|
|
726
|
+
});
|
|
727
|
+
const all = encodeRows(
|
|
728
|
+
entries.flatMap((e) => e.values),
|
|
729
|
+
mode
|
|
730
|
+
);
|
|
731
|
+
let next = 0;
|
|
732
|
+
const blocks = entries.map((e) => {
|
|
733
|
+
const block = all.values.slice(next, next + e.values.length);
|
|
734
|
+
next += e.values.length;
|
|
735
|
+
return block;
|
|
736
|
+
});
|
|
737
|
+
const res = await session(async (send) => {
|
|
738
|
+
const refs = await toRefs(send, ranges);
|
|
739
|
+
return send(
|
|
740
|
+
(t) => transport.valuesBatchUpdate({
|
|
741
|
+
...t,
|
|
742
|
+
data: refs.map((range, i) => ({ range, values: blocks[i] })),
|
|
743
|
+
valueInputOption: all.valueInputOption
|
|
744
|
+
}),
|
|
745
|
+
true
|
|
746
|
+
);
|
|
747
|
+
});
|
|
748
|
+
return { updatedCells: _nullishCoalesce(res.totalUpdatedCells, () => ( 0)) };
|
|
749
|
+
},
|
|
750
|
+
async clear(range) {
|
|
751
|
+
const rs = Array.isArray(range) ? parseRangeList(range, "range") : [parseRange(range)];
|
|
752
|
+
await session(async (send) => {
|
|
753
|
+
const refs = await toRefs(send, rs);
|
|
754
|
+
await send(
|
|
755
|
+
(t) => transport.valuesBatchClear({ ...t, ranges: refs }),
|
|
756
|
+
true
|
|
757
|
+
);
|
|
758
|
+
});
|
|
759
|
+
},
|
|
760
|
+
async append(tab, rows, o = {}) {
|
|
761
|
+
const t = parseTab(tab);
|
|
762
|
+
const enc = encodeRows(rows, _nullishCoalesce(o.input, () => ( "raw")), "rows");
|
|
763
|
+
const insert = _nullishCoalesce(o.insert, () => ( "insert_rows"));
|
|
764
|
+
if (typeof insert !== "string" || !Object.hasOwn(INSERT, insert)) {
|
|
765
|
+
throw bad("insert", 'insert must be "insert_rows" or "overwrite"');
|
|
766
|
+
}
|
|
767
|
+
const res = await session(async (send) => {
|
|
768
|
+
const [ref] = await toRefs(send, [{ tab: t, range: "A1" }]);
|
|
769
|
+
return send(
|
|
770
|
+
(x) => transport.valuesAppend({
|
|
771
|
+
...x,
|
|
772
|
+
range: ref,
|
|
773
|
+
values: enc.values,
|
|
774
|
+
valueInputOption: enc.valueInputOption,
|
|
775
|
+
insertDataOption: INSERT[insert]
|
|
776
|
+
}),
|
|
777
|
+
false
|
|
778
|
+
);
|
|
779
|
+
});
|
|
780
|
+
return appendResult(_optionalChain([res, 'access', _50 => _50.updates, 'optionalAccess', _51 => _51.updatedRange]));
|
|
781
|
+
},
|
|
782
|
+
async batch(requests) {
|
|
783
|
+
if (!Array.isArray(requests) || requests.length === 0 || !requests.every(isSheetsRequest)) {
|
|
784
|
+
throw bad(
|
|
785
|
+
"requests",
|
|
786
|
+
"requests must be a non-empty array of req.* builders"
|
|
787
|
+
);
|
|
788
|
+
}
|
|
789
|
+
const addedAt = /* @__PURE__ */ new Map();
|
|
790
|
+
requests.forEach((r, i) => {
|
|
791
|
+
if (!r.adds) return;
|
|
792
|
+
const key = lower(r.adds.title);
|
|
793
|
+
if (addedAt.has(key)) {
|
|
794
|
+
throw bad(
|
|
795
|
+
"requests",
|
|
796
|
+
`Duplicate addTab title in one batch: ${JSON.stringify(r.adds.title).slice(0, 64)}`
|
|
797
|
+
);
|
|
798
|
+
}
|
|
799
|
+
addedAt.set(key, i);
|
|
800
|
+
});
|
|
801
|
+
const addedBefore = (i, title2) => {
|
|
802
|
+
const j = addedAt.get(lower(title2));
|
|
803
|
+
return j !== void 0 && j < i ? j : void 0;
|
|
804
|
+
};
|
|
805
|
+
const needLookup = requests.some(
|
|
806
|
+
(r, i) => r.refs.some((tab) => {
|
|
807
|
+
if (typeof tab !== "string") return false;
|
|
808
|
+
const j = addedBefore(i, tab);
|
|
809
|
+
return j === void 0 || requests[j].adds.sheetId === void 0;
|
|
810
|
+
})
|
|
811
|
+
);
|
|
812
|
+
const res = await session(async (send) => {
|
|
813
|
+
const existing = needLookup ? await listTabs(send) : null;
|
|
814
|
+
const assigned = [];
|
|
815
|
+
if (existing) {
|
|
816
|
+
let next = Math.max(
|
|
817
|
+
-1,
|
|
818
|
+
...existing.map((t) => t.sheetId),
|
|
819
|
+
...requests.map((r) => _nullishCoalesce(_optionalChain([r, 'access', _52 => _52.adds, 'optionalAccess', _53 => _53.sheetId]), () => ( -1)))
|
|
820
|
+
) + 1;
|
|
821
|
+
requests.forEach((r, i) => {
|
|
822
|
+
if (r.adds && r.adds.sheetId === void 0) assigned[i] = next++;
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
const built = requests.map(
|
|
826
|
+
(r, i) => r.build(
|
|
827
|
+
{
|
|
828
|
+
sheetId(tab) {
|
|
829
|
+
if (typeof tab !== "string") return tab.sheetId;
|
|
830
|
+
const j = addedBefore(i, tab);
|
|
831
|
+
const added = j === void 0 ? void 0 : _nullishCoalesce(requests[j].adds.sheetId, () => ( assigned[j]));
|
|
832
|
+
if (added !== void 0) return added;
|
|
833
|
+
const found = _optionalChain([existing, 'optionalAccess', _54 => _54.find, 'call', _55 => _55(
|
|
834
|
+
(t) => lower(t.title) === lower(tab)
|
|
835
|
+
)]);
|
|
836
|
+
if (!found) throw tabNotFound(tab);
|
|
837
|
+
return found.sheetId;
|
|
838
|
+
}
|
|
839
|
+
},
|
|
840
|
+
assigned[i]
|
|
841
|
+
)
|
|
842
|
+
);
|
|
843
|
+
return send(
|
|
844
|
+
(t) => transport.batchUpdate({ ...t, requests: built }),
|
|
845
|
+
false
|
|
846
|
+
);
|
|
847
|
+
});
|
|
848
|
+
return _nullishCoalesce(res.replies, () => ( []));
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
return { open };
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
// src/sheets/requests.ts
|
|
856
|
+
function bad2(field, message) {
|
|
857
|
+
return new (0, _chunkUUXXCUIBcjs.InvalidSheetsInputError)(field, message);
|
|
858
|
+
}
|
|
859
|
+
function int(value, field, min) {
|
|
860
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < min) {
|
|
861
|
+
throw bad2(field, `${field} must be an integer >= ${String(min)}`);
|
|
862
|
+
}
|
|
863
|
+
return value;
|
|
864
|
+
}
|
|
865
|
+
function optInt(value, field, min) {
|
|
866
|
+
return value === void 0 ? void 0 : int(value, field, min);
|
|
867
|
+
}
|
|
868
|
+
function title(value, field) {
|
|
869
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
870
|
+
throw bad2(field, `${field} must be a non-empty string`);
|
|
871
|
+
}
|
|
872
|
+
return value;
|
|
873
|
+
}
|
|
874
|
+
function px(value) {
|
|
875
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 1 || value > 1e4) {
|
|
876
|
+
throw bad2("px", "px must be an integer between 1 and 10000");
|
|
877
|
+
}
|
|
878
|
+
return value;
|
|
879
|
+
}
|
|
880
|
+
function tabRef(tab, field = "tab") {
|
|
881
|
+
if (typeof tab === "string") {
|
|
882
|
+
if (tab.length === 0) throw bad2(field, `${field} must not be empty`);
|
|
883
|
+
return tab;
|
|
884
|
+
}
|
|
885
|
+
if (typeof tab !== "object" || tab === null || !Number.isInteger(tab.sheetId) || tab.sheetId < 0) {
|
|
886
|
+
throw bad2(field, `${field} must be a title or { sheetId }`);
|
|
887
|
+
}
|
|
888
|
+
return tab;
|
|
889
|
+
}
|
|
890
|
+
function column(value, field) {
|
|
891
|
+
if (typeof value === "number") return int(value, field, 1);
|
|
892
|
+
if (typeof value !== "string" || !/^[A-Za-z]{1,3}$/.test(value)) {
|
|
893
|
+
throw bad2(field, `${field} must be a column letter or a 1-based number`);
|
|
894
|
+
}
|
|
895
|
+
return _chunk4UEM6VO4cjs.a1.columnToIndex(value);
|
|
896
|
+
}
|
|
897
|
+
function columnSpan(value, field) {
|
|
898
|
+
if (Array.isArray(value)) {
|
|
899
|
+
const [start, end] = value;
|
|
900
|
+
const s = int(start, field, 1);
|
|
901
|
+
const e = int(end, field, 1);
|
|
902
|
+
if (s > e) throw bad2(field, `${field} start must not exceed end`);
|
|
903
|
+
return [s, e];
|
|
904
|
+
}
|
|
905
|
+
if (typeof value !== "string") throw bad2(field);
|
|
906
|
+
let bounds;
|
|
907
|
+
try {
|
|
908
|
+
bounds = _chunk4UEM6VO4cjs.a1.parse(value);
|
|
909
|
+
} catch (e2) {
|
|
910
|
+
throw bad2(field, `${field} must look like "B:D" or [2, 4]`);
|
|
911
|
+
}
|
|
912
|
+
if (bounds.startRow !== null || bounds.endRow !== null || bounds.startColumn === null || bounds.endColumn === null) {
|
|
913
|
+
throw bad2(field, `${field} must look like "B:D" or [2, 4]`);
|
|
914
|
+
}
|
|
915
|
+
return [bounds.startColumn, bounds.endColumn];
|
|
916
|
+
}
|
|
917
|
+
function rowSpan(value, field) {
|
|
918
|
+
if (!Array.isArray(value)) throw bad2(field, `${field} must be [start, end]`);
|
|
919
|
+
const s = int(value[0], field, 1);
|
|
920
|
+
const e = int(value[1], field, 1);
|
|
921
|
+
if (s > e) throw bad2(field, `${field} start must not exceed end`);
|
|
922
|
+
return [s, e];
|
|
923
|
+
}
|
|
924
|
+
function dimensionRange(sheetId, dimension, start, endInclusive) {
|
|
925
|
+
return {
|
|
926
|
+
sheetId,
|
|
927
|
+
dimension,
|
|
928
|
+
startIndex: start - 1,
|
|
929
|
+
endIndex: endInclusive
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
function toGridRange(sheetId, range) {
|
|
933
|
+
const grid = { sheetId };
|
|
934
|
+
if (range === null) return grid;
|
|
935
|
+
const b = _chunk4UEM6VO4cjs.a1.parse(range);
|
|
936
|
+
if (b.startRow !== null) grid.startRowIndex = b.startRow - 1;
|
|
937
|
+
if (b.endRow !== null) grid.endRowIndex = b.endRow;
|
|
938
|
+
if (b.startColumn !== null) grid.startColumnIndex = b.startColumn - 1;
|
|
939
|
+
if (b.endColumn !== null) grid.endColumnIndex = b.endColumn;
|
|
940
|
+
return grid;
|
|
941
|
+
}
|
|
942
|
+
function rangeText(range) {
|
|
943
|
+
if (typeof range !== "string") throw bad2("range", "range must be a string");
|
|
944
|
+
_chunk4UEM6VO4cjs.a1.parse(range);
|
|
945
|
+
return range;
|
|
946
|
+
}
|
|
947
|
+
function make(refs, build, adds) {
|
|
948
|
+
return {
|
|
949
|
+
[SHEETS_REQUEST]: true,
|
|
950
|
+
refs,
|
|
951
|
+
...adds ? { adds } : {},
|
|
952
|
+
build
|
|
953
|
+
};
|
|
954
|
+
}
|
|
955
|
+
function tabProps(tab, properties, fields) {
|
|
956
|
+
const t = tabRef(tab);
|
|
957
|
+
return make([t], (ctx) => ({
|
|
958
|
+
updateSheetProperties: {
|
|
959
|
+
properties: { sheetId: ctx.sheetId(t), ...properties },
|
|
960
|
+
fields
|
|
961
|
+
}
|
|
962
|
+
}));
|
|
963
|
+
}
|
|
964
|
+
function insertDimension(tab, dimension, start, count) {
|
|
965
|
+
const t = tabRef(tab);
|
|
966
|
+
return make([t], (ctx) => ({
|
|
967
|
+
insertDimension: {
|
|
968
|
+
range: dimensionRange(
|
|
969
|
+
ctx.sheetId(t),
|
|
970
|
+
dimension,
|
|
971
|
+
start,
|
|
972
|
+
start + count - 1
|
|
973
|
+
),
|
|
974
|
+
inheritFromBefore: false
|
|
975
|
+
}
|
|
976
|
+
}));
|
|
977
|
+
}
|
|
978
|
+
function deleteDimension(tab, dimension, start, count) {
|
|
979
|
+
const t = tabRef(tab);
|
|
980
|
+
return make([t], (ctx) => ({
|
|
981
|
+
deleteDimension: {
|
|
982
|
+
range: dimensionRange(
|
|
983
|
+
ctx.sheetId(t),
|
|
984
|
+
dimension,
|
|
985
|
+
start,
|
|
986
|
+
start + count - 1
|
|
987
|
+
)
|
|
988
|
+
}
|
|
989
|
+
}));
|
|
990
|
+
}
|
|
991
|
+
function setSize(tab, dimension, span, size) {
|
|
992
|
+
const t = tabRef(tab);
|
|
993
|
+
return make([t], (ctx) => ({
|
|
994
|
+
updateDimensionProperties: {
|
|
995
|
+
range: dimensionRange(ctx.sheetId(t), dimension, span[0], span[1]),
|
|
996
|
+
properties: { pixelSize: size },
|
|
997
|
+
fields: "pixelSize"
|
|
998
|
+
}
|
|
999
|
+
}));
|
|
1000
|
+
}
|
|
1001
|
+
var MERGE_TYPES = {
|
|
1002
|
+
all: "MERGE_ALL",
|
|
1003
|
+
columns: "MERGE_COLUMNS",
|
|
1004
|
+
rows: "MERGE_ROWS"
|
|
1005
|
+
};
|
|
1006
|
+
var PASTE_TYPES = {
|
|
1007
|
+
normal: "PASTE_NORMAL",
|
|
1008
|
+
values: "PASTE_VALUES",
|
|
1009
|
+
format: "PASTE_FORMAT",
|
|
1010
|
+
formula: "PASTE_FORMULA"
|
|
1011
|
+
};
|
|
1012
|
+
var NAMED_RANGE_NAME = /^[A-Za-z_][A-Za-z0-9_]{0,249}$/;
|
|
1013
|
+
var RESERVED_NAME = [/^[A-Za-z]{1,3}\d+$/, /^R\d*C\d*$/i, /^(true|false)$/i];
|
|
1014
|
+
function namedRangeName(name) {
|
|
1015
|
+
if (typeof name !== "string" || !NAMED_RANGE_NAME.test(name)) {
|
|
1016
|
+
throw bad2(
|
|
1017
|
+
"name",
|
|
1018
|
+
"name must start with a letter or underscore and use letters, digits or underscores (max 250)"
|
|
1019
|
+
);
|
|
1020
|
+
}
|
|
1021
|
+
if (RESERVED_NAME.some((re) => re.test(name))) {
|
|
1022
|
+
throw bad2(
|
|
1023
|
+
"name",
|
|
1024
|
+
"name must not look like a cell reference (A1, R1C1) or TRUE/FALSE"
|
|
1025
|
+
);
|
|
1026
|
+
}
|
|
1027
|
+
return name;
|
|
1028
|
+
}
|
|
1029
|
+
var req = {
|
|
1030
|
+
/** `index` is the 0-based tab position. */
|
|
1031
|
+
addTab(tabTitle, o = {}) {
|
|
1032
|
+
const name = title(tabTitle, "title");
|
|
1033
|
+
const index = optInt(o.index, "index", 0);
|
|
1034
|
+
const rows = optInt(o.rows, "rows", 1);
|
|
1035
|
+
const columns = optInt(o.columns, "columns", 1);
|
|
1036
|
+
const sheetId = optInt(o.sheetId, "sheetId", 0);
|
|
1037
|
+
return make(
|
|
1038
|
+
[],
|
|
1039
|
+
(_ctx, assignedSheetId) => {
|
|
1040
|
+
const id = _nullishCoalesce(sheetId, () => ( assignedSheetId));
|
|
1041
|
+
const properties = { title: name };
|
|
1042
|
+
if (id !== void 0) properties.sheetId = id;
|
|
1043
|
+
if (index !== void 0) properties.index = index;
|
|
1044
|
+
if (rows !== void 0 || columns !== void 0) {
|
|
1045
|
+
properties.gridProperties = {
|
|
1046
|
+
...rows !== void 0 ? { rowCount: rows } : {},
|
|
1047
|
+
...columns !== void 0 ? { columnCount: columns } : {}
|
|
1048
|
+
};
|
|
1049
|
+
}
|
|
1050
|
+
return { addSheet: { properties } };
|
|
1051
|
+
},
|
|
1052
|
+
sheetId === void 0 ? { title: name } : { title: name, sheetId }
|
|
1053
|
+
);
|
|
1054
|
+
},
|
|
1055
|
+
deleteTab(tab) {
|
|
1056
|
+
const t = tabRef(tab);
|
|
1057
|
+
return make([t], (ctx) => ({ deleteSheet: { sheetId: ctx.sheetId(t) } }));
|
|
1058
|
+
},
|
|
1059
|
+
renameTab(tab, newTitle) {
|
|
1060
|
+
return tabProps(tab, { title: title(newTitle, "title") }, "title");
|
|
1061
|
+
},
|
|
1062
|
+
/** `o.index` is the 0-based position of the copy. */
|
|
1063
|
+
duplicateTab(tab, newTitle, o = {}) {
|
|
1064
|
+
const t = tabRef(tab);
|
|
1065
|
+
const name = title(newTitle, "newTitle");
|
|
1066
|
+
const index = optInt(o.index, "index", 0);
|
|
1067
|
+
return make([t], (ctx) => ({
|
|
1068
|
+
duplicateSheet: {
|
|
1069
|
+
sourceSheetId: ctx.sheetId(t),
|
|
1070
|
+
newSheetName: name,
|
|
1071
|
+
...index !== void 0 ? { insertSheetIndex: index } : {}
|
|
1072
|
+
}
|
|
1073
|
+
}));
|
|
1074
|
+
},
|
|
1075
|
+
/**
|
|
1076
|
+
* `index` counts tab positions BEFORE the move (Google's semantics), 0-based.
|
|
1077
|
+
* Moving left, it is the tab's new position. Moving right, it is one more
|
|
1078
|
+
* than the new position: with tabs `[A, B, C]`, `moveTab("A", 2)` gives
|
|
1079
|
+
* `[B, A, C]` and `moveTab("A", 3)` gives `[B, C, A]`.
|
|
1080
|
+
*/
|
|
1081
|
+
moveTab(tab, index) {
|
|
1082
|
+
return tabProps(tab, { index: int(index, "index", 0) }, "index");
|
|
1083
|
+
},
|
|
1084
|
+
hideTab(tab) {
|
|
1085
|
+
return tabProps(tab, { hidden: true }, "hidden");
|
|
1086
|
+
},
|
|
1087
|
+
showTab(tab) {
|
|
1088
|
+
return tabProps(tab, { hidden: false }, "hidden");
|
|
1089
|
+
},
|
|
1090
|
+
/** Inserts `count` blank rows BEFORE 1-based row `at`. */
|
|
1091
|
+
insertRows(tab, at, count) {
|
|
1092
|
+
tabRef(tab);
|
|
1093
|
+
return insertDimension(
|
|
1094
|
+
tab,
|
|
1095
|
+
"ROWS",
|
|
1096
|
+
int(at, "at", 1),
|
|
1097
|
+
int(count, "count", 1)
|
|
1098
|
+
);
|
|
1099
|
+
},
|
|
1100
|
+
/** Inserts `count` blank columns BEFORE column `at` (`"C"` or `3`). */
|
|
1101
|
+
insertColumns(tab, at, count) {
|
|
1102
|
+
tabRef(tab);
|
|
1103
|
+
return insertDimension(
|
|
1104
|
+
tab,
|
|
1105
|
+
"COLUMNS",
|
|
1106
|
+
column(at, "at"),
|
|
1107
|
+
int(count, "count", 1)
|
|
1108
|
+
);
|
|
1109
|
+
},
|
|
1110
|
+
/** Deletes `count` rows starting at 1-based row `from`. */
|
|
1111
|
+
deleteRows(tab, from, count) {
|
|
1112
|
+
tabRef(tab);
|
|
1113
|
+
return deleteDimension(
|
|
1114
|
+
tab,
|
|
1115
|
+
"ROWS",
|
|
1116
|
+
int(from, "from", 1),
|
|
1117
|
+
int(count, "count", 1)
|
|
1118
|
+
);
|
|
1119
|
+
},
|
|
1120
|
+
/** Deletes `count` columns starting at column `from` (`"C"` or `3`). */
|
|
1121
|
+
deleteColumns(tab, from, count) {
|
|
1122
|
+
tabRef(tab);
|
|
1123
|
+
return deleteDimension(
|
|
1124
|
+
tab,
|
|
1125
|
+
"COLUMNS",
|
|
1126
|
+
column(from, "from"),
|
|
1127
|
+
int(count, "count", 1)
|
|
1128
|
+
);
|
|
1129
|
+
},
|
|
1130
|
+
/** `columns` is `"B:D"` or a 1-based inclusive pair `[2, 4]`. */
|
|
1131
|
+
setColumnWidth(tab, columns, pixels) {
|
|
1132
|
+
tabRef(tab);
|
|
1133
|
+
return setSize(tab, "COLUMNS", columnSpan(columns, "columns"), px(pixels));
|
|
1134
|
+
},
|
|
1135
|
+
/** `rows` is a 1-based inclusive pair `[1, 3]`. */
|
|
1136
|
+
setRowHeight(tab, rows, pixels) {
|
|
1137
|
+
tabRef(tab);
|
|
1138
|
+
return setSize(tab, "ROWS", rowSpan(rows, "rows"), px(pixels));
|
|
1139
|
+
},
|
|
1140
|
+
/** `columns` is `"B:D"` or a 1-based inclusive pair `[2, 4]`. */
|
|
1141
|
+
autoResizeColumns(tab, columns) {
|
|
1142
|
+
const t = tabRef(tab);
|
|
1143
|
+
const [s, e] = columnSpan(columns, "columns");
|
|
1144
|
+
return make([t], (ctx) => ({
|
|
1145
|
+
autoResizeDimensions: {
|
|
1146
|
+
dimensions: dimensionRange(ctx.sheetId(t), "COLUMNS", s, e)
|
|
1147
|
+
}
|
|
1148
|
+
}));
|
|
1149
|
+
},
|
|
1150
|
+
/** Freezes the first N rows/columns; `0` unfreezes. */
|
|
1151
|
+
freeze(tab, o) {
|
|
1152
|
+
const rows = optInt(_optionalChain([o, 'optionalAccess', _56 => _56.rows]), "rows", 0);
|
|
1153
|
+
const columns = optInt(_optionalChain([o, 'optionalAccess', _57 => _57.columns]), "columns", 0);
|
|
1154
|
+
if (rows === void 0 && columns === void 0) {
|
|
1155
|
+
throw bad2("freeze", "freeze needs rows and/or columns");
|
|
1156
|
+
}
|
|
1157
|
+
const grid = {};
|
|
1158
|
+
const fields = [];
|
|
1159
|
+
if (rows !== void 0) {
|
|
1160
|
+
grid.frozenRowCount = rows;
|
|
1161
|
+
fields.push("gridProperties.frozenRowCount");
|
|
1162
|
+
}
|
|
1163
|
+
if (columns !== void 0) {
|
|
1164
|
+
grid.frozenColumnCount = columns;
|
|
1165
|
+
fields.push("gridProperties.frozenColumnCount");
|
|
1166
|
+
}
|
|
1167
|
+
return tabProps(tab, { gridProperties: grid }, fields.join(","));
|
|
1168
|
+
},
|
|
1169
|
+
merge(tab, range, type = "all") {
|
|
1170
|
+
const t = tabRef(tab);
|
|
1171
|
+
const r = rangeText(range);
|
|
1172
|
+
if (!Object.hasOwn(MERGE_TYPES, type)) {
|
|
1173
|
+
throw bad2("type", `type must be "all", "columns" or "rows"`);
|
|
1174
|
+
}
|
|
1175
|
+
return make([t], (ctx) => ({
|
|
1176
|
+
mergeCells: {
|
|
1177
|
+
range: toGridRange(ctx.sheetId(t), r),
|
|
1178
|
+
mergeType: MERGE_TYPES[type]
|
|
1179
|
+
}
|
|
1180
|
+
}));
|
|
1181
|
+
},
|
|
1182
|
+
unmerge(tab, range) {
|
|
1183
|
+
const t = tabRef(tab);
|
|
1184
|
+
const r = rangeText(range);
|
|
1185
|
+
return make([t], (ctx) => ({
|
|
1186
|
+
unmergeCells: { range: toGridRange(ctx.sheetId(t), r) }
|
|
1187
|
+
}));
|
|
1188
|
+
},
|
|
1189
|
+
/** `fields` is the field mask; defaults to `"userEnteredFormat"`. */
|
|
1190
|
+
format(tab, range, cellFormat, fields = "userEnteredFormat") {
|
|
1191
|
+
const t = tabRef(tab);
|
|
1192
|
+
const r = rangeText(range);
|
|
1193
|
+
if (typeof cellFormat !== "object" || cellFormat === null) {
|
|
1194
|
+
throw bad2("cellFormat", "cellFormat must be an object");
|
|
1195
|
+
}
|
|
1196
|
+
const mask = title(fields, "fields");
|
|
1197
|
+
return make([t], (ctx) => ({
|
|
1198
|
+
repeatCell: {
|
|
1199
|
+
range: toGridRange(ctx.sheetId(t), r),
|
|
1200
|
+
cell: { userEnteredFormat: cellFormat },
|
|
1201
|
+
fields: mask
|
|
1202
|
+
}
|
|
1203
|
+
}));
|
|
1204
|
+
},
|
|
1205
|
+
copyPaste(from, to, pasteType = "normal") {
|
|
1206
|
+
const ft = tabRef(_optionalChain([from, 'optionalAccess', _58 => _58.tab]), "from");
|
|
1207
|
+
const tt = tabRef(_optionalChain([to, 'optionalAccess', _59 => _59.tab]), "to");
|
|
1208
|
+
const fr = rangeText(from.range);
|
|
1209
|
+
const tr = rangeText(to.range);
|
|
1210
|
+
if (!Object.hasOwn(PASTE_TYPES, pasteType)) {
|
|
1211
|
+
throw bad2("pasteType", "pasteType must be normal|values|format|formula");
|
|
1212
|
+
}
|
|
1213
|
+
return make([ft, tt], (ctx) => ({
|
|
1214
|
+
copyPaste: {
|
|
1215
|
+
source: toGridRange(ctx.sheetId(ft), fr),
|
|
1216
|
+
destination: toGridRange(ctx.sheetId(tt), tr),
|
|
1217
|
+
pasteType: PASTE_TYPES[pasteType]
|
|
1218
|
+
}
|
|
1219
|
+
}));
|
|
1220
|
+
},
|
|
1221
|
+
/** `column` letters are absolute sheet columns, not relative to `range`. */
|
|
1222
|
+
sort(tab, range, specs) {
|
|
1223
|
+
const t = tabRef(tab);
|
|
1224
|
+
const r = rangeText(range);
|
|
1225
|
+
if (!Array.isArray(specs) || specs.length === 0) {
|
|
1226
|
+
throw bad2("specs", "specs must be a non-empty array");
|
|
1227
|
+
}
|
|
1228
|
+
const sortSpecs = specs.map((s) => {
|
|
1229
|
+
if (typeof _optionalChain([s, 'optionalAccess', _60 => _60.column]) !== "string" || !/^[A-Za-z]{1,3}$/.test(s.column)) {
|
|
1230
|
+
throw bad2("specs", "each spec needs a column letter");
|
|
1231
|
+
}
|
|
1232
|
+
return {
|
|
1233
|
+
dimensionIndex: _chunk4UEM6VO4cjs.a1.columnToIndex(s.column) - 1,
|
|
1234
|
+
sortOrder: s.ascending === false ? "DESCENDING" : "ASCENDING"
|
|
1235
|
+
};
|
|
1236
|
+
});
|
|
1237
|
+
return make([t], (ctx) => ({
|
|
1238
|
+
sortRange: { range: toGridRange(ctx.sheetId(t), r), sortSpecs }
|
|
1239
|
+
}));
|
|
1240
|
+
},
|
|
1241
|
+
setBasicFilter(tab, range) {
|
|
1242
|
+
const t = tabRef(tab);
|
|
1243
|
+
const r = rangeText(range);
|
|
1244
|
+
return make([t], (ctx) => ({
|
|
1245
|
+
setBasicFilter: { filter: { range: toGridRange(ctx.sheetId(t), r) } }
|
|
1246
|
+
}));
|
|
1247
|
+
},
|
|
1248
|
+
clearBasicFilter(tab) {
|
|
1249
|
+
const t = tabRef(tab);
|
|
1250
|
+
return make([t], (ctx) => ({
|
|
1251
|
+
clearBasicFilter: { sheetId: ctx.sheetId(t) }
|
|
1252
|
+
}));
|
|
1253
|
+
},
|
|
1254
|
+
/**
|
|
1255
|
+
* `name`: letters, digits and underscores, starting with a letter or `_`;
|
|
1256
|
+
* names that read as a cell (`A1`, `R1C1`) or `TRUE`/`FALSE` are rejected.
|
|
1257
|
+
*/
|
|
1258
|
+
addNamedRange(name, tab, range) {
|
|
1259
|
+
namedRangeName(name);
|
|
1260
|
+
const t = tabRef(tab);
|
|
1261
|
+
const r = rangeText(range);
|
|
1262
|
+
return make([t], (ctx) => ({
|
|
1263
|
+
addNamedRange: {
|
|
1264
|
+
namedRange: { name, range: toGridRange(ctx.sheetId(t), r) }
|
|
1265
|
+
}
|
|
1266
|
+
}));
|
|
1267
|
+
},
|
|
1268
|
+
/**
|
|
1269
|
+
* Takes the range's `namedRangeId` (from `getInfo().namedRanges`), not its
|
|
1270
|
+
* name: Google's `deleteNamedRange` deletes by id only.
|
|
1271
|
+
*/
|
|
1272
|
+
deleteNamedRange(namedRangeId) {
|
|
1273
|
+
const id = title(namedRangeId, "namedRangeId");
|
|
1274
|
+
return make([], () => ({ deleteNamedRange: { namedRangeId: id } }));
|
|
1275
|
+
},
|
|
1276
|
+
/** Without `range`, protects the whole tab. */
|
|
1277
|
+
protect(tab, o = {}) {
|
|
1278
|
+
const t = tabRef(tab);
|
|
1279
|
+
const r = o.range === void 0 ? null : rangeText(o.range);
|
|
1280
|
+
if (o.editors !== void 0) {
|
|
1281
|
+
if (!Array.isArray(o.editors) || o.editors.some((e) => typeof e !== "string" || e.length === 0)) {
|
|
1282
|
+
throw bad2("editors", "editors must be an array of emails");
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
return make([t], (ctx) => {
|
|
1286
|
+
const protectedRange = {
|
|
1287
|
+
range: toGridRange(ctx.sheetId(t), r)
|
|
1288
|
+
};
|
|
1289
|
+
if (o.description !== void 0)
|
|
1290
|
+
protectedRange.description = o.description;
|
|
1291
|
+
if (o.warningOnly !== void 0)
|
|
1292
|
+
protectedRange.warningOnly = o.warningOnly;
|
|
1293
|
+
if (o.editors !== void 0) {
|
|
1294
|
+
protectedRange.editors = { users: [...o.editors] };
|
|
1295
|
+
}
|
|
1296
|
+
return { addProtectedRange: { protectedRange } };
|
|
1297
|
+
});
|
|
1298
|
+
},
|
|
1299
|
+
unprotect(protectedRangeId) {
|
|
1300
|
+
const id = int(protectedRangeId, "protectedRangeId", 0);
|
|
1301
|
+
return make([], () => ({ deleteProtectedRange: { protectedRangeId: id } }));
|
|
1302
|
+
},
|
|
1303
|
+
/** Passes a Google request through untouched (one key, e.g. `addChart`). */
|
|
1304
|
+
raw(request) {
|
|
1305
|
+
if (typeof request !== "object" || request === null || Array.isArray(request) || Object.keys(request).length !== 1) {
|
|
1306
|
+
throw bad2("request", "request must be an object with exactly one key");
|
|
1307
|
+
}
|
|
1308
|
+
return make([], () => request);
|
|
1309
|
+
}
|
|
1310
|
+
};
|
|
1311
|
+
|
|
1312
|
+
|
|
1313
|
+
|
|
1314
|
+
|
|
1315
|
+
|
|
1316
|
+
exports.a1 = _chunk4UEM6VO4cjs.a1; exports.createSheets = createSheets; exports.createSheetsApiTransport = createSheetsApiTransport; exports.req = req;
|
|
1317
|
+
//# sourceMappingURL=sheets.cjs.map
|