apexdevkit 2.1.3__py3-none-any.whl → 2.2.1__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.
Files changed (38) hide show
  1. apexdevkit/__init__.py +1 -1
  2. apexdevkit/annotation/deprecate.py +3 -3
  3. apexdevkit/date.py +16 -16
  4. apexdevkit/fastapi/__init__.py +2 -2
  5. apexdevkit/fastapi/builder.py +6 -3
  6. apexdevkit/fastapi/resource.py +18 -234
  7. apexdevkit/fastapi/router.py +21 -11
  8. apexdevkit/fastapi/schema.py +0 -3
  9. apexdevkit/fastapi/service.py +5 -55
  10. apexdevkit/query/__init__.py +11 -11
  11. apexdevkit/query/generator.py +16 -16
  12. apexdevkit/repository/__init__.py +5 -8
  13. apexdevkit/repository/core/__init__.py +4 -8
  14. apexdevkit/repository/core/database.py +1 -1
  15. apexdevkit/repository/in_memory/__init__.py +1 -1
  16. apexdevkit/repository/in_memory/repository.py +4 -1
  17. apexdevkit/repository/in_memory/store.py +4 -2
  18. apexdevkit/repository/sql/__init__.py +1 -1
  19. apexdevkit/repository/sql/connector.py +6 -3
  20. apexdevkit/repository/sql/field.py +17 -10
  21. apexdevkit/repository/sql/mssql/__init__.py +1 -1
  22. apexdevkit/repository/sql/mssql/repository.py +2 -2
  23. apexdevkit/repository/sql/mssql/table.py +6 -3
  24. apexdevkit/repository/sql/sqlite/__init__.py +1 -1
  25. apexdevkit/repository/sql/sqlite/repository.py +6 -3
  26. apexdevkit/repository/sql/sqlite/table.py +6 -3
  27. apexdevkit/server.py +7 -4
  28. apexdevkit/sync/__init__.py +4 -4
  29. apexdevkit/sync/observer.py +5 -3
  30. apexdevkit/sync/source.py +7 -7
  31. apexdevkit/sync/sync.py +12 -4
  32. apexdevkit/testing.py +6 -4
  33. {apexdevkit-2.1.3.dist-info → apexdevkit-2.2.1.dist-info}/METADATA +2 -2
  34. apexdevkit-2.2.1.dist-info/RECORD +50 -0
  35. apexdevkit/fastapi/docs.py +0 -15
  36. apexdevkit-2.1.3.dist-info/RECORD +0 -51
  37. {apexdevkit-2.1.3.dist-info → apexdevkit-2.2.1.dist-info}/WHEEL +0 -0
  38. {apexdevkit-2.1.3.dist-info → apexdevkit-2.2.1.dist-info}/licenses/LICENSE +0 -0
apexdevkit/__init__.py CHANGED
@@ -2,8 +2,8 @@ from dotenv import load_dotenv
2
2
  from fastapi import APIRouter, FastAPI, HTTPException
3
3
 
4
4
  __all__ = [
5
- "FastAPI",
6
5
  "APIRouter",
6
+ "FastAPI",
7
7
  "HTTPException",
8
8
  "load_dotenv",
9
9
  ]
@@ -25,7 +25,7 @@ def deprecated(warning: str) -> Callable[[F], F]:
25
25
  if inspect.isfunction(obj) or inspect.ismethod(obj):
26
26
  return _wrap_function(obj, warning)
27
27
  if inspect.isclass(obj):
28
- return cast(F, _deprecate_class(obj, warning))
28
+ return cast("F", _deprecate_class(obj, warning))
29
29
  raise TypeError(
30
30
  f"Unsupported type for deprecation: {type(obj)}"
31
31
  ) # pragma: no cover
@@ -38,7 +38,7 @@ def _wrap_function[F: Callable[..., Any]](func: F, warning: str) -> F:
38
38
  warn(warning, category=DeprecationWarning, stacklevel=2)
39
39
  return func(*args, **kwargs)
40
40
 
41
- return cast(F, wrapper)
41
+ return cast("F", wrapper)
42
42
 
43
43
 
44
44
  def _deprecate_class(cls: type, warning: str) -> type:
@@ -47,4 +47,4 @@ def _deprecate_class(cls: type, warning: str) -> type:
47
47
  warn(warning, category=DeprecationWarning, stacklevel=2)
