fix: schema

This commit is contained in:
Aslam H
2024-08-09 02:02:15 +07:00
parent 2d352605a2
commit a58b3853b4

View File

@@ -8,20 +8,17 @@
// open issue about it: https://github.com/gardencmp/jazz/issues/44 // open issue about it: https://github.com/gardencmp/jazz/issues/44
// TODO: figure out how to do default values, e.g. `GlobalLink.protocol` should have default value `https` so we don't have to supply it every time in code.. // TODO: figure out how to do default values, e.g. `GlobalLink.protocol` should have default value `https` so we don't have to supply it every time in code..
// TODO: can jazz support vector fields? e.g. `GlobalLinkAiSummary.vectorContent`, would be nice to store website content as vector for semantic search // TODO: can jazz support vector fields? e.g. `GlobalLinkAiSummary.vectorContent`, would be nice to store website content as vector for semantic search
import { CoMap, co, Account, Group } from "jazz-tools" import { CoMap, co, Account, Profile } from "jazz-tools"
import { PersonalPageLists } from "./personal-page" import { PersonalPageLists } from "./personal-page"
import { PersonalLinkLists } from "./personal-link" import { PersonalLinkLists } from "./personal-link"
import { GlobalTopicLists } from "./global-topic" import { GlobalTopicLists } from "./global-topic"
class UserProfile extends CoMap {
name = co.string
// TODO: avatar
}
export class UserRoot extends CoMap { export class UserRoot extends CoMap {
name = co.string name = co.string
username = co.string username = co.string
website = co.string avatar = co.optional.string
bio = co.string website = co.optional.string
bio = co.optional.string
is_public = co.optional.boolean
personalLinks = co.ref(PersonalLinkLists) personalLinks = co.ref(PersonalLinkLists)
personalPages = co.ref(PersonalPageLists) personalPages = co.ref(PersonalPageLists)
@@ -33,22 +30,24 @@ export class UserRoot extends CoMap {
} }
export class LaAccount extends Account { export class LaAccount extends Account {
profile = co.ref(UserProfile) profile = co.ref(Profile)
root = co.ref(UserRoot) root = co.ref(UserRoot)
async migrate(
this: LaAccount, migrate(this: LaAccount, creationProps?: { name: string }) {
creationProps?: { name: string; username: string; website: string; bio: string } | undefined // since we dont have a custom AuthProvider yet.
): Promise<void> { // and still using the DemoAuth. the creationProps will only accept name.
// so just do default profile create provided by jazz-tools
super.migrate(creationProps)
if (!this._refs.root && creationProps) { if (!this._refs.root && creationProps) {
const profileGroup = Group.create({ owner: this })
profileGroup.addMember("everyone", "reader")
this.profile = UserProfile.create({ name: creationProps.name }, { owner: profileGroup })
this.root = UserRoot.create( this.root = UserRoot.create(
{ {
name: creationProps.name, name: creationProps.name,
username: creationProps.username, username: creationProps.name,
website: creationProps.website, avatar: "",
bio: creationProps.bio, website: "",
bio: "",
is_public: false,
personalLinks: PersonalLinkLists.create([], { owner: this }), personalLinks: PersonalLinkLists.create([], { owner: this }),
personalPages: PersonalPageLists.create([], { owner: this }), personalPages: PersonalPageLists.create([], { owner: this }),
@@ -63,8 +62,6 @@ export class LaAccount extends Account {
} }
} }
} }
// TODO: need?
// class ListOfGlobalTopics extends CoList.Of(co.ref(GlobalTopic)) {}
export * from "./global-link" export * from "./global-link"
export * from "./global-topic" export * from "./global-topic"