google-spreadsheet 4.1.5 → 5.0.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/README.md +9 -0
- package/dist/index.cjs +4053 -1
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1652 -0
- package/dist/index.d.ts +635 -25
- package/dist/index.js +4047 -0
- package/dist/index.js.map +1 -0
- package/package.json +25 -42
- package/src/lib/GoogleSpreadsheet.ts +129 -123
- package/src/lib/GoogleSpreadsheetCell.ts +1 -1
- package/src/lib/GoogleSpreadsheetRow.ts +5 -6
- package/src/lib/GoogleSpreadsheetWorksheet.ts +54 -44
- package/src/lib/toolkit.ts +34 -0
- package/src/lib/types/auth-types.ts +1 -5
- package/src/lib/utils.ts +1 -20
- package/dist/index.mjs +0 -1
- package/src/lib/lodash.ts +0 -34
package/dist/index.js
ADDED
|
@@ -0,0 +1,4047 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// node_modules/.pnpm/ky@1.8.2/node_modules/ky/distribution/errors/HTTPError.js
|
|
5
|
+
var HTTPError = class extends Error {
|
|
6
|
+
static {
|
|
7
|
+
__name(this, "HTTPError");
|
|
8
|
+
}
|
|
9
|
+
response;
|
|
10
|
+
request;
|
|
11
|
+
options;
|
|
12
|
+
constructor(response, request, options) {
|
|
13
|
+
const code = response.status || response.status === 0 ? response.status : "";
|
|
14
|
+
const title = response.statusText || "";
|
|
15
|
+
const status = `${code} ${title}`.trim();
|
|
16
|
+
const reason = status ? `status code ${status}` : "an unknown error";
|
|
17
|
+
super(`Request failed with ${reason}: ${request.method} ${request.url}`);
|
|
18
|
+
this.name = "HTTPError";
|
|
19
|
+
this.response = response;
|
|
20
|
+
this.request = request;
|
|
21
|
+
this.options = options;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// node_modules/.pnpm/ky@1.8.2/node_modules/ky/distribution/errors/TimeoutError.js
|
|
26
|
+
var TimeoutError = class extends Error {
|
|
27
|
+
static {
|
|
28
|
+
__name(this, "TimeoutError");
|
|
29
|
+
}
|
|
30
|
+
request;
|
|
31
|
+
constructor(request) {
|
|
32
|
+
super(`Request timed out: ${request.method} ${request.url}`);
|
|
33
|
+
this.name = "TimeoutError";
|
|
34
|
+
this.request = request;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// node_modules/.pnpm/ky@1.8.2/node_modules/ky/distribution/core/constants.js
|
|
39
|
+
var supportsRequestStreams = (() => {
|
|
40
|
+
let duplexAccessed = false;
|
|
41
|
+
let hasContentType = false;
|
|
42
|
+
const supportsReadableStream = typeof globalThis.ReadableStream === "function";
|
|
43
|
+
const supportsRequest = typeof globalThis.Request === "function";
|
|
44
|
+
if (supportsReadableStream && supportsRequest) {
|
|
45
|
+
try {
|
|
46
|
+
hasContentType = new globalThis.Request("https://empty.invalid", {
|
|
47
|
+
body: new globalThis.ReadableStream(),
|
|
48
|
+
method: "POST",
|
|
49
|
+
// @ts-expect-error - Types are outdated.
|
|
50
|
+
get duplex() {
|
|
51
|
+
duplexAccessed = true;
|
|
52
|
+
return "half";
|
|
53
|
+
}
|
|
54
|
+
}).headers.has("Content-Type");
|
|
55
|
+
} catch (error) {
|
|
56
|
+
if (error instanceof Error && error.message === "unsupported BodyInit type") {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return duplexAccessed && !hasContentType;
|
|
63
|
+
})();
|
|
64
|
+
var supportsAbortController = typeof globalThis.AbortController === "function";
|
|
65
|
+
var supportsAbortSignal = typeof globalThis.AbortSignal === "function" && typeof globalThis.AbortSignal.any === "function";
|
|
66
|
+
var supportsResponseStreams = typeof globalThis.ReadableStream === "function";
|
|
67
|
+
var supportsFormData = typeof globalThis.FormData === "function";
|
|
68
|
+
var requestMethods = ["get", "post", "put", "patch", "head", "delete"];
|
|
69
|
+
var validate = /* @__PURE__ */ __name(() => void 0, "validate");
|
|
70
|
+
validate();
|
|
71
|
+
var responseTypes = {
|
|
72
|
+
json: "application/json",
|
|
73
|
+
text: "text/*",
|
|
74
|
+
formData: "multipart/form-data",
|
|
75
|
+
arrayBuffer: "*/*",
|
|
76
|
+
blob: "*/*"
|
|
77
|
+
};
|
|
78
|
+
var maxSafeTimeout = 2147483647;
|
|
79
|
+
var usualFormBoundarySize = new TextEncoder().encode("------WebKitFormBoundaryaxpyiPgbbPti10Rw").length;
|
|
80
|
+
var stop = Symbol("stop");
|
|
81
|
+
var kyOptionKeys = {
|
|
82
|
+
json: true,
|
|
83
|
+
parseJson: true,
|
|
84
|
+
stringifyJson: true,
|
|
85
|
+
searchParams: true,
|
|
86
|
+
prefixUrl: true,
|
|
87
|
+
retry: true,
|
|
88
|
+
timeout: true,
|
|
89
|
+
hooks: true,
|
|
90
|
+
throwHttpErrors: true,
|
|
91
|
+
onDownloadProgress: true,
|
|
92
|
+
onUploadProgress: true,
|
|
93
|
+
fetch: true
|
|
94
|
+
};
|
|
95
|
+
var requestOptionsRegistry = {
|
|
96
|
+
method: true,
|
|
97
|
+
headers: true,
|
|
98
|
+
body: true,
|
|
99
|
+
mode: true,
|
|
100
|
+
credentials: true,
|
|
101
|
+
cache: true,
|
|
102
|
+
redirect: true,
|
|
103
|
+
referrer: true,
|
|
104
|
+
referrerPolicy: true,
|
|
105
|
+
integrity: true,
|
|
106
|
+
keepalive: true,
|
|
107
|
+
signal: true,
|
|
108
|
+
window: true,
|
|
109
|
+
dispatcher: true,
|
|
110
|
+
duplex: true,
|
|
111
|
+
priority: true
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// node_modules/.pnpm/ky@1.8.2/node_modules/ky/distribution/utils/body.js
|
|
115
|
+
var getBodySize = /* @__PURE__ */ __name((body) => {
|
|
116
|
+
if (!body) {
|
|
117
|
+
return 0;
|
|
118
|
+
}
|
|
119
|
+
if (body instanceof FormData) {
|
|
120
|
+
let size = 0;
|
|
121
|
+
for (const [key, value] of body) {
|
|
122
|
+
size += usualFormBoundarySize;
|
|
123
|
+
size += new TextEncoder().encode(`Content-Disposition: form-data; name="${key}"`).length;
|
|
124
|
+
size += typeof value === "string" ? new TextEncoder().encode(value).length : value.size;
|
|
125
|
+
}
|
|
126
|
+
return size;
|
|
127
|
+
}
|
|
128
|
+
if (body instanceof Blob) {
|
|
129
|
+
return body.size;
|
|
130
|
+
}
|
|
131
|
+
if (body instanceof ArrayBuffer) {
|
|
132
|
+
return body.byteLength;
|
|
133
|
+
}
|
|
134
|
+
if (typeof body === "string") {
|
|
135
|
+
return new TextEncoder().encode(body).length;
|
|
136
|
+
}
|
|
137
|
+
if (body instanceof URLSearchParams) {
|
|
138
|
+
return new TextEncoder().encode(body.toString()).length;
|
|
139
|
+
}
|
|
140
|
+
if ("byteLength" in body) {
|
|
141
|
+
return body.byteLength;
|
|
142
|
+
}
|
|
143
|
+
if (typeof body === "object" && body !== null) {
|
|
144
|
+
try {
|
|
145
|
+
const jsonString = JSON.stringify(body);
|
|
146
|
+
return new TextEncoder().encode(jsonString).length;
|
|
147
|
+
} catch {
|
|
148
|
+
return 0;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return 0;
|
|
152
|
+
}, "getBodySize");
|
|
153
|
+
var streamResponse = /* @__PURE__ */ __name((response, onDownloadProgress) => {
|
|
154
|
+
const totalBytes = Number(response.headers.get("content-length")) || 0;
|
|
155
|
+
let transferredBytes = 0;
|
|
156
|
+
if (response.status === 204) {
|
|
157
|
+
if (onDownloadProgress) {
|
|
158
|
+
onDownloadProgress({ percent: 1, totalBytes, transferredBytes }, new Uint8Array());
|
|
159
|
+
}
|
|
160
|
+
return new Response(null, {
|
|
161
|
+
status: response.status,
|
|
162
|
+
statusText: response.statusText,
|
|
163
|
+
headers: response.headers
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
return new Response(new ReadableStream({
|
|
167
|
+
async start(controller) {
|
|
168
|
+
const reader = response.body.getReader();
|
|
169
|
+
if (onDownloadProgress) {
|
|
170
|
+
onDownloadProgress({ percent: 0, transferredBytes: 0, totalBytes }, new Uint8Array());
|
|
171
|
+
}
|
|
172
|
+
async function read() {
|
|
173
|
+
const { done, value } = await reader.read();
|
|
174
|
+
if (done) {
|
|
175
|
+
controller.close();
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
if (onDownloadProgress) {
|
|
179
|
+
transferredBytes += value.byteLength;
|
|
180
|
+
const percent = totalBytes === 0 ? 0 : transferredBytes / totalBytes;
|
|
181
|
+
onDownloadProgress({ percent, transferredBytes, totalBytes }, value);
|
|
182
|
+
}
|
|
183
|
+
controller.enqueue(value);
|
|
184
|
+
await read();
|
|
185
|
+
}
|
|
186
|
+
__name(read, "read");
|
|
187
|
+
await read();
|
|
188
|
+
}
|
|
189
|
+
}), {
|
|
190
|
+
status: response.status,
|
|
191
|
+
statusText: response.statusText,
|
|
192
|
+
headers: response.headers
|
|
193
|
+
});
|
|
194
|
+
}, "streamResponse");
|
|
195
|
+
var streamRequest = /* @__PURE__ */ __name((request, onUploadProgress) => {
|
|
196
|
+
const totalBytes = getBodySize(request.body);
|
|
197
|
+
let transferredBytes = 0;
|
|
198
|
+
return new Request(request, {
|
|
199
|
+
// @ts-expect-error - Types are outdated.
|
|
200
|
+
duplex: "half",
|
|
201
|
+
body: new ReadableStream({
|
|
202
|
+
async start(controller) {
|
|
203
|
+
const reader = request.body instanceof ReadableStream ? request.body.getReader() : new Response("").body.getReader();
|
|
204
|
+
async function read() {
|
|
205
|
+
const { done, value } = await reader.read();
|
|
206
|
+
if (done) {
|
|
207
|
+
if (onUploadProgress) {
|
|
208
|
+
onUploadProgress({ percent: 1, transferredBytes, totalBytes: Math.max(totalBytes, transferredBytes) }, new Uint8Array());
|
|
209
|
+
}
|
|
210
|
+
controller.close();
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
transferredBytes += value.byteLength;
|
|
214
|
+
let percent = totalBytes === 0 ? 0 : transferredBytes / totalBytes;
|
|
215
|
+
if (totalBytes < transferredBytes || percent === 1) {
|
|
216
|
+
percent = 0.99;
|
|
217
|
+
}
|
|
218
|
+
if (onUploadProgress) {
|
|
219
|
+
onUploadProgress({ percent: Number(percent.toFixed(2)), transferredBytes, totalBytes }, value);
|
|
220
|
+
}
|
|
221
|
+
controller.enqueue(value);
|
|
222
|
+
await read();
|
|
223
|
+
}
|
|
224
|
+
__name(read, "read");
|
|
225
|
+
await read();
|
|
226
|
+
}
|
|
227
|
+
})
|
|
228
|
+
});
|
|
229
|
+
}, "streamRequest");
|
|
230
|
+
|
|
231
|
+
// node_modules/.pnpm/ky@1.8.2/node_modules/ky/distribution/utils/is.js
|
|
232
|
+
var isObject = /* @__PURE__ */ __name((value) => value !== null && typeof value === "object", "isObject");
|
|
233
|
+
|
|
234
|
+
// node_modules/.pnpm/ky@1.8.2/node_modules/ky/distribution/utils/merge.js
|
|
235
|
+
var validateAndMerge = /* @__PURE__ */ __name((...sources) => {
|
|
236
|
+
for (const source of sources) {
|
|
237
|
+
if ((!isObject(source) || Array.isArray(source)) && source !== void 0) {
|
|
238
|
+
throw new TypeError("The `options` argument must be an object");
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return deepMerge({}, ...sources);
|
|
242
|
+
}, "validateAndMerge");
|
|
243
|
+
var mergeHeaders = /* @__PURE__ */ __name((source1 = {}, source2 = {}) => {
|
|
244
|
+
const result = new globalThis.Headers(source1);
|
|
245
|
+
const isHeadersInstance = source2 instanceof globalThis.Headers;
|
|
246
|
+
const source = new globalThis.Headers(source2);
|
|
247
|
+
for (const [key, value] of source.entries()) {
|
|
248
|
+
if (isHeadersInstance && value === "undefined" || value === void 0) {
|
|
249
|
+
result.delete(key);
|
|
250
|
+
} else {
|
|
251
|
+
result.set(key, value);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return result;
|
|
255
|
+
}, "mergeHeaders");
|
|
256
|
+
function newHookValue(original, incoming, property2) {
|
|
257
|
+
return Object.hasOwn(incoming, property2) && incoming[property2] === void 0 ? [] : deepMerge(original[property2] ?? [], incoming[property2] ?? []);
|
|
258
|
+
}
|
|
259
|
+
__name(newHookValue, "newHookValue");
|
|
260
|
+
var mergeHooks = /* @__PURE__ */ __name((original = {}, incoming = {}) => ({
|
|
261
|
+
beforeRequest: newHookValue(original, incoming, "beforeRequest"),
|
|
262
|
+
beforeRetry: newHookValue(original, incoming, "beforeRetry"),
|
|
263
|
+
afterResponse: newHookValue(original, incoming, "afterResponse"),
|
|
264
|
+
beforeError: newHookValue(original, incoming, "beforeError")
|
|
265
|
+
}), "mergeHooks");
|
|
266
|
+
var deepMerge = /* @__PURE__ */ __name((...sources) => {
|
|
267
|
+
let returnValue = {};
|
|
268
|
+
let headers = {};
|
|
269
|
+
let hooks = {};
|
|
270
|
+
for (const source of sources) {
|
|
271
|
+
if (Array.isArray(source)) {
|
|
272
|
+
if (!Array.isArray(returnValue)) {
|
|
273
|
+
returnValue = [];
|
|
274
|
+
}
|
|
275
|
+
returnValue = [...returnValue, ...source];
|
|
276
|
+
} else if (isObject(source)) {
|
|
277
|
+
for (let [key, value] of Object.entries(source)) {
|
|
278
|
+
if (isObject(value) && key in returnValue) {
|
|
279
|
+
value = deepMerge(returnValue[key], value);
|
|
280
|
+
}
|
|
281
|
+
returnValue = { ...returnValue, [key]: value };
|
|
282
|
+
}
|
|
283
|
+
if (isObject(source.hooks)) {
|
|
284
|
+
hooks = mergeHooks(hooks, source.hooks);
|
|
285
|
+
returnValue.hooks = hooks;
|
|
286
|
+
}
|
|
287
|
+
if (isObject(source.headers)) {
|
|
288
|
+
headers = mergeHeaders(headers, source.headers);
|
|
289
|
+
returnValue.headers = headers;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return returnValue;
|
|
294
|
+
}, "deepMerge");
|
|
295
|
+
|
|
296
|
+
// node_modules/.pnpm/ky@1.8.2/node_modules/ky/distribution/utils/normalize.js
|
|
297
|
+
var normalizeRequestMethod = /* @__PURE__ */ __name((input) => requestMethods.includes(input) ? input.toUpperCase() : input, "normalizeRequestMethod");
|
|
298
|
+
var retryMethods = ["get", "put", "head", "delete", "options", "trace"];
|
|
299
|
+
var retryStatusCodes = [408, 413, 429, 500, 502, 503, 504];
|
|
300
|
+
var retryAfterStatusCodes = [413, 429, 503];
|
|
301
|
+
var defaultRetryOptions = {
|
|
302
|
+
limit: 2,
|
|
303
|
+
methods: retryMethods,
|
|
304
|
+
statusCodes: retryStatusCodes,
|
|
305
|
+
afterStatusCodes: retryAfterStatusCodes,
|
|
306
|
+
maxRetryAfter: Number.POSITIVE_INFINITY,
|
|
307
|
+
backoffLimit: Number.POSITIVE_INFINITY,
|
|
308
|
+
delay: /* @__PURE__ */ __name((attemptCount) => 0.3 * 2 ** (attemptCount - 1) * 1e3, "delay")
|
|
309
|
+
};
|
|
310
|
+
var normalizeRetryOptions = /* @__PURE__ */ __name((retry = {}) => {
|
|
311
|
+
if (typeof retry === "number") {
|
|
312
|
+
return {
|
|
313
|
+
...defaultRetryOptions,
|
|
314
|
+
limit: retry
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
if (retry.methods && !Array.isArray(retry.methods)) {
|
|
318
|
+
throw new Error("retry.methods must be an array");
|
|
319
|
+
}
|
|
320
|
+
if (retry.statusCodes && !Array.isArray(retry.statusCodes)) {
|
|
321
|
+
throw new Error("retry.statusCodes must be an array");
|
|
322
|
+
}
|
|
323
|
+
return {
|
|
324
|
+
...defaultRetryOptions,
|
|
325
|
+
...retry
|
|
326
|
+
};
|
|
327
|
+
}, "normalizeRetryOptions");
|
|
328
|
+
|
|
329
|
+
// node_modules/.pnpm/ky@1.8.2/node_modules/ky/distribution/utils/timeout.js
|
|
330
|
+
async function timeout(request, init, abortController, options) {
|
|
331
|
+
return new Promise((resolve, reject) => {
|
|
332
|
+
const timeoutId = setTimeout(() => {
|
|
333
|
+
if (abortController) {
|
|
334
|
+
abortController.abort();
|
|
335
|
+
}
|
|
336
|
+
reject(new TimeoutError(request));
|
|
337
|
+
}, options.timeout);
|
|
338
|
+
void options.fetch(request, init).then(resolve).catch(reject).then(() => {
|
|
339
|
+
clearTimeout(timeoutId);
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
__name(timeout, "timeout");
|
|
344
|
+
|
|
345
|
+
// node_modules/.pnpm/ky@1.8.2/node_modules/ky/distribution/utils/delay.js
|
|
346
|
+
async function delay(ms, { signal }) {
|
|
347
|
+
return new Promise((resolve, reject) => {
|
|
348
|
+
if (signal) {
|
|
349
|
+
signal.throwIfAborted();
|
|
350
|
+
signal.addEventListener("abort", abortHandler, { once: true });
|
|
351
|
+
}
|
|
352
|
+
function abortHandler() {
|
|
353
|
+
clearTimeout(timeoutId);
|
|
354
|
+
reject(signal.reason);
|
|
355
|
+
}
|
|
356
|
+
__name(abortHandler, "abortHandler");
|
|
357
|
+
const timeoutId = setTimeout(() => {
|
|
358
|
+
signal?.removeEventListener("abort", abortHandler);
|
|
359
|
+
resolve();
|
|
360
|
+
}, ms);
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
__name(delay, "delay");
|
|
364
|
+
|
|
365
|
+
// node_modules/.pnpm/ky@1.8.2/node_modules/ky/distribution/utils/options.js
|
|
366
|
+
var findUnknownOptions = /* @__PURE__ */ __name((request, options) => {
|
|
367
|
+
const unknownOptions = {};
|
|
368
|
+
for (const key in options) {
|
|
369
|
+
if (!(key in requestOptionsRegistry) && !(key in kyOptionKeys) && !(key in request)) {
|
|
370
|
+
unknownOptions[key] = options[key];
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
return unknownOptions;
|
|
374
|
+
}, "findUnknownOptions");
|
|
375
|
+
|
|
376
|
+
// node_modules/.pnpm/ky@1.8.2/node_modules/ky/distribution/core/Ky.js
|
|
377
|
+
var Ky = class _Ky {
|
|
378
|
+
static {
|
|
379
|
+
__name(this, "Ky");
|
|
380
|
+
}
|
|
381
|
+
static create(input, options) {
|
|
382
|
+
const ky2 = new _Ky(input, options);
|
|
383
|
+
const function_ = /* @__PURE__ */ __name(async () => {
|
|
384
|
+
if (typeof ky2._options.timeout === "number" && ky2._options.timeout > maxSafeTimeout) {
|
|
385
|
+
throw new RangeError(`The \`timeout\` option cannot be greater than ${maxSafeTimeout}`);
|
|
386
|
+
}
|
|
387
|
+
await Promise.resolve();
|
|
388
|
+
let response = await ky2._fetch();
|
|
389
|
+
for (const hook of ky2._options.hooks.afterResponse) {
|
|
390
|
+
const modifiedResponse = await hook(ky2.request, ky2._options, ky2._decorateResponse(response.clone()));
|
|
391
|
+
if (modifiedResponse instanceof globalThis.Response) {
|
|
392
|
+
response = modifiedResponse;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
ky2._decorateResponse(response);
|
|
396
|
+
if (!response.ok && ky2._options.throwHttpErrors) {
|
|
397
|
+
let error = new HTTPError(response, ky2.request, ky2._options);
|
|
398
|
+
for (const hook of ky2._options.hooks.beforeError) {
|
|
399
|
+
error = await hook(error);
|
|
400
|
+
}
|
|
401
|
+
throw error;
|
|
402
|
+
}
|
|
403
|
+
if (ky2._options.onDownloadProgress) {
|
|
404
|
+
if (typeof ky2._options.onDownloadProgress !== "function") {
|
|
405
|
+
throw new TypeError("The `onDownloadProgress` option must be a function");
|
|
406
|
+
}
|
|
407
|
+
if (!supportsResponseStreams) {
|
|
408
|
+
throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
|
|
409
|
+
}
|
|
410
|
+
return streamResponse(response.clone(), ky2._options.onDownloadProgress);
|
|
411
|
+
}
|
|
412
|
+
return response;
|
|
413
|
+
}, "function_");
|
|
414
|
+
const isRetriableMethod = ky2._options.retry.methods.includes(ky2.request.method.toLowerCase());
|
|
415
|
+
const result = (isRetriableMethod ? ky2._retry(function_) : function_()).finally(async () => {
|
|
416
|
+
if (!ky2.request.bodyUsed) {
|
|
417
|
+
await ky2.request.body?.cancel();
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
for (const [type, mimeType] of Object.entries(responseTypes)) {
|
|
421
|
+
result[type] = async () => {
|
|
422
|
+
ky2.request.headers.set("accept", ky2.request.headers.get("accept") || mimeType);
|
|
423
|
+
const response = await result;
|
|
424
|
+
if (type === "json") {
|
|
425
|
+
if (response.status === 204) {
|
|
426
|
+
return "";
|
|
427
|
+
}
|
|
428
|
+
const arrayBuffer = await response.clone().arrayBuffer();
|
|
429
|
+
const responseSize = arrayBuffer.byteLength;
|
|
430
|
+
if (responseSize === 0) {
|
|
431
|
+
return "";
|
|
432
|
+
}
|
|
433
|
+
if (options.parseJson) {
|
|
434
|
+
return options.parseJson(await response.text());
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
return response[type]();
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
return result;
|
|
441
|
+
}
|
|
442
|
+
request;
|
|
443
|
+
abortController;
|
|
444
|
+
_retryCount = 0;
|
|
445
|
+
_input;
|
|
446
|
+
_options;
|
|
447
|
+
// eslint-disable-next-line complexity
|
|
448
|
+
constructor(input, options = {}) {
|
|
449
|
+
this._input = input;
|
|
450
|
+
this._options = {
|
|
451
|
+
...options,
|
|
452
|
+
headers: mergeHeaders(this._input.headers, options.headers),
|
|
453
|
+
hooks: mergeHooks({
|
|
454
|
+
beforeRequest: [],
|
|
455
|
+
beforeRetry: [],
|
|
456
|
+
beforeError: [],
|
|
457
|
+
afterResponse: []
|
|
458
|
+
}, options.hooks),
|
|
459
|
+
method: normalizeRequestMethod(options.method ?? this._input.method ?? "GET"),
|
|
460
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
461
|
+
prefixUrl: String(options.prefixUrl || ""),
|
|
462
|
+
retry: normalizeRetryOptions(options.retry),
|
|
463
|
+
throwHttpErrors: options.throwHttpErrors !== false,
|
|
464
|
+
timeout: options.timeout ?? 1e4,
|
|
465
|
+
fetch: options.fetch ?? globalThis.fetch.bind(globalThis)
|
|
466
|
+
};
|
|
467
|
+
if (typeof this._input !== "string" && !(this._input instanceof URL || this._input instanceof globalThis.Request)) {
|
|
468
|
+
throw new TypeError("`input` must be a string, URL, or Request");
|
|
469
|
+
}
|
|
470
|
+
if (this._options.prefixUrl && typeof this._input === "string") {
|
|
471
|
+
if (this._input.startsWith("/")) {
|
|
472
|
+
throw new Error("`input` must not begin with a slash when using `prefixUrl`");
|
|
473
|
+
}
|
|
474
|
+
if (!this._options.prefixUrl.endsWith("/")) {
|
|
475
|
+
this._options.prefixUrl += "/";
|
|
476
|
+
}
|
|
477
|
+
this._input = this._options.prefixUrl + this._input;
|
|
478
|
+
}
|
|
479
|
+
if (supportsAbortController && supportsAbortSignal) {
|
|
480
|
+
const originalSignal = this._options.signal ?? this._input.signal;
|
|
481
|
+
this.abortController = new globalThis.AbortController();
|
|
482
|
+
this._options.signal = originalSignal ? AbortSignal.any([originalSignal, this.abortController.signal]) : this.abortController.signal;
|
|
483
|
+
}
|
|
484
|
+
if (supportsRequestStreams) {
|
|
485
|
+
this._options.duplex = "half";
|
|
486
|
+
}
|
|
487
|
+
if (this._options.json !== void 0) {
|
|
488
|
+
this._options.body = this._options.stringifyJson?.(this._options.json) ?? JSON.stringify(this._options.json);
|
|
489
|
+
this._options.headers.set("content-type", this._options.headers.get("content-type") ?? "application/json");
|
|
490
|
+
}
|
|
491
|
+
this.request = new globalThis.Request(this._input, this._options);
|
|
492
|
+
if (this._options.searchParams) {
|
|
493
|
+
const textSearchParams = typeof this._options.searchParams === "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString();
|
|
494
|
+
const searchParams = "?" + textSearchParams;
|
|
495
|
+
const url = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, searchParams);
|
|
496
|
+
if ((supportsFormData && this._options.body instanceof globalThis.FormData || this._options.body instanceof URLSearchParams) && !(this._options.headers && this._options.headers["content-type"])) {
|
|
497
|
+
this.request.headers.delete("content-type");
|
|
498
|
+
}
|
|
499
|
+
this.request = new globalThis.Request(new globalThis.Request(url, { ...this.request }), this._options);
|
|
500
|
+
}
|
|
501
|
+
if (this._options.onUploadProgress) {
|
|
502
|
+
if (typeof this._options.onUploadProgress !== "function") {
|
|
503
|
+
throw new TypeError("The `onUploadProgress` option must be a function");
|
|
504
|
+
}
|
|
505
|
+
if (!supportsRequestStreams) {
|
|
506
|
+
throw new Error("Request streams are not supported in your environment. The `duplex` option for `Request` is not available.");
|
|
507
|
+
}
|
|
508
|
+
const originalBody = this.request.body;
|
|
509
|
+
if (originalBody) {
|
|
510
|
+
this.request = streamRequest(this.request, this._options.onUploadProgress);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
_calculateRetryDelay(error) {
|
|
515
|
+
this._retryCount++;
|
|
516
|
+
if (this._retryCount > this._options.retry.limit || error instanceof TimeoutError) {
|
|
517
|
+
throw error;
|
|
518
|
+
}
|
|
519
|
+
if (error instanceof HTTPError) {
|
|
520
|
+
if (!this._options.retry.statusCodes.includes(error.response.status)) {
|
|
521
|
+
throw error;
|
|
522
|
+
}
|
|
523
|
+
const retryAfter = error.response.headers.get("Retry-After") ?? error.response.headers.get("RateLimit-Reset") ?? error.response.headers.get("X-RateLimit-Reset") ?? error.response.headers.get("X-Rate-Limit-Reset");
|
|
524
|
+
if (retryAfter && this._options.retry.afterStatusCodes.includes(error.response.status)) {
|
|
525
|
+
let after = Number(retryAfter) * 1e3;
|
|
526
|
+
if (Number.isNaN(after)) {
|
|
527
|
+
after = Date.parse(retryAfter) - Date.now();
|
|
528
|
+
} else if (after >= Date.parse("2024-01-01")) {
|
|
529
|
+
after -= Date.now();
|
|
530
|
+
}
|
|
531
|
+
const max = this._options.retry.maxRetryAfter ?? after;
|
|
532
|
+
return after < max ? after : max;
|
|
533
|
+
}
|
|
534
|
+
if (error.response.status === 413) {
|
|
535
|
+
throw error;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
const retryDelay = this._options.retry.delay(this._retryCount);
|
|
539
|
+
return Math.min(this._options.retry.backoffLimit, retryDelay);
|
|
540
|
+
}
|
|
541
|
+
_decorateResponse(response) {
|
|
542
|
+
if (this._options.parseJson) {
|
|
543
|
+
response.json = async () => this._options.parseJson(await response.text());
|
|
544
|
+
}
|
|
545
|
+
return response;
|
|
546
|
+
}
|
|
547
|
+
async _retry(function_) {
|
|
548
|
+
try {
|
|
549
|
+
return await function_();
|
|
550
|
+
} catch (error) {
|
|
551
|
+
const ms = Math.min(this._calculateRetryDelay(error), maxSafeTimeout);
|
|
552
|
+
if (this._retryCount < 1) {
|
|
553
|
+
throw error;
|
|
554
|
+
}
|
|
555
|
+
await delay(ms, { signal: this._options.signal });
|
|
556
|
+
for (const hook of this._options.hooks.beforeRetry) {
|
|
557
|
+
const hookResult = await hook({
|
|
558
|
+
request: this.request,
|
|
559
|
+
options: this._options,
|
|
560
|
+
error,
|
|
561
|
+
retryCount: this._retryCount
|
|
562
|
+
});
|
|
563
|
+
if (hookResult === stop) {
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
return this._retry(function_);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
async _fetch() {
|
|
571
|
+
for (const hook of this._options.hooks.beforeRequest) {
|
|
572
|
+
const result = await hook(this.request, this._options);
|
|
573
|
+
if (result instanceof Request) {
|
|
574
|
+
this.request = result;
|
|
575
|
+
break;
|
|
576
|
+
}
|
|
577
|
+
if (result instanceof Response) {
|
|
578
|
+
return result;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
const nonRequestOptions = findUnknownOptions(this.request, this._options);
|
|
582
|
+
const mainRequest = this.request;
|
|
583
|
+
this.request = mainRequest.clone();
|
|
584
|
+
if (this._options.timeout === false) {
|
|
585
|
+
return this._options.fetch(mainRequest, nonRequestOptions);
|
|
586
|
+
}
|
|
587
|
+
return timeout(mainRequest, nonRequestOptions, this.abortController, this._options);
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
|
|
591
|
+
// node_modules/.pnpm/ky@1.8.2/node_modules/ky/distribution/index.js
|
|
592
|
+
var createInstance = /* @__PURE__ */ __name((defaults) => {
|
|
593
|
+
const ky2 = /* @__PURE__ */ __name((input, options) => Ky.create(input, validateAndMerge(defaults, options)), "ky");
|
|
594
|
+
for (const method of requestMethods) {
|
|
595
|
+
ky2[method] = (input, options) => Ky.create(input, validateAndMerge(defaults, options, { method }));
|
|
596
|
+
}
|
|
597
|
+
ky2.create = (newDefaults) => createInstance(validateAndMerge(newDefaults));
|
|
598
|
+
ky2.extend = (newDefaults) => {
|
|
599
|
+
if (typeof newDefaults === "function") {
|
|
600
|
+
newDefaults = newDefaults(defaults ?? {});
|
|
601
|
+
}
|
|
602
|
+
return createInstance(validateAndMerge(defaults, newDefaults));
|
|
603
|
+
};
|
|
604
|
+
ky2.stop = stop;
|
|
605
|
+
return ky2;
|
|
606
|
+
}, "createInstance");
|
|
607
|
+
var ky = createInstance();
|
|
608
|
+
var distribution_default = ky;
|
|
609
|
+
|
|
610
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/predicate/isLength.mjs
|
|
611
|
+
function isLength(value) {
|
|
612
|
+
return Number.isSafeInteger(value) && value >= 0;
|
|
613
|
+
}
|
|
614
|
+
__name(isLength, "isLength");
|
|
615
|
+
|
|
616
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/predicate/isArrayLike.mjs
|
|
617
|
+
function isArrayLike(value) {
|
|
618
|
+
return value != null && typeof value !== "function" && isLength(value.length);
|
|
619
|
+
}
|
|
620
|
+
__name(isArrayLike, "isArrayLike");
|
|
621
|
+
|
|
622
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/array/compact.mjs
|
|
623
|
+
function compact(arr) {
|
|
624
|
+
const result = [];
|
|
625
|
+
for (let i = 0; i < arr.length; i++) {
|
|
626
|
+
const item = arr[i];
|
|
627
|
+
if (item) {
|
|
628
|
+
result.push(item);
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
return result;
|
|
632
|
+
}
|
|
633
|
+
__name(compact, "compact");
|
|
634
|
+
|
|
635
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/array/compact.mjs
|
|
636
|
+
function compact2(arr) {
|
|
637
|
+
if (!isArrayLike(arr)) {
|
|
638
|
+
return [];
|
|
639
|
+
}
|
|
640
|
+
return compact(Array.from(arr));
|
|
641
|
+
}
|
|
642
|
+
__name(compact2, "compact");
|
|
643
|
+
|
|
644
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/array/flatten.mjs
|
|
645
|
+
function flatten(arr, depth = 1) {
|
|
646
|
+
const result = [];
|
|
647
|
+
const flooredDepth = Math.floor(depth);
|
|
648
|
+
const recursive = /* @__PURE__ */ __name((arr2, currentDepth) => {
|
|
649
|
+
for (let i = 0; i < arr2.length; i++) {
|
|
650
|
+
const item = arr2[i];
|
|
651
|
+
if (Array.isArray(item) && currentDepth < flooredDepth) {
|
|
652
|
+
recursive(item, currentDepth + 1);
|
|
653
|
+
} else {
|
|
654
|
+
result.push(item);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
}, "recursive");
|
|
658
|
+
recursive(arr, 0);
|
|
659
|
+
return result;
|
|
660
|
+
}
|
|
661
|
+
__name(flatten, "flatten");
|
|
662
|
+
|
|
663
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/function/identity.mjs
|
|
664
|
+
function identity(x) {
|
|
665
|
+
return x;
|
|
666
|
+
}
|
|
667
|
+
__name(identity, "identity");
|
|
668
|
+
|
|
669
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/_internal/isUnsafeProperty.mjs
|
|
670
|
+
function isUnsafeProperty(key) {
|
|
671
|
+
return key === "__proto__";
|
|
672
|
+
}
|
|
673
|
+
__name(isUnsafeProperty, "isUnsafeProperty");
|
|
674
|
+
|
|
675
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/_internal/isDeepKey.mjs
|
|
676
|
+
function isDeepKey(key) {
|
|
677
|
+
switch (typeof key) {
|
|
678
|
+
case "number":
|
|
679
|
+
case "symbol": {
|
|
680
|
+
return false;
|
|
681
|
+
}
|
|
682
|
+
case "string": {
|
|
683
|
+
return key.includes(".") || key.includes("[") || key.includes("]");
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
__name(isDeepKey, "isDeepKey");
|
|
688
|
+
|
|
689
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/_internal/toKey.mjs
|
|
690
|
+
function toKey(value) {
|
|
691
|
+
if (typeof value === "string" || typeof value === "symbol") {
|
|
692
|
+
return value;
|
|
693
|
+
}
|
|
694
|
+
if (Object.is(value?.valueOf?.(), -0)) {
|
|
695
|
+
return "-0";
|
|
696
|
+
}
|
|
697
|
+
return String(value);
|
|
698
|
+
}
|
|
699
|
+
__name(toKey, "toKey");
|
|
700
|
+
|
|
701
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/util/toPath.mjs
|
|
702
|
+
function toPath(deepKey) {
|
|
703
|
+
const result = [];
|
|
704
|
+
const length = deepKey.length;
|
|
705
|
+
if (length === 0) {
|
|
706
|
+
return result;
|
|
707
|
+
}
|
|
708
|
+
let index = 0;
|
|
709
|
+
let key = "";
|
|
710
|
+
let quoteChar = "";
|
|
711
|
+
let bracket = false;
|
|
712
|
+
if (deepKey.charCodeAt(0) === 46) {
|
|
713
|
+
result.push("");
|
|
714
|
+
index++;
|
|
715
|
+
}
|
|
716
|
+
while (index < length) {
|
|
717
|
+
const char = deepKey[index];
|
|
718
|
+
if (quoteChar) {
|
|
719
|
+
if (char === "\\" && index + 1 < length) {
|
|
720
|
+
index++;
|
|
721
|
+
key += deepKey[index];
|
|
722
|
+
} else if (char === quoteChar) {
|
|
723
|
+
quoteChar = "";
|
|
724
|
+
} else {
|
|
725
|
+
key += char;
|
|
726
|
+
}
|
|
727
|
+
} else if (bracket) {
|
|
728
|
+
if (char === '"' || char === "'") {
|
|
729
|
+
quoteChar = char;
|
|
730
|
+
} else if (char === "]") {
|
|
731
|
+
bracket = false;
|
|
732
|
+
result.push(key);
|
|
733
|
+
key = "";
|
|
734
|
+
} else {
|
|
735
|
+
key += char;
|
|
736
|
+
}
|
|
737
|
+
} else {
|
|
738
|
+
if (char === "[") {
|
|
739
|
+
bracket = true;
|
|
740
|
+
if (key) {
|
|
741
|
+
result.push(key);
|
|
742
|
+
key = "";
|
|
743
|
+
}
|
|
744
|
+
} else if (char === ".") {
|
|
745
|
+
if (key) {
|
|
746
|
+
result.push(key);
|
|
747
|
+
key = "";
|
|
748
|
+
}
|
|
749
|
+
} else {
|
|
750
|
+
key += char;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
index++;
|
|
754
|
+
}
|
|
755
|
+
if (key) {
|
|
756
|
+
result.push(key);
|
|
757
|
+
}
|
|
758
|
+
return result;
|
|
759
|
+
}
|
|
760
|
+
__name(toPath, "toPath");
|
|
761
|
+
|
|
762
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/object/get.mjs
|
|
763
|
+
function get(object, path, defaultValue) {
|
|
764
|
+
if (object == null) {
|
|
765
|
+
return defaultValue;
|
|
766
|
+
}
|
|
767
|
+
switch (typeof path) {
|
|
768
|
+
case "string": {
|
|
769
|
+
if (isUnsafeProperty(path)) {
|
|
770
|
+
return defaultValue;
|
|
771
|
+
}
|
|
772
|
+
const result = object[path];
|
|
773
|
+
if (result === void 0) {
|
|
774
|
+
if (isDeepKey(path)) {
|
|
775
|
+
return get(object, toPath(path), defaultValue);
|
|
776
|
+
} else {
|
|
777
|
+
return defaultValue;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
return result;
|
|
781
|
+
}
|
|
782
|
+
case "number":
|
|
783
|
+
case "symbol": {
|
|
784
|
+
if (typeof path === "number") {
|
|
785
|
+
path = toKey(path);
|
|
786
|
+
}
|
|
787
|
+
const result = object[path];
|
|
788
|
+
if (result === void 0) {
|
|
789
|
+
return defaultValue;
|
|
790
|
+
}
|
|
791
|
+
return result;
|
|
792
|
+
}
|
|
793
|
+
default: {
|
|
794
|
+
if (Array.isArray(path)) {
|
|
795
|
+
return getWithPath(object, path, defaultValue);
|
|
796
|
+
}
|
|
797
|
+
if (Object.is(path?.valueOf(), -0)) {
|
|
798
|
+
path = "-0";
|
|
799
|
+
} else {
|
|
800
|
+
path = String(path);
|
|
801
|
+
}
|
|
802
|
+
if (isUnsafeProperty(path)) {
|
|
803
|
+
return defaultValue;
|
|
804
|
+
}
|
|
805
|
+
const result = object[path];
|
|
806
|
+
if (result === void 0) {
|
|
807
|
+
return defaultValue;
|
|
808
|
+
}
|
|
809
|
+
return result;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
__name(get, "get");
|
|
814
|
+
function getWithPath(object, path, defaultValue) {
|
|
815
|
+
if (path.length === 0) {
|
|
816
|
+
return defaultValue;
|
|
817
|
+
}
|
|
818
|
+
let current = object;
|
|
819
|
+
for (let index = 0; index < path.length; index++) {
|
|
820
|
+
if (current == null) {
|
|
821
|
+
return defaultValue;
|
|
822
|
+
}
|
|
823
|
+
if (isUnsafeProperty(path[index])) {
|
|
824
|
+
return defaultValue;
|
|
825
|
+
}
|
|
826
|
+
current = current[path[index]];
|
|
827
|
+
}
|
|
828
|
+
if (current === void 0) {
|
|
829
|
+
return defaultValue;
|
|
830
|
+
}
|
|
831
|
+
return current;
|
|
832
|
+
}
|
|
833
|
+
__name(getWithPath, "getWithPath");
|
|
834
|
+
|
|
835
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/object/property.mjs
|
|
836
|
+
function property(path) {
|
|
837
|
+
return function(object) {
|
|
838
|
+
return get(object, path);
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
__name(property, "property");
|
|
842
|
+
|
|
843
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/predicate/isObject.mjs
|
|
844
|
+
function isObject2(value) {
|
|
845
|
+
return value !== null && (typeof value === "object" || typeof value === "function");
|
|
846
|
+
}
|
|
847
|
+
__name(isObject2, "isObject");
|
|
848
|
+
|
|
849
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/predicate/isPrimitive.mjs
|
|
850
|
+
function isPrimitive(value) {
|
|
851
|
+
return value == null || typeof value !== "object" && typeof value !== "function";
|
|
852
|
+
}
|
|
853
|
+
__name(isPrimitive, "isPrimitive");
|
|
854
|
+
|
|
855
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/util/eq.mjs
|
|
856
|
+
function eq(value, other) {
|
|
857
|
+
return value === other || Number.isNaN(value) && Number.isNaN(other);
|
|
858
|
+
}
|
|
859
|
+
__name(eq, "eq");
|
|
860
|
+
|
|
861
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/predicate/isMatchWith.mjs
|
|
862
|
+
function isMatchWith(target, source, compare) {
|
|
863
|
+
if (typeof compare !== "function") {
|
|
864
|
+
return isMatch(target, source);
|
|
865
|
+
}
|
|
866
|
+
return isMatchWithInternal(target, source, /* @__PURE__ */ __name(function doesMatch(objValue, srcValue, key, object, source2, stack) {
|
|
867
|
+
const isEqual2 = compare(objValue, srcValue, key, object, source2, stack);
|
|
868
|
+
if (isEqual2 !== void 0) {
|
|
869
|
+
return Boolean(isEqual2);
|
|
870
|
+
}
|
|
871
|
+
return isMatchWithInternal(objValue, srcValue, doesMatch, stack);
|
|
872
|
+
}, "doesMatch"), /* @__PURE__ */ new Map());
|
|
873
|
+
}
|
|
874
|
+
__name(isMatchWith, "isMatchWith");
|
|
875
|
+
function isMatchWithInternal(target, source, compare, stack) {
|
|
876
|
+
if (source === target) {
|
|
877
|
+
return true;
|
|
878
|
+
}
|
|
879
|
+
switch (typeof source) {
|
|
880
|
+
case "object": {
|
|
881
|
+
return isObjectMatch(target, source, compare, stack);
|
|
882
|
+
}
|
|
883
|
+
case "function": {
|
|
884
|
+
const sourceKeys = Object.keys(source);
|
|
885
|
+
if (sourceKeys.length > 0) {
|
|
886
|
+
return isMatchWithInternal(target, { ...source }, compare, stack);
|
|
887
|
+
}
|
|
888
|
+
return eq(target, source);
|
|
889
|
+
}
|
|
890
|
+
default: {
|
|
891
|
+
if (!isObject2(target)) {
|
|
892
|
+
return eq(target, source);
|
|
893
|
+
}
|
|
894
|
+
if (typeof source === "string") {
|
|
895
|
+
return source === "";
|
|
896
|
+
}
|
|
897
|
+
return true;
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
__name(isMatchWithInternal, "isMatchWithInternal");
|
|
902
|
+
function isObjectMatch(target, source, compare, stack) {
|
|
903
|
+
if (source == null) {
|
|
904
|
+
return true;
|
|
905
|
+
}
|
|
906
|
+
if (Array.isArray(source)) {
|
|
907
|
+
return isArrayMatch(target, source, compare, stack);
|
|
908
|
+
}
|
|
909
|
+
if (source instanceof Map) {
|
|
910
|
+
return isMapMatch(target, source, compare, stack);
|
|
911
|
+
}
|
|
912
|
+
if (source instanceof Set) {
|
|
913
|
+
return isSetMatch(target, source, compare, stack);
|
|
914
|
+
}
|
|
915
|
+
const keys2 = Object.keys(source);
|
|
916
|
+
if (target == null) {
|
|
917
|
+
return keys2.length === 0;
|
|
918
|
+
}
|
|
919
|
+
if (keys2.length === 0) {
|
|
920
|
+
return true;
|
|
921
|
+
}
|
|
922
|
+
if (stack && stack.has(source)) {
|
|
923
|
+
return stack.get(source) === target;
|
|
924
|
+
}
|
|
925
|
+
if (stack) {
|
|
926
|
+
stack.set(source, target);
|
|
927
|
+
}
|
|
928
|
+
try {
|
|
929
|
+
for (let i = 0; i < keys2.length; i++) {
|
|
930
|
+
const key = keys2[i];
|
|
931
|
+
if (!isPrimitive(target) && !(key in target)) {
|
|
932
|
+
return false;
|
|
933
|
+
}
|
|
934
|
+
if (source[key] === void 0 && target[key] !== void 0) {
|
|
935
|
+
return false;
|
|
936
|
+
}
|
|
937
|
+
if (source[key] === null && target[key] !== null) {
|
|
938
|
+
return false;
|
|
939
|
+
}
|
|
940
|
+
const isEqual2 = compare(target[key], source[key], key, target, source, stack);
|
|
941
|
+
if (!isEqual2) {
|
|
942
|
+
return false;
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
return true;
|
|
946
|
+
} finally {
|
|
947
|
+
if (stack) {
|
|
948
|
+
stack.delete(source);
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
__name(isObjectMatch, "isObjectMatch");
|
|
953
|
+
function isMapMatch(target, source, compare, stack) {
|
|
954
|
+
if (source.size === 0) {
|
|
955
|
+
return true;
|
|
956
|
+
}
|
|
957
|
+
if (!(target instanceof Map)) {
|
|
958
|
+
return false;
|
|
959
|
+
}
|
|
960
|
+
for (const [key, sourceValue] of source.entries()) {
|
|
961
|
+
const targetValue = target.get(key);
|
|
962
|
+
const isEqual2 = compare(targetValue, sourceValue, key, target, source, stack);
|
|
963
|
+
if (isEqual2 === false) {
|
|
964
|
+
return false;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
return true;
|
|
968
|
+
}
|
|
969
|
+
__name(isMapMatch, "isMapMatch");
|
|
970
|
+
function isArrayMatch(target, source, compare, stack) {
|
|
971
|
+
if (source.length === 0) {
|
|
972
|
+
return true;
|
|
973
|
+
}
|
|
974
|
+
if (!Array.isArray(target)) {
|
|
975
|
+
return false;
|
|
976
|
+
}
|
|
977
|
+
const countedIndex = /* @__PURE__ */ new Set();
|
|
978
|
+
for (let i = 0; i < source.length; i++) {
|
|
979
|
+
const sourceItem = source[i];
|
|
980
|
+
let found = false;
|
|
981
|
+
for (let j = 0; j < target.length; j++) {
|
|
982
|
+
if (countedIndex.has(j)) {
|
|
983
|
+
continue;
|
|
984
|
+
}
|
|
985
|
+
const targetItem = target[j];
|
|
986
|
+
let matches2 = false;
|
|
987
|
+
const isEqual2 = compare(targetItem, sourceItem, i, target, source, stack);
|
|
988
|
+
if (isEqual2) {
|
|
989
|
+
matches2 = true;
|
|
990
|
+
}
|
|
991
|
+
if (matches2) {
|
|
992
|
+
countedIndex.add(j);
|
|
993
|
+
found = true;
|
|
994
|
+
break;
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
if (!found) {
|
|
998
|
+
return false;
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
return true;
|
|
1002
|
+
}
|
|
1003
|
+
__name(isArrayMatch, "isArrayMatch");
|
|
1004
|
+
function isSetMatch(target, source, compare, stack) {
|
|
1005
|
+
if (source.size === 0) {
|
|
1006
|
+
return true;
|
|
1007
|
+
}
|
|
1008
|
+
if (!(target instanceof Set)) {
|
|
1009
|
+
return false;
|
|
1010
|
+
}
|
|
1011
|
+
return isArrayMatch([...target], [...source], compare, stack);
|
|
1012
|
+
}
|
|
1013
|
+
__name(isSetMatch, "isSetMatch");
|
|
1014
|
+
|
|
1015
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/predicate/isMatch.mjs
|
|
1016
|
+
function isMatch(target, source) {
|
|
1017
|
+
return isMatchWith(target, source, () => void 0);
|
|
1018
|
+
}
|
|
1019
|
+
__name(isMatch, "isMatch");
|
|
1020
|
+
|
|
1021
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/_internal/getSymbols.mjs
|
|
1022
|
+
function getSymbols(object) {
|
|
1023
|
+
return Object.getOwnPropertySymbols(object).filter((symbol) => Object.prototype.propertyIsEnumerable.call(object, symbol));
|
|
1024
|
+
}
|
|
1025
|
+
__name(getSymbols, "getSymbols");
|
|
1026
|
+
|
|
1027
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/_internal/getTag.mjs
|
|
1028
|
+
function getTag(value) {
|
|
1029
|
+
if (value == null) {
|
|
1030
|
+
return value === void 0 ? "[object Undefined]" : "[object Null]";
|
|
1031
|
+
}
|
|
1032
|
+
return Object.prototype.toString.call(value);
|
|
1033
|
+
}
|
|
1034
|
+
__name(getTag, "getTag");
|
|
1035
|
+
|
|
1036
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/_internal/tags.mjs
|
|
1037
|
+
var regexpTag = "[object RegExp]";
|
|
1038
|
+
var stringTag = "[object String]";
|
|
1039
|
+
var numberTag = "[object Number]";
|
|
1040
|
+
var booleanTag = "[object Boolean]";
|
|
1041
|
+
var argumentsTag = "[object Arguments]";
|
|
1042
|
+
var symbolTag = "[object Symbol]";
|
|
1043
|
+
var dateTag = "[object Date]";
|
|
1044
|
+
var mapTag = "[object Map]";
|
|
1045
|
+
var setTag = "[object Set]";
|
|
1046
|
+
var arrayTag = "[object Array]";
|
|
1047
|
+
var functionTag = "[object Function]";
|
|
1048
|
+
var arrayBufferTag = "[object ArrayBuffer]";
|
|
1049
|
+
var objectTag = "[object Object]";
|
|
1050
|
+
var errorTag = "[object Error]";
|
|
1051
|
+
var dataViewTag = "[object DataView]";
|
|
1052
|
+
var uint8ArrayTag = "[object Uint8Array]";
|
|
1053
|
+
var uint8ClampedArrayTag = "[object Uint8ClampedArray]";
|
|
1054
|
+
var uint16ArrayTag = "[object Uint16Array]";
|
|
1055
|
+
var uint32ArrayTag = "[object Uint32Array]";
|
|
1056
|
+
var bigUint64ArrayTag = "[object BigUint64Array]";
|
|
1057
|
+
var int8ArrayTag = "[object Int8Array]";
|
|
1058
|
+
var int16ArrayTag = "[object Int16Array]";
|
|
1059
|
+
var int32ArrayTag = "[object Int32Array]";
|
|
1060
|
+
var bigInt64ArrayTag = "[object BigInt64Array]";
|
|
1061
|
+
var float32ArrayTag = "[object Float32Array]";
|
|
1062
|
+
var float64ArrayTag = "[object Float64Array]";
|
|
1063
|
+
|
|
1064
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/predicate/isTypedArray.mjs
|
|
1065
|
+
function isTypedArray(x) {
|
|
1066
|
+
return ArrayBuffer.isView(x) && !(x instanceof DataView);
|
|
1067
|
+
}
|
|
1068
|
+
__name(isTypedArray, "isTypedArray");
|
|
1069
|
+
|
|
1070
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/object/cloneDeepWith.mjs
|
|
1071
|
+
function cloneDeepWith(obj, cloneValue) {
|
|
1072
|
+
return cloneDeepWithImpl(obj, void 0, obj, /* @__PURE__ */ new Map(), cloneValue);
|
|
1073
|
+
}
|
|
1074
|
+
__name(cloneDeepWith, "cloneDeepWith");
|
|
1075
|
+
function cloneDeepWithImpl(valueToClone, keyToClone, objectToClone, stack = /* @__PURE__ */ new Map(), cloneValue = void 0) {
|
|
1076
|
+
const cloned = cloneValue?.(valueToClone, keyToClone, objectToClone, stack);
|
|
1077
|
+
if (cloned != null) {
|
|
1078
|
+
return cloned;
|
|
1079
|
+
}
|
|
1080
|
+
if (isPrimitive(valueToClone)) {
|
|
1081
|
+
return valueToClone;
|
|
1082
|
+
}
|
|
1083
|
+
if (stack.has(valueToClone)) {
|
|
1084
|
+
return stack.get(valueToClone);
|
|
1085
|
+
}
|
|
1086
|
+
if (Array.isArray(valueToClone)) {
|
|
1087
|
+
const result = new Array(valueToClone.length);
|
|
1088
|
+
stack.set(valueToClone, result);
|
|
1089
|
+
for (let i = 0; i < valueToClone.length; i++) {
|
|
1090
|
+
result[i] = cloneDeepWithImpl(valueToClone[i], i, objectToClone, stack, cloneValue);
|
|
1091
|
+
}
|
|
1092
|
+
if (Object.hasOwn(valueToClone, "index")) {
|
|
1093
|
+
result.index = valueToClone.index;
|
|
1094
|
+
}
|
|
1095
|
+
if (Object.hasOwn(valueToClone, "input")) {
|
|
1096
|
+
result.input = valueToClone.input;
|
|
1097
|
+
}
|
|
1098
|
+
return result;
|
|
1099
|
+
}
|
|
1100
|
+
if (valueToClone instanceof Date) {
|
|
1101
|
+
return new Date(valueToClone.getTime());
|
|
1102
|
+
}
|
|
1103
|
+
if (valueToClone instanceof RegExp) {
|
|
1104
|
+
const result = new RegExp(valueToClone.source, valueToClone.flags);
|
|
1105
|
+
result.lastIndex = valueToClone.lastIndex;
|
|
1106
|
+
return result;
|
|
1107
|
+
}
|
|
1108
|
+
if (valueToClone instanceof Map) {
|
|
1109
|
+
const result = /* @__PURE__ */ new Map();
|
|
1110
|
+
stack.set(valueToClone, result);
|
|
1111
|
+
for (const [key, value] of valueToClone) {
|
|
1112
|
+
result.set(key, cloneDeepWithImpl(value, key, objectToClone, stack, cloneValue));
|
|
1113
|
+
}
|
|
1114
|
+
return result;
|
|
1115
|
+
}
|
|
1116
|
+
if (valueToClone instanceof Set) {
|
|
1117
|
+
const result = /* @__PURE__ */ new Set();
|
|
1118
|
+
stack.set(valueToClone, result);
|
|
1119
|
+
for (const value of valueToClone) {
|
|
1120
|
+
result.add(cloneDeepWithImpl(value, void 0, objectToClone, stack, cloneValue));
|
|
1121
|
+
}
|
|
1122
|
+
return result;
|
|
1123
|
+
}
|
|
1124
|
+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(valueToClone)) {
|
|
1125
|
+
return valueToClone.subarray();
|
|
1126
|
+
}
|
|
1127
|
+
if (isTypedArray(valueToClone)) {
|
|
1128
|
+
const result = new (Object.getPrototypeOf(valueToClone)).constructor(valueToClone.length);
|
|
1129
|
+
stack.set(valueToClone, result);
|
|
1130
|
+
for (let i = 0; i < valueToClone.length; i++) {
|
|
1131
|
+
result[i] = cloneDeepWithImpl(valueToClone[i], i, objectToClone, stack, cloneValue);
|
|
1132
|
+
}
|
|
1133
|
+
return result;
|
|
1134
|
+
}
|
|
1135
|
+
if (valueToClone instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && valueToClone instanceof SharedArrayBuffer) {
|
|
1136
|
+
return valueToClone.slice(0);
|
|
1137
|
+
}
|
|
1138
|
+
if (valueToClone instanceof DataView) {
|
|
1139
|
+
const result = new DataView(valueToClone.buffer.slice(0), valueToClone.byteOffset, valueToClone.byteLength);
|
|
1140
|
+
stack.set(valueToClone, result);
|
|
1141
|
+
copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
|
|
1142
|
+
return result;
|
|
1143
|
+
}
|
|
1144
|
+
if (typeof File !== "undefined" && valueToClone instanceof File) {
|
|
1145
|
+
const result = new File([valueToClone], valueToClone.name, {
|
|
1146
|
+
type: valueToClone.type
|
|
1147
|
+
});
|
|
1148
|
+
stack.set(valueToClone, result);
|
|
1149
|
+
copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
|
|
1150
|
+
return result;
|
|
1151
|
+
}
|
|
1152
|
+
if (valueToClone instanceof Blob) {
|
|
1153
|
+
const result = new Blob([valueToClone], { type: valueToClone.type });
|
|
1154
|
+
stack.set(valueToClone, result);
|
|
1155
|
+
copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
|
|
1156
|
+
return result;
|
|
1157
|
+
}
|
|
1158
|
+
if (valueToClone instanceof Error) {
|
|
1159
|
+
const result = new valueToClone.constructor();
|
|
1160
|
+
stack.set(valueToClone, result);
|
|
1161
|
+
result.message = valueToClone.message;
|
|
1162
|
+
result.name = valueToClone.name;
|
|
1163
|
+
result.stack = valueToClone.stack;
|
|
1164
|
+
result.cause = valueToClone.cause;
|
|
1165
|
+
copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
|
|
1166
|
+
return result;
|
|
1167
|
+
}
|
|
1168
|
+
if (typeof valueToClone === "object" && isCloneableObject(valueToClone)) {
|
|
1169
|
+
const result = Object.create(Object.getPrototypeOf(valueToClone));
|
|
1170
|
+
stack.set(valueToClone, result);
|
|
1171
|
+
copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
|
|
1172
|
+
return result;
|
|
1173
|
+
}
|
|
1174
|
+
return valueToClone;
|
|
1175
|
+
}
|
|
1176
|
+
__name(cloneDeepWithImpl, "cloneDeepWithImpl");
|
|
1177
|
+
function copyProperties(target, source, objectToClone = target, stack, cloneValue) {
|
|
1178
|
+
const keys2 = [...Object.keys(source), ...getSymbols(source)];
|
|
1179
|
+
for (let i = 0; i < keys2.length; i++) {
|
|
1180
|
+
const key = keys2[i];
|
|
1181
|
+
const descriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
1182
|
+
if (descriptor == null || descriptor.writable) {
|
|
1183
|
+
target[key] = cloneDeepWithImpl(source[key], key, objectToClone, stack, cloneValue);
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
__name(copyProperties, "copyProperties");
|
|
1188
|
+
function isCloneableObject(object) {
|
|
1189
|
+
switch (getTag(object)) {
|
|
1190
|
+
case argumentsTag:
|
|
1191
|
+
case arrayTag:
|
|
1192
|
+
case arrayBufferTag:
|
|
1193
|
+
case dataViewTag:
|
|
1194
|
+
case booleanTag:
|
|
1195
|
+
case dateTag:
|
|
1196
|
+
case float32ArrayTag:
|
|
1197
|
+
case float64ArrayTag:
|
|
1198
|
+
case int8ArrayTag:
|
|
1199
|
+
case int16ArrayTag:
|
|
1200
|
+
case int32ArrayTag:
|
|
1201
|
+
case mapTag:
|
|
1202
|
+
case numberTag:
|
|
1203
|
+
case objectTag:
|
|
1204
|
+
case regexpTag:
|
|
1205
|
+
case setTag:
|
|
1206
|
+
case stringTag:
|
|
1207
|
+
case symbolTag:
|
|
1208
|
+
case uint8ArrayTag:
|
|
1209
|
+
case uint8ClampedArrayTag:
|
|
1210
|
+
case uint16ArrayTag:
|
|
1211
|
+
case uint32ArrayTag: {
|
|
1212
|
+
return true;
|
|
1213
|
+
}
|
|
1214
|
+
default: {
|
|
1215
|
+
return false;
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
__name(isCloneableObject, "isCloneableObject");
|
|
1220
|
+
|
|
1221
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/object/cloneDeep.mjs
|
|
1222
|
+
function cloneDeep(obj) {
|
|
1223
|
+
return cloneDeepWithImpl(obj, void 0, obj, /* @__PURE__ */ new Map(), void 0);
|
|
1224
|
+
}
|
|
1225
|
+
__name(cloneDeep, "cloneDeep");
|
|
1226
|
+
|
|
1227
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/predicate/matches.mjs
|
|
1228
|
+
function matches(source) {
|
|
1229
|
+
source = cloneDeep(source);
|
|
1230
|
+
return (target) => {
|
|
1231
|
+
return isMatch(target, source);
|
|
1232
|
+
};
|
|
1233
|
+
}
|
|
1234
|
+
__name(matches, "matches");
|
|
1235
|
+
|
|
1236
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/object/cloneDeepWith.mjs
|
|
1237
|
+
function cloneDeepWith2(obj, customizer) {
|
|
1238
|
+
return cloneDeepWith(obj, (value, key, object, stack) => {
|
|
1239
|
+
const cloned = customizer?.(value, key, object, stack);
|
|
1240
|
+
if (cloned != null) {
|
|
1241
|
+
return cloned;
|
|
1242
|
+
}
|
|
1243
|
+
if (typeof obj !== "object") {
|
|
1244
|
+
return void 0;
|
|
1245
|
+
}
|
|
1246
|
+
switch (Object.prototype.toString.call(obj)) {
|
|
1247
|
+
case numberTag:
|
|
1248
|
+
case stringTag:
|
|
1249
|
+
case booleanTag: {
|
|
1250
|
+
const result = new obj.constructor(obj?.valueOf());
|
|
1251
|
+
copyProperties(result, obj);
|
|
1252
|
+
return result;
|
|
1253
|
+
}
|
|
1254
|
+
case argumentsTag: {
|
|
1255
|
+
const result = {};
|
|
1256
|
+
copyProperties(result, obj);
|
|
1257
|
+
result.length = obj.length;
|
|
1258
|
+
result[Symbol.iterator] = obj[Symbol.iterator];
|
|
1259
|
+
return result;
|
|
1260
|
+
}
|
|
1261
|
+
default: {
|
|
1262
|
+
return void 0;
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
});
|
|
1266
|
+
}
|
|
1267
|
+
__name(cloneDeepWith2, "cloneDeepWith");
|
|
1268
|
+
|
|
1269
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/object/cloneDeep.mjs
|
|
1270
|
+
function cloneDeep2(obj) {
|
|
1271
|
+
return cloneDeepWith2(obj);
|
|
1272
|
+
}
|
|
1273
|
+
__name(cloneDeep2, "cloneDeep");
|
|
1274
|
+
|
|
1275
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/_internal/isIndex.mjs
|
|
1276
|
+
var IS_UNSIGNED_INTEGER = /^(?:0|[1-9]\d*)$/;
|
|
1277
|
+
function isIndex(value, length = Number.MAX_SAFE_INTEGER) {
|
|
1278
|
+
switch (typeof value) {
|
|
1279
|
+
case "number": {
|
|
1280
|
+
return Number.isInteger(value) && value >= 0 && value < length;
|
|
1281
|
+
}
|
|
1282
|
+
case "symbol": {
|
|
1283
|
+
return false;
|
|
1284
|
+
}
|
|
1285
|
+
case "string": {
|
|
1286
|
+
return IS_UNSIGNED_INTEGER.test(value);
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
__name(isIndex, "isIndex");
|
|
1291
|
+
|
|
1292
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/predicate/isArguments.mjs
|
|
1293
|
+
function isArguments(value) {
|
|
1294
|
+
return value !== null && typeof value === "object" && getTag(value) === "[object Arguments]";
|
|
1295
|
+
}
|
|
1296
|
+
__name(isArguments, "isArguments");
|
|
1297
|
+
|
|
1298
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/object/has.mjs
|
|
1299
|
+
function has(object, path) {
|
|
1300
|
+
let resolvedPath;
|
|
1301
|
+
if (Array.isArray(path)) {
|
|
1302
|
+
resolvedPath = path;
|
|
1303
|
+
} else if (typeof path === "string" && isDeepKey(path) && object?.[path] == null) {
|
|
1304
|
+
resolvedPath = toPath(path);
|
|
1305
|
+
} else {
|
|
1306
|
+
resolvedPath = [path];
|
|
1307
|
+
}
|
|
1308
|
+
if (resolvedPath.length === 0) {
|
|
1309
|
+
return false;
|
|
1310
|
+
}
|
|
1311
|
+
let current = object;
|
|
1312
|
+
for (let i = 0; i < resolvedPath.length; i++) {
|
|
1313
|
+
const key = resolvedPath[i];
|
|
1314
|
+
if (current == null || !Object.hasOwn(current, key)) {
|
|
1315
|
+
const isSparseIndex = (Array.isArray(current) || isArguments(current)) && isIndex(key) && key < current.length;
|
|
1316
|
+
if (!isSparseIndex) {
|
|
1317
|
+
return false;
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
current = current[key];
|
|
1321
|
+
}
|
|
1322
|
+
return true;
|
|
1323
|
+
}
|
|
1324
|
+
__name(has, "has");
|
|
1325
|
+
|
|
1326
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/predicate/matchesProperty.mjs
|
|
1327
|
+
function matchesProperty(property2, source) {
|
|
1328
|
+
switch (typeof property2) {
|
|
1329
|
+
case "object": {
|
|
1330
|
+
if (Object.is(property2?.valueOf(), -0)) {
|
|
1331
|
+
property2 = "-0";
|
|
1332
|
+
}
|
|
1333
|
+
break;
|
|
1334
|
+
}
|
|
1335
|
+
case "number": {
|
|
1336
|
+
property2 = toKey(property2);
|
|
1337
|
+
break;
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
source = cloneDeep2(source);
|
|
1341
|
+
return function(target) {
|
|
1342
|
+
const result = get(target, property2);
|
|
1343
|
+
if (result === void 0) {
|
|
1344
|
+
return has(target, property2);
|
|
1345
|
+
}
|
|
1346
|
+
if (source === void 0) {
|
|
1347
|
+
return result === void 0;
|
|
1348
|
+
}
|
|
1349
|
+
return isMatch(result, source);
|
|
1350
|
+
};
|
|
1351
|
+
}
|
|
1352
|
+
__name(matchesProperty, "matchesProperty");
|
|
1353
|
+
|
|
1354
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/util/iteratee.mjs
|
|
1355
|
+
function iteratee(value) {
|
|
1356
|
+
if (value == null) {
|
|
1357
|
+
return identity;
|
|
1358
|
+
}
|
|
1359
|
+
switch (typeof value) {
|
|
1360
|
+
case "function": {
|
|
1361
|
+
return value;
|
|
1362
|
+
}
|
|
1363
|
+
case "object": {
|
|
1364
|
+
if (Array.isArray(value) && value.length === 2) {
|
|
1365
|
+
return matchesProperty(value[0], value[1]);
|
|
1366
|
+
}
|
|
1367
|
+
return matches(value);
|
|
1368
|
+
}
|
|
1369
|
+
case "string":
|
|
1370
|
+
case "symbol":
|
|
1371
|
+
case "number": {
|
|
1372
|
+
return property(value);
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
__name(iteratee, "iteratee");
|
|
1377
|
+
|
|
1378
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/predicate/isObjectLike.mjs
|
|
1379
|
+
function isObjectLike(value) {
|
|
1380
|
+
return typeof value === "object" && value !== null;
|
|
1381
|
+
}
|
|
1382
|
+
__name(isObjectLike, "isObjectLike");
|
|
1383
|
+
|
|
1384
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/predicate/isSymbol.mjs
|
|
1385
|
+
function isSymbol(value) {
|
|
1386
|
+
return typeof value === "symbol" || value instanceof Symbol;
|
|
1387
|
+
}
|
|
1388
|
+
__name(isSymbol, "isSymbol");
|
|
1389
|
+
|
|
1390
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/util/toNumber.mjs
|
|
1391
|
+
function toNumber(value) {
|
|
1392
|
+
if (isSymbol(value)) {
|
|
1393
|
+
return NaN;
|
|
1394
|
+
}
|
|
1395
|
+
return Number(value);
|
|
1396
|
+
}
|
|
1397
|
+
__name(toNumber, "toNumber");
|
|
1398
|
+
|
|
1399
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/util/toFinite.mjs
|
|
1400
|
+
function toFinite(value) {
|
|
1401
|
+
if (!value) {
|
|
1402
|
+
return value === 0 ? value : 0;
|
|
1403
|
+
}
|
|
1404
|
+
value = toNumber(value);
|
|
1405
|
+
if (value === Infinity || value === -Infinity) {
|
|
1406
|
+
const sign = value < 0 ? -1 : 1;
|
|
1407
|
+
return sign * Number.MAX_VALUE;
|
|
1408
|
+
}
|
|
1409
|
+
return value === value ? value : 0;
|
|
1410
|
+
}
|
|
1411
|
+
__name(toFinite, "toFinite");
|
|
1412
|
+
|
|
1413
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/util/toInteger.mjs
|
|
1414
|
+
function toInteger(value) {
|
|
1415
|
+
const finite = toFinite(value);
|
|
1416
|
+
const remainder = finite % 1;
|
|
1417
|
+
return remainder ? finite - remainder : finite;
|
|
1418
|
+
}
|
|
1419
|
+
__name(toInteger, "toInteger");
|
|
1420
|
+
|
|
1421
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/math/range.mjs
|
|
1422
|
+
function range(start, end, step = 1) {
|
|
1423
|
+
if (end == null) {
|
|
1424
|
+
end = start;
|
|
1425
|
+
start = 0;
|
|
1426
|
+
}
|
|
1427
|
+
if (!Number.isInteger(step) || step === 0) {
|
|
1428
|
+
throw new Error(`The step value must be a non-zero integer.`);
|
|
1429
|
+
}
|
|
1430
|
+
const length = Math.max(Math.ceil((end - start) / step), 0);
|
|
1431
|
+
const result = new Array(length);
|
|
1432
|
+
for (let i = 0; i < length; i++) {
|
|
1433
|
+
result[i] = start + i * step;
|
|
1434
|
+
}
|
|
1435
|
+
return result;
|
|
1436
|
+
}
|
|
1437
|
+
__name(range, "range");
|
|
1438
|
+
|
|
1439
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/array/forEach.mjs
|
|
1440
|
+
function forEach(collection, callback = identity) {
|
|
1441
|
+
if (!collection) {
|
|
1442
|
+
return collection;
|
|
1443
|
+
}
|
|
1444
|
+
const keys2 = isArrayLike(collection) || Array.isArray(collection) ? range(0, collection.length) : Object.keys(collection);
|
|
1445
|
+
for (let i = 0; i < keys2.length; i++) {
|
|
1446
|
+
const key = keys2[i];
|
|
1447
|
+
const value = collection[key];
|
|
1448
|
+
const result = callback(value, key, collection);
|
|
1449
|
+
if (result === false) {
|
|
1450
|
+
break;
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
return collection;
|
|
1454
|
+
}
|
|
1455
|
+
__name(forEach, "forEach");
|
|
1456
|
+
|
|
1457
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/_internal/isIterateeCall.mjs
|
|
1458
|
+
function isIterateeCall(value, index, object) {
|
|
1459
|
+
if (!isObject2(object)) {
|
|
1460
|
+
return false;
|
|
1461
|
+
}
|
|
1462
|
+
if (typeof index === "number" && isArrayLike(object) && isIndex(index) && index < object.length || typeof index === "string" && index in object) {
|
|
1463
|
+
return eq(object[index], value);
|
|
1464
|
+
}
|
|
1465
|
+
return false;
|
|
1466
|
+
}
|
|
1467
|
+
__name(isIterateeCall, "isIterateeCall");
|
|
1468
|
+
|
|
1469
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/predicate/isString.mjs
|
|
1470
|
+
function isString(value) {
|
|
1471
|
+
return typeof value === "string" || value instanceof String;
|
|
1472
|
+
}
|
|
1473
|
+
__name(isString, "isString");
|
|
1474
|
+
|
|
1475
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/array/filter.mjs
|
|
1476
|
+
function filter(source, predicate = identity) {
|
|
1477
|
+
if (!source) {
|
|
1478
|
+
return [];
|
|
1479
|
+
}
|
|
1480
|
+
predicate = iteratee(predicate);
|
|
1481
|
+
if (!Array.isArray(source)) {
|
|
1482
|
+
const result2 = [];
|
|
1483
|
+
const keys2 = Object.keys(source);
|
|
1484
|
+
const length2 = isArrayLike(source) ? source.length : keys2.length;
|
|
1485
|
+
for (let i = 0; i < length2; i++) {
|
|
1486
|
+
const key = keys2[i];
|
|
1487
|
+
const value = source[key];
|
|
1488
|
+
if (predicate(value, key, source)) {
|
|
1489
|
+
result2.push(value);
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
return result2;
|
|
1493
|
+
}
|
|
1494
|
+
const result = [];
|
|
1495
|
+
const length = source.length;
|
|
1496
|
+
for (let i = 0; i < length; i++) {
|
|
1497
|
+
const value = source[i];
|
|
1498
|
+
if (predicate(value, i, source)) {
|
|
1499
|
+
result.push(value);
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
return result;
|
|
1503
|
+
}
|
|
1504
|
+
__name(filter, "filter");
|
|
1505
|
+
|
|
1506
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/array/find.mjs
|
|
1507
|
+
function find(source, _doesMatch = identity, fromIndex = 0) {
|
|
1508
|
+
if (!source) {
|
|
1509
|
+
return void 0;
|
|
1510
|
+
}
|
|
1511
|
+
if (fromIndex < 0) {
|
|
1512
|
+
fromIndex = Math.max(source.length + fromIndex, 0);
|
|
1513
|
+
}
|
|
1514
|
+
const doesMatch = iteratee(_doesMatch);
|
|
1515
|
+
if (typeof doesMatch === "function" && !Array.isArray(source)) {
|
|
1516
|
+
const keys2 = Object.keys(source);
|
|
1517
|
+
for (let i = fromIndex; i < keys2.length; i++) {
|
|
1518
|
+
const key = keys2[i];
|
|
1519
|
+
const value = source[key];
|
|
1520
|
+
if (doesMatch(value, key, source)) {
|
|
1521
|
+
return value;
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
return void 0;
|
|
1525
|
+
}
|
|
1526
|
+
const values2 = Array.isArray(source) ? source.slice(fromIndex) : Object.values(source).slice(fromIndex);
|
|
1527
|
+
return values2.find(doesMatch);
|
|
1528
|
+
}
|
|
1529
|
+
__name(find, "find");
|
|
1530
|
+
|
|
1531
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/array/flatten.mjs
|
|
1532
|
+
function flatten2(value, depth = 1) {
|
|
1533
|
+
const result = [];
|
|
1534
|
+
const flooredDepth = Math.floor(depth);
|
|
1535
|
+
if (!isArrayLike(value)) {
|
|
1536
|
+
return result;
|
|
1537
|
+
}
|
|
1538
|
+
const recursive = /* @__PURE__ */ __name((arr, currentDepth) => {
|
|
1539
|
+
for (let i = 0; i < arr.length; i++) {
|
|
1540
|
+
const item = arr[i];
|
|
1541
|
+
if (currentDepth < flooredDepth && (Array.isArray(item) || Boolean(item?.[Symbol.isConcatSpreadable]) || item !== null && typeof item === "object" && Object.prototype.toString.call(item) === "[object Arguments]")) {
|
|
1542
|
+
if (Array.isArray(item)) {
|
|
1543
|
+
recursive(item, currentDepth + 1);
|
|
1544
|
+
} else {
|
|
1545
|
+
recursive(Array.from(item), currentDepth + 1);
|
|
1546
|
+
}
|
|
1547
|
+
} else {
|
|
1548
|
+
result.push(item);
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
}, "recursive");
|
|
1552
|
+
recursive(Array.from(value), 0);
|
|
1553
|
+
return result;
|
|
1554
|
+
}
|
|
1555
|
+
__name(flatten2, "flatten");
|
|
1556
|
+
|
|
1557
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/array/map.mjs
|
|
1558
|
+
function map(collection, _iteratee) {
|
|
1559
|
+
if (!collection) {
|
|
1560
|
+
return [];
|
|
1561
|
+
}
|
|
1562
|
+
const keys2 = isArrayLike(collection) || Array.isArray(collection) ? range(0, collection.length) : Object.keys(collection);
|
|
1563
|
+
const iteratee$1 = iteratee(_iteratee ?? identity);
|
|
1564
|
+
const result = new Array(keys2.length);
|
|
1565
|
+
for (let i = 0; i < keys2.length; i++) {
|
|
1566
|
+
const key = keys2[i];
|
|
1567
|
+
const value = collection[key];
|
|
1568
|
+
result[i] = iteratee$1(value, key, collection);
|
|
1569
|
+
}
|
|
1570
|
+
return result;
|
|
1571
|
+
}
|
|
1572
|
+
__name(map, "map");
|
|
1573
|
+
|
|
1574
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/array/groupBy.mjs
|
|
1575
|
+
function groupBy(arr, getKeyFromItem) {
|
|
1576
|
+
const result = {};
|
|
1577
|
+
for (let i = 0; i < arr.length; i++) {
|
|
1578
|
+
const item = arr[i];
|
|
1579
|
+
const key = getKeyFromItem(item);
|
|
1580
|
+
if (!Object.hasOwn(result, key)) {
|
|
1581
|
+
result[key] = [];
|
|
1582
|
+
}
|
|
1583
|
+
result[key].push(item);
|
|
1584
|
+
}
|
|
1585
|
+
return result;
|
|
1586
|
+
}
|
|
1587
|
+
__name(groupBy, "groupBy");
|
|
1588
|
+
|
|
1589
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/array/groupBy.mjs
|
|
1590
|
+
function groupBy2(source, _getKeyFromItem) {
|
|
1591
|
+
if (source == null) {
|
|
1592
|
+
return {};
|
|
1593
|
+
}
|
|
1594
|
+
const items = isArrayLike(source) ? Array.from(source) : Object.values(source);
|
|
1595
|
+
const getKeyFromItem = iteratee(_getKeyFromItem ?? identity);
|
|
1596
|
+
return groupBy(items, getKeyFromItem);
|
|
1597
|
+
}
|
|
1598
|
+
__name(groupBy2, "groupBy");
|
|
1599
|
+
|
|
1600
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/array/reduce.mjs
|
|
1601
|
+
function reduce(collection, iteratee2 = identity, accumulator) {
|
|
1602
|
+
if (!collection) {
|
|
1603
|
+
return accumulator;
|
|
1604
|
+
}
|
|
1605
|
+
let keys2;
|
|
1606
|
+
let startIndex = 0;
|
|
1607
|
+
if (isArrayLike(collection)) {
|
|
1608
|
+
keys2 = range(0, collection.length);
|
|
1609
|
+
if (accumulator == null && collection.length > 0) {
|
|
1610
|
+
accumulator = collection[0];
|
|
1611
|
+
startIndex += 1;
|
|
1612
|
+
}
|
|
1613
|
+
} else {
|
|
1614
|
+
keys2 = Object.keys(collection);
|
|
1615
|
+
if (accumulator == null) {
|
|
1616
|
+
accumulator = collection[keys2[0]];
|
|
1617
|
+
startIndex += 1;
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
for (let i = startIndex; i < keys2.length; i++) {
|
|
1621
|
+
const key = keys2[i];
|
|
1622
|
+
const value = collection[key];
|
|
1623
|
+
accumulator = iteratee2(accumulator, value, key, collection);
|
|
1624
|
+
}
|
|
1625
|
+
return accumulator;
|
|
1626
|
+
}
|
|
1627
|
+
__name(reduce, "reduce");
|
|
1628
|
+
|
|
1629
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/array/keyBy.mjs
|
|
1630
|
+
function keyBy(collection, iteratee$1) {
|
|
1631
|
+
if (!isArrayLike(collection) && !isObjectLike(collection)) {
|
|
1632
|
+
return {};
|
|
1633
|
+
}
|
|
1634
|
+
const keyFn = iteratee(iteratee$1 ?? identity);
|
|
1635
|
+
return reduce(collection, (result, value) => {
|
|
1636
|
+
const key = keyFn(value);
|
|
1637
|
+
result[key] = value;
|
|
1638
|
+
return result;
|
|
1639
|
+
}, {});
|
|
1640
|
+
}
|
|
1641
|
+
__name(keyBy, "keyBy");
|
|
1642
|
+
|
|
1643
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/_internal/compareValues.mjs
|
|
1644
|
+
function getPriority(a) {
|
|
1645
|
+
if (typeof a === "symbol") {
|
|
1646
|
+
return 1;
|
|
1647
|
+
}
|
|
1648
|
+
if (a === null) {
|
|
1649
|
+
return 2;
|
|
1650
|
+
}
|
|
1651
|
+
if (a === void 0) {
|
|
1652
|
+
return 3;
|
|
1653
|
+
}
|
|
1654
|
+
if (a !== a) {
|
|
1655
|
+
return 4;
|
|
1656
|
+
}
|
|
1657
|
+
return 0;
|
|
1658
|
+
}
|
|
1659
|
+
__name(getPriority, "getPriority");
|
|
1660
|
+
var compareValues = /* @__PURE__ */ __name((a, b, order) => {
|
|
1661
|
+
if (a !== b) {
|
|
1662
|
+
const aPriority = getPriority(a);
|
|
1663
|
+
const bPriority = getPriority(b);
|
|
1664
|
+
if (aPriority === bPriority && aPriority === 0) {
|
|
1665
|
+
if (a < b) {
|
|
1666
|
+
return order === "desc" ? 1 : -1;
|
|
1667
|
+
}
|
|
1668
|
+
if (a > b) {
|
|
1669
|
+
return order === "desc" ? -1 : 1;
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
return order === "desc" ? bPriority - aPriority : aPriority - bPriority;
|
|
1673
|
+
}
|
|
1674
|
+
return 0;
|
|
1675
|
+
}, "compareValues");
|
|
1676
|
+
|
|
1677
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/_internal/isKey.mjs
|
|
1678
|
+
var regexIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/;
|
|
1679
|
+
var regexIsPlainProp = /^\w*$/;
|
|
1680
|
+
function isKey(value, object) {
|
|
1681
|
+
if (Array.isArray(value)) {
|
|
1682
|
+
return false;
|
|
1683
|
+
}
|
|
1684
|
+
if (typeof value === "number" || typeof value === "boolean" || value == null || isSymbol(value)) {
|
|
1685
|
+
return true;
|
|
1686
|
+
}
|
|
1687
|
+
return typeof value === "string" && (regexIsPlainProp.test(value) || !regexIsDeepProp.test(value)) || object != null && Object.hasOwn(object, value);
|
|
1688
|
+
}
|
|
1689
|
+
__name(isKey, "isKey");
|
|
1690
|
+
|
|
1691
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/array/orderBy.mjs
|
|
1692
|
+
function orderBy(collection, criteria, orders, guard) {
|
|
1693
|
+
if (collection == null) {
|
|
1694
|
+
return [];
|
|
1695
|
+
}
|
|
1696
|
+
orders = guard ? void 0 : orders;
|
|
1697
|
+
if (!Array.isArray(collection)) {
|
|
1698
|
+
collection = Object.values(collection);
|
|
1699
|
+
}
|
|
1700
|
+
if (!Array.isArray(criteria)) {
|
|
1701
|
+
criteria = criteria == null ? [null] : [criteria];
|
|
1702
|
+
}
|
|
1703
|
+
if (criteria.length === 0) {
|
|
1704
|
+
criteria = [null];
|
|
1705
|
+
}
|
|
1706
|
+
if (!Array.isArray(orders)) {
|
|
1707
|
+
orders = orders == null ? [] : [orders];
|
|
1708
|
+
}
|
|
1709
|
+
orders = orders.map((order) => String(order));
|
|
1710
|
+
const getValueByNestedPath = /* @__PURE__ */ __name((object, path) => {
|
|
1711
|
+
let target = object;
|
|
1712
|
+
for (let i = 0; i < path.length && target != null; ++i) {
|
|
1713
|
+
target = target[path[i]];
|
|
1714
|
+
}
|
|
1715
|
+
return target;
|
|
1716
|
+
}, "getValueByNestedPath");
|
|
1717
|
+
const getValueByCriterion = /* @__PURE__ */ __name((criterion, object) => {
|
|
1718
|
+
if (object == null || criterion == null) {
|
|
1719
|
+
return object;
|
|
1720
|
+
}
|
|
1721
|
+
if (typeof criterion === "object" && "key" in criterion) {
|
|
1722
|
+
if (Object.hasOwn(object, criterion.key)) {
|
|
1723
|
+
return object[criterion.key];
|
|
1724
|
+
}
|
|
1725
|
+
return getValueByNestedPath(object, criterion.path);
|
|
1726
|
+
}
|
|
1727
|
+
if (typeof criterion === "function") {
|
|
1728
|
+
return criterion(object);
|
|
1729
|
+
}
|
|
1730
|
+
if (Array.isArray(criterion)) {
|
|
1731
|
+
return getValueByNestedPath(object, criterion);
|
|
1732
|
+
}
|
|
1733
|
+
if (typeof object === "object") {
|
|
1734
|
+
return object[criterion];
|
|
1735
|
+
}
|
|
1736
|
+
return object;
|
|
1737
|
+
}, "getValueByCriterion");
|
|
1738
|
+
const preparedCriteria = criteria.map((criterion) => {
|
|
1739
|
+
if (Array.isArray(criterion) && criterion.length === 1) {
|
|
1740
|
+
criterion = criterion[0];
|
|
1741
|
+
}
|
|
1742
|
+
if (criterion == null || typeof criterion === "function" || Array.isArray(criterion) || isKey(criterion)) {
|
|
1743
|
+
return criterion;
|
|
1744
|
+
}
|
|
1745
|
+
return { key: criterion, path: toPath(criterion) };
|
|
1746
|
+
});
|
|
1747
|
+
const preparedCollection = collection.map((item) => ({
|
|
1748
|
+
original: item,
|
|
1749
|
+
criteria: preparedCriteria.map((criterion) => getValueByCriterion(criterion, item))
|
|
1750
|
+
}));
|
|
1751
|
+
return preparedCollection.slice().sort((a, b) => {
|
|
1752
|
+
for (let i = 0; i < preparedCriteria.length; i++) {
|
|
1753
|
+
const comparedResult = compareValues(a.criteria[i], b.criteria[i], orders[i]);
|
|
1754
|
+
if (comparedResult !== 0) {
|
|
1755
|
+
return comparedResult;
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
return 0;
|
|
1759
|
+
}).map((item) => item.original);
|
|
1760
|
+
}
|
|
1761
|
+
__name(orderBy, "orderBy");
|
|
1762
|
+
|
|
1763
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/object/unset.mjs
|
|
1764
|
+
function unset(obj, path) {
|
|
1765
|
+
if (obj == null) {
|
|
1766
|
+
return true;
|
|
1767
|
+
}
|
|
1768
|
+
switch (typeof path) {
|
|
1769
|
+
case "symbol":
|
|
1770
|
+
case "number":
|
|
1771
|
+
case "object": {
|
|
1772
|
+
if (Array.isArray(path)) {
|
|
1773
|
+
return unsetWithPath(obj, path);
|
|
1774
|
+
}
|
|
1775
|
+
if (typeof path === "number") {
|
|
1776
|
+
path = toKey(path);
|
|
1777
|
+
} else if (typeof path === "object") {
|
|
1778
|
+
if (Object.is(path?.valueOf(), -0)) {
|
|
1779
|
+
path = "-0";
|
|
1780
|
+
} else {
|
|
1781
|
+
path = String(path);
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
if (isUnsafeProperty(path)) {
|
|
1785
|
+
return false;
|
|
1786
|
+
}
|
|
1787
|
+
if (obj?.[path] === void 0) {
|
|
1788
|
+
return true;
|
|
1789
|
+
}
|
|
1790
|
+
try {
|
|
1791
|
+
delete obj[path];
|
|
1792
|
+
return true;
|
|
1793
|
+
} catch {
|
|
1794
|
+
return false;
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
case "string": {
|
|
1798
|
+
if (obj?.[path] === void 0 && isDeepKey(path)) {
|
|
1799
|
+
return unsetWithPath(obj, toPath(path));
|
|
1800
|
+
}
|
|
1801
|
+
if (isUnsafeProperty(path)) {
|
|
1802
|
+
return false;
|
|
1803
|
+
}
|
|
1804
|
+
try {
|
|
1805
|
+
delete obj[path];
|
|
1806
|
+
return true;
|
|
1807
|
+
} catch {
|
|
1808
|
+
return false;
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
__name(unset, "unset");
|
|
1814
|
+
function unsetWithPath(obj, path) {
|
|
1815
|
+
const parent = get(obj, path.slice(0, -1), obj);
|
|
1816
|
+
const lastKey = path[path.length - 1];
|
|
1817
|
+
if (parent?.[lastKey] === void 0) {
|
|
1818
|
+
return true;
|
|
1819
|
+
}
|
|
1820
|
+
if (isUnsafeProperty(lastKey)) {
|
|
1821
|
+
return false;
|
|
1822
|
+
}
|
|
1823
|
+
try {
|
|
1824
|
+
delete parent[lastKey];
|
|
1825
|
+
return true;
|
|
1826
|
+
} catch {
|
|
1827
|
+
return false;
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
__name(unsetWithPath, "unsetWithPath");
|
|
1831
|
+
|
|
1832
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/predicate/isArray.mjs
|
|
1833
|
+
function isArray(value) {
|
|
1834
|
+
return Array.isArray(value);
|
|
1835
|
+
}
|
|
1836
|
+
__name(isArray, "isArray");
|
|
1837
|
+
|
|
1838
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/object/values.mjs
|
|
1839
|
+
function values(object) {
|
|
1840
|
+
if (object == null) {
|
|
1841
|
+
return [];
|
|
1842
|
+
}
|
|
1843
|
+
return Object.values(object);
|
|
1844
|
+
}
|
|
1845
|
+
__name(values, "values");
|
|
1846
|
+
|
|
1847
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/predicate/isNil.mjs
|
|
1848
|
+
function isNil(x) {
|
|
1849
|
+
return x == null;
|
|
1850
|
+
}
|
|
1851
|
+
__name(isNil, "isNil");
|
|
1852
|
+
|
|
1853
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/array/some.mjs
|
|
1854
|
+
function some(source, predicate, guard) {
|
|
1855
|
+
if (!source) {
|
|
1856
|
+
return false;
|
|
1857
|
+
}
|
|
1858
|
+
if (guard != null) {
|
|
1859
|
+
predicate = void 0;
|
|
1860
|
+
}
|
|
1861
|
+
if (!predicate) {
|
|
1862
|
+
predicate = identity;
|
|
1863
|
+
}
|
|
1864
|
+
const values2 = Array.isArray(source) ? source : Object.values(source);
|
|
1865
|
+
switch (typeof predicate) {
|
|
1866
|
+
case "function": {
|
|
1867
|
+
if (!Array.isArray(source)) {
|
|
1868
|
+
const keys2 = Object.keys(source);
|
|
1869
|
+
for (let i = 0; i < keys2.length; i++) {
|
|
1870
|
+
const key = keys2[i];
|
|
1871
|
+
const value = source[key];
|
|
1872
|
+
if (predicate(value, key, source)) {
|
|
1873
|
+
return true;
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
return false;
|
|
1877
|
+
}
|
|
1878
|
+
for (let i = 0; i < source.length; i++) {
|
|
1879
|
+
if (predicate(source[i], i, source)) {
|
|
1880
|
+
return true;
|
|
1881
|
+
}
|
|
1882
|
+
}
|
|
1883
|
+
return false;
|
|
1884
|
+
}
|
|
1885
|
+
case "object": {
|
|
1886
|
+
if (Array.isArray(predicate) && predicate.length === 2) {
|
|
1887
|
+
const key = predicate[0];
|
|
1888
|
+
const value = predicate[1];
|
|
1889
|
+
const matchFunc = matchesProperty(key, value);
|
|
1890
|
+
if (Array.isArray(source)) {
|
|
1891
|
+
for (let i = 0; i < source.length; i++) {
|
|
1892
|
+
if (matchFunc(source[i])) {
|
|
1893
|
+
return true;
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
return false;
|
|
1897
|
+
}
|
|
1898
|
+
return values2.some(matchFunc);
|
|
1899
|
+
} else {
|
|
1900
|
+
const matchFunc = matches(predicate);
|
|
1901
|
+
if (Array.isArray(source)) {
|
|
1902
|
+
for (let i = 0; i < source.length; i++) {
|
|
1903
|
+
if (matchFunc(source[i])) {
|
|
1904
|
+
return true;
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
return false;
|
|
1908
|
+
}
|
|
1909
|
+
return values2.some(matchFunc);
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
case "number":
|
|
1913
|
+
case "symbol":
|
|
1914
|
+
case "string": {
|
|
1915
|
+
const propFunc = property(predicate);
|
|
1916
|
+
if (Array.isArray(source)) {
|
|
1917
|
+
for (let i = 0; i < source.length; i++) {
|
|
1918
|
+
if (propFunc(source[i])) {
|
|
1919
|
+
return true;
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
return false;
|
|
1923
|
+
}
|
|
1924
|
+
return values2.some(propFunc);
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
__name(some, "some");
|
|
1929
|
+
|
|
1930
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/array/sortBy.mjs
|
|
1931
|
+
function sortBy(collection, ...criteria) {
|
|
1932
|
+
const length = criteria.length;
|
|
1933
|
+
if (length > 1 && isIterateeCall(collection, criteria[0], criteria[1])) {
|
|
1934
|
+
criteria = [];
|
|
1935
|
+
} else if (length > 2 && isIterateeCall(criteria[0], criteria[1], criteria[2])) {
|
|
1936
|
+
criteria = [criteria[0]];
|
|
1937
|
+
}
|
|
1938
|
+
return orderBy(collection, flatten(criteria), ["asc"]);
|
|
1939
|
+
}
|
|
1940
|
+
__name(sortBy, "sortBy");
|
|
1941
|
+
|
|
1942
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/function/identity.mjs
|
|
1943
|
+
function identity2(x) {
|
|
1944
|
+
return x;
|
|
1945
|
+
}
|
|
1946
|
+
__name(identity2, "identity");
|
|
1947
|
+
|
|
1948
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/_internal/assignValue.mjs
|
|
1949
|
+
var assignValue = /* @__PURE__ */ __name((object, key, value) => {
|
|
1950
|
+
const objValue = object[key];
|
|
1951
|
+
if (!(Object.hasOwn(object, key) && eq(objValue, value)) || value === void 0 && !(key in object)) {
|
|
1952
|
+
object[key] = value;
|
|
1953
|
+
}
|
|
1954
|
+
}, "assignValue");
|
|
1955
|
+
|
|
1956
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/object/updateWith.mjs
|
|
1957
|
+
function updateWith(obj, path, updater, customizer) {
|
|
1958
|
+
if (obj == null && !isObject2(obj)) {
|
|
1959
|
+
return obj;
|
|
1960
|
+
}
|
|
1961
|
+
const resolvedPath = isKey(path, obj) ? [path] : Array.isArray(path) ? path : typeof path === "string" ? toPath(path) : [path];
|
|
1962
|
+
let current = obj;
|
|
1963
|
+
for (let i = 0; i < resolvedPath.length && current != null; i++) {
|
|
1964
|
+
const key = toKey(resolvedPath[i]);
|
|
1965
|
+
if (isUnsafeProperty(key)) {
|
|
1966
|
+
continue;
|
|
1967
|
+
}
|
|
1968
|
+
let newValue;
|
|
1969
|
+
if (i === resolvedPath.length - 1) {
|
|
1970
|
+
newValue = updater(current[key]);
|
|
1971
|
+
} else {
|
|
1972
|
+
const objValue = current[key];
|
|
1973
|
+
const customizerResult = customizer?.(objValue, key, obj);
|
|
1974
|
+
newValue = customizerResult !== void 0 ? customizerResult : isObject2(objValue) ? objValue : isIndex(resolvedPath[i + 1]) ? [] : {};
|
|
1975
|
+
}
|
|
1976
|
+
assignValue(current, key, newValue);
|
|
1977
|
+
current = current[key];
|
|
1978
|
+
}
|
|
1979
|
+
return obj;
|
|
1980
|
+
}
|
|
1981
|
+
__name(updateWith, "updateWith");
|
|
1982
|
+
|
|
1983
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/object/set.mjs
|
|
1984
|
+
function set(obj, path, value) {
|
|
1985
|
+
return updateWith(obj, path, () => value, () => void 0);
|
|
1986
|
+
}
|
|
1987
|
+
__name(set, "set");
|
|
1988
|
+
|
|
1989
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/predicate/isPlainObject.mjs
|
|
1990
|
+
function isPlainObject(value) {
|
|
1991
|
+
if (!value || typeof value !== "object") {
|
|
1992
|
+
return false;
|
|
1993
|
+
}
|
|
1994
|
+
const proto = Object.getPrototypeOf(value);
|
|
1995
|
+
const hasObjectPrototype = proto === null || proto === Object.prototype || Object.getPrototypeOf(proto) === null;
|
|
1996
|
+
if (!hasObjectPrototype) {
|
|
1997
|
+
return false;
|
|
1998
|
+
}
|
|
1999
|
+
return Object.prototype.toString.call(value) === "[object Object]";
|
|
2000
|
+
}
|
|
2001
|
+
__name(isPlainObject, "isPlainObject");
|
|
2002
|
+
|
|
2003
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/predicate/isEqualWith.mjs
|
|
2004
|
+
function isEqualWith(a, b, areValuesEqual) {
|
|
2005
|
+
return isEqualWithImpl(a, b, void 0, void 0, void 0, void 0, areValuesEqual);
|
|
2006
|
+
}
|
|
2007
|
+
__name(isEqualWith, "isEqualWith");
|
|
2008
|
+
function isEqualWithImpl(a, b, property2, aParent, bParent, stack, areValuesEqual) {
|
|
2009
|
+
const result = areValuesEqual(a, b, property2, aParent, bParent, stack);
|
|
2010
|
+
if (result !== void 0) {
|
|
2011
|
+
return result;
|
|
2012
|
+
}
|
|
2013
|
+
if (typeof a === typeof b) {
|
|
2014
|
+
switch (typeof a) {
|
|
2015
|
+
case "bigint":
|
|
2016
|
+
case "string":
|
|
2017
|
+
case "boolean":
|
|
2018
|
+
case "symbol":
|
|
2019
|
+
case "undefined": {
|
|
2020
|
+
return a === b;
|
|
2021
|
+
}
|
|
2022
|
+
case "number": {
|
|
2023
|
+
return a === b || Object.is(a, b);
|
|
2024
|
+
}
|
|
2025
|
+
case "function": {
|
|
2026
|
+
return a === b;
|
|
2027
|
+
}
|
|
2028
|
+
case "object": {
|
|
2029
|
+
return areObjectsEqual(a, b, stack, areValuesEqual);
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
return areObjectsEqual(a, b, stack, areValuesEqual);
|
|
2034
|
+
}
|
|
2035
|
+
__name(isEqualWithImpl, "isEqualWithImpl");
|
|
2036
|
+
function areObjectsEqual(a, b, stack, areValuesEqual) {
|
|
2037
|
+
if (Object.is(a, b)) {
|
|
2038
|
+
return true;
|
|
2039
|
+
}
|
|
2040
|
+
let aTag = getTag(a);
|
|
2041
|
+
let bTag = getTag(b);
|
|
2042
|
+
if (aTag === argumentsTag) {
|
|
2043
|
+
aTag = objectTag;
|
|
2044
|
+
}
|
|
2045
|
+
if (bTag === argumentsTag) {
|
|
2046
|
+
bTag = objectTag;
|
|
2047
|
+
}
|
|
2048
|
+
if (aTag !== bTag) {
|
|
2049
|
+
return false;
|
|
2050
|
+
}
|
|
2051
|
+
switch (aTag) {
|
|
2052
|
+
case stringTag:
|
|
2053
|
+
return a.toString() === b.toString();
|
|
2054
|
+
case numberTag: {
|
|
2055
|
+
const x = a.valueOf();
|
|
2056
|
+
const y = b.valueOf();
|
|
2057
|
+
return eq(x, y);
|
|
2058
|
+
}
|
|
2059
|
+
case booleanTag:
|
|
2060
|
+
case dateTag:
|
|
2061
|
+
case symbolTag:
|
|
2062
|
+
return Object.is(a.valueOf(), b.valueOf());
|
|
2063
|
+
case regexpTag: {
|
|
2064
|
+
return a.source === b.source && a.flags === b.flags;
|
|
2065
|
+
}
|
|
2066
|
+
case functionTag: {
|
|
2067
|
+
return a === b;
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
stack = stack ?? /* @__PURE__ */ new Map();
|
|
2071
|
+
const aStack = stack.get(a);
|
|
2072
|
+
const bStack = stack.get(b);
|
|
2073
|
+
if (aStack != null && bStack != null) {
|
|
2074
|
+
return aStack === b;
|
|
2075
|
+
}
|
|
2076
|
+
stack.set(a, b);
|
|
2077
|
+
stack.set(b, a);
|
|
2078
|
+
try {
|
|
2079
|
+
switch (aTag) {
|
|
2080
|
+
case mapTag: {
|
|
2081
|
+
if (a.size !== b.size) {
|
|
2082
|
+
return false;
|
|
2083
|
+
}
|
|
2084
|
+
for (const [key, value] of a.entries()) {
|
|
2085
|
+
if (!b.has(key) || !isEqualWithImpl(value, b.get(key), key, a, b, stack, areValuesEqual)) {
|
|
2086
|
+
return false;
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
return true;
|
|
2090
|
+
}
|
|
2091
|
+
case setTag: {
|
|
2092
|
+
if (a.size !== b.size) {
|
|
2093
|
+
return false;
|
|
2094
|
+
}
|
|
2095
|
+
const aValues = Array.from(a.values());
|
|
2096
|
+
const bValues = Array.from(b.values());
|
|
2097
|
+
for (let i = 0; i < aValues.length; i++) {
|
|
2098
|
+
const aValue = aValues[i];
|
|
2099
|
+
const index = bValues.findIndex((bValue) => {
|
|
2100
|
+
return isEqualWithImpl(aValue, bValue, void 0, a, b, stack, areValuesEqual);
|
|
2101
|
+
});
|
|
2102
|
+
if (index === -1) {
|
|
2103
|
+
return false;
|
|
2104
|
+
}
|
|
2105
|
+
bValues.splice(index, 1);
|
|
2106
|
+
}
|
|
2107
|
+
return true;
|
|
2108
|
+
}
|
|
2109
|
+
case arrayTag:
|
|
2110
|
+
case uint8ArrayTag:
|
|
2111
|
+
case uint8ClampedArrayTag:
|
|
2112
|
+
case uint16ArrayTag:
|
|
2113
|
+
case uint32ArrayTag:
|
|
2114
|
+
case bigUint64ArrayTag:
|
|
2115
|
+
case int8ArrayTag:
|
|
2116
|
+
case int16ArrayTag:
|
|
2117
|
+
case int32ArrayTag:
|
|
2118
|
+
case bigInt64ArrayTag:
|
|
2119
|
+
case float32ArrayTag:
|
|
2120
|
+
case float64ArrayTag: {
|
|
2121
|
+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(a) !== Buffer.isBuffer(b)) {
|
|
2122
|
+
return false;
|
|
2123
|
+
}
|
|
2124
|
+
if (a.length !== b.length) {
|
|
2125
|
+
return false;
|
|
2126
|
+
}
|
|
2127
|
+
for (let i = 0; i < a.length; i++) {
|
|
2128
|
+
if (!isEqualWithImpl(a[i], b[i], i, a, b, stack, areValuesEqual)) {
|
|
2129
|
+
return false;
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2132
|
+
return true;
|
|
2133
|
+
}
|
|
2134
|
+
case arrayBufferTag: {
|
|
2135
|
+
if (a.byteLength !== b.byteLength) {
|
|
2136
|
+
return false;
|
|
2137
|
+
}
|
|
2138
|
+
return areObjectsEqual(new Uint8Array(a), new Uint8Array(b), stack, areValuesEqual);
|
|
2139
|
+
}
|
|
2140
|
+
case dataViewTag: {
|
|
2141
|
+
if (a.byteLength !== b.byteLength || a.byteOffset !== b.byteOffset) {
|
|
2142
|
+
return false;
|
|
2143
|
+
}
|
|
2144
|
+
return areObjectsEqual(new Uint8Array(a), new Uint8Array(b), stack, areValuesEqual);
|
|
2145
|
+
}
|
|
2146
|
+
case errorTag: {
|
|
2147
|
+
return a.name === b.name && a.message === b.message;
|
|
2148
|
+
}
|
|
2149
|
+
case objectTag: {
|
|
2150
|
+
const areEqualInstances = areObjectsEqual(a.constructor, b.constructor, stack, areValuesEqual) || isPlainObject(a) && isPlainObject(b);
|
|
2151
|
+
if (!areEqualInstances) {
|
|
2152
|
+
return false;
|
|
2153
|
+
}
|
|
2154
|
+
const aKeys = [...Object.keys(a), ...getSymbols(a)];
|
|
2155
|
+
const bKeys = [...Object.keys(b), ...getSymbols(b)];
|
|
2156
|
+
if (aKeys.length !== bKeys.length) {
|
|
2157
|
+
return false;
|
|
2158
|
+
}
|
|
2159
|
+
for (let i = 0; i < aKeys.length; i++) {
|
|
2160
|
+
const propKey = aKeys[i];
|
|
2161
|
+
const aProp = a[propKey];
|
|
2162
|
+
if (!Object.hasOwn(b, propKey)) {
|
|
2163
|
+
return false;
|
|
2164
|
+
}
|
|
2165
|
+
const bProp = b[propKey];
|
|
2166
|
+
if (!isEqualWithImpl(aProp, bProp, propKey, a, b, stack, areValuesEqual)) {
|
|
2167
|
+
return false;
|
|
2168
|
+
}
|
|
2169
|
+
}
|
|
2170
|
+
return true;
|
|
2171
|
+
}
|
|
2172
|
+
default: {
|
|
2173
|
+
return false;
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
} finally {
|
|
2177
|
+
stack.delete(a);
|
|
2178
|
+
stack.delete(b);
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
__name(areObjectsEqual, "areObjectsEqual");
|
|
2182
|
+
|
|
2183
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/function/noop.mjs
|
|
2184
|
+
function noop() {
|
|
2185
|
+
}
|
|
2186
|
+
__name(noop, "noop");
|
|
2187
|
+
|
|
2188
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/predicate/isEqual.mjs
|
|
2189
|
+
function isEqual(a, b) {
|
|
2190
|
+
return isEqualWith(a, b, noop);
|
|
2191
|
+
}
|
|
2192
|
+
__name(isEqual, "isEqual");
|
|
2193
|
+
|
|
2194
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/predicate/isBuffer.mjs
|
|
2195
|
+
function isBuffer(x) {
|
|
2196
|
+
return typeof Buffer !== "undefined" && Buffer.isBuffer(x);
|
|
2197
|
+
}
|
|
2198
|
+
__name(isBuffer, "isBuffer");
|
|
2199
|
+
|
|
2200
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/_internal/isPrototype.mjs
|
|
2201
|
+
function isPrototype(value) {
|
|
2202
|
+
const constructor = value?.constructor;
|
|
2203
|
+
const prototype = typeof constructor === "function" ? constructor.prototype : Object.prototype;
|
|
2204
|
+
return value === prototype;
|
|
2205
|
+
}
|
|
2206
|
+
__name(isPrototype, "isPrototype");
|
|
2207
|
+
|
|
2208
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/predicate/isTypedArray.mjs
|
|
2209
|
+
function isTypedArray2(x) {
|
|
2210
|
+
return isTypedArray(x);
|
|
2211
|
+
}
|
|
2212
|
+
__name(isTypedArray2, "isTypedArray");
|
|
2213
|
+
|
|
2214
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/util/times.mjs
|
|
2215
|
+
function times(n, getValue) {
|
|
2216
|
+
n = toInteger(n);
|
|
2217
|
+
if (n < 1 || !Number.isSafeInteger(n)) {
|
|
2218
|
+
return [];
|
|
2219
|
+
}
|
|
2220
|
+
const result = new Array(n);
|
|
2221
|
+
for (let i = 0; i < n; i++) {
|
|
2222
|
+
result[i] = typeof getValue === "function" ? getValue(i) : i;
|
|
2223
|
+
}
|
|
2224
|
+
return result;
|
|
2225
|
+
}
|
|
2226
|
+
__name(times, "times");
|
|
2227
|
+
|
|
2228
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/object/keys.mjs
|
|
2229
|
+
function keys(object) {
|
|
2230
|
+
if (isArrayLike(object)) {
|
|
2231
|
+
return arrayLikeKeys(object);
|
|
2232
|
+
}
|
|
2233
|
+
const result = Object.keys(Object(object));
|
|
2234
|
+
if (!isPrototype(object)) {
|
|
2235
|
+
return result;
|
|
2236
|
+
}
|
|
2237
|
+
return result.filter((key) => key !== "constructor");
|
|
2238
|
+
}
|
|
2239
|
+
__name(keys, "keys");
|
|
2240
|
+
function arrayLikeKeys(object) {
|
|
2241
|
+
const indices = times(object.length, (index) => `${index}`);
|
|
2242
|
+
const filteredKeys = new Set(indices);
|
|
2243
|
+
if (isBuffer(object)) {
|
|
2244
|
+
filteredKeys.add("offset");
|
|
2245
|
+
filteredKeys.add("parent");
|
|
2246
|
+
}
|
|
2247
|
+
if (isTypedArray2(object)) {
|
|
2248
|
+
filteredKeys.add("buffer");
|
|
2249
|
+
filteredKeys.add("byteLength");
|
|
2250
|
+
filteredKeys.add("byteOffset");
|
|
2251
|
+
}
|
|
2252
|
+
return [...indices, ...Object.keys(object).filter((key) => !filteredKeys.has(key))];
|
|
2253
|
+
}
|
|
2254
|
+
__name(arrayLikeKeys, "arrayLikeKeys");
|
|
2255
|
+
|
|
2256
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/object/keysIn.mjs
|
|
2257
|
+
function keysIn(object) {
|
|
2258
|
+
if (object == null) {
|
|
2259
|
+
return [];
|
|
2260
|
+
}
|
|
2261
|
+
switch (typeof object) {
|
|
2262
|
+
case "object":
|
|
2263
|
+
case "function": {
|
|
2264
|
+
if (isArrayLike(object)) {
|
|
2265
|
+
return arrayLikeKeysIn(object);
|
|
2266
|
+
}
|
|
2267
|
+
if (isPrototype(object)) {
|
|
2268
|
+
return prototypeKeysIn(object);
|
|
2269
|
+
}
|
|
2270
|
+
return keysInImpl(object);
|
|
2271
|
+
}
|
|
2272
|
+
default: {
|
|
2273
|
+
return keysInImpl(Object(object));
|
|
2274
|
+
}
|
|
2275
|
+
}
|
|
2276
|
+
}
|
|
2277
|
+
__name(keysIn, "keysIn");
|
|
2278
|
+
function keysInImpl(object) {
|
|
2279
|
+
const result = [];
|
|
2280
|
+
for (const key in object) {
|
|
2281
|
+
result.push(key);
|
|
2282
|
+
}
|
|
2283
|
+
return result;
|
|
2284
|
+
}
|
|
2285
|
+
__name(keysInImpl, "keysInImpl");
|
|
2286
|
+
function prototypeKeysIn(object) {
|
|
2287
|
+
const keys2 = keysInImpl(object);
|
|
2288
|
+
return keys2.filter((key) => key !== "constructor");
|
|
2289
|
+
}
|
|
2290
|
+
__name(prototypeKeysIn, "prototypeKeysIn");
|
|
2291
|
+
function arrayLikeKeysIn(object) {
|
|
2292
|
+
const indices = times(object.length, (index) => `${index}`);
|
|
2293
|
+
const filteredKeys = new Set(indices);
|
|
2294
|
+
if (isBuffer(object)) {
|
|
2295
|
+
filteredKeys.add("offset");
|
|
2296
|
+
filteredKeys.add("parent");
|
|
2297
|
+
}
|
|
2298
|
+
if (isTypedArray2(object)) {
|
|
2299
|
+
filteredKeys.add("buffer");
|
|
2300
|
+
filteredKeys.add("byteLength");
|
|
2301
|
+
filteredKeys.add("byteOffset");
|
|
2302
|
+
}
|
|
2303
|
+
return [...indices, ...keysInImpl(object).filter((key) => !filteredKeys.has(key))];
|
|
2304
|
+
}
|
|
2305
|
+
__name(arrayLikeKeysIn, "arrayLikeKeysIn");
|
|
2306
|
+
|
|
2307
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/object/omit.mjs
|
|
2308
|
+
function omit(obj, ...keysArr) {
|
|
2309
|
+
if (obj == null) {
|
|
2310
|
+
return {};
|
|
2311
|
+
}
|
|
2312
|
+
const result = cloneDeep(obj);
|
|
2313
|
+
for (let i = 0; i < keysArr.length; i++) {
|
|
2314
|
+
let keys2 = keysArr[i];
|
|
2315
|
+
switch (typeof keys2) {
|
|
2316
|
+
case "object": {
|
|
2317
|
+
if (!Array.isArray(keys2)) {
|
|
2318
|
+
keys2 = Array.from(keys2);
|
|
2319
|
+
}
|
|
2320
|
+
for (let j = 0; j < keys2.length; j++) {
|
|
2321
|
+
const key = keys2[j];
|
|
2322
|
+
unset(result, key);
|
|
2323
|
+
}
|
|
2324
|
+
break;
|
|
2325
|
+
}
|
|
2326
|
+
case "string":
|
|
2327
|
+
case "symbol":
|
|
2328
|
+
case "number": {
|
|
2329
|
+
unset(result, keys2);
|
|
2330
|
+
break;
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
}
|
|
2334
|
+
return result;
|
|
2335
|
+
}
|
|
2336
|
+
__name(omit, "omit");
|
|
2337
|
+
|
|
2338
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/_internal/getSymbolsIn.mjs
|
|
2339
|
+
function getSymbolsIn(object) {
|
|
2340
|
+
const result = [];
|
|
2341
|
+
while (object) {
|
|
2342
|
+
result.push(...getSymbols(object));
|
|
2343
|
+
object = Object.getPrototypeOf(object);
|
|
2344
|
+
}
|
|
2345
|
+
return result;
|
|
2346
|
+
}
|
|
2347
|
+
__name(getSymbolsIn, "getSymbolsIn");
|
|
2348
|
+
|
|
2349
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/object/pickBy.mjs
|
|
2350
|
+
function pickBy(obj, shouldPick) {
|
|
2351
|
+
if (obj == null) {
|
|
2352
|
+
return {};
|
|
2353
|
+
}
|
|
2354
|
+
const predicate = iteratee(shouldPick ?? identity2);
|
|
2355
|
+
const result = {};
|
|
2356
|
+
const keys2 = isArrayLike(obj) ? range(0, obj.length) : [...keysIn(obj), ...getSymbolsIn(obj)];
|
|
2357
|
+
for (let i = 0; i < keys2.length; i++) {
|
|
2358
|
+
const key = isSymbol(keys2[i]) ? keys2[i] : keys2[i].toString();
|
|
2359
|
+
const value = obj[key];
|
|
2360
|
+
if (predicate(value, key, obj)) {
|
|
2361
|
+
result[key] = value;
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2364
|
+
return result;
|
|
2365
|
+
}
|
|
2366
|
+
__name(pickBy, "pickBy");
|
|
2367
|
+
|
|
2368
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/predicate/isBoolean.mjs
|
|
2369
|
+
function isBoolean(value) {
|
|
2370
|
+
return typeof value === "boolean" || value instanceof Boolean;
|
|
2371
|
+
}
|
|
2372
|
+
__name(isBoolean, "isBoolean");
|
|
2373
|
+
|
|
2374
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/predicate/isFinite.mjs
|
|
2375
|
+
function isFinite(value) {
|
|
2376
|
+
return Number.isFinite(value);
|
|
2377
|
+
}
|
|
2378
|
+
__name(isFinite, "isFinite");
|
|
2379
|
+
|
|
2380
|
+
// node_modules/.pnpm/es-toolkit@1.39.8/node_modules/es-toolkit/dist/compat/predicate/isInteger.mjs
|
|
2381
|
+
function isInteger(value) {
|
|
2382
|
+
return Number.isInteger(value);
|
|
2383
|
+
}
|
|
2384
|
+
__name(isInteger, "isInteger");
|
|
2385
|
+
|
|
2386
|
+
// src/lib/utils.ts
|
|
2387
|
+
function getFieldMask(obj) {
|
|
2388
|
+
let fromGrid = "";
|
|
2389
|
+
const fromRoot = Object.keys(obj).filter((key) => key !== "gridProperties").join(",");
|
|
2390
|
+
if (obj.gridProperties) {
|
|
2391
|
+
fromGrid = Object.keys(obj.gridProperties).map((key) => `gridProperties.${key}`).join(",");
|
|
2392
|
+
if (fromGrid.length && fromRoot.length) {
|
|
2393
|
+
fromGrid = `${fromGrid},`;
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
return fromGrid + fromRoot;
|
|
2397
|
+
}
|
|
2398
|
+
__name(getFieldMask, "getFieldMask");
|
|
2399
|
+
function columnToLetter(column) {
|
|
2400
|
+
let temp;
|
|
2401
|
+
let letter = "";
|
|
2402
|
+
let col = column;
|
|
2403
|
+
while (col > 0) {
|
|
2404
|
+
temp = (col - 1) % 26;
|
|
2405
|
+
letter = String.fromCharCode(temp + 65) + letter;
|
|
2406
|
+
col = (col - temp - 1) / 26;
|
|
2407
|
+
}
|
|
2408
|
+
return letter;
|
|
2409
|
+
}
|
|
2410
|
+
__name(columnToLetter, "columnToLetter");
|
|
2411
|
+
function letterToColumn(letter) {
|
|
2412
|
+
let column = 0;
|
|
2413
|
+
const { length } = letter;
|
|
2414
|
+
for (let i = 0; i < length; i++) {
|
|
2415
|
+
column += (letter.charCodeAt(i) - 64) * 26 ** (length - i - 1);
|
|
2416
|
+
}
|
|
2417
|
+
return column;
|
|
2418
|
+
}
|
|
2419
|
+
__name(letterToColumn, "letterToColumn");
|
|
2420
|
+
function checkForDuplicateHeaders(headers) {
|
|
2421
|
+
const checkForDupes = groupBy2(headers);
|
|
2422
|
+
forEach(checkForDupes, (grouped, header) => {
|
|
2423
|
+
if (!header) return;
|
|
2424
|
+
if (grouped.length > 1) {
|
|
2425
|
+
throw new Error(`Duplicate header detected: "${header}". Please make sure all non-empty headers are unique`);
|
|
2426
|
+
}
|
|
2427
|
+
});
|
|
2428
|
+
}
|
|
2429
|
+
__name(checkForDuplicateHeaders, "checkForDuplicateHeaders");
|
|
2430
|
+
|
|
2431
|
+
// src/lib/GoogleSpreadsheetRow.ts
|
|
2432
|
+
var GoogleSpreadsheetRow = class {
|
|
2433
|
+
constructor(_worksheet, _rowNumber, _rawData) {
|
|
2434
|
+
this._worksheet = _worksheet;
|
|
2435
|
+
this._rowNumber = _rowNumber;
|
|
2436
|
+
this._rawData = _rawData;
|
|
2437
|
+
}
|
|
2438
|
+
static {
|
|
2439
|
+
__name(this, "GoogleSpreadsheetRow");
|
|
2440
|
+
}
|
|
2441
|
+
_deleted = false;
|
|
2442
|
+
get deleted() {
|
|
2443
|
+
return this._deleted;
|
|
2444
|
+
}
|
|
2445
|
+
/** row number (matches A1 notation, ie first row is 1) */
|
|
2446
|
+
get rowNumber() {
|
|
2447
|
+
return this._rowNumber;
|
|
2448
|
+
}
|
|
2449
|
+
/**
|
|
2450
|
+
* @internal
|
|
2451
|
+
* Used internally to update row numbers after deleting rows.
|
|
2452
|
+
* Should not be called directly.
|
|
2453
|
+
*/
|
|
2454
|
+
_updateRowNumber(newRowNumber) {
|
|
2455
|
+
this._rowNumber = newRowNumber;
|
|
2456
|
+
}
|
|
2457
|
+
get a1Range() {
|
|
2458
|
+
return [
|
|
2459
|
+
this._worksheet.a1SheetName,
|
|
2460
|
+
"!",
|
|
2461
|
+
`A${this._rowNumber}`,
|
|
2462
|
+
":",
|
|
2463
|
+
`${columnToLetter(this._worksheet.headerValues.length)}${this._rowNumber}`
|
|
2464
|
+
].join("");
|
|
2465
|
+
}
|
|
2466
|
+
/** get row's value of specific cell (by header key) */
|
|
2467
|
+
get(key) {
|
|
2468
|
+
const index = this._worksheet.headerValues.indexOf(key);
|
|
2469
|
+
return this._rawData[index];
|
|
2470
|
+
}
|
|
2471
|
+
/** set row's value of specific cell (by header key) */
|
|
2472
|
+
set(key, val) {
|
|
2473
|
+
const index = this._worksheet.headerValues.indexOf(key);
|
|
2474
|
+
this._rawData[index] = val;
|
|
2475
|
+
}
|
|
2476
|
+
/** set multiple values in the row at once from an object */
|
|
2477
|
+
assign(obj) {
|
|
2478
|
+
for (const key in obj) this.set(key, obj[key]);
|
|
2479
|
+
}
|
|
2480
|
+
/** return raw object of row data */
|
|
2481
|
+
toObject() {
|
|
2482
|
+
const o = {};
|
|
2483
|
+
for (let i = 0; i < this._worksheet.headerValues.length; i++) {
|
|
2484
|
+
const key = this._worksheet.headerValues[i];
|
|
2485
|
+
if (!key) continue;
|
|
2486
|
+
o[key] = this._rawData[i];
|
|
2487
|
+
}
|
|
2488
|
+
return o;
|
|
2489
|
+
}
|
|
2490
|
+
/** save row values */
|
|
2491
|
+
async save(options) {
|
|
2492
|
+
if (this._deleted) throw new Error("This row has been deleted - call getRows again before making updates.");
|
|
2493
|
+
const response = await this._worksheet._spreadsheet.sheetsApi.put(`values/${encodeURIComponent(this.a1Range)}`, {
|
|
2494
|
+
searchParams: {
|
|
2495
|
+
valueInputOption: options?.raw ? "RAW" : "USER_ENTERED",
|
|
2496
|
+
includeValuesInResponse: true
|
|
2497
|
+
},
|
|
2498
|
+
json: {
|
|
2499
|
+
range: this.a1Range,
|
|
2500
|
+
majorDimension: "ROWS",
|
|
2501
|
+
values: [this._rawData]
|
|
2502
|
+
}
|
|
2503
|
+
});
|
|
2504
|
+
const data = await response.json();
|
|
2505
|
+
this._rawData = data.updatedData.values[0];
|
|
2506
|
+
}
|
|
2507
|
+
/** delete this row */
|
|
2508
|
+
async delete() {
|
|
2509
|
+
if (this._deleted) throw new Error("This row has been deleted - call getRows again before making updates.");
|
|
2510
|
+
const result = await this._worksheet._makeSingleUpdateRequest("deleteRange", {
|
|
2511
|
+
range: {
|
|
2512
|
+
sheetId: this._worksheet.sheetId,
|
|
2513
|
+
startRowIndex: this._rowNumber - 1,
|
|
2514
|
+
// this format is zero indexed, because of course...
|
|
2515
|
+
endRowIndex: this._rowNumber
|
|
2516
|
+
},
|
|
2517
|
+
shiftDimension: "ROWS"
|
|
2518
|
+
});
|
|
2519
|
+
this._deleted = true;
|
|
2520
|
+
this._worksheet._shiftRowCache(this.rowNumber);
|
|
2521
|
+
return result;
|
|
2522
|
+
}
|
|
2523
|
+
/**
|
|
2524
|
+
* @internal
|
|
2525
|
+
* Used internally to clear row data after calling sheet.clearRows
|
|
2526
|
+
* Should not be called directly.
|
|
2527
|
+
*/
|
|
2528
|
+
_clearRowData() {
|
|
2529
|
+
for (let i = 0; i < this._rawData.length; i++) {
|
|
2530
|
+
this._rawData[i] = "";
|
|
2531
|
+
}
|
|
2532
|
+
}
|
|
2533
|
+
};
|
|
2534
|
+
|
|
2535
|
+
// src/lib/GoogleSpreadsheetCellErrorValue.ts
|
|
2536
|
+
var GoogleSpreadsheetCellErrorValue = class {
|
|
2537
|
+
static {
|
|
2538
|
+
__name(this, "GoogleSpreadsheetCellErrorValue");
|
|
2539
|
+
}
|
|
2540
|
+
/**
|
|
2541
|
+
* type of the error
|
|
2542
|
+
* @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#ErrorType
|
|
2543
|
+
* */
|
|
2544
|
+
type;
|
|
2545
|
+
/** A message with more information about the error (in the spreadsheet's locale) */
|
|
2546
|
+
message;
|
|
2547
|
+
constructor(rawError) {
|
|
2548
|
+
this.type = rawError.type;
|
|
2549
|
+
this.message = rawError.message;
|
|
2550
|
+
}
|
|
2551
|
+
};
|
|
2552
|
+
|
|
2553
|
+
// src/lib/GoogleSpreadsheetCell.ts
|
|
2554
|
+
var GoogleSpreadsheetCell = class {
|
|
2555
|
+
constructor(_sheet, _rowIndex, _columnIndex, rawCellData) {
|
|
2556
|
+
this._sheet = _sheet;
|
|
2557
|
+
this._rowIndex = _rowIndex;
|
|
2558
|
+
this._columnIndex = _columnIndex;
|
|
2559
|
+
this._updateRawData(rawCellData);
|
|
2560
|
+
this._rawData = rawCellData;
|
|
2561
|
+
}
|
|
2562
|
+
static {
|
|
2563
|
+
__name(this, "GoogleSpreadsheetCell");
|
|
2564
|
+
}
|
|
2565
|
+
_rawData;
|
|
2566
|
+
_draftData = {};
|
|
2567
|
+
_error;
|
|
2568
|
+
// TODO: figure out how to deal with empty rawData
|
|
2569
|
+
// newData can be undefined/null if the cell is totally empty and unformatted
|
|
2570
|
+
/**
|
|
2571
|
+
* update cell using raw CellData coming back from sheets API
|
|
2572
|
+
* @internal
|
|
2573
|
+
*/
|
|
2574
|
+
_updateRawData(newData) {
|
|
2575
|
+
this._rawData = newData;
|
|
2576
|
+
this._draftData = {};
|
|
2577
|
+
if (this._rawData?.effectiveValue && "errorValue" in this._rawData.effectiveValue) {
|
|
2578
|
+
this._error = new GoogleSpreadsheetCellErrorValue(this._rawData.effectiveValue.errorValue);
|
|
2579
|
+
} else {
|
|
2580
|
+
this._error = void 0;
|
|
2581
|
+
}
|
|
2582
|
+
}
|
|
2583
|
+
// CELL LOCATION/ADDRESS /////////////////////////////////////////////////////////////////////////
|
|
2584
|
+
get rowIndex() {
|
|
2585
|
+
return this._rowIndex;
|
|
2586
|
+
}
|
|
2587
|
+
get columnIndex() {
|
|
2588
|
+
return this._columnIndex;
|
|
2589
|
+
}
|
|
2590
|
+
get a1Column() {
|
|
2591
|
+
return columnToLetter(this._columnIndex + 1);
|
|
2592
|
+
}
|
|
2593
|
+
get a1Row() {
|
|
2594
|
+
return this._rowIndex + 1;
|
|
2595
|
+
}
|
|
2596
|
+
// a1 row numbers start at 1 instead of 0
|
|
2597
|
+
get a1Address() {
|
|
2598
|
+
return `${this.a1Column}${this.a1Row}`;
|
|
2599
|
+
}
|
|
2600
|
+
// CELL CONTENTS - VALUE/FORMULA/NOTES ///////////////////////////////////////////////////////////
|
|
2601
|
+
get value() {
|
|
2602
|
+
if (this._draftData.value !== void 0) throw new Error("Value has been changed");
|
|
2603
|
+
if (this._error) return this._error;
|
|
2604
|
+
if (!this._rawData?.effectiveValue) return null;
|
|
2605
|
+
return values(this._rawData.effectiveValue)[0];
|
|
2606
|
+
}
|
|
2607
|
+
set value(newValue) {
|
|
2608
|
+
if (newValue instanceof GoogleSpreadsheetCellErrorValue) {
|
|
2609
|
+
throw new Error("You can't manually set a value to an error");
|
|
2610
|
+
}
|
|
2611
|
+
if (isBoolean(newValue)) {
|
|
2612
|
+
this._draftData.valueType = "boolValue";
|
|
2613
|
+
} else if (isString(newValue)) {
|
|
2614
|
+
if (newValue.substring(0, 1) === "=") this._draftData.valueType = "formulaValue";
|
|
2615
|
+
else this._draftData.valueType = "stringValue";
|
|
2616
|
+
} else if (isFinite(newValue)) {
|
|
2617
|
+
this._draftData.valueType = "numberValue";
|
|
2618
|
+
} else if (isNil(newValue)) {
|
|
2619
|
+
this._draftData.valueType = "stringValue";
|
|
2620
|
+
newValue = "";
|
|
2621
|
+
} else {
|
|
2622
|
+
throw new Error("Set value to boolean, string, or number");
|
|
2623
|
+
}
|
|
2624
|
+
this._draftData.value = newValue;
|
|
2625
|
+
}
|
|
2626
|
+
get valueType() {
|
|
2627
|
+
if (this._error) return "errorValue";
|
|
2628
|
+
if (!this._rawData?.effectiveValue) return null;
|
|
2629
|
+
return keys(this._rawData.effectiveValue)[0];
|
|
2630
|
+
}
|
|
2631
|
+
/** The formatted value of the cell - this is the value as it's shown to the user */
|
|
2632
|
+
get formattedValue() {
|
|
2633
|
+
return this._rawData?.formattedValue || null;
|
|
2634
|
+
}
|
|
2635
|
+
get formula() {
|
|
2636
|
+
return get(this._rawData, "userEnteredValue.formulaValue", null);
|
|
2637
|
+
}
|
|
2638
|
+
set formula(newValue) {
|
|
2639
|
+
if (!newValue) throw new Error("To clear a formula, set `cell.value = null`");
|
|
2640
|
+
if (newValue.substring(0, 1) !== "=") throw new Error('formula must begin with "="');
|
|
2641
|
+
this.value = newValue;
|
|
2642
|
+
}
|
|
2643
|
+
/**
|
|
2644
|
+
* @deprecated use `cell.errorValue` instead
|
|
2645
|
+
*/
|
|
2646
|
+
get formulaError() {
|
|
2647
|
+
return this._error;
|
|
2648
|
+
}
|
|
2649
|
+
/**
|
|
2650
|
+
* error contained in the cell, which can happen with a bad formula (maybe some other weird cases?)
|
|
2651
|
+
*/
|
|
2652
|
+
get errorValue() {
|
|
2653
|
+
return this._error;
|
|
2654
|
+
}
|
|
2655
|
+
get numberValue() {
|
|
2656
|
+
if (this.valueType !== "numberValue") return void 0;
|
|
2657
|
+
return this.value;
|
|
2658
|
+
}
|
|
2659
|
+
set numberValue(val) {
|
|
2660
|
+
this.value = val;
|
|
2661
|
+
}
|
|
2662
|
+
get boolValue() {
|
|
2663
|
+
if (this.valueType !== "boolValue") return void 0;
|
|
2664
|
+
return this.value;
|
|
2665
|
+
}
|
|
2666
|
+
set boolValue(val) {
|
|
2667
|
+
this.value = val;
|
|
2668
|
+
}
|
|
2669
|
+
get stringValue() {
|
|
2670
|
+
if (this.valueType !== "stringValue") return void 0;
|
|
2671
|
+
return this.value;
|
|
2672
|
+
}
|
|
2673
|
+
set stringValue(val) {
|
|
2674
|
+
if (val?.startsWith("=")) {
|
|
2675
|
+
throw new Error("Use cell.formula to set formula values");
|
|
2676
|
+
}
|
|
2677
|
+
this.value = val;
|
|
2678
|
+
}
|
|
2679
|
+
/**
|
|
2680
|
+
* Hyperlink contained within the cell.
|
|
2681
|
+
*
|
|
2682
|
+
* To modify, do not set directly. Instead set cell.formula, for example `cell.formula = \'=HYPERLINK("http://google.com", "Google")\'`
|
|
2683
|
+
*/
|
|
2684
|
+
get hyperlink() {
|
|
2685
|
+
if (this._draftData.value) throw new Error("Save cell to be able to read hyperlink");
|
|
2686
|
+
return this._rawData?.hyperlink;
|
|
2687
|
+
}
|
|
2688
|
+
/** a note attached to the cell */
|
|
2689
|
+
get note() {
|
|
2690
|
+
return this._draftData.note !== void 0 ? this._draftData.note : this._rawData?.note || "";
|
|
2691
|
+
}
|
|
2692
|
+
set note(newVal) {
|
|
2693
|
+
if (newVal === null || newVal === void 0 || newVal === false) newVal = "";
|
|
2694
|
+
if (!isString(newVal)) throw new Error("Note must be a string");
|
|
2695
|
+
if (newVal === this._rawData?.note) delete this._draftData.note;
|
|
2696
|
+
else this._draftData.note = newVal;
|
|
2697
|
+
}
|
|
2698
|
+
// CELL FORMATTING ///////////////////////////////////////////////////////////////////////////////
|
|
2699
|
+
get userEnteredFormat() {
|
|
2700
|
+
return Object.freeze(this._rawData?.userEnteredFormat);
|
|
2701
|
+
}
|
|
2702
|
+
get effectiveFormat() {
|
|
2703
|
+
return Object.freeze(this._rawData?.effectiveFormat);
|
|
2704
|
+
}
|
|
2705
|
+
_getFormatParam(param) {
|
|
2706
|
+
if (get(this._draftData, `userEnteredFormat.${param}`)) {
|
|
2707
|
+
throw new Error("User format is unsaved - save the cell to be able to read it again");
|
|
2708
|
+
}
|
|
2709
|
+
return Object.freeze(this._rawData.userEnteredFormat[param]);
|
|
2710
|
+
}
|
|
2711
|
+
_setFormatParam(param, newVal) {
|
|
2712
|
+
if (isEqual(newVal, get(this._rawData, `userEnteredFormat.${param}`))) {
|
|
2713
|
+
unset(this._draftData, `userEnteredFormat.${param}`);
|
|
2714
|
+
} else {
|
|
2715
|
+
set(this._draftData, `userEnteredFormat.${param}`, newVal);
|
|
2716
|
+
this._draftData.clearFormat = false;
|
|
2717
|
+
}
|
|
2718
|
+
}
|
|
2719
|
+
// format getters
|
|
2720
|
+
get numberFormat() {
|
|
2721
|
+
return this._getFormatParam("numberFormat");
|
|
2722
|
+
}
|
|
2723
|
+
get backgroundColor() {
|
|
2724
|
+
return this._getFormatParam("backgroundColor");
|
|
2725
|
+
}
|
|
2726
|
+
get backgroundColorStyle() {
|
|
2727
|
+
return this._getFormatParam("backgroundColorStyle");
|
|
2728
|
+
}
|
|
2729
|
+
get borders() {
|
|
2730
|
+
return this._getFormatParam("borders");
|
|
2731
|
+
}
|
|
2732
|
+
get padding() {
|
|
2733
|
+
return this._getFormatParam("padding");
|
|
2734
|
+
}
|
|
2735
|
+
get horizontalAlignment() {
|
|
2736
|
+
return this._getFormatParam("horizontalAlignment");
|
|
2737
|
+
}
|
|
2738
|
+
get verticalAlignment() {
|
|
2739
|
+
return this._getFormatParam("verticalAlignment");
|
|
2740
|
+
}
|
|
2741
|
+
get wrapStrategy() {
|
|
2742
|
+
return this._getFormatParam("wrapStrategy");
|
|
2743
|
+
}
|
|
2744
|
+
get textDirection() {
|
|
2745
|
+
return this._getFormatParam("textDirection");
|
|
2746
|
+
}
|
|
2747
|
+
get textFormat() {
|
|
2748
|
+
return this._getFormatParam("textFormat");
|
|
2749
|
+
}
|
|
2750
|
+
get hyperlinkDisplayType() {
|
|
2751
|
+
return this._getFormatParam("hyperlinkDisplayType");
|
|
2752
|
+
}
|
|
2753
|
+
get textRotation() {
|
|
2754
|
+
return this._getFormatParam("textRotation");
|
|
2755
|
+
}
|
|
2756
|
+
// format setters
|
|
2757
|
+
set numberFormat(newVal) {
|
|
2758
|
+
this._setFormatParam("numberFormat", newVal);
|
|
2759
|
+
}
|
|
2760
|
+
set backgroundColor(newVal) {
|
|
2761
|
+
this._setFormatParam("backgroundColor", newVal);
|
|
2762
|
+
}
|
|
2763
|
+
set backgroundColorStyle(newVal) {
|
|
2764
|
+
this._setFormatParam("backgroundColorStyle", newVal);
|
|
2765
|
+
}
|
|
2766
|
+
set borders(newVal) {
|
|
2767
|
+
this._setFormatParam("borders", newVal);
|
|
2768
|
+
}
|
|
2769
|
+
set padding(newVal) {
|
|
2770
|
+
this._setFormatParam("padding", newVal);
|
|
2771
|
+
}
|
|
2772
|
+
set horizontalAlignment(newVal) {
|
|
2773
|
+
this._setFormatParam("horizontalAlignment", newVal);
|
|
2774
|
+
}
|
|
2775
|
+
set verticalAlignment(newVal) {
|
|
2776
|
+
this._setFormatParam("verticalAlignment", newVal);
|
|
2777
|
+
}
|
|
2778
|
+
set wrapStrategy(newVal) {
|
|
2779
|
+
this._setFormatParam("wrapStrategy", newVal);
|
|
2780
|
+
}
|
|
2781
|
+
set textDirection(newVal) {
|
|
2782
|
+
this._setFormatParam("textDirection", newVal);
|
|
2783
|
+
}
|
|
2784
|
+
set textFormat(newVal) {
|
|
2785
|
+
this._setFormatParam("textFormat", newVal);
|
|
2786
|
+
}
|
|
2787
|
+
set hyperlinkDisplayType(newVal) {
|
|
2788
|
+
this._setFormatParam("hyperlinkDisplayType", newVal);
|
|
2789
|
+
}
|
|
2790
|
+
set textRotation(newVal) {
|
|
2791
|
+
this._setFormatParam("textRotation", newVal);
|
|
2792
|
+
}
|
|
2793
|
+
clearAllFormatting() {
|
|
2794
|
+
this._draftData.clearFormat = true;
|
|
2795
|
+
delete this._draftData.userEnteredFormat;
|
|
2796
|
+
}
|
|
2797
|
+
// SAVING + UTILS ////////////////////////////////////////////////////////////////////////////////
|
|
2798
|
+
// returns true if there are any updates that have not been saved yet
|
|
2799
|
+
get _isDirty() {
|
|
2800
|
+
if (this._draftData.note !== void 0) return true;
|
|
2801
|
+
if (keys(this._draftData.userEnteredFormat).length) return true;
|
|
2802
|
+
if (this._draftData.clearFormat) return true;
|
|
2803
|
+
if (this._draftData.value !== void 0) return true;
|
|
2804
|
+
return false;
|
|
2805
|
+
}
|
|
2806
|
+
discardUnsavedChanges() {
|
|
2807
|
+
this._draftData = {};
|
|
2808
|
+
}
|
|
2809
|
+
/**
|
|
2810
|
+
* saves updates for single cell
|
|
2811
|
+
* usually it's better to make changes and call sheet.saveUpdatedCells
|
|
2812
|
+
* */
|
|
2813
|
+
async save() {
|
|
2814
|
+
await this._sheet.saveCells([this]);
|
|
2815
|
+
}
|
|
2816
|
+
/**
|
|
2817
|
+
* used by worksheet when saving cells
|
|
2818
|
+
* returns an individual batchUpdate request to update the cell
|
|
2819
|
+
* @internal
|
|
2820
|
+
*/
|
|
2821
|
+
_getUpdateRequest() {
|
|
2822
|
+
const isValueUpdated = this._draftData.value !== void 0;
|
|
2823
|
+
const isNoteUpdated = this._draftData.note !== void 0;
|
|
2824
|
+
const isFormatUpdated = !!keys(this._draftData.userEnteredFormat || {}).length;
|
|
2825
|
+
const isFormatCleared = this._draftData.clearFormat;
|
|
2826
|
+
if (!some([isValueUpdated, isNoteUpdated, isFormatUpdated, isFormatCleared])) {
|
|
2827
|
+
return null;
|
|
2828
|
+
}
|
|
2829
|
+
const format = {
|
|
2830
|
+
// have to pass the whole object or it will clear existing properties
|
|
2831
|
+
...this._rawData?.userEnteredFormat,
|
|
2832
|
+
...this._draftData.userEnteredFormat
|
|
2833
|
+
};
|
|
2834
|
+
if (get(this._draftData, "userEnteredFormat.backgroundColor")) {
|
|
2835
|
+
delete format.backgroundColorStyle;
|
|
2836
|
+
}
|
|
2837
|
+
return {
|
|
2838
|
+
updateCells: {
|
|
2839
|
+
rows: [{
|
|
2840
|
+
values: [{
|
|
2841
|
+
...isValueUpdated && {
|
|
2842
|
+
userEnteredValue: { [this._draftData.valueType]: this._draftData.value }
|
|
2843
|
+
},
|
|
2844
|
+
...isNoteUpdated && {
|
|
2845
|
+
note: this._draftData.note
|
|
2846
|
+
},
|
|
2847
|
+
...isFormatUpdated && {
|
|
2848
|
+
userEnteredFormat: format
|
|
2849
|
+
},
|
|
2850
|
+
...isFormatCleared && {
|
|
2851
|
+
userEnteredFormat: {}
|
|
2852
|
+
}
|
|
2853
|
+
}]
|
|
2854
|
+
}],
|
|
2855
|
+
// turns into a string of which fields to update ex "note,userEnteredFormat"
|
|
2856
|
+
fields: keys(pickBy({
|
|
2857
|
+
userEnteredValue: isValueUpdated,
|
|
2858
|
+
note: isNoteUpdated,
|
|
2859
|
+
userEnteredFormat: isFormatUpdated || isFormatCleared
|
|
2860
|
+
})).join(","),
|
|
2861
|
+
start: {
|
|
2862
|
+
sheetId: this._sheet.sheetId,
|
|
2863
|
+
rowIndex: this.rowIndex,
|
|
2864
|
+
columnIndex: this.columnIndex
|
|
2865
|
+
}
|
|
2866
|
+
}
|
|
2867
|
+
};
|
|
2868
|
+
}
|
|
2869
|
+
};
|
|
2870
|
+
|
|
2871
|
+
// src/lib/GoogleSpreadsheetWorksheet.ts
|
|
2872
|
+
var GoogleSpreadsheetWorksheet = class {
|
|
2873
|
+
constructor(_spreadsheet, rawProperties, rawCellData) {
|
|
2874
|
+
this._spreadsheet = _spreadsheet;
|
|
2875
|
+
this._headerRowIndex = 1;
|
|
2876
|
+
this._rawProperties = rawProperties;
|
|
2877
|
+
this._cells = [];
|
|
2878
|
+
this._rowMetadata = [];
|
|
2879
|
+
this._columnMetadata = [];
|
|
2880
|
+
if (rawCellData) this._fillCellData(rawCellData);
|
|
2881
|
+
}
|
|
2882
|
+
static {
|
|
2883
|
+
__name(this, "GoogleSpreadsheetWorksheet");
|
|
2884
|
+
}
|
|
2885
|
+
// assume "header row" (for row-based calls) is in first row, can be adjusted later
|
|
2886
|
+
_headerRowIndex = 1;
|
|
2887
|
+
_rawProperties = null;
|
|
2888
|
+
_cells = [];
|
|
2889
|
+
_rowMetadata = [];
|
|
2890
|
+
_columnMetadata = [];
|
|
2891
|
+
_headerValues;
|
|
2892
|
+
get headerValues() {
|
|
2893
|
+
if (!this._headerValues) {
|
|
2894
|
+
throw new Error("Header values are not yet loaded");
|
|
2895
|
+
}
|
|
2896
|
+
return this._headerValues;
|
|
2897
|
+
}
|
|
2898
|
+
// INTERNAL UTILITY FUNCTIONS ////////////////////////////////////////////////////////////////////
|
|
2899
|
+
updateRawData(properties, rawCellData) {
|
|
2900
|
+
this._rawProperties = properties;
|
|
2901
|
+
this._fillCellData(rawCellData);
|
|
2902
|
+
}
|
|
2903
|
+
async _makeSingleUpdateRequest(requestType, requestParams) {
|
|
2904
|
+
return this._spreadsheet._makeSingleUpdateRequest(requestType, {
|
|
2905
|
+
...requestParams
|
|
2906
|
+
});
|
|
2907
|
+
}
|
|
2908
|
+
_ensureInfoLoaded() {
|
|
2909
|
+
if (!this._rawProperties) {
|
|
2910
|
+
throw new Error("You must call `doc.loadInfo()` again before accessing this property");
|
|
2911
|
+
}
|
|
2912
|
+
}
|
|
2913
|
+
/** clear local cache of sheet data/properties */
|
|
2914
|
+
resetLocalCache(dataOnly) {
|
|
2915
|
+
if (!dataOnly) this._rawProperties = null;
|
|
2916
|
+
this._headerValues = void 0;
|
|
2917
|
+
this._headerRowIndex = 1;
|
|
2918
|
+
this._cells = [];
|
|
2919
|
+
}
|
|
2920
|
+
_fillCellData(dataRanges) {
|
|
2921
|
+
forEach(dataRanges, (range2) => {
|
|
2922
|
+
const startRow = range2.startRow || 0;
|
|
2923
|
+
const startColumn = range2.startColumn || 0;
|
|
2924
|
+
const numRows = range2.rowMetadata.length;
|
|
2925
|
+
const numColumns = range2.columnMetadata.length;
|
|
2926
|
+
for (let i = 0; i < numRows; i++) {
|
|
2927
|
+
const actualRow = startRow + i;
|
|
2928
|
+
for (let j = 0; j < numColumns; j++) {
|
|
2929
|
+
const actualColumn = startColumn + j;
|
|
2930
|
+
if (!this._cells[actualRow]) this._cells[actualRow] = [];
|
|
2931
|
+
const cellData = get(range2, `rowData[${i}].values[${j}]`);
|
|
2932
|
+
if (this._cells[actualRow][actualColumn]) {
|
|
2933
|
+
this._cells[actualRow][actualColumn]._updateRawData(cellData);
|
|
2934
|
+
} else {
|
|
2935
|
+
this._cells[actualRow][actualColumn] = new GoogleSpreadsheetCell(
|
|
2936
|
+
this,
|
|
2937
|
+
actualRow,
|
|
2938
|
+
actualColumn,
|
|
2939
|
+
cellData
|
|
2940
|
+
);
|
|
2941
|
+
}
|
|
2942
|
+
}
|
|
2943
|
+
}
|
|
2944
|
+
for (let i = 0; i < range2.rowMetadata.length; i++) {
|
|
2945
|
+
this._rowMetadata[startRow + i] = range2.rowMetadata[i];
|
|
2946
|
+
}
|
|
2947
|
+
for (let i = 0; i < range2.columnMetadata.length; i++) {
|
|
2948
|
+
this._columnMetadata[startColumn + i] = range2.columnMetadata[i];
|
|
2949
|
+
}
|
|
2950
|
+
});
|
|
2951
|
+
}
|
|
2952
|
+
// TODO: make this handle A1 ranges as well?
|
|
2953
|
+
_addSheetIdToRange(range2) {
|
|
2954
|
+
if (range2.sheetId && range2.sheetId !== this.sheetId) {
|
|
2955
|
+
throw new Error("Leave sheet ID blank or set to matching ID of this sheet");
|
|
2956
|
+
}
|
|
2957
|
+
return {
|
|
2958
|
+
...range2,
|
|
2959
|
+
sheetId: this.sheetId
|
|
2960
|
+
};
|
|
2961
|
+
}
|
|
2962
|
+
// PROPERTY GETTERS //////////////////////////////////////////////////////////////////////////////
|
|
2963
|
+
_getProp(param) {
|
|
2964
|
+
this._ensureInfoLoaded();
|
|
2965
|
+
return this._rawProperties[param];
|
|
2966
|
+
}
|
|
2967
|
+
// eslint-disable-line no-unused-vars
|
|
2968
|
+
_setProp(_param, _newVal) {
|
|
2969
|
+
throw new Error("Do not update directly - use `updateProperties()`");
|
|
2970
|
+
}
|
|
2971
|
+
get sheetId() {
|
|
2972
|
+
return this._getProp("sheetId");
|
|
2973
|
+
}
|
|
2974
|
+
get title() {
|
|
2975
|
+
return this._getProp("title");
|
|
2976
|
+
}
|
|
2977
|
+
get index() {
|
|
2978
|
+
return this._getProp("index");
|
|
2979
|
+
}
|
|
2980
|
+
get sheetType() {
|
|
2981
|
+
return this._getProp("sheetType");
|
|
2982
|
+
}
|
|
2983
|
+
get gridProperties() {
|
|
2984
|
+
return this._getProp("gridProperties");
|
|
2985
|
+
}
|
|
2986
|
+
get hidden() {
|
|
2987
|
+
return this._getProp("hidden");
|
|
2988
|
+
}
|
|
2989
|
+
get tabColor() {
|
|
2990
|
+
return this._getProp("tabColor");
|
|
2991
|
+
}
|
|
2992
|
+
get rightToLeft() {
|
|
2993
|
+
return this._getProp("rightToLeft");
|
|
2994
|
+
}
|
|
2995
|
+
get _headerRange() {
|
|
2996
|
+
return `A${this._headerRowIndex}:${this.lastColumnLetter}${this._headerRowIndex}`;
|
|
2997
|
+
}
|
|
2998
|
+
set sheetId(newVal) {
|
|
2999
|
+
this._setProp("sheetId", newVal);
|
|
3000
|
+
}
|
|
3001
|
+
set title(newVal) {
|
|
3002
|
+
this._setProp("title", newVal);
|
|
3003
|
+
}
|
|
3004
|
+
set index(newVal) {
|
|
3005
|
+
this._setProp("index", newVal);
|
|
3006
|
+
}
|
|
3007
|
+
set sheetType(newVal) {
|
|
3008
|
+
this._setProp("sheetType", newVal);
|
|
3009
|
+
}
|
|
3010
|
+
set gridProperties(newVal) {
|
|
3011
|
+
this._setProp("gridProperties", newVal);
|
|
3012
|
+
}
|
|
3013
|
+
set hidden(newVal) {
|
|
3014
|
+
this._setProp("hidden", newVal);
|
|
3015
|
+
}
|
|
3016
|
+
set tabColor(newVal) {
|
|
3017
|
+
this._setProp("tabColor", newVal);
|
|
3018
|
+
}
|
|
3019
|
+
set rightToLeft(newVal) {
|
|
3020
|
+
this._setProp("rightToLeft", newVal);
|
|
3021
|
+
}
|
|
3022
|
+
get rowCount() {
|
|
3023
|
+
this._ensureInfoLoaded();
|
|
3024
|
+
return this.gridProperties.rowCount;
|
|
3025
|
+
}
|
|
3026
|
+
get columnCount() {
|
|
3027
|
+
this._ensureInfoLoaded();
|
|
3028
|
+
return this.gridProperties.columnCount;
|
|
3029
|
+
}
|
|
3030
|
+
get a1SheetName() {
|
|
3031
|
+
return `'${this.title.replace(/'/g, "''")}'`;
|
|
3032
|
+
}
|
|
3033
|
+
get encodedA1SheetName() {
|
|
3034
|
+
return encodeURIComponent(this.a1SheetName);
|
|
3035
|
+
}
|
|
3036
|
+
get lastColumnLetter() {
|
|
3037
|
+
return this.columnCount ? columnToLetter(this.columnCount) : "";
|
|
3038
|
+
}
|
|
3039
|
+
// CELLS-BASED INTERACTIONS //////////////////////////////////////////////////////////////////////
|
|
3040
|
+
get cellStats() {
|
|
3041
|
+
let allCells = flatten2(this._cells);
|
|
3042
|
+
allCells = compact2(allCells);
|
|
3043
|
+
return {
|
|
3044
|
+
nonEmpty: filter(allCells, (c) => c.value).length,
|
|
3045
|
+
loaded: allCells.length,
|
|
3046
|
+
total: this.rowCount * this.columnCount
|
|
3047
|
+
};
|
|
3048
|
+
}
|
|
3049
|
+
getCellByA1(a1Address) {
|
|
3050
|
+
const split = a1Address.match(/([A-Z]+)([0-9]+)/);
|
|
3051
|
+
if (!split) throw new Error(`Cell address "${a1Address}" not valid`);
|
|
3052
|
+
const columnIndex = letterToColumn(split[1]);
|
|
3053
|
+
const rowIndex = parseInt(split[2]);
|
|
3054
|
+
return this.getCell(rowIndex - 1, columnIndex - 1);
|
|
3055
|
+
}
|
|
3056
|
+
getCell(rowIndex, columnIndex) {
|
|
3057
|
+
if (rowIndex < 0 || columnIndex < 0) throw new Error("Min coordinate is 0, 0");
|
|
3058
|
+
if (rowIndex >= this.rowCount || columnIndex >= this.columnCount) {
|
|
3059
|
+
throw new Error(`Out of bounds, sheet is ${this.rowCount} by ${this.columnCount}`);
|
|
3060
|
+
}
|
|
3061
|
+
if (!get(this._cells, `[${rowIndex}][${columnIndex}]`)) {
|
|
3062
|
+
throw new Error("This cell has not been loaded yet");
|
|
3063
|
+
}
|
|
3064
|
+
return this._cells[rowIndex][columnIndex];
|
|
3065
|
+
}
|
|
3066
|
+
async loadCells(sheetFilters) {
|
|
3067
|
+
if (!sheetFilters) return this._spreadsheet.loadCells(this.a1SheetName);
|
|
3068
|
+
const filtersArray = isArray(sheetFilters) ? sheetFilters : [sheetFilters];
|
|
3069
|
+
const filtersArrayWithSheetId = map(filtersArray, (filter2) => {
|
|
3070
|
+
if (isString(filter2)) {
|
|
3071
|
+
if (filter2.startsWith(this.a1SheetName)) return filter2;
|
|
3072
|
+
return `${this.a1SheetName}!${filter2}`;
|
|
3073
|
+
}
|
|
3074
|
+
if (isObject2(filter2)) {
|
|
3075
|
+
const filterAny = filter2;
|
|
3076
|
+
if (filterAny.sheetId && filterAny.sheetId !== this.sheetId) {
|
|
3077
|
+
throw new Error("Leave sheet ID blank or set to matching ID of this sheet");
|
|
3078
|
+
}
|
|
3079
|
+
return { sheetId: this.sheetId, ...filter2 };
|
|
3080
|
+
}
|
|
3081
|
+
throw new Error("Each filter must be a A1 range string or gridrange object");
|
|
3082
|
+
});
|
|
3083
|
+
return this._spreadsheet.loadCells(filtersArrayWithSheetId);
|
|
3084
|
+
}
|
|
3085
|
+
async saveUpdatedCells() {
|
|
3086
|
+
const cellsToSave = filter(flatten2(this._cells), { _isDirty: true });
|
|
3087
|
+
if (cellsToSave.length) {
|
|
3088
|
+
await this.saveCells(cellsToSave);
|
|
3089
|
+
}
|
|
3090
|
+
}
|
|
3091
|
+
async saveCells(cellsToUpdate) {
|
|
3092
|
+
const requests = map(cellsToUpdate, (cell) => cell._getUpdateRequest());
|
|
3093
|
+
const responseRanges = map(cellsToUpdate, (c) => `${this.a1SheetName}!${c.a1Address}`);
|
|
3094
|
+
if (!compact2(requests).length) {
|
|
3095
|
+
throw new Error("At least one cell must have something to update");
|
|
3096
|
+
}
|
|
3097
|
+
await this._spreadsheet._makeBatchUpdateRequest(requests, responseRanges);
|
|
3098
|
+
}
|
|
3099
|
+
// SAVING THIS FOR FUTURE USE
|
|
3100
|
+
// puts the cells that need updating into batches
|
|
3101
|
+
// async updateCellsByBatches() {
|
|
3102
|
+
// // saving this code, but it's problematic because each group must have the same update fields
|
|
3103
|
+
// const cellsByRow = _.groupBy(cellsToUpdate, 'rowIndex');
|
|
3104
|
+
// const groupsToSave = [];
|
|
3105
|
+
// _.each(cellsByRow, (cells, rowIndex) => {
|
|
3106
|
+
// let cellGroup = [];
|
|
3107
|
+
// _.each(cells, (c) => {
|
|
3108
|
+
// if (!cellGroup.length) {
|
|
3109
|
+
// cellGroup.push(c);
|
|
3110
|
+
// } else if (
|
|
3111
|
+
// cellGroup[cellGroup.length - 1].columnIndex ===
|
|
3112
|
+
// c.columnIndex - 1
|
|
3113
|
+
// ) {
|
|
3114
|
+
// cellGroup.push(c);
|
|
3115
|
+
// } else {
|
|
3116
|
+
// groupsToSave.push(cellGroup);
|
|
3117
|
+
// cellGroup = [];
|
|
3118
|
+
// }
|
|
3119
|
+
// });
|
|
3120
|
+
// groupsToSave.push(cellGroup);
|
|
3121
|
+
// });
|
|
3122
|
+
// const requests = _.map(groupsToSave, (cellGroup) => ({
|
|
3123
|
+
// updateCells: {
|
|
3124
|
+
// rows: [
|
|
3125
|
+
// {
|
|
3126
|
+
// values: _.map(cellGroup, (cell) => ({
|
|
3127
|
+
// ...cell._draftData.value && {
|
|
3128
|
+
// userEnteredValue: { [cell._draftData.valueType]: cell._draftData.value },
|
|
3129
|
+
// },
|
|
3130
|
+
// ...cell._draftData.note !== undefined && {
|
|
3131
|
+
// note: cell._draftData.note ,
|
|
3132
|
+
// },
|
|
3133
|
+
// ...cell._draftData.userEnteredFormat && {
|
|
3134
|
+
// userEnteredValue: cell._draftData.userEnteredFormat,
|
|
3135
|
+
// },
|
|
3136
|
+
// })),
|
|
3137
|
+
// },
|
|
3138
|
+
// ],
|
|
3139
|
+
// fields: 'userEnteredValue,note,userEnteredFormat',
|
|
3140
|
+
// start: {
|
|
3141
|
+
// sheetId: this.sheetId,
|
|
3142
|
+
// rowIndex: cellGroup[0].rowIndex,
|
|
3143
|
+
// columnIndex: cellGroup[0].columnIndex,
|
|
3144
|
+
// },
|
|
3145
|
+
// },
|
|
3146
|
+
// }));
|
|
3147
|
+
// const responseRanges = _.map(groupsToSave, (cellGroup) => {
|
|
3148
|
+
// let a1Range = cellGroup[0].a1Address;
|
|
3149
|
+
// if (cellGroup.length > 1)
|
|
3150
|
+
// a1Range += `:${cellGroup[cellGroup.length - 1].a1Address}`;
|
|
3151
|
+
// return `${cellGroup[0]._sheet.a1SheetName}!${a1Range}`;
|
|
3152
|
+
// });
|
|
3153
|
+
// }
|
|
3154
|
+
// ROW BASED FUNCTIONS ///////////////////////////////////////////////////////////////////////////
|
|
3155
|
+
async _ensureHeaderRowLoaded() {
|
|
3156
|
+
if (!this._headerValues) {
|
|
3157
|
+
await this.loadHeaderRow();
|
|
3158
|
+
}
|
|
3159
|
+
}
|
|
3160
|
+
async loadHeaderRow(headerRowIndex) {
|
|
3161
|
+
if (headerRowIndex !== void 0) this._headerRowIndex = headerRowIndex;
|
|
3162
|
+
const rows = await this.getCellsInRange(this._headerRange);
|
|
3163
|
+
this._processHeaderRow(rows);
|
|
3164
|
+
}
|
|
3165
|
+
_processHeaderRow(rows) {
|
|
3166
|
+
if (!rows) {
|
|
3167
|
+
throw new Error("No values in the header row - fill the first row with header values before trying to interact with rows");
|
|
3168
|
+
}
|
|
3169
|
+
this._headerValues = map(rows[0], (header) => header?.trim());
|
|
3170
|
+
if (!compact2(this.headerValues).length) {
|
|
3171
|
+
throw new Error("All your header cells are blank - fill the first row with header values before trying to interact with rows");
|
|
3172
|
+
}
|
|
3173
|
+
checkForDuplicateHeaders(this.headerValues);
|
|
3174
|
+
}
|
|
3175
|
+
async setHeaderRow(headerValues, headerRowIndex) {
|
|
3176
|
+
if (!headerValues) return;
|
|
3177
|
+
if (headerValues.length > this.columnCount) {
|
|
3178
|
+
throw new Error(`Sheet is not large enough to fit ${headerValues.length} columns. Resize the sheet first.`);
|
|
3179
|
+
}
|
|
3180
|
+
const trimmedHeaderValues = map(headerValues, (h) => h?.trim());
|
|
3181
|
+
checkForDuplicateHeaders(trimmedHeaderValues);
|
|
3182
|
+
if (!compact2(trimmedHeaderValues).length) {
|
|
3183
|
+
throw new Error("All your header cells are blank -");
|
|
3184
|
+
}
|
|
3185
|
+
if (headerRowIndex) this._headerRowIndex = headerRowIndex;
|
|
3186
|
+
const response = await this._spreadsheet.sheetsApi.put(
|
|
3187
|
+
`values/${this.encodedA1SheetName}!${this._headerRowIndex}:${this._headerRowIndex}`,
|
|
3188
|
+
{
|
|
3189
|
+
searchParams: {
|
|
3190
|
+
valueInputOption: "USER_ENTERED",
|
|
3191
|
+
// other option is RAW
|
|
3192
|
+
includeValuesInResponse: true
|
|
3193
|
+
},
|
|
3194
|
+
json: {
|
|
3195
|
+
range: `${this.a1SheetName}!${this._headerRowIndex}:${this._headerRowIndex}`,
|
|
3196
|
+
majorDimension: "ROWS",
|
|
3197
|
+
values: [[
|
|
3198
|
+
...trimmedHeaderValues,
|
|
3199
|
+
// pad the rest of the row with empty values to clear them all out
|
|
3200
|
+
...times(this.columnCount - trimmedHeaderValues.length, () => "")
|
|
3201
|
+
]]
|
|
3202
|
+
}
|
|
3203
|
+
}
|
|
3204
|
+
);
|
|
3205
|
+
const data = await response.json();
|
|
3206
|
+
this._headerValues = data.updatedData.values[0];
|
|
3207
|
+
}
|
|
3208
|
+
// TODO: look at these types
|
|
3209
|
+
async addRows(rows, options = {}) {
|
|
3210
|
+
if (this.title.includes(":")) {
|
|
3211
|
+
throw new Error('Please remove the ":" from your sheet title. There is a bug with the google API which breaks appending rows if any colons are in the sheet title.');
|
|
3212
|
+
}
|
|
3213
|
+
if (!isArray(rows)) throw new Error("You must pass in an array of row values to append");
|
|
3214
|
+
await this._ensureHeaderRowLoaded();
|
|
3215
|
+
const rowsAsArrays = [];
|
|
3216
|
+
forEach(rows, (row) => {
|
|
3217
|
+
let rowAsArray;
|
|
3218
|
+
if (isArray(row)) {
|
|
3219
|
+
rowAsArray = row;
|
|
3220
|
+
} else if (isObject2(row)) {
|
|
3221
|
+
rowAsArray = [];
|
|
3222
|
+
for (let i = 0; i < this.headerValues.length; i++) {
|
|
3223
|
+
const propName = this.headerValues[i];
|
|
3224
|
+
rowAsArray[i] = row[propName];
|
|
3225
|
+
}
|
|
3226
|
+
} else {
|
|
3227
|
+
throw new Error("Each row must be an object or an array");
|
|
3228
|
+
}
|
|
3229
|
+
rowsAsArrays.push(rowAsArray);
|
|
3230
|
+
});
|
|
3231
|
+
const response = await this._spreadsheet.sheetsApi.post(
|
|
3232
|
+
`values/${this.encodedA1SheetName}!A${this._headerRowIndex}:append`,
|
|
3233
|
+
{
|
|
3234
|
+
searchParams: {
|
|
3235
|
+
valueInputOption: options.raw ? "RAW" : "USER_ENTERED",
|
|
3236
|
+
insertDataOption: options.insert ? "INSERT_ROWS" : "OVERWRITE",
|
|
3237
|
+
includeValuesInResponse: true
|
|
3238
|
+
},
|
|
3239
|
+
json: {
|
|
3240
|
+
values: rowsAsArrays
|
|
3241
|
+
}
|
|
3242
|
+
}
|
|
3243
|
+
);
|
|
3244
|
+
const data = await response.json();
|
|
3245
|
+
const { updatedRange } = data.updates;
|
|
3246
|
+
let rowNumber = updatedRange.match(/![A-Z]+([0-9]+):?/)[1];
|
|
3247
|
+
rowNumber = parseInt(rowNumber);
|
|
3248
|
+
this._ensureInfoLoaded();
|
|
3249
|
+
if (options.insert) {
|
|
3250
|
+
this._rawProperties.gridProperties.rowCount += rows.length;
|
|
3251
|
+
} else if (rowNumber + rows.length > this.rowCount) {
|
|
3252
|
+
this._rawProperties.gridProperties.rowCount = rowNumber + rows.length - 1;
|
|
3253
|
+
}
|
|
3254
|
+
return map(data.updates.updatedData.values, (rowValues) => {
|
|
3255
|
+
const row = new GoogleSpreadsheetRow(this, rowNumber++, rowValues);
|
|
3256
|
+
return row;
|
|
3257
|
+
});
|
|
3258
|
+
}
|
|
3259
|
+
/** add a single row - see addRows for more info */
|
|
3260
|
+
async addRow(rowValues, options) {
|
|
3261
|
+
const rows = await this.addRows([rowValues], options);
|
|
3262
|
+
return rows[0];
|
|
3263
|
+
}
|
|
3264
|
+
_rowCache = [];
|
|
3265
|
+
async getRows(options) {
|
|
3266
|
+
const offset = options?.offset || 0;
|
|
3267
|
+
const limit = options?.limit || this.rowCount - 1;
|
|
3268
|
+
const firstRow = 1 + this._headerRowIndex + offset;
|
|
3269
|
+
const lastRow = firstRow + limit - 1;
|
|
3270
|
+
let rawRows;
|
|
3271
|
+
if (this._headerValues) {
|
|
3272
|
+
const lastColumn = columnToLetter(this.headerValues.length);
|
|
3273
|
+
rawRows = await this.getCellsInRange(
|
|
3274
|
+
`A${firstRow}:${lastColumn}${lastRow}`
|
|
3275
|
+
);
|
|
3276
|
+
} else {
|
|
3277
|
+
const result = await this.batchGetCellsInRange([
|
|
3278
|
+
this._headerRange,
|
|
3279
|
+
`A${firstRow}:${this.lastColumnLetter}${lastRow}`
|
|
3280
|
+
]);
|
|
3281
|
+
this._processHeaderRow(result[0]);
|
|
3282
|
+
rawRows = result[1];
|
|
3283
|
+
}
|
|
3284
|
+
if (!rawRows) return [];
|
|
3285
|
+
const rows = [];
|
|
3286
|
+
let rowNum = firstRow;
|
|
3287
|
+
for (let i = 0; i < rawRows.length; i++) {
|
|
3288
|
+
const row = new GoogleSpreadsheetRow(this, rowNum++, rawRows[i]);
|
|
3289
|
+
this._rowCache[row.rowNumber] = row;
|
|
3290
|
+
rows.push(row);
|
|
3291
|
+
}
|
|
3292
|
+
return rows;
|
|
3293
|
+
}
|
|
3294
|
+
/**
|
|
3295
|
+
* @internal
|
|
3296
|
+
* Used internally to update row numbers after deleting rows.
|
|
3297
|
+
* Should not be called directly.
|
|
3298
|
+
* */
|
|
3299
|
+
_shiftRowCache(deletedRowNumber) {
|
|
3300
|
+
delete this._rowCache[deletedRowNumber];
|
|
3301
|
+
this._rowCache.forEach((row) => {
|
|
3302
|
+
if (row.rowNumber > deletedRowNumber) {
|
|
3303
|
+
row._updateRowNumber(row.rowNumber - 1);
|
|
3304
|
+
}
|
|
3305
|
+
});
|
|
3306
|
+
}
|
|
3307
|
+
async clearRows(options) {
|
|
3308
|
+
const startRowIndex = options?.start || this._headerRowIndex + 1;
|
|
3309
|
+
const endRowIndex = options?.end || this.rowCount;
|
|
3310
|
+
await this._spreadsheet.sheetsApi.post(`values/${this.encodedA1SheetName}!${startRowIndex}:${endRowIndex}:clear`);
|
|
3311
|
+
this._rowCache.forEach((row) => {
|
|
3312
|
+
if (row.rowNumber >= startRowIndex && row.rowNumber <= endRowIndex) row._clearRowData();
|
|
3313
|
+
});
|
|
3314
|
+
}
|
|
3315
|
+
// BASIC PROPS ///////////////////////////////////////////////////////////////////////////////////
|
|
3316
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#UpdateSheetPropertiesRequest */
|
|
3317
|
+
async updateProperties(properties) {
|
|
3318
|
+
return this._makeSingleUpdateRequest("updateSheetProperties", {
|
|
3319
|
+
properties: {
|
|
3320
|
+
sheetId: this.sheetId,
|
|
3321
|
+
...properties
|
|
3322
|
+
},
|
|
3323
|
+
fields: getFieldMask(properties)
|
|
3324
|
+
});
|
|
3325
|
+
}
|
|
3326
|
+
/**
|
|
3327
|
+
* passes through the call to updateProperties to update only the gridProperties object
|
|
3328
|
+
*/
|
|
3329
|
+
async updateGridProperties(gridProperties) {
|
|
3330
|
+
return this.updateProperties({ gridProperties });
|
|
3331
|
+
}
|
|
3332
|
+
/** resize, internally just calls updateGridProperties */
|
|
3333
|
+
async resize(gridProperties) {
|
|
3334
|
+
return this.updateGridProperties(gridProperties);
|
|
3335
|
+
}
|
|
3336
|
+
/**
|
|
3337
|
+
*
|
|
3338
|
+
* @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#updatedimensionpropertiesrequest
|
|
3339
|
+
*/
|
|
3340
|
+
async updateDimensionProperties(columnsOrRows, properties, bounds) {
|
|
3341
|
+
return this._makeSingleUpdateRequest("updateDimensionProperties", {
|
|
3342
|
+
range: {
|
|
3343
|
+
sheetId: this.sheetId,
|
|
3344
|
+
dimension: columnsOrRows,
|
|
3345
|
+
...bounds
|
|
3346
|
+
},
|
|
3347
|
+
properties,
|
|
3348
|
+
fields: getFieldMask(properties)
|
|
3349
|
+
});
|
|
3350
|
+
}
|
|
3351
|
+
// OTHER /////////////////////////////////////////////////////////////////////////////////////////
|
|
3352
|
+
// this uses the "values" getter and does not give all the info about the cell contents
|
|
3353
|
+
// it is used internally when loading header cells
|
|
3354
|
+
async getCellsInRange(a1Range, options) {
|
|
3355
|
+
const response = await this._spreadsheet.sheetsApi.get(`values/${this.encodedA1SheetName}!${a1Range}`, {
|
|
3356
|
+
searchParams: options
|
|
3357
|
+
});
|
|
3358
|
+
const data = await response.json();
|
|
3359
|
+
return data.values;
|
|
3360
|
+
}
|
|
3361
|
+
async batchGetCellsInRange(a1Ranges, options) {
|
|
3362
|
+
const ranges = a1Ranges.map((r) => `ranges=${this.encodedA1SheetName}!${r}`).join("&");
|
|
3363
|
+
const response = await this._spreadsheet.sheetsApi.get(`values:batchGet?${ranges}`, {
|
|
3364
|
+
searchParams: options
|
|
3365
|
+
});
|
|
3366
|
+
const data = await response.json();
|
|
3367
|
+
return data.valueRanges.map((r) => r.values);
|
|
3368
|
+
}
|
|
3369
|
+
async updateNamedRange() {
|
|
3370
|
+
}
|
|
3371
|
+
async addNamedRange() {
|
|
3372
|
+
}
|
|
3373
|
+
async deleteNamedRange() {
|
|
3374
|
+
}
|
|
3375
|
+
async repeatCell() {
|
|
3376
|
+
}
|
|
3377
|
+
async autoFill() {
|
|
3378
|
+
}
|
|
3379
|
+
async cutPaste() {
|
|
3380
|
+
}
|
|
3381
|
+
async copyPaste() {
|
|
3382
|
+
}
|
|
3383
|
+
// TODO: check types on these ranges
|
|
3384
|
+
/**
|
|
3385
|
+
* Merges all cells in the range
|
|
3386
|
+
* @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#MergeCellsRequest
|
|
3387
|
+
*/
|
|
3388
|
+
async mergeCells(range2, mergeType = "MERGE_ALL") {
|
|
3389
|
+
await this._makeSingleUpdateRequest("mergeCells", {
|
|
3390
|
+
mergeType,
|
|
3391
|
+
range: this._addSheetIdToRange(range2)
|
|
3392
|
+
});
|
|
3393
|
+
}
|
|
3394
|
+
/**
|
|
3395
|
+
* Unmerges cells in the given range
|
|
3396
|
+
* @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#UnmergeCellsRequest
|
|
3397
|
+
*/
|
|
3398
|
+
async unmergeCells(range2) {
|
|
3399
|
+
await this._makeSingleUpdateRequest("unmergeCells", {
|
|
3400
|
+
range: this._addSheetIdToRange(range2)
|
|
3401
|
+
});
|
|
3402
|
+
}
|
|
3403
|
+
async updateBorders() {
|
|
3404
|
+
}
|
|
3405
|
+
async addFilterView() {
|
|
3406
|
+
}
|
|
3407
|
+
async appendCells() {
|
|
3408
|
+
}
|
|
3409
|
+
async clearBasicFilter() {
|
|
3410
|
+
}
|
|
3411
|
+
async deleteDimension() {
|
|
3412
|
+
}
|
|
3413
|
+
async deleteEmbeddedObject() {
|
|
3414
|
+
}
|
|
3415
|
+
async deleteFilterView() {
|
|
3416
|
+
}
|
|
3417
|
+
async duplicateFilterView() {
|
|
3418
|
+
}
|
|
3419
|
+
/**
|
|
3420
|
+
* Duplicate worksheet within the document
|
|
3421
|
+
* @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#DuplicateSheetRequest
|
|
3422
|
+
*/
|
|
3423
|
+
async duplicate(options) {
|
|
3424
|
+
const response = await this._makeSingleUpdateRequest("duplicateSheet", {
|
|
3425
|
+
sourceSheetId: this.sheetId,
|
|
3426
|
+
...options?.index !== void 0 && { insertSheetIndex: options.index },
|
|
3427
|
+
...options?.id && { newSheetId: options.id },
|
|
3428
|
+
...options?.title && { newSheetName: options.title }
|
|
3429
|
+
});
|
|
3430
|
+
const newSheetId = response.properties.sheetId;
|
|
3431
|
+
return this._spreadsheet.sheetsById[newSheetId];
|
|
3432
|
+
}
|
|
3433
|
+
async findReplace() {
|
|
3434
|
+
}
|
|
3435
|
+
/**
|
|
3436
|
+
* Inserts rows or columns at a particular index
|
|
3437
|
+
* @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#InsertDimensionRequest
|
|
3438
|
+
*/
|
|
3439
|
+
async insertDimension(columnsOrRows, rangeIndexes, inheritFromBefore) {
|
|
3440
|
+
if (!columnsOrRows) throw new Error("You need to specify a dimension. i.e. COLUMNS|ROWS");
|
|
3441
|
+
if (!isObject2(rangeIndexes)) throw new Error("`range` must be an object containing `startIndex` and `endIndex`");
|
|
3442
|
+
if (!isInteger(rangeIndexes.startIndex) || rangeIndexes.startIndex < 0) throw new Error("range.startIndex must be an integer >=0");
|
|
3443
|
+
if (!isInteger(rangeIndexes.endIndex) || rangeIndexes.endIndex < 0) throw new Error("range.endIndex must be an integer >=0");
|
|
3444
|
+
if (rangeIndexes.endIndex <= rangeIndexes.startIndex) throw new Error("range.endIndex must be greater than range.startIndex");
|
|
3445
|
+
if (inheritFromBefore === void 0) {
|
|
3446
|
+
inheritFromBefore = rangeIndexes.startIndex > 0;
|
|
3447
|
+
}
|
|
3448
|
+
if (inheritFromBefore && rangeIndexes.startIndex === 0) {
|
|
3449
|
+
throw new Error("Cannot set inheritFromBefore to true if inserting in first row/column");
|
|
3450
|
+
}
|
|
3451
|
+
return this._makeSingleUpdateRequest("insertDimension", {
|
|
3452
|
+
range: {
|
|
3453
|
+
sheetId: this.sheetId,
|
|
3454
|
+
dimension: columnsOrRows,
|
|
3455
|
+
startIndex: rangeIndexes.startIndex,
|
|
3456
|
+
endIndex: rangeIndexes.endIndex
|
|
3457
|
+
},
|
|
3458
|
+
inheritFromBefore
|
|
3459
|
+
});
|
|
3460
|
+
}
|
|
3461
|
+
async insertRange() {
|
|
3462
|
+
}
|
|
3463
|
+
async moveDimension() {
|
|
3464
|
+
}
|
|
3465
|
+
async updateEmbeddedObjectPosition() {
|
|
3466
|
+
}
|
|
3467
|
+
async pasteData() {
|
|
3468
|
+
}
|
|
3469
|
+
async textToColumns() {
|
|
3470
|
+
}
|
|
3471
|
+
async updateFilterView() {
|
|
3472
|
+
}
|
|
3473
|
+
async deleteRange() {
|
|
3474
|
+
}
|
|
3475
|
+
async appendDimension() {
|
|
3476
|
+
}
|
|
3477
|
+
async addConditionalFormatRule() {
|
|
3478
|
+
}
|
|
3479
|
+
async updateConditionalFormatRule() {
|
|
3480
|
+
}
|
|
3481
|
+
async deleteConditionalFormatRule() {
|
|
3482
|
+
}
|
|
3483
|
+
async sortRange() {
|
|
3484
|
+
}
|
|
3485
|
+
/**
|
|
3486
|
+
* Sets (or unsets) a data validation rule to every cell in the range
|
|
3487
|
+
* @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#SetDataValidationRequest
|
|
3488
|
+
*/
|
|
3489
|
+
async setDataValidation(range2, rule) {
|
|
3490
|
+
return this._makeSingleUpdateRequest("setDataValidation", {
|
|
3491
|
+
range: {
|
|
3492
|
+
sheetId: this.sheetId,
|
|
3493
|
+
...range2
|
|
3494
|
+
},
|
|
3495
|
+
...rule && { rule }
|
|
3496
|
+
});
|
|
3497
|
+
}
|
|
3498
|
+
async setBasicFilter() {
|
|
3499
|
+
}
|
|
3500
|
+
async addProtectedRange() {
|
|
3501
|
+
}
|
|
3502
|
+
async updateProtectedRange() {
|
|
3503
|
+
}
|
|
3504
|
+
async deleteProtectedRange() {
|
|
3505
|
+
}
|
|
3506
|
+
async autoResizeDimensions() {
|
|
3507
|
+
}
|
|
3508
|
+
async addChart() {
|
|
3509
|
+
}
|
|
3510
|
+
async updateChartSpec() {
|
|
3511
|
+
}
|
|
3512
|
+
async updateBanding() {
|
|
3513
|
+
}
|
|
3514
|
+
async addBanding() {
|
|
3515
|
+
}
|
|
3516
|
+
async deleteBanding() {
|
|
3517
|
+
}
|
|
3518
|
+
async createDeveloperMetadata() {
|
|
3519
|
+
}
|
|
3520
|
+
async updateDeveloperMetadata() {
|
|
3521
|
+
}
|
|
3522
|
+
async deleteDeveloperMetadata() {
|
|
3523
|
+
}
|
|
3524
|
+
async randomizeRange() {
|
|
3525
|
+
}
|
|
3526
|
+
async addDimensionGroup() {
|
|
3527
|
+
}
|
|
3528
|
+
async deleteDimensionGroup() {
|
|
3529
|
+
}
|
|
3530
|
+
async updateDimensionGroup() {
|
|
3531
|
+
}
|
|
3532
|
+
async trimWhitespace() {
|
|
3533
|
+
}
|
|
3534
|
+
async deleteDuplicates() {
|
|
3535
|
+
}
|
|
3536
|
+
async addSlicer() {
|
|
3537
|
+
}
|
|
3538
|
+
async updateSlicerSpec() {
|
|
3539
|
+
}
|
|
3540
|
+
/** delete this worksheet */
|
|
3541
|
+
async delete() {
|
|
3542
|
+
return this._spreadsheet.deleteSheet(this.sheetId);
|
|
3543
|
+
}
|
|
3544
|
+
/**
|
|
3545
|
+
* copies this worksheet into another document/spreadsheet
|
|
3546
|
+
* @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.sheets/copyTo
|
|
3547
|
+
* */
|
|
3548
|
+
async copyToSpreadsheet(destinationSpreadsheetId) {
|
|
3549
|
+
const req = this._spreadsheet.sheetsApi.post(`sheets/${this.sheetId}:copyTo`, {
|
|
3550
|
+
json: {
|
|
3551
|
+
destinationSpreadsheetId
|
|
3552
|
+
}
|
|
3553
|
+
});
|
|
3554
|
+
const data = await req.json();
|
|
3555
|
+
return data;
|
|
3556
|
+
}
|
|
3557
|
+
/** clear data in the sheet - either the entire sheet or a specific range */
|
|
3558
|
+
async clear(a1Range) {
|
|
3559
|
+
const range2 = a1Range ? `!${a1Range}` : "";
|
|
3560
|
+
await this._spreadsheet.sheetsApi.post(`values/${this.encodedA1SheetName}${range2}:clear`);
|
|
3561
|
+
this.resetLocalCache(true);
|
|
3562
|
+
}
|
|
3563
|
+
async downloadAsCSV(returnStreamInsteadOfBuffer = false) {
|
|
3564
|
+
return this._spreadsheet._downloadAs("csv", this.sheetId, returnStreamInsteadOfBuffer);
|
|
3565
|
+
}
|
|
3566
|
+
async downloadAsTSV(returnStreamInsteadOfBuffer = false) {
|
|
3567
|
+
return this._spreadsheet._downloadAs("tsv", this.sheetId, returnStreamInsteadOfBuffer);
|
|
3568
|
+
}
|
|
3569
|
+
async downloadAsPDF(returnStreamInsteadOfBuffer = false) {
|
|
3570
|
+
return this._spreadsheet._downloadAs("pdf", this.sheetId, returnStreamInsteadOfBuffer);
|
|
3571
|
+
}
|
|
3572
|
+
};
|
|
3573
|
+
|
|
3574
|
+
// src/lib/GoogleSpreadsheet.ts
|
|
3575
|
+
var SHEETS_API_BASE_URL = "https://sheets.googleapis.com/v4/spreadsheets";
|
|
3576
|
+
var DRIVE_API_BASE_URL = "https://www.googleapis.com/drive/v3/files";
|
|
3577
|
+
var EXPORT_CONFIG = {
|
|
3578
|
+
html: {},
|
|
3579
|
+
zip: {},
|
|
3580
|
+
xlsx: {},
|
|
3581
|
+
ods: {},
|
|
3582
|
+
csv: { singleWorksheet: true },
|
|
3583
|
+
tsv: { singleWorksheet: true },
|
|
3584
|
+
pdf: { singleWorksheet: true }
|
|
3585
|
+
};
|
|
3586
|
+
function getAuthMode(auth) {
|
|
3587
|
+
if ("getRequestHeaders" in auth) return "google_auth" /* GOOGLE_AUTH_CLIENT */;
|
|
3588
|
+
if ("token" in auth && auth.token) return "raw_access_token" /* RAW_ACCESS_TOKEN */;
|
|
3589
|
+
if ("apiKey" in auth && auth.apiKey) return "api_key" /* API_KEY */;
|
|
3590
|
+
throw new Error("Invalid auth");
|
|
3591
|
+
}
|
|
3592
|
+
__name(getAuthMode, "getAuthMode");
|
|
3593
|
+
async function getRequestAuthConfig(auth) {
|
|
3594
|
+
if ("getRequestHeaders" in auth) {
|
|
3595
|
+
const headers = await auth.getRequestHeaders();
|
|
3596
|
+
if ("entries" in headers) {
|
|
3597
|
+
return { headers: Object.fromEntries(headers.entries()) };
|
|
3598
|
+
}
|
|
3599
|
+
if (isObject2(headers)) {
|
|
3600
|
+
return { headers };
|
|
3601
|
+
}
|
|
3602
|
+
throw new Error("unexpected headers returned from getRequestHeaders");
|
|
3603
|
+
}
|
|
3604
|
+
if ("apiKey" in auth && auth.apiKey) {
|
|
3605
|
+
return { searchParams: { key: auth.apiKey } };
|
|
3606
|
+
}
|
|
3607
|
+
if ("token" in auth && auth.token) {
|
|
3608
|
+
return { headers: { Authorization: `Bearer ${auth.token}` } };
|
|
3609
|
+
}
|
|
3610
|
+
throw new Error("Invalid auth");
|
|
3611
|
+
}
|
|
3612
|
+
__name(getRequestAuthConfig, "getRequestAuthConfig");
|
|
3613
|
+
var GoogleSpreadsheet = class _GoogleSpreadsheet {
|
|
3614
|
+
static {
|
|
3615
|
+
__name(this, "GoogleSpreadsheet");
|
|
3616
|
+
}
|
|
3617
|
+
spreadsheetId;
|
|
3618
|
+
auth;
|
|
3619
|
+
get authMode() {
|
|
3620
|
+
return getAuthMode(this.auth);
|
|
3621
|
+
}
|
|
3622
|
+
_rawSheets;
|
|
3623
|
+
_rawProperties = null;
|
|
3624
|
+
_spreadsheetUrl = null;
|
|
3625
|
+
_deleted = false;
|
|
3626
|
+
/**
|
|
3627
|
+
* Sheets API [ky](https://github.com/sindresorhus/ky?tab=readme-ov-file#kycreatedefaultoptions) instance
|
|
3628
|
+
* authentication is automatically attached
|
|
3629
|
+
* can be used if unsupported sheets calls need to be made
|
|
3630
|
+
* @see https://developers.google.com/sheets/api/reference/rest
|
|
3631
|
+
* */
|
|
3632
|
+
sheetsApi;
|
|
3633
|
+
/**
|
|
3634
|
+
* Drive API [ky](https://github.com/sindresorhus/ky?tab=readme-ov-file#kycreatedefaultoptions) instance
|
|
3635
|
+
* authentication automatically attached
|
|
3636
|
+
* can be used if unsupported drive calls need to be made
|
|
3637
|
+
* @topic permissions
|
|
3638
|
+
* @see https://developers.google.com/drive/api/v3/reference
|
|
3639
|
+
* */
|
|
3640
|
+
driveApi;
|
|
3641
|
+
/**
|
|
3642
|
+
* initialize new GoogleSpreadsheet
|
|
3643
|
+
* @category Initialization
|
|
3644
|
+
* */
|
|
3645
|
+
constructor(spreadsheetId, auth) {
|
|
3646
|
+
this.spreadsheetId = spreadsheetId;
|
|
3647
|
+
this.auth = auth;
|
|
3648
|
+
this._rawSheets = {};
|
|
3649
|
+
this._spreadsheetUrl = null;
|
|
3650
|
+
this.sheetsApi = distribution_default.create({
|
|
3651
|
+
prefixUrl: `${SHEETS_API_BASE_URL}/${spreadsheetId}`,
|
|
3652
|
+
hooks: {
|
|
3653
|
+
beforeRequest: [(r) => this._setAuthRequestHook(r)],
|
|
3654
|
+
beforeError: [(e) => this._errorHook(e)]
|
|
3655
|
+
}
|
|
3656
|
+
});
|
|
3657
|
+
this.driveApi = distribution_default.create({
|
|
3658
|
+
prefixUrl: `${DRIVE_API_BASE_URL}/${spreadsheetId}`,
|
|
3659
|
+
hooks: {
|
|
3660
|
+
beforeRequest: [(r) => this._setAuthRequestHook(r)],
|
|
3661
|
+
beforeError: [(e) => this._errorHook(e)]
|
|
3662
|
+
}
|
|
3663
|
+
});
|
|
3664
|
+
}
|
|
3665
|
+
// INTERNAL UTILITY FUNCTIONS ////////////////////////////////////////////////////////////////////
|
|
3666
|
+
/** @internal */
|
|
3667
|
+
async _setAuthRequestHook(req) {
|
|
3668
|
+
const authConfig = await getRequestAuthConfig(this.auth);
|
|
3669
|
+
if (authConfig.headers) {
|
|
3670
|
+
Object.entries(authConfig.headers).forEach(([key, val]) => {
|
|
3671
|
+
req.headers.set(key, String(val));
|
|
3672
|
+
});
|
|
3673
|
+
}
|
|
3674
|
+
if (authConfig.searchParams) {
|
|
3675
|
+
const url = new URL(req.url);
|
|
3676
|
+
Object.entries(authConfig.searchParams).forEach(([key, val]) => {
|
|
3677
|
+
url.searchParams.set(key, String(val));
|
|
3678
|
+
});
|
|
3679
|
+
return new Request(url, req);
|
|
3680
|
+
}
|
|
3681
|
+
return req;
|
|
3682
|
+
}
|
|
3683
|
+
/** @internal */
|
|
3684
|
+
async _errorHook(error) {
|
|
3685
|
+
const { response } = error;
|
|
3686
|
+
const errorDataText = await response?.text();
|
|
3687
|
+
let errorData;
|
|
3688
|
+
try {
|
|
3689
|
+
errorData = JSON.parse(errorDataText);
|
|
3690
|
+
} catch (e) {
|
|
3691
|
+
}
|
|
3692
|
+
if (errorData) {
|
|
3693
|
+
if (!errorData.error) return error;
|
|
3694
|
+
const { code, message } = errorData.error;
|
|
3695
|
+
error.message = `Google API error - [${code}] ${message}`;
|
|
3696
|
+
return error;
|
|
3697
|
+
}
|
|
3698
|
+
if (get(error, "response.status") === 403) {
|
|
3699
|
+
if ("apiKey" in this.auth) {
|
|
3700
|
+
throw new Error("Sheet is private. Use authentication or make public. (see https://github.com/theoephraim/node-google-spreadsheet#a-note-on-authentication for details)");
|
|
3701
|
+
}
|
|
3702
|
+
}
|
|
3703
|
+
return error;
|
|
3704
|
+
}
|
|
3705
|
+
/** @internal */
|
|
3706
|
+
async _makeSingleUpdateRequest(requestType, requestParams) {
|
|
3707
|
+
const response = await this.sheetsApi.post(":batchUpdate", {
|
|
3708
|
+
json: {
|
|
3709
|
+
requests: [{ [requestType]: requestParams }],
|
|
3710
|
+
includeSpreadsheetInResponse: true
|
|
3711
|
+
// responseRanges: [string]
|
|
3712
|
+
// responseIncludeGridData: true
|
|
3713
|
+
}
|
|
3714
|
+
});
|
|
3715
|
+
const data = await response.json();
|
|
3716
|
+
this._updateRawProperties(data.updatedSpreadsheet.properties);
|
|
3717
|
+
forEach(data.updatedSpreadsheet.sheets, (s) => this._updateOrCreateSheet(s));
|
|
3718
|
+
return data.replies[0][requestType];
|
|
3719
|
+
}
|
|
3720
|
+
// TODO: review these types
|
|
3721
|
+
// currently only used in batching cell updates
|
|
3722
|
+
/** @internal */
|
|
3723
|
+
async _makeBatchUpdateRequest(requests, responseRanges) {
|
|
3724
|
+
const response = await this.sheetsApi.post(":batchUpdate", {
|
|
3725
|
+
json: {
|
|
3726
|
+
requests,
|
|
3727
|
+
includeSpreadsheetInResponse: true,
|
|
3728
|
+
...responseRanges && {
|
|
3729
|
+
responseIncludeGridData: true,
|
|
3730
|
+
...responseRanges !== "*" && { responseRanges }
|
|
3731
|
+
}
|
|
3732
|
+
}
|
|
3733
|
+
});
|
|
3734
|
+
const data = await response.json();
|
|
3735
|
+
this._updateRawProperties(data.updatedSpreadsheet.properties);
|
|
3736
|
+
forEach(data.updatedSpreadsheet.sheets, (s) => this._updateOrCreateSheet(s));
|
|
3737
|
+
}
|
|
3738
|
+
/** @internal */
|
|
3739
|
+
_ensureInfoLoaded() {
|
|
3740
|
+
if (!this._rawProperties) throw new Error("You must call `doc.loadInfo()` before accessing this property");
|
|
3741
|
+
}
|
|
3742
|
+
/** @internal */
|
|
3743
|
+
_updateRawProperties(newProperties) {
|
|
3744
|
+
this._rawProperties = newProperties;
|
|
3745
|
+
}
|
|
3746
|
+
/** @internal */
|
|
3747
|
+
_updateOrCreateSheet(sheetInfo) {
|
|
3748
|
+
const { properties, data } = sheetInfo;
|
|
3749
|
+
const { sheetId } = properties;
|
|
3750
|
+
if (!this._rawSheets[sheetId]) {
|
|
3751
|
+
this._rawSheets[sheetId] = new GoogleSpreadsheetWorksheet(this, properties, data);
|
|
3752
|
+
} else {
|
|
3753
|
+
this._rawSheets[sheetId].updateRawData(properties, data);
|
|
3754
|
+
}
|
|
3755
|
+
}
|
|
3756
|
+
// BASIC PROPS //////////////////////////////////////////////////////////////////////////////
|
|
3757
|
+
_getProp(param) {
|
|
3758
|
+
this._ensureInfoLoaded();
|
|
3759
|
+
return this._rawProperties[param];
|
|
3760
|
+
}
|
|
3761
|
+
get title() {
|
|
3762
|
+
return this._getProp("title");
|
|
3763
|
+
}
|
|
3764
|
+
get locale() {
|
|
3765
|
+
return this._getProp("locale");
|
|
3766
|
+
}
|
|
3767
|
+
get timeZone() {
|
|
3768
|
+
return this._getProp("timeZone");
|
|
3769
|
+
}
|
|
3770
|
+
get autoRecalc() {
|
|
3771
|
+
return this._getProp("autoRecalc");
|
|
3772
|
+
}
|
|
3773
|
+
get defaultFormat() {
|
|
3774
|
+
return this._getProp("defaultFormat");
|
|
3775
|
+
}
|
|
3776
|
+
get spreadsheetTheme() {
|
|
3777
|
+
return this._getProp("spreadsheetTheme");
|
|
3778
|
+
}
|
|
3779
|
+
get iterativeCalculationSettings() {
|
|
3780
|
+
return this._getProp("iterativeCalculationSettings");
|
|
3781
|
+
}
|
|
3782
|
+
/**
|
|
3783
|
+
* update spreadsheet properties
|
|
3784
|
+
* @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets#SpreadsheetProperties
|
|
3785
|
+
* */
|
|
3786
|
+
async updateProperties(properties) {
|
|
3787
|
+
await this._makeSingleUpdateRequest("updateSpreadsheetProperties", {
|
|
3788
|
+
properties,
|
|
3789
|
+
fields: getFieldMask(properties)
|
|
3790
|
+
});
|
|
3791
|
+
}
|
|
3792
|
+
// BASIC INFO ////////////////////////////////////////////////////////////////////////////////////
|
|
3793
|
+
async loadInfo(includeCells = false) {
|
|
3794
|
+
const response = await this.sheetsApi.get("", {
|
|
3795
|
+
searchParams: {
|
|
3796
|
+
...includeCells && { includeGridData: true }
|
|
3797
|
+
}
|
|
3798
|
+
});
|
|
3799
|
+
const data = await response.json();
|
|
3800
|
+
this._spreadsheetUrl = data.spreadsheetUrl;
|
|
3801
|
+
this._rawProperties = data.properties;
|
|
3802
|
+
data.sheets?.forEach((s) => this._updateOrCreateSheet(s));
|
|
3803
|
+
}
|
|
3804
|
+
resetLocalCache() {
|
|
3805
|
+
this._rawProperties = null;
|
|
3806
|
+
this._rawSheets = {};
|
|
3807
|
+
}
|
|
3808
|
+
// WORKSHEETS ////////////////////////////////////////////////////////////////////////////////////
|
|
3809
|
+
get sheetCount() {
|
|
3810
|
+
this._ensureInfoLoaded();
|
|
3811
|
+
return values(this._rawSheets).length;
|
|
3812
|
+
}
|
|
3813
|
+
get sheetsById() {
|
|
3814
|
+
this._ensureInfoLoaded();
|
|
3815
|
+
return this._rawSheets;
|
|
3816
|
+
}
|
|
3817
|
+
get sheetsByIndex() {
|
|
3818
|
+
this._ensureInfoLoaded();
|
|
3819
|
+
return sortBy(this._rawSheets, "index");
|
|
3820
|
+
}
|
|
3821
|
+
get sheetsByTitle() {
|
|
3822
|
+
this._ensureInfoLoaded();
|
|
3823
|
+
return keyBy(this._rawSheets, "title");
|
|
3824
|
+
}
|
|
3825
|
+
/**
|
|
3826
|
+
* Add new worksheet to document
|
|
3827
|
+
* @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#AddSheetRequest
|
|
3828
|
+
* */
|
|
3829
|
+
async addSheet(properties = {}) {
|
|
3830
|
+
const response = await this._makeSingleUpdateRequest("addSheet", {
|
|
3831
|
+
properties: omit(properties, "headerValues", "headerRowIndex")
|
|
3832
|
+
});
|
|
3833
|
+
const newSheetId = response.properties.sheetId;
|
|
3834
|
+
const newSheet = this.sheetsById[newSheetId];
|
|
3835
|
+
if (properties.headerValues) {
|
|
3836
|
+
await newSheet.setHeaderRow(properties.headerValues, properties.headerRowIndex);
|
|
3837
|
+
}
|
|
3838
|
+
return newSheet;
|
|
3839
|
+
}
|
|
3840
|
+
/**
|
|
3841
|
+
* delete a worksheet
|
|
3842
|
+
* @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#DeleteSheetRequest
|
|
3843
|
+
* */
|
|
3844
|
+
async deleteSheet(sheetId) {
|
|
3845
|
+
await this._makeSingleUpdateRequest("deleteSheet", { sheetId });
|
|
3846
|
+
delete this._rawSheets[sheetId];
|
|
3847
|
+
}
|
|
3848
|
+
// NAMED RANGES //////////////////////////////////////////////////////////////////////////////////
|
|
3849
|
+
/**
|
|
3850
|
+
* create a new named range
|
|
3851
|
+
* @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#AddNamedRangeRequest
|
|
3852
|
+
*/
|
|
3853
|
+
async addNamedRange(name, range2, namedRangeId) {
|
|
3854
|
+
return this._makeSingleUpdateRequest("addNamedRange", {
|
|
3855
|
+
name,
|
|
3856
|
+
namedRangeId,
|
|
3857
|
+
range: range2
|
|
3858
|
+
});
|
|
3859
|
+
}
|
|
3860
|
+
/**
|
|
3861
|
+
* delete a named range
|
|
3862
|
+
* @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#DeleteNamedRangeRequest
|
|
3863
|
+
* */
|
|
3864
|
+
async deleteNamedRange(namedRangeId) {
|
|
3865
|
+
return this._makeSingleUpdateRequest("deleteNamedRange", { namedRangeId });
|
|
3866
|
+
}
|
|
3867
|
+
// LOADING CELLS /////////////////////////////////////////////////////////////////////////////////
|
|
3868
|
+
/** fetch cell data into local cache */
|
|
3869
|
+
async loadCells(filters) {
|
|
3870
|
+
const readOnlyMode = this.authMode === "api_key" /* API_KEY */;
|
|
3871
|
+
const filtersArray = isArray(filters) ? filters : [filters];
|
|
3872
|
+
const dataFilters = map(filtersArray, (filter2) => {
|
|
3873
|
+
if (isString(filter2)) {
|
|
3874
|
+
return readOnlyMode ? filter2 : { a1Range: filter2 };
|
|
3875
|
+
}
|
|
3876
|
+
if (isObject2(filter2)) {
|
|
3877
|
+
if (readOnlyMode) {
|
|
3878
|
+
throw new Error("Only A1 ranges are supported when fetching cells with read-only access (using only an API key)");
|
|
3879
|
+
}
|
|
3880
|
+
return { gridRange: filter2 };
|
|
3881
|
+
}
|
|
3882
|
+
throw new Error("Each filter must be an A1 range string or a gridrange object");
|
|
3883
|
+
});
|
|
3884
|
+
let result;
|
|
3885
|
+
if (this.authMode === "api_key" /* API_KEY */) {
|
|
3886
|
+
const params = new URLSearchParams();
|
|
3887
|
+
params.append("includeGridData", "true");
|
|
3888
|
+
dataFilters.forEach((singleFilter) => {
|
|
3889
|
+
if (!isString(singleFilter)) {
|
|
3890
|
+
throw new Error("Only A1 ranges are supported when fetching cells with read-only access (using only an API key)");
|
|
3891
|
+
}
|
|
3892
|
+
params.append("ranges", singleFilter);
|
|
3893
|
+
});
|
|
3894
|
+
result = await this.sheetsApi.get("", {
|
|
3895
|
+
searchParams: params
|
|
3896
|
+
});
|
|
3897
|
+
} else {
|
|
3898
|
+
result = await this.sheetsApi.post(":getByDataFilter", {
|
|
3899
|
+
json: {
|
|
3900
|
+
includeGridData: true,
|
|
3901
|
+
dataFilters
|
|
3902
|
+
}
|
|
3903
|
+
});
|
|
3904
|
+
}
|
|
3905
|
+
const data = await result?.json();
|
|
3906
|
+
forEach(data.sheets, (sheet) => {
|
|
3907
|
+
this._updateOrCreateSheet(sheet);
|
|
3908
|
+
});
|
|
3909
|
+
}
|
|
3910
|
+
// EXPORTING /////////////////////////////////////////////////////////////
|
|
3911
|
+
/**
|
|
3912
|
+
* export/download helper, not meant to be called directly (use downloadAsX methods on spreadsheet and worksheet instead)
|
|
3913
|
+
* @internal
|
|
3914
|
+
*/
|
|
3915
|
+
async _downloadAs(fileType, worksheetId, returnStreamInsteadOfBuffer) {
|
|
3916
|
+
if (!EXPORT_CONFIG[fileType]) throw new Error(`unsupported export fileType - ${fileType}`);
|
|
3917
|
+
if (EXPORT_CONFIG[fileType].singleWorksheet) {
|
|
3918
|
+
if (worksheetId === void 0) throw new Error(`Must specify worksheetId when exporting as ${fileType}`);
|
|
3919
|
+
} else if (worksheetId) throw new Error(`Cannot specify worksheetId when exporting as ${fileType}`);
|
|
3920
|
+
if (fileType === "html") fileType = "zip";
|
|
3921
|
+
if (!this._spreadsheetUrl) throw new Error("Cannot export sheet that is not fully loaded");
|
|
3922
|
+
const exportUrl = this._spreadsheetUrl.replace("edit", "export");
|
|
3923
|
+
const response = await this.sheetsApi.get(exportUrl, {
|
|
3924
|
+
prefixUrl: "",
|
|
3925
|
+
// unset baseUrl since we're not hitting the normal sheets API
|
|
3926
|
+
searchParams: {
|
|
3927
|
+
id: this.spreadsheetId,
|
|
3928
|
+
format: fileType,
|
|
3929
|
+
// worksheetId can be 0
|
|
3930
|
+
...worksheetId !== void 0 && { gid: worksheetId }
|
|
3931
|
+
}
|
|
3932
|
+
});
|
|
3933
|
+
if (returnStreamInsteadOfBuffer) {
|
|
3934
|
+
return response.body;
|
|
3935
|
+
}
|
|
3936
|
+
return response.arrayBuffer();
|
|
3937
|
+
}
|
|
3938
|
+
async downloadAsZippedHTML(returnStreamInsteadOfBuffer) {
|
|
3939
|
+
return this._downloadAs("html", void 0, returnStreamInsteadOfBuffer);
|
|
3940
|
+
}
|
|
3941
|
+
/**
|
|
3942
|
+
* @deprecated
|
|
3943
|
+
* use `doc.downloadAsZippedHTML()` instead
|
|
3944
|
+
* */
|
|
3945
|
+
async downloadAsHTML(returnStreamInsteadOfBuffer) {
|
|
3946
|
+
return this._downloadAs("html", void 0, returnStreamInsteadOfBuffer);
|
|
3947
|
+
}
|
|
3948
|
+
async downloadAsXLSX(returnStreamInsteadOfBuffer = false) {
|
|
3949
|
+
return this._downloadAs("xlsx", void 0, returnStreamInsteadOfBuffer);
|
|
3950
|
+
}
|
|
3951
|
+
async downloadAsODS(returnStreamInsteadOfBuffer = false) {
|
|
3952
|
+
return this._downloadAs("ods", void 0, returnStreamInsteadOfBuffer);
|
|
3953
|
+
}
|
|
3954
|
+
async delete() {
|
|
3955
|
+
await this.driveApi.delete("");
|
|
3956
|
+
this._deleted = true;
|
|
3957
|
+
}
|
|
3958
|
+
// PERMISSIONS ///////////////////////////////////////////////////////////////////////////////////
|
|
3959
|
+
/**
|
|
3960
|
+
* list all permissions entries for doc
|
|
3961
|
+
*/
|
|
3962
|
+
async listPermissions() {
|
|
3963
|
+
const listReq = await this.driveApi.get("permissions", {
|
|
3964
|
+
searchParams: {
|
|
3965
|
+
fields: "permissions(id,type,emailAddress,domain,role,displayName,photoLink,deleted)"
|
|
3966
|
+
}
|
|
3967
|
+
});
|
|
3968
|
+
const data = await listReq.json();
|
|
3969
|
+
return data.permissions;
|
|
3970
|
+
}
|
|
3971
|
+
async setPublicAccessLevel(role) {
|
|
3972
|
+
const permissions = await this.listPermissions();
|
|
3973
|
+
const existingPublicPermission = find(permissions, (p) => p.type === "anyone");
|
|
3974
|
+
if (role === false) {
|
|
3975
|
+
if (!existingPublicPermission) {
|
|
3976
|
+
return;
|
|
3977
|
+
}
|
|
3978
|
+
await this.driveApi.delete(`permissions/${existingPublicPermission.id}`);
|
|
3979
|
+
} else {
|
|
3980
|
+
await this.driveApi.post("permissions", {
|
|
3981
|
+
json: {
|
|
3982
|
+
role: role || "viewer",
|
|
3983
|
+
type: "anyone"
|
|
3984
|
+
}
|
|
3985
|
+
});
|
|
3986
|
+
}
|
|
3987
|
+
}
|
|
3988
|
+
/** share document to email or domain */
|
|
3989
|
+
async share(emailAddressOrDomain, opts) {
|
|
3990
|
+
let emailAddress;
|
|
3991
|
+
let domain;
|
|
3992
|
+
if (emailAddressOrDomain.includes("@")) {
|
|
3993
|
+
emailAddress = emailAddressOrDomain;
|
|
3994
|
+
} else {
|
|
3995
|
+
domain = emailAddressOrDomain;
|
|
3996
|
+
}
|
|
3997
|
+
const shareReq = await this.driveApi.post("permissions", {
|
|
3998
|
+
searchParams: {
|
|
3999
|
+
...opts?.emailMessage === false && { sendNotificationEmail: false },
|
|
4000
|
+
...isString(opts?.emailMessage) && { emailMessage: opts?.emailMessage },
|
|
4001
|
+
...opts?.role === "owner" && { transferOwnership: true }
|
|
4002
|
+
},
|
|
4003
|
+
json: {
|
|
4004
|
+
role: opts?.role || "writer",
|
|
4005
|
+
...emailAddress && {
|
|
4006
|
+
type: opts?.isGroup ? "group" : "user",
|
|
4007
|
+
emailAddress
|
|
4008
|
+
},
|
|
4009
|
+
...domain && {
|
|
4010
|
+
type: "domain",
|
|
4011
|
+
domain
|
|
4012
|
+
}
|
|
4013
|
+
}
|
|
4014
|
+
});
|
|
4015
|
+
return shareReq.json();
|
|
4016
|
+
}
|
|
4017
|
+
//
|
|
4018
|
+
// CREATE NEW DOC ////////////////////////////////////////////////////////////////////////////////
|
|
4019
|
+
static async createNewSpreadsheetDocument(auth, properties) {
|
|
4020
|
+
if (getAuthMode(auth) === "api_key" /* API_KEY */) {
|
|
4021
|
+
throw new Error("Cannot use api key only to create a new spreadsheet - it is only usable for read-only access of public docs");
|
|
4022
|
+
}
|
|
4023
|
+
const authConfig = await getRequestAuthConfig(auth);
|
|
4024
|
+
const response = await distribution_default.post(SHEETS_API_BASE_URL, {
|
|
4025
|
+
...authConfig,
|
|
4026
|
+
// has the auth header
|
|
4027
|
+
json: {
|
|
4028
|
+
properties
|
|
4029
|
+
}
|
|
4030
|
+
});
|
|
4031
|
+
const data = await response.json();
|
|
4032
|
+
const newSpreadsheet = new _GoogleSpreadsheet(data.spreadsheetId, auth);
|
|
4033
|
+
newSpreadsheet._spreadsheetUrl = data.spreadsheetUrl;
|
|
4034
|
+
newSpreadsheet._rawProperties = data.properties;
|
|
4035
|
+
forEach(data.sheets, (s) => newSpreadsheet._updateOrCreateSheet(s));
|
|
4036
|
+
return newSpreadsheet;
|
|
4037
|
+
}
|
|
4038
|
+
};
|
|
4039
|
+
/*! Bundled license information:
|
|
4040
|
+
|
|
4041
|
+
ky/distribution/index.js:
|
|
4042
|
+
(*! MIT License © Sindre Sorhus *)
|
|
4043
|
+
*/
|
|
4044
|
+
|
|
4045
|
+
export { GoogleSpreadsheet, GoogleSpreadsheetCell, GoogleSpreadsheetCellErrorValue, GoogleSpreadsheetRow, GoogleSpreadsheetWorksheet };
|
|
4046
|
+
//# sourceMappingURL=index.js.map
|
|
4047
|
+
//# sourceMappingURL=index.js.map
|