48
48
  super().__init__(*args, **kwargs)
49
49
 
50
- return cast(type, DeprecatedClass)
50
+ return cast("type", DeprecatedClass)
apexdevkit/date.py CHANGED
@@ -36,28 +36,28 @@ class DateTime:
36
36
  # Date in format of "yyyy-mm-dd"
37
37
  @classmethod
38
38
  def from_date(cls, date: str, time_zone: ZoneInfo | None = None) -> DateTime:
39
- if time_zone is None:
40
- time_zone = ZoneInfo("UTC")
41
-
42
- dt = datetime.strptime(date, "%Y-%m-%d")
43
- dt = dt.replace(tzinfo=time_zone)
44
- timestamp_ms = int(dt.timestamp() * 1000)
45
-
46
- return cls(timestamp_ms=timestamp_ms)
39
+ return cls(
40
+ timestamp_ms=int(
41
+ datetime.strptime(date, "%Y-%m-%d")
42
+ .replace(tzinfo=time_zone or ZoneInfo("UTC"))
43
+ .timestamp()
44
+ * 1000
45
+ )
46
+ )
47
47
 
48
48
  # Date in format of "yyyy-mm-ddTHH:MM:SS"
49
49
  @classmethod
50
50
  def from_date_time(
51
51
  cls, date_time: str, time_zone: ZoneInfo | None = None
52
52
  ) -> DateTime:
53
- if time_zone is None:
54
- time_zone = ZoneInfo("UTC")
55
-
56
- dt = datetime.strptime(date_time, "%Y-%m-%dT%H:%M:%S")
57
- dt = dt.replace(tzinfo=time_zone)
58
- timestamp_ms = int(dt.timestamp() * 1000)
59
-
60
- return cls(timestamp_ms=timestamp_ms)
53
+ return cls(
54
+ timestamp_ms=int(
55
+ datetime.strptime(date_time, "%Y-%m-%dT%H:%M:%S")
56
+ .replace(tzinfo=time_zone or ZoneInfo("UTC"))
57
+ .timestamp()
58
+ * 1000
59
+ )
60
+ )
61
61
 
62
62
  @classmethod
63
63
  def from_timestamp(cls, timestamp: float) -> DateTime:
@@ -5,9 +5,9 @@ from apexdevkit.fastapi.service import RestfulRepository
5
5
 
6
6
  __all__ = [
7
7
  "FastApiBuilder",
8
- "RestfulServiceBuilder",
9
- "inject",
10
8
  "RestfulRepository",
11
9
  "RestfulRouter",
10
+ "RestfulServiceBuilder",
12
11
  "RouterWithHiddenUnderscoreRoutes",
12
+ "inject",
13
13
  ]
@@ -1,9 +1,8 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from abc import ABC, abstractmethod
4
- from collections.abc import Mapping, MutableSet
5
4
  from dataclasses import dataclass, field
6
- from typing import Any, Protocol, Self
5
+ from typing import TYPE_CHECKING, Any, Protocol, Self
7
6
 
8
7
  from fastapi import APIRouter, FastAPI
9
8
  from fastapi.middleware.cors import CORSMiddleware
@@ -12,7 +11,11 @@ from fastapi.responses import JSONResponse
12
11
  from apexdevkit.annotation import deprecated
13
12
  from apexdevkit.error import ApiError
14
13
  from apexdevkit.fastapi.dependable import DependableBuilder
15
- from apexdevkit.fastapi.service import RestfulService
14
+
15
+ if TYPE_CHECKING:
16
+ from collections.abc import Mapping, MutableSet
17
+
18
+ from apexdevkit.fastapi.service import RestfulService
16
19
 
17
20
 
18
21
  @dataclass
@@ -1,30 +1,11 @@
1
- import re
2
1
  from collections.abc import Callable
3
2
  from dataclasses import dataclass
4
- from typing import Any, Union
3
+ from typing import Any
5
4
 
6
5
  from fastapi.responses import JSONResponse
7
- from pydantic import BaseModel
8
6
 
9
7
  from apexdevkit.error import DoesNotExistError, ExistsError, ForbiddenError
10
8
  from apexdevkit.fastapi.response import RestfulResponse
