Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): update via SDK Studio #1676

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2403,7 +2403,6 @@ Params Types:
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers#D1BindingParam">D1BindingParam</a>
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers#DispatchNamespaceBindingParam">DispatchNamespaceBindingParam</a>
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers#DurableObjectBindingParam">DurableObjectBindingParam</a>
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers#KVNamespaceBindingParam">KVNamespaceBindingParam</a>
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers#MigrationStepParam">MigrationStepParam</a>
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers#MTLSCERTBindingParam">MTLSCERTBindingParam</a>
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers#PlacementConfigurationParam">PlacementConfigurationParam</a>
Expand All @@ -2418,7 +2417,6 @@ Response Types:
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers#D1Binding">D1Binding</a>
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers#DispatchNamespaceBinding">DispatchNamespaceBinding</a>
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers#DurableObjectBinding">DurableObjectBinding</a>
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers#KVNamespaceBinding">KVNamespaceBinding</a>
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers#MigrationStep">MigrationStep</a>
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers#MTLSCERTBinding">MTLSCERTBinding</a>
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v2/workers#PlacementConfiguration">PlacementConfiguration</a>
Expand Down
49 changes: 47 additions & 2 deletions workers/scriptbinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (r Binding) AsUnion() BindingUnion {
return r.union
}

