fauna 2.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +5 -0
- data/LICENSE +1 -1
- data/README.md +6 -6
- data/fauna.gemspec +1 -1
- data/lib/fauna.rb +1 -0
- data/lib/fauna/client.rb +1 -1
- data/lib/fauna/json.rb +2 -0
- data/lib/fauna/objects.rb +40 -3
- data/lib/fauna/page.rb +4 -4
- data/lib/fauna/query.rb +16 -0
- data/lib/fauna/version.rb +1 -1
- data/spec/bytes_spec.rb +36 -0
- data/spec/fauna_helper.rb +4 -0
- data/spec/json_spec.rb +18 -0
- data/spec/query_spec.rb +24 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8996ca66ac2a5d3c0eb4d33251e3148e4a1e4de
|
4
|
+
data.tar.gz: 4b29fdaad2dc9b4a6f704bd5e6df7111abf25b0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa414baf0fff3c8a3e07c14fb7ec3ce000bbb4d306be7b1286be7c9495281584398d34b71505a4bc6d58ad34ebf8620f521bdc415c7822992be35f9018304045
|
7
|
+
data.tar.gz: e40f66fc8c23f1fb10d5e918e4788142503a017e76c74c444768c7b0efc7a2d3b6b76f729b3583d5f740c4531f782f890b21243f7402f8e58c4bfda9ae151be9
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
2.3.0
|
2
|
+
* Change default domain to `db.fauna.com`.
|
3
|
+
* Added `key_from_secret` and `at` query functions.
|
4
|
+
* Added support for `@bytes` type (via `Fauna::Bytes`).
|
5
|
+
|
1
6
|
2.2.0
|
2
7
|
* Added `create_class`, `create_index`, `create_database`, `create_key`, `database`, `class`,
|
3
8
|
and `index` query functions.
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# FaunaDB
|
2
2
|
|
3
|
-
[![Build Status](https://img.shields.io/travis/
|
4
|
-
[![Coverage Status](https://img.shields.io/codecov/c/github/
|
3
|
+
[![Build Status](https://img.shields.io/travis/fauna/faunadb-ruby/master.svg?maxAge=21600)](https://travis-ci.org/fauna/faunadb-ruby)
|
4
|
+
[![Coverage Status](https://img.shields.io/codecov/c/github/fauna/faunadb-ruby/master.svg?maxAge=21600)](https://codecov.io/gh/fauna/faunadb-ruby/branch/master)
|
5
5
|
[![Gem Version](https://img.shields.io/gem/v/fauna.svg?maxAge=21600)](https://rubygems.org/gems/fauna)
|
6
|
-
[![License](https://img.shields.io/badge/license-MPL_2.0-blue.svg?maxAge=2592000)](https://raw.githubusercontent.com/
|
6
|
+
[![License](https://img.shields.io/badge/license-MPL_2.0-blue.svg?maxAge=2592000)](https://raw.githubusercontent.com/fauna/faunadb-ruby/master/LICENSE)
|
7
7
|
|
8
8
|
Ruby driver for [FaunaDB](https://fauna.com).
|
9
9
|
|
@@ -23,11 +23,11 @@ And then execute:
|
|
23
23
|
|
24
24
|
## Documentation
|
25
25
|
|
26
|
-
The driver documentation is [hosted on GitHub Pages](https://
|
26
|
+
The driver documentation is [hosted on GitHub Pages](https://fauna.github.io/faunadb-ruby/).
|
27
27
|
|
28
28
|
Please see the [FaunaDB Documentation](https://fauna.com/documentation) for
|
29
29
|
a complete API reference, or look in
|
30
|
-
[`/test`](https://github.com/
|
30
|
+
[`/test`](https://github.com/fauna/faunadb-ruby/tree/master/test) for more
|
31
31
|
examples.
|
32
32
|
|
33
33
|
## Compatibility
|
@@ -130,7 +130,7 @@ GitHub pull requests are very welcome.
|
|
130
130
|
|
131
131
|
## LICENSE
|
132
132
|
|
133
|
-
Copyright
|
133
|
+
Copyright 2017 [Fauna, Inc.](https://fauna.com/)
|
134
134
|
|
135
135
|
Licensed under the Mozilla Public License, Version 2.0 (the
|
136
136
|
"License"); you may not use this software except in compliance with
|
data/fauna.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.email = 'priority@fauna.com'
|
9
9
|
s.summary = 'FaunaDB Ruby driver'
|
10
10
|
s.description = 'Ruby driver for FaunaDB.'
|
11
|
-
s.homepage = 'https://github.com/
|
11
|
+
s.homepage = 'https://github.com/fauna/faunadb-ruby'
|
12
12
|
s.license = 'MPL-2.0'
|
13
13
|
|
14
14
|
s.files = %w(CHANGELOG Gemfile LICENSE README.md Rakefile fauna.gemspec lib/fauna.rb) + Dir.glob('lib/fauna/**') + Dir.glob('spec/**')
|
data/lib/fauna.rb
CHANGED
data/lib/fauna/client.rb
CHANGED
@@ -40,7 +40,7 @@ module Fauna
|
|
40
40
|
# +:observer+:: Callback that will be passed a RequestResult after every completed request.
|
41
41
|
# +:adapter+:: Faraday[https://github.com/lostisland/faraday] adapter to use. Either can be a symbol for the adapter, or an array of arguments.
|
42
42
|
def initialize(params = {})
|
43
|
-
@domain = params[:domain] || '
|
43
|
+
@domain = params[:domain] || 'db.fauna.com'
|
44
44
|
@scheme = params[:scheme] || 'https'
|
45
45
|
@port = params[:port] || (scheme == 'https' ? 443 : 80)
|
46
46
|
@read_timeout = params[:read_timeout] || 60
|
data/lib/fauna/json.rb
CHANGED
data/lib/fauna/objects.rb
CHANGED
@@ -2,7 +2,7 @@ module Fauna
|
|
2
2
|
##
|
3
3
|
# A Ref.
|
4
4
|
#
|
5
|
-
# Reference: {FaunaDB Special Types}[https://fauna.com/documentation/queries
|
5
|
+
# Reference: {FaunaDB Special Types}[https://fauna.com/documentation/queries#values-special_types]
|
6
6
|
class Ref
|
7
7
|
# The raw ref string.
|
8
8
|
attr_accessor :value
|
@@ -63,7 +63,7 @@ module Fauna
|
|
63
63
|
##
|
64
64
|
# A SetRef.
|
65
65
|
#
|
66
|
-
# Reference: {FaunaDB Special Types}[https://fauna.com/documentation/queries
|
66
|
+
# Reference: {FaunaDB Special Types}[https://fauna.com/documentation/queries#values-special_types]
|
67
67
|
class SetRef
|
68
68
|
# The raw set hash.
|
69
69
|
attr_accessor :value
|
@@ -73,7 +73,7 @@ module Fauna
|
|
73
73
|
#
|
74
74
|
# +params+:: Hash of parameters to build the SetRef with.
|
75
75
|
#
|
76
|
-
# Reference: {FaunaDB Special Types}[https://fauna.com/documentation/queries
|
76
|
+
# Reference: {FaunaDB Special Types}[https://fauna.com/documentation/queries#values-special_types]
|
77
77
|
def initialize(params = {})
|
78
78
|
self.value = params
|
79
79
|
end
|
@@ -91,4 +91,41 @@ module Fauna
|
|
91
91
|
|
92
92
|
alias_method :eql?, :==
|
93
93
|
end
|
94
|
+
|
95
|
+
##
|
96
|
+
# A Bytes wrapper.
|
97
|
+
#
|
98
|
+
# Reference: {FaunaDB Special Types}[https://fauna.com/documentation/queries#values-special_types]
|
99
|
+
class Bytes
|
100
|
+
# The raw bytes.
|
101
|
+
attr_accessor :bytes
|
102
|
+
|
103
|
+
##
|
104
|
+
# Creates a new Bytes wrapper with the given parameters.
|
105
|
+
#
|
106
|
+
# +bytes+:: The bytes to be wrapped by the Bytes object.
|
107
|
+
#
|
108
|
+
# Reference: {FaunaDB Special Types}[https://fauna.com/documentation/queries#values-special_types]
|
109
|
+
def initialize(bytes)
|
110
|
+
self.bytes = bytes
|
111
|
+
end
|
112
|
+
|
113
|
+
# Converts the Bytes to Hash form.
|
114
|
+
def to_hash
|
115
|
+
{ :@bytes => Base64.urlsafe_encode64(bytes) }
|
116
|
+
end
|
117
|
+
|
118
|
+
# Returns +true+ if +other+ is a Bytes and contains the same bytes.
|
119
|
+
def ==(other)
|
120
|
+
return false unless other.is_a? Bytes
|
121
|
+
bytes == other.bytes
|
122
|
+
end
|
123
|
+
|
124
|
+
alias_method :eql?, :==
|
125
|
+
|
126
|
+
# Create new Bytes object from Base64 encoded bytes.
|
127
|
+
def self.from_base64(enc)
|
128
|
+
new(Base64.urlsafe_decode64(enc))
|
129
|
+
end
|
130
|
+
end
|
94
131
|
end
|
data/lib/fauna/page.rb
CHANGED
@@ -16,24 +16,24 @@ module Fauna
|
|
16
16
|
#
|
17
17
|
# Paging over a class index
|
18
18
|
#
|
19
|
-
# page = Page.new(client, Query.match(Ref('indexes/items')))
|
19
|
+
# page = Page.new(client, Query.match(Ref.new('indexes/items')))
|
20
20
|
#
|
21
21
|
# Paging over a class index 5 at a time, mapping the refs to the +data.value+ for each instance
|
22
22
|
#
|
23
|
-
# page = Page.new(client, Query.match(Ref('indexes/items')), size: 5) do |ref|
|
23
|
+
# page = Page.new(client, Query.match(Ref.new('indexes/items')), size: 5) do |ref|
|
24
24
|
# select ['data', 'value'], get(ref)
|
25
25
|
# end
|
26
26
|
#
|
27
27
|
# # Same thing, but using builders instead
|
28
28
|
#
|
29
|
-
# page = Page.new(client, Query.match(Ref('indexes/items'))).with_params(size: 5).map do |ref|
|
29
|
+
# page = Page.new(client, Query.match(Ref.new('indexes/items'))).with_params(size: 5).map do |ref|
|
30
30
|
# select ['data', 'value'], get(ref)
|
31
31
|
# end
|
32
32
|
#
|
33
33
|
# Paging over a class index, mapping refs to the +data.value+ for each instance, filtering out odd numbers, and
|
34
34
|
# multiplying the value:
|
35
35
|
#
|
36
|
-
# page = Page.new(client, Query.match(Ref('indexes/items'))).map do |ref|
|
36
|
+
# page = Page.new(client, Query.match(Ref.new('indexes/items'))).map do |ref|
|
37
37
|
# select ['data', 'value'], get(ref)
|
38
38
|
# end.filter do |value|
|
39
39
|
# equals modulo(value, 2), 0
|
data/lib/fauna/query.rb
CHANGED
@@ -66,6 +66,14 @@ module Fauna
|
|
66
66
|
|
67
67
|
# :section: Basic forms
|
68
68
|
|
69
|
+
##
|
70
|
+
# An at expression
|
71
|
+
#
|
72
|
+
# Reference: {FaunaDB Basic Forms}[https://fauna.com/documentation/queries#basic_forms]
|
73
|
+
def at(timestamp, expr)
|
74
|
+
Expr.new at: Expr.wrap(timestamp), expr: Expr.wrap(expr)
|
75
|
+
end
|
76
|
+
|
69
77
|
##
|
70
78
|
# A let expression
|
71
79
|
#
|
@@ -243,6 +251,14 @@ module Fauna
|
|
243
251
|
Expr.new Expr.wrap_values(params).merge(get: Expr.wrap(ref))
|
244
252
|
end
|
245
253
|
|
254
|
+
##
|
255
|
+
# A key_from_secret expression
|
256
|
+
#
|
257
|
+
# Reference: {FaunaDB Read functions}[https://fauna.com/documentation/queries#read_functions]
|
258
|
+
def key_from_secret(secret)
|
259
|
+
Expr.new key_from_secret: Expr.wrap(secret)
|
260
|
+
end
|
261
|
+
|
246
262
|
##
|
247
263
|
# A paginate expression
|
248
264
|
#
|
data/lib/fauna/version.rb
CHANGED
data/spec/bytes_spec.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
RSpec.describe Fauna::Bytes do
|
2
|
+
describe '#initalize' do
|
3
|
+
it 'creates from bytes' do
|
4
|
+
raw = random_bytes
|
5
|
+
expect(Fauna::Bytes.new(raw).bytes).to eq(raw)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#from_base64' do
|
10
|
+
it 'creates from base64' do
|
11
|
+
raw = random_bytes
|
12
|
+
encoded = Base64.urlsafe_encode64(raw)
|
13
|
+
|
14
|
+
expect(Fauna::Bytes.from_base64(encoded).bytes).to eq(raw)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#==' do
|
19
|
+
it 'equals same bytes' do
|
20
|
+
raw = random_bytes
|
21
|
+
bytes = Fauna::Bytes.new(raw)
|
22
|
+
|
23
|
+
expect(bytes).to eq(Fauna::Bytes.new(raw))
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'does not equal different bytes' do
|
27
|
+
expect(Fauna::Bytes.new(random_bytes)).not_to eq(Fauna::Bytes.new(random_bytes))
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'does not equal other type' do
|
31
|
+
raw = random_bytes
|
32
|
+
|
33
|
+
expect(Fauna::Bytes.new(raw)).not_to eq(raw)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/spec/fauna_helper.rb
CHANGED
data/spec/json_spec.rb
CHANGED
@@ -40,6 +40,15 @@ RSpec.describe Fauna::FaunaJson do
|
|
40
40
|
expect(Fauna::FaunaJson.deserialize(data)).to eq(obj)
|
41
41
|
end
|
42
42
|
|
43
|
+
it 'deserializes bytes' do
|
44
|
+
raw = random_bytes
|
45
|
+
|
46
|
+
data = { :@bytes => Base64.urlsafe_encode64(raw) }
|
47
|
+
obj = Fauna::Bytes.new(raw)
|
48
|
+
|
49
|
+
expect(Fauna::FaunaJson.deserialize(data)).to eq(obj)
|
50
|
+
end
|
51
|
+
|
43
52
|
it 'recursively deserializes hashes' do
|
44
53
|
ref = random_ref_string
|
45
54
|
|
@@ -100,6 +109,15 @@ RSpec.describe Fauna::FaunaJson do
|
|
100
109
|
expect(Fauna::FaunaJson.serialize(obj)).to eq(data)
|
101
110
|
end
|
102
111
|
|
112
|
+
it 'serializes bytes' do
|
113
|
+
raw = random_bytes
|
114
|
+
|
115
|
+
data = { :@bytes => Base64.urlsafe_encode64(raw) }
|
116
|
+
obj = Fauna::Bytes.new(raw)
|
117
|
+
|
118
|
+
expect(Fauna::FaunaJson.serialize(obj)).to eq(data)
|
119
|
+
end
|
120
|
+
|
103
121
|
it 'recursively serializes hashes' do
|
104
122
|
ref = random_ref_string
|
105
123
|
terms = random_string
|
data/spec/query_spec.rb
CHANGED
@@ -123,6 +123,20 @@ RSpec.describe Fauna::Query do
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
+
describe '#at' do
|
127
|
+
it 'performs at for given expression' do
|
128
|
+
instance = create_instance
|
129
|
+
ref = instance[:ref]
|
130
|
+
ts = instance[:ts]
|
131
|
+
|
132
|
+
prev_ts = ts - 1
|
133
|
+
value = random_number
|
134
|
+
client.query { insert(ref, prev_ts, :create, data: { x: value }) }
|
135
|
+
|
136
|
+
expect(client.query { at(prev_ts, get(ref)) }[:data]).to eq(x: value)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
126
140
|
describe '#let' do
|
127
141
|
it 'performs let with expression' do
|
128
142
|
x = random_number
|
@@ -284,6 +298,16 @@ RSpec.describe Fauna::Query do
|
|
284
298
|
end
|
285
299
|
end
|
286
300
|
|
301
|
+
describe '#key_from_secret' do
|
302
|
+
it 'gets key from secret' do
|
303
|
+
# Create a key
|
304
|
+
db_ref = admin_client.query { create(ref('databases'), name: random_string) }[:ref]
|
305
|
+
key = admin_client.query { create_key(database: db_ref, role: 'server') }
|
306
|
+
|
307
|
+
expect(admin_client.query { key_from_secret key[:secret] }).to eq(admin_client.query { get key[:ref] })
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
287
311
|
describe '#paginate' do
|
288
312
|
before do
|
289
313
|
@x_value = random_number
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fauna
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fauna, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- lib/fauna/request_result.rb
|
122
122
|
- lib/fauna/util.rb
|
123
123
|
- lib/fauna/version.rb
|
124
|
+
- spec/bytes_spec.rb
|
124
125
|
- spec/client_logger_spec.rb
|
125
126
|
- spec/client_spec.rb
|
126
127
|
- spec/context_spec.rb
|
@@ -133,7 +134,7 @@ files:
|
|
133
134
|
- spec/setref_spec.rb
|
134
135
|
- spec/spec_helper.rb
|
135
136
|
- spec/util_spec.rb
|
136
|
-
homepage: https://github.com/
|
137
|
+
homepage: https://github.com/fauna/faunadb-ruby
|
137
138
|
licenses:
|
138
139
|
- MPL-2.0
|
139
140
|
metadata: {}
|
@@ -158,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
159
|
version: '0'
|
159
160
|
requirements: []
|
160
161
|
rubyforge_project:
|
161
|
-
rubygems_version: 2.
|
162
|
+
rubygems_version: 2.6.10
|
162
163
|
signing_key:
|
163
164
|
specification_version: 4
|
164
165
|
summary: FaunaDB Ruby driver
|
@@ -173,5 +174,6 @@ test_files:
|
|
173
174
|
- spec/errors_spec.rb
|
174
175
|
- spec/setref_spec.rb
|
175
176
|
- spec/ref_spec.rb
|
177
|
+
- spec/bytes_spec.rb
|
176
178
|
- spec/spec_helper.rb
|
177
179
|
- spec/json_spec.rb
|