11
- from apexdevkit.query.query import (
12
- Aggregation,
13
- AggregationOption,
14
- DateValue,
15
- Filter,
16
- FooterOptions,
17
- Leaf,
18
- ListValue,
19
- NullValue,
20
- NumericValue,
21
- Operation,
22
- Operator,
23
- Page,
24
- QueryOptions,
25
- Sort,
26
- StringValue,
27
- )
28
9
 
29
10
  _Response = JSONResponse | dict[str, Any]
30
11
  _Endpoint = Callable[..., _Response]
@@ -34,82 +15,55 @@ _Endpoint = Callable[..., _Response]
34
15
  class RestfulResource:
35
16
  response: RestfulResponse
36
17
 
37
- def create_one(self, Service, Item) -> _Endpoint: # type: ignore
18
+ def create_one_endpoint(self, Service, Item) -> _Endpoint:
38
19
  def endpoint(service: Service, item: Item) -> _Response:
39
20
  try:
40
- item = service.create_one(item)
21
+ result = service.create_one(item)
41
22
  except ExistsError as e:
42
23
  return JSONResponse(self.response.exists(e), 409)
43
24
  except ForbiddenError as e:
44
25
  return JSONResponse(self.response.forbidden(e), 403)
45
26
 
46
- return self.response.created_one(item)
27
+ return self.response.created_one(result)
47
28
 
48
29
  return endpoint
49
30
 
50
- def create_many(self, Service, Collection) -> _Endpoint: # type: ignore
51
- def endpoint(service: Service, items: Collection) -> _Response:
52
- try:
53
- return self.response.created_many(service.create_many(items))
54
- except ExistsError as e:
55
- return JSONResponse(self.response.exists(e), 409)
56
- except ForbiddenError as e:
57
- return JSONResponse(self.response.forbidden(e), 403)
58
-
59
- return endpoint
60
-
61
- def read_one(self, Service, ItemId) -> _Endpoint: # type: ignore
31
+ def read_one_endpoint(self, Service, ItemId) -> _Endpoint:
62
32
  def endpoint(service: Service, item_id: ItemId) -> _Response:
63
33
  try:
64
- return self.response.found_one(service.read_one(item_id))
34
+ result = service.read_one(item_id)
65
35
  except DoesNotExistError as e:
66
36
  return JSONResponse(self.response.not_found(e), 404)
67
37
  except ForbiddenError as e:
68
38
  return JSONResponse(self.response.forbidden(e), 403)
69
39
 
70
- return endpoint
71
-
72
- def read_many(self, Service, QueryParams) -> _Endpoint: # type: ignore
73
- def endpoint(service: Service, params: QueryParams) -> _Response:
74
- try:
75
- return self.response.found_many(list(service.read_many(**dict(params))))
76
- except ForbiddenError as e:
77
- return JSONResponse(self.response.forbidden(e), 403)
40
+ return self.response.found_one(result)
78
41
 
79
42
  return endpoint
80
43
 
81
- def filter_with(self, Service, QueryOptions) -> _Endpoint: # type: ignore
82
- def endpoint(service: Service, options: QueryOptions) -> _Response:
44
+ def read_many_endpoint(self, Service, QueryParams) -> _Endpoint:
45
+ def endpoint(service: Service, params: QueryParams) -> _Response:
83
46
  try:
84
- return self.response.found_many(list(service.filter_with(options)))
47
+ result = list(service.read_many(**dict(params)))
85
48
  except ForbiddenError as e:
86
49
  return JSONResponse(self.response.forbidden(e), 403)
87
50
 
88
- return endpoint
89
-
90
- def aggregation_with(self, Service, FilterOptions) -> _Endpoint: # type: ignore
91
- def endpoint(service: Service, options: FilterOptions) -> _Response:
92
- try:
93
- return {
94
- "status": "success",
95
- "code": 200,
96
- "aggregations": service.aggregation_with(options),
97
- }
98
- except ForbiddenError as e:
99
- return JSONResponse(self.response.forbidden(e), 403)
51
+ return self.response.found_many(result)
100
52
 
101
53
  return endpoint
102
54
 
103
- def read_all(self, Service) -> _Endpoint: # type: ignore
55
+ def read_all_endpoint(self, Service) -> _Endpoint:
104
56
  def endpoint(service: Service) -> _Response:
