fora-protocol 1.0.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
wire/names.py ADDED
@@ -0,0 +1,50 @@
1
+ """Recovering a proto field name from protojson's lowerCamelCase spelling of it.
2
+
3
+ Hand-written; not regenerated. The TypeScript twin is ``gen/ts/wire/names.ts``, and the
4
+ two are held to one answer by a shared vector set.
5
+
6
+ This lives beside the generated models rather than in the SDK because the schema seam
7
+ itself needs it: :mod:`wire.base` refuses an answer spelled in the ``json_name`` alias, and
8
+ a rule the seam depends on cannot live in a tier above the seam. The SDK re-exports it, so
9
+ there is one implementation per language rather than one per caller.
10
+
11
+ The FORA wire is snake_case proto-JSON everywhere — proto field names, the corpus, the
12
+ generated clients — and the camelCase alias is out of contract. Two places still have to
13
+ reason about it:
14
+
15
+ * Connect's error-detail ``debug`` projection IS lowerCamelCase and cannot be made
16
+ otherwise. connect-go renders it with its own protojson codec at default options, inside
17
+ a method on an unexported type, so the snake_case codec a FORA deployment registers
18
+ reaches the response body and not the error beside it. That projection is normalized
19
+ before parsing.
20
+ * A response body from a server that registered no snake_case codec is lowerCamelCase
21
+ throughout. That one is REFUSED rather than normalized: it is out of contract, and naming
22
+ it is what turns a message with every multiword field silently missing into an error.
23
+
24
+ The boundary test is ASCII ``A-Z`` and nothing else, deliberately. protojson builds
25
+ ``json_name`` by uppercasing the character after each underscore, and a proto field name is
26
+ ``[a-z_][a-z0-9_]*``, so an ASCII uppercase letter is the only boundary protojson can
27
+ produce. A broader test — ``str.isupper()``, or "not equal to its own lowercase" — answers
28
+ differently for characters protojson never emits (titlecase ``Dž`` is the plain example),
29
+ which is how three transcriptions of one rule drifted apart.
30
+
31
+ The rewrite is textual. It is sound only while protojson's spelling inverts back to every
32
+ field's name — it would not for a field like ``field_2``, whose ``json_name`` is
33
+ ``field2`` — which the conformance suite asserts for the whole contract.
34
+ """
35
+
36
+ from __future__ import annotations
37
+
38
+ _ASCII_UPPER = frozenset("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
39
+
40
+
41
+ def snake_from_json_name(name: str) -> str:
42
+ """Recover a proto field name from protojson's lowerCamelCase spelling of it."""
43
+ out: list[str] = []
44
+ for ch in name:
45
+ if ch in _ASCII_UPPER:
46
+ out.append("_")
47
+ out.append(ch.lower())
48
+ else:
49
+ out.append(ch)
50
+ return "".join(out)
wire/py.typed ADDED
File without changes
wire/unique.py ADDED
@@ -0,0 +1,12 @@
1
+ # Code generated from the FORA proto (via conformance/uniquegen). DO NOT EDIT.
2
+ # Regenerate: scripts/gen-sdk-types.sh Enforcement seam: wire/base.py
3
+ """Message -> field names whose repeated items must be unique on the wire.
4
+
5
+ Mirrors (buf.validate.field).repeated.unique. wire.base.WireModel reads this to reject a
6
+ duplicate item exactly where Go protovalidate does; the Zod client gets the same rule from
7
+ `uniqueItems` in the generated JSON Schema.
8
+ """
9
+
10
+ UNIQUE_ITEM_FIELDS: dict[str, tuple[str, ...]] = {
11
+ "ReportingPolicy": ("required_fields",),
12
+ }