Skip to content

Commit

Permalink
👽 Rename $pk to $primary_key
Browse files Browse the repository at this point in the history
  • Loading branch information
awtkns committed Nov 5, 2024
1 parent 3f90d84 commit 862193b
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 12 deletions.
8 changes: 4 additions & 4 deletions core/harambe_core/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ class SchemaParser:
def __init__(
self, schema: Schema, evaluator: ExpressionEvaluator | None = None
) -> None:
self._pk_expression = schema.get("$pk", None)
self._pk_expression = schema.get("$primary_key", None)

if "$schema" in schema:
del schema["$schema"]
if "$pk" in schema:
del schema["$pk"]
if "$primary_key" in schema:
del schema["$primary_key"]

if evaluator is None:
evaluator = ExpressionEvaluator()
Expand All @@ -58,7 +58,7 @@ def validate(self, data: dict[str, Any], base_url: str) -> dict[str, Any]:
try:
res = model(**data).model_dump()
if self._pk_expression:
res["$pk"] = self.evaluator.evaluate(self._pk_expression, res)
res["$primary_key"] = self.evaluator.evaluate(self._pk_expression, res)
return res

except ValidationError as validation_error:
Expand Down
2 changes: 1 addition & 1 deletion core/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "harambe-core"
version = "0.45.3"
version = "0.46.0"
description = "Core types for harambe SDK 🐒🍌"
authors = [
{ name = "Adam Watkins", email = "[email protected]" }
Expand Down
2 changes: 1 addition & 1 deletion core/test/parser/mock_schemas/computed_pk.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/reworkd/harambe/refs/heads/main/schema.json",
"$pk": "CONCAT_WS('_', resource.name, resource.link)",
"$primary_key": "CONCAT_WS('_', resource.name, resource.link)",
"resource": {
"type": "object",
"properties": {
Expand Down
5 changes: 2 additions & 3 deletions core/test/parser/test_parser_computed.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest

from harambe_core import SchemaParser
from harambe_core.errors import SchemaValidationError
from test.parser.mock_schemas.load_schema import load_schema


Expand Down Expand Up @@ -114,7 +113,7 @@ def test_nested_reference(schema, data):

def test_parser_computed_pk():
schema_ = load_schema("computed_pk")
schema_["$pk"] = "CONCAT(resource.name, '_', resource.link)"
schema_["$primary_key"] = "CONCAT(resource.name, '_', resource.link)"
data = {
"resource": {
"name": "API Documentation",
Expand All @@ -124,7 +123,7 @@ def test_parser_computed_pk():

validator = SchemaParser(schema_)
output_data = validator.validate(data, base_url="http://example.com")
assert output_data["$pk"] == "API Documentation_https://reworkd.ai/docs"
assert output_data["$primary_key"] == "API Documentation_https://reworkd.ai/docs"


def test_computed_on_nullable_field(schema, data):
Expand Down
2 changes: 1 addition & 1 deletion schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
"$schema": {
"type": "string"
},
"$pk": {
"$primary_key": {
"type": "string",
"description": "Primary key expression override"
}
Expand Down
4 changes: 2 additions & 2 deletions sdk/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[project]
name = "harambe-sdk"
version = "0.45.3"
version = "0.46.0"
description = "Data extraction SDK for Playwright 🐒🍌"
authors = [
{ name = "Adam Watkins", email = "[email protected]" }
]
requires-python = ">=3.11,<4.0"
readme = "README.md"
dependencies = [
"harambe_core==0.45.3",
"harambe_core==0.46.0",
"pydantic==2.9.2",
"playwright==1.47.0",
"setuptools==73.0.0",
Expand Down

0 comments on commit 862193b

Please sign in to comment.