macss-modular-api-postgres 0.5.0__tar.gz → 0.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: macss-modular-api-postgres
3
- Version: 0.5.0
3
+ Version: 0.6.0
4
4
  Summary: Official MACSS Postgres integration package for Python.
5
5
  Author: ccisne.dev
6
6
  License-Expression: MIT
@@ -56,10 +56,12 @@ else:
56
56
 
57
57
  See [example/example.py](example/example.py) for a complete in-memory wiring sample.
58
58
 
59
- ## Current slice
59
+ ## What this package provides
60
60
 
61
61
  - normalized Postgres connection defaults and redacted summaries
62
62
  - engine-agnostic `DbClient`, `DbRepository`, and transaction contracts
63
63
  - explicit lease ownership semantics for package-owned and application-owned sessions
64
64
  - health contributor and GraphQL support bundle for higher-level integrations
65
- - real driver bindings intentionally remain outside this first slice
65
+ - the application supplies the driver binding (adapter) for its chosen engine and driver
66
+
67
+ This package is **contracts-only by design** and will never ship a driver binding; you choose your engine and driver and provide the adapter. See [ADR-0004](../../../docs/adr/0004-contracts-only-database-packages.md).
@@ -32,10 +32,12 @@ else:
32
32
 
33
33
  See [example/example.py](example/example.py) for a complete in-memory wiring sample.
34
34
 
35
- ## Current slice
35
+ ## What this package provides
36
36
 
37
37
  - normalized Postgres connection defaults and redacted summaries
38
38
  - engine-agnostic `DbClient`, `DbRepository`, and transaction contracts
39
39
  - explicit lease ownership semantics for package-owned and application-owned sessions
40
40
  - health contributor and GraphQL support bundle for higher-level integrations
41
- - real driver bindings intentionally remain outside this first slice
41
+ - the application supplies the driver binding (adapter) for its chosen engine and driver
42
+
43
+ This package is **contracts-only by design** and will never ship a driver binding; you choose your engine and driver and provide the adapter. See [ADR-0004](../../../docs/adr/0004-contracts-only-database-packages.md).
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "macss-modular-api-postgres"
7
- version = "0.5.0"
7
+ version = "0.6.0"
8
8
  description = "Official MACSS Postgres integration package for Python."
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: macss-modular-api-postgres
3
- Version: 0.5.0
3
+ Version: 0.6.0
4
4
  Summary: Official MACSS Postgres integration package for Python.
5
5
  Author: ccisne.dev
6
6
  License-Expression: MIT
@@ -56,10 +56,12 @@ else:
56
56
 
57
57
  See [example/example.py](example/example.py) for a complete in-memory wiring sample.
58
58
 
59
- ## Current slice
59
+ ## What this package provides
60
60
 
61
61
  - normalized Postgres connection defaults and redacted summaries
62
62
  - engine-agnostic `DbClient`, `DbRepository`, and transaction contracts
63
63
  - explicit lease ownership semantics for package-owned and application-owned sessions
64
64
  - health contributor and GraphQL support bundle for higher-level integrations
