Skip to content

Commit

Permalink
Update response types - correctly model single-value tuples.
Browse files Browse the repository at this point in the history
  • Loading branch information
grantneale committed Mar 18, 2019
1 parent c363e22 commit a7c4e5e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 32 deletions.
1 change: 1 addition & 0 deletions src/Fable.Import.GoogleCloud.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<Compile Include="ToughCookie\ToughCookie.fs" />
<Compile Include="FormData\FormData.fs" />
<Compile Include="Request\Request.fs" />
<Compile Include="GoogleCloud.Common\Hacks.fs" />
<Compile Include="GoogleCloud.Common\CommonUtil.fs" />
<Compile Include="GoogleCloud.Common\Service.fs" />
<Compile Include="GoogleCloud.Common\ServiceObject.fs" />
Expand Down
21 changes: 21 additions & 0 deletions src/GoogleCloud.Common/Hacks.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace rec Fable.Import.GoogleCloud.Common

/// <summary>
/// Single-value tuple (aka womple). Used as a workaround to represent single value tuples in Typescript.
/// </summary>
/// <remarks>
/// Many Google Cloud API endpoints return single element tuples (womples), for which no equivalent type exists in F#.
/// This type can be used to represent such types. It's more palatable than the alternative, which is modelling such
/// types as arrays (Typescript tuples are implemented as arrays in Javascript)
/// and then indexing into them to get the value.
///
/// See: https://github.com/fable-compiler/ts2fable/issues/296
/// </remarks>
type Tuple1<'a> = 'a * unit

