api-foundry 0.8.1__tar.gz → 0.8.2__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: api-foundry
3
- Version: 0.8.1
3
+ Version: 0.8.2
4
4
  Summary: The `api_foundry` project is a powerful tool designed to automate the deployment of REST APIs on AWS using Lambda services to access and interact with relational databases (RDBMS). This project leverages the OpenAPI specification to define and manage the APIs
5
5
  Project-URL: Documentation, https://github.com/DanRepik/api-foundry
6
6
  Project-URL: Source, https://github.com/DanRepik/api-foundry
@@ -124,6 +124,9 @@ class SchemaObjectProperty(OpenAPIElement):
124
124
  self.key_type = None
125
125
  self.sequence_name = None
126
126
  self.concurrency_control = self._concurrency_control(schema_name, prop)
127
+ # Value injection attributes
128
+ self.inject_value = prop.get("x-af-inject-value", None)
129
+ self.inject_on = self._parse_inject_on(name, prop) or None
127
130
  # For embedded objects/arrays
128
131
  self.sub_properties: Optional[Dict[str, SchemaObjectProperty]] = None
129
132
  self.items_sub_properties: Optional[Dict[str, SchemaObjectProperty]] = None
@@ -143,6 +146,47 @@ class SchemaObjectProperty(OpenAPIElement):
143
146
  )
144
147
  return concurrency_control
145
148
 
149
+ def _parse_inject_on(self, property_name: str, prop_dict: dict) -> list[str]:
150
+ """
151
+ Parse x-af-inject-on attribute or infer default behavior based on
152
+ property name and x-af-inject-value presence.
153
+ """
154
+ inject_value = prop_dict.get("x-af-inject-value")
155
+ if not inject_value:
156
+ return []
157
+
158
+ # Explicit configuration takes precedence
159
+ if "x-af-inject-on" in prop_dict:
160
+ inject_on = prop_dict["x-af-inject-on"]
161
+ if isinstance(inject_on, list):
162
+ return inject_on
163
+ return [inject_on]
164
+
165
+ # Infer from property name patterns
166
+ # Properties starting with "created" default to create-only
167
+ if property_name.startswith("created_"):
168
+ return ["create"]
169
+
170
+ # Properties starting with "updated" default to update-only
171
+ if property_name.startswith("updated_"):
172
+ return ["update"]
173
+
174
+ # Properties ending with "_by" or "_at" default to create-only
175
+ if property_name.endswith(("_by", "_at")):
176
+ return ["create"]
177
+
178
+ # Tenant/owner fields default to create-only (immutable)
179
+ if property_name in [
180
+ "tenant_id",
181
+ "owner_id",
182
+ "organization_id",
183
+ "workspace_id",
184
+ ]:
185
+ return ["create"]
186
+
187
+ # Default: inject only on create for safety
188
+ return ["create"]
189
+
146
190
 
147
191
  class SchemaObjectKey(SchemaObjectProperty):
148
192
  """Represents a primary key in a schema object."""
@@ -206,6 +250,7 @@ class SchemaObject(OpenAPIElement):
206
250
  self.relations = self._resolve_relations(schema_object)
207
251
  self.concurrency_property = self._get_concurrency_property(schema_object)
208
252
  self.permissions = self._get_permissions(schema_object)
253
+ self.inject_properties = self._get_inject_properties()
209
254
 
210
255
  def _get_table_name(self, schema_object: dict) -> str:
211
256
  schema = schema_object.get("x-af-schema")
@@ -380,6 +425,21 @@ class SchemaObject(OpenAPIElement):
380
425
  validate_permissions(normalized)
381
426
  return normalized or {}
382
427
 
428
+ def _get_inject_properties(self) -> dict:
429
+ """
430
+ Collect all properties that have injection attributes.
431
+
432
+ Returns a dictionary mapping property names to their injection metadata.
433
+ """
434
+ inject_props = {}
435
+ for prop_name, prop in self.properties.items():
436
+ if hasattr(prop, "inject_value") and prop.inject_value:
437
+ inject_props[prop_name] = {
438
+ "inject_value": prop.inject_value,
439
+ "inject_on": getattr(prop, "inject_on", ["create"]),
440
+ }
441
+ return inject_props
442
+
383
443
  def to_dict(self) -> Dict[str, Any]:
384
444
  """Recursively convert this schema object and its properties."""
385
445
  data = super().to_dict()
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "api-foundry"
7
- version = "0.8.1"
7
+ version = "0.8.2"
8
8
  authors = [
9
9
  { name="Daniel Repik", email="danrepik@icloud.com" },
10
10
  ]
File without changes
File without changes