65
- - real driver bindings intentionally remain outside this first slice
65
+ - the application supplies the driver binding (adapter) for its chosen engine and driver
66
+
67
+ This package is **contracts-only by design** and will never ship a driver binding; you choose your engine and driver and provide the adapter. See [ADR-0004](../../../docs/adr/0004-contracts-only-database-packages.md).
@@ -14,6 +14,9 @@ from .db_client import (
14
14
  DbHealthContributor,
15
15
  DbHealthReport,
16
16
  DbHealthStatus,
17
+ DbParameter,
18
+ DbParameterDirection,
19
+ DbProcedureOutcome,
17
20
  DbProviderDescription,
18
21
  DbRepository,
19
22
  DbRepositoryContext,
@@ -40,6 +43,9 @@ __all__ = [
40
43
  "DbHealthContributor",
41
44
  "DbHealthReport",
42
45
  "DbHealthStatus",
46
+ "DbParameter",
47
+ "DbParameterDirection",
48
+ "DbProcedureOutcome",
43
49
  "DbProviderDescription",
44
50
  "DbRepository",
45
51
  "DbRepositoryContext",
@@ -17,6 +17,13 @@ class DbCommandKind(str, Enum):
17
17
  EXECUTE = "execute"
18
18
  BATCH = "batch"
19
19
  SCALAR = "scalar"
20
+ PROCEDURE = "procedure"
21
+
22
+
23
+ class DbParameterDirection(str, Enum):
24
+ INPUT = "input"
25
+ OUTPUT = "output"
26
+ INPUT_OUTPUT = "inputOutput"
20
27
 
21
28
 
22
29
  class DbFailureKind(str, Enum):
@@ -81,6 +88,39 @@ class DbConnectionSettings:
81
88
  )
82
89
 
83
90
 
91
+ @dataclass(frozen=True, slots=True)
92
+ class DbParameter:
93
+ name: str
94
+ value: object | None = None
95
+ direction: DbParameterDirection = DbParameterDirection.INPUT
96
+ type_hint: str | None = None
97
+
98
+ @classmethod
99
+ def input(cls, name: str, value: object | None, type_hint: str | None = None) -> DbParameter:
100
+ return cls(name=name, value=value, direction=DbParameterDirection.INPUT, type_hint=type_hint)
101
+
102
+ @classmethod
103
+ def output(cls, name: str, type_hint: str | None = None) -> DbParameter:
104
+ return cls(name=name, direction=DbParameterDirection.OUTPUT, type_hint=type_hint)
105
+
106
+ @classmethod
107
+ def input_output(
108
+ cls, name: str, value: object | None, type_hint: str | None = None
109
+ ) -> DbParameter:
110
+ return cls(
111
+ name=name,
112
+ value=value,
113
+ direction=DbParameterDirection.INPUT_OUTPUT,
114
+ type_hint=type_hint,
115
+ )
116
+
117
+
118
+ @dataclass(frozen=True, slots=True)
119
+ class DbProcedureOutcome:
120
+ return_value: object | None = None
121
+ output_parameters: Mapping[str, object] | None = None
122
+
123
+
84
124
  @dataclass(frozen=True, slots=True)
85
125
  class DbCommand:
86
126
  kind: DbCommandKind
@@ -101,12 +141,14 @@ class DbExecutionMetadata:
101
141
  class DbRowSet:
102
142
  rows: list[Mapping[str, object]]
103
143
  metadata: DbExecutionMetadata
144
+ procedure: DbProcedureOutcome | None = None
104
145
 
105
146
 
106
147
  @dataclass(frozen=True, slots=True)
107
148
  class DbExecutionSummary:
108
149
  affected_count: int
109
150
  metadata: DbExecutionMetadata
151
+ procedure: DbProcedureOutcome | None = None
110
152
 
111
153
 
112
154
  @dataclass(frozen=True, slots=True)
@@ -16,6 +16,9 @@ from modular_api_postgres import (
16
16
  DbGraphqlSupport,
17
17
  DbHealthContributor,
18
18
  DbHealthStatus,
19
+ DbParameter,
20
+ DbParameterDirection,
21
+ DbProcedureOutcome,
19
22
  DbProviderDescription,
20
23
  DbRepository,
21
24
  DbRepositoryContext,
@@ -475,4 +478,98 @@ class _UserStatsRepository(DbRepository[str]):
475
478
  label="users.count",
476
479
  )
477
480
  )
478
- return result.map(lambda value: int(value.value))
481
+ return result.map(lambda value: int(value.value))
482
+
483
+
484
+ # --- 0.6.0: typed parameters and stored-procedure support ---
485
+
486
+
487
+ def test_db_parameter_input_captures_name_value_and_optional_type_hint() -> None:
488
+ plain = DbParameter.input("id", 42)
489
+ assert plain.name == "id"
490
+ assert plain.value == 42
491
+ assert plain.direction is DbParameterDirection.INPUT
492
+ assert plain.type_hint is None
493
+
494
+ hinted = DbParameter.input("payload", b"\x01\x02\x03", "bytea")
495
+ assert hinted.direction is DbParameterDirection.INPUT
496
+ assert hinted.type_hint == "bytea"
497
+
498
+
499
+ def test_db_parameter_output_carries_no_input_value_and_defaults_direction() -> None:
500
+ out = DbParameter.output("total", "integer")
501
+ assert out.name == "total"
502
+ assert out.value is None
503
+ assert out.direction is DbParameterDirection.OUTPUT
504
+ assert out.type_hint == "integer"
505
+
506
+
507
+ def test_db_parameter_input_output_marks_bidirectional_parameters() -> None:
508
+ io = DbParameter.input_output("counter", 1, "integer")
509
+ assert io.direction is DbParameterDirection.INPUT_OUTPUT
510
+ assert io.value == 1
511
+
512
+
513
+ def test_db_parameter_defaults_direction_to_input_when_constructed_directly() -> None:
514
+ param = DbParameter(name="name", value="foto.jpg")
515
+ assert param.direction is DbParameterDirection.INPUT
516
+
517
+
518
+ def test_db_parameter_flows_through_db_command_parameters_unchanged() -> None:
519
+ command = DbCommand(
520
+ kind=DbCommandKind.PROCEDURE,
521
+ text="fn_eliminar_foto",
522
+ parameters=(DbParameter.input("nombre", "foto.jpg"), "positional-still-allowed"),
523
+ )
524
+ assert len(command.parameters) == 2
525
+ assert isinstance(command.parameters[0], DbParameter)
526
+ assert command.parameters[0].name == "nombre"
527
+ assert command.parameters[1] == "positional-still-allowed"
528
+
529
+
530
+ def test_db_command_kind_exposes_procedure() -> None:
531
+ assert DbCommandKind.PROCEDURE.value == "procedure"
532
+
533
+
534
+ def test_db_procedure_outcome_carries_return_value_and_output_parameters() -> None:
535
+ outcome = DbProcedureOutcome(return_value=0, output_parameters={"total": 5})
536
+ assert outcome.return_value == 0
537
+ assert outcome.output_parameters == {"total": 5}
538
+
539
+
540
+ def test_db_procedure_outcome_allows_both_fields_to_be_absent() -> None:
541
+ empty = DbProcedureOutcome()
542
+ assert empty.return_value is None
543
+ assert empty.output_parameters is None
544
+
545
+
546
+ def test_db_procedure_outcome_attaches_optionally_to_db_row_set() -> None:
547
+ without_outcome = DbRowSet(
548
+ rows=[{"id": 1}],
549
+ metadata=DbExecutionMetadata(duration=1),
550
+ )
551
+ assert without_outcome.procedure is None
552
+
553
+ with_outcome = DbRowSet(
554
+ rows=[{"id": 1}],
555
+ metadata=DbExecutionMetadata(duration=1),
556
+ procedure=DbProcedureOutcome(return_value=0),
557
+ )
558
+ assert with_outcome.procedure is not None
559
+ assert with_outcome.procedure.return_value == 0
560
+
561
+
562
+ def test_db_procedure_outcome_attaches_optionally_to_db_execution_summary() -> None:
563
+ without_outcome = DbExecutionSummary(
564
+ affected_count=1,
565
+ metadata=DbExecutionMetadata(duration=1),
566
+ )
567
+ assert without_outcome.procedure is None
568
+
569
+ with_outcome = DbExecutionSummary(
570
+ affected_count=1,
571
+ metadata=DbExecutionMetadata(duration=1),
572
+ procedure=DbProcedureOutcome(output_parameters={"id": 99}),
573
+ )
574
+ assert with_outcome.procedure is not None
575
+ assert with_outcome.procedure.output_parameters == {"id": 99}
@@ -3,7 +3,16 @@ from __future__ import annotations
3
3
  import json