module Tuple1 =
/// Unbox the single element of a Tuple1.
let unbox (t1 : Tuple1<'a>) : 'a =
let (v, _) = t1
v

6 changes: 3 additions & 3 deletions src/GoogleCloud.Common/ServiceObject.fs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ type [<AllowNullLiteral>] ResponseCallback =
[<Emit "$0($1...)">] abstract Invoke: ?err: Error * ?apiResponse: R.Response -> unit

type SetMetadataResponse =
Metadata
Tuple1<Metadata>

type SetMetadataOptions =
obj
Expand Down Expand Up @@ -118,11 +118,11 @@ type [<AllowNullLiteral>] ServiceObject<'T> =
abstract create: options: CreateOptions * callback: CreateCallback<'T> -> unit
abstract create: callback: CreateCallback<'T> -> unit
/// Delete the object.
abstract delete: ?options: DeleteOptions -> Promise<R.Response>
abstract delete: ?options: DeleteOptions -> Promise<Tuple1<R.Response>>
abstract delete: options: DeleteOptions * callback: DeleteCallback -> unit
abstract delete: callback: DeleteCallback -> unit
/// Check if the object exists.
abstract exists: ?options: ExistsOptions -> Promise<bool>
abstract exists: ?options: ExistsOptions -> Promise<Tuple1<bool>>
abstract exists: options: ExistsOptions * callback: ExistsCallback -> unit
abstract exists: callback: ExistsCallback -> unit
/// <summary>Get the object if it exists. Optionally have the object created if an
Expand Down
2 changes: 1 addition & 1 deletion src/GoogleCloud.Storage/Acl.fs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type [<AllowNullLiteral>] AddAclCallback =
[<Emit "$0($1...)">] abstract Invoke: err: Error option * ?acl: AccessControlObject * ?apiResponse: R.Response -> unit

type RemoveAclResponse =
R.Response
Tuple1<R.Response>

type [<AllowNullLiteral>] RemoveAclCallback =
[<Emit "$0($1...)">] abstract Invoke: err: Error option * ?apiResponse: R.Response -> unit
Expand Down
55 changes: 27 additions & 28 deletions src/GoogleCloud.Storage/GoogleCloud.Storage.fs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ type [<AllowNullLiteral>] DeleteBucketOptions =
abstract userProject: string option with get, set

type DeleteBucketResponse =
Request.Response
Tuple1<Request.Response>

type [<AllowNullLiteral>] DeleteBucketCallback =
inherit DeleteCallback
Expand All @@ -146,13 +146,13 @@ type [<AllowNullLiteral>] DeleteLabelsCallback =
inherit SetLabelsCallback

type DisableRequesterPaysResponse =
Request.Response
Tuple1<Request.Response>

type [<AllowNullLiteral>] DisableRequesterPaysCallback =
[<Emit "$0($1...)">] abstract Invoke: ?err: Error * ?apiResponse: obj -> unit

type EnableRequesterPaysResponse =
Request.Response
Tuple1<Request.Response>

type [<AllowNullLiteral>] EnableRequesterPaysCallback =
[<Emit "$0($1...)">] abstract Invoke: ?err: Error * ?apiResponse: Request.Response -> unit
Expand All @@ -162,7 +162,7 @@ type [<AllowNullLiteral>] BucketExistsOptions =
abstract userProject: string option with get, set

type BucketExistsResponse =
bool
Tuple1<bool>

type [<AllowNullLiteral>] BucketExistsCallback =
inherit ExistsCallback
Expand All @@ -181,7 +181,7 @@ type [<AllowNullLiteral>] GetLabelsOptions =
abstract userProject: string option with get, set

type GetLabelsResponse =
Request.Response
Tuple1<Request.Response>

type [<AllowNullLiteral>] GetLabelsCallback =
[<Emit "$0($1...)">] abstract Invoke: err: Error option * labels: obj option -> unit
Expand Down Expand Up @@ -210,7 +210,7 @@ type [<AllowNullLiteral>] MakeBucketPrivateOptions =
abstract userProject: string option with get, set

type MakeBucketPrivateResponse =
ResizeArray<File>
Tuple1<ResizeArray<File>>

type [<AllowNullLiteral>] MakeBucketPrivateCallback =
[<Emit "$0($1...)">] abstract Invoke: ?err: Error * ?files: ResizeArray<File> -> unit
Expand All @@ -223,13 +223,13 @@ type [<AllowNullLiteral>] MakeBucketPublicCallback =
[<Emit "$0($1...)">] abstract Invoke: ?err: Error * ?files: ResizeArray<File> -> unit

type MakeBucketPublicResponse =
ResizeArray<File>
Tuple1<ResizeArray<File>>

type [<AllowNullLiteral>] SetBucketMetadataOptions =
abstract userProject: string option with get, set

type SetBucketMetadataResponse =
Request.Response
Tuple1<Request.Response>

type [<AllowNullLiteral>] SetBucketMetadataCallback =
[<Emit "$0($1...)">] abstract Invoke: ?err: Error * ?metadata: Metadata -> unit
Expand All @@ -238,7 +238,7 @@ type [<AllowNullLiteral>] BucketLockCallback =
[<Emit "$0($1...)">] abstract Invoke: ?err: Error * ?apiResponse: Request.Response -> unit

type BucketLockResponse =
Request.Response
Tuple1<Request.Response>

type [<AllowNullLiteral>] Labels =
[<Emit "$0[$1]{{=$2}}">] abstract Item: key: string -> string with get, set
Expand All @@ -247,7 +247,7 @@ type [<AllowNullLiteral>] SetLabelsOptions =
abstract userProject: string option with get, set

type SetLabelsResponse =
Request.Response
Tuple1<Request.Response>

type [<AllowNullLiteral>] SetLabelsCallback =
[<Emit "$0($1...)">] abstract Invoke: ?err: Error * ?metadata: Metadata -> unit
Expand Down Expand Up @@ -282,7 +282,7 @@ type [<AllowNullLiteral>] MakeAllFilesPublicPrivateCallback =
[<Emit "$0($1...)">] abstract Invoke: ?err: U2<Error, ResizeArray<Error>> * ?files: ResizeArray<File> -> unit

type MakeAllFilesPublicPrivateResponse =
ResizeArray<File>
Tuple1<ResizeArray<File>>

/// Create a Bucket object to interact with a Cloud Storage bucket.
type [<AllowNullLiteral>] Bucket =
Expand Down Expand Up @@ -350,7 +350,7 @@ type [<AllowNullLiteral>] Bucket =
/// `projects/my-project/locations/location/keyRings/my-kr/cryptoKeys/my-key`.
/// KMS key ring must use the same location as the bucket.</param>
abstract file: name: string * ?options: FileOptions -> File
abstract getFiles: ?query: GetFilesOptions -> Promise<ResizeArray<File>>
abstract getFiles: ?query: GetFilesOptions -> Promise<Tuple1<ResizeArray<File>>>
abstract getFiles: query: GetFilesOptions * callback: GetFilesCallback -> unit
abstract getFiles: callback: GetFilesCallback -> unit
abstract getLabels: options: GetLabelsOptions -> Promise<GetLabelsResponse>
Expand Down Expand Up @@ -427,7 +427,7 @@ module File =


type GetExpirationDateResponse =
DateTime
Tuple1<DateTime>

type [<AllowNullLiteral>] GetExpirationDateCallback =
[<Emit "$0($1...)">] abstract Invoke: err: Error option * ?expirationDate: DateTime * ?apiResponse: R.Response -> unit
Expand All @@ -445,7 +445,7 @@ type [<AllowNullLiteral>] GetSignedUrlConfig =
abstract responseType: string option with get, set

type GetSignedUrlResponse =
string array
Tuple1<string>

type [<AllowNullLiteral>] GetSignedUrlCallback =
[<Emit "$0($1...)">] abstract Invoke: err: Error option * ?url: string -> unit
Expand All @@ -456,7 +456,7 @@ type [<AllowNullLiteral>] PolicyDocument =
abstract string: string with get, set

type GetSignedPolicyResponse =
PolicyDocument
Tuple1<PolicyDocument>

type [<AllowNullLiteral>] GetSignedPolicyCallback =
[<Emit "$0($1...)">] abstract Invoke: err: Error option * ?policy: PolicyDocument -> unit
Expand Down Expand Up @@ -493,7 +493,7 @@ type [<AllowNullLiteral>] FileExistsOptions =
abstract userProject: string option with get, set

type FileExistsResponse =
bool
Tuple1<bool>

type [<AllowNullLiteral>] FileExistsCallback =
[<Emit "$0($1...)">] abstract Invoke: err: Error option * ?exists: bool -> unit
Expand All @@ -502,7 +502,7 @@ type [<AllowNullLiteral>] DeleteFileOptions =
abstract userProject: string option with get, set

type DeleteFileResponse =
R.Response
Tuple1<R.Response>

type [<AllowNullLiteral>] DeleteFileCallback =
[<Emit "$0($1...)">] abstract Invoke: err: Error option * ?apiResponse: R.Response -> unit
Expand All @@ -526,7 +526,7 @@ type [<AllowNullLiteral>] CreateResumableUploadOptions =
abstract userProject: string option with get, set

type CreateResumableUploadResponse =
string array
Tuple1<string>

type [<AllowNullLiteral>] CreateResumableUploadCallback =
[<Emit "$0($1...)">] abstract Invoke: err: Error option * ?uri: string -> unit
Expand All @@ -543,19 +543,19 @@ type [<AllowNullLiteral>] MakeFilePrivateOptions =
abstract userProject: string option with get, set

type MakeFilePrivateResponse =
R.Response
Tuple1<R.Response>

type [<AllowNullLiteral>] MakeFilePrivateCallback =
inherit SetFileMetadataCallback

type MakeFilePublicResponse =
R.Response
Tuple1<R.Response>

type [<AllowNullLiteral>] MakeFilePublicCallback =
[<Emit "$0($1...)">] abstract Invoke: ?err: Error * ?apiResponse: R.Response -> unit

type MoveResponse =
R.Response
Tuple1<R.Response>

type [<AllowNullLiteral>] MoveCallback =
[<Emit "$0($1...)">] abstract Invoke: err: Error option * ?destinationFile: File * ?apiResponse: R.Response -> unit
Expand Down Expand Up @@ -608,7 +608,7 @@ type [<AllowNullLiteral>] CopyCallback =
[<Emit "$0($1...)">] abstract Invoke: err: Error option * ?file: File * ?apiResponse: R.Response -> unit

type DownloadResponse =
Buffer
Tuple1<Buffer>

type [<AllowNullLiteral>] DownloadCallback =
[<Emit "$0($1...)">] abstract Invoke: err: RequestError option * contents: Buffer -> unit
Expand Down Expand Up @@ -636,10 +636,10 @@ type [<AllowNullLiteral>] SetFileMetadataCallback =
[<Emit "$0($1...)">] abstract Invoke: ?err: Error * ?apiResponse: R.Response -> unit

type SetFileMetadataResponse =
R.Response
Tuple1<R.Response>

type SetStorageClassResponse =
R.Response
Tuple1<R.Response>

type [<AllowNullLiteral>] SetStorageClassOptions =
abstract userProject: string option with get, set
Expand Down Expand Up @@ -908,7 +908,7 @@ type [<AllowNullLiteral>] DeleteNotificationCallback =
/// notifications.
type [<AllowNullLiteral>] Notification =
inherit ServiceObject
abstract delete: ?options: DeleteNotificationOptions -> Promise<Request.Response>
abstract delete: ?options: DeleteNotificationOptions -> Promise<Tuple1<Request.Response>>
abstract delete: options: DeleteNotificationOptions * callback: DeleteNotificationCallback -> unit
abstract delete: callback: DeleteNotificationCallback -> unit
abstract get: ?options: GetNotificationOptions -> Promise<GetNotificationResponse>
Expand Down Expand Up @@ -995,7 +995,7 @@ type [<AllowNullLiteral>] BucketCallback =
[<Emit "$0($1...)">] abstract Invoke: err: Error option * ?bucket: Bucket * ?apiResponse: R.Response -> unit

type GetBucketsResponse =
ResizeArray<Bucket>
Tuple1<ResizeArray<Bucket>>

type [<AllowNullLiteral>] GetBucketsCallback =
[<Emit "$0($1...)">] abstract Invoke: err: Error option * buckets: ResizeArray<Bucket> -> unit
Expand Down Expand Up @@ -1076,7 +1076,6 @@ type [<AllowNullLiteral>] StorageStatic =
// channel.d.ts
//

type Response = Request.Response
//type Storage = __storage.Storage

[<RequireQualifiedAccess>]
Expand All @@ -1090,7 +1089,7 @@ type [<AllowNullLiteral>] StopCallback =
/// Create a channel object to interact with a Cloud Storage channel.
type [<AllowNullLiteral>] Channel =
inherit ServiceObject
abstract stop: unit -> Promise<Response>
abstract stop: unit -> Promise<Request.Response>
abstract stop: callback: StopCallback -> unit

/// Create a channel object to interact with a Cloud Storage channel.
Expand Down

0 comments on commit a7c4e5e

Please sign in to comment.