diff --git a/CHANGELOG.md b/CHANGELOG.md index af42f6ee..2ab6e104 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Change Log +## v1.0.0 + +* Breaking: Activate parameter was removed from CreateDeployment; use WithCreateDeploymentActivate. +* Breaking: UpdateRelationshipAttribute API path changed and old overload removed. +* Added: GetConsolePausing endpoint to monitor console pausing status. +* Added: TTL option to list operations for documents and rows. +* Updated: Document and Row sequence comments to reflect sequence IDs. + ## 0.17.0 * Added new Activities service to the Go SDK with a NewActivities constructor to access Activities endpoints. diff --git a/client/client.go b/client/client.go index dff15cca..f3373104 100644 --- a/client/client.go +++ b/client/client.go @@ -74,11 +74,11 @@ type Client struct { func New(optionalSetters ...ClientOption) Client { headers := map[string]string{ "X-Appwrite-Response-Format" : "1.8.0", - "user-agent" : fmt.Sprintf("AppwriteGoSDK/v0.17.0 (%s; %s)", runtime.GOOS, runtime.GOARCH), + "user-agent" : fmt.Sprintf("AppwriteGoSDK/v1.0.0 (%s; %s)", runtime.GOOS, runtime.GOARCH), "x-sdk-name": "Go", "x-sdk-platform": "server", "x-sdk-language": "go", - "x-sdk-version": "v0.17.0", + "x-sdk-version": "v1.0.0", } httpClient, err := GetDefaultClient(defaultTimeout) if err != nil { diff --git a/databases/databases.go b/databases/databases.go index bb2f4282..70830c2a 100644 --- a/databases/databases.go +++ b/databases/databases.go @@ -2949,6 +2949,82 @@ func (srv *Databases) CreateRelationshipAttribute(DatabaseId string, CollectionI } return &parsed, nil +} +type UpdateRelationshipAttributeOptions struct { + OnDelete string + NewKey string + enabledSetters map[string]bool +} +func (options UpdateRelationshipAttributeOptions) New() *UpdateRelationshipAttributeOptions { + options.enabledSetters = map[string]bool{ + "OnDelete": false, + "NewKey": false, + } + return &options +} +type UpdateRelationshipAttributeOption func(*UpdateRelationshipAttributeOptions) +func (srv *Databases) WithUpdateRelationshipAttributeOnDelete(v string) UpdateRelationshipAttributeOption { + return func(o *UpdateRelationshipAttributeOptions) { + o.OnDelete = v + o.enabledSetters["OnDelete"] = true + } +} +func (srv *Databases) WithUpdateRelationshipAttributeNewKey(v string) UpdateRelationshipAttributeOption { + return func(o *UpdateRelationshipAttributeOptions) { + o.NewKey = v + o.enabledSetters["NewKey"] = true + } +} + +// UpdateRelationshipAttribute update relationship attribute. [Learn more +// about relationship +// attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes). +// +// Deprecated: This API has been deprecated since 1.8.0. Please use `TablesDB.updateRelationshipColumn` instead. +func (srv *Databases) UpdateRelationshipAttribute(DatabaseId string, CollectionId string, Key string, optionalSetters ...UpdateRelationshipAttributeOption)(*models.AttributeRelationship, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/relationship/{key}") + options := UpdateRelationshipAttributeOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + if options.enabledSetters["OnDelete"] { + params["onDelete"] = options.OnDelete + } + if options.enabledSetters["NewKey"] { + params["newKey"] = options.NewKey + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.AttributeRelationship{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.AttributeRelationship + parsed, ok := resp.Result.(models.AttributeRelationship) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + } type CreateStringAttributeOptions struct { Default string @@ -3637,87 +3713,12 @@ func (srv *Databases) DeleteAttribute(DatabaseId string, CollectionId string, Ke } return &parsed, nil -} -type UpdateRelationshipAttributeOptions struct { - OnDelete string - NewKey string - enabledSetters map[string]bool -} -func (options UpdateRelationshipAttributeOptions) New() *UpdateRelationshipAttributeOptions { - options.enabledSetters = map[string]bool{ - "OnDelete": false, - "NewKey": false, - } - return &options -} -type UpdateRelationshipAttributeOption func(*UpdateRelationshipAttributeOptions) -func (srv *Databases) WithUpdateRelationshipAttributeOnDelete(v string) UpdateRelationshipAttributeOption { - return func(o *UpdateRelationshipAttributeOptions) { - o.OnDelete = v - o.enabledSetters["OnDelete"] = true - } -} -func (srv *Databases) WithUpdateRelationshipAttributeNewKey(v string) UpdateRelationshipAttributeOption { - return func(o *UpdateRelationshipAttributeOptions) { - o.NewKey = v - o.enabledSetters["NewKey"] = true - } -} - -// UpdateRelationshipAttribute update relationship attribute. [Learn more -// about relationship -// attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes). -// -// Deprecated: This API has been deprecated since 1.8.0. Please use `TablesDB.updateRelationshipColumn` instead. -func (srv *Databases) UpdateRelationshipAttribute(DatabaseId string, CollectionId string, Key string, optionalSetters ...UpdateRelationshipAttributeOption)(*models.AttributeRelationship, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key) - path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/{key}/relationship") - options := UpdateRelationshipAttributeOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - params["key"] = Key - if options.enabledSetters["OnDelete"] { - params["onDelete"] = options.OnDelete - } - if options.enabledSetters["NewKey"] { - params["newKey"] = options.NewKey - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("PATCH", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.AttributeRelationship{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.AttributeRelationship - parsed, ok := resp.Result.(models.AttributeRelationship) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - } type ListDocumentsOptions struct { Queries []string TransactionId string Total bool + Ttl int enabledSetters map[string]bool } func (options ListDocumentsOptions) New() *ListDocumentsOptions { @@ -3725,6 +3726,7 @@ func (options ListDocumentsOptions) New() *ListDocumentsOptions { "Queries": false, "TransactionId": false, "Total": false, + "Ttl": false, } return &options } @@ -3747,6 +3749,12 @@ func (srv *Databases) WithListDocumentsTotal(v bool) ListDocumentsOption { o.enabledSetters["Total"] = true } } +func (srv *Databases) WithListDocumentsTtl(v int) ListDocumentsOption { + return func(o *ListDocumentsOptions) { + o.Ttl = v + o.enabledSetters["Ttl"] = true + } +} // ListDocuments get a list of all the user's documents in a given collection. // You can use the query params to filter your results. @@ -3771,6 +3779,9 @@ func (srv *Databases) ListDocuments(DatabaseId string, CollectionId string, opti if options.enabledSetters["Total"] { params["total"] = options.Total } + if options.enabledSetters["Ttl"] { + params["ttl"] = options.Ttl + } headers := map[string]interface{}{ } diff --git a/docs/examples/databases/list-documents.md b/docs/examples/databases/list-documents.md index ab86f086..1c702d71 100644 --- a/docs/examples/databases/list-documents.md +++ b/docs/examples/databases/list-documents.md @@ -21,5 +21,6 @@ response, error := service.ListDocuments( databases.WithListDocumentsQueries([]interface{}{}), databases.WithListDocumentsTransactionId(""), databases.WithListDocumentsTotal(false), + databases.WithListDocumentsTtl(0), ) ``` diff --git a/docs/examples/health/get-console-pausing.md b/docs/examples/health/get-console-pausing.md new file mode 100644 index 00000000..44038133 --- /dev/null +++ b/docs/examples/health/get-console-pausing.md @@ -0,0 +1,22 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/health" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := health.New(client) + +response, error := service.GetConsolePausing( + health.WithGetConsolePausingThreshold(0), + health.WithGetConsolePausingInactivityDays(0), +) +``` diff --git a/docs/examples/sites/create-deployment.md b/docs/examples/sites/create-deployment.md index ed2dfb70..086b5f1f 100644 --- a/docs/examples/sites/create-deployment.md +++ b/docs/examples/sites/create-deployment.md @@ -18,9 +18,9 @@ service := sites.New(client) response, error := service.CreateDeployment( "", file.NewInputFile("/path/to/file.png", "file.png"), - false, sites.WithCreateDeploymentInstallCommand(""), sites.WithCreateDeploymentBuildCommand(""), sites.WithCreateDeploymentOutputDirectory(""), + sites.WithCreateDeploymentActivate(false), ) ``` diff --git a/docs/examples/tablesdb/list-rows.md b/docs/examples/tablesdb/list-rows.md index b1977609..49c382f9 100644 --- a/docs/examples/tablesdb/list-rows.md +++ b/docs/examples/tablesdb/list-rows.md @@ -21,5 +21,6 @@ response, error := service.ListRows( tablesdb.WithListRowsQueries([]interface{}{}), tablesdb.WithListRowsTransactionId(""), tablesdb.WithListRowsTotal(false), + tablesdb.WithListRowsTtl(0), ) ``` diff --git a/health/health.go b/health/health.go index c02f233b..873f3975 100644 --- a/health/health.go +++ b/health/health.go @@ -172,6 +172,75 @@ func (srv *Health) GetCertificate(optionalSetters ...GetCertificateOption)(*mode } return &parsed, nil +} +type GetConsolePausingOptions struct { + Threshold int + InactivityDays int + enabledSetters map[string]bool +} +func (options GetConsolePausingOptions) New() *GetConsolePausingOptions { + options.enabledSetters = map[string]bool{ + "Threshold": false, + "InactivityDays": false, + } + return &options +} +type GetConsolePausingOption func(*GetConsolePausingOptions) +func (srv *Health) WithGetConsolePausingThreshold(v int) GetConsolePausingOption { + return func(o *GetConsolePausingOptions) { + o.Threshold = v + o.enabledSetters["Threshold"] = true + } +} +func (srv *Health) WithGetConsolePausingInactivityDays(v int) GetConsolePausingOption { + return func(o *GetConsolePausingOptions) { + o.InactivityDays = v + o.enabledSetters["InactivityDays"] = true + } +} + +// GetConsolePausing get console pausing health status. Monitors projects +// approaching the pause threshold to detect potential issues with console +// access tracking. +func (srv *Health) GetConsolePausing(optionalSetters ...GetConsolePausingOption)(*models.HealthStatus, error) { + path := "/health/console-pausing" + options := GetConsolePausingOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Threshold"] { + params["threshold"] = options.Threshold + } + if options.enabledSetters["InactivityDays"] { + params["inactivityDays"] = options.InactivityDays + } + headers := map[string]interface{}{ + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.HealthStatus{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.HealthStatus + parsed, ok := resp.Result.(models.HealthStatus) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + } // GetDB check the Appwrite database servers are up and connection is diff --git a/models/document.go b/models/document.go index c58d586a..1dcaa7a3 100644 --- a/models/document.go +++ b/models/document.go @@ -9,7 +9,7 @@ import ( type Document struct { // Document ID. Id string `json:"$id"` - // Document automatically incrementing ID. + // Document sequence ID. Sequence int `json:"$sequence"` // Collection ID. CollectionId string `json:"$collectionId"` diff --git a/models/row.go b/models/row.go index a5742e81..cf3343d6 100644 --- a/models/row.go +++ b/models/row.go @@ -9,7 +9,7 @@ import ( type Row struct { // Row ID. Id string `json:"$id"` - // Row automatically incrementing ID. + // Row sequence ID. Sequence int `json:"$sequence"` // Table ID. TableId string `json:"$tableId"` diff --git a/sites/sites.go b/sites/sites.go index cd1864e4..567b62e6 100644 --- a/sites/sites.go +++ b/sites/sites.go @@ -774,6 +774,7 @@ type CreateDeploymentOptions struct { InstallCommand string BuildCommand string OutputDirectory string + Activate bool enabledSetters map[string]bool } func (options CreateDeploymentOptions) New() *CreateDeploymentOptions { @@ -781,6 +782,7 @@ func (options CreateDeploymentOptions) New() *CreateDeploymentOptions { "InstallCommand": false, "BuildCommand": false, "OutputDirectory": false, + "Activate": false, } return &options } @@ -803,12 +805,18 @@ func (srv *Sites) WithCreateDeploymentOutputDirectory(v string) CreateDeployment o.enabledSetters["OutputDirectory"] = true } } - +func (srv *Sites) WithCreateDeploymentActivate(v bool) CreateDeploymentOption { + return func(o *CreateDeploymentOptions) { + o.Activate = v + o.enabledSetters["Activate"] = true + } +} + // CreateDeployment create a new site code deployment. Use this endpoint to // upload a new version of your site code. To activate your newly uploaded // code, you'll need to update the site's deployment to use your new // deployment ID. -func (srv *Sites) CreateDeployment(SiteId string, Code file.InputFile, Activate bool, optionalSetters ...CreateDeploymentOption)(*models.Deployment, error) { +func (srv *Sites) CreateDeployment(SiteId string, Code file.InputFile, optionalSetters ...CreateDeploymentOption)(*models.Deployment, error) { r := strings.NewReplacer("{siteId}", SiteId) path := r.Replace("/sites/{siteId}/deployments") options := CreateDeploymentOptions{}.New() @@ -818,7 +826,6 @@ func (srv *Sites) CreateDeployment(SiteId string, Code file.InputFile, Activate params := map[string]interface{}{} params["siteId"] = SiteId params["code"] = Code - params["activate"] = Activate if options.enabledSetters["InstallCommand"] { params["installCommand"] = options.InstallCommand } @@ -828,6 +835,9 @@ func (srv *Sites) CreateDeployment(SiteId string, Code file.InputFile, Activate if options.enabledSetters["OutputDirectory"] { params["outputDirectory"] = options.OutputDirectory } + if options.enabledSetters["Activate"] { + params["activate"] = options.Activate + } headers := map[string]interface{}{ "content-type": "multipart/form-data", } diff --git a/tablesdb/tables_db.go b/tablesdb/tables_db.go index e7d021dd..a13243a9 100644 --- a/tablesdb/tables_db.go +++ b/tablesdb/tables_db.go @@ -3862,6 +3862,7 @@ type ListRowsOptions struct { Queries []string TransactionId string Total bool + Ttl int enabledSetters map[string]bool } func (options ListRowsOptions) New() *ListRowsOptions { @@ -3869,6 +3870,7 @@ func (options ListRowsOptions) New() *ListRowsOptions { "Queries": false, "TransactionId": false, "Total": false, + "Ttl": false, } return &options } @@ -3891,6 +3893,12 @@ func (srv *TablesDB) WithListRowsTotal(v bool) ListRowsOption { o.enabledSetters["Total"] = true } } +func (srv *TablesDB) WithListRowsTtl(v int) ListRowsOption { + return func(o *ListRowsOptions) { + o.Ttl = v + o.enabledSetters["Ttl"] = true + } +} // ListRows get a list of all the user's rows in a given table. You can use // the query params to filter your results. @@ -3913,6 +3921,9 @@ func (srv *TablesDB) ListRows(DatabaseId string, TableId string, optionalSetters if options.enabledSetters["Total"] { params["total"] = options.Total } + if options.enabledSetters["Ttl"] { + params["ttl"] = options.Ttl + } headers := map[string]interface{}{ }