Skip to content

Commit

Permalink
push wip on datamodel
Browse files Browse the repository at this point in the history
  • Loading branch information
verdverm committed Oct 17, 2020
1 parent 82d0a57 commit 6af87cd
Show file tree
Hide file tree
Showing 18 changed files with 471 additions and 47 deletions.
1 change: 1 addition & 0 deletions cue.mods
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ replace github.com/hofstadter-io/hofmod-cuefig => ../mods/cuefig

replace github.com/hofstadter-io/hofmod-model => ../mods/model
replace github.com/hofstadter-io/hofmod-sql => ../mods/sql
replace github.com/hofstadter-io/hofmod-gotyp => ../mods/gotyp
2 changes: 2 additions & 0 deletions cue.sums
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ github.com/hofstadter-io/hofmod-datastore v0.0.0 h1:lsIXa2L8JadSBNk5DkN6HO/T2i/D
github.com/hofstadter-io/hofmod-datastore v0.0.0/cue.mods h1:rh7w4JQKpreX0QyAmrTaMoiMgWJ3AXCNHHiPasG2wg0=
github.com/hofstadter-io/hofmod-devenv v0.0.0 h1:38MxYooWR+pcucjQzrEwjcmkPYcvIDmo2JNpH2pnCmY=
github.com/hofstadter-io/hofmod-devenv v0.0.0/cue.mods h1:/UaALg30rbzh/WvQ9e5bBqSqGKhdkGeBnKcJWXx3O3w=
github.com/hofstadter-io/hofmod-gotyp v0.0.0 h1:A13xTevZom6OofTQ5MePSOjurOiC4xwDNXbUtc4oR20=
github.com/hofstadter-io/hofmod-gotyp v0.0.0/cue.mods h1:x5wRO+09ePOQrcLUyM3PXvGOLq58n7zRup9C1T0UX/A=
github.com/hofstadter-io/hofmod-k8s v0.0.0 h1:sQOw6rSFRaV1Xyy4f77Y5aMXEMS8yv51SUbK1gM+Kvw=
github.com/hofstadter-io/hofmod-k8s v0.0.0/cue.mods h1:DFy090tDzZ0ax+j6CrjqDYaIgpda4CfPgl7GMqJdMUw=
github.com/hofstadter-io/hofmod-model v0.0.0 h1:morjwfhtk0VTs+o5piSNZXckuM0BtxKC9vs+6/UJ61w=
Expand Down
46 changes: 33 additions & 13 deletions schema/datamodel.cue
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
package schema

//import (
//"github.com/hofstadter-io/hof/schema/datamodel"
//)
#Datamodel: {
Name: string

//#Datamodel: [N=string]: #Datamodel & { Name: N, ... }
//#Datamodel: {
//Name: string
Modelsets?: #Modelsets
Models?: #Models
Views?: #Views
...
}

//Workbase: string | *"" // usually current directory
//Entrypoint: string // paths from workbase
#Modelsets: [name=string]: #Modelset & { Name: name, ... }
#Modelset: {
Name: string

//Modelsets: datamodel.#Modelsets
//Models: #Models
//Views: #Models
Models?: #Models
Views?: #Models
}

#Models: [name=string]: #Model & { Name: name, ... }
#Model: {
Name: string

Views?: #Models

Fields: [string]: {...}

...
}

#Views: [name=string]: #View & { Name: name, ... }
#View: {
Name: string
Models: #Models

Fields: [string]: _
...
}

//...
//}
9 changes: 0 additions & 9 deletions schema/datamodel/model.cue

This file was deleted.

11 changes: 0 additions & 11 deletions schema/datamodel/modelset.cue

This file was deleted.

9 changes: 0 additions & 9 deletions schema/datamodel/view.cue

This file was deleted.

72 changes: 72 additions & 0 deletions schema/datatypes.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package schema

#DataTypes: #ID |
#UUID |
#CUID |
#XUID |
#Bool |
#String |
#Enum |
#Password |
#Email

#ID: #UUID

#UUID: {
type: "uuid"
nullable: bool | *false
unique: bool | *true
generate: bool | *true
...
}

#CUID: {
type: "cuid"
nullable: bool | *false
unique: bool | *true
generate: bool | *true
...
}

#XUID: {
type: "xuid"
nullable: bool | *false
unique: bool | *true
generate: bool | *true
...
}

#Bool: {
type: "boolean"
default: bool | *false
nullable: bool | *false
...
}

#String: {
type: "string"
length: int | *64
unique: bool | *false
nullable: bool | *false
default?: string
...
}

#Enum: {
type: "string"
vals: [...string]
nullable: bool | *false
default?: string
...
}

#Password: {
type: "text"
bcrypt: true
}

#Email: #String & {
validation: "email"
...
}

10 changes: 5 additions & 5 deletions schema/testers.cue
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ package schema
method: *"GET" | "POST" | "PUT" | "DELETE" | "OPTIONS" | "HEAD" | "CONNECT" | "TRACE" | "PATCH"
host: string
path: string | *""
// auth?: string
auth?: string
headers?: [string]: string
query?: [string]: string
data?: string | {...}
timeout: int | *15
timeout?: string
retry?: {
count: int
timer: int
count?: int
timer?: string
codes: [...int]
}
}
Expand All @@ -25,5 +25,5 @@ package schema
status?: int
headers?: [string]: string
body?: string
latency?: float
// latency?: float
}
23 changes: 23 additions & 0 deletions test/datamodel/acct.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package datamodel

import "github.com/hofstadter-io/hof/schema"

#Account: schema.#Model & {

Permissioned: {
Object: "required"
Group: true
User: true
}

Fields: {
short: schema.#XUID
name: schema.#String
state: schema.#String & { length: 32 }
}

Lookup: {
short: Fields.short
name: Fields.name
}
}
88 changes: 88 additions & 0 deletions test/datamodel/app.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package datamodel

import "github.com/hofstadter-io/hof/schema"

#App: schema.#Model & {
plural: "apps"

Permissioned: {
group: true
user: true
}

Quotas: {
enabled: true
}

Owned: {
by: "#Project"
type: "has-many"
}

Fields: {
short: schema.#XUID
name: schema.#String
type: schema.#String
description: schema.#String
version: schema.#String
}

Relations: {
appDeployment: {
relation: "has-many"
type: "#AppDeployment"
}
}

Index: [
{ unique: true, fields: ["project_id", "name"] }
]

Lookup: {
short: Fields.short
name: Fields.name
}

}

#AppDeployment: schema.#Model & {
plural: "app-deployments"

Permissioned: {
group: true
user: true
}

Quotas: {
enabled: true
}

Owned: {
by: "#Project"
type: "has-many"
}

Fields: {
short: schema.#XUID
name: schema.#String
mode: schema.#String
version: schema.#String
}

Relations: {
app: {
relation: "belongs-to-one"
type: "#App"
}
}

Index: [
{ unique: true, fields: ["project_id", "name"] }
]

Lookup: {
short: Fields.short
name: Fields.name
}

}
10 changes: 10 additions & 0 deletions test/datamodel/auth.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package datamodel

import "github.com/hofstadter-io/hof/schema"

#Apikey: schema.#Model & {
Fields: {
apikey: schema.#UUID & { bcrypt: true }
name: schema.#String
}
}
75 changes: 75 additions & 0 deletions test/datamodel/billing.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package datamodel

import "github.com/hofstadter-io/hof/schema"

#BillingAccount: schema.#Model & {
Permissioned: {
object: "optional"
group: true
user: true
}

Owned: {
by: "#Account"
type: "has-many"
}

Fields: {
name: schema.#String
type: schema.#String
state: schema.#String
stripeToken: schema.#String
stripeCustomer: schema.#String
}

Index: [
{ unique: true, fields: ["account_id", "name"] }
]

Lookup: {
name: Fields.name
}

Relations: {
project: {
relation: "has-many"
type: "#Project"
}
}

}

#StripeSubscription: schema.#Model & {
Permissioned: {
object: "optional"
group: true
user: true
}

Owned: {
by: "#Account"
type: "has-many"
}

Fields: {
name: schema.#String
type: schema.#String
stripeID: schema.#UUID
}

Index: [
{ unique: true, fields: ["account_id", "name"] }
]

Lookup: {
name: Fields.name
}

Relations: {
billing: {
relation: "belongs-to-many"
type: "#BillingAccount"
nullable: true
}
}
}

0 comments on commit 6af87cd

Please sign in to comment.