Skip to content

Commit

Permalink
Merge branch 'release/v1.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jirenius committed Jun 15, 2020
2 parents 2d5c9ca + aea80b8 commit c6377af
Show file tree
Hide file tree
Showing 48 changed files with 2,274 additions and 1,493 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go
go:
- 1.13.x
- 1.14.1
- 1.14.4
install:
- go get -t ./...
- ./scripts/install-checks.sh
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.14.1-alpine3.11 as builder
FROM golang:1.14.4-alpine3.12 as builder

LABEL maintainer="Samuel Jirenius <[email protected]>"

Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.14.1-alpine3.11 as builder
FROM golang:1.14.4-alpine3.12 as builder

LABEL maintainer="Samuel Jirenius <[email protected]>"

Expand All @@ -15,7 +15,7 @@ COPY . .

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -ldflags "-s -w" -o /resgate

FROM alpine:3.11
FROM alpine:3.12
COPY --from=builder /resgate /bin/resgate

EXPOSE 8080
Expand Down
6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All changes to the RES Protocol will be documented in this file.

## v1.2.1 - [Resgate v1.6.0](compare/v1.4.0...v1.6.0) - 2020-06-15

* #157 Soft resource references.
* #161 Unsubscribe count field.
* #165 Data values.

## v1.2.0 - [Resgate v1.4.0](compare/v1.3.0...v1.4.0) - 2019-11-20

* #127 Resource response on query request.
Expand Down
29 changes: 18 additions & 11 deletions docs/res-client-protocol.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The RES-Client Protocol Specification

*Version: [1.2.0](res-protocol-semver.md)*
*Version: [1.2.1](res-protocol-semver.md)*

