omnibase_infra 0.3.0__py3-none-any.whl → 0.3.1__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.
@@ -76,7 +76,7 @@ See Also
76
76
  - Runtime kernel: omnibase_infra.runtime.service_kernel
77
77
  """
78
78
 
79
- __version__ = "0.3.0"
79
+ __version__ = "0.3.1"
80
80
 
81
81
  from . import (
82
82
  enums,
@@ -125,7 +125,10 @@ logger = logging.getLogger(__name__)
125
125
  #
126
126
  # =============================================================================
127
127
  _ORDER_BY_PATTERN = re.compile(r"\bORDER\s+BY\b", re.IGNORECASE)
128
- _LIMIT_PATTERN = re.compile(r"\bLIMIT\s+(\d+)\b", re.IGNORECASE)
128
+ # Pattern to detect numeric LIMIT for validation (e.g., LIMIT 100)
129
+ _LIMIT_NUMERIC_PATTERN = re.compile(r"\bLIMIT\s+(\d+)\b", re.IGNORECASE)
130
+ # Pattern to detect parameterized LIMIT (e.g., LIMIT $1) - cannot validate at build time
131
+ _LIMIT_PARAM_PATTERN = re.compile(r"\bLIMIT\s+\$\d+\b", re.IGNORECASE)
129
132
 
130
133
 
131
134
  class PostgresRepositoryRuntime:
@@ -392,6 +395,11 @@ class PostgresRepositoryRuntime:
392
395
  - If no ORDER BY and PK declared: inject ORDER BY {pk}
393
396
  - If no ORDER BY and no PK: HARD ERROR
394
397
 
398
+ When injecting ORDER BY, the clause is inserted BEFORE any existing
399
+ LIMIT clause to produce valid SQL. For example:
400
+ - Input: "SELECT * FROM users LIMIT $1"
401
+ - Output: "SELECT * FROM users ORDER BY id LIMIT $1"
402
+
395
403
  Args:
396
404
  sql: The SQL query to potentially modify.
397
405
  op_name: Operation name for error context.
@@ -423,7 +431,21 @@ class PostgresRepositoryRuntime:
423
431
 
424
432
  # Inject ORDER BY using configured order or just PK
425
433
  order_by = self._config.default_order_by or pk_column
426
- return f"{sql.rstrip().rstrip(';')} ORDER BY {order_by}"
434
+
435
+ # Check if LIMIT exists - ORDER BY must be inserted BEFORE LIMIT
436
+ param_match = _LIMIT_PARAM_PATTERN.search(sql)
437
+ numeric_match = _LIMIT_NUMERIC_PATTERN.search(sql)
438
+ limit_match = param_match or numeric_match
439
+
440
+ if limit_match:
441
+ # Insert ORDER BY before LIMIT
442
+ limit_start = limit_match.start()
443
+ return (
444
+ f"{sql[:limit_start].rstrip()} ORDER BY {order_by} {sql[limit_start:]}"
445
+ )
446
+ else:
447
+ # No LIMIT, append at end
448
+ return f"{sql.rstrip().rstrip(';')} ORDER BY {order_by}"
427
449
 
428
450
  def _inject_limit(
429
451
  self,
@@ -434,9 +456,10 @@ class PostgresRepositoryRuntime:
434
456
  """Inject or validate LIMIT clause for multi-row results.
435
457
 
436
458
  Rules:
437
- - If LIMIT > max_row_limit: HARD ERROR
459
+ - If parameterized LIMIT (e.g., $1): OK (no change, can't validate at build time)
460
+ - If numeric LIMIT > max_row_limit: HARD ERROR
461
+ - If numeric LIMIT <= max_row_limit: OK (no change)
438
462
  - If no LIMIT: inject LIMIT {max_row_limit}
439
- - If LIMIT <= max_row_limit: OK (no change)
440
463
 
441
464
  Args:
442
465
  sql: The SQL query to potentially modify.
@@ -447,13 +470,18 @@ class PostgresRepositoryRuntime:
447
470
  SQL with LIMIT clause (injected or original).
448
471
 
449
472
  Raises:
450
- RepositoryContractError: LIMIT exceeds max_row_limit.
473
+ RepositoryContractError: Numeric LIMIT exceeds max_row_limit.
451
474
  """
452
475
  max_limit = self._config.max_row_limit
453
- limit_match = _LIMIT_PATTERN.search(sql)
454
476
 
477
+ # Check for parameterized LIMIT (e.g., LIMIT $1) - can't validate at build time
478
+ if _LIMIT_PARAM_PATTERN.search(sql):
479
+ return sql
480
+
481
+ # Check for numeric LIMIT (e.g., LIMIT 100) - can validate
482
+ limit_match = _LIMIT_NUMERIC_PATTERN.search(sql)
455
483
  if limit_match:
456
- # Existing LIMIT - validate it
484
+ # Existing numeric LIMIT - validate it
457
485
  existing_limit = int(limit_match.group(1))
458
486
  if existing_limit > max_limit:
459
487
  raise RepositoryContractError(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: omnibase_infra
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: ONEX Infrastructure - Service integration and database infrastructure tools
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -1,4 +1,4 @@
1
- omnibase_infra/__init__.py,sha256=GaHfYUvSgKlKfO2_asrsWp0245bbZP91s5O__WZPkHI,3853
1
+ omnibase_infra/__init__.py,sha256=cUEvzmpkZWPGbrKvpI3JpMQ4HjR_YEF_9gOZePu-AQQ,3853
2
2
  omnibase_infra/adapters/adapter_onex_tool_execution.py,sha256=gKiRTr3pc7-DNAS9_bSmLWssOr1FDCiciwE16cQF3Ro,15377
3
3
  omnibase_infra/capabilities/__init__.py,sha256=O6qQjWNwe0ZQt5hpGMMLx4CgagdpxBJzMGVpowi8eKY,462
4
4
  omnibase_infra/capabilities/capability_inference_rules.py,sha256=2VDLhvBlDOYyi1eCQGSNB8eXf2JQ4cG9Xftsb3P2xm0,8166
@@ -639,7 +639,7 @@ omnibase_infra/runtime/contract_loaders/operation_bindings_loader.py,sha256=TaOs
639
639
  omnibase_infra/runtime/db/__init__.py,sha256=WZLFf7XIXAefkUIiA1sg3Npw120P9zaqK6862mq7wgM,2380
640
640
  omnibase_infra/runtime/db/models/__init__.py,sha256=ENQ696584GQHSvbVN85PgEo3Agij5Oo10Vz7-FoVYBE,1377
641
641
  omnibase_infra/runtime/db/models/model_repository_runtime_config.py,sha256=4X231FUSe8UywlFIhb4cuyEBk2G0FiJP7-X5-f8Zop0,7826
642
- omnibase_infra/runtime/db/postgres_repository_runtime.py,sha256=74M8qR6We7DitPwstrFosJiiWXyjBpeVsfn4IXxuo2Q,20297
642
+ omnibase_infra/runtime/db/postgres_repository_runtime.py,sha256=cijrpfrK1vwt6RqqHIi1PTfqPxfQ3IQT82dDx4eGQAE,21673
643
643
  omnibase_infra/runtime/dispatch_context_enforcer.py,sha256=44McRbtsqkGTiz7dQTOtV4AmisYOlVKKhI_1n5Jwziw,16620
644
644
  omnibase_infra/runtime/emit_daemon/__init__.py,sha256=wnc8rcQCu0vO10y8uqgoEFUsBbYQsJJiKYrJoLgEhsU,3012
645
645
  omnibase_infra/runtime/emit_daemon/cli.py,sha256=KP0h3f_cfmNcH-lsVl8rWc-m4Xlhuc0yN5VnNtvNM68,26117
@@ -884,8 +884,8 @@ omnibase_infra/validation/validator_routing_coverage.py,sha256=51vYEi5NhU6wqohk2
884
884
  omnibase_infra/validation/validator_runtime_shape.py,sha256=9Xl37_dNDinT7nr-BoJ9fG3O5cT1_j6N-C7bojwQi3g,39033
885
885
  omnibase_infra/validation/validator_security.py,sha256=Yn_kwxBtPzEj1GzrW0OafL-bR-FgoqdeFzseQqF2_B8,20622
886
886
  omnibase_infra/validation/validator_topic_category.py,sha256=1y6STpSNIJsE2AmX5f8PVzPuOfoQmedgocSbEqOdtrM,48798
887
- omnibase_infra-0.3.0.dist-info/METADATA,sha256=0N0aDXnWUfwLdAWoj6ivITqhPj681TUwj9salQS_Ens,7554
888
- omnibase_infra-0.3.0.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
889
- omnibase_infra-0.3.0.dist-info/entry_points.txt,sha256=8jORmczvjPYrahcGRwxtuVqh8KIFOfb04GgnRnQfNsQ,166
890
- omnibase_infra-0.3.0.dist-info/licenses/LICENSE,sha256=CwYWppeN0neFHYdbbUdHbR4_PiyTYnmk6ufFWuVsL7I,1070
891
- omnibase_infra-0.3.0.dist-info/RECORD,,
887
+ omnibase_infra-0.3.1.dist-info/METADATA,sha256=Y2H_CE7DKXZubx6YDg4IIwvUG1cYsMuB0uJ1sAb7CEI,7554
888
+ omnibase_infra-0.3.1.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
889
+ omnibase_infra-0.3.1.dist-info/entry_points.txt,sha256=8jORmczvjPYrahcGRwxtuVqh8KIFOfb04GgnRnQfNsQ,166
890
+ omnibase_infra-0.3.1.dist-info/licenses/LICENSE,sha256=CwYWppeN0neFHYdbbUdHbR4_PiyTYnmk6ufFWuVsL7I,1070
891
+ omnibase_infra-0.3.1.dist-info/RECORD,,