Skip to content

Commit 394c6a9

Browse files
authored
Merge pull request #23 from nitrictech/feature/document-service
grpc faas, documents service and new sdk api conventions
2 parents 3178ac4 + 86d57e3 commit 394c6a9

87 files changed

Lines changed: 8601 additions & 7873 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Protoc Output Files
2-
*_pb2.py
3-
*_pb2_grpc.py
2+
nitric/proto/
43

54
.idea/
65

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ pip3 install nitric
4141

4242
```python
4343
# import classes/modules as required
44-
from nitric.api import EventClient, KeyValueClient
44+
from nitric.api import Events, KeyValueClient
4545
```

contracts

docs/nitric/api/events.html

Lines changed: 370 additions & 0 deletions
Large diffs are not rendered by default.

docs/nitric/api/index.html

Lines changed: 220 additions & 440 deletions
Large diffs are not rendered by default.

docs/nitric/api/kv.html

Lines changed: 67 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -44,44 +44,38 @@ <h1 class="title">Module <code>nitric.api.kv</code></h1>
4444
# See the License for the specific language governing permissions and
4545
# limitations under the License.
4646
#
47-
from nitric.proto import key_value
48-
from nitric.proto import key_value_service
49-
from nitric.api._base_client import BaseClient
50-
from google.protobuf.struct_pb2 import Struct
51-
from google.protobuf.json_format import MessageToDict
52-
from nitric.proto.kv.v1.kv_pb2 import KeyValueGetResponse
47+
from nitric.utils import new_default_channel, _struct_from_dict
48+
from nitric.proto.nitric.kv.v1 import KeyValueStub
5349

5450

55-
class KeyValueClient(BaseClient):
51+
class KeyValueClient(object):
5652
&#34;&#34;&#34;
5753
Nitric generic document store/db client.
5854

5955
This client insulates application code from stack specific document CRUD operations or SDKs.
6056
&#34;&#34;&#34;
6157

62-
def __init__(self):
63-
&#34;&#34;&#34;Construct a new DocumentClient.&#34;&#34;&#34;
64-
super(self.__class__, self).__init__()
65-
self._stub = key_value_service.KeyValueStub(self._channel)
58+
def __init__(self, collection: str):
59+
&#34;&#34;&#34;
60+
Construct a new DocumentClient.
6661

