nosql

package module
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2022 License: MPL-2.0 Imports: 15 Imported by: 4

Documentation

Overview

Package nosql provides a consistent and unique API for NoSQL integrations, allowing to manage documents.

Index

Constants

View Source
const Specification string = "nosql"

Specification is the string representation of the NoSQL specification.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {

	// Collection is the collection name of the NoSQL database to interact with.
	// In some cases, this can also be referred as a "table".
	//
	// Example: "users"
	//
	// Required.
	Collection string `json:"collection"`

	// Key is the primary key that uniquely distinguishes a document in a collection.
	//
	// Example: "_id"
	//
	// Required.
	Key string `json:"key"`

	// Params holds optional parameters an integration might need to leverage.
	Params url.Values `json:"params,omitempty"`

	// Policies allows to set activity policies, such as timeouts and retries.
	Policies Policies `json:"policies"`
	// contains filtered or unexported fields
}

Config allows the end-user to configure the specification for an integration.

func (*Config) Validate

func (config *Config) Validate() error

Validate validates the config passed by the end-user when registering the specification for the overlying integration. It returns an error if anything critical occured.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler handles the NoSQL specification for an integration.

func New

func New(ctx context.Context, from integration.Integration, config Config, attachments ...With) (*Handler, error)

New returns a new NoSQL Handler for the given integration. It applies the configuration passed by the end-user (forwarded by the integration). It also applies additional attachments an integration might leverage.

Example:

func New(myintegration, config, WithCollection(collection))

func (*Handler) ActivityCreateExecution

func (h *Handler) ActivityCreateExecution(ctx context.Context, input Input) (Output, error)

ActivityCreateExecution is the activity executing the creation request against the collection.

func (*Handler) ActivityCreateValidation

func (h *Handler) ActivityCreateValidation(ctx context.Context, input Input) (Output, error)

ActivityCreateValidation is the activity validating the input.

func (*Handler) ActivityDeleteExecution

func (h *Handler) ActivityDeleteExecution(ctx context.Context, input Input) (Output, error)

ActivityDeleteExecution is the activity executing the deletion request against the collection.

func (*Handler) ActivityDeleteValidation

func (h *Handler) ActivityDeleteValidation(ctx context.Context, input Input) (Output, error)

ActivityDeleteValidation is the activity validating the input.

func (*Handler) ActivityPutExecution

func (h *Handler) ActivityPutExecution(ctx context.Context, input Input) (Output, error)

ActivityPutExecution is the activity executing the put request against the collection.

func (*Handler) ActivityPutValidation

func (h *Handler) ActivityPutValidation(ctx context.Context, input Input) (Output, error)

ActivityPutValidation is the activity validating the input.

func (*Handler) ActivityReplaceExecution

func (h *Handler) ActivityReplaceExecution(ctx context.Context, input Input) (Output, error)

ActivityReplaceExecution is the activity executing the replace request against the collection.

func (*Handler) ActivityReplaceValidation

func (h *Handler) ActivityReplaceValidation(ctx context.Context, input Input) (Output, error)

ActivityReplaceValidation is the activity validating the input.

func (*Handler) ActivityUpdateExecution

func (h *Handler) ActivityUpdateExecution(ctx context.Context, input Input) (Output, error)

ActivityUpdateExecution is the activity executing the update request against the collection.

func (*Handler) ActivityUpdateValidation

func (h *Handler) ActivityUpdateValidation(ctx context.Context, input Input) (Output, error)

ActivityUpdateValidation is the activity validating the input.

func (*Handler) Close

func (h *Handler) Close() error

Close tries to properly close the specification. An error is returned in case the Handler has already been closed.

func (*Handler) ConfigMap

func (h *Handler) ConfigMap() map[string]any

ConfigMap transforms the configuration to a map, including a "from" key with the configuration of the overlying integration.

func (*Handler) Init

func (h *Handler) Init() error

Init initializes the specification. An error is returned in case the Handler has already been initialized.

func (*Handler) IsReady

func (h *Handler) IsReady() bool

IsReady indicates if the specification is ready to be consumed by the overlying integration. The specification must be initialized, must not be closed, and must have registered its workflows and activities in the Temporal worker.

func (*Handler) ListActivities

func (h *Handler) ListActivities() []string

ListActivities returns a sorted list of activities' name registered by the specification for the overlying integration.

func (*Handler) ListWorkflows

func (h *Handler) ListWorkflows() []string

ListWorkflows returns a sorted list of workflows' name registered by the specification for the overlying integration.

func (*Handler) Register

func (h *Handler) Register(w worker.Worker) error

Register registers the specification's workflows and activities in the given Temporal worker. An error is returned in case the registration has already been made.

func (*Handler) String

func (h *Handler) String() string

String returns the string representation of the overlying integration.

func (*Handler) WorkflowCreate

