1.6.0 • Published 17 days ago

@restorecommerce/resource-base-interface v1.6.0

Weekly downloads
19
License
MIT
Repository
github
Last release
17 days ago

resource-base-interface

VersionBuild StatusDependenciesCoverage Status

https://github.com/restorecommerce/notification-srv/actions/workflows/build.yaml[image:https://img.shields.io/github/actions/workflow/status/restorecommerce/notification-srv/build.yaml?style=flat-square[Build Status]]

The resource-base-interface describes resource CRUD operations which can be bound to a service. Such operations are described via a gRPC interface with the message structures therefore being defined using Protocol Buffers. This interface can be bound with any protobuf definition as long as it contains the endpoints defined in the resource-base.proto file (note that any resource message structure can be defined).

The exposed gRPC methods are implemented by the ServiceBase object which uses a ResourceAPI instance to perform operations with a database provider. The exposed interface is therefore agnostic to a specific database implementation. However, a valid database provider is required. A set of such providers is implemented in chassis-srv. This interface emits resource-related messages to Apache Kafka which can be enabled or disabled at the ServiceBase's constructor.

Methods for managing and traversing graph databases are supported for the ArangoDB provider

gRPC Interface

This interface describes the following gRPC endpoints for a generic resource of type Resource.

io.restorecommerce.resourcebase.Resource

FieldTypeLabelDescription
idstringoptionalidentifier for the resource
metaio.restorecommerce.meta.Meta metaoptionalMeta information common to all Restore Commerce resources
valuenumberoptionalvalue for the resource
textstringoptionaltextual data for the resource

Create

This operation is used for inserting resources to the database. Requests are performed by providing a list of resources which are returned in the response. A meta should be present, containing relevant resource ownership information. Timestamps for creation and modification are then appended automatically to this property upon a Create request. The resource is stored as a normal collection document by default. If there is a graph configuration specified for the resource then it is stored as a vertex collection along with the edge definitions provided in the configuration.

io.restorecommerce.resourcebase.ResourceList

FieldTypeLabelDescription
items io.restorecommerce.resourcebase.Resourcerequiredlist of resources
total_countnumberoptionaltotal number of resources

Read

This operation returns resources based on provided filter and options. Requests are performed using io.restorecommerce.resourcebase.ReadRequest and responses are a list of resources.

io.restorecommerce.resourcebase.ReadRequest

FieldTypeLabelDescription
offsetnumberoptionaloffset of the resource
limitnumberoptionallimit, default value is 1000
filtersio.restorecommerce.filter.FilterOpoptionalnested filters based on field values, multiple filters can be combined with AND and OR operators
sorts io.restorecommerce.resourcebase.Sortoptionalsort the resources
fields io.restorecommerce.resourcebase.FieldFilteroptionalfields selector, list of fields to be included or excluded, by default we get all the fields
search stringoptionalword search, not yet implemeneted
locales_limiter stringoptionalquerying based on locales, not yet implemented

io.restorecommerce.filter.FilterOp

FieldTypeLabelDescription
filtersio.restorecommerce.filter.Filteroptionalnested filters
operatorenumoptionaloperator and, or or

io.restorecommerce.graph.Filter

FieldTypeLabelDescription
fieldstringrequiredfilter based on field
operationenumoptionaloperator eq, lt, lte, gt, gte, isEmpty, ilike, in, neq, default value is eq
valuestringrequiredfilter based on value
typeenumoptionalvalue type STRING, NUMBER, BOOLEAN, DATE or ARRAY, default value is STRING
filters io.restorecommerce.filter.FilterOprequirednested filters

io.restorecommerce.resourcebase.Sort

FieldTypeLabelDescription
fieldstringoptionalfield to be sorted upon
SortOrderenumoptionalsorting order, UNSORTED, ASCENDING or DESCENDING

io.restorecommerce.resourcebase.FieldFilter

FieldTypeLabelDescription
namestringoptionalfield name
includebooloptionalinclude or exclude field

Update

This operation is used for updating resources in the database. Requests are performed by providing a list of resources and all updated items are returned within the response. Note that the only required properties on each resource are its id and the properties which are meant to be modified. It is possible to specify in the configuration multiple edge definitions for one vertex. These edges are automatically updated when vertex documents are updated.

Upsert

This operation is used for updating resources in the database or creating them if they do not exist. Requests are performed by providing a resource list, which is returned in the response.

Delete

This operation is used for deleting resources in the database. Requests are performed using io.restorecommerce.resourcebase.DeleteRequest and responses are google.protobuf.Empty messages. If a graph vertex is deleted, all connected edges are also deleted.

io.restorecommerce.resourcebase.DeleteRequest

