-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.js
154 lines (133 loc) · 3.6 KB
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import { repository, $or } from "./src/db.mjs"
import { macros_article_JSON, cezare_borgia_JSON } from "./sample_data/index.js"
import browser from "./src/adapters/browser.js"
import { getVNodeTree, render } from "./src/utils.js"
const syncDom = (target, vdom) => {
const el = render(null, vdom)
target.replaceWith(el)
return el
}
const renderer = target => [
() => getVNodeTree(target),
vdom => {
target = syncDom(target, vdom)
}
];
!(async () => {
// const db = await db.open('pero')
// globalThis.db = db
const schema = () => {
// define('doc')
// define('post')
class TaxonomyHead {
title = String
slug = String
}
class Vdom {
tag = String
attrs = Object
children = Array($or(Vdom, String))
}
return {
user() {
return class User {
name = String
email = String
}
},
post({
tag, category, // user
}) {
const Tag = this.belongsToMany({ tag })
const Category = this.belongsToMany({ category })
// const Author = this.belongsToOne({ author: user })
// const Subscribers = this.belongsToMany({ subscribers: user })
class Taxonomies {
tags = Array(Tag)
categories = Array(Category)
}
return class Post {
header = TaxonomyHead
body = Vdom
taxonomies = Taxonomies
}
},
page() {
return class Page {
header = TaxonomyHead
body = Vdom
}
},
category({ post }) {
this.publish = true
this.hasMany({ post }, "category")
return TaxonomyHead
},
tag({ post }) {
this.publish = true
this.hasMany({ post }, "tag")
return TaxonomyHead
},
pageTree({ page }) {
const Page = this.belongsToMany({ page })
return class Route {
page_id = Page
path = String
children = Array(Route)
}
}
}
}
const db = repository(browser)
const repo = db(schema)
// const r = await repo[localStorage.hasOwnProperty("Pero") ? "open" : "create"]("Pero")
const r = globalThis.$ = await repo[localStorage.hasOwnProperty("Blazo") ? "open" : "create"]("Blazo")
cezare_borgia_JSON.tag = "div"
cezare_borgia_JSON.attrs.contenteditable = true
const [readDOM, writeDOM] = renderer(document.body.querySelector("#app"))
// r.query(
// $ => $.tag.queryRelationship(
// tag => tag.post.category(1, 2, 3)
// )
// )
// const getRevisionByIndex = index => r.query(($) => $.doc.getRevisions().data())[index]
// const loadRevision = i => {
// const r = getRevisionByIndex(i)
// writeDOM(r.data)
// return r
// }
// const saveRevision = ({ document: { id, type } = {}, revision: { from } = {} } = {}) => {
// r.save({
// id,
// type: "doc",
// data: readDOM(),
// from,
// publish: true
// })
// }
Object.assign(globalThis, {
render,
r,
readDOM,
writeDOM,
repository,
db,
repo,
// getRevisionByIndex,
// loadRevision,
// saveRevision,
macros_article_JSON,
cezare_borgia_JSON
})
// globalThis.db = db
})()
console.log(`
OK, so few notes here:
=====================================================================
Conclusion for relational querying
*********************************************************************
Instead of Post.latest({ rel: post => post.tag() })
Instead of Post.latest({ from: post => post.tag.latest() })
---------------------------------------------------------------------
All in due time though!
`)