105
57
  try:
106
- return self.response.found_many(list(service.read_all()))
58
+ result = list(service.read_all())
107
59
  except ForbiddenError as e:
108
60
  return JSONResponse(self.response.forbidden(e), 403)
109
61
 
62
+ return self.response.found_many(result)
63
+
110
64
  return endpoint
111
65
 
112
- def update_one(self, Service, ItemId, Updates) -> _Endpoint: # type: ignore
66
+ def update_one_endpoint(self, Service, ItemId, Updates) -> _Endpoint:
113
67
  def endpoint(service: Service, item_id: ItemId, updates: Updates) -> _Response:
114
68
  try:
115
69
  service.update_one(item_id, **updates)
@@ -122,20 +76,7 @@ class RestfulResource:
122
76
 
123
77
  return endpoint
124
78
 
125
- def update_many(self, Service, Collection) -> _Endpoint: # type: ignore
126
- def endpoint(service: Service, items: Collection) -> _Response:
127
- try:
128
- service.update_many(items)
129
- except DoesNotExistError as e:
130
- return JSONResponse(self.response.not_found(e), 404)
131
- except ForbiddenError as e:
132
- return JSONResponse(self.response.forbidden(e), 403)
133
-
134
- return self.response.ok()
135
-
136
- return endpoint
137
-
138
- def replace_one(self, Service, Item) -> _Endpoint: # type: ignore
79
+ def replace_one_endpoint(self, Service, Item) -> _Endpoint:
139
80
  def endpoint(service: Service, item: Item) -> _Response:
140
81
  try:
141
82
  service.replace_one(item)
@@ -148,20 +89,7 @@ class RestfulResource:
148
89
 
149
90
  return endpoint
150
91
 
151
- def replace_many(self, Service, Collection) -> _Endpoint: # type: ignore
152
- def endpoint(service: Service, items: Collection) -> _Response:
153
- try:
154
- service.replace_many(items)
155
- except DoesNotExistError as e:
156
- return JSONResponse(self.response.not_found(e), 404)
157
- except ForbiddenError as e:
158
- return JSONResponse(self.response.forbidden(e), 403)
159
-
160
- return self.response.ok()
161
-
162
- return endpoint
163
-
164
- def delete_one(self, Service, ItemId) -> _Endpoint: # type: ignore
92
+ def delete_one_endpoint(self, Service, ItemId) -> _Endpoint:
165
93
  def endpoint(service: Service, item_id: ItemId) -> _Response:
166
94
  try:
167
95
  service.delete_one(item_id)
@@ -173,147 +101,3 @@ class RestfulResource:
173
101
  return self.response.ok()
174
102
 
175
103
  return endpoint
