google-spreadsheet 3.3.0 → 4.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 +73 -34
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +987 -0
- package/dist/index.mjs +1 -0
- package/package.json +74 -37
- package/src/index.ts +5 -0
- package/src/lib/GoogleSpreadsheet.ts +636 -0
- package/src/lib/GoogleSpreadsheetCell.ts +307 -0
- package/src/lib/GoogleSpreadsheetCellErrorValue.ts +25 -0
- package/src/lib/GoogleSpreadsheetRow.ts +117 -0
- package/{lib/GoogleSpreadsheetWorksheet.js → src/lib/GoogleSpreadsheetWorksheet.ts} +271 -178
- package/src/lib/lodash.ts +32 -0
- package/src/lib/types/auth-types.ts +18 -0
- package/src/lib/types/drive-types.ts +40 -0
- package/src/lib/types/sheets-types.ts +528 -0
- package/src/lib/types/util-types.ts +8 -0
- package/src/lib/utils.ts +57 -0
- package/.eslintrc.js +0 -61
- package/.nvmrc +0 -1
- package/Changelog.md +0 -10
- package/TODO +0 -73
- package/UNLICENSE +0 -24
- package/index.js +0 -13
- package/lib/GoogleSpreadsheet.js +0 -426
- package/lib/GoogleSpreadsheetCell.js +0 -239
- package/lib/GoogleSpreadsheetRow.js +0 -72
- package/lib/errors.js +0 -10
- package/lib/utils.js +0 -32
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// re-export just what we need from lodash
|
|
2
|
+
// we do this so we can use a single import, but hopefully
|
|
3
|
+
// it helps keep bundle sizes down in front-end projects using this lib
|
|
4
|
+
|
|
5
|
+
export { default as compact } from 'lodash/compact';
|
|
6
|
+
|
|
7
|
+
export { default as each } from 'lodash/each';
|
|
8
|
+
export { default as filter } from 'lodash/filter';
|
|
9
|
+
export { default as find } from 'lodash/find';
|
|
10
|
+
export { default as flatten } from 'lodash/flatten';
|
|
11
|
+
export { default as get } from 'lodash/get';
|
|
12
|
+
export { default as groupBy } from 'lodash/groupBy';
|
|
13
|
+
export { default as isArray } from 'lodash/isArray';
|
|
14
|
+
export { default as isBoolean } from 'lodash/isBoolean';
|
|
15
|
+
export { default as isEqual } from 'lodash/isEqual';
|
|
16
|
+
export { default as isFinite } from 'lodash/isFinite';
|
|
17
|
+
export { default as isInteger } from 'lodash/isInteger';
|
|
18
|
+
export { default as isNil } from 'lodash/isNil';
|
|
19
|
+
export { default as isNumber } from 'lodash/isNumber';
|
|
20
|
+
export { default as isObject } from 'lodash/isObject';
|
|
21
|
+
export { default as isString } from 'lodash/isString';
|
|
22
|
+
export { default as keyBy } from 'lodash/keyBy';
|
|
23
|
+
export { default as keys } from 'lodash/keys';
|
|
24
|
+
export { default as map } from 'lodash/map';
|
|
25
|
+
export { default as omit } from 'lodash/omit';
|
|
26
|
+
export { default as pickBy } from 'lodash/pickBy';
|
|
27
|
+
export { default as set } from 'lodash/set';
|
|
28
|
+
export { default as some } from 'lodash/some';
|
|
29
|
+
export { default as sortBy } from 'lodash/sortBy';
|
|
30
|
+
export { default as times } from 'lodash/times';
|
|
31
|
+
export { default as unset } from 'lodash/unset';
|
|
32
|
+
export { default as values } from 'lodash/values';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// optional peer dependency - this ts-ignore should help when user is not using it
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
import type { Headers } from 'google-auth-library/build/src/auth/oauth2client';
|
|
4
|
+
|
|
5
|
+
/** single type to handle all valid auth types */
|
|
6
|
+
export type GoogleApiAuth =
|
|
7
|
+
// this simple interface should cover all google-auth-library auth methods
|
|
8
|
+
| { getRequestHeaders: () => Promise<Headers> }
|
|
9
|
+
// used to pass in an API key only
|
|
10
|
+
| { apiKey: string }
|
|
11
|
+
// used to pass in a raw token
|
|
12
|
+
| { token: string };
|
|
13
|
+
|
|
14
|
+
export enum AUTH_MODES {
|
|
15
|
+
GOOGLE_AUTH_CLIENT = 'google_auth',
|
|
16
|
+
RAW_ACCESS_TOKEN = 'raw_access_token',
|
|
17
|
+
API_KEY = 'api_key'
|
|
18
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
|
|
2
|
+
export type PermissionRoles =
|
|
3
|
+
'owner' |
|
|
4
|
+
'writer' |
|
|
5
|
+
'commenter' |
|
|
6
|
+
'reader';
|
|
7
|
+
// these roles also exist but are not needed for our use case
|
|
8
|
+
// 'organizer' | 'fileOrganizer'
|
|
9
|
+
|
|
10
|
+
export type PublicPermissionRoles = Exclude<PermissionRoles, 'owner'>;
|
|
11
|
+
|
|
12
|
+
// this shape is set by what we request...
|
|
13
|
+
type PublicPermissionListEntry = {
|
|
14
|
+
id: 'anyoneWithLink'
|
|
15
|
+
type: 'anyone',
|
|
16
|
+
role: PublicPermissionRoles,
|
|
17
|
+
};
|
|
18
|
+
type UserOrGroupPermissionListEntry = {
|
|
19
|
+
id: string;
|
|
20
|
+
displayName: string;
|
|
21
|
+
type: 'user' | 'group';
|
|
22
|
+
photoLink?: string;
|
|
23
|
+
emailAddress: string;
|
|
24
|
+
role: PermissionRoles;
|
|
25
|
+
deleted: boolean;
|
|
26
|
+
};
|
|
27
|
+
type DomainPermissionListEntry = {
|
|
28
|
+
id: string;
|
|
29
|
+
displayName: string;
|
|
30
|
+
type: 'domain';
|
|
31
|
+
domain: string;
|
|
32
|
+
role: PublicPermissionRoles;
|
|
33
|
+
photoLink?: string;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type PermissionsList = (
|
|
37
|
+
PublicPermissionListEntry |
|
|
38
|
+
UserOrGroupPermissionListEntry |
|
|
39
|
+
DomainPermissionListEntry
|
|
40
|
+
)[];
|
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
|
|
3
|
+
import { MakeOptional } from './util-types';
|
|
4
|
+
|
|
5
|
+
// some basic types which are just aliases, but they make the code a bit clearer
|
|
6
|
+
export type Integer = number;
|
|
7
|
+
|
|
8
|
+
export type SpreadsheetId = string;
|
|
9
|
+
export type WorksheetId = number;
|
|
10
|
+
export type DataSourceId = string;
|
|
11
|
+
|
|
12
|
+
export type WorksheetIndex = number;
|
|
13
|
+
export type RowOrColumnIndex = number;
|
|
14
|
+
export type RowIndex = number;
|
|
15
|
+
export type ColumnIndex = number;
|
|
16
|
+
export type A1Address = string;
|
|
17
|
+
export type ColumnAddress = string;
|
|
18
|
+
export type A1Range = string;
|
|
19
|
+
|
|
20
|
+
export type NamedRangeId = string;
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* ISO language code
|
|
26
|
+
* @example en
|
|
27
|
+
* @example en_US
|
|
28
|
+
* */
|
|
29
|
+
export type LocaleCode = string;
|
|
30
|
+
/**
|
|
31
|
+
* timezone code, if not recognized, may be a custom time zone such as `GMT-07:00`
|
|
32
|
+
* @example America/New_York
|
|
33
|
+
* */
|
|
34
|
+
export type Timezone = string;
|
|
35
|
+
|
|
36
|
+
// ENUMS ///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
37
|
+
|
|
38
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/sheets#SheetType */
|
|
39
|
+
export type WorksheetType =
|
|
40
|
+
/** The sheet is a grid. */
|
|
41
|
+
'GRID' |
|
|
42
|
+
/** The sheet has no grid and instead has an object like a chart or image. */
|
|
43
|
+
'OBJECT' |
|
|
44
|
+
/** The sheet connects with an external DataSource and shows the preview of data. */
|
|
45
|
+
'DATA_SOURCE';
|
|
46
|
+
|
|
47
|
+
export type WorksheetDimension = 'ROWS' | 'COLUMNS';
|
|
48
|
+
|
|
49
|
+
export type HyperlinkDisplayType = 'LINKED' | 'PLAIN_TEXT';
|
|
50
|
+
|
|
51
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#numberformattype */
|
|
52
|
+
export type NumberFormatType =
|
|
53
|
+
/** Text formatting, e.g 1000.12 */
|
|
54
|
+
'TEXT' |
|
|
55
|
+
/** Number formatting, e.g, 1,000.12 */
|
|
56
|
+
'NUMBER' |
|
|
57
|
+
/** Percent formatting, e.g 10.12% */
|
|
58
|
+
'PERCENT' |
|
|
59
|
+
/** Currency formatting, e.g $1,000.12 */
|
|
60
|
+
'CURRENCY' |
|
|
61
|
+
/** Date formatting, e.g 9/26/2008 */
|
|
62
|
+
'DATE' |
|
|
63
|
+
/** Time formatting, e.g 3:59:00 PM */
|
|
64
|
+
'TIME' |
|
|
65
|
+
/** Date+Time formatting, e.g 9/26/08 15:59:00 */
|
|
66
|
+
'DATE_TIME' |
|
|
67
|
+
/** Scientific number formatting, e.g 1.01E+03 */
|
|
68
|
+
'SCIENTIFIC';
|
|
69
|
+
|
|
70
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#errortype */
|
|
71
|
+
export type CellValueErrorType =
|
|
72
|
+
/** Corresponds to the #ERROR! error */
|
|
73
|
+
'ERROR' |
|
|
74
|
+
/** Corresponds to the #NULL! error. */
|
|
75
|
+
'NULL_VALUE' |
|
|
76
|
+
/** Corresponds to the #DIV/0 error. */
|
|
77
|
+
'DIVIDE_BY_ZERO' |
|
|
78
|
+
/** Corresponds to the #VALUE! error. */
|
|
79
|
+
'VALUE' |
|
|
80
|
+
/** Corresponds to the #REF! error. */
|
|
81
|
+
'REF' |
|
|
82
|
+
/** Corresponds to the #NAME? error. */
|
|
83
|
+
'NAME' |
|
|
84
|
+
/** Corresponds to the #NUM! error. */
|
|
85
|
+
'NUM' |
|
|
86
|
+
/** Corresponds to the #N/A error. */
|
|
87
|
+
'N_A' |
|
|
88
|
+
/** Corresponds to the Loading... state. */
|
|
89
|
+
'LOADING';
|
|
90
|
+
|
|
91
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#horizontalalign */
|
|
92
|
+
export type HorizontalAlign = 'LEFT' | 'CENTER' | 'RIGHT';
|
|
93
|
+
|
|
94
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#verticalalign */
|
|
95
|
+
export type VerticalAlign = 'TOP' | 'MIDDLE' | 'BOTTOM';
|
|
96
|
+
|
|
97
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#textdirection */
|
|
98
|
+
export type TextDirection = 'LEFT_TO_RIGHT' | 'RIGHT_TO_LEFT';
|
|
99
|
+
|
|
100
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#wrapstrategy */
|
|
101
|
+
export type WrapStrategy = 'OVERFLOW_CELL' | 'LEGACY_WRAP' | 'CLIP' | 'WRAP';
|
|
102
|
+
|
|
103
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#themecolortype */
|
|
104
|
+
export type ThemeColorType = 'TEXT' | 'BACKGROUND' | 'ACCENT1' | 'ACCENT2' | 'ACCENT3' | 'ACCENT4' | 'ACCENT5' | 'ACCENT6' | 'LINK';
|
|
105
|
+
|
|
106
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets#recalculationinterval */
|
|
107
|
+
export type RecalculationInterval = 'ON_CHANGE' | 'MINUTE' | 'HOUR';
|
|
108
|
+
|
|
109
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.developerMetadata#developermetadatavisibility */
|
|
110
|
+
export type DeveloperMetadataVisibility =
|
|
111
|
+
/** Document-visible metadata is accessible from any developer project with access to the document. */
|
|
112
|
+
| 'DOCUMENT'
|
|
113
|
+
/** Project-visible metadata is only visible to and accessible by the developer project that created the metadata. */
|
|
114
|
+
| 'PROJECT';
|
|
115
|
+
|
|
116
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.developerMetadata#developermetadatalocationtype */
|
|
117
|
+
export type DeveloperMetadataLocationType = 'ROW' | 'COLUMN' | 'SHEET' | 'SPREADSHEET';
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
// formatting types
|
|
122
|
+
export type TextFormat = {
|
|
123
|
+
foregroundColor?: Color;
|
|
124
|
+
foregroundColorStyle?: ColorStyle;
|
|
125
|
+
fontFamily?: string;
|
|
126
|
+
fontSize?: number;
|
|
127
|
+
bold?: boolean;
|
|
128
|
+
italic?: boolean;
|
|
129
|
+
strikethrough?: boolean;
|
|
130
|
+
underline?: boolean;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#Style */
|
|
134
|
+
export type CellBorderLineStyle = 'NONE' | 'DOTTED' | 'DASHED' | 'SOLID' | 'SOLID_MEDIUM' | 'SOLID_THICK' | 'DOUBLE';
|
|
135
|
+
|
|
136
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#Border */
|
|
137
|
+
export type CellBorder = {
|
|
138
|
+
style: CellBorderLineStyle;
|
|
139
|
+
width: number;
|
|
140
|
+
color: Color;
|
|
141
|
+
colorStyle: ColorStyle;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#Borders */
|
|
145
|
+
export type CellBorders = {
|
|
146
|
+
top: CellBorder;
|
|
147
|
+
bottom: CellBorder;
|
|
148
|
+
left: CellBorder;
|
|
149
|
+
right: CellBorder;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#Padding */
|
|
153
|
+
export type CellPadding = {
|
|
154
|
+
top: number;
|
|
155
|
+
bottom: number;
|
|
156
|
+
left: number;
|
|
157
|
+
right: number;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export type TextRotation = {
|
|
161
|
+
angle: number;
|
|
162
|
+
vertical: boolean;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
export type ThemeColorPair = {
|
|
166
|
+
color: ColorStyle;
|
|
167
|
+
colorType: ThemeColorType;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
export type SpreadsheetTheme = {
|
|
171
|
+
primaryFontFamily: string;
|
|
172
|
+
themeColors: ThemeColorPair[];
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
// ---------------------------------
|
|
176
|
+
|
|
177
|
+
export type PaginationOptions = {
|
|
178
|
+
limit: number;
|
|
179
|
+
offset: number;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets#iterativecalculationsettings
|
|
184
|
+
*/
|
|
185
|
+
export type IterativeCalculationSetting = {
|
|
186
|
+
maxIterations: number;
|
|
187
|
+
convergenceThreshold: number;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
export type DimensionRangeIndexes = {
|
|
192
|
+
startIndex: RowOrColumnIndex;
|
|
193
|
+
endIndex: RowOrColumnIndex;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.developerMetadata#DeveloperMetadata.DeveloperMetadataLocation */
|
|
198
|
+
export interface DeveloperMetadataLocation {
|
|
199
|
+
sheetId: number;
|
|
200
|
+
spreadsheet: boolean;
|
|
201
|
+
dimensionRange: DimensionRange;
|
|
202
|
+
locationType: DeveloperMetadataLocationType;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.developerMetadata#DeveloperMetadata.DeveloperMetadataLocation */
|
|
206
|
+
export interface DeveloperMetadata {
|
|
207
|
+
metadataId: number;
|
|
208
|
+
metadataKey: string;
|
|
209
|
+
metadataValue: string;
|
|
210
|
+
location: DeveloperMetadataLocation;
|
|
211
|
+
visibility: DeveloperMetadataVisibility;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export interface WorksheetDimensionProperties {
|
|
215
|
+
pixelSize: number;
|
|
216
|
+
hiddenByUser: boolean;
|
|
217
|
+
hiddenByFilter: boolean;
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.developerMetadata#DeveloperMetadata
|
|
221
|
+
*/
|
|
222
|
+
developerMetadata: DeveloperMetadata[];
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#DataSourceColumnReference */
|
|
226
|
+
type DataSourceColumnReference = {
|
|
227
|
+
name: string;
|
|
228
|
+
};
|
|
229
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#DataSourceColumn */
|
|
230
|
+
type DataSourceColumn = {
|
|
231
|
+
reference: DataSourceColumnReference,
|
|
232
|
+
formula: string
|
|
233
|
+
};
|
|
234
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#DataExecutionState */
|
|
235
|
+
type DataExecutionState =
|
|
236
|
+
/** The data execution has not started. */
|
|
237
|
+
'NOT_STARTED' |
|
|
238
|
+
/** The data execution has started and is running. */
|
|
239
|
+
'RUNNING' |
|
|
240
|
+
/** The data execution has completed successfully. */
|
|
241
|
+
'SUCCEEDED' |
|
|
242
|
+
/** The data execution has completed with errors. */
|
|
243
|
+
'FAILED';
|
|
244
|
+
|
|
245
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#DataExecutionState */
|
|
246
|
+
type DataExecutionErrorCode =
|
|
247
|
+
/** Default value, do not use. */
|
|
248
|
+
'DATA_EXECUTION_ERROR_CODE_UNSPECIFIED' |
|
|
249
|
+
/** The data execution timed out. */
|
|
250
|
+
'TIMED_OUT' |
|
|
251
|
+
/** The data execution returns more rows than the limit. */
|
|
252
|
+
'TOO_MANY_ROWS' |
|
|
253
|
+
/** The data execution returns more columns than the limit. */
|
|
254
|
+
'TOO_MANY_COLUMNS' |
|
|
255
|
+
/** The data execution returns more cells than the limit. */
|
|
256
|
+
'TOO_MANY_CELLS' |
|
|
257
|
+
/** Error is received from the backend data execution engine (e.g. BigQuery). Check errorMessage for details. */
|
|
258
|
+
'ENGINE' |
|
|
259
|
+
/** One or some of the provided data source parameters are invalid. */
|
|
260
|
+
'PARAMETER_INVALID' |
|
|
261
|
+
/** The data execution returns an unsupported data type. */
|
|
262
|
+
'UNSUPPORTED_DATA_TYPE' |
|
|
263
|
+
/** The data execution returns duplicate column names or aliases. */
|
|
264
|
+
'DUPLICATE_COLUMN_NAMES' |
|
|
265
|
+
/** The data execution is interrupted. Please refresh later. */
|
|
266
|
+
'INTERRUPTED' |
|
|
267
|
+
/** The data execution is currently in progress, can not be refreshed until it completes. */
|
|
268
|
+
'CONCURRENT_QUERY' |
|
|
269
|
+
/** Other errors. */
|
|
270
|
+
'OTHER' |
|
|
271
|
+
/** The data execution returns values that exceed the maximum characters allowed in a single cell. */
|
|
272
|
+
'TOO_MANY_CHARS_PER_CELL' |
|
|
273
|
+
/** The database referenced by the data source is not found. */
|
|
274
|
+
'DATA_NOT_FOUND' |
|
|
275
|
+
/** The user does not have access to the database referenced by the data source. */
|
|
276
|
+
'PERMISSION_DENIED' |
|
|
277
|
+
/** The data execution returns columns with missing aliases. */
|
|
278
|
+
'MISSING_COLUMN_ALIAS' |
|
|
279
|
+
/** The data source object does not exist. */
|
|
280
|
+
'OBJECT_NOT_FOUND' |
|
|
281
|
+
/** The data source object is currently in error state. To force refresh, set force in RefreshDataSourceRequest . */
|
|
282
|
+
'OBJECT_IN_ERROR_STATE' |
|
|
283
|
+
/** The data source object specification is invalid. */
|
|
284
|
+
'OBJECT_SPEC_INVALID';
|
|
285
|
+
|
|
286
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#DataExecutionStatus */
|
|
287
|
+
type DataExecutionStatus = {
|
|
288
|
+
'state': DataExecutionState,
|
|
289
|
+
'errorCode': DataExecutionErrorCode,
|
|
290
|
+
'errorMessage': string,
|
|
291
|
+
'lastRefreshTime': string
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/sheets#DataSourceSheetProperties */
|
|
295
|
+
export type DataSourceSheetProperties = {
|
|
296
|
+
'dataSourceId': DataSourceId
|
|
297
|
+
'columns': DataSourceColumn[],
|
|
298
|
+
'dataExecutionStatus': DataExecutionStatus,
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
// Spreadsheet types /////////////////////
|
|
303
|
+
|
|
304
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets#SpreadsheetProperties */
|
|
305
|
+
export type SpreadsheetProperties = {
|
|
306
|
+
/** title of the spreadsheet */
|
|
307
|
+
title: string,
|
|
308
|
+
/** locale of the spreadsheet (note - not all locales are supported) */
|
|
309
|
+
locale: LocaleCode,
|
|
310
|
+
/** amount of time to wait before volatile functions are recalculated */
|
|
311
|
+
autoRecalc: RecalculationInterval,
|
|
312
|
+
/** timezone of the sheet */
|
|
313
|
+
timeZone: Timezone;
|
|
314
|
+
|
|
315
|
+
// TODO
|
|
316
|
+
defaultFormat: any
|
|
317
|
+
iterativeCalculationSettings: any,
|
|
318
|
+
spreadsheetTheme: any
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/sheets#SheetProperties */
|
|
324
|
+
export type WorksheetProperties = {
|
|
325
|
+
'sheetId': WorksheetId,
|
|
326
|
+
'title': string,
|
|
327
|
+
'index': WorksheetIndex,
|
|
328
|
+
'sheetType': WorksheetType,
|
|
329
|
+
'gridProperties': WorksheetGridProperties,
|
|
330
|
+
'hidden': boolean,
|
|
331
|
+
'tabColor': Color,
|
|
332
|
+
'tabColorStyle': ColorStyle,
|
|
333
|
+
'rightToLeft': boolean,
|
|
334
|
+
'dataSourceSheetProperties': DataSourceSheetProperties
|
|
335
|
+
};
|
|
336
|
+
export type WorksheetPropertiesPartial = {
|
|
337
|
+
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
// Spreadsheet Cell types ///////////////////
|
|
341
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#CellFormat */
|
|
342
|
+
export type CellFormat = {
|
|
343
|
+
/** format describing how number values should be represented to the user */
|
|
344
|
+
numberFormat: NumberFormat,
|
|
345
|
+
/** @deprecated use backgroundColorStyle */
|
|
346
|
+
backgroundColor: Color,
|
|
347
|
+
backgroundColorStyle: ColorStyle,
|
|
348
|
+
borders: CellBorders,
|
|
349
|
+
padding: CellPadding,
|
|
350
|
+
horizontalAlignment: HorizontalAlign,
|
|
351
|
+
verticalAlignment: VerticalAlign,
|
|
352
|
+
wrapStrategy: WrapStrategy,
|
|
353
|
+
textDirection: TextDirection,
|
|
354
|
+
textFormat: TextFormat
|
|
355
|
+
hyperlinkDisplayType: HyperlinkDisplayType,
|
|
356
|
+
textRotation: TextRotation,
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#numberformat */
|
|
361
|
+
export type NumberFormat = {
|
|
362
|
+
type: NumberFormatType;
|
|
363
|
+
/**
|
|
364
|
+
* pattern string used for formatting
|
|
365
|
+
* @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#numberformat
|
|
366
|
+
* */
|
|
367
|
+
pattern: string;
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/sheets#GridProperties */
|
|
371
|
+
export type WorksheetGridProperties = {
|
|
372
|
+
rowCount: number;
|
|
373
|
+
columnCount: number;
|
|
374
|
+
frozenRowCount?: number;
|
|
375
|
+
frozenColumnCount?: number;
|
|
376
|
+
hideGridlines?: boolean;
|
|
377
|
+
rowGroupControlAfter?: boolean;
|
|
378
|
+
columnGroupControlAfter?: boolean;
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
//
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
*
|
|
385
|
+
* @see https://developers.google.com/sheets/api/reference/rest/v4/DimensionRange
|
|
386
|
+
*/
|
|
387
|
+
export type DimensionRange = {
|
|
388
|
+
sheetId: WorksheetId,
|
|
389
|
+
dimension: WorksheetDimension,
|
|
390
|
+
startIndex?: Integer,
|
|
391
|
+
endIndex?: Integer,
|
|
392
|
+
};
|
|
393
|
+
export type DimensionRangeWithoutWorksheetId = Omit<DimensionRange, 'sheetId'>;
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* object describing a range in a sheet
|
|
397
|
+
* see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#GridRange
|
|
398
|
+
* */
|
|
399
|
+
export type GridRange = {
|
|
400
|
+
/** The sheet this range is on */
|
|
401
|
+
sheetId: WorksheetId,
|
|
402
|
+
/** The start row (inclusive) of the range, or not set if unbounded. */
|
|
403
|
+
startRowIndex?: Integer,
|
|
404
|
+
/** The end row (exclusive) of the range, or not set if unbounded. */
|
|
405
|
+
endRowIndex?: Integer,
|
|
406
|
+
/** The start column (inclusive) of the range, or not set if unbounded. */
|
|
407
|
+
startColumnIndex?: Integer,
|
|
408
|
+
/** The end column (exclusive) of the range, or not set if unbounded. */
|
|
409
|
+
endColumnIndex?: Integer
|
|
410
|
+
};
|
|
411
|
+
export type GridRangeWithoutWorksheetId = Omit<GridRange, 'sheetId'>;
|
|
412
|
+
export type GridRangeWithOptionalWorksheetId = MakeOptional<GridRange, 'sheetId'>;
|
|
413
|
+
export type DataFilter = A1Range | GridRange;
|
|
414
|
+
export type DataFilterWithoutWorksheetId = A1Range | GridRangeWithoutWorksheetId;
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#colorstyle */
|
|
418
|
+
export type ColorStyle = { Color: Color } | { themeColor: ThemeColorType };
|
|
419
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#Color */
|
|
420
|
+
export type Color = {
|
|
421
|
+
red: number,
|
|
422
|
+
green: number,
|
|
423
|
+
blue: number,
|
|
424
|
+
/** docs say alpha is not generally supported? */
|
|
425
|
+
alpha?: number
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/ValueRenderOption */
|
|
430
|
+
type ValueRenderOption =
|
|
431
|
+
/** Values will be calculated & formatted in the reply according to the cell's formatting. Formatting is based on the spreadsheet's locale, not the requesting user's locale. For example, if A1 is 1.23 and A2 is =A1 and formatted as currency, then A2 would return "$1.23". */
|
|
432
|
+
'FORMATTED_VALUE' |
|
|
433
|
+
/** Values will be calculated, but not formatted in the reply. For example, if A1 is 1.23 and A2 is =A1 and formatted as currency, then A2 would return the number 1.23. */
|
|
434
|
+
'UNFORMATTED_VALUE' |
|
|
435
|
+
/** Values will not be calculated. The reply will include the formulas. For example, if A1 is 1.23 and A2 is =A1 and formatted as currency, then A2 would return "=A1". */
|
|
436
|
+
'FORMULA';
|
|
437
|
+
|
|
438
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/DateTimeRenderOption */
|
|
439
|
+
type DateTimeRenderOption =
|
|
440
|
+
/** Instructs date, time, datetime, and duration fields to be output as doubles in "serial number" format, as popularized by Lotus 1-2-3. The whole number portion of the value (left of the decimal) counts the days since December 30th 1899. The fractional portion (right of the decimal) counts the time as a fraction of the day. For example, January 1st 1900 at noon would be 2.5, 2 because it's 2 days after December 30th 1899, and .5 because noon is half a day. February 1st 1900 at 3pm would be 33.625. This correctly treats the year 1900 as not a leap year. */
|
|
441
|
+
'SERIAL_NUMBER' |
|
|
442
|
+
/** Instructs date, time, datetime, and duration fields to be output as strings in their given number format (which depends on the spreadsheet locale). */
|
|
443
|
+
'FORMATTED_STRING';
|
|
444
|
+
|
|
445
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/get#query-parameters */
|
|
446
|
+
export type GetValuesRequestOptions = {
|
|
447
|
+
majorDimension?: WorksheetDimension,
|
|
448
|
+
valueRenderOption?: ValueRenderOption
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Info about an error in a cell
|
|
456
|
+
* @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#errortype
|
|
457
|
+
*/
|
|
458
|
+
export type ErrorValue = {
|
|
459
|
+
type: CellValueErrorType,
|
|
460
|
+
message: string
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#ExtendedValue */
|
|
464
|
+
export type ExtendedValue =
|
|
465
|
+
{ numberValue: number } |
|
|
466
|
+
{ stringValue: string } |
|
|
467
|
+
{ boolValue: boolean } |
|
|
468
|
+
{ formulaValue: string } |
|
|
469
|
+
{ errorValue: ErrorValue };
|
|
470
|
+
export type CellValueType = 'boolValue' | 'stringValue' | 'numberValue' | 'errorValue';
|
|
471
|
+
|
|
472
|
+
//------------------------------------
|
|
473
|
+
|
|
474
|
+
/** @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells */
|
|
475
|
+
export type CellData = {
|
|
476
|
+
/** The value the user entered in the cell. e.g., 1234, 'Hello', or =NOW() Note: Dates, Times and DateTimes are represented as doubles in serial number format. */
|
|
477
|
+
userEnteredValue: ExtendedValue,
|
|
478
|
+
/** The effective value of the cell. For cells with formulas, this is the calculated value. For cells with literals, this is the same as the userEnteredValue. This field is read-only. */
|
|
479
|
+
effectiveValue: ExtendedValue,
|
|
480
|
+
/** The formatted value of the cell. This is the value as it's shown to the user. This field is read-only. */
|
|
481
|
+
formattedValue: string,
|
|
482
|
+
|
|
483
|
+
/** The format the user entered for the cell. */
|
|
484
|
+
userEnteredFormat: CellFormat,
|
|
485
|
+
/** The effective format being used by the cell. This includes the results of applying any conditional formatting and, if the cell contains a formula, the computed number format. If the effective format is the default format, effective format will not be written. This field is read-only. */
|
|
486
|
+
effectiveFormat: CellFormat,
|
|
487
|
+
/** hyperlink in the cell if any */
|
|
488
|
+
hyperlink?: string,
|
|
489
|
+
/** note on the cell */
|
|
490
|
+
note?: string,
|
|
491
|
+
// textFormatRuns: [
|
|
492
|
+
// {
|
|
493
|
+
// object (TextFormatRun)
|
|
494
|
+
// }
|
|
495
|
+
// ],
|
|
496
|
+
// dataValidation: {
|
|
497
|
+
// object (DataValidationRule)
|
|
498
|
+
// },
|
|
499
|
+
// pivotTable: {
|
|
500
|
+
// object (PivotTable)
|
|
501
|
+
// },
|
|
502
|
+
// dataSourceTable: {
|
|
503
|
+
// object (DataSourceTable)
|
|
504
|
+
// },
|
|
505
|
+
// dataSourceFormula: {
|
|
506
|
+
// object (DataSourceFormula)
|
|
507
|
+
// }
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
/** shape of the cell data sent back when fetching the sheet */
|
|
511
|
+
export type CellDataRange = {
|
|
512
|
+
startRow?: RowIndex,
|
|
513
|
+
startColumn?: ColumnIndex,
|
|
514
|
+
// TODO: fix these types
|
|
515
|
+
rowMetadata: any[],
|
|
516
|
+
columnMetadata: any[],
|
|
517
|
+
rowData: {
|
|
518
|
+
values: any[]
|
|
519
|
+
}[]
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
export type AddRowOptions = {
|
|
523
|
+
|
|
524
|
+
/** set to true to use raw mode rather than user entered */
|
|
525
|
+
raw?: boolean,
|
|
526
|
+
/** set to true to insert new rows in the sheet while adding this data */
|
|
527
|
+
insert?: boolean,
|
|
528
|
+
};
|
package/src/lib/utils.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as _ from './lodash';
|
|
2
|
+
|
|
3
|
+
export function getFieldMask(obj: Record<string, unknown>) {
|
|
4
|
+
return Object.keys(obj).join(',');
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function columnToLetter(column: number) {
|
|
8
|
+
let temp;
|
|
9
|
+
let letter = '';
|
|
10
|
+
let col = column;
|
|
11
|
+
while (col > 0) {
|
|
12
|
+
temp = (col - 1) % 26;
|
|
13
|
+
letter = String.fromCharCode(temp + 65) + letter;
|
|
14
|
+
col = (col - temp - 1) / 26;
|
|
15
|
+
}
|
|
16
|
+
return letter;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function letterToColumn(letter: string) {
|
|
20
|
+
let column = 0;
|
|
21
|
+
const { length } = letter;
|
|
22
|
+
for (let i = 0; i < length; i++) {
|
|
23
|
+
column += (letter.charCodeAt(i) - 64) * 26 ** (length - i - 1);
|
|
24
|
+
}
|
|
25
|
+
return column;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// send arrays in params with duplicate keys - ie `?thing=1&thing=2` vs `?thing[]=1...`
|
|
29
|
+
// solution taken from https://github.com/axios/axios/issues/604
|
|
30
|
+
export function axiosParamsSerializer(params: Record<PropertyKey, any>) {
|
|
31
|
+
let options = '';
|
|
32
|
+
Object.keys(params).forEach((key) => {
|
|
33
|
+
const isParamTypeObject = typeof params[key] === 'object';
|
|
34
|
+
const isParamTypeArray = isParamTypeObject && (params[key].length >= 0);
|
|
35
|
+
if (!isParamTypeObject) options += `${key}=${encodeURIComponent(params[key])}&`;
|
|
36
|
+
if (isParamTypeObject && isParamTypeArray) {
|
|
37
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
38
|
+
for (const val of params[key]) {
|
|
39
|
+
options += `${key}=${encodeURIComponent(val)}&`;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return options ? options.slice(0, -1) : options;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
export function checkForDuplicateHeaders(headers: string[]) {
|
|
48
|
+
// check for duplicate headers
|
|
49
|
+
const checkForDupes = _.groupBy(headers); // { c1: ['c1'], c2: ['c2', 'c2' ]}
|
|
50
|
+
_.each(checkForDupes, (grouped, header) => {
|
|
51
|
+
if (!header) return; // empty columns are skipped, so multiple is ok
|
|
52
|
+
if (grouped.length > 1) {
|
|
53
|
+
throw new Error(`Duplicate header detected: "${header}". Please make sure all non-empty headers are unique`);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|