pending

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BootstrappedPendingDocumentService is the key to bootstrapped document service
	BootstrappedPendingDocumentService = "BootstrappedPendingDocumentService"
)
View Source
const (
	// DocPrefix holds the generic prefix of a document in DB
	DocPrefix string = "pending_document_"
)
View Source
const ErrPendingDocumentExists = errors.Error("Pending document already created")

ErrPendingDocumentExists is a sentinel error used when document was created and tried to create a new one.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddTransitionRules

type AddTransitionRules struct {
	AttributeRules     []AttributeRule     `json:"attribute_rules"`
	ComputeFieldsRules []ComputeFieldsRule `json:"compute_fields_rules"`
}

AddTransitionRules contains list of attribute rules to be created.

type AttributeRule

type AttributeRule struct {
	// attribute key label
	KeyLabel string `json:"key_label"`

	// roleID is 32 byte role ID in hex. RoleID should already be part of the document.
	RoleID byteutils.HexBytes `json:"role_id" swaggertype:"primitive,string"`
}

AttributeRule contains Attribute key label for which the rule has to be created with write access enabled to RoleID Note: role ID should already exist in the document.

type Bootstrapper

type Bootstrapper struct{}

Bootstrapper implements bootstrap.Bootstrapper.

func (Bootstrapper) Bootstrap

func (Bootstrapper) Bootstrap(ctx map[string]interface{}) error

Bootstrap sets the required storage and registers

type ComputeFieldsRule added in v1.2.0

type ComputeFieldsRule struct {
	WASM byteutils.HexBytes `json:"wasm" swaggertype:"primitive,string"`

	// AttributeLabels that are passed to the WASM for execution
	AttributeLabels []string `json:"attribute_labels"`

	// TargetAttributeLabel is the label of the attribute which holds the result from the executed WASM.
	// This attribute is automatically added and updated everytime document is updated.
	TargetAttributeLabel string `json:"target_attribute_label"`
}

ComputeFieldsRule contains compute wasm, attribute fields, and target field

type Repository

type Repository interface {
	// Get returns the Document associated with ID, owned by accountID
	Get(accountID, id []byte) (documents.Document, error)

	// Create creates the model if not present in the DB.
	// should error out if the document exists.
	Create(accountID, id []byte, model documents.Document) error

	// Update strictly updates the model.
	// Will error out when the model doesn't exist in the DB.
	Update(accountID, id []byte, model documents.Document) error

	// Delete deletes the data associated with account and ID.
	Delete(accountID, id []byte) error
}

Repository defines the required methods for a document repository. Can be implemented by any type that stores the documents. Ex: levelDB, sql etc...

func NewRepository

func NewRepository(db storage.Repository) Repository

NewRepository creates an instance of the pending document Repository

type Service

type Service interface {
	// Get returns the document associated with docID and Status.
	Get(ctx context.Context, docID []byte, status documents.Status) (documents.Document, error)

	// GetVersion returns the document associated with docID and versionID.
	GetVersion(ctx context.Context, docID, versionID []byte) (documents.Document, error)

	// Update updates a pending document from the payload
	Update(ctx context.Context, payload documents.UpdatePayload) (documents.Document, error)

	// Create creates a pending document from the payload
	Create(ctx context.Context, payload documents.UpdatePayload) (documents.Document, error)

	// Clone creates a pending document from the template document
	Clone(ctx context.Context, payload documents.ClonePayload) (documents.Document, error)

	// Commit validates, shares and anchors document
	Commit(ctx context.Context, docID []byte) (documents.Document, gocelery.JobID, error)

	// AddSignedAttribute signs the value using the account keys and adds the attribute to the pending document.
	AddSignedAttribute(ctx context.Context, docID []byte, label string, value []byte, valType documents.AttributeType) (documents.Document, error)

	// AddAttributes adds attributes to the document.
	AddAttributes(ctx context.Context, docID []byte, attrs []documents.Attribute) (documents.Document, error)

	// DeleteAttribute deletes an attribute in the document.
	DeleteAttribute(ctx context.Context, docID []byte, key documents.AttrKey) (documents.Document, error)

	// RemoveCollaborators removes collaborators from the document.
	RemoveCollaborators(ctx context.Context, docID []byte, dids []identity.DID) (documents.Document, error)

	// GetRole returns specific role in the latest version of the document.
	GetRole(ctx context.Context, docID, roleID []byte) (*coredocumentpb.Role, error)

	// AddRole adds a new role to given document
	AddRole(ctx context.Context, docID []byte, roleKey string, collabs []identity.DID) (*coredocumentpb.Role, error)

	// UpdateRole updates a role in the given document
	UpdateRole(ctx context.Context, docID, roleID []byte, collabs []identity.DID) (*coredocumentpb.Role, error)

	// AddTransitionRules creates transition rules to the given document.
	// The access is only given to the roleKey which is expected to be present already.
	AddTransitionRules(ctx context.Context, docID []byte, addRules AddTransitionRules) ([]*coredocumentpb.TransitionRule, error)

	// GetTransitionRule returns the transition rule associated with ruleID from the latest version of the document.
	GetTransitionRule(ctx context.Context, docID, ruleID []byte) (*coredocumentpb.TransitionRule, error)

	// DeleteTransitionRule deletes the transition rule associated with ruleID in th document.
	DeleteTransitionRule(ctx context.Context, docID, ruleID []byte) error
}

Service provides an interface for functions common to all document types

func DefaultService

func DefaultService(docSrv documents.Service, repo Repository) Service

DefaultService returns the default implementation of the service

Jump to

Keyboard shortcuts

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