b24api 2.5.1__tar.gz → 2.6.0__tar.gz
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.
- {b24api-2.5.1/b24api.egg-info → b24api-2.6.0}/PKG-INFO +165 -3
- {b24api-2.5.1 → b24api-2.6.0}/README.md +164 -2
- {b24api-2.5.1 → b24api-2.6.0}/b24api/_client_traversal.py +58 -2
- b24api-2.6.0/b24api/batch/correlation.py +70 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/batch/engine.py +114 -91
- {b24api-2.5.1 → b24api-2.6.0}/b24api/batch/logical.py +20 -8
- {b24api-2.5.1 → b24api-2.6.0}/b24api/batch/stream.py +10 -4
- b24api-2.6.0/b24api/batch/v3.py +343 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/client.py +44 -2
- {b24api-2.5.1 → b24api-2.6.0}/b24api/completion/closure.py +13 -7
- {b24api-2.5.1 → b24api-2.6.0}/b24api/completion/fast_recorder.py +66 -30
- {b24api-2.5.1 → b24api-2.6.0}/b24api/completion/gate.py +8 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/completion/operation_stream.py +4 -1
- {b24api-2.5.1 → b24api-2.6.0}/b24api/completion/reference_recorder.py +94 -3
- {b24api-2.5.1 → b24api-2.6.0}/b24api/contracts/__init__.py +24 -1
- {b24api-2.5.1 → b24api-2.6.0}/b24api/contracts/completion.py +2 -0
- b24api-2.6.0/b24api/contracts/continuation.py +181 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/contracts/policy.py +5 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/contracts/reference.py +8 -0
- b24api-2.6.0/b24api/contracts/reference_source.py +59 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/contracts/report.py +7 -1
- {b24api-2.5.1 → b24api-2.6.0}/b24api/contracts/request.py +8 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/contracts/response.py +43 -2
- {b24api-2.5.1 → b24api-2.6.0}/b24api/contracts/traversal.py +172 -8
- b24api-2.6.0/b24api/contracts/wire_body.py +74 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/errors.py +33 -2
- {b24api-2.5.1 → b24api-2.6.0}/b24api/execution/boundary.py +35 -1
- {b24api-2.5.1 → b24api-2.6.0}/b24api/execution/context.py +22 -1
- {b24api-2.5.1 → b24api-2.6.0}/b24api/execution/executor.py +193 -11
- {b24api-2.5.1 → b24api-2.6.0}/b24api/execution/snapshot.py +5 -1
- b24api-2.6.0/b24api/references/budget_view.py +128 -0
- b24api-2.6.0/b24api/references/compatibility.py +83 -0
- b24api-2.6.0/b24api/references/counted_io.py +348 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/references/dispatch.py +246 -58
- {b24api-2.5.1 → b24api-2.6.0}/b24api/references/facade.py +111 -18
- b24api-2.6.0/b24api/references/keyset_run.py +199 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/references/outcome.py +4 -0
- b24api-2.6.0/b24api/references/program.py +95 -0
- b24api-2.6.0/b24api/references/run.py +52 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/references/scheduler.py +331 -156
- b24api-2.6.0/b24api/references/sources.py +200 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/references/stream.py +14 -4
- {b24api-2.5.1 → b24api-2.6.0}/b24api/references/support.py +3 -0
- b24api-2.6.0/b24api/references/wave_engine.py +161 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/testing/__init__.py +3 -1
- b24api-2.6.0/b24api/testing/scripted.py +290 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/transport/__init__.py +10 -1
- {b24api-2.5.1 → b24api-2.6.0}/b24api/transport/base.py +74 -0
- b24api-2.6.0/b24api/transport/disposition.py +148 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/transport/httpx.py +14 -6
- {b24api-2.5.1 → b24api-2.6.0}/b24api/transport/protocol.py +5 -3
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/__init__.py +1 -1
- b24api-2.6.0/b24api/traversal/continuation.py +173 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/control_preflight.py +40 -0
- b24api-2.6.0/b24api/traversal/counted_batch.py +355 -0
- b24api-2.6.0/b24api/traversal/counted_io.py +306 -0
- b24api-2.6.0/b24api/traversal/counted_rules.py +220 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/cursor.py +27 -9
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/driver.py +71 -13
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/facade.py +67 -5
- b24api-2.6.0/b24api/traversal/facade_support.py +94 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/identity.py +4 -0
- b24api-2.6.0/b24api/traversal/inclusive_window.py +225 -0
- b24api-2.6.0/b24api/traversal/keyset_context.py +81 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/keyset_fast_stream.py +7 -2
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/keyset_runtime.py +8 -5
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/keyset_transaction_contract.py +6 -6
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/keyset_transactions.py +2 -2
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/plans.py +97 -2
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/sequential.py +8 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/strategy_context.py +16 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/stream.py +9 -2
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/values.py +8 -11
- {b24api-2.5.1 → b24api-2.6.0/b24api.egg-info}/PKG-INFO +165 -3
- {b24api-2.5.1 → b24api-2.6.0}/b24api.egg-info/SOURCES.txt +18 -0
- b24api-2.5.1/b24api/testing/scripted.py +0 -147
- b24api-2.5.1/b24api/traversal/counted_batch.py +0 -369
- b24api-2.5.1/b24api/traversal/counted_rules.py +0 -74
- b24api-2.5.1/b24api/traversal/facade_support.py +0 -36
- {b24api-2.5.1 → b24api-2.6.0}/LICENSE +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/MANIFEST.in +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/__init__.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/_diagnostics.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/_error_types.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/_sources.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/batch/__init__.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/batch/facade.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/batch/outcome.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/cli.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/cli_contract.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/completion/__init__.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/completion/recorder.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/contracts/bounded_range.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/contracts/command.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/contracts/dispatch.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/contracts/error_base.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/contracts/evidence.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/contracts/identity_store.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/contracts/json.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/contracts/keyset_capability.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/contracts/keyset_execution.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/contracts/page.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/contracts/page_stop.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/contracts/positional.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/contracts/request_summary.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/contracts/stream.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/contracts/v3_codes.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/contracts/violation.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/contracts/wire.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/encoding.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/execution/__init__.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/execution/cleanup.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/execution/failure.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/execution/lifecycle.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/execution/rate.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/execution/throttle.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/migration.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/py.typed +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/redaction.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/references/__init__.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/references/binding.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/references/dispatch_plan.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/references/fanout.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/settings.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/testing/_isolation.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/testing/transport.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/transport/decoding.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/transport/log_records.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/transport/logging_shield.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/counted.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/cursor_domain.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/identity_ledger.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/keyset.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/keyset_auto.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/keyset_capability.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/keyset_eligibility.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/keyset_fast_plan.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/keyset_geometry.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/keyset_observation.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/keyset_ordered_admission.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/keyset_page_validation.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/keyset_plan.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/keyset_reporting.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/keyset_step.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/keyset_verifier.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/offset_rules.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/page_adaptation.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api/traversal/sparse.py +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api.egg-info/dependency_links.txt +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api.egg-info/entry_points.txt +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api.egg-info/requires.txt +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/b24api.egg-info/top_level.txt +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/pyproject.toml +0 -0
- {b24api-2.5.1 → b24api-2.6.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: b24api
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.6.0
|
|
4
4
|
Summary: Bitrix24 API
|
|
5
5
|
Author-email: Shkarupa Alex <shkarupa.alex@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -29,7 +29,7 @@ Requires-Dist: pydantic>=2.12.0
|
|
|
29
29
|
Requires-Dist: pydantic-settings>=2.10.1
|
|
30
30
|
Dynamic: license-file
|
|
31
31
|
|
|
32
|
-
# b24api
|
|
32
|
+
# b24api 2.x
|
|
33
33
|
|
|
34
34
|
`b24api` is a thin asynchronous Bitrix24 REST client for Python 3.12+. It knows how to send
|
|
35
35
|
requests, split logical batches, traverse lists, retry safely, preserve caller correlation and
|
|
@@ -98,6 +98,12 @@ archive = await client.call_bytes(Request("example.export.download", replay_safe
|
|
|
98
98
|
payload = archive.body
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
+
`archive.filename` is the name decoded from `Content-Disposition` (`filename*` takes precedence
|
|
102
|
+
over `filename`), or `None`; `archive.evidence.filename_status` records whether that header was
|
|
103
|
+
absent, parsed or malformed. The name is caller-facing metadata, not a safe path: it is never
|
|
104
|
+
normalized, truncated or reduced to a basename, and it stays out of the representation and
|
|
105
|
+
diagnostics. Sanitize it before using it on a filesystem.
|
|
106
|
+
|
|
101
107
|
<!-- tested: tests/client_v2_test.py::test_call_and_call_response_have_stable_detached_types -->
|
|
102
108
|
```python
|
|
103
109
|
from b24api import RouteKind
|
|
@@ -200,6 +206,36 @@ async with client.batch_outcomes(commands) as stream:
|
|
|
200
206
|
handle(outcome)
|
|
201
207
|
```
|
|
202
208
|
|
|
209
|
+
Commands whose request uses `RouteKind.API_V3` travel in native REST 3.0 batch envelopes: one JSON
|
|
210
|
+
array of at most 50 commands, never mixed with classic commands and grouped into contiguous runs of
|
|
211
|
+
one replay safety (`UNSAFE` and `UNKNOWN` share a run). Envelopes go out in input order: a classic
|
|
212
|
+
command between two v3 commands travels in its own envelope between theirs. The transport must
|
|
213
|
+
advertise JSON-array bodies, as `HttpxTransport` does; otherwise such a command fails with
|
|
214
|
+
`CapabilityError` before any request. Each array element is checked against its own request's
|
|
215
|
+
embedded-error contract, so one failed command neither fails nor resends its successful neighbours.
|
|
216
|
+
|
|
217
|
+
<!-- tested: tests/v3_batch_test.py::test_a21_wire_four_safe_v3_reads_travel_in_one_envelope_in_input_order -->
|
|
218
|
+
```python
|
|
219
|
+
from b24api import RouteKind
|
|
220
|
+
from b24api.contracts import Command
|
|
221
|
+
|
|
222
|
+
v3_commands = (
|
|
223
|
+
Command(Request("example.item.get", {"id": item_id}, ReplaySafety.SAFE, route=RouteKind.API_V3), item_id)
|
|
224
|
+
for item_id in source_ids
|
|
225
|
+
)
|
|
226
|
+
async with client.batch_outcomes(v3_commands) as stream:
|
|
227
|
+
async for outcome in stream:
|
|
228
|
+
handle(outcome)
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
REST 3.0 does not roll a batch back. When a whole envelope fails after it may have run, `SAFE`
|
|
232
|
+
commands of a transient failure get one envelope retry within their attempt budget, and commands
|
|
233
|
+
still unresolved are sent individually (`RetryPolicy.isolate_safe_batch_abort`, enabled by default)
|
|
234
|
+
under the same attempt lineage; `UNSAFE` and `UNKNOWN` commands arrive
|
|
235
|
+
as `CommandOutcomeUnknown` without a resend. The report counts `ambiguous_physical_attempts` and
|
|
236
|
+
`batch_isolation_requests`. Fail-fast `batch()` finishes resolving the envelope it already sent and
|
|
237
|
+
then raises without reading further input.
|
|
238
|
+
|
|
203
239
|
For independently dispatchable commands, use `fan_out()` or `fan_out_outcomes()` with
|
|
204
240
|
`DirectDispatch` or `BatchDispatch`. Delivery order is explicitly `READY` or `INPUT`.
|
|
205
241
|
|
|
@@ -214,8 +250,11 @@ more specialized mechanics have explicit names and explicit preconditions.
|
|
|
214
250
|
| `iter_list_counted` | The first response provides an exact filtered `total` and stable offset pages. | Head page is direct; all known tail offsets are grouped into physical Bitrix batches. | Exact total, ranges and identities. |
|
|
215
251
|
| `iter_list_keyset` | The method may omit `total`, but reliably supports ordering and filtering by a unique integer identity. | Auto by default: it plans first, then selects boundary-only, sequential, range, or partitioned execution; runtime sends no diagnostic canaries. | Caller-asserted keyset contract, strict monotonic identity, active bound validation, and terminal empty confirmation. |
|
|
216
252
|
| `iter_list_cursor` | Each next request depends on a cursor from the previous response. | Sequential dependent cursor requests. | Strict unique monotonic cursor and empty terminal page. |
|
|
253
|
+
| `iter_list_continuation` | The next request is described by values on the current page, such as a response cursor object or a pair of controls. | Sequential requests; a pure caller rule returns the next values of declared controls or ends the source. | Rule-declared end; undeclared updates and repeated control vectors fail closed. |
|
|
254
|
+
| `iter_list_window` | A newest-first list resumes from an inclusive timestamp boundary and may also return pinned rows. | Sequential requests carrying the oldest paging timestamp of the previous page. | Strict boundary progress, overlap delivered once, and a response flag that closes the source. |
|
|
217
255
|
| `iter_cursors` | One or many parent-bound cursor traversals need correlation and shared batching. | Lazy per-parent drivers share the reference batch queue; each binding may have `start_cursor`. | Isolated strict cursor progress and terminal event per binding. |
|
|
218
256
|
| `iter_references` | The same list method must run for many parent parameter sets, such as comments per owner or messages per chat. | Bindings are scheduled with direct or physical-batch dispatch; each binding has its own traversal state. | Per-binding rows, completion/failure and caller correlation. |
|
|
257
|
+
| `iter_reference_sources` | Parents need different methods or traversals in one operation. | Each source brings its own request and traversal; compatible pages of all sources share one batch queue. | Per-source rows, terminal event and correlation. |
|
|
219
258
|
|
|
220
259
|
`page_size` is a local decoded-page cap. It is sent to Bitrix only when you provide the endpoint's
|
|
221
260
|
exact `limit_path`; the client never guesses method-specific parameter names.
|
|
@@ -347,7 +386,8 @@ contract or when the previous request-by-request behavior is required.
|
|
|
347
386
|
Static incompatibility with the auto contract raises `CapabilityError` from the
|
|
348
387
|
`iter_list_keyset(...)` call before iteration begins. A portal that accepts but contradicts the
|
|
349
388
|
declared controls fails before emission with `IncompleteTraversalError`; auto never restarts that
|
|
350
|
-
operation silently.
|
|
389
|
+
operation silently. Reference traversal can opt into the same selection for each binding; see
|
|
390
|
+
[Keyset references](#keyset-references). The
|
|
351
391
|
terminal report carries a compact `keyset_selection` (`requested_kind`, `selected_kind`, `reason`)
|
|
352
392
|
for every keyset traversal. A `page_stop` callback needs the ordered page stream, so auto reports
|
|
353
393
|
`AUTO`, `SEQUENTIAL`, `PAGE_STOP`; an explicit `SequentialKeysetExecution()` reports
|
|
@@ -429,6 +469,58 @@ stream = client.iter_list_cursor(
|
|
|
429
469
|
Cursor values must be unique and strictly monotonic. If an endpoint exposes only a non-unique
|
|
430
470
|
boundary, use an application-owned direct-call workflow or supply a unique tie-breaker.
|
|
431
471
|
|
|
472
|
+
Some message endpoints move the boundary toward older rows but return each page oldest-first.
|
|
473
|
+
Declare that page order separately with `page_order="ascending"` beside `direction="descending"` and
|
|
474
|
+
`take="first"`: rows must be strictly ordered inside the page and every value must lie beyond the
|
|
475
|
+
previous boundary. `continuation=ResponseFlagTerminal(ResultSelector(("hasNextPage",)))` closes the
|
|
476
|
+
traversal on a `False` flag, even on a non-empty page, instead of requesting an empty confirmation
|
|
477
|
+
page; a missing or non-boolean flag fails closed. An explicit global ascending or descending
|
|
478
|
+
`ConsistencyPolicy` order contradicting a reversed page order is refused before any request.
|
|
479
|
+
|
|
480
|
+
### Response-driven continuation
|
|
481
|
+
|
|
482
|
+
When the next request is fully described by the current page, `iter_list_continuation()` keeps the
|
|
483
|
+
request transaction, identity checks and terminal evidence in the client and asks a pure rule only
|
|
484
|
+
for the next control values. `ResponseCursorRule` carries a response cursor, whole and unchanged
|
|
485
|
+
(an object cursor keeps every field and its full precision), while a boolean response flag says more
|
|
486
|
+
pages exist:
|
|
487
|
+
|
|
488
|
+
<!-- tested: tests/continuation_test.py::test_a22_a_response_object_cursor_is_carried_whole_and_rule_ends_nonempty_page -->
|
|
489
|
+
```python
|
|
490
|
+
from b24api import ParameterPath, ResultSelector, RouteKind
|
|
491
|
+
from b24api.contracts import ContinuationTraversal, ResponseCursorRule, ResponseFlagTerminal
|
|
492
|
+
|
|
493
|
+
cursor_control = ParameterPath(("cursor",))
|
|
494
|
+
stream = client.iter_list_continuation(
|
|
495
|
+
Request("example.event.list", replay_safety=ReplaySafety.SAFE, route=RouteKind.BARE),
|
|
496
|
+
traversal=ContinuationTraversal(
|
|
497
|
+
selector=ResultSelector(("items",)),
|
|
498
|
+
identity=identity,
|
|
499
|
+
controls=(cursor_control,),
|
|
500
|
+
rule=ResponseCursorRule(
|
|
501
|
+
cursor_selector=ResultSelector(("cursor",)),
|
|
502
|
+
parameter_path=cursor_control,
|
|
503
|
+
terminal=ResponseFlagTerminal(ResultSelector(("hasMore",))),
|
|
504
|
+
),
|
|
505
|
+
),
|
|
506
|
+
)
|
|
507
|
+
async with stream:
|
|
508
|
+
async for item in stream:
|
|
509
|
+
consume(item)
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
A custom rule implements `evaluate(page)` and returns `ContinueWith(updates)` for exactly the
|
|
513
|
+
declared controls, or `EndOfSource()`. Rows of the page that ends the source are still delivered,
|
|
514
|
+
and the report closes with `rule_declared_end`. The client rejects updates to undeclared controls,
|
|
515
|
+
control vectors over 64 KiB and a repeated control vector with `ContinuationError`; such a failure
|
|
516
|
+
never reports the source as exhausted.
|
|
517
|
+
|
|
518
|
+
For newest-first lists that resume from an inclusive timestamp and may also return pinned rows,
|
|
519
|
+
`iter_list_window()` sends the oldest paging timestamp of each page unchanged, delivers rows
|
|
520
|
+
repeated by the overlap once and fails as non-progress, without another request, when the boundary
|
|
521
|
+
does not move. See
|
|
522
|
+
[Inclusive timestamp windows](https://github.com/shkarupa-alex/b24api/blob/master/docs/recipes.md#inclusive-timestamp-windows).
|
|
523
|
+
|
|
432
524
|
For multiple parent-bound cursor chains, `iter_cursors()` keeps cursor progress and correlation
|
|
433
525
|
isolated per binding while ready pages share the physical batch queue.
|
|
434
526
|
|
|
@@ -529,6 +621,76 @@ messages = client.iter_references(
|
|
|
529
621
|
`Binding` has no valid caller correlation, so it terminates the source with `InputSourceError`
|
|
530
622
|
rather than fabricating a reference outcome. Already accepted bindings retain their real outcomes.
|
|
531
623
|
|
|
624
|
+
### Keyset references
|
|
625
|
+
|
|
626
|
+
`KeysetTraversal` bindings run sequentially by default (`SequentialKeysetExecution()`), unlike
|
|
627
|
+
`iter_list_keyset()`, whose default is automatic. Pass `AutoKeysetExecution`,
|
|
628
|
+
`RangeKeysetExecution` or `PartitionedKeysetExecution` as the traversal's `execution` to opt in. A
|
|
629
|
+
binding with automatic, range or partitioned execution runs its own planning barrier and selection;
|
|
630
|
+
its waves travel through the shared batch queue beside other bindings' pages, and its
|
|
631
|
+
`ReferenceComplete` carries the binding's `keyset_selection` and, when the fast path ran, its
|
|
632
|
+
`keyset_execution`. From its first request to its terminal event the binding holds a fixed share of
|
|
633
|
+
`ExecutionPolicy.max_buffered_rows` and plans every wave within it; requests, pages, attempts and
|
|
634
|
+
elapsed time stay on the one operation budget. An automatic binding whose planning floor exceeds the
|
|
635
|
+
whole row budget waits to run alone with all of it (under `INPUT` delivery, once it is the next
|
|
636
|
+
binding to deliver); a binding that cannot obtain its floor while no other binding can release rows
|
|
637
|
+
fails with `BudgetExceededError`, and waiting for a share never outlasts `max_elapsed`.
|
|
638
|
+
|
|
639
|
+
Fast and automatic keyset references need `BatchDispatch`. With a `page_stop`, automatic execution
|
|
640
|
+
runs sequentially and reports `PAGE_STOP`; an explicit fast mode with a `page_stop` or
|
|
641
|
+
`DirectDispatch` is refused before any request. A `KeysetSpec.boundary` remains unavailable in
|
|
642
|
+
references.
|
|
643
|
+
|
|
644
|
+
### Counted references
|
|
645
|
+
|
|
646
|
+
`CountedTraversal` bindings read their head page and every known tail offset through the shared
|
|
647
|
+
batch queue, so one physical batch can carry pages of several bindings and the HTTP count drops
|
|
648
|
+
accordingly; each subrequest still performs its own server-side COUNT. Pages are committed in
|
|
649
|
+
offset order per binding. Counted references need `BatchDispatch` and do not accept a `page_stop`.
|
|
650
|
+
|
|
651
|
+
### Different methods in one operation
|
|
652
|
+
|
|
653
|
+
`iter_reference_sources()` accepts a lazy source of `ReferenceSource` values, each with its own
|
|
654
|
+
request template, traversal, binding and optional `page_stop`. All sources share one dispatcher,
|
|
655
|
+
row pool, `ExecutionPolicy` and terminal report, so compatible pages of different methods coalesce
|
|
656
|
+
into the same physical batch, and late sources start as capacity frees up rather than after earlier
|
|
657
|
+
sources finish. Identities and page state belong to each source: equal child IDs under different
|
|
658
|
+
sources are never conflated.
|
|
659
|
+
|
|
660
|
+
<!-- tested: tests/reference_sources_test.py::test_a28_different_templates_share_the_dispatcher_and_keep_separate_state -->
|
|
661
|
+
```python
|
|
662
|
+
from b24api import Binding, ParameterPath, ParameterUpdate, RouteKind, SequentialTraversal
|
|
663
|
+
from b24api.contracts import ReferenceItem, ReferenceSource
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
def owned(method, owner_id):
|
|
667
|
+
return ReferenceSource(
|
|
668
|
+
Request(method, replay_safety=ReplaySafety.SAFE, route=RouteKind.BARE),
|
|
669
|
+
SequentialTraversal(selector=ResultSelector(("items",)), identity=identity),
|
|
670
|
+
Binding(
|
|
671
|
+
summary=f"{method} for owner {owner_id}",
|
|
672
|
+
updates=(ParameterUpdate(ParameterPath(("filter", "OWNER_ID")), owner_id),),
|
|
673
|
+
correlation=(method, owner_id),
|
|
674
|
+
),
|
|
675
|
+
)
|
|
676
|
+
|
|
677
|
+
|
|
678
|
+
sources = (
|
|
679
|
+
owned(method, owner_id)
|
|
680
|
+
for owner_id in parent_ids
|
|
681
|
+
for method in ("example.comment.list", "example.activity.list")
|
|
682
|
+
)
|
|
683
|
+
stream = client.iter_reference_sources(sources)
|
|
684
|
+
async with stream:
|
|
685
|
+
async for event in stream:
|
|
686
|
+
if isinstance(event, ReferenceItem):
|
|
687
|
+
consume(event.correlation, event.item)
|
|
688
|
+
```
|
|
689
|
+
|
|
690
|
+
`iter_reference_source_outcomes()` additionally yields correlated failures. A valid source the
|
|
691
|
+
operation cannot run, such as a counted source under `DirectDispatch`, becomes a correlated
|
|
692
|
+
`ReferenceNotExecuted` before any request while the other sources continue.
|
|
693
|
+
|
|
532
694
|
## Streams, partial results and reports
|
|
533
695
|
|
|
534
696
|
Every multi-item operation returns an `OperationStream`. Prefer `async with`: a plain `break` does
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# b24api
|
|
1
|
+
# b24api 2.x
|
|
2
2
|
|
|
3
3
|
`b24api` is a thin asynchronous Bitrix24 REST client for Python 3.12+. It knows how to send
|
|
4
4
|
requests, split logical batches, traverse lists, retry safely, preserve caller correlation and
|
|
@@ -67,6 +67,12 @@ archive = await client.call_bytes(Request("example.export.download", replay_safe
|
|
|
67
67
|
payload = archive.body
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
+
`archive.filename` is the name decoded from `Content-Disposition` (`filename*` takes precedence
|
|
71
|
+
over `filename`), or `None`; `archive.evidence.filename_status` records whether that header was
|
|
72
|
+
absent, parsed or malformed. The name is caller-facing metadata, not a safe path: it is never
|
|
73
|
+
normalized, truncated or reduced to a basename, and it stays out of the representation and
|
|
74
|
+
diagnostics. Sanitize it before using it on a filesystem.
|
|
75
|
+
|
|
70
76
|
<!-- tested: tests/client_v2_test.py::test_call_and_call_response_have_stable_detached_types -->
|
|
71
77
|
```python
|
|
72
78
|
from b24api import RouteKind
|
|
@@ -169,6 +175,36 @@ async with client.batch_outcomes(commands) as stream:
|
|
|
169
175
|
handle(outcome)
|
|
170
176
|
```
|
|
171
177
|
|
|
178
|
+
Commands whose request uses `RouteKind.API_V3` travel in native REST 3.0 batch envelopes: one JSON
|
|
179
|
+
array of at most 50 commands, never mixed with classic commands and grouped into contiguous runs of
|
|
180
|
+
one replay safety (`UNSAFE` and `UNKNOWN` share a run). Envelopes go out in input order: a classic
|
|
181
|
+
command between two v3 commands travels in its own envelope between theirs. The transport must
|
|
182
|
+
advertise JSON-array bodies, as `HttpxTransport` does; otherwise such a command fails with
|
|
183
|
+
`CapabilityError` before any request. Each array element is checked against its own request's
|
|
184
|
+
embedded-error contract, so one failed command neither fails nor resends its successful neighbours.
|
|
185
|
+
|
|
186
|
+
<!-- tested: tests/v3_batch_test.py::test_a21_wire_four_safe_v3_reads_travel_in_one_envelope_in_input_order -->
|
|
187
|
+
```python
|
|
188
|
+
from b24api import RouteKind
|
|
189
|
+
from b24api.contracts import Command
|
|
190
|
+
|
|
191
|
+
v3_commands = (
|
|
192
|
+
Command(Request("example.item.get", {"id": item_id}, ReplaySafety.SAFE, route=RouteKind.API_V3), item_id)
|
|
193
|
+
for item_id in source_ids
|
|
194
|
+
)
|
|
195
|
+
async with client.batch_outcomes(v3_commands) as stream:
|
|
196
|
+
async for outcome in stream:
|
|
197
|
+
handle(outcome)
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
REST 3.0 does not roll a batch back. When a whole envelope fails after it may have run, `SAFE`
|
|
201
|
+
commands of a transient failure get one envelope retry within their attempt budget, and commands
|
|
202
|
+
still unresolved are sent individually (`RetryPolicy.isolate_safe_batch_abort`, enabled by default)
|
|
203
|
+
under the same attempt lineage; `UNSAFE` and `UNKNOWN` commands arrive
|
|
204
|
+
as `CommandOutcomeUnknown` without a resend. The report counts `ambiguous_physical_attempts` and
|
|
205
|
+
`batch_isolation_requests`. Fail-fast `batch()` finishes resolving the envelope it already sent and
|
|
206
|
+
then raises without reading further input.
|
|
207
|
+
|
|
172
208
|
For independently dispatchable commands, use `fan_out()` or `fan_out_outcomes()` with
|
|
173
209
|
`DirectDispatch` or `BatchDispatch`. Delivery order is explicitly `READY` or `INPUT`.
|
|
174
210
|
|
|
@@ -183,8 +219,11 @@ more specialized mechanics have explicit names and explicit preconditions.
|
|
|
183
219
|
| `iter_list_counted` | The first response provides an exact filtered `total` and stable offset pages. | Head page is direct; all known tail offsets are grouped into physical Bitrix batches. | Exact total, ranges and identities. |
|
|
184
220
|
| `iter_list_keyset` | The method may omit `total`, but reliably supports ordering and filtering by a unique integer identity. | Auto by default: it plans first, then selects boundary-only, sequential, range, or partitioned execution; runtime sends no diagnostic canaries. | Caller-asserted keyset contract, strict monotonic identity, active bound validation, and terminal empty confirmation. |
|
|
185
221
|
| `iter_list_cursor` | Each next request depends on a cursor from the previous response. | Sequential dependent cursor requests. | Strict unique monotonic cursor and empty terminal page. |
|
|
222
|
+
| `iter_list_continuation` | The next request is described by values on the current page, such as a response cursor object or a pair of controls. | Sequential requests; a pure caller rule returns the next values of declared controls or ends the source. | Rule-declared end; undeclared updates and repeated control vectors fail closed. |
|
|
223
|
+
| `iter_list_window` | A newest-first list resumes from an inclusive timestamp boundary and may also return pinned rows. | Sequential requests carrying the oldest paging timestamp of the previous page. | Strict boundary progress, overlap delivered once, and a response flag that closes the source. |
|
|
186
224
|
| `iter_cursors` | One or many parent-bound cursor traversals need correlation and shared batching. | Lazy per-parent drivers share the reference batch queue; each binding may have `start_cursor`. | Isolated strict cursor progress and terminal event per binding. |
|
|
187
225
|
| `iter_references` | The same list method must run for many parent parameter sets, such as comments per owner or messages per chat. | Bindings are scheduled with direct or physical-batch dispatch; each binding has its own traversal state. | Per-binding rows, completion/failure and caller correlation. |
|
|
226
|
+
| `iter_reference_sources` | Parents need different methods or traversals in one operation. | Each source brings its own request and traversal; compatible pages of all sources share one batch queue. | Per-source rows, terminal event and correlation. |
|
|
188
227
|
|
|
189
228
|
`page_size` is a local decoded-page cap. It is sent to Bitrix only when you provide the endpoint's
|
|
190
229
|
exact `limit_path`; the client never guesses method-specific parameter names.
|
|
@@ -316,7 +355,8 @@ contract or when the previous request-by-request behavior is required.
|
|
|
316
355
|
Static incompatibility with the auto contract raises `CapabilityError` from the
|
|
317
356
|
`iter_list_keyset(...)` call before iteration begins. A portal that accepts but contradicts the
|
|
318
357
|
declared controls fails before emission with `IncompleteTraversalError`; auto never restarts that
|
|
319
|
-
operation silently.
|
|
358
|
+
operation silently. Reference traversal can opt into the same selection for each binding; see
|
|
359
|
+
[Keyset references](#keyset-references). The
|
|
320
360
|
terminal report carries a compact `keyset_selection` (`requested_kind`, `selected_kind`, `reason`)
|
|
321
361
|
for every keyset traversal. A `page_stop` callback needs the ordered page stream, so auto reports
|
|
322
362
|
`AUTO`, `SEQUENTIAL`, `PAGE_STOP`; an explicit `SequentialKeysetExecution()` reports
|
|
@@ -398,6 +438,58 @@ stream = client.iter_list_cursor(
|
|
|
398
438
|
Cursor values must be unique and strictly monotonic. If an endpoint exposes only a non-unique
|
|
399
439
|
boundary, use an application-owned direct-call workflow or supply a unique tie-breaker.
|
|
400
440
|
|
|
441
|
+
Some message endpoints move the boundary toward older rows but return each page oldest-first.
|
|
442
|
+
Declare that page order separately with `page_order="ascending"` beside `direction="descending"` and
|
|
443
|
+
`take="first"`: rows must be strictly ordered inside the page and every value must lie beyond the
|
|
444
|
+
previous boundary. `continuation=ResponseFlagTerminal(ResultSelector(("hasNextPage",)))` closes the
|
|
445
|
+
traversal on a `False` flag, even on a non-empty page, instead of requesting an empty confirmation
|
|
446
|
+
page; a missing or non-boolean flag fails closed. An explicit global ascending or descending
|
|
447
|
+
`ConsistencyPolicy` order contradicting a reversed page order is refused before any request.
|
|
448
|
+
|
|
449
|
+
### Response-driven continuation
|
|
450
|
+
|
|
451
|
+
When the next request is fully described by the current page, `iter_list_continuation()` keeps the
|
|
452
|
+
request transaction, identity checks and terminal evidence in the client and asks a pure rule only
|
|
453
|
+
for the next control values. `ResponseCursorRule` carries a response cursor, whole and unchanged
|
|
454
|
+
(an object cursor keeps every field and its full precision), while a boolean response flag says more
|
|
455
|
+
pages exist:
|
|
456
|
+
|
|
457
|
+
<!-- tested: tests/continuation_test.py::test_a22_a_response_object_cursor_is_carried_whole_and_rule_ends_nonempty_page -->
|
|
458
|
+
```python
|
|
459
|
+
from b24api import ParameterPath, ResultSelector, RouteKind
|
|
460
|
+
from b24api.contracts import ContinuationTraversal, ResponseCursorRule, ResponseFlagTerminal
|
|
461
|
+
|
|
462
|
+
cursor_control = ParameterPath(("cursor",))
|
|
463
|
+
stream = client.iter_list_continuation(
|
|
464
|
+
Request("example.event.list", replay_safety=ReplaySafety.SAFE, route=RouteKind.BARE),
|
|
465
|
+
traversal=ContinuationTraversal(
|
|
466
|
+
selector=ResultSelector(("items",)),
|
|
467
|
+
identity=identity,
|
|
468
|
+
controls=(cursor_control,),
|
|
469
|
+
rule=ResponseCursorRule(
|
|
470
|
+
cursor_selector=ResultSelector(("cursor",)),
|
|
471
|
+
parameter_path=cursor_control,
|
|
472
|
+
terminal=ResponseFlagTerminal(ResultSelector(("hasMore",))),
|
|
473
|
+
),
|
|
474
|
+
),
|
|
475
|
+
)
|
|
476
|
+
async with stream:
|
|
477
|
+
async for item in stream:
|
|
478
|
+
consume(item)
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
A custom rule implements `evaluate(page)` and returns `ContinueWith(updates)` for exactly the
|
|
482
|
+
declared controls, or `EndOfSource()`. Rows of the page that ends the source are still delivered,
|
|
483
|
+
and the report closes with `rule_declared_end`. The client rejects updates to undeclared controls,
|
|
484
|
+
control vectors over 64 KiB and a repeated control vector with `ContinuationError`; such a failure
|
|
485
|
+
never reports the source as exhausted.
|
|
486
|
+
|
|
487
|
+
For newest-first lists that resume from an inclusive timestamp and may also return pinned rows,
|
|
488
|
+
`iter_list_window()` sends the oldest paging timestamp of each page unchanged, delivers rows
|
|
489
|
+
repeated by the overlap once and fails as non-progress, without another request, when the boundary
|
|
490
|
+
does not move. See
|
|
491
|
+
[Inclusive timestamp windows](https://github.com/shkarupa-alex/b24api/blob/master/docs/recipes.md#inclusive-timestamp-windows).
|
|
492
|
+
|
|
401
493
|
For multiple parent-bound cursor chains, `iter_cursors()` keeps cursor progress and correlation
|
|
402
494
|
isolated per binding while ready pages share the physical batch queue.
|
|
403
495
|
|
|
@@ -498,6 +590,76 @@ messages = client.iter_references(
|
|
|
498
590
|
`Binding` has no valid caller correlation, so it terminates the source with `InputSourceError`
|
|
499
591
|
rather than fabricating a reference outcome. Already accepted bindings retain their real outcomes.
|
|
500
592
|
|
|
593
|
+
### Keyset references
|
|
594
|
+
|
|
595
|
+
`KeysetTraversal` bindings run sequentially by default (`SequentialKeysetExecution()`), unlike
|
|
596
|
+
`iter_list_keyset()`, whose default is automatic. Pass `AutoKeysetExecution`,
|
|
597
|
+
`RangeKeysetExecution` or `PartitionedKeysetExecution` as the traversal's `execution` to opt in. A
|
|
598
|
+
binding with automatic, range or partitioned execution runs its own planning barrier and selection;
|
|
599
|
+
its waves travel through the shared batch queue beside other bindings' pages, and its
|
|
600
|
+
`ReferenceComplete` carries the binding's `keyset_selection` and, when the fast path ran, its
|
|
601
|
+
`keyset_execution`. From its first request to its terminal event the binding holds a fixed share of
|
|
602
|
+
`ExecutionPolicy.max_buffered_rows` and plans every wave within it; requests, pages, attempts and
|
|
603
|
+
elapsed time stay on the one operation budget. An automatic binding whose planning floor exceeds the
|
|
604
|
+
whole row budget waits to run alone with all of it (under `INPUT` delivery, once it is the next
|
|
605
|
+
binding to deliver); a binding that cannot obtain its floor while no other binding can release rows
|
|
606
|
+
fails with `BudgetExceededError`, and waiting for a share never outlasts `max_elapsed`.
|
|
607
|
+
|
|
608
|
+
Fast and automatic keyset references need `BatchDispatch`. With a `page_stop`, automatic execution
|
|
609
|
+
runs sequentially and reports `PAGE_STOP`; an explicit fast mode with a `page_stop` or
|
|
610
|
+
`DirectDispatch` is refused before any request. A `KeysetSpec.boundary` remains unavailable in
|
|
611
|
+
references.
|
|
612
|
+
|
|
613
|
+
### Counted references
|
|
614
|
+
|
|
615
|
+
`CountedTraversal` bindings read their head page and every known tail offset through the shared
|
|
616
|
+
batch queue, so one physical batch can carry pages of several bindings and the HTTP count drops
|
|
617
|
+
accordingly; each subrequest still performs its own server-side COUNT. Pages are committed in
|
|
618
|
+
offset order per binding. Counted references need `BatchDispatch` and do not accept a `page_stop`.
|
|
619
|
+
|
|
620
|
+
### Different methods in one operation
|
|
621
|
+
|
|
622
|
+
`iter_reference_sources()` accepts a lazy source of `ReferenceSource` values, each with its own
|
|
623
|
+
request template, traversal, binding and optional `page_stop`. All sources share one dispatcher,
|
|
624
|
+
row pool, `ExecutionPolicy` and terminal report, so compatible pages of different methods coalesce
|
|
625
|
+
into the same physical batch, and late sources start as capacity frees up rather than after earlier
|
|
626
|
+
sources finish. Identities and page state belong to each source: equal child IDs under different
|
|
627
|
+
sources are never conflated.
|
|
628
|
+
|
|
629
|
+
<!-- tested: tests/reference_sources_test.py::test_a28_different_templates_share_the_dispatcher_and_keep_separate_state -->
|
|
630
|
+
```python
|
|
631
|
+
from b24api import Binding, ParameterPath, ParameterUpdate, RouteKind, SequentialTraversal
|
|
632
|
+
from b24api.contracts import ReferenceItem, ReferenceSource
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
def owned(method, owner_id):
|
|
636
|
+
return ReferenceSource(
|
|
637
|
+
Request(method, replay_safety=ReplaySafety.SAFE, route=RouteKind.BARE),
|
|
638
|
+
SequentialTraversal(selector=ResultSelector(("items",)), identity=identity),
|
|
639
|
+
Binding(
|
|
640
|
+
summary=f"{method} for owner {owner_id}",
|
|
641
|
+
updates=(ParameterUpdate(ParameterPath(("filter", "OWNER_ID")), owner_id),),
|
|
642
|
+
correlation=(method, owner_id),
|
|
643
|
+
),
|
|
644
|
+
)
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
sources = (
|
|
648
|
+
owned(method, owner_id)
|
|
649
|
+
for owner_id in parent_ids
|
|
650
|
+
for method in ("example.comment.list", "example.activity.list")
|
|
651
|
+
)
|
|
652
|
+
stream = client.iter_reference_sources(sources)
|
|
653
|
+
async with stream:
|
|
654
|
+
async for event in stream:
|
|
655
|
+
if isinstance(event, ReferenceItem):
|
|
656
|
+
consume(event.correlation, event.item)
|
|
657
|
+
```
|
|
658
|
+
|
|
659
|
+
`iter_reference_source_outcomes()` additionally yields correlated failures. A valid source the
|
|
660
|
+
operation cannot run, such as a counted source under `DirectDispatch`, becomes a correlated
|
|
661
|
+
`ReferenceNotExecuted` before any request while the other sources continue.
|
|
662
|
+
|
|
501
663
|
## Streams, partial results and reports
|
|
502
664
|
|
|
503
665
|
Every multi-item operation returns an `OperationStream`. Prefer `async with`: a plain `break` does
|
|
@@ -7,8 +7,15 @@ from b24api.contracts.keyset_execution import AutoKeysetExecution, KeysetExecuti
|
|
|
7
7
|
from b24api.contracts.page import IdentityPageAdapter, PageAdapter
|
|
8
8
|
from b24api.contracts.request import IdentitySpec, RequestLike, ResultSelector, TraversalIdentity, canonical_request
|
|
9
9
|
from b24api.contracts.response import ResultCollectionShape
|
|
10
|
-
from b24api.contracts.traversal import
|
|
11
|
-
|
|
10
|
+
from b24api.contracts.traversal import (
|
|
11
|
+
ContinuationTraversal,
|
|
12
|
+
CursorSpec,
|
|
13
|
+
InclusiveWindowTraversal,
|
|
14
|
+
KeysetSpec,
|
|
15
|
+
OffsetSpec,
|
|
16
|
+
TotalTermination,
|
|
17
|
+
)
|
|
18
|
+
from b24api.traversal.facade import counted_stream, cursor_stream, declared_stream, keyset_stream, sequential_stream
|
|
12
19
|
|
|
13
20
|
if TYPE_CHECKING:
|
|
14
21
|
from b24api.contracts.identity_store import IdentityStore
|
|
@@ -191,5 +198,54 @@ class _TraversalFacade:
|
|
|
191
198
|
),
|
|
192
199
|
)
|
|
193
200
|
|
|
201
|
+
def iter_list_continuation(
|
|
202
|
+
self,
|
|
203
|
+
request: RequestLike,
|
|
204
|
+
*,
|
|
205
|
+
traversal: ContinuationTraversal,
|
|
206
|
+
policy: ExecutionPolicy | None = None,
|
|
207
|
+
page_stop: PageStopPolicy | None = None,
|
|
208
|
+
) -> OperationStream[JsonValue]:
|
|
209
|
+
"""Return a pure caller-rule continuation over SDK-owned controls."""
|
|
210
|
+
if not isinstance(traversal, ContinuationTraversal):
|
|
211
|
+
raise TypeError("traversal must be a ContinuationTraversal")
|
|
212
|
+
return self._declared(request, traversal=traversal, policy=policy, page_stop=page_stop)
|
|
213
|
+
|
|
214
|
+
def iter_list_window(
|
|
215
|
+
self,
|
|
216
|
+
request: RequestLike,
|
|
217
|
+
*,
|
|
218
|
+
traversal: InclusiveWindowTraversal,
|
|
219
|
+
policy: ExecutionPolicy | None = None,
|
|
220
|
+
page_stop: PageStopPolicy | None = None,
|
|
221
|
+
) -> OperationStream[JsonValue]:
|
|
222
|
+
"""Return a descending inclusive-timestamp window traversal with classified paging rows."""
|
|
223
|
+
if not isinstance(traversal, InclusiveWindowTraversal):
|
|
224
|
+
raise TypeError("traversal must be an InclusiveWindowTraversal")
|
|
225
|
+
return self._declared(request, traversal=traversal, policy=policy, page_stop=page_stop)
|
|
226
|
+
|
|
227
|
+
def _declared(
|
|
228
|
+
self,
|
|
229
|
+
request: RequestLike,
|
|
230
|
+
*,
|
|
231
|
+
traversal: ContinuationTraversal | InclusiveWindowTraversal,
|
|
232
|
+
policy: ExecutionPolicy | None,
|
|
233
|
+
page_stop: PageStopPolicy | None,
|
|
234
|
+
) -> OperationStream[JsonValue]:
|
|
235
|
+
self._require_open()
|
|
236
|
+
canonical = canonical_request(request)
|
|
237
|
+
audit_violation = self._audit_unknown(canonical)
|
|
238
|
+
return self._register_stream(
|
|
239
|
+
declared_stream(
|
|
240
|
+
self._executor,
|
|
241
|
+
canonical,
|
|
242
|
+
traversal=traversal,
|
|
243
|
+
policy=policy or self._default_policy,
|
|
244
|
+
deregister=self._discard_stream,
|
|
245
|
+
page_stop=page_stop,
|
|
246
|
+
audit_violations=(() if audit_violation is None else (audit_violation,)),
|
|
247
|
+
),
|
|
248
|
+
)
|
|
249
|
+
|
|
194
250
|
|
|
195
251
|
__all__: list[str] = []
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""Correlated per-command outcomes shared by the classic and the native v3 batch dialects."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
from b24api.batch.outcome import BatchCommandEvidence, BatchFailure, BatchSuccess
|
|
8
|
+
from b24api.contracts.policy import ReplayDisposition
|
|
9
|
+
from b24api.contracts.request import ReplaySafety, Request
|
|
10
|
+
from b24api.errors import B24ApiError, ProtocolError, TransportError
|
|
11
|
+
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from b24api.contracts.response import Response
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class _BatchNotExecutedError(ProtocolError):
|
|
17
|
+
"""Internal correlated marker for a fail-fast window stopped before dispatch."""
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True, slots=True)
|
|
21
|
+
class _Command:
|
|
22
|
+
index: int
|
|
23
|
+
stable_key: str
|
|
24
|
+
request: Request
|
|
25
|
+
correlation: object
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _command_failure(
|
|
29
|
+
command: _Command,
|
|
30
|
+
error: B24ApiError,
|
|
31
|
+
*,
|
|
32
|
+
evidence: BatchCommandEvidence,
|
|
33
|
+
refused: bool = False,
|
|
34
|
+
) -> BatchFailure:
|
|
35
|
+
safety = command.request.replay_safety or ReplaySafety.UNKNOWN
|
|
36
|
+
# A listed Bitrix refusal of the command, or a transport failure before dispatch, proves it did not run.
|
|
37
|
+
proven_not_run = refused or (isinstance(error, TransportError) and not error.possible_acceptance)
|
|
38
|
+
eligible = error.retryable and (safety is ReplaySafety.SAFE or proven_not_run)
|
|
39
|
+
return BatchFailure(
|
|
40
|
+
command.index,
|
|
41
|
+
command.stable_key,
|
|
42
|
+
command.request,
|
|
43
|
+
error,
|
|
44
|
+
replay_safety=safety,
|
|
45
|
+
replay_disposition=ReplayDisposition.ELIGIBLE if eligible else ReplayDisposition.NOT_ELIGIBLE,
|
|
46
|
+
correlation=command.correlation,
|
|
47
|
+
evidence=evidence,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _shared_failure(command: _Command, error: B24ApiError) -> BatchFailure:
|
|
52
|
+
return _command_failure(
|
|
53
|
+
command,
|
|
54
|
+
error,
|
|
55
|
+
evidence=BatchCommandEvidence(command.index, command.stable_key),
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _command_success(command: _Command, response: Response, evidence: BatchCommandEvidence) -> BatchSuccess:
|
|
60
|
+
return BatchSuccess._from_response( # noqa: SLF001 - trusted correlated decoder fast path
|
|
61
|
+
command.index,
|
|
62
|
+
command.stable_key,
|
|
63
|
+
command.request,
|
|
64
|
+
response,
|
|
65
|
+
command.correlation,
|
|
66
|
+
evidence,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
__all__: list[str] = []
|