Skip to content

Commit

Permalink
feat(api): update via SDK Studio (#2062)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed May 17, 2024
1 parent f6bcbf7 commit 2a62b13
Show file tree
Hide file tree
Showing 19 changed files with 1,932 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 1283
configured_endpoints: 1296
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-241f970730129e553d466806420a1cf2f6d665abec11667004cb9cf070932a1e.yml
41 changes: 41 additions & 0 deletions api.md

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions d1/d1.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package d1

import (
"github.com/cloudflare/cloudflare-go/v2/internal/apijson"
"github.com/cloudflare/cloudflare-go/v2/option"
)

Expand All @@ -26,3 +27,35 @@ func NewD1Service(opts ...option.RequestOption) (r *D1Service) {
r.Database = NewDatabaseService(opts...)
return
}

type D1 struct {
// Specifies the timestamp the resource was created as an ISO8601 string.
CreatedAt string `json:"created_at"`
// The D1 database's size, in bytes.
FileSize float64 `json:"file_size"`
Name string `json:"name"`
NumTables float64 `json:"num_tables"`
UUID string `json:"uuid"`
Version string `json:"version"`
JSON d1JSON `json:"-"`
}

// d1JSON contains the JSON metadata for the struct [D1]
type d1JSON struct {
CreatedAt apijson.Field
FileSize apijson.Field
Name apijson.Field
NumTables apijson.Field
UUID apijson.Field
Version apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *D1) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r d1JSON) RawJSON() string {
return r.raw
}
263 changes: 263 additions & 0 deletions d1/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"net/http"
"net/url"
"reflect"

"github.com/cloudflare/cloudflare-go/v2/internal/apijson"
"github.com/cloudflare/cloudflare-go/v2/internal/apiquery"
Expand All @@ -15,6 +16,7 @@ import (
"github.com/cloudflare/cloudflare-go/v2/internal/requestconfig"
"github.com/cloudflare/cloudflare-go/v2/option"
"github.com/cloudflare/cloudflare-go/v2/shared"
"github.com/tidwall/gjson"
)

// DatabaseService contains methods and other services that help with interacting
Expand Down Expand Up @@ -72,6 +74,101 @@ func (r *DatabaseService) ListAutoPaging(ctx context.Context, params DatabaseLis
return pagination.NewV4PagePaginationArrayAutoPager(r.List(ctx, params, opts...))
}