FieldTypeLabelDescription
collectionstringoptionalName of the target collection
ids stringoptionalList of resource identifiers to be deleted; if empty or not provided, the whole collection is truncated

Traversal

This operation is used for traversing graph resource in the database. Requests are performed using io.restorecommerce.graph.TraversalRequest and respone is io.restorecommerce.graph.TraversalResponse message.

io.restorecommerce.graph.TraversalRequest

FieldTypeLabelDescription
vertices io.restorecommerce.graph.Verticesoptionallist of vertices for traversal
collectionio.restorecommerce.graph.Collectionoptionalcollection data for traversal
optsio.restorecommerce.graph.OptionsoptionalList of options for graph traversal
pathbooloptionalif set to true only the traversed paths are returned
subjectio.restorecommerce.auth.SubjectrequiredSubject details
filtersio.restorecommerce.graph.Filtersoptionalfilters

io.restorecommerce.graph.Vertices

FieldTypeLabelDescription
collection_namestringrequiredcollection name
start_vertex_ids stringrequiredlist of start vertex ids

io.restorecommerce.graph.Collection

FieldTypeLabelDescription
collection_namestringrequiredcollection name
limit numberoptionallimit
sorts io.restorecommerce.resourcebase.Sortoptionalsorting based on fields

io.restorecommerce.graph.Filters

FieldTypeLabelDescription
entitystringoptionalentity name
edgestringoptionaledge name
filtersio.restorecommerce.graph.FilteroptionalFilter
operatorenumoptionaloperator, and or or, default is and

io.restorecommerce.graph.Options

FieldTypeLabelDescription
include_vertexs stringoptionallist of vertex's to be included in traversal
exclude_vertexs stringoptionallist of vertex's to be excluded in traversal
include_edges stringoptionallist of edge's to be included in traversal
exclude_edges stringoptionallist of edge's to be excluded in traversal
directionenumoptionaldirection of traversal, OUTBOUND or INBOUND, default is OUTBOUND

io.restorecommerce.graph.TraversalResponse

FieldTypeLabelDescription
pathsgoogle.protobuf.Anyrequiredbuffered data, contains the list of visited paths
datagoogle.protobuf.Anyrequiredbuffered data, contains all the data from the visited vertices
operation_statusio.restorecommerce.status.OperationStatusrequiredoperation status

Kafka Events

A kafka Topic can be provided when instantiating a ServiceBase. If enableEvents is set to true, a list of events is then emitted to Kafka by this microservice for each document of each CRUD request :

  • Created
  • Read
  • Modified
  • Deleted

The events emitted to Kafka can be used for restoring the system in case of failure by implementing a command-interface in the used microservice. For usage details please see command-interface tests.

Fields Configuration

It is possible to pass a fields configuration object to ResourceAPI in order to enable some special field handlers.

Field Generators

The strategies property can be used to specify fields within each resource which should be generated automatically. Such autogeneration feature currently includes UUIDs, timestamps and sequential counters. The latter one is particularly useful for fields such as a customer or an item number, which can have a type of sequential logic. In these cases, a Redis database is used to generate and read these values efficiently.

Buffer Fields

Buffer-encoded fields can be decoded before being stored in the database. It is possible to specify within the bufferFields property what fields of each resource should be specially handled this way. The values are also encoded into a buffer again when read from the database.

Required Fields

It is possible to specify which fields are required for each document of each resource on the requiredFields config. An InvalidArgument error is thrown if one of these fields is missing when attempting to store a document.

Development

Tests

See tests. To execute the tests a set of backing services are needed. Refer to System repository to start the backing-services before running the tests.

  • To run tests
npm run test

Usage

  • Install dependencies
npm install
  • Build
# compile the code
npm run build
1.6.0

17 days ago

1.5.0

22 days ago

1.4.8

2 months ago

1.4.6

2 months ago

1.4.7

2 months ago

1.4.5

3 months ago

1.4.4

5 months ago

1.4.3

5 months ago

1.2.5

10 months ago

1.4.2

6 months ago

1.2.4

10 months ago

1.4.1

6 months ago

1.2.3

10 months ago

1.4.0

7 months ago

1.2.2

10 months ago

1.3.0

8 months ago

1.2.0

11 months ago

1.2.1

11 months ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago

0.2.15

2 years ago

0.2.14

2 years ago

0.2.13

2 years ago

0.2.12

2 years ago

0.2.11

2 years ago

0.2.10

2 years ago

0.2.9

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.8

2 years ago

0.2.3

2 years ago

0.2.5

2 years ago

0.2.1

2 years ago

0.2.2

2 years ago

0.2.0

3 years ago

0.1.0

3 years ago

0.1.1

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago