cozemble / monorepo

A data and process canvas
https://cozemble.com
Apache License 2.0
13 stars 1 forks source link

Property Descriptor Design V2 #77

Open mike-hogan opened 1 year ago

mike-hogan commented 1 year ago

What we need from the new Property Descriptor design:

Considerations/Options

Reasons

What we want to retain

Example 1: Core property type defined as JsonDefinedPropertyDescriptor

Instead of this:

export interface StringProperty extends Property {
  propertyType: { _type: 'property.type'; value: 'string.property' }
  validations: RegexValidation[]
  multiline: boolean
}

export interface RegexValidation {
  _type: 'regex.validation'
  regex: string
  message: string
}

Definition of the core string property type would be extension of a String type with a json schema defining the extra config of regex validations and multiline support

We would lose the nice type checking in tests that we have now, but may be we could retain that by writing a companion typescript definition that wraps the underlying json schema driven type.

Example 2: We want to be able to generate cozemble models using Generative AI

I prompted ChatGTP with: Generate jsonschema for this project. Use json schema "ref" to express relationships: I run a bicycle repair shop. People book repairs via my website so they can come to my shop at an agreed time, drop off their bike, and collect it at an agreed time on the same day. I call this service Bike Check. The booking part of my website works fine and I am happy with that. What I need is a system to manage what goes on behind the website. I want to be able to: Enter customer data: first name, last name, email and mobile number. I want emails and mobile numbers to be unique. I want to be able to enter data for a Bike Check: customer, drop off date, make and model of bike, and general notes about the booking. I want to be able to upload pictures of the bike into the Bike Check record when the bike arrives. I want be to able to find customers using free text search I want to be able to find Bike Check records by date, and using free text search of all fields, but especially: make, model, customer name and notes. When adding a new Bike Check, if the customer is not already in the database, I want to be able to enter a new one

And it returned me this:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "definitions": {
        "Customer": {
            "type": "object",
            "properties": {
                "firstName": {"type": "string"},
                "lastName": {"type": "string"},
                "email": {
                    "type": "string",
                    "format": "email",
                    "uniqueItems": true
                },
                "mobileNumber": {
                    "type": "string",
                    "pattern": "^(\\+[0-9]{1,4})?[0-9]{7,14}$",
                    "uniqueItems": true
                }
            },
            "required": ["firstName", "lastName", "email", "mobileNumber"]
        },
        "BikeCheck": {
            "type": "object",
            "properties": {
                "customer": {"$ref": "#/definitions/Customer"},
                "dropOffDate": {
                    "type": "string",
                    "format": "date-time"
                },
                "bike": {
                    "type": "object",
                    "properties": {
                        "make": {"type": "string"},
                        "model": {"type": "string"}
                    },
                    "required": ["make", "model"]
                },
                "notes": {"type": "string"},
                "images": {
                    "type": "array",
                    "items": {
                        "type": "string",
                        "format": "uri"
                    }
                }
            },
            "required": ["customer", "dropOffDate", "bike"]
        }
    },
    "type": "object",
    "properties": {
        "Customers": {
            "type": "array",
            "items": {"$ref": "#/definitions/Customer"}
        },
        "BikeChecks": {
            "type": "array",
            "items": {"$ref": "#/definitions/BikeCheck"}
        }
    }
}

If I can round trip between json schema and cozemble models then we can provide existing model state to prompts via json schema, and create new models in response to the prompts via the generated json schema.

Metehan-Altuntekin commented 1 year ago

If we are going to use JSON Schema models anyway, why don't we just make it the base of Cozemble models instead of trying convert one another?