176
-
177
-
178
- @dataclass
179
- class _ColumnName:
180
- raw: str
181
-
182
- def __str__(self) -> str:
183
- return re.sub(r"(?<!^)(?=[A-Z])", "_", self.raw).lower()
184
-
185
-
186
- class _NumericItem(BaseModel):
187
- value: int
188
- exponent: int
189
-
190
- def to_value(self) -> NumericValue:
191
- return NumericValue(self.value, self.exponent)
192
-
193
-
194
- class _StringItem(BaseModel):
195
- value: str
196
-
197
- def to_value(self) -> StringValue:
198
- return StringValue(self.value)
199
-
200
-
201
- class _DateItem(BaseModel):
202
- date: str
203
-
204
- def to_value(self) -> DateValue:
205
- return DateValue(self.date)
206
-
207
-
208
- class _ListItem(BaseModel):
209
- values: list[_NumericItem | _StringItem | _DateItem]
210
-
211
- def to_value(self) -> ListValue:
212
- return ListValue([item.to_value() for item in self.values])
213
-
214
-
215
- class _LeafItem(BaseModel):
216
- name: str
217
- values: list[_NumericItem | _StringItem | _DateItem]
218
-
219
- def to_value(self) -> Leaf:
220
- return Leaf(
221
- name=str(_ColumnName(self.name)),
222
- values=[item.to_value() for item in self.values],
223
- )
224
-
225
-
226
- class _OperatorItem(BaseModel):
227
- operation: Operation
228
- operands: list[Union["_LeafItem", "_OperatorItem"]]
229
-
230
- def to_value(self) -> Operator:
231
- return Operator(self.operation, [item.to_value() for item in self.operands])
232
-
233
-
234
- class _SortItem(BaseModel):
235
- name: str
236
- is_descending: bool
237
-
238
- def to_value(self) -> Sort:
239
- return Sort(str(_ColumnName(self.name)), self.is_descending)
240
-
241
-
242
- class _PageItem(BaseModel):
243
- page: int | None
244
- length: int | None
245
- offset: int | None
246
-
247
- def to_value(self) -> Page:
248
- return Page(self.page, self.length, self.offset)
249
-
250
-
251
- class _FilterItem(BaseModel):
252
- args: list[_NumericItem | _StringItem | _DateItem | _ListItem | None]
253
-
254
- def to_value(self) -> Filter:
255
- return Filter(
256
- [arg.to_value() if arg is not None else None for arg in self.args]
257
- )
258
-
259
-
260
- class _AggregationOptionItem(BaseModel):
261
- name: str | None
262
- aggregation: Aggregation
263
-
264
- def to_value(self) -> AggregationOption:
265
- return AggregationOption(
266
- str(_ColumnName(self.name)) if self.name else None,
267
- self.aggregation,
268
- )
269
-
270
-
271
- class _FooterOptions(BaseModel):
272
- filter: _FilterItem | None
273
- condition: _OperatorItem | None
274
- aggregations: list[_AggregationOptionItem]
275
-
276
- def to_footer_options(self) -> FooterOptions:
277
- return FooterOptions(
278
- filter=self.filter.to_value() if self.filter else None,
279
- condition=self.condition.to_value() if self.condition else None,
280
- aggregations=[item.to_value() for item in self.aggregations],
281
- )
282
-
283
-
284
- class _QueryOptions(BaseModel):
285
- filter: _FilterItem | None
286
- condition: _OperatorItem | None
287
- ordering: list[_SortItem]
288
- paging: _PageItem
289
-
290
- def to_query_options(self) -> QueryOptions:
291
- return QueryOptions(
292
- filter=self.filter.to_value() if self.filter else None,
293
- condition=self.condition.to_value() if self.condition else None,
294
- ordering=[item.to_value() for item in self.ordering],
295
- paging=self.paging.to_value(),
296
- )
297
-
298
-
299
- class _SummaryItem(BaseModel):
300
- name: str | None
301
- aggregation: Aggregation
302
- result: NumericValue | StringValue | DateValue | NullValue
303
-
304
-
305
- class _SummaryListEnvelope(BaseModel):
306
- count: int
307
- summaries: list[_SummaryItem]
308
-
309
-
310
- class SummaryResponse(BaseModel):
311
- status: str
312
- code: int
313
- data: _SummaryListEnvelope
314
-
315
-
316
- class SumResponse(BaseModel):
317
- status: str
318
- code: int
319
- count: int
@@ -1,7 +1,7 @@
1
1
  from collections.abc import Callable
2
2
  from dataclasses import dataclass, field
3
3
  from enum import Enum
4
- from typing import Annotated, Any, Protocol, Self, TypeVar
4
+ from typing import Annotated, Any, Protocol, Self
5
5
 
6
6
  from fastapi import APIRouter, Depends, Path, Query
7
7
  from fastapi.responses import JSONResponse
@@ -47,8 +47,6 @@ class RouterWithHiddenUnderscoreRoutes(APIRouter):
47
47
 
48
48
  _Response = JSONResponse | dict[str, Any]
49
49
 
50
- T = TypeVar("T")
51
-
52
50
 
53
51
  class Dependency(Protocol): # pragma: no cover
54
52
  def as_dependable(self) -> type[RestfulService]:
@@ -123,11 +121,12 @@ class RestfulRouter:
123
121
  def with_create_one(
124
122
  self,
125
123
  dependency: Dependency | None = None,
124
+ *,
126
125
  is_documented: bool = True,
127
126
  ) -> Self:
