reyserver 1.1.54__py3-none-any.whl → 1.1.56__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of reyserver might be problematic. Click here for more details.

reyserver/rauth.py CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
  from typing import Any, Literal
13
13
  from datetime import datetime as Datetime
14
- from fastapi import APIRouter
14
+ from fastapi import APIRouter, Request
15
15
  from reydb import rorm, DatabaseEngine, DatabaseEngineAsync
16
16
  from reykit.rdata import encode_jwt, is_hash_bcrypt
17
17
  from reykit.rtime import now, time_to
@@ -30,7 +30,7 @@ __all__ = (
30
30
  )
31
31
 
32
32
 
33
- class DatabaseORMTableUser(rorm.Model, table=True):
33
+ class DatabaseORMTableUser(rorm.Table):
34
34
  """
35
35
  Database `user` table ORM model.
36
36
  """
@@ -48,7 +48,7 @@ class DatabaseORMTableUser(rorm.Model, table=True):
48
48
  is_valid: bool = rorm.Field(rorm.types_mysql.TINYINT(unsigned=True), field_default='1', not_null=True, comment='Is the valid.')
49
49
 
50
50
 
51
- class DatabaseORMTableRole(rorm.Model, table=True):
51
+ class DatabaseORMTableRole(rorm.Table):
52
52
  """
53
53
  Database `role` table ORM model.
54
54
  """
@@ -62,7 +62,7 @@ class DatabaseORMTableRole(rorm.Model, table=True):
62
62
  desc: str = rorm.Field(rorm.types.VARCHAR(500), comment='Role description.')
63
63
 
64
64
 
65
- class DatabaseORMTablePerm(rorm.Model, table=True):
65
+ class DatabaseORMTablePerm(rorm.Table):
66
66
  """
67
67
  Database `perm` table ORM model.
68
68
  """
@@ -77,7 +77,7 @@ class DatabaseORMTablePerm(rorm.Model, table=True):
77
77
  api: str = rorm.Field(rorm.types.VARCHAR(1000), comment='API resource path regular expression "match" pattern.')
78
78
 
79
79
 
80
- class DatabaseORMTableUserRole(rorm.Model, table=True):
80
+ class DatabaseORMTableUserRole(rorm.Table):
81
81
  """
82
82
  Database `user_role` table ORM model.
83
83
  """
@@ -90,7 +90,7 @@ class DatabaseORMTableUserRole(rorm.Model, table=True):
90
90
  role_id: int = rorm.Field(rorm.types_mysql.SMALLINT(unsigned=True), key=True, comment='Role ID.')
91
91
 
92
92
 
93
- class DatabaseORMTableRolePerm(rorm.Model, table=True):
93
+ class DatabaseORMTableRolePerm(rorm.Table):
94
94
  """
95
95
  Database `role_perm` table ORM model.
96
96
  """
@@ -197,8 +197,6 @@ def build_auth_db(engine: DatabaseEngine | DatabaseEngineAsync) -> None:
197
197
 
198
198
 
199
199
  auth_router = APIRouter()
200
- depend_auth_sess = Bind.create_depend_db('auth', 'sess')
201
- depend_auth_conn = Bind.create_depend_db('auth', 'conn')
202
200
 
203
201
 
204
202
  @auth_router.post('/sessions')
@@ -206,7 +204,7 @@ async def create_sessions(
206
204
  account: str = Bind.i.body,
207
205
  password: str = Bind.i.body,
208
206
  account_type: Literal['name', 'email', 'phone'] = Bind.Body('name'),
209
- conn: Bind.Conn = depend_auth_conn
207
+ conn: Bind.Conn = Bind.conn.auth
210
208
  ) -> dict:
211
209
  """
212
210
  Create session.
@@ -300,3 +298,6 @@ async def create_sessions(
300
298
  data = {'token': token}
301
299
 
302
300
  return data
301
+
302
+
303
+ def has_auth(request: Request) -> bool: ...
reyserver/rbase.py CHANGED
@@ -9,7 +9,7 @@
9
9
  """
10
10
 
11
11
 
12
- from typing import Literal, NoReturn
12
+ from typing import NoReturn, overload
13
13
  from http import HTTPStatus
14
14
  from fastapi import HTTPException, UploadFile as File