## Table of contents
- [Introduction](#introduction)
Expand Down Expand Up @@ -40,17 +40,17 @@ The RES-Client protocol is used in communication between the client and the gate

A core concept in the RES-Client protocol is the subscriptions. A client may subscribe to resources by making [subscribe requests](#subscribe-request) with the unique [resource ID](res-protocol.md#resource-ids), or by getting a resource response on a [call request](#call-request) or [auth request](#auth-request).

A resource may be subscribed to [directly](#direct-subscription) or [indirectly](#indirect-subscription). Any reference to *subscription*, or a resource being *subscribed* to, in this document should be interpreted as both *direct* and *indirect* subscriptions, unless specified.
A resource may be subscribed to [directly](#direct-subscription) or [indirectly](#indirect-subscription). Any reference in this document to *subscription* or a resource being *subscribed* to, should be interpreted as both *direct* and *indirect* subscriptions, unless specified.

The client will receive [events](#events) on anything that happens on a subscribed resource. A subscription lasts as long as the resource has direct or indirect subscriptions, or when the connection to the gateway is closed.

## Direct subscription
The resource that is subscribed to with a [subscribe request](#subscribe-request), or returned as a resource response to a [call request](#call-request) or [auth request](#auth-request) will be considered *directly subscribed*.

It is possible to make multiple direct subscriptions on a resource. It will be considered directly subscribed until an equal number of [unsubscribe requests](#unsubscribe-request) has been made.
It is possible to have multiple direct subscriptions on a resource. It will be considered directly subscribed until the same number of subscriptions are matched using one ore more [unsubscribe requests](#unsubscribe-request).

## Indirect subscription
A resource that is referred to with a [resource reference](res-protocol.md#values) by a [directly subscribed](#direct-subscription) resource, or by an indirectly subscribed resource, will be considered *indirectly subscribed*. Cyclic references where none of the resources are directly subscribed will not be considered subscribed.
A resource that is referred to with a non-soft [resource reference](res-protocol.md#resource-references) by a [directly subscribed](#direct-subscription) resource, or by an indirectly subscribed resource, will be considered *indirectly subscribed*. Cyclic references where none of the resources are directly subscribed will not be considered subscribed.


## Resource set
Expand Down Expand Up @@ -231,26 +231,33 @@ May be omitted if no subscribed resources encountered errors.
### Error

An error response will be sent if the resource couldn't be subscribed to.
Any [resource reference](res-protocol.md#values) that fails will not lead to an error response, but the error will be added to the [resource set](#resource-set) errors.
Any [resource reference](res-protocol.md#resource-references) that fails will not lead to an error response, but the error will be added to the [resource set](#resource-set) errors.

## Unsubscribe request

Unsubscribe requests are sent by the client to unsubscribe to a previous made [direct subscription](#direct-subscription).
Unsubscribe requests are sent by the client to unsubscribe to previous [direct subscriptions](#direct-subscription).

The resource will only be considered unsubscribed when there are no more [direct](#direct-subscription) or [indirect](#indirect-subscription) subscriptions.

If the **count** property is omitted in the request, the value of 1 is assumed.

**method**
`unsubscribe.<resourceID>`

### Parameters
The request has no parameters.
The request parameters are optional.
It not omitted, the parameters object SHOULD have the following property:

**count**
The number of direct subscriptions to unsubscribe to.
MUST be a number greater than 0.

### Result
The result has no payload.

### Error

An error response with code `system.noSubscription` will be sent if the resource has no direct subscription.
An error response with code `system.noSubscription` will be sent if the resource has no direct subscription, or if *count* exceeds the number of direct subscriptions. If so, the number of direct subscriptions will be unaffected.


## Get request
Expand Down Expand Up @@ -280,7 +287,7 @@ May be omitted if no retrieved resources encountered errors.
### Error

An error response will be sent if the resource couldn't be retrieved.
Any [resource reference](res-protocol.md#values) that fails will not lead to an error response, but the error will be added to the [resource set](#resource-set) errors.
Any [resource reference](res-protocol.md#resource-references) that fails will not lead to an error response, but the error will be added to the [resource set](#resource-set) errors.


## Call request
Expand Down Expand Up @@ -420,7 +427,7 @@ Event data. The payload is defined by the event type.
## Model change event

Change events are sent when a [model](res-protocol.md#models)'s properties has been changed.
Will result in new [indirect subscriptions](#indirect-subscription) if changed properties contain [resource references](res-protocol.md#values) previously not subscribed.
Will result in new [indirect subscriptions](#indirect-subscription) if changed properties contain [resource references](res-protocol.md#resource-references) previously not subscribed.
Change events are only sent on [models](res-protocol.md#models).

**event**
Expand Down Expand Up @@ -467,7 +474,7 @@ A delete action is a JSON object used when a property has been deleted from a mo

## Collection add event
Add events are sent when a value is added to a [collection](res-protocol.md#collections).
Will result in one or more new [indirect subscriptions](#indirect-subscription) if added value is a [resource references](res-protocol.md#values) previously not subscribed.
Will result in one or more new [indirect subscriptions](#indirect-subscription) if added value is a [resource references](res-protocol.md#resource-references) previously not subscribed.
Add events are only sent on [collections](res-protocol.md#collections).

**event**
Expand Down
1 change: 1 addition & 0 deletions docs/res-protocol-semver.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ New patch versions may include features like:
* The current RES Protocol version is stated at the top of the [RES Protocol Specification](res-protocol.md) document.
* The same version number is used for both the [RES Service protocol](res-service-protocol.md) and [RES Client protocol](res-client-protocol.md), even if some version changes only affect one part of the protocol.
* Language updates, clarifications, or added examples, does not justify a version change.
* Unreleased versions are given a preliminary PATCH version, which may change to a MINOR version on release.
41 changes: 31 additions & 10 deletions docs/res-protocol.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# RES Protocol

*Version: [1.2.0](res-protocol-semver.md)*
*Version: [1.2.1](res-protocol-semver.md)*

## Table of contents
- [Introduction](#introduction)
Expand Down Expand Up @@ -79,27 +79,48 @@ A collection is an ordered list of [values](#values) represented by a JSON array

## Values

A value is either a *primitive* or a [resource reference](#resource-references).
A primitive is either a JSON `string`, `number`, `true`, `false`, or `null` value.
A value is either a [primitive](#primitives), a [resource reference](#resource-references), or a [data value](#data-values).

### Example
```javascript
"foo" // string
42 // number
true // boolean true
false // boolean false
null // null
{ "rid": "example.user.42" } // resource reference
"foo" // string
42 // number
true // boolean true
false // boolean false
null // null

{ "rid": "example.user.42" } // resource reference
{ "rid": "example.page.2", "soft":true } // soft reference
{ "data": { "foo": [ "bar" ] }} // data value
{ "data": 42 } // data value interchangeable with the primitive 42
```

## Primitives

A primitive is either a JSON `string`, `number`, `true`, `false`, or `null` value.

## Resource references

A resource reference is a JSON objects with the following parameter:
A resource reference is a link to a resource. A *soft reference* is a resource reference which will not automatically be followed by the gateway. The resource reference is a JSON object with the following parameters:

**rid**
Resource ID of the referenced resource.
MUST be a valid [resource ID](#resource-ids).

**soft**
Flag telling if the reference is a soft resource reference.
May be omitted if the reference is not a soft reference.
MUST be a boolean.

## Data values

A data value contains any JSON value, including nested objects and arrays.
If the contained value can be expressed as a [primitive](#primitives), the data value is interchangeable with the primitive.
The data value is a JSON object with the following parameter:

**data**
The contained JSON value.

## Messaging system

The messaging system handles the communication between [services](#services) and [gateways](#gateways). It MUST provide the following functionality:
Expand Down
15 changes: 10 additions & 5 deletions docs/res-service-protocol.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The RES-Service Protocol Specification

*Version: [1.2.0](res-protocol-semver.md)*
*Version: [1.2.1](res-protocol-semver.md)*

## Table of contents
- [Introduction](#introduction)
Expand Down Expand Up @@ -152,14 +152,16 @@ MUST be a string.
### Result

**get**
Flag if the client has access to get (read) the resource.
Flag telling if the client has access to get (read) the resource, including any
resource recursively referenced by non-soft [resource
references](res-protocol.md#resource-references).
May be omitted if client has no get access.
MUST be a boolean
MUST be a boolean.

**call**
A comma separated list of methods that the client can call. Eg. `"set,foo,bar"`.
May be omitted if client is not allowed to call any methods.
Value may be a single asterisk character (`"*"`) if client is allowed to call any method.
Value may be a single asterisk character (`"*"`) if client is allowed to call any method.

### Error

Expand Down Expand Up @@ -343,7 +345,7 @@ For new models, the parameters SHOULD be an object containing the named properti
For new collections, the parameters SHOULD be an ordered array containing the [values](res-protocol.md#values) of the collection.

**Result**
MUST be a [resource reference](res-protocol.md#values) to the new resource.
MUST be a [resource reference](res-protocol.md#resource-references) to the new resource.


# Events
Expand Down Expand Up @@ -378,6 +380,7 @@ The event payload has the following parameter:
**values**
A key/value object describing the properties that was changed.
Each property should have a new [value](res-protocol.md#values) or a [delete action](#delete-action).
For changes in [data values](res-protocol.md#data-values), the value is changed in its entirety.
Unchanged properties SHOULD NOT be included.

**Example payload**
Expand All @@ -404,6 +407,7 @@ A delete action is a JSON object used when a property has been deleted from a mo
Add events are sent when a value is added to a [collection](res-protocol.md#collections).
Any previous value at the same index or higher will implicitly be shifted one step to a higher index.
MUST NOT be sent on [models](res-protocol.md#models).
Values cannot be added to arrays inside [data values](res-protocol.md#data-values), but the data value must be changed in its entirety.
The event payload has the following parameters:

**value**
Expand All @@ -429,6 +433,7 @@ MUST be a number that is zero or greater and less than or equal to the length of
Remove events are sent when a value is removed from a [collection](res-protocol.md#collections).
Any previous value at a higher index will implicitly be shifted one step to a lower index.
MUST NOT be sent on [models](res-protocol.md#models).
Values cannot be removed from arrays inside [data values](res-protocol.md#data-values), but the data value must be changed in its entirety.
The event payload has the following parameter:

**idx**
Expand Down
30 changes: 15 additions & 15 deletions examples/book-collection/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/book-collection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Resgate Book Collection Example",
"dependencies": {
"connect": "^3.7.0",
"nats": "^1.3.0",
"nats": "^1.4.9",
"serve-static": "^1.14.1"
},
"devDependencies": {},
Expand Down
Loading

0 comments on commit c6377af

Please sign in to comment.