Skip to content

Commit c6a52c6

Browse files
grantweswigham
authored andcommitted
Override Google Apps Script generated types (remove Object, add JSDoc comments) (DefinitelyTyped#27459)
1 parent d937097 commit c6a52c6

File tree

6 files changed

+231
-21
lines changed

6 files changed

+231
-21
lines changed

types/google-apps-script/google-apps-script.card-service.d.ts renamed to types/google-apps-script/google-apps-script.card.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/// <reference path="google-apps-script.gmail.d.ts" />
88

99
declare namespace GoogleAppsScript {
10-
export module Card_Service {
10+
export module Card {
1111
/**
1212
* An action that enables interactivity within UI elements. The action does not happen directly on
1313
* the client but rather invokes an Apps Script callback function with optional parameters.
@@ -657,4 +657,4 @@ declare namespace GoogleAppsScript {
657657
}
658658
}
659659

660-
declare var CardService: GoogleAppsScript.Card_Service.CardService;
660+
declare var CardService: GoogleAppsScript.Card.CardService;

types/google-apps-script/google-apps-script.drive.d.ts

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,104 @@ declare namespace GoogleAppsScript {
3232
export interface DriveApp {
3333
Access: typeof Access;
3434
Permission: typeof Permission;
35+
/**
36+
* Adds the given file to the root of the user's Drive.
37+
* This method does not move the file out of its existing parent folder;
38+
* a file can have more than one parent simultaneously.
39+
*/
3540
addFile(child: File): Folder;
41+
/**
42+
* Adds the given folder to the root of the user's Drive.
43+
* This method does not move the folder out of its existing parent folder;
44+
* a folder can have more than one parent simultaneously.
45+
*/
3646
addFolder(child: Folder): Folder;
47+
/**
48+
* Resumes a file iteration using a continuation token from a previous iterator.
49+
* This method is useful if processing an iterator in one execution would exceed
50+
* the maximum execution time. Continuation tokens are generally valid for one week.
51+
*/
3752
continueFileIterator(continuationToken: string): FileIterator;
53+
/**
54+
* Resumes a folder iteration using a continuation token from a previous iterator.
55+
* This method is useful if processing an iterator in one execution would exceed
56+
* the maximum execution time. Continuation tokens are generally valid for one week.
57+
*/
3858
continueFolderIterator(continuationToken: string): FolderIterator;
59+
/** Creates a file in the root of the user's Drive from a given Blob of arbitrary data. */
3960
createFile(blob: Base.BlobSource): File;
61+
/**
62+
* Creates a text file in the root of the user's Drive with the given name
63+
* and contents. Throws an exception if content is larger than 50 MB.
64+
*/
4065
createFile(name: string, content: string): File;
66+
/**
67+
* Creates a file in the root of the user's Drive with the given name, contents, and MIME type.
68+
* Throws an exception if content is larger than 10MB.
69+
*/
4170
createFile(name: string, content: string, mimeType: string): File;
71+
/** Creates a folder in the root of the user's Drive with the given name. */
4272
createFolder(name: string): Folder;
73+
/**
74+
* Gets the file with the given ID.
75+
* Throws a scripting exception if the file does not exist or
76+
* the user does not have permission to access it.
77+
*/
4378
getFileById(id: string): File;
79+
/** Gets a collection of all files in the user's Drive. */
4480
getFiles(): FileIterator;
81+
/** Gets a collection of all files in the user's Drive that have the given name. */
4582
getFilesByName(name: string): FileIterator;
83+
/** Gets a collection of all files in the user's Drive that have the given MIME type. */
4684
getFilesByType(mimeType: string): FileIterator;
85+
/**
86+
* Gets the folder with the given ID. Throws a scripting exception if the folder
87+
* does not exist or the user does not have permission to access it.
88+
*/
4789
getFolderById(id: string): Folder;
90+
/** Gets a collection of all folders in the user's Drive. */
4891
getFolders(): FolderIterator;
92+
/** Gets a collection of all folders in the user's Drive that have the given name. */
4993
getFoldersByName(name: string): FolderIterator;
94+
/** Gets the folder at the root of the user's Drive. */
5095
getRootFolder(): Folder;
96+
/** Gets the number of bytes the user is allowed to store in Drive. */
5197
getStorageLimit(): Integer;
98+
/** Gets the number of bytes the user is currently storing in Drive. */
5299
getStorageUsed(): Integer;
100+
/** Gets a collection of all the files in the trash of the user's Drive. */
53101
getTrashedFiles(): FileIterator;
102+
/** Gets a collection of all the folders in the trash of the user's Drive. */
54103
getTrashedFolders(): FolderIterator;
104+
/**
105+
* Removes the given file from the root of the user's Drive.
106+
* This method does not delete the file, but if a file is removed from all
107+
* of its parents, it cannot be seen in Drive except by searching for it
108+
* or using the "All items" view.
109+
*/
55110
removeFile(child: File): Folder;
111+
/**
112+
* Removes the given folder from the root of the user's Drive.
113+
* This method does not delete the folder or its contents, but if a folder
114+
* is removed from all of its parents, it cannot be seen in Drive except
115+
* by searching for it or using the "All items" view.
116+
*/
56117
removeFolder(child: Folder): Folder;
118+
/**
119+
* Gets a collection of all files in the user's Drive that match the given search criteria.
120+
* The search criteria are detailed the Google Drive SDK documentation.
121+
* Note that the params argument is a query string that may contain string values,
122+
* so take care to escape quotation marks correctly
123+
* (for example "title contains 'Gulliver\\'s Travels'" or 'title contains "Gulliver\'s Travels"').
124+
*/
57125
searchFiles(params: string): FileIterator;
126+
/**
127+
* Gets a collection of all folders in the user's Drive that match the given search criteria.
128+
* The search criteria are detailed the Google Drive SDK documentation.
129+
* Note that the params argument is a query string that may contain string values,
130+
* so take care to escape quotation marks correctly
131+
* (for example "title contains 'Gulliver\\'s Travels'" or 'title contains "Gulliver\'s Travels"').
132+
*/
58133
searchFolders(params: string): FolderIterator;
59134
}
60135

@@ -138,8 +213,18 @@ declare namespace GoogleAppsScript {
138213
* }
139214
*/
140215
export interface FileIterator {
216+
/**
217+
* Gets a token that can be used to resume this iteration at a later time.
218+
* This method is useful if processing an iterator in one execution would
219+
* exceed the maximum execution time. Continuation tokens are generally valid for one week.
220+
*/
141221
getContinuationToken(): string;
222+
/** Determines whether calling next() will return an item. */
142223
hasNext(): boolean;
224+
/**
225+
* Gets the next item in the collection of files or folders.
226+
* Throws an exception if no items remain.
227+
*/
143228
next(): File;
144229
}
145230

@@ -249,13 +334,26 @@ declare namespace GoogleAppsScript {
249334
* }
250335
*/
251336
export interface User {
337+
/** Gets the domain name associated with the user's account. */
252338
getDomain(): string;
339+
/**
340+
* Gets the user's email address. The user's email address is only available
341+
* if the user has chosen to share the address from the Google+ account settings
342+
* page, or if the user belongs to the same domain as the user running the script
343+
* and the domain administrator has allowed all users within the domain to see
344+
* other users' email addresses.
345+
*/
253346
getEmail(): string;
347+
/** Gets the user's name. This method returns null if the user's name is not available. */
254348
getName(): string;
349+
/** Gets the URL for the user's photo. This method returns null if the user's photo is not available. */
255350
getPhotoUrl(): string;
351+
/**
352+
* Gets the user's email address.
353+
* @deprecated As of June 24, 2013, replaced by getEmail()
354+
*/
256355
getUserLoginId(): string;
257356
}
258-
259357
}
260358
}
261359

types/google-apps-script/google-apps-script.forms.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ declare namespace GoogleAppsScript {
151151
* checkBoxItem.setValidation(checkBoxValidation);
152152
*/
153153
export interface CheckboxValidation {
154+
requireSelectAtLeast(number: Integer): CheckboxValidation;
155+
requireSelectAtMost(number: Integer): CheckboxValidation;
156+
requireSelectExactly(number: Integer): CheckboxValidation;
154157
}
155158

156159
/**

types/google-apps-script/google-apps-script.gmail.d.ts

Lines changed: 69 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,72 @@ declare namespace GoogleAppsScript {
119119
* A user-created draft message in a user's Gmail account.
120120
*/
121121
export interface GmailDraft {
122+
/**
123+
* Deletes this draft message.
124+
*/
122125
deleteDraft(): void;
126+
/**
127+
* Gets the ID of this draft message.
128+
*/
123129
getId(): string;
130+
/**
131+
* Returns a GmailMessage representing this draft.
132+
*/
124133
getMessage(): GmailMessage;
134+
/**
135+
* Returns the ID of the `GmailMessage` representing this draft.
136+
*/
125137
getMessageId(): string;
138+
/**
139+
* Sends this draft email message.
140+
*/
126141
send(): GmailMessage;
142+
/**
143+
* Replaces the contents of this draft message.
144+
*/
127145
update(recipient: string, subject: string, body: string): GmailDraft;
128-
update(recipient: string, subject: string, body: string, options: Object): GmailDraft;
146+
/**
147+
* Replaces the contents of this draft message using optional arguments.
148+
*/
149+
update(recipient: string, subject: string, body: string, options: GmailDraftOptions): GmailDraft;
150+
}
151+
152+
/**
153+
* Options for a Gmail draft.
154+
*/
155+
export type GmailDraftOptions = {
156+
/**
157+
* An array of files to send with the email.
158+
*/
159+
attachments?: Base.BlobSource[];
160+
/**
161+
* A comma-separated list of email addresses to BCC.
162+
*/
163+
bcc?: string;
164+
/**
165+
* A comma-separated list of email addresses to CC.
166+
*/
167+
cc?: string;
168+
/**
169+
* The address that the email should be sent from, which must be one of the values returned by `GmailApp.getAliases()`.
170+
*/
171+
from?: string;
172+
/**
173+
* If set, devices capable of rendering HTML will use it instead of the required body argument; you can add an optional `inlineImages` field in HTML body if you have inlined images for your email.
174+
*/
175+
htmlBody?: string;
176+
/**
177+
* A JavaScript object containing a mapping from image key (`String`) to image data (`BlobSource`) ; this assumes that the `htmlBody` parameter is used and contains references to these images in the format `<img src="cid:imageKey" />`.
178+
*/
179+
inlineImages?: { [imageKey: string]: Base.BlobSource };
180+
/**
181+
* The name of the sender of the email (default: the user's name).
182+
*/
183+
name?: string;
184+
/**
185+
* An email address to use as the default reply-to address (default: the user's email address).
186+
*/
187+
replyTo?: string;
129188
}
130189

131190
/**
@@ -148,11 +207,11 @@ declare namespace GoogleAppsScript {
148207
*/
149208
export interface GmailMessage {
150209
createDraftReply(body: string): GmailDraft;
151-
createDraftReply(body: string, options: Object): GmailDraft;
210+
createDraftReply(body: string, options: GmailDraftOptions): GmailDraft;
152211
createDraftReplyAll(body: string): GmailDraft;
153-
createDraftReplyAll(body: string, options: Object): GmailDraft;
212+
createDraftReplyAll(body: string, options: GmailDraftOptions): GmailDraft;
154213
forward(recipient: string): GmailMessage;
155-
forward(recipient: string, options: Object): GmailMessage;
214+
forward(recipient: string, options: GmailDraftOptions): GmailMessage;
156215
getAttachments(): GmailAttachment[];
157216
getBcc(): string;
158217
getBody(): string;
@@ -178,9 +237,9 @@ declare namespace GoogleAppsScript {
178237
moveToTrash(): GmailMessage;
179238
refresh(): GmailMessage;
180239
reply(body: string): GmailMessage;
181-
reply(body: string, options: Object): GmailMessage;
240+
reply(body: string, options: GmailDraftOptions): GmailMessage;
182241
replyAll(body: string): GmailMessage;
183-
replyAll(body: string, options: Object): GmailMessage;
242+
replyAll(body: string, options: GmailDraftOptions): GmailMessage;
184243
star(): GmailMessage;
185244
unstar(): GmailMessage;
186245
}
@@ -191,9 +250,9 @@ declare namespace GoogleAppsScript {
191250
export interface GmailThread {
192251
addLabel(label: GmailLabel): GmailThread;
193252
createDraftReply(body: string): GmailDraft;
194-
createDraftReply(body: string, options: Object): GmailDraft;
253+
createDraftReply(body: string, options: GmailDraftOptions): GmailDraft;
195254
createDraftReplyAll(body: string): GmailDraft;
196-
createDraftReplyAll(body: string, options: Object): GmailDraft;
255+
createDraftReplyAll(body: string, options: GmailDraftOptions): GmailDraft;
197256
getFirstMessageSubject(): string;
198257
getId(): string;
199258
getLabels(): GmailLabel[];
@@ -220,11 +279,10 @@ declare namespace GoogleAppsScript {
220279
refresh(): GmailThread;
221280
removeLabel(label: GmailLabel): GmailThread;
222281
reply(body: string): GmailThread;
223-
reply(body: string, options: Object): GmailThread;
282+
reply(body: string, options: GmailDraftOptions): GmailThread;
224283
replyAll(body: string): GmailThread;
225-
replyAll(body: string, options: Object): GmailThread;
284+
replyAll(body: string, options: GmailDraftOptions): GmailThread;
226285
}
227-
228286
}
229287
}
230288

types/google-apps-script/google-apps-script.url-fetch.d.ts

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,61 @@ declare namespace GoogleAppsScript {
2525
getResponseCode(): Integer;
2626
}
2727

28+
export interface URLFetchRequestOptions {
29+
/**
30+
* the content type (defaults to 'application/x-www-form-urlencoded'). Another example of content
31+
* type is 'application/xml; charset=utf-8'.
32+
*/
33+
contentType?: string;
34+
35+
/**
36+
* a JavaScript key/value map of HTTP headers for the request
37+
*/
38+
headers?: Object;
39+
40+
/**
41+
* the HTTP method for the request: get, delete, patch, post, or put. The default is get.
42+
*/
43+
method?: 'get' | 'delete' | 'patch' | 'post' | 'put';
44+
45+
/**
46+
* the payload (e.g. POST body) for the request. Certain HTTP methods (e.g. GET) do not accept a
47+
* payload. It can be a string, a byte array, or a JavaScript object. A JavaScript object will be
48+
* interpretted as a map of form field names to values, where the values can be either strings or blobs.
49+
*/
50+
payload?: string;
51+
52+
/**
53+
* Deprecated. This instructs fetch to resolve the specified URL within the intranet linked to your
54+
* domain through (deprecated) SDC
55+
*/
56+
useIntranet?: boolean;
57+
58+
/**
59+
* if this is set to false, the fetch will ignore any invalid certificates for HTTPS requests.
60+
* The default is true.
61+
*/
62+
validateHttpsCertificates?: boolean;
63+
64+
/**
65+
* if this is set to false, the fetch not automatically follow HTTP redirects; it will return
66+
* the original HTTP response. The default is true.
67+
*/
68+
followRedirects?: boolean;
69+
70+
/**
71+
* if this is set to true, the fetch will not throw an exception if the response code indicates
72+
* failure, and will instead return the HTTPResponse (default: false)
73+
*/
74+
muteHttpExceptions?: boolean;
75+
76+
/**
77+
* if this is set to false, reserved characters in the URL will not be escaped (default: true)
78+
*/
79+
escaping?: boolean;
80+
}
81+
82+
2883
/**
2984
* Fetch resources and communicate with other hosts over the Internet.
3085
*
@@ -47,11 +102,9 @@ declare namespace GoogleAppsScript {
47102
* Setting explicit scopes
48103
*/
49104
export interface UrlFetchApp {
50-
fetch(url: string): HTTPResponse;
51-
fetch(url: string, params: Object): HTTPResponse;
105+
fetch(url: string, params?: URLFetchRequestOptions): HTTPResponse;
52106
fetchAll(requests: Object[]): HTTPResponse[];
53-
getRequest(url: string): Object;
54-
getRequest(url: string, params: Object): Object;
107+
getRequest(url: string, params?: URLFetchRequestOptions): Object;
55108
}
56109

57110
}

types/google-apps-script/index.d.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
// Definitions by: motemen <https://github.com/motemen>, grant <https://github.com/grant>
44
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
55

6-
76
/// <reference path="google-apps-script.base.d.ts"/>
87
/// <reference path="google-apps-script.cache.d.ts"/>
98
/// <reference path="google-apps-script.calendar.d.ts"/>
10-
/// <reference path="google-apps-script.card-service.d.ts"/>
9+
/// <reference path="google-apps-script.card.d.ts"/>
1110
/// <reference path="google-apps-script.charts.d.ts"/>
1211
/// <reference path="google-apps-script.contacts.d.ts"/>
1312
/// <reference path="google-apps-script.content.d.ts"/>
@@ -33,4 +32,3 @@
3332
/// <reference path="google-apps-script.url-fetch.d.ts"/>
3433
/// <reference path="google-apps-script.utilities.d.ts"/>
3534
/// <reference path="google-apps-script.xml-service.d.ts"/>
36-

0 commit comments

Comments
 (0)