Skip to content
Open
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
24 changes: 24 additions & 0 deletions typesense/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,19 @@ import (

// AliasInterface is a type for Alias API operations
type AliasInterface interface {
// Retrieve an alias.
//
// Find out which collection an alias points to by fetching it
//
// HTTP: GET /aliases/{aliasName}
//
// See: https://typesense.org/docs/latest/api/collections.html
Retrieve(ctx context.Context) (*api.CollectionAlias, error)
// Delete an alias.
//
// HTTP: DELETE /aliases/{aliasName}
//
// See: https://typesense.org/docs/latest/api/collections.html
Delete(ctx context.Context) (*api.CollectionAlias, error)
}

Expand All @@ -17,6 +29,13 @@ type alias struct {
name string
}

// Retrieve an alias.
//
// # Find out which collection an alias points to by fetching it
//
// HTTP: GET /aliases/{aliasName}
//
// See: https://typesense.org/docs/latest/api/collections.html
func (a *alias) Retrieve(ctx context.Context) (*api.CollectionAlias, error) {
response, err := a.apiClient.GetAliasWithResponse(ctx, a.name)
if err != nil {
Expand All @@ -28,6 +47,11 @@ func (a *alias) Retrieve(ctx context.Context) (*api.CollectionAlias, error) {
return response.JSON200, nil
}

// Delete an alias.
//
// HTTP: DELETE /aliases/{aliasName}
//
// See: https://typesense.org/docs/latest/api/collections.html
func (a *alias) Delete(ctx context.Context) (*api.CollectionAlias, error) {
response, err := a.apiClient.DeleteAliasWithResponse(ctx, a.name)
if err != nil {
Expand Down
28 changes: 28 additions & 0 deletions typesense/aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,21 @@ import (

// AliasesInterface is a type for Aliases API operations
type AliasesInterface interface {
// Create or update a collection alias.
//
// Create or update a collection alias. An alias is a virtual collection name that points to a real collection. If you're familiar with symbolic links on Linux, it's very similar to that. Aliases are useful when you want to reindex your data in the background on a new collection and switch your application to it without any changes to your code.
//
// HTTP: PUT /aliases/{aliasName}
//
// See: https://typesense.org/docs/latest/api/collections.html
Upsert(ctx context.Context, aliasName string, aliasSchema *api.CollectionAliasSchema) (*api.CollectionAlias, error)
// List all aliases.
//
// List all aliases and the corresponding collections that they map to.
//
// HTTP: GET /aliases
//
// See: https://typesense.org/docs/latest/api/collections.html
Retrieve(ctx context.Context) ([]*api.CollectionAlias, error)
}

Expand All @@ -17,6 +31,13 @@ type aliases struct {
apiClient APIClientInterface
}

// Create or update a collection alias.
//
// Create or update a collection alias. An alias is a virtual collection name that points to a real collection. If you're familiar with symbolic links on Linux, it's very similar to that. Aliases are useful when you want to reindex your data in the background on a new collection and switch your application to it without any changes to your code.
//
// HTTP: PUT /aliases/{aliasName}
//
// See: https://typesense.org/docs/latest/api/collections.html
func (a *aliases) Upsert(ctx context.Context, aliasName string, aliasSchema *api.CollectionAliasSchema) (*api.CollectionAlias, error) {
response, err := a.apiClient.UpsertAliasWithResponse(ctx,
aliasName, api.UpsertAliasJSONRequestBody(*aliasSchema))
Expand All @@ -29,6 +50,13 @@ func (a *aliases) Upsert(ctx context.Context, aliasName string, aliasSchema *api
return response.JSON200, nil
}

// List all aliases.
//
// List all aliases and the corresponding collections that they map to.
//
// HTTP: GET /aliases
//
// See: https://typesense.org/docs/latest/api/collections.html
func (a *aliases) Retrieve(ctx context.Context) ([]*api.CollectionAlias, error) {
response, err := a.apiClient.GetAliasesWithResponse(ctx)
if err != nil {
Expand Down
28 changes: 28 additions & 0 deletions typesense/analytics_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,35 @@ import (
)

type AnalyticsEventsInterface interface {
// Create an analytics event.
//
// Submit a single analytics event. The event must correspond to an existing analytics rule by name.
//
// HTTP: POST /analytics/events
//
// See: https://typesense.org/docs/latest/api/analytics-query-suggestions.html
Create(ctx context.Context, eventSchema *api.AnalyticsEvent) (*api.AnalyticsEventCreateResponse, error)
// Retrieve analytics events.
//
// Retrieve the most recent events for a user and rule.
//
// HTTP: GET /analytics/events
//
// See: https://typesense.org/docs/latest/api/analytics-query-suggestions.html
Retrieve(ctx context.Context, params *api.GetAnalyticsEventsParams) (*api.AnalyticsEventsResponse, error)
}

type analyticsEvents struct {
apiClient APIClientInterface
}

// Create an analytics event.
//
// Submit a single analytics event. The event must correspond to an existing analytics rule by name.
//
// HTTP: POST /analytics/events
//
// See: https://typesense.org/docs/latest/api/analytics-query-suggestions.html
func (a *analyticsEvents) Create(ctx context.Context, eventSchema *api.AnalyticsEvent) (*api.AnalyticsEventCreateResponse, error) {
response, err := a.apiClient.CreateAnalyticsEventWithResponse(ctx, api.CreateAnalyticsEventJSONRequestBody(*eventSchema))
if err != nil {
Expand All @@ -26,6 +47,13 @@ func (a *analyticsEvents) Create(ctx context.Context, eventSchema *api.Analytics
return response.JSON200, nil
}

// Retrieve analytics events.
//
// Retrieve the most recent events for a user and rule.
//
// HTTP: GET /analytics/events
//
// See: https://typesense.org/docs/latest/api/analytics-query-suggestions.html
func (a *analyticsEvents) Retrieve(ctx context.Context, params *api.GetAnalyticsEventsParams) (*api.AnalyticsEventsResponse, error) {
response, err := a.apiClient.GetAnalyticsEventsWithResponse(ctx, params)
if err != nil {
Expand Down
42 changes: 42 additions & 0 deletions typesense/analytics_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,29 @@ import (
)

type AnalyticsRuleInterface interface {
// Delete an analytics rule.
//
// Permanently deletes an analytics rule, given it's name
//
// HTTP: DELETE /analytics/rules/{ruleName}
//
// See: https://typesense.org/docs/latest/api/analytics-query-suggestions.html
Delete(ctx context.Context) (*api.AnalyticsRule, error)
// Retrieves an analytics rule.
//
// Retrieve the details of an analytics rule, given it's name
//
// HTTP: GET /analytics/rules/{ruleName}
//
// See: https://typesense.org/docs/latest/api/analytics-query-suggestions.html
Retrieve(ctx context.Context) (*api.AnalyticsRule, error)
// Upserts an analytics rule.
//
// Upserts an analytics rule with the given name.
//
// HTTP: PUT /analytics/rules/{ruleName}
//
// See: https://typesense.org/docs/latest/api/analytics-query-suggestions.html
Update(ctx context.Context, ruleSchema *api.AnalyticsRuleUpdate) (*api.AnalyticsRule, error)
}

Expand All @@ -17,6 +38,13 @@ type analyticsRule struct {
ruleName string
}

// Delete an analytics rule.
//
// # Permanently deletes an analytics rule, given it's name
//
// HTTP: DELETE /analytics/rules/{ruleName}
//
// See: https://typesense.org/docs/latest/api/analytics-query-suggestions.html
func (a *analyticsRule) Delete(ctx context.Context) (*api.AnalyticsRule, error) {
response, err := a.apiClient.DeleteAnalyticsRuleWithResponse(ctx, a.ruleName)
if err != nil {
Expand All @@ -28,6 +56,13 @@ func (a *analyticsRule) Delete(ctx context.Context) (*api.AnalyticsRule, error)
return response.JSON200, nil
}

// Retrieves an analytics rule.
//
// # Retrieve the details of an analytics rule, given it's name
//
// HTTP: GET /analytics/rules/{ruleName}
//
// See: https://typesense.org/docs/latest/api/analytics-query-suggestions.html
func (a *analyticsRule) Retrieve(ctx context.Context) (*api.AnalyticsRule, error) {
response, err := a.apiClient.RetrieveAnalyticsRuleWithResponse(ctx, a.ruleName)
if err != nil {
Expand All @@ -39,6 +74,13 @@ func (a *analyticsRule) Retrieve(ctx context.Context) (*api.AnalyticsRule, error
return response.JSON200, nil
}

// Upserts an analytics rule.
//
// Upserts an analytics rule with the given name.
//
// HTTP: PUT /analytics/rules/{ruleName}
//
// See: https://typesense.org/docs/latest/api/analytics-query-suggestions.html
func (a *analyticsRule) Update(ctx context.Context, ruleSchema *api.AnalyticsRuleUpdate) (*api.AnalyticsRule, error) {
response, err := a.apiClient.UpsertAnalyticsRuleWithResponse(ctx, a.ruleName, api.UpsertAnalyticsRuleJSONRequestBody(*ruleSchema))
if err != nil {
Expand Down
28 changes: 28 additions & 0 deletions typesense/analytics_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,35 @@ import (
)

type AnalyticsRulesInterface interface {
// Create analytics rule(s).
//
// Create one or more analytics rules. You can send a single rule object or an array of rule objects.
//
// HTTP: POST /analytics/rules
//
// See: https://typesense.org/docs/latest/api/analytics-query-suggestions.html
Create(ctx context.Context, rules []*api.AnalyticsRuleCreate) ([]*api.AnalyticsRule, error)
// Retrieve analytics rules.
//
// Retrieve all analytics rules. Use the optional rule_tag filter to narrow down results.
//
// HTTP: GET /analytics/rules
//
// See: https://typesense.org/docs/latest/api/analytics-query-suggestions.html
Retrieve(ctx context.Context) ([]*api.AnalyticsRule, error)
}

type analyticsRules struct {
apiClient APIClientInterface
}

// Create analytics rule(s).
//
// Create one or more analytics rules. You can send a single rule object or an array of rule objects.
//
// HTTP: POST /analytics/rules
//
// See: https://typesense.org/docs/latest/api/analytics-query-suggestions.html
func (a *analyticsRules) Create(ctx context.Context, rules []*api.AnalyticsRuleCreate) ([]*api.AnalyticsRule, error) {
// Convert []*AnalyticsRuleCreate to []AnalyticsRuleCreate for the API call
ruleCreates := make([]api.AnalyticsRuleCreate, len(rules))
Expand Down Expand Up @@ -73,6 +94,13 @@ func (a *analyticsRules) Create(ctx context.Context, rules []*api.AnalyticsRuleC
return nil, fmt.Errorf("failed to parse response: %s", string(responseBody))
}

// Retrieve analytics rules.
//
// Retrieve all analytics rules. Use the optional rule_tag filter to narrow down results.
//
// HTTP: GET /analytics/rules
//
// See: https://typesense.org/docs/latest/api/analytics-query-suggestions.html
func (a *analyticsRules) Retrieve(ctx context.Context) ([]*api.AnalyticsRule, error) {
response, err := a.apiClient.RetrieveAnalyticsRulesWithResponse(ctx, &api.RetrieveAnalyticsRulesParams{})
if err != nil {
Expand Down
Loading
Loading