google-spreadsheet 5.0.2 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.cjs +1900 -1637
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1332 -816
- package/dist/index.d.ts +1332 -816
- package/dist/index.js +1872 -1632
- package/dist/index.js.map +1 -1
- package/package.json +21 -25
- package/src/lib/GoogleSpreadsheet.ts +21 -9
- package/src/lib/GoogleSpreadsheetCell.ts +24 -0
- package/src/lib/GoogleSpreadsheetRow.ts +10 -0
- package/src/lib/GoogleSpreadsheetWorksheet.ts +865 -138
- package/src/lib/types/sheets-types.ts +290 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "google-spreadsheet",
|
|
3
|
-
"version": "5.0
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "Google Sheets API -- simple interface to read/write data and manage sheets",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"google spreadsheets",
|
|
@@ -39,27 +39,37 @@
|
|
|
39
39
|
"src/index.ts",
|
|
40
40
|
"src/lib"
|
|
41
41
|
],
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsdown",
|
|
44
|
+
"dev": "tsdown --watch",
|
|
45
|
+
"docs:preview": "docsify serve docs",
|
|
46
|
+
"lint": "eslint ./ --ext .ts",
|
|
47
|
+
"lint:fix": "bun run lint --fix",
|
|
48
|
+
"nodev": "node -v",
|
|
49
|
+
"readme:copy": "echo \"<!-- DO NOT EDIT THIS FILE, EDIT MAIN README.md AND RUN \\`bun readme:copy\\` instead -->\n\n_Welcome to the docs site for_\n\" | cat - README.md > docs/README.md",
|
|
50
|
+
"test": "vitest",
|
|
51
|
+
"test:ci": "vitest run"
|
|
52
|
+
},
|
|
42
53
|
"dependencies": {
|
|
43
|
-
"es-toolkit": "^1.
|
|
44
|
-
"ky": "^1.
|
|
54
|
+
"es-toolkit": "^1.44.0",
|
|
55
|
+
"ky": "^1.14.3"
|
|
45
56
|
},
|
|
46
57
|
"devDependencies": {
|
|
47
|
-
"@changesets/cli": "^2.29.
|
|
48
|
-
"@types/node": "^
|
|
58
|
+
"@changesets/cli": "^2.29.8",
|
|
59
|
+
"@types/node": "^25.2.3",
|
|
49
60
|
"@typescript-eslint/eslint-plugin": "^5.59.7",
|
|
50
61
|
"@typescript-eslint/parser": "^5.59.7",
|
|
51
|
-
"auto-changelog": "^2.4.0",
|
|
52
62
|
"docsify-cli": "^4.4.4",
|
|
53
63
|
"eslint": "^8.41.0",
|
|
54
64
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
55
65
|
"eslint-config-airbnb-typescript": "^17.0.0",
|
|
56
66
|
"eslint-plugin-import": "^2.27.5",
|
|
57
67
|
"eslint-plugin-no-floating-promise": "^1.0.2",
|
|
58
|
-
"google-auth-library": "^10.
|
|
59
|
-
"
|
|
60
|
-
"typescript": "^5.
|
|
61
|
-
"varlock": "^0.
|
|
62
|
-
"vitest": "^
|
|
68
|
+
"google-auth-library": "^10.5.0",
|
|
69
|
+
"tsdown": "^0.20.3",
|
|
70
|
+
"typescript": "^5.9.3",
|
|
71
|
+
"varlock": "^0.2.2",
|
|
72
|
+
"vitest": "^4.0.18"
|
|
63
73
|
},
|
|
64
74
|
"peerDependencies": {
|
|
65
75
|
"google-auth-library": ">=8.8.0"
|
|
@@ -68,19 +78,5 @@
|
|
|
68
78
|
"google-auth-library": {
|
|
69
79
|
"optional": true
|
|
70
80
|
}
|
|
71
|
-
},
|
|
72
|
-
"volta": {
|
|
73
|
-
"node": "20.17.0"
|
|
74
|
-
},
|
|
75
|
-
"scripts": {
|
|
76
|
-
"build": "tsup",
|
|
77
|
-
"dev": "tsup --watch",
|
|
78
|
-
"docs:preview": "docsify serve docs",
|
|
79
|
-
"lint": "eslint ./ --ext .ts",
|
|
80
|
-
"lint:fix": "pnpm run lint --fix",
|
|
81
|
-
"nodev": "node -v",
|
|
82
|
-
"readme:copy": "echo \"<!-- DO NOT EDIT THIS FILE, EDIT MAIN README.md AND RUN \\`npm readme:copy\\` instead -->\n\n_Welcome to the docs site for_\n\" | cat - README.md > docs/README.md",
|
|
83
|
-
"test": "vitest",
|
|
84
|
-
"test:ci": "vitest run"
|
|
85
81
|
}
|
|
86
82
|
}
|
|
@@ -3,7 +3,8 @@ import * as _ from './toolkit';
|
|
|
3
3
|
import { GoogleSpreadsheetWorksheet } from './GoogleSpreadsheetWorksheet';
|
|
4
4
|
import { getFieldMask } from './utils';
|
|
5
5
|
import {
|
|
6
|
-
DataFilter, GridRange, NamedRangeId,
|
|
6
|
+
DataFilter, GridRange, NamedRangeId, ProtectedRange,
|
|
7
|
+
SpreadsheetId, SpreadsheetProperties, WorksheetId, WorksheetProperties,
|
|
7
8
|
} from './types/sheets-types';
|
|
8
9
|
import { PermissionRoles, PermissionsList, PublicPermissionRoles } from './types/drive-types';
|
|
9
10
|
import { RecursivePartial } from './types/util-types';
|
|
@@ -125,6 +126,7 @@ export class GoogleSpreadsheet {
|
|
|
125
126
|
// create a ky instance with sheet root URL and hooks to handle auth
|
|
126
127
|
this.sheetsApi = ky.create({
|
|
127
128
|
prefixUrl: `${SHEETS_API_BASE_URL}/${spreadsheetId}`,
|
|
129
|
+
timeout: 180_000,
|
|
128
130
|
hooks: {
|
|
129
131
|
beforeRequest: [(r) => this._setAuthRequestHook(r)],
|
|
130
132
|
beforeError: [(e) => this._errorHook(e)],
|
|
@@ -143,7 +145,7 @@ export class GoogleSpreadsheet {
|
|
|
143
145
|
// INTERNAL UTILITY FUNCTIONS ////////////////////////////////////////////////////////////////////
|
|
144
146
|
|
|
145
147
|
/** @internal */
|
|
146
|
-
async _setAuthRequestHook(req: Request) {
|
|
148
|
+
async _setAuthRequestHook(req: Request): Promise<Request> {
|
|
147
149
|
const authConfig = await getRequestAuthConfig(this.auth);
|
|
148
150
|
if (authConfig.headers) {
|
|
149
151
|
Object.entries(authConfig.headers).forEach(([key, val]) => {
|
|
@@ -239,13 +241,13 @@ export class GoogleSpreadsheet {
|
|
|
239
241
|
_updateRawProperties(newProperties: SpreadsheetProperties) { this._rawProperties = newProperties; }
|
|
240
242
|
|
|
241
243
|
/** @internal */
|
|
242
|
-
_updateOrCreateSheet(sheetInfo: { properties: WorksheetProperties, data: any }) {
|
|
243
|
-
const { properties, data } = sheetInfo;
|
|
244
|
+
_updateOrCreateSheet(sheetInfo: { properties: WorksheetProperties, data: any, protectedRanges?: ProtectedRange[] }) {
|
|
245
|
+
const { properties, data, protectedRanges } = sheetInfo;
|
|
244
246
|
const { sheetId } = properties;
|
|
245
247
|
if (!this._rawSheets[sheetId]) {
|
|
246
|
-
this._rawSheets[sheetId] = new GoogleSpreadsheetWorksheet(this, properties, data);
|
|
248
|
+
this._rawSheets[sheetId] = new GoogleSpreadsheetWorksheet(this, properties, data, protectedRanges);
|
|
247
249
|
} else {
|
|
248
|
-
this._rawSheets[sheetId].updateRawData(properties, data);
|
|
250
|
+
this._rawSheets[sheetId].updateRawData(properties, data, protectedRanges);
|
|
249
251
|
}
|
|
250
252
|
}
|
|
251
253
|
|
|
@@ -367,9 +369,11 @@ export class GoogleSpreadsheet {
|
|
|
367
369
|
) {
|
|
368
370
|
// TODO: add named range to local cache
|
|
369
371
|
return this._makeSingleUpdateRequest('addNamedRange', {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
372
|
+
namedRange: {
|
|
373
|
+
name,
|
|
374
|
+
namedRangeId,
|
|
375
|
+
range,
|
|
376
|
+
},
|
|
373
377
|
});
|
|
374
378
|
}
|
|
375
379
|
|
|
@@ -619,6 +623,14 @@ export class GoogleSpreadsheet {
|
|
|
619
623
|
return shareReq.json();
|
|
620
624
|
}
|
|
621
625
|
|
|
626
|
+
/**
|
|
627
|
+
* delete a permission by its ID
|
|
628
|
+
* @see https://developers.google.com/drive/api/v3/reference/permissions/delete
|
|
629
|
+
*/
|
|
630
|
+
async deletePermission(permissionId: string) {
|
|
631
|
+
await this.driveApi.delete(`permissions/${permissionId}`);
|
|
632
|
+
}
|
|
633
|
+
|
|
622
634
|
//
|
|
623
635
|
// CREATE NEW DOC ////////////////////////////////////////////////////////////////////////////////
|
|
624
636
|
static async createNewSpreadsheetDocument(auth: GoogleApiAuth, properties?: Partial<SpreadsheetProperties>) {
|
|
@@ -15,6 +15,7 @@ export class GoogleSpreadsheetCell {
|
|
|
15
15
|
private _rawData?: CellData;
|
|
16
16
|
private _draftData: any = {};
|
|
17
17
|
private _error?: GoogleSpreadsheetCellErrorValue;
|
|
18
|
+
private _deleted = false;
|
|
18
19
|
|
|
19
20
|
constructor(
|
|
20
21
|
readonly _sheet: GoogleSpreadsheetWorksheet,
|
|
@@ -26,6 +27,8 @@ export class GoogleSpreadsheetCell {
|
|
|
26
27
|
this._rawData = rawCellData; // so TS does not complain
|
|
27
28
|
}
|
|
28
29
|
|
|
30
|
+
get deleted() { return this._deleted; }
|
|
31
|
+
|
|
29
32
|
// TODO: figure out how to deal with empty rawData
|
|
30
33
|
// newData can be undefined/null if the cell is totally empty and unformatted
|
|
31
34
|
/**
|
|
@@ -49,6 +52,25 @@ export class GoogleSpreadsheetCell {
|
|
|
49
52
|
get a1Row() { return this._rowIndex + 1; } // a1 row numbers start at 1 instead of 0
|
|
50
53
|
get a1Address() { return `${this.a1Column}${this.a1Row}`; }
|
|
51
54
|
|
|
55
|
+
/**
|
|
56
|
+
* @internal
|
|
57
|
+
* Used internally to update cell indices after deleting rows/columns.
|
|
58
|
+
* Should not be called directly.
|
|
59
|
+
*/
|
|
60
|
+
_updateIndices(rowIndex: RowIndex, columnIndex: ColumnIndex) {
|
|
61
|
+
this._rowIndex = rowIndex;
|
|
62
|
+
this._columnIndex = columnIndex;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @internal
|
|
67
|
+
* Used internally to mark cell as deleted.
|
|
68
|
+
* Should not be called directly.
|
|
69
|
+
*/
|
|
70
|
+
_markDeleted() {
|
|
71
|
+
this._deleted = true;
|
|
72
|
+
}
|
|
73
|
+
|
|
52
74
|
// CELL CONTENTS - VALUE/FORMULA/NOTES ///////////////////////////////////////////////////////////
|
|
53
75
|
get value(): number | boolean | string | null | GoogleSpreadsheetCellErrorValue {
|
|
54
76
|
// const typeKey = _.keys(this._rawData.effectiveValue)[0];
|
|
@@ -60,6 +82,8 @@ export class GoogleSpreadsheetCell {
|
|
|
60
82
|
|
|
61
83
|
|
|
62
84
|
set value(newValue: number | boolean | Date | string | null | undefined | GoogleSpreadsheetCellErrorValue) {
|
|
85
|
+
if (this._deleted) throw new Error('This cell has been deleted - reload cells before making updates.');
|
|
86
|
+
|
|
63
87
|
// had to include the GoogleSpreadsheetCellErrorValue in the type to make TS happy
|
|
64
88
|
if (newValue instanceof GoogleSpreadsheetCellErrorValue) {
|
|
65
89
|
throw new Error("You can't manually set a value to an error");
|
|
@@ -29,6 +29,16 @@ export class GoogleSpreadsheetRow<T extends Record<string, any> = Record<string,
|
|
|
29
29
|
_updateRowNumber(newRowNumber: number) {
|
|
30
30
|
this._rowNumber = newRowNumber;
|
|
31
31
|
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @internal
|
|
35
|
+
* Used internally to mark row as deleted.
|
|
36
|
+
* Should not be called directly.
|
|
37
|
+
*/
|
|
38
|
+
_markDeleted() {
|
|
39
|
+
this._deleted = true;
|
|
40
|
+
}
|
|
41
|
+
|
|
32
42
|
get a1Range() {
|
|
33
43
|
return [
|
|
34
44
|
this._worksheet.a1SheetName,
|