// Union satisfied by [workers.KVNamespaceBinding] or
// Union satisfied by [workers.BindingWorkersKVNamespaceBinding] or
// [workers.BindingWorkersWasmModuleBinding].
type BindingUnion interface {
implementsWorkersBinding()
Expand All @@ -95,7 +95,7 @@ func init() {
"",
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(KVNamespaceBinding{}),
Type: reflect.TypeOf(BindingWorkersKVNamespaceBinding{}),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Expand All @@ -104,6 +104,51 @@ func init() {
)
}

type BindingWorkersKVNamespaceBinding struct {
// A JavaScript variable name for the binding.
Name string `json:"name,required"`
// Namespace identifier tag.
NamespaceID string `json:"namespace_id,required"`
// The class of resource that the binding provides.
Type BindingWorkersKVNamespaceBindingType `json:"type,required"`
JSON bindingWorkersKVNamespaceBindingJSON `json:"-"`
}

// bindingWorkersKVNamespaceBindingJSON contains the JSON metadata for the struct
// [BindingWorkersKVNamespaceBinding]
type bindingWorkersKVNamespaceBindingJSON struct {
Name apijson.Field
NamespaceID apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

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

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

func (r BindingWorkersKVNamespaceBinding) implementsWorkersBinding() {}

// The class of resource that the binding provides.
type BindingWorkersKVNamespaceBindingType string

const (
BindingWorkersKVNamespaceBindingTypeKVNamespace BindingWorkersKVNamespaceBindingType = "kv_namespace"
)

func (r BindingWorkersKVNamespaceBindingType) IsKnown() bool {
switch r {
case BindingWorkersKVNamespaceBindingTypeKVNamespace:
return true
}
return false
}

type BindingWorkersWasmModuleBinding struct {
// A JavaScript variable name for the binding.
Name string `json:"name,required"`
Expand Down
72 changes: 64 additions & 8 deletions workers/scriptversionsetting.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ func (r BindingItem) AsUnion() BindingItemUnion {

// A binding to allow the Worker to communicate with resources
//
// Union satisfied by [workers.KVNamespaceBinding], [workers.ServiceBinding],
// [workers.DurableObjectBinding], [workers.R2Binding],
// Union satisfied by [workers.BindingItemWorkersKVNamespaceBinding],
// [workers.ServiceBinding], [workers.DurableObjectBinding], [workers.R2Binding],
// [workers.BindingItemWorkersQueueBinding], [workers.D1Binding],
// [workers.DispatchNamespaceBinding] or [workers.MTLSCERTBinding].
type BindingItemUnion interface {
Expand All @@ -147,7 +147,7 @@ func init() {
"",
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(KVNamespaceBinding{}),
Type: reflect.TypeOf(BindingItemWorkersKVNamespaceBinding{}),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Expand Down Expand Up @@ -180,6 +180,51 @@ func init() {
)
}

type BindingItemWorkersKVNamespaceBinding struct {
// A JavaScript variable name for the binding.
Name string `json:"name,required"`
// Namespace identifier tag.
NamespaceID string `json:"namespace_id,required"`
// The class of resource that the binding provides.
Type BindingItemWorkersKVNamespaceBindingType `json:"type,required"`
JSON bindingItemWorkersKVNamespaceBindingJSON `json:"-"`
}

// bindingItemWorkersKVNamespaceBindingJSON contains the JSON metadata for the
// struct [BindingItemWorkersKVNamespaceBinding]
type bindingItemWorkersKVNamespaceBindingJSON struct {
Name apijson.Field
NamespaceID apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

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

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

func (r BindingItemWorkersKVNamespaceBinding) implementsWorkersBindingItem() {}

// The class of resource that the binding provides.
type BindingItemWorkersKVNamespaceBindingType string

const (
BindingItemWorkersKVNamespaceBindingTypeKVNamespace BindingItemWorkersKVNamespaceBindingType = "kv_namespace"
)

func (r BindingItemWorkersKVNamespaceBindingType) IsKnown() bool {
switch r {
case BindingItemWorkersKVNamespaceBindingTypeKVNamespace:
return true
}
return false
}

type BindingItemWorkersQueueBinding struct {
// A JavaScript variable name for the binding.
Name string `json:"name,required"`
Expand Down Expand Up @@ -281,15 +326,26 @@ func (r BindingItemParam) implementsWorkersBindingItemUnionParam() {}

// A binding to allow the Worker to communicate with resources
//
// Satisfied by [workers.KVNamespaceBindingParam], [workers.ServiceBindingParam],
// [workers.DurableObjectBindingParam], [workers.R2BindingParam],
// [workers.BindingItemWorkersQueueBindingParam], [workers.D1BindingParam],
// [workers.DispatchNamespaceBindingParam], [workers.MTLSCERTBindingParam],
// [BindingItemParam].
// Satisfied by [workers.BindingItemWorkersKVNamespaceBindingParam],
// [workers.ServiceBindingParam], [workers.DurableObjectBindingParam],
// [workers.R2BindingParam], [workers.BindingItemWorkersQueueBindingParam],
// [workers.D1BindingParam], [workers.DispatchNamespaceBindingParam],
// [workers.MTLSCERTBindingParam], [BindingItemParam].
type BindingItemUnionParam interface {
implementsWorkersBindingItemUnionParam()
}

type BindingItemWorkersKVNamespaceBindingParam struct {
// The class of resource that the binding provides.
Type param.Field[BindingItemWorkersKVNamespaceBindingType] `json:"type,required"`
}

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

func (r BindingItemWorkersKVNamespaceBindingParam) implementsWorkersBindingItemUnionParam() {}

type BindingItemWorkersQueueBindingParam struct {
// Name of the Queue to bind to
QueueName param.Field[string] `json:"queue_name,required"`
Expand Down
12 changes: 6 additions & 6 deletions workers/scriptversionsetting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ func TestScriptVersionSettingEditWithOptionalParams(t *testing.T) {
workers.ScriptVersionSettingEditParams{
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
Settings: cloudflare.F(workers.SettingsItemParam{
Bindings: cloudflare.F([]workers.BindingItemUnionParam{workers.KVNamespaceBindingParam{
Type: cloudflare.F(workers.KVNamespaceBindingTypeKVNamespace),
}, workers.KVNamespaceBindingParam{
Type: cloudflare.F(workers.KVNamespaceBindingTypeKVNamespace),
}, workers.KVNamespaceBindingParam{
Type: cloudflare.F(workers.KVNamespaceBindingTypeKVNamespace),
Bindings: cloudflare.F([]workers.BindingItemUnionParam{workers.BindingItemWorkersKVNamespaceBindingParam{
Type: cloudflare.F(workers.BindingItemWorkersKVNamespaceBindingTypeKVNamespace),
}, workers.BindingItemWorkersKVNamespaceBindingParam{
Type: cloudflare.F(workers.BindingItemWorkersKVNamespaceBindingTypeKVNamespace),
}, workers.BindingItemWorkersKVNamespaceBindingParam{
Type: cloudflare.F(workers.BindingItemWorkersKVNamespaceBindingTypeKVNamespace),
}}),
CompatibilityDate: cloudflare.F("2022-04-05"),
CompatibilityFlags: cloudflare.F([]workers.CompatibilityFlagsItemParam{"formdata_parser_supports_files", "formdata_parser_supports_files", "formdata_parser_supports_files"}),
Expand Down
117 changes: 48 additions & 69 deletions workers/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ func (r Binding) AsUnion() BindingUnion {

// A binding to allow the Worker to communicate with resources
//
// Union satisfied by [workers.KVNamespaceBinding], [workers.ServiceBinding],
// [workers.DurableObjectBinding], [workers.R2Binding],
// Union satisfied by [workers.BindingWorkersKVNamespaceBinding],
// [workers.ServiceBinding], [workers.DurableObjectBinding], [workers.R2Binding],
// [workers.BindingWorkersQueueBinding], [workers.D1Binding],
// [workers.DispatchNamespaceBinding] or [workers.MTLSCERTBinding].
type BindingUnion interface {
Expand All @@ -133,7 +133,7 @@ func init() {
"",
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(KVNamespaceBinding{}),
Type: reflect.TypeOf(BindingWorkersKVNamespaceBinding{}),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Expand Down Expand Up @@ -166,6 +166,51 @@ func init() {
)
}

type BindingWorkersKVNamespaceBinding struct {
// A JavaScript variable name for the binding.
Name string `json:"name,required"`
// Namespace identifier tag.
NamespaceID string `json:"namespace_id,required"`
// The class of resource that the binding provides.
Type BindingWorkersKVNamespaceBindingType `json:"type,required"`
JSON bindingWorkersKVNamespaceBindingJSON `json:"-"`
}

// bindingWorkersKVNamespaceBindingJSON contains the JSON metadata for the struct
// [BindingWorkersKVNamespaceBinding]
type bindingWorkersKVNamespaceBindingJSON struct {
Name apijson.Field
NamespaceID apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

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

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

func (r BindingWorkersKVNamespaceBinding) implementsWorkersBinding() {}

// The class of resource that the binding provides.
type BindingWorkersKVNamespaceBindingType string

const (
BindingWorkersKVNamespaceBindingTypeKVNamespace BindingWorkersKVNamespaceBindingType = "kv_namespace"
)

func (r BindingWorkersKVNamespaceBindingType) IsKnown() bool {
switch r {
case BindingWorkersKVNamespaceBindingTypeKVNamespace:
return true
}
return false
}

type BindingWorkersQueueBinding struct {
// A JavaScript variable name for the binding.
Name string `json:"name,required"`
Expand Down Expand Up @@ -537,72 +582,6 @@ func (r DurableObjectBindingParam) implementsWorkersBindingItemUnionParam() {}

func (r DurableObjectBindingParam) implementsWorkersBindingItemUnionParam() {}

type KVNamespaceBinding struct {
// A JavaScript variable name for the binding.
Name string `json:"name,required"`
// Namespace identifier tag.
NamespaceID string `json:"namespace_id,required"`
// The class of resource that the binding provides.
Type KVNamespaceBindingType `json:"type,required"`
JSON kvNamespaceBindingJSON `json:"-"`
}

// kvNamespaceBindingJSON contains the JSON metadata for the struct
// [KVNamespaceBinding]
type kvNamespaceBindingJSON struct {
Name apijson.Field
NamespaceID apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

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

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

func (r KVNamespaceBinding) implementsWorkersBinding() {}

func (r KVNamespaceBinding) implementsWorkersBindingItem() {}

// The class of resource that the binding provides.
type KVNamespaceBindingType string

const (
KVNamespaceBindingTypeKVNamespace KVNamespaceBindingType = "kv_namespace"
)

func (r KVNamespaceBindingType) IsKnown() bool {
switch r {
case KVNamespaceBindingTypeKVNamespace:
return true
}
return false
}

type KVNamespaceBindingParam struct {
// The class of resource that the binding provides.
Type param.Field[KVNamespaceBindingType] `json:"type,required"`
}

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

func (r KVNamespaceBindingParam) implementsWorkersBindingItemUnionParam() {}

func (r KVNamespaceBindingParam) implementsWorkersBindingItemUnionParam() {}

func (r KVNamespaceBindingParam) implementsWorkersBindingItemUnionParam() {}

func (r KVNamespaceBindingParam) implementsWorkersBindingItemUnionParam() {}

func (r KVNamespaceBindingParam) implementsWorkersBindingItemUnionParam() {}

type MigrationStep struct {
// A list of classes to delete Durable Object namespaces from.
DeletedClasses []string `json:"deleted_classes"`
Expand Down