15
15
  from fastapi.params import (
@@ -35,6 +35,10 @@ __all__ = (
35
35
  'ServerExit',
36
36
  'ServerExitAPI',
37
37
  'exit_api',
38
+ 'ServerBindInstanceDatabaseSuper',
39
+ 'ServerBindInstanceDatabaseConnection',
40
+ 'ServerBindInstanceDatabaseSession',
41
+ 'ServerBindInstance',
38
42
  'ServerBind',
39
43
  'Bind'
40
44
  )
@@ -89,6 +93,71 @@ def exit_api(code: int = 400, text: str | None = None) -> NoReturn:
89
93
  raise ServerExitAPI(code, text)
90
94
 
91
95
 
96
+ class ServerBindInstanceDatabaseSuper(ServerBase):
97
+ """
98
+ Server API bind parameter build database instance super type.
99
+ """
100
+
101
+
102
+ def __getattr__(self, name: str) -> Depends:
103
+ """
104
+ Create dependencie instance of asynchronous database.
105
+
106
+ Parameters
107
+ ----------
108
+ name : Database engine name.
109
+ mode : Mode.
110
+ - `Literl['sess']`: Create ORM session instance.
111
+ - `Literl['conn']`: Create connection instance.
112
+
113
+ Returns
114
+ -------
115
+ Dependencie instance.
116
+ """
117
+
118
+
119
+ async def depend_func():
120
+ """
121
+ Dependencie function of asynchronous database.
122
+ """
123
+
124
+ # Parameter.
125
+ engine = ServerConfig.server.db[name]
126
+
127
+ # Context.
128
+ match self:
129
+ case ServerBindInstanceDatabaseConnection():
130
+ async with engine.connect() as conn:
131
+ yield conn
132
+ case ServerBindInstanceDatabaseSession():
133
+ async with engine.orm.session() as sess:
134
+ yield sess
135
+
136
+
137
+ # Create.
138
+ depend = Depends(depend_func)
139
+
140
+ return depend
141
+
142
+
143
+ @overload
144
+ def __getitem__(self, engine: str) -> DatabaseConnectionAsync: ...
145
+
146
+ __getitem__ = __getattr__
147
+
148
+
149
+ class ServerBindInstanceDatabaseConnection(ServerBindInstanceDatabaseSuper, Singleton):
150
+ """
151
+ Server API bind parameter build database connection instance type.
152
+ """
153
+
154
+
155
+ class ServerBindInstanceDatabaseSession(ServerBindInstanceDatabaseSuper, Singleton):
156
+ """
157
+ Server API bind parameter build database session instance type.
158
+ """
159
+
160
+
92
161
  class ServerBindInstance(ServerBase, Singleton):
93
162
  """
94
163
  Server API bind parameter build instance type.
@@ -256,47 +325,6 @@ class ServerBind(ServerBase, metaclass=StaticMeta):
256
325
  Server API bind parameter type.
257
326
  """
258
327
 
259
-
260
- def create_depend_db(database: str, mode: Literal['sess', 'conn']) -> Depends:
261
- """
262
- Create dependencie type of asynchronous database.
263
-
264
- Parameters
265
- ----------
266
- database : Database name.
267
- mode : Mode.
268
- - `Literl['sess']`: Create ORM session instance.
269
- - `Literl['conn']`: Create connection instance.
270
-
271
- Returns
272
- -------
273
- Dependencie type.
274
- """
275
-
276
-
277
- async def depend_db():
278
- """
279
- Dependencie function of asynchronous database.
280
- """
281
-
282
- # Parameter.
283
- engine = ServerConfig.server.db[database]
284
-
285
- # Context.
286
- if mode == 'sess':
287
- async with engine.orm.session() as sess:
288
- yield sess
289
- elif mode == 'conn':
290
- async with engine.connect() as conn:
291
- yield conn
292
-
293
-
294
- # Create.
295
- depend = Depends(depend_db)
296
-
297
- return depend
298
-
299
-
300
328
  Depend = Depends
301
329
  Path = Path
302
330
  Query = Query
@@ -310,6 +338,8 @@ class ServerBind(ServerBase, metaclass=StaticMeta):
310
338
  Conn = DatabaseConnectionAsync
311
339
  Sess = DatabaseORMSessionAsync
312
340
  i = ServerBindInstance()
341
+ conn = ServerBindInstanceDatabaseConnection()
342
+ sess = ServerBindInstanceDatabaseSession()
313
343
 
314
344
 
315
345
  Bind = ServerBind
reyserver/rfile.py CHANGED
@@ -25,7 +25,7 @@ __all__ = (
25
25
  )
26
26
 
27
27
 
28
- class DatabaseORMTableInfo(rorm.Model, table=True):
28
+ class DatabaseORMTableInfo(rorm.Table):
29
29
  """
30
30
  Database `info` table ORM model.
31
31
  """
@@ -39,7 +39,7 @@ class DatabaseORMTableInfo(rorm.Model, table=True):
39
39
  note: str = rorm.Field(rorm.types.VARCHAR(500), comment='File note.')
40
40
 
41
41
 
42
- class DatabaseORMTableData(rorm.Model, table=True):
42
+ class DatabaseORMTableData(rorm.Table):
43
43
  """
44
44
  Database `data` table ORM model.
45
45
  """
@@ -178,14 +178,12 @@ def build_file_db(engine: DatabaseEngine | DatabaseEngineAsync) -> None:
178
178
 
179
179
 
180
180
  file_router = APIRouter()
181
- depend_file_sess = Bind.create_depend_db('file', 'sess')
182
- depend_file_conn = Bind.create_depend_db('file', 'conn')
183
181
 
184
182
 
185
183
  @file_router.get('/files/{file_id}')
186
184
  async def get_file_info(
187
185
  file_id: int = Bind.i.path,
188
- sess: Bind.Sess = depend_file_sess
186
+ sess: Bind.Sess = Bind.sess.file
189
187
  ) -> DatabaseORMTableInfo:
190
188
  """
191
189
  Get file information.
@@ -214,7 +212,7 @@ async def upload_file(
214
212
  file: Bind.File = Bind.i.forms,
215
213
  name: str = Bind.i.forms_n,
216
214
  note: str = Bind.i.forms_n,
217
- sess: Bind.Sess = depend_file_sess
215
+ sess: Bind.Sess = Bind.sess.file
218
216
  ) -> DatabaseORMTableInfo:
219
217
  """
220
218
  Upload file.
@@ -266,7 +264,7 @@ async def upload_file(
266
264
  @file_router.get('/files/{file_id}/download')
267
265
  async def download_file(
268
266
  file_id: int = Bind.i.path,
269
- conn: Bind.Conn = depend_file_conn
267
+ conn: Bind.Conn = Bind.conn.file
270
268
  ) -> FileResponse:
271
269
  """
272
270
  Download file.
reyserver/rserver.py CHANGED
@@ -159,7 +159,7 @@ class Server(ServerBase, Singleton):
159
159
  for task in before:
160
160
  await task()
161
161
 
162
- # Databse.
162
+ ## Databse.
163
163
  if db_warm:
164
164
  await self.db.warm_all()
165
165
 
@@ -170,7 +170,7 @@ class Server(ServerBase, Singleton):
170
170
  for task in after:
171
171
  await after()
172
172
 
173
- # Database.
173
+ ## Database.
174
174
  await self.db.dispose_all()
175
175
 
176
176
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reyserver
3
- Version: 1.1.54
3
+ Version: 1.1.56
4
4
  Summary: Backend server method set.
5
5
  Project-URL: homepage, https://github.com/reyxbo/reyserver/
6
6
  Author-email: Rey <reyxbo@163.com>
@@ -19,6 +19,7 @@ Requires-Dist: fastapi
19
19
  Requires-Dist: python-multipart
20
20
  Requires-Dist: reydb
21
21
  Requires-Dist: reykit
22
+ Requires-Dist: sqladmin
22
23
  Requires-Dist: uvicorn[standard]
23
24
  Description-Content-Type: text/markdown
24
25
 
@@ -0,0 +1,11 @@
1
+ reyserver/__init__.py,sha256=7GX64p7uI2eetJH9NJ-DTg-8iyQwOsGcviADFJCPxVA,373
2
+ reyserver/rall.py,sha256=riyDRTUsigco_Bee1H4aZFb8IgvjnxdX9qcnVb9i9mE,270
3
+ reyserver/rauth.py,sha256=pOkA7E4W31Ii8iCLkhhcoL5-ge9cFq7lMYxQtLYvQbg,11606
4
+ reyserver/rbase.py,sha256=WbL2W6nc2jbkDumiXWrb25TaAhT-9xAI4wE0e_2prtg,6553
5
+ reyserver/rclient.py,sha256=IWZ3smyIP0_YJrfSrM8JFCr0FCtN02AyT3hp8YuSsDQ,5103
6
+ reyserver/rfile.py,sha256=CH2uJbBNmBH9ISDirn1LWL5wsjGW5xjB9ZIrdc5UzL0,8864
7
+ reyserver/rserver.py,sha256=0lCvaac7N-A25vbrNAbQKQoWFqvxMNlHtMfnoVoGX0I,8563
8
+ reyserver-1.1.56.dist-info/METADATA,sha256=M5Ocw__l3_sN1Pso7TryMu2505S-B82fOJ7uevyOIN0,1713
9
+ reyserver-1.1.56.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
+ reyserver-1.1.56.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
11
+ reyserver-1.1.56.dist-info/RECORD,,
@@ -1,11 +0,0 @@
1
- reyserver/__init__.py,sha256=7GX64p7uI2eetJH9NJ-DTg-8iyQwOsGcviADFJCPxVA,373
2
- reyserver/rall.py,sha256=riyDRTUsigco_Bee1H4aZFb8IgvjnxdX9qcnVb9i9mE,270
3
- reyserver/rauth.py,sha256=oa6Iwuutcj9eO6RH7DaT-rPn_YqYwKuyHYaBd3lZoZE,11728
4
- reyserver/rbase.py,sha256=jgjAkT1kxzVKB60xfWxZbnQJsehhcTBr24AclTYjc4g,5603
5
- reyserver/rclient.py,sha256=IWZ3smyIP0_YJrfSrM8JFCr0FCtN02AyT3hp8YuSsDQ,5103
6
- reyserver/rfile.py,sha256=bvuXOYO3UDM1jMiyNzQDz56_0ekZUEIRcfNFAhGgdUY,9010
7
- reyserver/rserver.py,sha256=EDIspT0uWhiWl7uIhRDJtcxRvZG96GaVNWYik7pprz4,8561
8
- reyserver-1.1.54.dist-info/METADATA,sha256=xajKdcgwZ5ajkYubVO_TXjA1dL1KY6xH_36zokahzbA,1689
9
- reyserver-1.1.54.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
- reyserver-1.1.54.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
11
- reyserver-1.1.54.dist-info/RECORD,,