b24api 2.5.2__tar.gz → 2.6.1__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.2/b24api.egg-info → b24api-2.6.1}/PKG-INFO +203 -4
- {b24api-2.5.2 → b24api-2.6.1}/README.md +202 -3
- {b24api-2.5.2 → b24api-2.6.1}/b24api/_client_traversal.py +58 -2
- {b24api-2.5.2 → b24api-2.6.1}/b24api/_diagnostics.py +21 -2
- b24api-2.6.1/b24api/batch/correlation.py +70 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/batch/engine.py +114 -91
- {b24api-2.5.2 → b24api-2.6.1}/b24api/batch/logical.py +20 -8
- {b24api-2.5.2 → b24api-2.6.1}/b24api/batch/stream.py +10 -4
- b24api-2.6.1/b24api/batch/v3.py +343 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/client.py +44 -2
- {b24api-2.5.2 → b24api-2.6.1}/b24api/completion/closure.py +13 -7
- {b24api-2.5.2 → b24api-2.6.1}/b24api/completion/fast_recorder.py +66 -30
- {b24api-2.5.2 → b24api-2.6.1}/b24api/completion/gate.py +8 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/completion/operation_stream.py +4 -1
- {b24api-2.5.2 → b24api-2.6.1}/b24api/completion/reference_recorder.py +94 -3
- {b24api-2.5.2 → b24api-2.6.1}/b24api/contracts/__init__.py +24 -1
- {b24api-2.5.2 → b24api-2.6.1}/b24api/contracts/completion.py +2 -0
- b24api-2.6.1/b24api/contracts/continuation.py +181 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/contracts/policy.py +14 -2
- {b24api-2.5.2 → b24api-2.6.1}/b24api/contracts/reference.py +8 -0
- b24api-2.6.1/b24api/contracts/reference_source.py +59 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/contracts/report.py +7 -1
- {b24api-2.5.2 → b24api-2.6.1}/b24api/contracts/request.py +8 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/contracts/response.py +43 -2
- {b24api-2.5.2 → b24api-2.6.1}/b24api/contracts/traversal.py +172 -8
- b24api-2.6.1/b24api/contracts/v3_codes.py +115 -0
- b24api-2.6.1/b24api/contracts/wire_body.py +74 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/errors.py +47 -5
- {b24api-2.5.2 → b24api-2.6.1}/b24api/execution/boundary.py +35 -1
- {b24api-2.5.2 → b24api-2.6.1}/b24api/execution/context.py +22 -1
- {b24api-2.5.2 → b24api-2.6.1}/b24api/execution/executor.py +193 -11
- {b24api-2.5.2 → b24api-2.6.1}/b24api/execution/snapshot.py +5 -1
- {b24api-2.5.2 → b24api-2.6.1}/b24api/redaction.py +18 -0
- b24api-2.6.1/b24api/references/budget_view.py +128 -0
- b24api-2.6.1/b24api/references/compatibility.py +83 -0
- b24api-2.6.1/b24api/references/counted_io.py +348 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/references/dispatch.py +246 -58
- {b24api-2.5.2 → b24api-2.6.1}/b24api/references/facade.py +111 -18
- b24api-2.6.1/b24api/references/keyset_run.py +199 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/references/outcome.py +4 -0
- b24api-2.6.1/b24api/references/program.py +95 -0
- b24api-2.6.1/b24api/references/run.py +52 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/references/scheduler.py +331 -156
- b24api-2.6.1/b24api/references/sources.py +200 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/references/stream.py +14 -4
- {b24api-2.5.2 → b24api-2.6.1}/b24api/references/support.py +3 -0
- b24api-2.6.1/b24api/references/wave_engine.py +161 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/testing/__init__.py +3 -1
- b24api-2.6.1/b24api/testing/scripted.py +290 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/transport/__init__.py +10 -1
- {b24api-2.5.2 → b24api-2.6.1}/b24api/transport/base.py +74 -0
- b24api-2.6.1/b24api/transport/disposition.py +148 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/transport/httpx.py +14 -6
- {b24api-2.5.2 → b24api-2.6.1}/b24api/transport/protocol.py +8 -4
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/__init__.py +1 -1
- b24api-2.6.1/b24api/traversal/continuation.py +173 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/control_preflight.py +40 -0
- b24api-2.6.1/b24api/traversal/counted_batch.py +355 -0
- b24api-2.6.1/b24api/traversal/counted_io.py +306 -0
- b24api-2.6.1/b24api/traversal/counted_rules.py +220 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/cursor.py +27 -9
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/driver.py +71 -13
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/facade.py +67 -5
- b24api-2.6.1/b24api/traversal/facade_support.py +94 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/identity.py +4 -0
- b24api-2.6.1/b24api/traversal/inclusive_window.py +225 -0
- b24api-2.6.1/b24api/traversal/keyset_context.py +81 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/keyset_fast_stream.py +7 -2
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/keyset_runtime.py +8 -5
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/keyset_transaction_contract.py +6 -6
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/keyset_transactions.py +2 -2
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/plans.py +97 -2
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/sequential.py +8 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/strategy_context.py +16 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/stream.py +9 -2
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/values.py +8 -11
- {b24api-2.5.2 → b24api-2.6.1/b24api.egg-info}/PKG-INFO +203 -4
- {b24api-2.5.2 → b24api-2.6.1}/b24api.egg-info/SOURCES.txt +18 -0
- b24api-2.5.2/b24api/contracts/v3_codes.py +0 -61
- b24api-2.5.2/b24api/testing/scripted.py +0 -147
- b24api-2.5.2/b24api/traversal/counted_batch.py +0 -369
- b24api-2.5.2/b24api/traversal/counted_rules.py +0 -74
- b24api-2.5.2/b24api/traversal/facade_support.py +0 -36
- {b24api-2.5.2 → b24api-2.6.1}/LICENSE +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/MANIFEST.in +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/__init__.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/_error_types.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/_sources.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/batch/__init__.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/batch/facade.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/batch/outcome.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/cli.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/cli_contract.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/completion/__init__.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/completion/recorder.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/contracts/bounded_range.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/contracts/command.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/contracts/dispatch.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/contracts/error_base.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/contracts/evidence.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/contracts/identity_store.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/contracts/json.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/contracts/keyset_capability.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/contracts/keyset_execution.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/contracts/page.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/contracts/page_stop.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/contracts/positional.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/contracts/request_summary.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/contracts/stream.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/contracts/violation.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/contracts/wire.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/encoding.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/execution/__init__.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/execution/cleanup.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/execution/failure.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/execution/lifecycle.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/execution/rate.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/execution/throttle.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/migration.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/py.typed +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/references/__init__.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/references/binding.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/references/dispatch_plan.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/references/fanout.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/settings.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/testing/_isolation.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/testing/transport.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/transport/decoding.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/transport/log_records.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/transport/logging_shield.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/counted.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/cursor_domain.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/identity_ledger.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/keyset.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/keyset_auto.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/keyset_capability.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/keyset_eligibility.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/keyset_fast_plan.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/keyset_geometry.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/keyset_observation.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/keyset_ordered_admission.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/keyset_page_validation.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/keyset_plan.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/keyset_reporting.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/keyset_step.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/keyset_verifier.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/offset_rules.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/page_adaptation.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api/traversal/sparse.py +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api.egg-info/dependency_links.txt +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api.egg-info/entry_points.txt +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api.egg-info/requires.txt +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/b24api.egg-info/top_level.txt +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/pyproject.toml +0 -0
- {b24api-2.5.2 → b24api-2.6.1}/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.1
|
|
4
4
|
Summary: Bitrix24 API
|
|
5
5
|
Author-email: Shkarupa Alex <shkarupa.alex@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -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
|
|
@@ -121,8 +127,9 @@ may already have reached Bitrix:
|
|
|
121
127
|
|
|
122
128
|
A failure that proves the request did not run is retried whatever its safety: a transport failure
|
|
123
129
|
before dispatch, or a refusal listed in `AmbiguityPolicy`, which by default is an unstructured 423, 425
|
|
124
|
-
or 429 (`refusal_http_statuses`) or a `QUERY_LIMIT_EXCEEDED` / `OPERATION_TIME_LIMIT`
|
|
125
|
-
(`refusal_api_codes`). A code or
|
|
130
|
+
or 429 (`refusal_http_statuses`) or a `QUERY_LIMIT_EXCEEDED` / `OPERATION_TIME_LIMIT` /
|
|
131
|
+
REST 3.0 `BITRIX_REST_V3_EXCEPTION_RATELIMITEXCEPTION` refusal (`refusal_api_codes`). A code or
|
|
132
|
+
status added only to `RetryPolicy` is retried for `SAFE` work alone.
|
|
126
133
|
A physical batch applies these rules to each command: after a failure, only the commands that
|
|
127
134
|
may run again are sent again, in a smaller batch, and an `UNSAFE` command of a batch that may have run
|
|
128
135
|
arrives as unknown. Replay rounds spend the same attempt and retry-time budget as the sends before
|
|
@@ -155,6 +162,42 @@ one_attempt = dataclasses.replace(ExecutionPolicy.from_settings(settings), max_a
|
|
|
155
162
|
result = await client.call(request, policy=one_attempt)
|
|
156
163
|
```
|
|
157
164
|
|
|
165
|
+
### Error codes
|
|
166
|
+
|
|
167
|
+
A structured refusal raises `ApiResponseError`. Its message, `wire_code`, `normalized_code`, `code`
|
|
168
|
+
(lower case) and `to_safe_dict()` name the server's code, so failures can be told apart:
|
|
169
|
+
|
|
170
|
+
```text
|
|
171
|
+
API error [BITRIX_REST_V3_EXCEPTION_ACCESSDENIEDEXCEPTION]: Access denied
|
|
172
|
+
API error [NOTE_EMPTY_UPDATE]: Nothing to update
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
A REST 3.0 `error.code` is shown verbatim whenever it is a snake-case identifier: upper case, such
|
|
176
|
+
as `BITRIX_REST_V3_EXCEPTION_INVALIDSELECTEXCEPTION` or `FEATURE_NOT_AVAILABLE_ON_CURRENT_PLAN`, or
|
|
177
|
+
lower case of letters only, such as `invalid_select_field`; the server's set is open, so no list is
|
|
178
|
+
kept. Error texts, classic
|
|
179
|
+
`{"error": ...}` codes and response previews keep the conservative redaction, so a long run of
|
|
180
|
+
letters and digits there still renders as `[REDACTED]`. A code that equals or contains your
|
|
181
|
+
webhook token or a credential of the request, in any letter case, is always `[REDACTED]`; one that
|
|
182
|
+
names a field of your request is shown as its `field#N` alias, or as `[REDACTED]` when only its
|
|
183
|
+
letter case differs.
|
|
184
|
+
|
|
185
|
+
Recognizing a code does not make it retryable. By default only the REST 3.0 load limits are retried,
|
|
186
|
+
after the server's `Retry-After`:
|
|
187
|
+
|
|
188
|
+
| Code | Status | Retried |
|
|
189
|
+
|---|---|---|
|
|
190
|
+
| `BITRIX_REST_V3_EXCEPTION_RATELIMITEXCEPTION` | 429 | Any direct request: the limiter refuses before the method runs. In a REST 3.0 batch envelope only `SAFE` commands, as for any structured envelope error. |
|
|
191
|
+
| `BITRIX_REST_V3_EXCEPTION_LIMITER_QUERYTIMELIMITEXCEPTION` | 503 | `SAFE` requests only: the method may have run. |
|
|
192
|
+
|
|
193
|
+
Every other REST 3.0 code is a deterministic refusal and is raised at once, including a 429 or 503
|
|
194
|
+
that a module declares for a longer-lived state (`LANDING_AI_SITE_MODERATION_BLOCK_LIMIT`,
|
|
195
|
+
`LANDING_AI_MODULE_UNAVAILABLE`). List more codes in `RetryPolicy.transient_api_codes` (and in
|
|
196
|
+
`AmbiguityPolicy.refusal_api_codes` when the code proves the method did not run). The request
|
|
197
|
+
faults `BITRIX_REST_V3_EXCEPTION_VALIDATION_REQUESTVALIDATIONEXCEPTION` and
|
|
198
|
+
`BITRIX_REST_V3_EXCEPTION_METHODNOTFOUNDEXCEPTION` in a REST 3.0 error envelope are never retried,
|
|
199
|
+
even when listed.
|
|
200
|
+
|
|
158
201
|
## Logical batch and correlation
|
|
159
202
|
|
|
160
203
|
`batch()` accepts an arbitrary-length synchronous or asynchronous command source. It consumes the
|
|
@@ -200,6 +243,36 @@ async with client.batch_outcomes(commands) as stream:
|
|
|
200
243
|
handle(outcome)
|
|
201
244
|
```
|
|
202
245
|
|
|
246
|
+
Commands whose request uses `RouteKind.API_V3` travel in native REST 3.0 batch envelopes: one JSON
|
|
247
|
+
array of at most 50 commands, never mixed with classic commands and grouped into contiguous runs of
|
|
248
|
+
one replay safety (`UNSAFE` and `UNKNOWN` share a run). Envelopes go out in input order: a classic
|
|
249
|
+
command between two v3 commands travels in its own envelope between theirs. The transport must
|
|
250
|
+
advertise JSON-array bodies, as `HttpxTransport` does; otherwise such a command fails with
|
|
251
|
+
`CapabilityError` before any request. Each array element is checked against its own request's
|
|
252
|
+
embedded-error contract, so one failed command neither fails nor resends its successful neighbours.
|
|
253
|
+
|
|
254
|
+
<!-- tested: tests/v3_batch_test.py::test_a21_wire_four_safe_v3_reads_travel_in_one_envelope_in_input_order -->
|
|
255
|
+
```python
|
|
256
|
+
from b24api import RouteKind
|
|
257
|
+
from b24api.contracts import Command
|
|
258
|
+
|
|
259
|
+
v3_commands = (
|
|
260
|
+
Command(Request("example.item.get", {"id": item_id}, ReplaySafety.SAFE, route=RouteKind.API_V3), item_id)
|
|
261
|
+
for item_id in source_ids
|
|
262
|
+
)
|
|
263
|
+
async with client.batch_outcomes(v3_commands) as stream:
|
|
264
|
+
async for outcome in stream:
|
|
265
|
+
handle(outcome)
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
REST 3.0 does not roll a batch back. When a whole envelope fails after it may have run, `SAFE`
|
|
269
|
+
commands of a transient failure get one envelope retry within their attempt budget, and commands
|
|
270
|
+
still unresolved are sent individually (`RetryPolicy.isolate_safe_batch_abort`, enabled by default)
|
|
271
|
+
under the same attempt lineage; `UNSAFE` and `UNKNOWN` commands arrive
|
|
272
|
+
as `CommandOutcomeUnknown` without a resend. The report counts `ambiguous_physical_attempts` and
|
|
273
|
+
`batch_isolation_requests`. Fail-fast `batch()` finishes resolving the envelope it already sent and
|
|
274
|
+
then raises without reading further input.
|
|
275
|
+
|
|
203
276
|
For independently dispatchable commands, use `fan_out()` or `fan_out_outcomes()` with
|
|
204
277
|
`DirectDispatch` or `BatchDispatch`. Delivery order is explicitly `READY` or `INPUT`.
|
|
205
278
|
|
|
@@ -214,8 +287,11 @@ more specialized mechanics have explicit names and explicit preconditions.
|
|
|
214
287
|
| `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
288
|
| `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
289
|
| `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. |
|
|
290
|
+
| `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. |
|
|
291
|
+
| `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
292
|
| `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
293
|
| `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. |
|
|
294
|
+
| `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
295
|
|
|
220
296
|
`page_size` is a local decoded-page cap. It is sent to Bitrix only when you provide the endpoint's
|
|
221
297
|
exact `limit_path`; the client never guesses method-specific parameter names.
|
|
@@ -347,7 +423,8 @@ contract or when the previous request-by-request behavior is required.
|
|
|
347
423
|
Static incompatibility with the auto contract raises `CapabilityError` from the
|
|
348
424
|
`iter_list_keyset(...)` call before iteration begins. A portal that accepts but contradicts the
|
|
349
425
|
declared controls fails before emission with `IncompleteTraversalError`; auto never restarts that
|
|
350
|
-
operation silently.
|
|
426
|
+
operation silently. Reference traversal can opt into the same selection for each binding; see
|
|
427
|
+
[Keyset references](#keyset-references). The
|
|
351
428
|
terminal report carries a compact `keyset_selection` (`requested_kind`, `selected_kind`, `reason`)
|
|
352
429
|
for every keyset traversal. A `page_stop` callback needs the ordered page stream, so auto reports
|
|
353
430
|
`AUTO`, `SEQUENTIAL`, `PAGE_STOP`; an explicit `SequentialKeysetExecution()` reports
|
|
@@ -429,6 +506,58 @@ stream = client.iter_list_cursor(
|
|
|
429
506
|
Cursor values must be unique and strictly monotonic. If an endpoint exposes only a non-unique
|
|
430
507
|
boundary, use an application-owned direct-call workflow or supply a unique tie-breaker.
|
|
431
508
|
|
|
509
|
+
Some message endpoints move the boundary toward older rows but return each page oldest-first.
|
|
510
|
+
Declare that page order separately with `page_order="ascending"` beside `direction="descending"` and
|
|
511
|
+
`take="first"`: rows must be strictly ordered inside the page and every value must lie beyond the
|
|
512
|
+
previous boundary. `continuation=ResponseFlagTerminal(ResultSelector(("hasNextPage",)))` closes the
|
|
513
|
+
traversal on a `False` flag, even on a non-empty page, instead of requesting an empty confirmation
|
|
514
|
+
page; a missing or non-boolean flag fails closed. An explicit global ascending or descending
|
|
515
|
+
`ConsistencyPolicy` order contradicting a reversed page order is refused before any request.
|
|
516
|
+
|
|
517
|
+
### Response-driven continuation
|
|
518
|
+
|
|
519
|
+
When the next request is fully described by the current page, `iter_list_continuation()` keeps the
|
|
520
|
+
request transaction, identity checks and terminal evidence in the client and asks a pure rule only
|
|
521
|
+
for the next control values. `ResponseCursorRule` carries a response cursor, whole and unchanged
|
|
522
|
+
(an object cursor keeps every field and its full precision), while a boolean response flag says more
|
|
523
|
+
pages exist:
|
|
524
|
+
|
|
525
|
+
<!-- tested: tests/continuation_test.py::test_a22_a_response_object_cursor_is_carried_whole_and_rule_ends_nonempty_page -->
|
|
526
|
+
```python
|
|
527
|
+
from b24api import ParameterPath, ResultSelector, RouteKind
|
|
528
|
+
from b24api.contracts import ContinuationTraversal, ResponseCursorRule, ResponseFlagTerminal
|
|
529
|
+
|
|
530
|
+
cursor_control = ParameterPath(("cursor",))
|
|
531
|
+
stream = client.iter_list_continuation(
|
|
532
|
+
Request("example.event.list", replay_safety=ReplaySafety.SAFE, route=RouteKind.BARE),
|
|
533
|
+
traversal=ContinuationTraversal(
|
|
534
|
+
selector=ResultSelector(("items",)),
|
|
535
|
+
identity=identity,
|
|
536
|
+
controls=(cursor_control,),
|
|
537
|
+
rule=ResponseCursorRule(
|
|
538
|
+
cursor_selector=ResultSelector(("cursor",)),
|
|
539
|
+
parameter_path=cursor_control,
|
|
540
|
+
terminal=ResponseFlagTerminal(ResultSelector(("hasMore",))),
|
|
541
|
+
),
|
|
542
|
+
),
|
|
543
|
+
)
|
|
544
|
+
async with stream:
|
|
545
|
+
async for item in stream:
|
|
546
|
+
consume(item)
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
A custom rule implements `evaluate(page)` and returns `ContinueWith(updates)` for exactly the
|
|
550
|
+
declared controls, or `EndOfSource()`. Rows of the page that ends the source are still delivered,
|
|
551
|
+
and the report closes with `rule_declared_end`. The client rejects updates to undeclared controls,
|
|
552
|
+
control vectors over 64 KiB and a repeated control vector with `ContinuationError`; such a failure
|
|
553
|
+
never reports the source as exhausted.
|
|
554
|
+
|
|
555
|
+
For newest-first lists that resume from an inclusive timestamp and may also return pinned rows,
|
|
556
|
+
`iter_list_window()` sends the oldest paging timestamp of each page unchanged, delivers rows
|
|
557
|
+
repeated by the overlap once and fails as non-progress, without another request, when the boundary
|
|
558
|
+
does not move. See
|
|
559
|
+
[Inclusive timestamp windows](https://github.com/shkarupa-alex/b24api/blob/master/docs/recipes.md#inclusive-timestamp-windows).
|
|
560
|
+
|
|
432
561
|
For multiple parent-bound cursor chains, `iter_cursors()` keeps cursor progress and correlation
|
|
433
562
|
isolated per binding while ready pages share the physical batch queue.
|
|
434
563
|
|
|
@@ -529,6 +658,76 @@ messages = client.iter_references(
|
|
|
529
658
|
`Binding` has no valid caller correlation, so it terminates the source with `InputSourceError`
|
|
530
659
|
rather than fabricating a reference outcome. Already accepted bindings retain their real outcomes.
|
|
531
660
|
|
|
661
|
+
### Keyset references
|
|
662
|
+
|
|
663
|
+
`KeysetTraversal` bindings run sequentially by default (`SequentialKeysetExecution()`), unlike
|
|
664
|
+
`iter_list_keyset()`, whose default is automatic. Pass `AutoKeysetExecution`,
|
|
665
|
+
`RangeKeysetExecution` or `PartitionedKeysetExecution` as the traversal's `execution` to opt in. A
|
|
666
|
+
binding with automatic, range or partitioned execution runs its own planning barrier and selection;
|
|
667
|
+
its waves travel through the shared batch queue beside other bindings' pages, and its
|
|
668
|
+
`ReferenceComplete` carries the binding's `keyset_selection` and, when the fast path ran, its
|
|
669
|
+
`keyset_execution`. From its first request to its terminal event the binding holds a fixed share of
|
|
670
|
+
`ExecutionPolicy.max_buffered_rows` and plans every wave within it; requests, pages, attempts and
|
|
671
|
+
elapsed time stay on the one operation budget. An automatic binding whose planning floor exceeds the
|
|
672
|
+
whole row budget waits to run alone with all of it (under `INPUT` delivery, once it is the next
|
|
673
|
+
binding to deliver); a binding that cannot obtain its floor while no other binding can release rows
|
|
674
|
+
fails with `BudgetExceededError`, and waiting for a share never outlasts `max_elapsed`.
|
|
675
|
+
|
|
676
|
+
Fast and automatic keyset references need `BatchDispatch`. With a `page_stop`, automatic execution
|
|
677
|
+
runs sequentially and reports `PAGE_STOP`; an explicit fast mode with a `page_stop` or
|
|
678
|
+
`DirectDispatch` is refused before any request. A `KeysetSpec.boundary` remains unavailable in
|
|
679
|
+
references.
|
|
680
|
+
|
|
681
|
+
### Counted references
|
|
682
|
+
|
|
683
|
+
`CountedTraversal` bindings read their head page and every known tail offset through the shared
|
|
684
|
+
batch queue, so one physical batch can carry pages of several bindings and the HTTP count drops
|
|
685
|
+
accordingly; each subrequest still performs its own server-side COUNT. Pages are committed in
|
|
686
|
+
offset order per binding. Counted references need `BatchDispatch` and do not accept a `page_stop`.
|
|
687
|
+
|
|
688
|
+
### Different methods in one operation
|
|
689
|
+
|
|
690
|
+
`iter_reference_sources()` accepts a lazy source of `ReferenceSource` values, each with its own
|
|
691
|
+
request template, traversal, binding and optional `page_stop`. All sources share one dispatcher,
|
|
692
|
+
row pool, `ExecutionPolicy` and terminal report, so compatible pages of different methods coalesce
|
|
693
|
+
into the same physical batch, and late sources start as capacity frees up rather than after earlier
|
|
694
|
+
sources finish. Identities and page state belong to each source: equal child IDs under different
|
|
695
|
+
sources are never conflated.
|
|
696
|
+
|
|
697
|
+
<!-- tested: tests/reference_sources_test.py::test_a28_different_templates_share_the_dispatcher_and_keep_separate_state -->
|
|
698
|
+
```python
|
|
699
|
+
from b24api import Binding, ParameterPath, ParameterUpdate, RouteKind, SequentialTraversal
|
|
700
|
+
from b24api.contracts import ReferenceItem, ReferenceSource
|
|
701
|
+
|
|
702
|
+
|
|
703
|
+
def owned(method, owner_id):
|
|
704
|
+
return ReferenceSource(
|
|
705
|
+
Request(method, replay_safety=ReplaySafety.SAFE, route=RouteKind.BARE),
|
|
706
|
+
SequentialTraversal(selector=ResultSelector(("items",)), identity=identity),
|
|
707
|
+
Binding(
|
|
708
|
+
summary=f"{method} for owner {owner_id}",
|
|
709
|
+
updates=(ParameterUpdate(ParameterPath(("filter", "OWNER_ID")), owner_id),),
|
|
710
|
+
correlation=(method, owner_id),
|
|
711
|
+
),
|
|
712
|
+
)
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
sources = (
|
|
716
|
+
owned(method, owner_id)
|
|
717
|
+
for owner_id in parent_ids
|
|
718
|
+
for method in ("example.comment.list", "example.activity.list")
|
|
719
|
+
)
|
|
720
|
+
stream = client.iter_reference_sources(sources)
|
|
721
|
+
async with stream:
|
|
722
|
+
async for event in stream:
|
|
723
|
+
if isinstance(event, ReferenceItem):
|
|
724
|
+
consume(event.correlation, event.item)
|
|
725
|
+
```
|
|
726
|
+
|
|
727
|
+
`iter_reference_source_outcomes()` additionally yields correlated failures. A valid source the
|
|
728
|
+
operation cannot run, such as a counted source under `DirectDispatch`, becomes a correlated
|
|
729
|
+
`ReferenceNotExecuted` before any request while the other sources continue.
|
|
730
|
+
|
|
532
731
|
## Streams, partial results and reports
|
|
533
732
|
|
|
534
733
|
Every multi-item operation returns an `OperationStream`. Prefer `async with`: a plain `break` does
|
|
@@ -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
|
|
@@ -90,8 +96,9 @@ may already have reached Bitrix:
|
|
|
90
96
|
|
|
91
97
|
A failure that proves the request did not run is retried whatever its safety: a transport failure
|
|
92
98
|
before dispatch, or a refusal listed in `AmbiguityPolicy`, which by default is an unstructured 423, 425
|
|
93
|
-
or 429 (`refusal_http_statuses`) or a `QUERY_LIMIT_EXCEEDED` / `OPERATION_TIME_LIMIT`
|
|
94
|
-
(`refusal_api_codes`). A code or
|
|
99
|
+
or 429 (`refusal_http_statuses`) or a `QUERY_LIMIT_EXCEEDED` / `OPERATION_TIME_LIMIT` /
|
|
100
|
+
REST 3.0 `BITRIX_REST_V3_EXCEPTION_RATELIMITEXCEPTION` refusal (`refusal_api_codes`). A code or
|
|
101
|
+
status added only to `RetryPolicy` is retried for `SAFE` work alone.
|
|
95
102
|
A physical batch applies these rules to each command: after a failure, only the commands that
|
|
96
103
|
may run again are sent again, in a smaller batch, and an `UNSAFE` command of a batch that may have run
|
|
97
104
|
arrives as unknown. Replay rounds spend the same attempt and retry-time budget as the sends before
|
|
@@ -124,6 +131,42 @@ one_attempt = dataclasses.replace(ExecutionPolicy.from_settings(settings), max_a
|
|
|
124
131
|
result = await client.call(request, policy=one_attempt)
|
|
125
132
|
```
|
|
126
133
|
|
|
134
|
+
### Error codes
|
|
135
|
+
|
|
136
|
+
A structured refusal raises `ApiResponseError`. Its message, `wire_code`, `normalized_code`, `code`
|
|
137
|
+
(lower case) and `to_safe_dict()` name the server's code, so failures can be told apart:
|
|
138
|
+
|
|
139
|
+
```text
|
|
140
|
+
API error [BITRIX_REST_V3_EXCEPTION_ACCESSDENIEDEXCEPTION]: Access denied
|
|
141
|
+
API error [NOTE_EMPTY_UPDATE]: Nothing to update
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
A REST 3.0 `error.code` is shown verbatim whenever it is a snake-case identifier: upper case, such
|
|
145
|
+
as `BITRIX_REST_V3_EXCEPTION_INVALIDSELECTEXCEPTION` or `FEATURE_NOT_AVAILABLE_ON_CURRENT_PLAN`, or
|
|
146
|
+
lower case of letters only, such as `invalid_select_field`; the server's set is open, so no list is
|
|
147
|
+
kept. Error texts, classic
|
|
148
|
+
`{"error": ...}` codes and response previews keep the conservative redaction, so a long run of
|
|
149
|
+
letters and digits there still renders as `[REDACTED]`. A code that equals or contains your
|
|
150
|
+
webhook token or a credential of the request, in any letter case, is always `[REDACTED]`; one that
|
|
151
|
+
names a field of your request is shown as its `field#N` alias, or as `[REDACTED]` when only its
|
|
152
|
+
letter case differs.
|
|
153
|
+
|
|
154
|
+
Recognizing a code does not make it retryable. By default only the REST 3.0 load limits are retried,
|
|
155
|
+
after the server's `Retry-After`:
|
|
156
|
+
|
|
157
|
+
| Code | Status | Retried |
|
|
158
|
+
|---|---|---|
|
|
159
|
+
| `BITRIX_REST_V3_EXCEPTION_RATELIMITEXCEPTION` | 429 | Any direct request: the limiter refuses before the method runs. In a REST 3.0 batch envelope only `SAFE` commands, as for any structured envelope error. |
|
|
160
|
+
| `BITRIX_REST_V3_EXCEPTION_LIMITER_QUERYTIMELIMITEXCEPTION` | 503 | `SAFE` requests only: the method may have run. |
|
|
161
|
+
|
|
162
|
+
Every other REST 3.0 code is a deterministic refusal and is raised at once, including a 429 or 503
|
|
163
|
+
that a module declares for a longer-lived state (`LANDING_AI_SITE_MODERATION_BLOCK_LIMIT`,
|
|
164
|
+
`LANDING_AI_MODULE_UNAVAILABLE`). List more codes in `RetryPolicy.transient_api_codes` (and in
|
|
165
|
+
`AmbiguityPolicy.refusal_api_codes` when the code proves the method did not run). The request
|
|
166
|
+
faults `BITRIX_REST_V3_EXCEPTION_VALIDATION_REQUESTVALIDATIONEXCEPTION` and
|
|
167
|
+
`BITRIX_REST_V3_EXCEPTION_METHODNOTFOUNDEXCEPTION` in a REST 3.0 error envelope are never retried,
|
|
168
|
+
even when listed.
|
|
169
|
+
|
|
127
170
|
## Logical batch and correlation
|
|
128
171
|
|
|
129
172
|
`batch()` accepts an arbitrary-length synchronous or asynchronous command source. It consumes the
|
|
@@ -169,6 +212,36 @@ async with client.batch_outcomes(commands) as stream:
|
|
|
169
212
|
handle(outcome)
|
|
170
213
|
```
|
|
171
214
|
|
|
215
|
+
Commands whose request uses `RouteKind.API_V3` travel in native REST 3.0 batch envelopes: one JSON
|
|
216
|
+
array of at most 50 commands, never mixed with classic commands and grouped into contiguous runs of
|
|
217
|
+
one replay safety (`UNSAFE` and `UNKNOWN` share a run). Envelopes go out in input order: a classic
|
|
218
|
+
command between two v3 commands travels in its own envelope between theirs. The transport must
|
|
219
|
+
advertise JSON-array bodies, as `HttpxTransport` does; otherwise such a command fails with
|
|
220
|
+
`CapabilityError` before any request. Each array element is checked against its own request's
|
|
221
|
+
embedded-error contract, so one failed command neither fails nor resends its successful neighbours.
|
|
222
|
+
|
|
223
|
+
<!-- tested: tests/v3_batch_test.py::test_a21_wire_four_safe_v3_reads_travel_in_one_envelope_in_input_order -->
|
|
224
|
+
```python
|
|
225
|
+
from b24api import RouteKind
|
|
226
|
+
from b24api.contracts import Command
|
|
227
|
+
|
|
228
|
+
v3_commands = (
|
|
229
|
+
Command(Request("example.item.get", {"id": item_id}, ReplaySafety.SAFE, route=RouteKind.API_V3), item_id)
|
|
230
|
+
for item_id in source_ids
|
|
231
|
+
)
|
|
232
|
+
async with client.batch_outcomes(v3_commands) as stream:
|
|
233
|
+
async for outcome in stream:
|
|
234
|
+
handle(outcome)
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
REST 3.0 does not roll a batch back. When a whole envelope fails after it may have run, `SAFE`
|
|
238
|
+
commands of a transient failure get one envelope retry within their attempt budget, and commands
|
|
239
|
+
still unresolved are sent individually (`RetryPolicy.isolate_safe_batch_abort`, enabled by default)
|
|
240
|
+
under the same attempt lineage; `UNSAFE` and `UNKNOWN` commands arrive
|
|
241
|
+
as `CommandOutcomeUnknown` without a resend. The report counts `ambiguous_physical_attempts` and
|
|
242
|
+
`batch_isolation_requests`. Fail-fast `batch()` finishes resolving the envelope it already sent and
|
|
243
|
+
then raises without reading further input.
|
|
244
|
+
|
|
172
245
|
For independently dispatchable commands, use `fan_out()` or `fan_out_outcomes()` with
|
|
173
246
|
`DirectDispatch` or `BatchDispatch`. Delivery order is explicitly `READY` or `INPUT`.
|
|
174
247
|
|
|
@@ -183,8 +256,11 @@ more specialized mechanics have explicit names and explicit preconditions.
|
|
|
183
256
|
| `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
257
|
| `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
258
|
| `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. |
|
|
259
|
+
| `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. |
|
|
260
|
+
| `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
261
|
| `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
262
|
| `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. |
|
|
263
|
+
| `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
264
|
|
|
189
265
|
`page_size` is a local decoded-page cap. It is sent to Bitrix only when you provide the endpoint's
|
|
190
266
|
exact `limit_path`; the client never guesses method-specific parameter names.
|
|
@@ -316,7 +392,8 @@ contract or when the previous request-by-request behavior is required.
|
|
|
316
392
|
Static incompatibility with the auto contract raises `CapabilityError` from the
|
|
317
393
|
`iter_list_keyset(...)` call before iteration begins. A portal that accepts but contradicts the
|
|
318
394
|
declared controls fails before emission with `IncompleteTraversalError`; auto never restarts that
|
|
319
|
-
operation silently.
|
|
395
|
+
operation silently. Reference traversal can opt into the same selection for each binding; see
|
|
396
|
+
[Keyset references](#keyset-references). The
|
|
320
397
|
terminal report carries a compact `keyset_selection` (`requested_kind`, `selected_kind`, `reason`)
|
|
321
398
|
for every keyset traversal. A `page_stop` callback needs the ordered page stream, so auto reports
|
|
322
399
|
`AUTO`, `SEQUENTIAL`, `PAGE_STOP`; an explicit `SequentialKeysetExecution()` reports
|
|
@@ -398,6 +475,58 @@ stream = client.iter_list_cursor(
|
|
|
398
475
|
Cursor values must be unique and strictly monotonic. If an endpoint exposes only a non-unique
|
|
399
476
|
boundary, use an application-owned direct-call workflow or supply a unique tie-breaker.
|
|
400
477
|
|
|
478
|
+
Some message endpoints move the boundary toward older rows but return each page oldest-first.
|
|
479
|
+
Declare that page order separately with `page_order="ascending"` beside `direction="descending"` and
|
|
480
|
+
`take="first"`: rows must be strictly ordered inside the page and every value must lie beyond the
|
|
481
|
+
previous boundary. `continuation=ResponseFlagTerminal(ResultSelector(("hasNextPage",)))` closes the
|
|
482
|
+
traversal on a `False` flag, even on a non-empty page, instead of requesting an empty confirmation
|
|
483
|
+
page; a missing or non-boolean flag fails closed. An explicit global ascending or descending
|
|
484
|
+
`ConsistencyPolicy` order contradicting a reversed page order is refused before any request.
|
|
485
|
+
|
|
486
|
+
### Response-driven continuation
|
|
487
|
+
|
|
488
|
+
When the next request is fully described by the current page, `iter_list_continuation()` keeps the
|
|
489
|
+
request transaction, identity checks and terminal evidence in the client and asks a pure rule only
|
|
490
|
+
for the next control values. `ResponseCursorRule` carries a response cursor, whole and unchanged
|
|
491
|
+
(an object cursor keeps every field and its full precision), while a boolean response flag says more
|
|
492
|
+
pages exist:
|
|
493
|
+
|
|
494
|
+
<!-- tested: tests/continuation_test.py::test_a22_a_response_object_cursor_is_carried_whole_and_rule_ends_nonempty_page -->
|
|
495
|
+
```python
|
|
496
|
+
from b24api import ParameterPath, ResultSelector, RouteKind
|
|
497
|
+
from b24api.contracts import ContinuationTraversal, ResponseCursorRule, ResponseFlagTerminal
|
|
498
|
+
|
|
499
|
+
cursor_control = ParameterPath(("cursor",))
|
|
500
|
+
stream = client.iter_list_continuation(
|
|
501
|
+
Request("example.event.list", replay_safety=ReplaySafety.SAFE, route=RouteKind.BARE),
|
|
502
|
+
traversal=ContinuationTraversal(
|
|
503
|
+
selector=ResultSelector(("items",)),
|
|
504
|
+
identity=identity,
|
|
505
|
+
controls=(cursor_control,),
|
|
506
|
+
rule=ResponseCursorRule(
|
|
507
|
+
cursor_selector=ResultSelector(("cursor",)),
|
|
508
|
+
parameter_path=cursor_control,
|
|
509
|
+
terminal=ResponseFlagTerminal(ResultSelector(("hasMore",))),
|
|
510
|
+
),
|
|
511
|
+
),
|
|
512
|
+
)
|
|
513
|
+
async with stream:
|
|
514
|
+
async for item in stream:
|
|
515
|
+
consume(item)
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
A custom rule implements `evaluate(page)` and returns `ContinueWith(updates)` for exactly the
|
|
519
|
+
declared controls, or `EndOfSource()`. Rows of the page that ends the source are still delivered,
|
|
520
|
+
and the report closes with `rule_declared_end`. The client rejects updates to undeclared controls,
|
|
521
|
+
control vectors over 64 KiB and a repeated control vector with `ContinuationError`; such a failure
|
|
522
|
+
never reports the source as exhausted.
|
|
523
|
+
|
|
524
|
+
For newest-first lists that resume from an inclusive timestamp and may also return pinned rows,
|
|
525
|
+
`iter_list_window()` sends the oldest paging timestamp of each page unchanged, delivers rows
|
|
526
|
+
repeated by the overlap once and fails as non-progress, without another request, when the boundary
|
|
527
|
+
does not move. See
|
|
528
|
+
[Inclusive timestamp windows](https://github.com/shkarupa-alex/b24api/blob/master/docs/recipes.md#inclusive-timestamp-windows).
|
|
529
|
+
|
|
401
530
|
For multiple parent-bound cursor chains, `iter_cursors()` keeps cursor progress and correlation
|
|
402
531
|
isolated per binding while ready pages share the physical batch queue.
|
|
403
532
|
|
|
@@ -498,6 +627,76 @@ messages = client.iter_references(
|
|
|
498
627
|
`Binding` has no valid caller correlation, so it terminates the source with `InputSourceError`
|
|
499
628
|
rather than fabricating a reference outcome. Already accepted bindings retain their real outcomes.
|
|
500
629
|
|
|
630
|
+
### Keyset references
|
|
631
|
+
|
|
632
|
+
`KeysetTraversal` bindings run sequentially by default (`SequentialKeysetExecution()`), unlike
|
|
633
|
+
`iter_list_keyset()`, whose default is automatic. Pass `AutoKeysetExecution`,
|
|
634
|
+
`RangeKeysetExecution` or `PartitionedKeysetExecution` as the traversal's `execution` to opt in. A
|
|
635
|
+
binding with automatic, range or partitioned execution runs its own planning barrier and selection;
|
|
636
|
+
its waves travel through the shared batch queue beside other bindings' pages, and its
|
|
637
|
+
`ReferenceComplete` carries the binding's `keyset_selection` and, when the fast path ran, its
|
|
638
|
+
`keyset_execution`. From its first request to its terminal event the binding holds a fixed share of
|
|
639
|
+
`ExecutionPolicy.max_buffered_rows` and plans every wave within it; requests, pages, attempts and
|
|
640
|
+
elapsed time stay on the one operation budget. An automatic binding whose planning floor exceeds the
|
|
641
|
+
whole row budget waits to run alone with all of it (under `INPUT` delivery, once it is the next
|
|
642
|
+
binding to deliver); a binding that cannot obtain its floor while no other binding can release rows
|
|
643
|
+
fails with `BudgetExceededError`, and waiting for a share never outlasts `max_elapsed`.
|
|
644
|
+
|
|
645
|
+
Fast and automatic keyset references need `BatchDispatch`. With a `page_stop`, automatic execution
|
|
646
|
+
runs sequentially and reports `PAGE_STOP`; an explicit fast mode with a `page_stop` or
|
|
647
|
+
`DirectDispatch` is refused before any request. A `KeysetSpec.boundary` remains unavailable in
|
|
648
|
+
references.
|
|
649
|
+
|
|
650
|
+
### Counted references
|
|
651
|
+
|
|
652
|
+
`CountedTraversal` bindings read their head page and every known tail offset through the shared
|
|
653
|
+
batch queue, so one physical batch can carry pages of several bindings and the HTTP count drops
|
|
654
|
+
accordingly; each subrequest still performs its own server-side COUNT. Pages are committed in
|
|
655
|
+
offset order per binding. Counted references need `BatchDispatch` and do not accept a `page_stop`.
|
|
656
|
+
|
|
657
|
+
### Different methods in one operation
|
|
658
|
+
|
|
659
|
+
`iter_reference_sources()` accepts a lazy source of `ReferenceSource` values, each with its own
|
|
660
|
+
request template, traversal, binding and optional `page_stop`. All sources share one dispatcher,
|
|
661
|
+
row pool, `ExecutionPolicy` and terminal report, so compatible pages of different methods coalesce
|
|
662
|
+
into the same physical batch, and late sources start as capacity frees up rather than after earlier
|
|
663
|
+
sources finish. Identities and page state belong to each source: equal child IDs under different
|
|
664
|
+
sources are never conflated.
|
|
665
|
+
|
|
666
|
+
<!-- tested: tests/reference_sources_test.py::test_a28_different_templates_share_the_dispatcher_and_keep_separate_state -->
|
|
667
|
+
```python
|
|
668
|
+
from b24api import Binding, ParameterPath, ParameterUpdate, RouteKind, SequentialTraversal
|
|
669
|
+
from b24api.contracts import ReferenceItem, ReferenceSource
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
def owned(method, owner_id):
|
|
673
|
+
return ReferenceSource(
|
|
674
|
+
Request(method, replay_safety=ReplaySafety.SAFE, route=RouteKind.BARE),
|
|
675
|
+
SequentialTraversal(selector=ResultSelector(("items",)), identity=identity),
|
|
676
|
+
Binding(
|
|
677
|
+
summary=f"{method} for owner {owner_id}",
|
|
678
|
+
updates=(ParameterUpdate(ParameterPath(("filter", "OWNER_ID")), owner_id),),
|
|
679
|
+
correlation=(method, owner_id),
|
|
680
|
+
),
|
|
681
|
+
)
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
sources = (
|
|
685
|
+
owned(method, owner_id)
|
|
686
|
+
for owner_id in parent_ids
|
|
687
|
+
for method in ("example.comment.list", "example.activity.list")
|
|
688
|
+
)
|
|
689
|
+
stream = client.iter_reference_sources(sources)
|
|
690
|
+
async with stream:
|
|
691
|
+
async for event in stream:
|
|
692
|
+
if isinstance(event, ReferenceItem):
|
|
693
|
+
consume(event.correlation, event.item)
|
|
694
|
+
```
|
|
695
|
+
|
|
696
|
+
`iter_reference_source_outcomes()` additionally yields correlated failures. A valid source the
|
|
697
|
+
operation cannot run, such as a counted source under `DirectDispatch`, becomes a correlated
|
|
698
|
+
`ReferenceNotExecuted` before any request while the other sources continue.
|
|
699
|
+
|
|
501
700
|
## Streams, partial results and reports
|
|
502
701
|
|
|
503
702
|
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] = []
|
|
@@ -14,7 +14,7 @@ import re
|
|
|
14
14
|
from collections.abc import Iterable, Mapping, Sequence
|
|
15
15
|
from typing import NoReturn
|
|
16
16
|
|
|
17
|
-
from b24api.redaction import DEFAULT_SENSITIVE_KEYS, is_secret, replace_secrets, secret_values
|
|
17
|
+
from b24api.redaction import DEFAULT_SENSITIVE_KEYS, contains_secret, is_secret, replace_secrets, secret_values
|
|
18
18
|
|
|
19
19
|
_ALIASED_PARAMETERS = frozenset({"filter", "order", "fields", "select"})
|
|
20
20
|
_SENSITIVE_NAMES = frozenset(name.casefold().replace("-", "_") for name in DEFAULT_SENSITIVE_KEYS)
|
|
@@ -29,7 +29,7 @@ _MAX_SECRET_DEPTH = 32
|
|
|
29
29
|
class DiagnosticContext:
|
|
30
30
|
"""Aliases and exact secrets of one canonical request, resolved on first use."""
|
|
31
31
|
|
|
32
|
-
__slots__ = ("_aliases", "_headers", "_parameters", "_pattern", "_secrets")
|
|
32
|
+
__slots__ = ("_aliases", "_folded_pattern", "_headers", "_parameters", "_pattern", "_secrets")
|
|
33
33
|
|
|
34
34
|
def __init__(
|
|
35
35
|
self,
|
|
@@ -42,6 +42,7 @@ class DiagnosticContext:
|
|
|
42
42
|
self._headers = tuple(headers)
|
|
43
43
|
self._aliases: dict[str, str] | None = None
|
|
44
44
|
self._pattern: re.Pattern[str] | None = None
|
|
45
|
+
self._folded_pattern: re.Pattern[str] | None = None
|
|
45
46
|
self._secrets: frozenset[str] = frozenset()
|
|
46
47
|
|
|
47
48
|
def __repr__(self) -> str:
|
|
@@ -65,6 +66,24 @@ class DiagnosticContext:
|
|
|
65
66
|
self._resolved()
|
|
66
67
|
return is_secret(value, self._secrets, ignore_case=ignore_case)
|
|
67
68
|
|
|
69
|
+
def contains_known_secret(self, text: str) -> bool:
|
|
70
|
+
"""Report whether any of the request's own exact secrets occurs in ``text``, ignoring letter case."""
|
|
71
|
+
self._resolved()
|
|
72
|
+
return contains_secret(text, self._secrets)
|
|
73
|
+
|
|
74
|
+
def aliases_text(self, text: str) -> bool:
|
|
75
|
+
"""Report whether ``text`` holds a whole declared field name, ignoring letter case.
|
|
76
|
+
|
|
77
|
+
Rendering aliases only the exact spelling; Bitrix field names are case-insensitive, so this check
|
|
78
|
+
also reports a field name the server echoed in another letter case.
|
|
79
|
+
"""
|
|
80
|
+
self._resolved()
|
|
81
|
+
if self._pattern is None:
|
|
82
|
+
return False
|
|
83
|
+
if self._folded_pattern is None:
|
|
84
|
+
self._folded_pattern = re.compile(self._pattern.pattern, re.IGNORECASE)
|
|
85
|
+
return self._folded_pattern.search(text) is not None
|
|
86
|
+
|
|
68
87
|
def replace_secrets(self, text: str) -> str:
|
|
69
88
|
"""Replace the request's own exact secrets wherever they occur."""
|
|
70
89
|
self._resolved()
|