128
127
  self.router.add_api_route(
129
128
  "",
130
- self.resource.create_one(
129
+ self.resource.create_one_endpoint(
131
130
  Service=self._resolve(dependency),
132
131
  Item=Annotated[
133
132
  RawItem,
@@ -147,11 +146,12 @@ class RestfulRouter:
147
146
  def with_read_one(
148
147
  self,
149
148
  dependency: Dependency | None = None,
149
+ *,
150
150
  is_documented: bool = True,
151
151
  ) -> Self:
152
152
  self.router.add_api_route(
153
153
  self.item_path,
154
- self.resource.read_one(
154
+ self.resource.read_one_endpoint(
155
155
  Service=self._resolve(dependency),
156
156
  ItemId=Annotated[
157
157
  str,
@@ -172,14 +172,18 @@ class RestfulRouter:
172
172
  self,
173
173
  query: FluentDict[Any],
174
174
  dependency: Dependency | None = None,
175
+ *,
175
176
  is_documented: bool = True,
176
177
  ) -> Self:
177
178
  self.router.add_api_route(
178
179
  "",
179
- self.resource.read_many(
180
+ self.resource.read_many_endpoint(
180
181
  Service=self._resolve(dependency),
181
182
  QueryParams=Annotated[
182
- Schema(self.name.singular).optional_schema_for("ReadMany", query),
183
+ Schema(self.name.singular).optional_schema_for(
184
+ action="ReadMany",
185
+ fields=query,
186
+ ),
183
187
  Query(),
184
188
  ],
185
189
  ),
@@ -196,11 +200,14 @@ class RestfulRouter:
196
200
  def with_read_all(
197
201
  self,
198
202
  dependency: Dependency | None = None,
203
+ *,
199
204
  is_documented: bool = True,
200
205
  ) -> Self:
201
206
  self.router.add_api_route(
202
207
  "",
203
- self.resource.read_all(Service=self._resolve(dependency)),
208
+ self.resource.read_all_endpoint(
209
+ Service=self._resolve(dependency),
210
+ ),
204
211
  methods=["GET"],
205
212
  status_code=200,
206
213
  responses={},
@@ -214,11 +221,12 @@ class RestfulRouter:
214
221
  def with_update_one(
215
222
  self,
216
223
  dependency: Dependency | None = None,
224
+ *,
217
225
  is_documented: bool = True,
218
226
  ) -> Self:
219
227
  self.router.add_api_route(
220
228
  self.item_path,
221
- self.resource.update_one(
229
+ self.resource.update_one_endpoint(
222
230
  Service=self._resolve(dependency),
223
231
  ItemId=Annotated[
224
232
  str,
@@ -242,11 +250,12 @@ class RestfulRouter:
242
250
  def with_replace_one(
243
251
  self,
244
252
  dependency: Dependency | None = None,
253
+ *,
245
254
  is_documented: bool = True,
246
255
  ) -> Self:
247
256
  self.router.add_api_route(
248
257
  "",
249
- self.resource.replace_one(
258
+ self.resource.replace_one_endpoint(
250
259
  Service=self._resolve(dependency),
251
260
  Item=Annotated[
252
261
  RawItem,
@@ -266,11 +275,12 @@ class RestfulRouter:
266
275
  def with_delete_one(
267
276
  self,
268
277
  dependency: Dependency | None = None,
278
+ *,
269
279
  is_documented: bool = True,
270
280
  ) -> Self:
271
281
  self.router.add_api_route(
272
282
  self.item_path,
273
- self.resource.delete_one(
283
+ self.resource.delete_one_endpoint(
274
284
  Service=self._resolve(dependency),
275
285
  ItemId=Annotated[
276
286
  str,
@@ -11,9 +11,6 @@ from apexdevkit.fastapi.name import RestfulName
11
11
 
12
12
 
13
13
  class SchemaFields(ABC):
14
- def id(self) -> FluentDict[type]:
15
- return self.readable().select("id")
16
-
17
14
  def writable(self) -> FluentDict[type]:
18
15
  return self.readable().drop("id")
19
16
 
@@ -2,59 +2,36 @@ from __future__ import annotations
2
2
 
3
3
  from collections.abc import Iterable, Mapping
4
4
  from dataclasses import dataclass
5
- from functools import cached_property
6
- from typing import Any
5
+ from typing import TYPE_CHECKING, Any
7
6
 
8
- from apexdevkit.formatter import Formatter
9
- from apexdevkit.repository import BruteForceBatch, Entity, Repository
10
- from apexdevkit.repository.core.interface import BatchRepository
7
+ from apexdevkit.repository import Entity, Repository
8
+
9
+ if TYPE_CHECKING:
10
+ from apexdevkit.formatter import Formatter
11
11
 
12
12
  RawItem = Mapping[str, Any]
13
13
  RawCollection = Iterable[RawItem]
14
14
 
15
15
 
16
- class _RawItemWithId(dict[str, Any]):
17
- def __post_init__(self) -> None:
18
- assert "id" in self
19
-
20
-
21
- RawCollectionWithId = Iterable[_RawItemWithId]
22
-
23
-
24
16
  class RestfulService: # pragma: no cover
25
17
  def create_one(self, item: RawItem) -> RawItem:
26
18
  raise NotImplementedError(self.create_one.__name__)
27
19
 
28
- def create_many(self, items: RawCollection) -> RawCollection:
29
- raise NotImplementedError(self.create_many.__name__)
30
-
31
20
  def read_one(self, item_id: str) -> RawItem:
32
21
  raise NotImplementedError(self.read_one.__name__)
33
22
 
34
23
  def read_many(self, **params: Any) -> RawCollection:
35
24
  raise NotImplementedError(self.read_many.__name__)
36
25
 
37
- def filter_with(self, options: RawItem) -> RawCollection:
38
- raise NotImplementedError(self.filter_with.__name__)
39
-
40
- def aggregation_with(self, options: RawItem) -> RawItem:
41
- raise NotImplementedError(self.filter_with.__name__)
42
-
43
26
  def read_all(self) -> RawCollection:
44
27
  raise NotImplementedError(self.read_all.__name__)
45
28
 
46
29
  def update_one(self, item_id: str, **with_fields: Any) -> RawItem:
47
30
  raise NotImplementedError(self.update_one.__name__)
48
31
 
49
- def update_many(self, items: RawCollectionWithId) -> RawCollection:
50
- raise NotImplementedError(self.update_many.__name__)
51
-
52
32
  def replace_one(self, item: RawItem) -> RawItem:
53
33
  raise NotImplementedError(self.replace_one.__name__)
54
34
 
55
- def replace_many(self, items: RawCollection) -> RawCollection:
56
- raise NotImplementedError(self.replace_many.__name__)
57
-
58
35
  def delete_one(self, item_id: str) -> None:
59
36
  raise NotImplementedError(self.delete_one.__name__)
60
37
 
@@ -65,21 +42,9 @@ class RestfulRepository[ItemT: Entity](RestfulService):
65
42
 
66
43
  formatter: Formatter[Mapping[str, Any], ItemT]
67
44
 
68
- @cached_property
69
- def _batch(self) -> BatchRepository[ItemT]:
70
- return BruteForceBatch(inner=self.repository)
71
-
72
45
  def create_one(self, item: RawItem) -> RawItem:
73
46
  return self.formatter.dump(self.repository.create(self.formatter.load(item)))
74
47
 
75
- def create_many(self, items: RawCollection) -> RawCollection:
76
- return [
77
- self.formatter.dump(item)
78
- for item in self._batch.load(
79
- [self.formatter.load(fields) for fields in items]
80
- )
81
- ]
82
-
83
48
  def read_one(self, item_id: str) -> RawItem:
84
49
  return self.formatter.dump(self.repository.read(item_id))
85
50
 
@@ -94,25 +59,10 @@ class RestfulRepository[ItemT: Entity](RestfulService):
94
59
 
95
60
  return data
96
61
 
97
- def update_many(self, items: RawCollectionWithId) -> RawCollection:
98
- updates = []
99
- for fields in items:
100
- data = dict(self.formatter.dump(self.repository.read(fields["id"])))
101
- data.update(**fields)
102
-
103
- updates.append(self.formatter.load(data))
104
-
105
- return [self.formatter.dump(item) for item in self._batch.renew(updates)]
106
-
107
62
  def replace_one(self, item: RawItem) -> RawItem:
108
63
  self.repository.update(self.formatter.load(item))
109
64
 
110
65
  return item
111
66
 
112
- def replace_many(self, items: RawCollection) -> RawCollection:
113
- updated = self._batch.renew([self.formatter.load(item) for item in items])
114
-
115
- return [self.formatter.dump(item) for item in updated]
116
-
117
67
  def delete_one(self, item_id: str) -> None:
118
68
  self.repository.delete(item_id)