// Deletes the specified D1 database.
func (r *DatabaseService) Delete(ctx context.Context, databaseID string, body DatabaseDeleteParams, opts ...option.RequestOption) (res *DatabaseDeleteResponseUnion, err error) {
opts = append(r.Options[:], opts...)
var env DatabaseDeleteResponseEnvelope
path := fmt.Sprintf("accounts/%s/d1/database/%s", body.AccountID, databaseID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}

// Returns the specified D1 database.
func (r *DatabaseService) Get(ctx context.Context, databaseID string, query DatabaseGetParams, opts ...option.RequestOption) (res *D1, err error) {
opts = append(r.Options[:], opts...)
var env DatabaseGetResponseEnvelope
path := fmt.Sprintf("accounts/%s/d1/database/%s", query.AccountID, databaseID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}

// Returns the query result.
func (r *DatabaseService) Query(ctx context.Context, databaseID string, params DatabaseQueryParams, opts ...option.RequestOption) (res *[]QueryResult, err error) {
opts = append(r.Options[:], opts...)
var env DatabaseQueryResponseEnvelope
path := fmt.Sprintf("accounts/%s/d1/database/%s/query", params.AccountID, databaseID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}

type QueryResult struct {
Meta QueryResultMeta `json:"meta"`
Results []interface{} `json:"results"`
Success bool `json:"success"`
JSON queryResultJSON `json:"-"`
}

// queryResultJSON contains the JSON metadata for the struct [QueryResult]
type queryResultJSON struct {
Meta apijson.Field
Results apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *QueryResult) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r queryResultJSON) RawJSON() string {
return r.raw
}

type QueryResultMeta struct {
ChangedDB bool `json:"changed_db"`
Changes float64 `json:"changes"`
Duration float64 `json:"duration"`
LastRowID float64 `json:"last_row_id"`
RowsRead float64 `json:"rows_read"`
RowsWritten float64 `json:"rows_written"`
SizeAfter float64 `json:"size_after"`
JSON queryResultMetaJSON `json:"-"`
}

// queryResultMetaJSON contains the JSON metadata for the struct [QueryResultMeta]
type queryResultMetaJSON struct {
ChangedDB apijson.Field
Changes apijson.Field
Duration apijson.Field
LastRowID apijson.Field
RowsRead apijson.Field
RowsWritten apijson.Field
SizeAfter apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *QueryResultMeta) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r queryResultMetaJSON) RawJSON() string {
return r.raw
}

type DatabaseNewResponse struct {
// Specifies the timestamp the resource was created as an ISO8601 string.
CreatedAt string `json:"created_at"`
Expand Down Expand Up @@ -128,6 +225,22 @@ func (r databaseListResponseJSON) RawJSON() string {
return r.raw
}

// Union satisfied by [d1.DatabaseDeleteResponseUnknown] or [shared.UnionString].
type DatabaseDeleteResponseUnion interface {
ImplementsD1DatabaseDeleteResponseUnion()
}

func init() {
apijson.RegisterUnion(
reflect.TypeOf((*DatabaseDeleteResponseUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
)
}

type DatabaseNewParams struct {
// Account identifier tag.
AccountID param.Field[string] `path:"account_id,required"`
Expand Down Expand Up @@ -199,3 +312,153 @@ func (r DatabaseListParams) URLQuery() (v url.Values) {
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}

type DatabaseDeleteParams struct {
// Account identifier tag.
AccountID param.Field[string] `path:"account_id,required"`
}

type DatabaseDeleteResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result DatabaseDeleteResponseUnion `json:"result,required"`
// Whether the API call was successful
Success DatabaseDeleteResponseEnvelopeSuccess `json:"success,required"`
JSON databaseDeleteResponseEnvelopeJSON `json:"-"`
}

// databaseDeleteResponseEnvelopeJSON contains the JSON metadata for the struct
// [DatabaseDeleteResponseEnvelope]
type databaseDeleteResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *DatabaseDeleteResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r databaseDeleteResponseEnvelopeJSON) RawJSON() string {
return r.raw
}

// Whether the API call was successful
type DatabaseDeleteResponseEnvelopeSuccess bool

const (
DatabaseDeleteResponseEnvelopeSuccessTrue DatabaseDeleteResponseEnvelopeSuccess = true
)

func (r DatabaseDeleteResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case DatabaseDeleteResponseEnvelopeSuccessTrue:
return true
}
return false
}

type DatabaseGetParams struct {
// Account identifier tag.
AccountID param.Field[string] `path:"account_id,required"`
}

type DatabaseGetResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result D1 `json:"result,required"`
// Whether the API call was successful
Success DatabaseGetResponseEnvelopeSuccess `json:"success,required"`
JSON databaseGetResponseEnvelopeJSON `json:"-"`
}

// databaseGetResponseEnvelopeJSON contains the JSON metadata for the struct
// [DatabaseGetResponseEnvelope]
type databaseGetResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *DatabaseGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r databaseGetResponseEnvelopeJSON) RawJSON() string {
return r.raw
}

// Whether the API call was successful
type DatabaseGetResponseEnvelopeSuccess bool

const (
DatabaseGetResponseEnvelopeSuccessTrue DatabaseGetResponseEnvelopeSuccess = true
)

func (r DatabaseGetResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case DatabaseGetResponseEnvelopeSuccessTrue:
return true
}
return false
}

type DatabaseQueryParams struct {
// Account identifier tag.
AccountID param.Field[string] `path:"account_id,required"`
Sql param.Field[string] `json:"sql,required"`
Params param.Field[[]string] `json:"params"`
}

func (r DatabaseQueryParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

type DatabaseQueryResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result []QueryResult `json:"result,required"`
// Whether the API call was successful
Success DatabaseQueryResponseEnvelopeSuccess `json:"success,required"`
JSON databaseQueryResponseEnvelopeJSON `json:"-"`
}

// databaseQueryResponseEnvelopeJSON contains the JSON metadata for the struct
// [DatabaseQueryResponseEnvelope]
type databaseQueryResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *DatabaseQueryResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r databaseQueryResponseEnvelopeJSON) RawJSON() string {
return r.raw
}

// Whether the API call was successful
type DatabaseQueryResponseEnvelopeSuccess bool

const (
DatabaseQueryResponseEnvelopeSuccessTrue DatabaseQueryResponseEnvelopeSuccess = true
)

func (r DatabaseQueryResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case DatabaseQueryResponseEnvelopeSuccessTrue:
return true
}
return false
}

0 comments on commit 2a62b13

Please sign in to comment.