2
2
3
3
import logging
4
4
from abc import ABC , abstractmethod
5
- from datetime import datetime
6
5
from pathlib import Path
7
6
from typing import (
8
7
Any ,
26
25
from aleph_message .models .execution .program import Encoding
27
26
from aleph_message .status import MessageStatus
28
27
29
- from aleph .sdk .models import PostsResponse
30
- from aleph .sdk .types import GenericMessage , StorageEnum
28
+ from .models .message import MessageFilter
29
+ from .models .post import PostFilter , PostsResponse
30
+ from .types import GenericMessage , StorageEnum
31
31
32
32
DEFAULT_PAGE_SIZE = 200
33
33
34
34
35
35
class BaseAlephClient (ABC ):
36
36
@abstractmethod
37
- async def fetch_aggregate (
38
- self ,
39
- address : str ,
40
- key : str ,
41
- limit : int = 100 ,
42
- ) -> Dict [str , Dict ]:
37
+ async def fetch_aggregate (self , address : str , key : str ) -> Dict [str , Dict ]:
43
38
"""
44
39
Fetch a value from the aggregate store by owner address and item key.
45
40
46
41
:param address: Address of the owner of the aggregate
47
42
:param key: Key of the aggregate
48
- :param limit: Maximum number of items to fetch (Default: 100)
49
43
"""
50
44
pass
51
45
52
46
@abstractmethod
53
47
async def fetch_aggregates (
54
- self ,
55
- address : str ,
56
- keys : Optional [Iterable [str ]] = None ,
57
- limit : int = 100 ,
48
+ self , address : str , keys : Optional [Iterable [str ]] = None
58
49
) -> Dict [str , Dict ]:
59
50
"""
60
51
Fetch key-value pairs from the aggregate store by owner address.
61
52
62
53
:param address: Address of the owner of the aggregate
63
54
:param keys: Keys of the aggregates to fetch (Default: all items)
64
- :param limit: Maximum number of items to fetch (Default: 100)
65
55
"""
66
56
pass
67
57
@@ -70,15 +60,7 @@ async def get_posts(
70
60
self ,
71
61
pagination : int = DEFAULT_PAGE_SIZE ,
72
62
page : int = 1 ,
73
- types : Optional [Iterable [str ]] = None ,
74
- refs : Optional [Iterable [str ]] = None ,
75
- addresses : Optional [Iterable [str ]] = None ,
76
- tags : Optional [Iterable [str ]] = None ,
77
- hashes : Optional [Iterable [str ]] = None ,
78
- channels : Optional [Iterable [str ]] = None ,
79
- chains : Optional [Iterable [str ]] = None ,
80
- start_date : Optional [Union [datetime , float ]] = None ,
81
- end_date : Optional [Union [datetime , float ]] = None ,
63
+ post_filter : Optional [PostFilter ] = None ,
82
64
ignore_invalid_messages : Optional [bool ] = True ,
83
65
invalid_messages_log_level : Optional [int ] = logging .NOTSET ,
84
66
) -> PostsResponse :
@@ -87,60 +69,28 @@ async def get_posts(
87
69
88
70
:param pagination: Number of items to fetch (Default: 200)
89
71
:param page: Page to fetch, begins at 1 (Default: 1)
90
- :param types: Types of posts to fetch (Default: all types)
91
- :param refs: If set, only fetch posts that reference these hashes (in the "refs" field)
92
- :param addresses: Addresses of the posts to fetch (Default: all addresses)
93
- :param tags: Tags of the posts to fetch (Default: all tags)
94
- :param hashes: Specific item_hashes to fetch
95
- :param channels: Channels of the posts to fetch (Default: all channels)
96
- :param chains: Chains of the posts to fetch (Default: all chains)
97
- :param start_date: Earliest date to fetch messages from
98
- :param end_date: Latest date to fetch messages from
72
+ :param post_filter: Filter to apply to the posts (Default: None)
99
73
:param ignore_invalid_messages: Ignore invalid messages (Default: True)
100
74
:param invalid_messages_log_level: Log level to use for invalid messages (Default: logging.NOTSET)
101
75
"""
102
76
pass
103
77
104
78
async def get_posts_iterator (
105
79
self ,
106
- types : Optional [Iterable [str ]] = None ,
107
- refs : Optional [Iterable [str ]] = None ,
108
- addresses : Optional [Iterable [str ]] = None ,
109
- tags : Optional [Iterable [str ]] = None ,
110
- hashes : Optional [Iterable [str ]] = None ,
111
- channels : Optional [Iterable [str ]] = None ,
112
- chains : Optional [Iterable [str ]] = None ,
113
- start_date : Optional [Union [datetime , float ]] = None ,
114
- end_date : Optional [Union [datetime , float ]] = None ,
80
+ post_filter : Optional [PostFilter ] = None ,
115
81
) -> AsyncIterable [PostMessage ]:
116
82
"""
117
83
Fetch all filtered posts, returning an async iterator and fetching them page by page. Might return duplicates
118
84
but will always return all posts.
119
85
120
- :param types: Types of posts to fetch (Default: all types)
121
- :param refs: If set, only fetch posts that reference these hashes (in the "refs" field)
122
- :param addresses: Addresses of the posts to fetch (Default: all addresses)
123
- :param tags: Tags of the posts to fetch (Default: all tags)
124
- :param hashes: Specific item_hashes to fetch
125
- :param channels: Channels of the posts to fetch (Default: all channels)
126
- :param chains: Chains of the posts to fetch (Default: all chains)
127
- :param start_date: Earliest date to fetch messages from
128
- :param end_date: Latest date to fetch messages from
86
+ :param post_filter: Filter to apply to the posts (Default: None)
129
87
"""
130
88
page = 1
131
89
resp = None
132
90
while resp is None or len (resp .posts ) > 0 :
133
91
resp = await self .get_posts (
134
92
page = page ,
135
- types = types ,
136
- refs = refs ,
137
- addresses = addresses ,
138
- tags = tags ,
139
- hashes = hashes ,
140
- channels = channels ,
141
- chains = chains ,
142
- start_date = start_date ,
143
- end_date = end_date ,
93
+ post_filter = post_filter ,
144
94
)
145
95
page += 1
146
96
for post in resp .posts :
@@ -165,18 +115,7 @@ async def get_messages(
165
115
self ,
166
116
pagination : int = DEFAULT_PAGE_SIZE ,
167
117
page : int = 1 ,
168
- message_type : Optional [MessageType ] = None ,
169
- message_types : Optional [Iterable [MessageType ]] = None ,
170
- content_types : Optional [Iterable [str ]] = None ,
171
- content_keys : Optional [Iterable [str ]] = None ,
172
- refs : Optional [Iterable [str ]] = None ,
173
- addresses : Optional [Iterable [str ]] = None ,
174
- tags : Optional [Iterable [str ]] = None ,
175
- hashes : Optional [Iterable [str ]] = None ,
176
- channels : Optional [Iterable [str ]] = None ,
177
- chains : Optional [Iterable [str ]] = None ,
178
- start_date : Optional [Union [datetime , float ]] = None ,
179
- end_date : Optional [Union [datetime , float ]] = None ,
118
+ message_filter : Optional [MessageFilter ] = None ,
180
119
ignore_invalid_messages : Optional [bool ] = True ,
181
120
invalid_messages_log_level : Optional [int ] = logging .NOTSET ,
182
121
) -> MessagesResponse :
@@ -185,69 +124,28 @@ async def get_messages(
185
124
186
125
:param pagination: Number of items to fetch (Default: 200)
187
126
:param page: Page to fetch, begins at 1 (Default: 1)
188
- :param message_type: [DEPRECATED] Filter by message type, can be "AGGREGATE", "POST", "PROGRAM", "VM", "STORE" or "FORGET"
189
- :param message_types: Filter by message types, can be any combination of "AGGREGATE", "POST", "PROGRAM", "VM", "STORE" or "FORGET"
190
- :param content_types: Filter by content type
191
- :param content_keys: Filter by aggregate key
192
- :param refs: If set, only fetch posts that reference these hashes (in the "refs" field)
193
- :param addresses: Addresses of the posts to fetch (Default: all addresses)
194
- :param tags: Tags of the posts to fetch (Default: all tags)
195
- :param hashes: Specific item_hashes to fetch
196
- :param channels: Channels of the posts to fetch (Default: all channels)
197
- :param chains: Filter by sender address chain
198
- :param start_date: Earliest date to fetch messages from
199
- :param end_date: Latest date to fetch messages from
127
+ :param message_filter: Filter to apply to the messages
200
128
:param ignore_invalid_messages: Ignore invalid messages (Default: True)
201
129
:param invalid_messages_log_level: Log level to use for invalid messages (Default: logging.NOTSET)
202
130
"""
203
131
pass
204
132
205
133
async def get_messages_iterator (
206
134
self ,
207
- message_type : Optional [MessageType ] = None ,
208
- content_types : Optional [Iterable [str ]] = None ,
209
- content_keys : Optional [Iterable [str ]] = None ,
210
- refs : Optional [Iterable [str ]] = None ,
211
- addresses : Optional [Iterable [str ]] = None ,
212
- tags : Optional [Iterable [str ]] = None ,
213
- hashes : Optional [Iterable [str ]] = None ,
214
- channels : Optional [Iterable [str ]] = None ,
215
- chains : Optional [Iterable [str ]] = None ,
216
- start_date : Optional [Union [datetime , float ]] = None ,
217
- end_date : Optional [Union [datetime , float ]] = None ,
135
+ message_filter : Optional [MessageFilter ] = None ,
218
136
) -> AsyncIterable [AlephMessage ]:
219
137
"""
220
138
Fetch all filtered messages, returning an async iterator and fetching them page by page. Might return duplicates
221
139
but will always return all messages.
222
140
223
- :param message_type: Filter by message type, can be "AGGREGATE", "POST", "PROGRAM", "VM", "STORE" or "FORGET"
224
- :param content_types: Filter by content type
225
- :param content_keys: Filter by content key
226
- :param refs: If set, only fetch posts that reference these hashes (in the "refs" field)
227
- :param addresses: Addresses of the posts to fetch (Default: all addresses)
228
- :param tags: Tags of the posts to fetch (Default: all tags)
229
- :param hashes: Specific item_hashes to fetch
230
- :param channels: Channels of the posts to fetch (Default: all channels)
231
- :param chains: Filter by sender address chain
232
- :param start_date: Earliest date to fetch messages from
233
- :param end_date: Latest date to fetch messages from
141
+ :param message_filter: Filter to apply to the messages
234
142
"""
235
143
page = 1
236
144
resp = None
237
145
while resp is None or len (resp .messages ) > 0 :
238
146
resp = await self .get_messages (
239
147
page = page ,
240
- message_type = message_type ,
241
- content_types = content_types ,
242
- content_keys = content_keys ,
243
- refs = refs ,
244
- addresses = addresses ,
245
- tags = tags ,
246
- hashes = hashes ,
247
- channels = channels ,
248
- chains = chains ,
249
- start_date = start_date ,
250
- end_date = end_date ,
148
+ message_filter = message_filter ,
251
149
)
252
150
page += 1
253
151
for message in resp .messages :
@@ -272,34 +170,12 @@ async def get_message(
272
170
@abstractmethod
273
171
def watch_messages (
274
172
self ,
275
- message_type : Optional [MessageType ] = None ,
276
- message_types : Optional [Iterable [MessageType ]] = None ,
277
- content_types : Optional [Iterable [str ]] = None ,
278
- content_keys : Optional [Iterable [str ]] = None ,
279
- refs : Optional [Iterable [str ]] = None ,
280
- addresses : Optional [Iterable [str ]] = None ,
281
- tags : Optional [Iterable [str ]] = None ,
282
- hashes : Optional [Iterable [str ]] = None ,
283
- channels : Optional [Iterable [str ]] = None ,
284
- chains : Optional [Iterable [str ]] = None ,
285
- start_date : Optional [Union [datetime , float ]] = None ,
286
- end_date : Optional [Union [datetime , float ]] = None ,
173
+ message_filter : Optional [MessageFilter ] = None ,
287
174
) -> AsyncIterable [AlephMessage ]:
288
175
"""
289
176
Iterate over current and future matching messages asynchronously.
290
177
291
- :param message_type: [DEPRECATED] Type of message to watch
292
- :param message_types: Types of messages to watch
293
- :param content_types: Content types to watch
294
- :param content_keys: Filter by aggregate key
295
- :param refs: References to watch
296
- :param addresses: Addresses to watch
297
- :param tags: Tags to watch
298
- :param hashes: Hashes to watch
299
- :param channels: Channels to watch
300
- :param chains: Chains to watch
301
- :param start_date: Start date from when to watch
302
- :param end_date: End date until when to watch
178
+ :param message_filter: Filter to apply to the messages
303
179
"""
304
180
pass
305
181
@@ -318,7 +194,7 @@ async def create_post(
318
194
sync : bool = False ,
319
195
) -> Tuple [AlephMessage , MessageStatus ]:
320
196
"""
321
- Create a POST message on the Aleph network. It is associated with a channel and owned by an account.
197
+ Create a POST message on the aleph.im network. It is associated with a channel and owned by an account.
322
198
323
199
:param post_content: The content of the message
324
200
:param post_type: An arbitrary content type that helps to describe the post_content
@@ -368,7 +244,7 @@ async def create_store(
368
244
sync : bool = False ,
369
245
) -> Tuple [AlephMessage , MessageStatus ]:
370
246
"""
371
- Create a STORE message to store a file on the Aleph network.
247
+ Create a STORE message to store a file on the aleph.im network.
372
248
373
249
Can be passed either a file path, an IPFS hash or the file's content as raw bytes.
374
250
@@ -422,7 +298,7 @@ async def create_program(
422
298
:param persistent: Whether the program should be persistent or not (Default: False)
423
299
:param encoding: Encoding to use (Default: Encoding.zip)
424
300
:param volumes: Volumes to mount
425
- :param subscriptions: Patterns of Aleph messages to forward to the program's event receiver
301
+ :param subscriptions: Patterns of aleph.im messages to forward to the program's event receiver
426
302
:param metadata: Metadata to attach to the message
427
303
"""
428
304
pass
0 commit comments