4
4
  from pathlib import Path
5
5
 
6
- from modular_api_postgres import DbConnectionSettings, DbFailure, DbFailureKind, DbResult
6
+ from modular_api_postgres import (
7
+ DbCommand,
8
+ DbCommandKind,
9
+ DbConnectionSettings,
10
+ DbFailure,
11
+ DbFailureKind,
12
+ DbParameter,
13
+ DbProcedureOutcome,
14
+ DbResult,
15
+ )
7
16
 
8
17
 
9
18
  def _load_fixture() -> dict[str, object]:
@@ -65,4 +74,45 @@ def test_matches_the_shared_db_result_fixture() -> None:
65
74
  )
66
75
  )
67
76
 
68
- assert mapped_failure.failure.code == result_fixture["wrappedFailureCode"]
77
+ assert mapped_failure.failure.code == result_fixture["wrappedFailureCode"]
78
+
79
+
80
+ def test_matches_the_shared_typed_parameter_and_stored_procedure_fixture() -> None:
81
+ command_fixture = _load_fixture()["command"]
82
+ input_fixture = command_fixture["inputParameter"]
83
+
84
+ input_parameter = DbParameter.input(
85
+ input_fixture["name"], input_fixture["value"], input_fixture["typeHint"]
86
+ )
87
+ assert input_parameter.name == input_fixture["name"]
88
+ assert input_parameter.value == input_fixture["value"]
89
+ assert input_parameter.type_hint == input_fixture["typeHint"]
90
+ assert input_parameter.direction.value == input_fixture["expectedDirection"]
91
+
92
+ output_fixture = command_fixture["outputParameter"]
93
+ output_parameter = DbParameter.output(output_fixture["name"], output_fixture["typeHint"])
94
+ assert output_parameter.value is None
95
+ assert output_parameter.direction.value == output_fixture["expectedDirection"]
96
+
97
+ command = DbCommand(
98
+ kind=DbCommandKind.PROCEDURE,
99
+ text=command_fixture["procedureName"],
100
+ parameters=(input_parameter,),
101
+ )
102
+ assert command.kind.value == "procedure"
103
+ assert command.text == command_fixture["procedureName"]
104
+ assert isinstance(command.parameters[0], DbParameter)
105
+
106
+ outcome_fixture = command_fixture["outcome"]
107
+ outcome = DbProcedureOutcome(
108
+ return_value=outcome_fixture["returnValue"],
109
+ output_parameters={
110
+ outcome_fixture["outputParameterName"]: outcome_fixture["outputParameterValue"]
111
+ },
112
+ )
113
+ assert outcome.return_value == outcome_fixture["returnValue"]
114
+ assert outcome.output_parameters is not None
115
+ assert (
116
+ outcome.output_parameters[outcome_fixture["outputParameterName"]]
117
+ == outcome_fixture["outputParameterValue"]
118
+ )