diff --git a/__tests__/backend/utils/DriveBackedValue.test.ts b/__tests__/backend/utils/DriveBackedValue.test.ts index 06bbe77f..17b82048 100644 --- a/__tests__/backend/utils/DriveBackedValue.test.ts +++ b/__tests__/backend/utils/DriveBackedValue.test.ts @@ -307,7 +307,9 @@ test("DriveBackedValue loads a value - the folder exists, the value exists", () const driveServiceMock = mockedSafeDriveService(); driveServiceMock.Files.get.mockReturnValueOnce( // Incorrect upstream typings, string is actually permissible - JSON.stringify("VALUE") as unknown as GoogleAppsScript.Drive.Schema.File, + JSON.stringify( + "VALUE" + ) as unknown as GoogleAppsScript.Drive_v3.Drive.V3.Schema.File, ); driveServiceMock.Files.list .mockReturnValueOnce(response1) diff --git a/__tests__/test-utils/SafeDriveService-stub.ts b/__tests__/test-utils/SafeDriveService-stub.ts index 552b6e6d..c7a037e6 100644 --- a/__tests__/test-utils/SafeDriveService-stub.ts +++ b/__tests__/test-utils/SafeDriveService-stub.ts @@ -24,7 +24,7 @@ export function mockedSafeDriveService< insert: jest.fn< ( - resource: GoogleAppsScript.Drive.Schema.Comment, + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.Comment, fileId: string, ) => SafeComment >(), @@ -47,7 +47,7 @@ export function mockedSafeDriveService< Files: { copy: jest.fn< ( - resource: GoogleAppsScript.Drive.Schema.File, + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.File, fileId: string, fields: F | null, optionalArgs?: { supportsAllDrives?: boolean }, @@ -62,7 +62,7 @@ export function mockedSafeDriveService< >(), insert: jest.fn< ( - resource: GoogleAppsScript.Drive.Schema.File, + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.File, fields: F | null, // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required by the Drive API mediaData?: any, @@ -86,7 +86,7 @@ export function mockedSafeDriveService< remove: jest.fn<(fileId: string) => void>(), update: jest.fn< ( - resource: GoogleAppsScript.Drive.Schema.File, + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.File, fileId: string, fields: F | null, // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required by the Drive API diff --git a/__tests__/test-utils/gas-stubs.ts b/__tests__/test-utils/gas-stubs.ts index 391e49a2..1ba4e79f 100644 --- a/__tests__/test-utils/gas-stubs.ts +++ b/__tests__/test-utils/gas-stubs.ts @@ -2,173 +2,173 @@ import { jest } from "@jest/globals"; /* eslint-disable @typescript-eslint/naming-convention -- These are stubs for external functions */ -export function mockedCommentsCollection(): GoogleAppsScript.Drive.Collection.CommentsCollection { +export function mockedCommentsCollection(): GoogleAppsScript.Drive_v3.Drive.V3.Collection.CommentsCollection { return { get: jest.fn< ( fileId: string, commentId: string, - ) => GoogleAppsScript.Drive.Schema.Comment + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Comment >(), insert: jest.fn< ( - resource: GoogleAppsScript.Drive.Schema.Comment, + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.Comment, fileId: string, - ) => GoogleAppsScript.Drive.Schema.Comment + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Comment >(), list: jest.fn< - (fileId: string) => GoogleAppsScript.Drive.Schema.CommentList + (fileId: string) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.CommentList >(), patch: jest.fn< ( - resource: GoogleAppsScript.Drive.Schema.Comment, + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.Comment, fileId: string, commentId: string, - ) => GoogleAppsScript.Drive.Schema.Comment + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Comment >(), remove: jest.fn<(fileId: string, commentId: string) => void>(), update: jest.fn< ( - resource: GoogleAppsScript.Drive.Schema.Comment, + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.Comment, fileId: string, commentId: string, - ) => GoogleAppsScript.Drive.Schema.Comment + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Comment >(), }; } -export function mockedDrive(): GoogleAppsScript.Drive_v2 { +export function mockedDrive(): GoogleAppsScript.Drive { return { - newChannel: jest.fn<() => GoogleAppsScript.Drive.Schema.Channel>(), + newChannel: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Channel>(), newChildReference: - jest.fn<() => GoogleAppsScript.Drive.Schema.ChildReference>(), - newComment: jest.fn<() => GoogleAppsScript.Drive.Schema.Comment>(), + jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.ChildReference>(), + newComment: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Comment>(), newCommentContext: - jest.fn<() => GoogleAppsScript.Drive.Schema.CommentContext>(), + jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.CommentContext>(), newCommentReply: - jest.fn<() => GoogleAppsScript.Drive.Schema.CommentReply>(), - newDrive: jest.fn<() => GoogleAppsScript.Drive.Schema.Drive>(), + jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.CommentReply>(), + newDrive: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Drive>(), newDriveBackgroundImageFile: - jest.fn<() => GoogleAppsScript.Drive.Schema.DriveBackgroundImageFile>(), + jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.DriveBackgroundImageFile>(), newDriveCapabilities: - jest.fn<() => GoogleAppsScript.Drive.Schema.DriveCapabilities>(), + jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.DriveCapabilities>(), newDriveRestrictions: - jest.fn<() => GoogleAppsScript.Drive.Schema.DriveRestrictions>(), - newFile: jest.fn<() => GoogleAppsScript.Drive.Schema.File>(), + jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.DriveRestrictions>(), + newFile: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.File>(), newFileCapabilities: - jest.fn<() => GoogleAppsScript.Drive.Schema.FileCapabilities>(), + jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.FileCapabilities>(), newFileImageMediaMetadata: - jest.fn<() => GoogleAppsScript.Drive.Schema.FileImageMediaMetadata>(), + jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.FileImageMediaMetadata>(), newFileImageMediaMetadataLocation: jest.fn< - () => GoogleAppsScript.Drive.Schema.FileImageMediaMetadataLocation + () => GoogleAppsScript.Drive_v3.Drive.V3.Schema.FileImageMediaMetadataLocation >(), newFileIndexableText: - jest.fn<() => GoogleAppsScript.Drive.Schema.FileIndexableText>(), - newFileLabels: jest.fn<() => GoogleAppsScript.Drive.Schema.FileLabels>(), + jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.FileIndexableText>(), + newFileLabels: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.FileLabels>(), newFileThumbnail: - jest.fn<() => GoogleAppsScript.Drive.Schema.FileThumbnail>(), + jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.FileThumbnail>(), newFileVideoMediaMetadata: - jest.fn<() => GoogleAppsScript.Drive.Schema.FileVideoMediaMetadata>(), + jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.FileVideoMediaMetadata>(), newParentReference: - jest.fn<() => GoogleAppsScript.Drive.Schema.ParentReference>(), - newPermission: jest.fn<() => GoogleAppsScript.Drive.Schema.Permission>(), + jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.ParentReference>(), + newPermission: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Permission>(), newPermissionPermissionDetails: jest.fn< - () => GoogleAppsScript.Drive.Schema.PermissionPermissionDetails + () => GoogleAppsScript.Drive_v3.Drive.V3.Schema.PermissionPermissionDetails >(), newPermissionTeamDrivePermissionDetails: jest.fn< - () => GoogleAppsScript.Drive.Schema.PermissionTeamDrivePermissionDetails + () => GoogleAppsScript.Drive_v3.Drive.V3.Schema.PermissionTeamDrivePermissionDetails >(), - newProperty: jest.fn<() => GoogleAppsScript.Drive.Schema.Property>(), - newRevision: jest.fn<() => GoogleAppsScript.Drive.Schema.Revision>(), - newTeamDrive: jest.fn<() => GoogleAppsScript.Drive.Schema.TeamDrive>(), + newProperty: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Property>(), + newRevision: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Revision>(), + newTeamDrive: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.TeamDrive>(), newTeamDriveBackgroundImageFile: jest.fn< - () => GoogleAppsScript.Drive.Schema.TeamDriveBackgroundImageFile + () => GoogleAppsScript.Drive_v3.Drive.V3.Schema.TeamDriveBackgroundImageFile >(), newTeamDriveCapabilities: - jest.fn<() => GoogleAppsScript.Drive.Schema.TeamDriveCapabilities>(), + jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.TeamDriveCapabilities>(), newTeamDriveRestrictions: - jest.fn<() => GoogleAppsScript.Drive.Schema.TeamDriveRestrictions>(), - newUser: jest.fn<() => GoogleAppsScript.Drive.Schema.User>(), - newUserPicture: jest.fn<() => GoogleAppsScript.Drive.Schema.UserPicture>(), + jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.TeamDriveRestrictions>(), + newUser: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.User>(), + newUserPicture: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.UserPicture>(), }; } -export function mockedDrivesCollection(): GoogleAppsScript.Drive.Collection.DrivesCollection { +export function mockedDrivesCollection(): GoogleAppsScript.Drive_v3.Drive.V3.Collection.DrivesCollection { return { - get: jest.fn<(driveId: string) => GoogleAppsScript.Drive.Schema.Drive>(), - hide: jest.fn<(driveId: string) => GoogleAppsScript.Drive.Schema.Drive>(), + get: jest.fn<(driveId: string) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Drive>(), + hide: jest.fn<(driveId: string) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Drive>(), insert: jest.fn< ( - resource: GoogleAppsScript.Drive.Schema.Drive, + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.Drive, requestId: string, - ) => GoogleAppsScript.Drive.Schema.Drive + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Drive >(), - list: jest.fn<() => GoogleAppsScript.Drive.Schema.DriveList>(), + list: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.DriveList>(), remove: jest.fn<(driveId: string) => void>(), - unhide: jest.fn<(driveId: string) => GoogleAppsScript.Drive.Schema.Drive>(), + unhide: jest.fn<(driveId: string) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Drive>(), update: jest.fn< ( - resource: GoogleAppsScript.Drive.Schema.Drive, + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.Drive, driveId: string, - ) => GoogleAppsScript.Drive.Schema.Drive + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Drive >(), }; } -export function mockedFilesCollection(): GoogleAppsScript.Drive.Collection.FilesCollection { +export function mockedFilesCollection(): GoogleAppsScript.Drive_v3.Drive.V3.Collection.FilesCollection { return { copy: jest.fn< ( - resource: GoogleAppsScript.Drive.Schema.File, + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.File, fileId: string, - ) => GoogleAppsScript.Drive.Schema.File + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.File >(), emptyTrash: jest.fn<() => void>(), export: jest.fn<(fileId: string, mimeType: string) => void>(), - generateIds: jest.fn<() => GoogleAppsScript.Drive.Schema.GeneratedIds>(), - get: jest.fn<(fileId: string) => GoogleAppsScript.Drive.Schema.File>(), + generateIds: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.GeneratedIds>(), + get: jest.fn<(fileId: string) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.File>(), insert: jest.fn< ( - resource: GoogleAppsScript.Drive.Schema.File, + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.File, mediaData?: Blob, - ) => GoogleAppsScript.Drive.Schema.File + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.File >(), - list: jest.fn<() => GoogleAppsScript.Drive.Schema.FileList>(), + list: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.FileList>(), patch: jest.fn< ( - resource: GoogleAppsScript.Drive.Schema.File, + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.File, fileId: string, - ) => GoogleAppsScript.Drive.Schema.File + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.File >(), remove: jest.fn<(fileId: string) => void>(), - touch: jest.fn<(fileId: string) => GoogleAppsScript.Drive.Schema.File>(), - trash: jest.fn<(fileId: string) => GoogleAppsScript.Drive.Schema.File>(), - untrash: jest.fn<(fileId: string) => GoogleAppsScript.Drive.Schema.File>(), + touch: jest.fn<(fileId: string) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.File>(), + trash: jest.fn<(fileId: string) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.File>(), + untrash: jest.fn<(fileId: string) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.File>(), update: jest.fn< ( - resource: GoogleAppsScript.Drive.Schema.File, + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.File, fileId: string, mediaData?: Blob, - ) => GoogleAppsScript.Drive.Schema.File + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.File >(), watch: jest.fn< ( - resource: GoogleAppsScript.Drive.Schema.Channel, + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.Channel, fileId: string, - ) => GoogleAppsScript.Drive.Schema.Channel + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Channel >(), }; } @@ -250,48 +250,48 @@ export function mockedHtmlTemplate(): GoogleAppsScript.HTML.HtmlTemplate { }; } -export function mockedRepliesCollection(): GoogleAppsScript.Drive.Collection.RepliesCollection { +export function mockedRepliesCollection(): GoogleAppsScript.Drive_v3.Drive.V3.Collection.RepliesCollection { return { get: jest.fn< ( fileId: string, commentId: string, replyId: string, - ) => GoogleAppsScript.Drive.Schema.CommentReply + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.CommentReply >(), insert: jest.fn< ( - resource: GoogleAppsScript.Drive.Schema.CommentReply, + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.CommentReply, fileId: string, commentId: string, - ) => GoogleAppsScript.Drive.Schema.CommentReply + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.CommentReply >(), list: jest.fn< ( fileId: string, commentId: string, - ) => GoogleAppsScript.Drive.Schema.CommentReplyList + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.CommentReplyList >(), patch: jest.fn< ( - resource: GoogleAppsScript.Drive.Schema.CommentReply, + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.CommentReply, fileId: string, commentId: string, replyId: string, - ) => GoogleAppsScript.Drive.Schema.CommentReply + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.CommentReply >(), remove: jest.fn<(fileId: string, commentId: string, replyId: string) => void>(), update: jest.fn< ( - resource: GoogleAppsScript.Drive.Schema.CommentReply, + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.CommentReply, fileId: string, commentId: string, replyId: string, - ) => GoogleAppsScript.Drive.Schema.CommentReply + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.CommentReply >(), }; } diff --git a/backend.tsconfig.json b/backend.tsconfig.json index 99dc9f22..b069e796 100644 --- a/backend.tsconfig.json +++ b/backend.tsconfig.json @@ -5,8 +5,5 @@ "lib": ["es6"], "types": ["google-apps-script", "google.script.client-side"], "verbatimModuleSyntax": false - }, - "include": [ - "src/backend/Drive-shim.d.ts" - ] + } } diff --git a/src/appsscript.json b/src/appsscript.json index c367c0ed..e1702b62 100644 --- a/src/appsscript.json +++ b/src/appsscript.json @@ -5,7 +5,7 @@ "enabledAdvancedServices": [{ "userSymbol": "Drive", "serviceId": "drive", - "version": "v2" + "version": "v3" }] }, "webapp": { diff --git a/src/backend/Drive-shim.d.ts b/src/backend/Drive-shim.d.ts deleted file mode 100644 index 970f69ee..00000000 --- a/src/backend/Drive-shim.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -// eslint-disable-next-line no-var, @typescript-eslint/naming-convention -- GAS global, needs var -declare var Drive: GoogleAppsScript.Drive_v2; diff --git a/src/backend/listFolders.ts b/src/backend/listFolders.ts index a2c5da50..c7307af5 100644 --- a/src/backend/listFolders.ts +++ b/src/backend/listFolders.ts @@ -37,7 +37,7 @@ export function listFolders(parentID: google.script.Parameter): ListResponse { }, ), (listResponse) => - listResponse.items + listResponse.files .sort((first, second) => first.title.localeCompare( second.title, diff --git a/src/backend/listSharedDrives.ts b/src/backend/listSharedDrives.ts index af4de46c..b0c04d71 100644 --- a/src/backend/listSharedDrives.ts +++ b/src/backend/listSharedDrives.ts @@ -25,7 +25,7 @@ export function listSharedDrives(): ListResponse { }, ), (listResponse) => - listResponse.items.map((item) => ({ id: item.id, name: item.name })), + listResponse.drives.map((item) => ({ id: item.id, name: item.name })), ); return { response, diff --git a/src/backend/move/copyFileComments.ts b/src/backend/move/copyFileComments.ts index e0628a39..7f6c9136 100644 --- a/src/backend/move/copyFileComments.ts +++ b/src/backend/move/copyFileComments.ts @@ -13,20 +13,17 @@ export function copyFileComments_( ): void { const comments = listFileComments_(sourceID, driveService); for (const comment of comments) { - if (!comment.author.isAuthenticatedUser) { + if (!comment.author.me) { comment.content = `*${comment.author.displayName}:*\n${comment.content}`; } const replies = comment.replies; comment.replies = []; - const commentId = driveService.Comments.insert( - comment, - destinationID, - ).commentId; + const commentId = driveService.Comments.create(comment, destinationID).id; for (const reply of replies) { - if (!reply.author.isAuthenticatedUser) { + if (!reply.author.me) { reply.content = `*${reply.author.displayName}:*\n${reply.content}`; } - driveService.Replies.insert(reply, destinationID, commentId); + driveService.Replies.create(reply, destinationID, commentId); } } } diff --git a/src/backend/move/folderManagement.ts b/src/backend/move/folderManagement.ts index ad553def..26540f98 100644 --- a/src/backend/move/folderManagement.ts +++ b/src/backend/move/folderManagement.ts @@ -44,7 +44,7 @@ export function isFolderEmpty_( supportsAllDrives: true, }, ); - return response.items.length === 0; + return response.files.length === 0; } export function listFilesInFolder_( @@ -93,6 +93,6 @@ function listFolderContents_( supportsAllDrives: true, }, ), - (response) => response.items, + (response) => response.files, ); } diff --git a/src/backend/move/moveFile.ts b/src/backend/move/moveFile.ts index fe8918b2..2c3be7b3 100644 --- a/src/backend/move/moveFile.ts +++ b/src/backend/move/moveFile.ts @@ -42,8 +42,8 @@ function moveFileByCopy_( () => { const copy = driveService.Files.copy( { - parents: [{ id: context.destinationID }], - title: name, + name, + parents: [context.destinationID], }, fileID, { id: true }, diff --git a/src/backend/move/resolveDestinationFolder.ts b/src/backend/move/resolveDestinationFolder.ts index e7a9f45c..bb084979 100644 --- a/src/backend/move/resolveDestinationFolder.ts +++ b/src/backend/move/resolveDestinationFolder.ts @@ -30,11 +30,11 @@ export function resolveDestinationFolder_( ); } } - return driveService.Files.insert( + return driveService.Files.create( { mimeType: "application/vnd.google-apps.folder", - parents: [{ id: context.destinationID }], - title: sourceFolder.title, + name: sourceFolder.title, + parents: [context.destinationID], }, { id: true }, undefined, diff --git a/src/backend/utils/DriveBackedValue.ts b/src/backend/utils/DriveBackedValue.ts index fc63cade..3510356a 100644 --- a/src/backend/utils/DriveBackedValue.ts +++ b/src/backend/utils/DriveBackedValue.ts @@ -50,10 +50,10 @@ export class DriveBackedValue_ { } private createDriveFolder(): string { - const response = this.driveService.Files.insert( + const response = this.driveService.Files.create( { mimeType: "application/vnd.google-apps.folder", - title: DriveBackedValue_.driveFolderName, + name: DriveBackedValue_.driveFolderName, }, { id: true, @@ -89,10 +89,10 @@ export class DriveBackedValue_ { }, ); if ( - response.items.length === 1 && - typeof response.items[0].id === "string" + response.files.length === 1 && + typeof response.files[0].id === "string" ) { - return response.items[0].id; + return response.files[0].id; } return null; } @@ -106,10 +106,10 @@ export class DriveBackedValue_ { }, ); if ( - response.items.length === 1 && - typeof response.items[0].id === "string" + response.files.length === 1 && + typeof response.files[0].id === "string" ) { - return response.items[0].id; + return response.files[0].id; } return null; } @@ -126,15 +126,15 @@ export class DriveBackedValue_ { q: `"${folderId}" in parents and trashed = false`, }, ); - return response.items.length === 0; + return response.files.length === 0; } private saveAsNewDriveFile(folderId: string, value: T): void { - this.driveService.Files.insert( + this.driveService.Files.create( { mimeType: "application/json", - parents: [{ id: folderId }], - title: this.getFileName(), + name: this.getFileName(), + parents: [folderId], }, {}, Utilities.newBlob(JSON.stringify(value), "application/json"), diff --git a/src/backend/utils/SafeDriveService.ts b/src/backend/utils/SafeDriveService.ts index 1449cb45..028b08ab 100644 --- a/src/backend/utils/SafeDriveService.ts +++ b/src/backend/utils/SafeDriveService.ts @@ -19,7 +19,7 @@ export class SafeDriveService_ { public readonly Comments: SafeCommentsCollection_; public readonly Drives: SafeDrivesCollection_; public readonly Files: SafeFilesCollection_; - public readonly Replies: GoogleAppsScript.Drive.Collection.RepliesCollection; + public readonly Replies: GoogleAppsScript.Drive_v3.Drive.V3.Collection.RepliesCollection; public constructor() { if (Drive.Replies === undefined) { diff --git a/src/backend/utils/SafeDriveService/SafeCommentsCollection.ts b/src/backend/utils/SafeDriveService/SafeCommentsCollection.ts index 090828d1..0c4e12c4 100644 --- a/src/backend/utils/SafeDriveService/SafeCommentsCollection.ts +++ b/src/backend/utils/SafeDriveService/SafeCommentsCollection.ts @@ -1,8 +1,8 @@ export interface SafeComment { author: SafeUser; - commentId: string; content: string; - replies: Array; + id: string; + replies: Array; } export interface SafeCommentList { @@ -10,33 +10,30 @@ export interface SafeCommentList { nextPageToken?: string | undefined; } -interface SafeCommentReply { +interface SafeReply { author: SafeUser; content: string; } interface SafeUser { displayName: string; - isAuthenticatedUser: boolean; + me: boolean; } export class SafeCommentsCollection_ { - private readonly unsafeComments: GoogleAppsScript.Drive.Collection.CommentsCollection; + private readonly unsafeComments: GoogleAppsScript.Drive_v3.Drive.V3.Collection.CommentsCollection; public constructor() { - if (Drive.Comments === undefined) { - throw new Error(); - } this.unsafeComments = Drive.Comments; } private static commentIsSafe( - comment: GoogleAppsScript.Drive.Schema.Comment, + comment: GoogleAppsScript.Drive_v3.Drive.V3.Schema.Comment, ): comment is SafeComment { return ( comment.author !== undefined && SafeCommentsCollection_.userIsSafe(comment.author) && - comment.commentId !== undefined && + comment.id !== undefined && comment.content !== undefined && comment.replies?.every((reply) => SafeCommentsCollection_.commentReplyIsSafe(reply), @@ -45,18 +42,18 @@ export class SafeCommentsCollection_ { } private static commentListIsSafe( - commentList: GoogleAppsScript.Drive.Schema.CommentList, + commentList: GoogleAppsScript.Drive_v3.Drive.V3.Schema.CommentList, ): commentList is SafeCommentList { return ( - commentList.items?.every((comment) => + commentList.comments.every((comment) => SafeCommentsCollection_.commentIsSafe(comment), ) === true ); } private static commentReplyIsSafe( - commentReply: GoogleAppsScript.Drive.Schema.CommentReply, - ): commentReply is SafeCommentReply { + commentReply: GoogleAppsScript.Drive_v3.Drive.V3.Schema.Reply, + ): commentReply is SafeReply { return ( commentReply.author !== undefined && SafeCommentsCollection_.userIsSafe(commentReply.author) && @@ -65,18 +62,18 @@ export class SafeCommentsCollection_ { } private static userIsSafe( - user: GoogleAppsScript.Drive.Schema.User, + user: GoogleAppsScript.Drive_v3.Drive.V3.Schema.User, ): user is SafeUser { return ( - user.isAuthenticatedUser !== undefined && user.displayName !== undefined + user.me !== undefined && user.displayName !== undefined ); } - public insert( - resource: GoogleAppsScript.Drive.Schema.Comment, + public create( + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.Comment, fileId: string, ): SafeComment { - const ret = this.unsafeComments.insert(resource, fileId); + const ret = this.unsafeComments.create(resource, fileId); if (!SafeCommentsCollection_.commentIsSafe(ret)) { throw new Error(""); } diff --git a/src/backend/utils/SafeDriveService/SafeDrivesCollection.ts b/src/backend/utils/SafeDriveService/SafeDrivesCollection.ts index 89cd8447..f9cee06a 100644 --- a/src/backend/utils/SafeDriveService/SafeDrivesCollection.ts +++ b/src/backend/utils/SafeDriveService/SafeDrivesCollection.ts @@ -9,7 +9,7 @@ export interface SafeDrive { } export interface SafeDriveList> { - items: Array>; + drives: Array>; nextPageToken?: string; } @@ -19,7 +19,7 @@ const safeDriveKeys: DeepKeyof = { }; export class SafeDrivesCollection_ { - private readonly unsafeDrives: GoogleAppsScript.Drive.Collection.DrivesCollection; + private readonly unsafeDrives: GoogleAppsScript.Drive_v3.Drive.V3.Collection.DrivesCollection; public constructor() { if (Drive.Drives === undefined) { @@ -29,7 +29,7 @@ export class SafeDrivesCollection_ { } private static driveIsSafe>( - drive: GoogleAppsScript.Drive.Schema.Drive, + drive: GoogleAppsScript.Drive_v3.Drive.V3.Schema.Drive, keys: F | null, ): drive is typeof keys extends null ? SafeDrive : DeepPick { if (keys === null) { @@ -47,13 +47,10 @@ export class SafeDrivesCollection_ { } private static driveListIsSafe>( - driveList: GoogleAppsScript.Drive.Schema.DriveList, + driveList: GoogleAppsScript.Drive_v3.Drive.V3.Schema.DriveList, keys: F | null, ): driveList is SafeDriveList { - if (driveList.items === undefined) { - return false; - } - return driveList.items.every((file) => + return driveList.drives.every((file) => SafeDrivesCollection_.driveIsSafe(file, keys), ); } diff --git a/src/backend/utils/SafeDriveService/SafeFilesCollection.ts b/src/backend/utils/SafeDriveService/SafeFilesCollection.ts index 532d5e52..dcb5369f 100644 --- a/src/backend/utils/SafeDriveService/SafeFilesCollection.ts +++ b/src/backend/utils/SafeDriveService/SafeFilesCollection.ts @@ -42,7 +42,7 @@ const safeFileKeys: DeepKeyof = { }; export interface SafeFileList> { - items: Array>; + files: Array>; nextPageToken?: string | undefined; } interface GetArg { @@ -56,7 +56,7 @@ type GetReturn, A extends GetArg> = A extends { : DeepPick; export class SafeFilesCollection_ { - private readonly unsafeFiles: GoogleAppsScript.Drive.Collection.FilesCollection; + private readonly unsafeFiles: GoogleAppsScript.Drive_v3.Drive.V3.Collection.FilesCollection; public constructor() { if (Drive.Files === undefined) { @@ -66,7 +66,7 @@ export class SafeFilesCollection_ { } private static fileIsSafe>( - file: GoogleAppsScript.Drive.Schema.File, + file: GoogleAppsScript.Drive_v3.Drive.V3.Schema.File, keys: F | null, ): file is typeof keys extends null ? SafeFile : DeepPick { if (keys === null) { @@ -99,19 +99,16 @@ export class SafeFilesCollection_ { } private static fileListIsSafe>( - fileList: GoogleAppsScript.Drive.Schema.FileList, + fileList: GoogleAppsScript.Drive_v3.Drive.V3.Schema.FileList, keys: F | null, ): fileList is SafeFileList { - if (fileList.items === undefined) { - return false; - } - return fileList.items.every((file) => + return fileList.files.every((file) => SafeFilesCollection_.fileIsSafe(file, keys), ); } public copy>( - resource: GoogleAppsScript.Drive.Schema.File, + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.File, fileId: string, fields: F | null, optionalArgs: { @@ -130,45 +127,44 @@ export class SafeFilesCollection_ { return ret; } - public get, A extends GetArg>( - fileId: string, + public create>( + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.File, fields: F | null, - optionalArgs: A = {} as A, - ): GetReturn { - const ret = this.unsafeFiles.get(fileId, { + mediaData?: GoogleAppsScript.Base.Blob, + optionalArgs: { + supportsAllDrives?: boolean; + } = {}, + ): DeepPick { + const ret = this.unsafeFiles.create(resource, mediaData, { ...optionalArgs, ...(fields !== null && { fields: stringifyFields_(fields), }), }); - if ( - typeof ret !== "string" && - !SafeFilesCollection_.fileIsSafe(ret, fields) - ) { + if (!SafeFilesCollection_.fileIsSafe(ret, fields)) { throw new Error(""); } - return ret as unknown as GetReturn; + return ret; } - public insert>( - resource: GoogleAppsScript.Drive.Schema.File, + public get, A extends GetArg>( + fileId: string, fields: F | null, - // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- Required by the Drive API - mediaData?: any, - optionalArgs: { - supportsAllDrives?: boolean; - } = {}, - ): DeepPick { - const ret = this.unsafeFiles.insert(resource, mediaData, { + optionalArgs: A = {} as A, + ): GetReturn { + const ret = this.unsafeFiles.get(fileId, { ...optionalArgs, ...(fields !== null && { fields: stringifyFields_(fields), }), }); - if (!SafeFilesCollection_.fileIsSafe(ret, fields)) { + if ( + typeof ret !== "string" && + !SafeFilesCollection_.fileIsSafe(ret, fields) + ) { throw new Error(""); } - return ret; + return ret as unknown as GetReturn; } public list>( @@ -198,7 +194,7 @@ export class SafeFilesCollection_ { } public update>( - resource: GoogleAppsScript.Drive.Schema.File, + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.File, fileId: string, fields: F | null, // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- Required by the Drive API