67-
def put(self, collection: str, key: str, value: dict):
68-
&#34;&#34;&#34;Create a new document with the specified key in the specified collection.&#34;&#34;&#34;
69-
value_struct = Struct()
70-
value_struct.update(value)
71-
request = key_value.KeyValuePutRequest(collection=collection, key=key, value=value_struct)
72-
return self._exec(&#34;Put&#34;, request)
62+
:param collection: name of the key/value collection
63+
&#34;&#34;&#34;
64+
self.collection = collection
65+
self._stub = KeyValueStub(channel=new_default_channel())
7366

74-
def get(self, collection: str, key: str) -&gt; dict:
75-
&#34;&#34;&#34;Retrieve a document from the specified collection by its key.&#34;&#34;&#34;
76-
request = key_value.KeyValueGetRequest(collection=collection, key=key)
77-
reply: KeyValueGetResponse = self._exec(&#34;Get&#34;, request)
78-
document = MessageToDict(reply)[&#34;value&#34;]
79-
return document
67+
async def put(self, key: str, value: dict):
68+
&#34;&#34;&#34;Create a new document with the specified key.&#34;&#34;&#34;
69+
await self._stub.put(collection=self.collection, key=key, value=_struct_from_dict(value))
8070

81-
def delete(self, collection: str, key: str):
71+
async def get(self, key: str) -&gt; dict:
72+
&#34;&#34;&#34;Retrieve a document from the specified key.&#34;&#34;&#34;
73+
response = await self._stub.get(collection=self.collection, key=key)
74+
return response.value.to_dict()
75+
76+
async def delete(self, key: str):
8277
&#34;&#34;&#34;Delete the specified document from the collection.&#34;&#34;&#34;
83-
request = key_value.KeyValueDeleteRequest(collection=collection, key=key)
84-
return self._exec(&#34;Delete&#34;, request)</code></pre>
78+
await self._stub.delete(collection=self.collection, key=key)</code></pre>
8579
</details>
8680
</section>
8781
<section>
@@ -95,94 +89,94 @@ <h2 class="section-title" id="header-classes">Classes</h2>
9589
<dl>
9690
<dt id="nitric.api.kv.KeyValueClient"><code class="flex name class">
9791
<span>class <span class="ident">KeyValueClient</span></span>
92+
<span>(</span><span>collection: str)</span>
9893
</code></dt>
9994
<dd>
10095
<div class="desc"><p>Nitric generic document store/db client.</p>
10196
<p>This client insulates application code from stack specific document CRUD operations or SDKs.</p>
102-
<p>Construct a new DocumentClient.</p></div>
97+
<p>Construct a new DocumentClient.</p>
98+
<p>:param collection: name of the key/value collection</p></div>
10399
<details class="source">
104100
<summary>
105101
<span>Expand source code</span>
106102
</summary>
107-
<pre><code class="python">class KeyValueClient(BaseClient):
103+
<pre><code class="python">class KeyValueClient(object):
108104
&#34;&#34;&#34;
109105
Nitric generic document store/db client.
110106

111107
This client insulates application code from stack specific document CRUD operations or SDKs.
112108
&#34;&#34;&#34;
113109

114-
def __init__(self):
115-
&#34;&#34;&#34;Construct a new DocumentClient.&#34;&#34;&#34;
116-
super(self.__class__, self).__init__()
117-
self._stub = key_value_service.KeyValueStub(self._channel)
110+
def __init__(self, collection: str):
111+
&#34;&#34;&#34;
112+
Construct a new DocumentClient.
113+
114+
:param collection: name of the key/value collection
115+
&#34;&#34;&#34;
116+
self.collection = collection
117+
self._stub = KeyValueStub(channel=new_default_channel())
118118

119-
def put(self, collection: str, key: str, value: dict):
120-
&#34;&#34;&#34;Create a new document with the specified key in the specified collection.&#34;&#34;&#34;
121-
value_struct = Struct()
122-
value_struct.update(value)
123-
request = key_value.KeyValuePutRequest(collection=collection, key=key, value=value_struct)
124-
return self._exec(&#34;Put&#34;, request)
119+
async def put(self, key: str, value: dict):
120+
&#34;&#34;&#34;Create a new document with the specified key.&#34;&#34;&#34;
121+
await self._stub.put(collection=self.collection, key=key, value=_struct_from_dict(value))
125122

126-
def get(self, collection: str, key: str) -&gt; dict:
127-
&#34;&#34;&#34;Retrieve a document from the specified collection by its key.&#34;&#34;&#34;
128-
request = key_value.KeyValueGetRequest(collection=collection, key=key)
129-
reply: KeyValueGetResponse = self._exec(&#34;Get&#34;, request)
130-
document = MessageToDict(reply)[&#34;value&#34;]
131-
return document
123+
async def get(self, key: str) -&gt; dict:
124+
&#34;&#34;&#34;Retrieve a document from the specified key.&#34;&#34;&#34;
125+
response = await self._stub.get(collection=self.collection, key=key)
126+
return response.value.to_dict()
132127

133-
def delete(self, collection: str, key: str):
128+
async def delete(self, key: str):
134129
&#34;&#34;&#34;Delete the specified document from the collection.&#34;&#34;&#34;
135-
request = key_value.KeyValueDeleteRequest(collection=collection, key=key)
136-
return self._exec(&#34;Delete&#34;, request)</code></pre>
130+
await self._stub.delete(collection=self.collection, key=key)</code></pre>
137131
</details>
138-
<h3>Ancestors</h3>
139-
<ul class="hlist">
140-
<li>nitric.api._base_client.BaseClient</li>
141-
<li>abc.ABC</li>
142-
</ul>
143132
<h3>Methods</h3>
144133
<dl>
145134
<dt id="nitric.api.kv.KeyValueClient.delete"><code class="name flex">
146-
<span>def <span class="ident">delete</span></span>(<span>self, collection: str, key: str)</span>
135+
<span>async def <span class="ident">delete</span></span>(<span>self, key: str)</span>
147136
</code></dt>
148137
<dd>
149138
<div class="desc"><p>Delete the specified document from the collection.</p></div>
150139
<details class="source">
151140
<summary>
152141
<span>Expand source code</span>
153142
</summary>
154-
<pre><code class="python">def delete(self, collection: str, key: str):
143+
<pre><code class="python">async def delete(self, key: str):
155144
&#34;&#34;&#34;Delete the specified document from the collection.&#34;&#34;&#34;
156-
request = key_value.KeyValueDeleteRequest(collection=collection, key=key)
157-
return self._exec(&#34;Delete&#34;, request)</code></pre>
145+
await self._stub.delete(collection=self.collection, key=key)</code></pre>
158146
</details>
159147
</dd>
160148
<dt id="nitric.api.kv.KeyValueClient.get"><code class="name flex">
161-
<span>def <span class="ident">get</span></span>(<span>self, collection: str, key: str) ‑> dict</span>
149+
<span>async def <span class="ident">get</span></span>(<span>self, key: str) ‑> dict</span>
162150
</code></dt>
163151
<dd>
164-
<div class="desc"><p>Retrieve a document from the specified collection by its key.</p></div>
152+
<div class="desc"><p>Retrieve a document from the specified key.</p></div>
165153
<details class="source">
166154
<summary>
167155
<span>Expand source code</span>
168156
</summary>
169-
<pre><code class="python">def get(self, collection: str, key: str) -&gt; dict:
170-
&#34;&#34;&#34;Retrieve a document from the specified collection by its key.&#34;&#34;&#34;
171-
request = key_value.KeyValueGetRequest(collection=collection, key=key)
172-
reply: KeyValueGetResponse = self._exec(&#34;Get&#34;, request)
173-
document = MessageToDict(reply)[&#34;value&#34;]
174-
return document</code></pre>
157+
<pre><code class="python">async def get(self, key: str) -&gt; dict:
158+
&#34;&#34;&#34;Retrieve a document from the specified key.&#34;&#34;&#34;
159+
response = await self._stub.get(collection=self.collection, key=key)
160+
return response.value.to_dict()</code></pre>
175161
</details>
176162
</dd>
177163
<dt id="nitric.api.kv.KeyValueClient.put"><code class="name flex">
164+
<<<<<<< refs/remotes/origin/main
178165
<span>def <span class="ident">put</span></span>(<span>self, collection: str, key: str, value: dict)</span>
179166
</code></dt>
180167
<dd>
181168
<div class="desc"><p>Create a new document with the specified key in the specified collection.</p></div>
169+
=======
170+
<span>async def <span class="ident">put</span></span>(<span>self, key: str, value: dict)</span>
171+
</code></dt>
172+
<dd>
173+
<div class="desc"><p>Create a new document with the specified key.</p></div>
174+
>>>>>>> feat: port faas.start to bi-di streaming with membrane
182175
<details class="source">
183176
<summary>
184177
<span>Expand source code</span>
185178
</summary>
179+
<<<<<<< refs/remotes/origin/main
186180
<pre><code class="python">def put(self, collection: str, key: str, value: dict):
187181
&#34;&#34;&#34;Create a new document with the specified key in the specified collection.&#34;&#34;&#34;
188182
value_struct = Struct()
@@ -216,6 +210,12 @@ <h3>Instance variables</h3>
216210
<dt id="nitric.api.kv.KeyValueGetResponse.value"><code class="name">var <span class="ident">value</span></code></dt>
217211
<dd>
218212
<div class="desc"><p>Field nitric.kv.v1.KeyValueGetResponse.value</p></div>
213+
=======
214+
<pre><code class="python">async def put(self, key: str, value: dict):
215+
&#34;&#34;&#34;Create a new document with the specified key.&#34;&#34;&#34;
216+
await self._stub.put(collection=self.collection, key=key, value=_struct_from_dict(value))</code></pre>
217+
</details>
218+
>>>>>>> feat: port faas.start to bi-di streaming with membrane
219219
</dd>
220220
</dl>
221221
</dd>
@@ -243,13 +243,16 @@ <h4><code><a title="nitric.api.kv.KeyValueClient" href="#nitric.api.kv.KeyValueC
243243
<li><code><a title="nitric.api.kv.KeyValueClient.put" href="#nitric.api.kv.KeyValueClient.put">put</a></code></li>
244244
</ul>
245245
</li>
246+
<<<<<<< refs/remotes/origin/main
246247
<li>
247248
<h4><code><a title="nitric.api.kv.KeyValueGetResponse" href="#nitric.api.kv.KeyValueGetResponse">KeyValueGetResponse</a></code></h4>
248249
<ul class="">
249250
<li><code><a title="nitric.api.kv.KeyValueGetResponse.DESCRIPTOR" href="#nitric.api.kv.KeyValueGetResponse.DESCRIPTOR">DESCRIPTOR</a></code></li>
250251
<li><code><a title="nitric.api.kv.KeyValueGetResponse.value" href="#nitric.api.kv.KeyValueGetResponse.value">value</a></code></li>
251252
</ul>
252253
</li>
254+
=======
255+
>>>>>>> feat: port faas.start to bi-di streaming with membrane
253256
</ul>
254257
</li>
255258
</ul>

0 commit comments

Comments
 (0)