This commit is contained in:
2025-08-20 04:15:43 +02:00
parent 6b9f0cf291
commit e4bb201181
95 changed files with 194 additions and 907 deletions

View File

@@ -0,0 +1,38 @@
from pydantic import BaseModel, Field
from typing import Dict, Any, Type, TypeVar
from heroscript.heroscript import *
class User(BaseModel, HeroScriptMixin):
oid: str = Field()
name: str = Field(min_length=2, description="Chosen name by user", example="myname")
city: str = Field()
age: int = Field()
description: str = Field()
# Example usage
u1 = User(oid="abc123", name="John", age=30, city="New York",
description="""
this is a multiline
we need to remove the
this will stay 4 chars in
end
""")
myheroscript = u1.heroscript()
print(myheroscript)
u2 = User.from_heroscript(heroscript=myheroscript)
myprint(u2)
# p1 = Product(id=1, name="Phone", price=999.99, description="A smart phone")
# product_heroscript = p1.heroscript()
# print(product_heroscript)
# p2 = Product.from_heroscript(product_heroscript)
# print(p2)

View File

@@ -0,0 +1,78 @@
from pydantic import BaseModel, Field
from typing import Dict, Any, Type, TypeVar, List
from heroscript.heroscript import *
class Comment(BaseModel):
description: str = Field(default="")
class HeroBase(BaseModel, HeroScriptMixin):
oid: str = Field(default="",metadata={"unique": True})
name: str = Field(min_length=2, description="Chosen name by user", example="myname",metadata={"unique": True})
comments: List[Comment] = Field(..., description="Comment which can be attached to obj")
class User(HeroBase):
city: str = Field(metadata={"index": True})
age: int = Field(metadata={"index": True})
description: str = Field(default="")
class Product(BaseModel, HeroScriptMixin):
id: int = Field(default="",metadata={"unique": True})
name: str = Field(metadata={"unique": True})
price: float = Field()
description: str = Field()
myheroscript="""
```hero
!!user.define
oid:abc123
name:John
description:'
this is a multiline
we need to remove the
this will stay 4 chars in
end
'
age:30
city:'New York'
!!product.define
id:33
name:aproduct
description:'
this is a multiline
we need to remove the
this will stay 4 chars in
end
'
price:10.0
```
"""
# hs=HeroScripts(class_types={"user":User,"product":Product},content=myheroscript)
mypath="~/code/git.threefold.info/tfgrid/hero_research/hero/osis/heroscript/example"
hs=HeroScripts(class_types={"user":User,"product":Product},path=mypath)
objs=hs.get_objects()
for o in objs:
myprint(o)
for item in hs.heroscripts:
print(item)
query = "john*"
results = hs.search(User, query)
# Print the search results
for r in results:
# print(f"User: {r["path"]}")
print(r)

View File

@@ -0,0 +1 @@
{"/Users/despiegk/code/git.threefold.info/tfgrid/hero_research/hero/osis/heroscript/example/testFile.md": "f6e8b6a32349c262cb9afbea771c5add", "/Users/despiegk/code/git.threefold.info/tfgrid/hero_research/hero/osis/heroscript/example/sub/test file 2.md": "0ecc29046b6ef743481358e4c5630a6d"}

View File

@@ -0,0 +1,15 @@
# header
!!product.define
id:33
name:aproduct
description:'
this is a multiline
we need to remove the
this will stay 4 chars in
end
'
price:10.0
something else

View File

@@ -0,0 +1,22 @@
!!user.define
oid:abc123
name:John
description:'
this is a multiline
we need to remove the
this will stay 4 chars in
end
'
age:30
city:'New York'
```heroscript
!!user.define
oid:4nd
name:John2
age:40
city:bxl
```