func (h *Handler) WorkflowCreate(ctx workflow.Context, input Input) (Output, error)

WorkflowCreate is a high-level opiniated Temporal workflow. It executes the following activities:

  1. ActivityCreateValidation: Validates the input (local activity).

  2. ActivityCreateRequest: Executes the requests

func (*Handler) WorkflowDelete

func (h *Handler) WorkflowDelete(ctx workflow.Context, input Input) (Output, error)

WorkflowDelete is a high-level opiniated Temporal workflow. It executes the following activities:

  1. ActivityDeleteValidation: Validates the input (local activity).

  2. ActivityDeleteExecution: Executes the request against the NoSQL database to delete a document from the collection.

func (*Handler) WorkflowPut

func (h *Handler) WorkflowPut(ctx workflow.Context, input Input) (Output, error)

WorkflowPut is a high-level opiniated Temporal workflow. It executes the following activities:

  1. ActivityPutValidation: Validates the input (local activity).

  2. ActivityPutExecution: Executes the request against the NoSQL database to put a document in the collection.

func (*Handler) WorkflowReplace

func (h *Handler) WorkflowReplace(ctx workflow.Context, input Input) (Output, error)

WorkflowReplace is a high-level opiniated Temporal workflow. It executes the following activities:

  1. ActivityReplaceValidation: Validates the input (local activity).

  2. ActivityReplaceExecution: Executes the request against the NoSQL database to replace a document in the collection.

func (*Handler) WorkflowUpdate

func (h *Handler) WorkflowUpdate(ctx workflow.Context, input Input) (Output, error)

WorkflowUpdate is a high-level opiniated Temporal workflow. It executes the following activities:

  1. ActivityUpdateValidation: Validates the input (local activity).

  2. ActivityUpdateExecution: Executes the request against the NoSQL database to update a document in the collection.

type Input

type Input struct {

	// Policies passed in the input can override the ones set when creating the
	// specification. It will only apply if allowed in the integration's Config
	// via AllowPoliciesOverride.
	Policies *Policies `json:"policies"`

	// Context represents the event's context, shared across every specifications
	// and integrations of this ecosystem.
	Context *event.Context `json:"context,omitempty"`

	// Document is the document to write in the NoSQL database. It will be written
	// as-is, with no transformation. The Key set in the specification's Config
	// must always be set in the map and must be a string. Otherwise the validation
	// will fail, regardless the method to execute.
	//
	// Example:
	//
	//  map[string]any{
	//    "_id": "y943yr7843yr873",
	//  }
	//
	Document map[string]any `json:"document"`
}

Input is the input workflows and activities share when operating on a document. Either it's a "Create", "Put", "Update", "Replace", or "Delete", the output always follows the same convention.

func (*Input) Validate

func (input *Input) Validate(config *Config) error

Validate can be used to validate the workflow/activity's input. It's the validation function used in the share activity activityValidation.

type NoSQL

type NoSQL interface {

	// RegisterWithNoSQL allows an end-user to register the nosql specification
	// within an integration.
	RegisterWithNoSQL(worker.Worker, Config) error
}

NoSQL is the interface used by an overlying integration to leverage the nosql specification.

type Output

type Output struct {

	// Status is the status of the workflow or activity. It's one of "success",
	// "failure".
	Status lifecycle.Status `json:"status"`

	// Document is the document returned by the NoSQL database after the execution.
	// It may be altered by the database with new/updated/deleted fields.
	//
	// Note: If the NoSQL database is eventually consistent, the document returned
	// might not reflect the changes just applied.
	Document map[string]any `json:"document"`
}

Output is the output workflows and activities share after operating on a document. Either it's a "Create", "Put", "Update", "Replace", or "Delete", the output always follows the same convention.

type Policies

type Policies struct {

	// Execution is the policy to apply by the activity used to make the HTTP request
	// against the third-party service.
	//
	// Note: Since this is a short-live policy, activity's heartbeat is not used.
	// Therefore, Execution.HeartbeatTimeout is not applied. We advise to set a
	// short-live Execution.SingleAttemptTimeout, such as 3 seconds.
	Execution lifecycle.ActivityPolicy `json:"execution"`
	// contains filtered or unexported fields
}

Policies represents the Temporal activity policies to apply within the workflows exposed by this package and the overlying integration.

type With

type With func(*Handler) error

With allows an integration to customize the behavior of the specification. It's in addition to Config. Since Config is designed for — and accessible by — end-users, With is specifically designed for integrations.

For example, an integration must call WithCollection to attach the *docstore.Collection:

func New(myintegration, config, WithCollection(collection))

func WithCollection

func WithCollection(collection *docstore.Collection) With

WithCollection must be passed to New to attach the *docstore.Collection from the overlying integration:

func New(myintegration, config, WithCollection(collection))

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL