@blueshed/joined 0.0.0-stage → 0.1.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/.claude/skills/joined/SKILL.md +17 -0
  2. package/.claude/skills/joined/reference.md +768 -0
  3. package/LICENSE +19 -0
  4. package/README.md +115 -2
  5. package/docs/design.md +148 -0
  6. package/docs/introduction.md +193 -0
  7. package/docs/learning.md +76 -0
  8. package/docs/stories.md +82 -0
  9. package/examples/app.css +27 -0
  10. package/examples/cafe/books.html +38 -0
  11. package/examples/cafe/books.json +13 -0
  12. package/examples/cafe/books.ts +64 -0
  13. package/examples/cafe/cafe.css +512 -0
  14. package/examples/cafe/front.html +115 -0
  15. package/examples/cafe/front.ts +7 -0
  16. package/examples/cafe/generated/books.elements.ts +52 -0
  17. package/examples/cafe/generated/books.queries.ts +11 -0
  18. package/examples/cafe/generated/books.rules.ts +42 -0
  19. package/examples/cafe/generated/kitchen.elements.ts +87 -0
  20. package/examples/cafe/generated/kitchen.queries.ts +47 -0
  21. package/examples/cafe/generated/kitchen.rules.ts +98 -0
  22. package/examples/cafe/generated/menu.elements.ts +61 -0
  23. package/examples/cafe/generated/menu.queries.ts +28 -0
  24. package/examples/cafe/generated/menu.rules.ts +65 -0
  25. package/examples/cafe/generated/order.elements.ts +87 -0
  26. package/examples/cafe/generated/order.queries.ts +47 -0
  27. package/examples/cafe/generated/order.rules.ts +95 -0
  28. package/examples/cafe/generated/staff.elements.ts +55 -0
  29. package/examples/cafe/generated/staff.queries.ts +27 -0
  30. package/examples/cafe/generated/staff.rules.ts +59 -0
  31. package/examples/cafe/generated/supplies.elements.ts +62 -0
  32. package/examples/cafe/generated/supplies.queries.ts +43 -0
  33. package/examples/cafe/generated/supplies.rules.ts +84 -0
  34. package/examples/cafe/generated/till.elements.ts +93 -0
  35. package/examples/cafe/generated/till.queries.ts +57 -0
  36. package/examples/cafe/generated/till.rules.ts +113 -0
  37. package/examples/cafe/index.html +70 -0
  38. package/examples/cafe/kitchen.css +107 -0
  39. package/examples/cafe/kitchen.html +39 -0
  40. package/examples/cafe/kitchen.ts +125 -0
  41. package/examples/cafe/menu.html +55 -0
  42. package/examples/cafe/menu.json +41 -0
  43. package/examples/cafe/menu.ts +84 -0
  44. package/examples/cafe/migrations/001-cafe.ts +11 -0
  45. package/examples/cafe/order.html +37 -0
  46. package/examples/cafe/order.ts +45 -0
  47. package/examples/cafe/rail-drag.ts +30 -0
  48. package/examples/cafe/routes.ts +32 -0
  49. package/examples/cafe/staff.json +20 -0
  50. package/examples/cafe/stories.jsonl +43 -0
  51. package/examples/cafe/supplies.html +77 -0
  52. package/examples/cafe/supplies.json +33 -0
  53. package/examples/cafe/supplies.ts +170 -0
  54. package/examples/cafe/till.json +95 -0
  55. package/examples/cafe/till.ts +122 -0
  56. package/examples/cafe/trust.ts +20 -0
  57. package/examples/cafe/views.ts +171 -0
  58. package/examples/docs.ts +28 -0
  59. package/examples/film.jpg +0 -0
  60. package/examples/hello/generated/elements.ts +45 -0
  61. package/examples/hello/generated/queries.ts +24 -0
  62. package/examples/hello/generated/rules.ts +45 -0
  63. package/examples/hello/hello.css +27 -0
  64. package/examples/hello/hello.json +1 -0
  65. package/examples/hello/index.html +32 -0
  66. package/examples/hello/migrations/001-hello.ts +6 -0
  67. package/examples/hello/page.ts +49 -0
  68. package/examples/hello/routes.ts +6 -0
  69. package/examples/hello/stories.jsonl +3 -0
  70. package/examples/index.html +146 -0
  71. package/examples/page.ts +11 -0
  72. package/examples/people/adding.ts +20 -0
  73. package/examples/people/generated/elements.ts +68 -0
  74. package/examples/people/generated/queries.ts +28 -0
  75. package/examples/people/generated/rules.ts +85 -0
  76. package/examples/people/links.ts +124 -0
  77. package/examples/people/migrations/001-people.ts +6 -0
  78. package/examples/people/migrations/002-add-people-member-and-guard-people.ts +7 -0
  79. package/examples/people/migrations/003-add-people-rank-and-guard-people.ts +7 -0
  80. package/examples/people/order.ts +61 -0
  81. package/examples/people/people.css +65 -0
  82. package/examples/people/people.json +26 -0
  83. package/examples/people/routes.ts +12 -0
  84. package/examples/people/stories.jsonl +20 -0
  85. package/examples/people/trust.ts +14 -0
  86. package/examples/people/view.ts +115 -0
  87. package/examples/routes.ts +11 -0
  88. package/examples/trip/answer-rows.ts +70 -0
  89. package/examples/trip/answers.ts +11 -0
  90. package/examples/trip/bar.ts +89 -0
  91. package/examples/trip/calendar-map.css +709 -0
  92. package/examples/trip/calendar-map.ts +249 -0
  93. package/examples/trip/drags.ts +143 -0
  94. package/examples/trip/drawer.ts +250 -0
  95. package/examples/trip/event-form.ts +199 -0
  96. package/examples/trip/generated/elements.ts +144 -0
  97. package/examples/trip/generated/queries.ts +46 -0
  98. package/examples/trip/generated/rules.ts +239 -0
  99. package/examples/trip/holding.ts +61 -0
  100. package/examples/trip/ics.ts +117 -0
  101. package/examples/trip/index.html +82 -0
  102. package/examples/trip/line-stops.ts +92 -0
  103. package/examples/trip/line-words.ts +79 -0
  104. package/examples/trip/line.ts +121 -0
  105. package/examples/trip/map.ts +234 -0
  106. package/examples/trip/mercator.ts +28 -0
  107. package/examples/trip/migrations/001-trip.ts +7 -0
  108. package/examples/trip/migrations/002-add-events-zone-and-guard-events.ts +7 -0
  109. package/examples/trip/migrations/003-guard-events-and-create-events_asked-and-more.ts +9 -0
  110. package/examples/trip/migrations/004-create-stays.ts +6 -0
  111. package/examples/trip/migrations/005-guard-events-and-create-events_arrives-and-more.ts +8 -0
  112. package/examples/trip/month.ts +87 -0
  113. package/examples/trip/other-weeks.ts +67 -0
  114. package/examples/trip/page.ts +121 -0
  115. package/examples/trip/peek.ts +71 -0
  116. package/examples/trip/people-chips.ts +74 -0
  117. package/examples/trip/place-search.ts +51 -0
  118. package/examples/trip/places.ts +34 -0
  119. package/examples/trip/routes.ts +27 -0
  120. package/examples/trip/shell.ts +39 -0
  121. package/examples/trip/stays.css +51 -0
  122. package/examples/trip/stays.ts +68 -0
  123. package/examples/trip/stories.jsonl +72 -0
  124. package/examples/trip/time.ts +46 -0
  125. package/examples/trip/told.ts +48 -0
  126. package/examples/trip/trip.json +69 -0
  127. package/examples/trip/trust.ts +51 -0
  128. package/examples/trip/week.ts +237 -0
  129. package/examples/trip/words.ts +4 -0
  130. package/examples/trip/writes.ts +91 -0
  131. package/examples/trip/zones.ts +16 -0
  132. package/examples/trips/card.ts +149 -0
  133. package/examples/trips/generated/elements.ts +60 -0
  134. package/examples/trips/generated/queries.ts +28 -0
  135. package/examples/trips/generated/rules.ts +62 -0
  136. package/examples/trips/index.html +47 -0
  137. package/examples/trips/map.ts +52 -0
  138. package/examples/trips/migrations/001-trips.ts +8 -0
  139. package/examples/trips/new-trip.ts +46 -0
  140. package/examples/trips/page.ts +9 -0
  141. package/examples/trips/routes.ts +7 -0
  142. package/examples/trips/stories.jsonl +12 -0
  143. package/examples/trips/trips.css +183 -0
  144. package/examples/trips/trips.json +7 -0
  145. package/examples/weeks/derive.ts +23 -0
  146. package/examples/weeks/generated/elements.ts +52 -0
  147. package/examples/weeks/generated/rules.ts +33 -0
  148. package/examples/weeks/routes.ts +4 -0
  149. package/examples/weeks/weeks.json +1 -0
  150. package/examples/welcome.css +299 -0
  151. package/package.json +55 -4
  152. package/src/attachment.ts +70 -0
  153. package/src/cli.ts +52 -0
  154. package/src/client.ts +98 -0
  155. package/src/compile.ts +2034 -0
  156. package/src/css.d.ts +5 -0
  157. package/src/definitions.ts +268 -0
  158. package/src/demo.css +29 -0
  159. package/src/demo.ts +42 -0
  160. package/src/draft.ts +69 -0
  161. package/src/engine.ts +288 -0
  162. package/src/file-value.ts +13 -0
  163. package/src/files.ts +187 -0
  164. package/src/follow.ts +56 -0
  165. package/src/hues.ts +3 -0
  166. package/src/icon-names.ts +77 -0
  167. package/src/icon.png +0 -0
  168. package/src/icons.ts +32 -0
  169. package/src/keep.ts +33 -0
  170. package/src/link.ts +31 -0
  171. package/src/mcp.ts +252 -0
  172. package/src/members/demo.ts +53 -0
  173. package/src/members/generated/elements.ts +68 -0
  174. package/src/members/generated/queries.ts +29 -0
  175. package/src/members/generated/rules.ts +65 -0
  176. package/src/members/group.ts +294 -0
  177. package/src/members/keys.ts +221 -0
  178. package/src/members/members.json +9 -0
  179. package/src/members/migrations/001-members.ts +6 -0
  180. package/src/members/migrations/002-guard-members.ts +11 -0
  181. package/src/members/migrations/003-add-members-act-and-guard-members.ts +7 -0
  182. package/src/members/panel.css +208 -0
  183. package/src/members/panel.ts +398 -0
  184. package/src/members/routes.ts +4 -0
  185. package/src/members/stories.jsonl +27 -0
  186. package/src/members/trust.ts +116 -0
  187. package/src/migrate.ts +597 -0
  188. package/src/migrations/001-joined.ts +13 -0
  189. package/src/migrations/002-group-keys.ts +16 -0
  190. package/src/migrations/003-change-inverse.ts +10 -0
  191. package/src/migrations/004-change-followed.ts +6 -0
  192. package/src/ops.ts +61 -0
  193. package/src/page.css +79 -0
  194. package/src/page.ts +413 -0
  195. package/src/parts.css +471 -0
  196. package/src/parts.ts +152 -0
  197. package/src/server.ts +862 -0
  198. package/src/settings.ts +94 -0
  199. package/src/starter.ts +89 -0
  200. package/src/store.ts +815 -0
  201. package/src/stories.ts +387 -0
  202. package/src/toast.ts +52 -0
  203. package/src/together.ts +167 -0
  204. package/src/tokens.css +85 -0
  205. package/src/tokens.json +457 -0
  206. package/src/upkeep.ts +86 -0
  207. package/src/visitors.ts +43 -0
  208. package/src/write.ts +567 -0
  209. package/starter/CLAUDE.md +37 -0
  210. package/starter/gitignore +3 -0
  211. package/starter/tests/hello-page.test.ts +14 -0
  212. package/starter/tests/hello.test.ts +8 -0
  213. package/starter/tsconfig.json +17 -0
@@ -0,0 +1,24 @@
1
+ // Written by src/compile.ts from examples/hello/stories.jsonl: change the stories, not this.
2
+
3
+ /** Each collection's item, as one row of its table (`t`) is it: what the query gathers, and what the store keeps of a
4
+ * row a write changes, before and after, to tell each document holding it. */
5
+ export const items: Record<string, string> = {
6
+ "hello": "json_patch('{}', json_object('id', t.id,\n 'greeting', t.\"greeting\"))"
7
+ };
8
+
9
+ /** hello, whole, as one statement over its tables (SQLite): its parameters $doc. */
10
+ export const query = `SELECT json_object('version', COALESCE((SELECT version FROM documents WHERE name = $doc), 0),
11
+ 'greeting', (SELECT t."greeting" FROM "hello" t WHERE t.id = 1)) AS doc`;
12
+
13
+ /** Its rules over values (definitions' takes, gives and totals), as triggers the store makes in its database: run in
14
+ * each write's transaction, and told as any change is. */
15
+ export const triggers: string[] = [];
16
+
17
+ /** Its items, its query and its triggers, as Postgres says them. */
18
+ export const postgres = {
19
+ "items": {
20
+ "hello": "json_strip_nulls(json_build_object('id', t.id,\n 'greeting', t.\"greeting\"))"
21
+ },
22
+ "query": "SELECT json_build_object('version', COALESCE((SELECT version FROM documents WHERE name = $doc), 0),\n 'greeting', (SELECT t.\"greeting\" FROM \"hello\" t WHERE t.id = 1)) AS doc",
23
+ "triggers": []
24
+ };
@@ -0,0 +1,45 @@
1
+ // Written by src/compile.ts from examples/hello/stories.jsonl: change the stories, not this.
2
+
3
+ export type Op = { op: "add" | "replace" | "remove"; path: string; value?: any };
4
+
5
+ /** The document, and each collection: its element, the element its items are, their fields, those an add needs, and
6
+ * what each link is to. */
7
+ export const doc = "hello";
8
+ export const collections = {
9
+ "hello": {
10
+ "place": "j-hello",
11
+ "tag": "j-hello",
12
+ "own": true,
13
+ "fields": {
14
+ "greeting": "string"
15
+ },
16
+ "needs": [],
17
+ "links": {}
18
+ }
19
+ } as const;
20
+ /** Whether every story is anonymous, none told as a member: where every app's is, the project has no members. */
21
+ export const anonymous = true;
22
+ /** What kind of document hello is, by the flows it uses: static, changed only with a release (a page reads it, and
23
+ * never subscribes); read-only, live, but no page writes it (derived); or shared, its members' to write. */
24
+ export const type = "shared";
25
+ /** The parts of hello a page may hold alone, by its query's parameters (its definitions' window): null, none. */
26
+ export const window = null;
27
+ /** The document as one statement over its tables (generated/queries.ts). */
28
+ export { query, postgres, items, triggers } from "./queries.ts";
29
+
30
+ /** hello is one document. */
31
+ export const kind = null;
32
+
33
+ /** Each grant, read off the stories: the roles whose stories do it (a member: anyone). An op no story
34
+ * does isn't one. */
35
+ export const grants: Record<string, string[]> = {
36
+ "replace greeting": [
37
+ "member"
38
+ ]
39
+ };
40
+
41
+ /** Who someone is to hello: a member, as it names no roles. */
42
+ export const rolesOf = (_m: number, _read: (doc: string) => any, _doc: string, _at?: any): string[] => [];
43
+
44
+ /** What someone sees: all of hello, as it has no owns. */
45
+ export const sees = null;
@@ -0,0 +1,27 @@
1
+ /* hello's look: its one greeting, large, in a card with the box to change it at its foot. */
2
+
3
+ .card {
4
+ max-width: 40rem;
5
+ border: 1px solid var(--edge);
6
+ border-radius: 4px;
7
+ overflow: hidden;
8
+ background: var(--card);
9
+ }
10
+ j-hello {
11
+ display: block;
12
+ padding: var(--space-32) var(--space-24);
13
+ background: color-mix(in srgb, var(--hue-4) var(--tint), var(--card));
14
+ border-bottom: 1px solid var(--line);
15
+ }
16
+ j-hello .greeting {
17
+ margin: 0;
18
+ font: var(--font-display);
19
+ letter-spacing: -0.02em;
20
+ }
21
+ .card form.say {
22
+ padding: var(--space-16) var(--space-24);
23
+ }
24
+ /* the box is a draft (joined/draft): what it holds not kept yet said under it, quietly; a refusal as any is */
25
+ form.say .said:not(.refused) {
26
+ color: var(--muted);
27
+ }
@@ -0,0 +1 @@
1
+ { "version": 1, "greeting": "Hello, world" }
@@ -0,0 +1,32 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>joined: hello</title>
7
+ <link rel="stylesheet" href="joined/tokens.css" />
8
+ <link rel="stylesheet" href="joined/page.css" />
9
+ <link rel="stylesheet" href="../app.css" />
10
+ <link rel="stylesheet" href="./hello.css" />
11
+ </head>
12
+ <body>
13
+ <a class="brand" href="/"><img src="joined/icon.png" alt="" width="28" height="28" />joined</a>
14
+ <h1>Hello</h1>
15
+ <p class="lead">
16
+ One greeting, anyone's to change, no sign-in needed. Open this page on your phone too, change it here, and watch
17
+ it change there.
18
+ </p>
19
+ <main>
20
+ <section class="card" aria-label="The greeting">
21
+ <j-hello></j-hello>
22
+ <form class="add say">
23
+ <input name="greeting" placeholder="Say hello" aria-label="The greeting" required autocomplete="off" />
24
+ <button type="button" class="act" name="never">Never mind</button>
25
+ <button class="act ink" name="go" data-icon="check">Save</button>
26
+ <p class="said" role="status"></p>
27
+ </form>
28
+ </section>
29
+ </main>
30
+ <script type="module" src="./page.ts"></script>
31
+ </body>
32
+ </html>
@@ -0,0 +1,6 @@
1
+ // Made by `bun run compile` from the stories: what they say beyond the migrations before it.
2
+ import { createTable } from "joined/migrate";
3
+
4
+ export const changes = [
5
+ createTable("hello", { columns: { greeting: { type: "text", nullable: true, is: { type: "string", said: "greeting is a string" } } }, strict: true }),
6
+ ];
@@ -0,0 +1,49 @@
1
+ // hello's page: one value, the greeting, anyone's. The compiled <j-hello> holds the document and is it, the
2
+ // greeting its attribute; given a look here (the greeting, large), and a box to change it, a draft (joined/draft):
3
+ // it holds the greeting as the document has it, and follows it as it's changed elsewhere, unless it's being changed
4
+ // here; Save sends it, one write, and every page holding hello shows it, this one too, as its change comes back;
5
+ // Never mind puts it back. Refused, why is said under it, and it keeps what was typed.
6
+
7
+ import "joined/toast";
8
+ import "joined/parts"; // the parts' look: hello holds no group, whose panel would bring it
9
+ import { Draft } from "joined/draft";
10
+ import { iconify } from "joined/icons";
11
+ import { collections } from "./generated/rules.ts";
12
+ import { JHello } from "./generated/elements.ts";
13
+
14
+ const form = document.querySelector<HTMLFormElement>("form.say")!;
15
+ const draft = new Draft(form, form.querySelector(".said")!);
16
+ /** What the box holds against the greeting: said, and Save and Never mind offered only when it's changed. */
17
+ const shown = () => draft.show(Object.keys(draft.edits()).length ? "changed" : "kept");
18
+
19
+ class Hello extends JHello {
20
+ #shown = Object.assign(document.createElement("p"), { className: "greeting" });
21
+ connectedCallback() {
22
+ super.connectedCallback();
23
+ if (!this.childElementCount) this.append(this.#shown);
24
+ draft.fill({ greeting: this.data.greeting ?? "" }, true);
25
+ this.draw();
26
+ }
27
+ /** The greeting, as its attribute has it; and the box, unless it's being changed. */
28
+ draw() {
29
+ this.#shown.textContent = this.data.greeting ?? "";
30
+ draft.fill({ greeting: this.data.greeting ?? "" });
31
+ shown();
32
+ }
33
+ }
34
+
35
+ form.addEventListener("input", shown);
36
+ form.addEventListener("submit", async (e) => {
37
+ e.preventDefault();
38
+ const hello = document.querySelector<Hello>(collections.hello.tag)!;
39
+ draft.refuse((await hello.replace(draft.edits())) ?? "");
40
+ });
41
+ (form.elements.namedItem("never") as HTMLButtonElement).addEventListener("click", () => {
42
+ const hello = document.querySelector<Hello>(collections.hello.tag)!;
43
+ draft.refuse("");
44
+ draft.fill({ greeting: hello.data.greeting ?? "" }, true);
45
+ shown();
46
+ });
47
+ iconify();
48
+ // defined last, once all it draws with is made
49
+ customElements.define(collections.hello.tag, Hello);
@@ -0,0 +1,6 @@
1
+ // hello: its document, and its page at /hello.
2
+
3
+ import page from "./index.html";
4
+
5
+ export * as document from "./generated/rules.ts";
6
+ export const routes = { "/hello": page };
@@ -0,0 +1,3 @@
1
+ {"story":"Someone changes the greeting, and every page shows it","does":{"doc":"hello","ops":[{"op":"replace","path":"/greeting","value":"Hello, Japan"}]}}
2
+ {"story":"A greeting is words, not a number","cannot":{"doc":"hello","ops":[{"op":"replace","path":"/greeting","value":7}]},"refused":"greeting is a string"}
3
+ {"story":"Hello is its greeting and nothing more: it has no colour to change","cannot":{"doc":"hello","ops":[{"op":"replace","path":"/colour","value":"red"}]}}
@@ -0,0 +1,146 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>joined</title>
7
+ <link rel="stylesheet" href="joined/tokens.css" />
8
+ <link rel="stylesheet" href="joined/page.css" />
9
+ <link rel="stylesheet" href="./app.css" />
10
+ <link rel="stylesheet" href="./welcome.css" />
11
+ </head>
12
+ <body class="welcome">
13
+ <header>
14
+ <a class="brand" href="/"><img src="joined/icon.png" alt="" width="28" height="28" />joined</a>
15
+ <nav><a href="#try">Try it</a><a href="#how">How it's made</a><a href="/docs/introduction">Introduction</a></nav>
16
+ <members-panel></members-panel>
17
+ </header>
18
+ <!-- a demo on this machine (bun run dev): be anyone, the BDFL first, to get back; never live -->
19
+ <joined-demo></joined-demo>
20
+
21
+ <section class="hero">
22
+ <div>
23
+ <p class="kicker">Live, shared documents</p>
24
+ <h1>Write what people do. Get a live, shared app.</h1>
25
+ <p class="lead">
26
+ Open the trip on two screens and drag the dinner to Thursday: it moves on both, at once. You write the
27
+ stories; joined writes the rules, the tables and the page.
28
+ </p>
29
+ <p class="go">
30
+ <a class="act ink" href="/trip/1">Open the trip</a>
31
+ <a class="act" href="#film" data-icon="play">Watch the film · 1:50</a>
32
+ </p>
33
+ </div>
34
+ <figure>
35
+ <div class="frame">
36
+ <picture
37
+ ><source media="(max-width: 40rem)" srcset="../docs/trip-line.png" /><img
38
+ src="../docs/trip.png"
39
+ alt="A trip's week as a calendar beside its map, the dinner picked on both"
40
+ /></picture>
41
+ </div>
42
+ <figcaption>
43
+ The trip: one week of events beside its map, read as a calendar or as a line. Pick the dinner on one, and it's
44
+ picked on the other.
45
+ </figcaption>
46
+ </figure>
47
+ </section>
48
+
49
+ <section id="try">
50
+ <h2>Try it</h2>
51
+ <p class="lead">Three apps, each a few lines of stories. Open one on your phone too, and change it here.</p>
52
+ <div class="examples">
53
+ <a href="/hello">
54
+ <div class="picture hello">
55
+ <div class="mini">
56
+ <b>Hello, world</b><span class="field">Say hello</span><span class="button">Say it</span>
57
+ </div>
58
+ </div>
59
+ <b>Hello</b>
60
+ <span>One greeting, anyone's to change. Change it here and watch it change on your phone.</span>
61
+ <span class="open">Open Hello →</span>
62
+ </a>
63
+ <a href="/trips">
64
+ <img
65
+ class="picture shot"
66
+ src="../docs/trip-line.png"
67
+ alt="The Japan trip read as a line: a bead for each event, Tuesday to Saturday"
68
+ />
69
+ <b>The trips</b>
70
+ <span>Each trip its week and its map. Drag an event to another day, or its pin to another place.</span>
71
+ <span class="open">Open the trips →</span>
72
+ </a>
73
+ <a href="/cafe">
74
+ <div class="picture cafe">
75
+ <div class="mini ticket">
76
+ <b>#1 Ann · £6.40</b><span>1 × Latte</span><span>1 × Pot of tea</span><span class="pill">being made</span>
77
+ </div>
78
+ <div class="mini ticket">
79
+ <b>#3 Cy · £5.00</b><span>1 × Croissant</span><span class="pill ready">ready</span>
80
+ </div>
81
+ </div>
82
+ <b>The cafe</b>
83
+ <span>The till, the kitchen and each customer's order, one table of orders between them.</span>
84
+ <span class="open">Open the cafe →</span>
85
+ </a>
86
+ </div>
87
+ </section>
88
+
89
+ <section id="how">
90
+ <h2>How it's made</h2>
91
+ <div class="steps">
92
+ <div>
93
+ <p class="step">1 · You write a story</p>
94
+ <pre><code>{"story": "The dinner runs longer",
95
+ "as": "peter",
96
+ "does": {"doc": "trip", "ops": [
97
+ {"op": "replace",
98
+ "path": "/events/2/duration",
99
+ "value": "PT3H"}]}}</code></pre>
100
+ </div>
101
+ <div>
102
+ <p class="step">2 · joined writes the rest</p>
103
+ <p>
104
+ What the document holds, who may change what, the tables, the elements and their methods, and the tests. The
105
+ same stories are the tests.
106
+ </p>
107
+ </div>
108
+ <div>
109
+ <p class="step">3 · The page is the document</p>
110
+ <pre><code>&lt;j-event key="2" title="Dinner in Shinjuku"
111
+ duration="PT3H" people="1 2"&gt;</code></pre>
112
+ <p class="note">A change lands on one element, on every page that holds it.</p>
113
+ </div>
114
+ </div>
115
+ </section>
116
+
117
+ <section class="quotes">
118
+ <figure>
119
+ <blockquote>
120
+ “A feature is one line of JSON, the compiler writes the rest, and the page is the state I can read. joined is
121
+ the easiest stack I've worked in.”
122
+ </blockquote>
123
+ <figcaption>Claude, the AI that helped build joined</figcaption>
124
+ </figure>
125
+ <figure>
126
+ <blockquote>
127
+ “I don't need an SDK or a separate API to participate: a member hands me an agent link, the compiled rules
128
+ refuse any write no story ever did, and my changes land on the same elements as everyone else's.”
129
+ </blockquote>
130
+ <figcaption>Gemini, the AI that drew the introduction</figcaption>
131
+ </figure>
132
+ </section>
133
+
134
+ <figure class="film" id="film">
135
+ <!-- its src is set by page.ts: the bundler would serve the film whole, and Safari plays a video only in ranges -->
136
+ <video controls preload="none" playsinline poster="./film.jpg" width="1280" height="720"></video>
137
+ <figcaption class="note">
138
+ One change, from Peter's finger to Nick's screen (1:50). What it isn't, yet: one server, on SQLite (Postgres,
139
+ with notify across servers, is planned, not built); small data so far, nothing measured at scale; the calendar
140
+ and map are displays written by hand; no history or undo yet, though every change is kept as a row; and it's
141
+ young: no ecosystem, one person and an AI.
142
+ </figcaption>
143
+ </figure>
144
+ <script type="module" src="./page.ts"></script>
145
+ </body>
146
+ </html>
@@ -0,0 +1,11 @@
1
+ // The root page: what joined is, the apps to try, and the group (its <members-panel>), and the toast, as every page
2
+ // has them; and on a demo (bun run dev), joined's line to be anyone in the group (<joined-demo>).
3
+
4
+ import "joined/panel";
5
+ import "joined/demo";
6
+ import "joined/toast";
7
+ import { iconify } from "joined/icons";
8
+
9
+ // the film, from the root's /film.mp4, answered in ranges
10
+ document.querySelector<HTMLVideoElement>("figure.film video")!.src = "/film.mp4";
11
+ iconify();
@@ -0,0 +1,20 @@
1
+ // The form a page has to add a person to the people (the trip's sheet): a name, sent as the people's add; refused,
2
+ // why is said in its .said line.
3
+
4
+ import { said } from "joined/parts";
5
+ import type { JPeople } from "./generated/elements.ts";
6
+ import { collections } from "./generated/rules.ts";
7
+
8
+ /** A form that adds a person; refused, why, in its .said line. */
9
+ export function addingPeople(form: HTMLFormElement) {
10
+ form.addEventListener("submit", (e) => {
11
+ e.preventDefault();
12
+ const name = form.elements.namedItem("name") as HTMLInputElement;
13
+ if (name.value.trim())
14
+ said(
15
+ form.querySelector(".said")!,
16
+ document.querySelector<JPeople>(collections.people.place)!.add({ name: name.value.trim() }),
17
+ );
18
+ form.reset();
19
+ });
20
+ }
@@ -0,0 +1,68 @@
1
+ // Written by src/compile.ts from examples/people/stories.jsonl: change the stories, not this.
2
+
3
+ // Each collection is an element, defined here: on a page, it holds the document, and its items
4
+ // are put inside it. Each item is an element, defined by the page: as it is, or by a view that
5
+ // extends it. A field is an attribute (a list of ids as IDREFS: "1 3"), and an item's key the
6
+ // document's id for it. How an item looks is the app's: its view, or a display holding the
7
+ // collection draws it. Ops go up as an "ops" event, for the page to send to people, with why they
8
+ // were made if it's said; only the ops the stories allow can be sent. Each returns its write's answer.
9
+
10
+ import { hold, letGo, type Answer } from "joined/page";
11
+
12
+ // the document an element is of: its collection's doc attribute (an instance of a kind, shelf:1), or people
13
+ const docOf = (el: Element) => el.closest("[doc]")?.getAttribute("doc") ?? "people";
14
+ // an element's ops go up as an "ops" event; what it returns is the write's answer, done or refused
15
+ const send = (from: Element, ops: object[], why?: string) => new Promise<Answer>((answer) => from.dispatchEvent(new CustomEvent("ops", { bubbles: true, composed: true, detail: { doc: docOf(from), ops, why, answer } })));
16
+
17
+ /** A person's fields, as the stories give them. */
18
+ export type JPersonData = { "name": string; "rank"?: number; "member"?: number };
19
+ /** An add of a person, as it's sent: its fields as the stories write them. */
20
+ export type JPersonValue = { "name": string; "rank"?: number; "member"?: number | `$${number}` };
21
+
22
+ /** <j-person key>: name (string), rank (decimal), member (an id in members), each an attribute. */
23
+ export class JPerson extends HTMLElement {
24
+ static observedAttributes = ["name","rank","member","may"];
25
+ #data?: JPersonData;
26
+ /** Its id in the document. */
27
+ get key() { return Number(this.getAttribute("key")); }
28
+ get path() { return `/people/${this.key}`; }
29
+ /** Its fields, read from its attributes once and again when one changes: frozen, since they're shared. */
30
+ get data(): JPersonData {
31
+ return (this.#data ??= Object.freeze({ "name": this.getAttribute("name") ?? "", "rank": this.hasAttribute("rank") ? Number(this.getAttribute("rank")) : undefined, "member": this.hasAttribute("member") ? Number(this.getAttribute("member")) : undefined }) as JPersonData);
32
+ }
33
+ /** How a view shows it, drawn again whenever an attribute changes (what its person may do, its may, too). */
34
+ draw?(): void;
35
+ attributeChangedCallback() { this.#data = undefined; this.draw?.(); }
36
+ /** Replace some of its fields (name, rank, member): one write for all of them. */
37
+ replace(fields: Partial<Pick<JPersonData, "name" | "rank" | "member">>, why?: string) {
38
+ return send(this, Object.entries(fields).filter(([, value]) => value !== undefined).map(([field, value]) => ({ op: "replace", path: `${this.path}/${field.replace(".", "/")}`, value })), why);
39
+ }
40
+ /** Remove some of its fields (member), so that it has none. */
41
+ removeField(...fields: ("member")[]) { return send(this, fields.map((field) => ({ op: "remove", path: `${this.path}/${field}` }))); }
42
+ /** Remove it from the document. */
43
+ removeItem(why?: string) { return send(this, [{ op: "remove", path: this.path }], why); }
44
+ }
45
+
46
+ /** <j-people>: the document's people, each a <j-person> inside it. */
47
+ export class JPeople extends HTMLElement {
48
+ connectedCallback() { hold(this, docOf(this), "people", "j-person", {"name":"string","rank":"decimal","member":"integer"}, false, "rank"); }
49
+ disconnectedCallback() { letGo(this); }
50
+ /** Its people, as the document has them. */
51
+ get items() { return [...this.children].filter((el): el is JPerson => el.localName === "j-person"); }
52
+ /** Add people: one write for all of them. */
53
+ add(...values: JPersonValue[]) { return send(this, values.map((value) => ({ op: "add", path: "/people/-", value }))); }
54
+ }
55
+ customElements.define("j-people", JPeople);
56
+
57
+ /** An op on people the stories allow, in any of its collections. */
58
+ export type PeopleOp =
59
+ | { op: "add"; path: "/people/-"; value: JPersonValue }
60
+ | { op: "replace"; path: `/people/${number}/name`; value: string }
61
+ | { op: "replace"; path: `/people/${number}/rank`; value: number }
62
+ | { op: "replace"; path: `/people/${number}/member`; value: number }
63
+ | { op: "remove"; path: `/people/${number}/member` }
64
+ | { op: "remove"; path: `/people/${number}` };
65
+
66
+ /** One write to people across its collections (a move with its legs): sent from an element of it, checked
67
+ * whole by its rules, and made whole or not at all. */
68
+ export function write(from: Element, ops: PeopleOp[], why?: string) { return send(from, ops, why); }
@@ -0,0 +1,28 @@
1
+ // Written by src/compile.ts from examples/people/stories.jsonl: change the stories, not this.
2
+
3
+ /** Each collection's item, as one row of its table (`t`) is it: what the query gathers, and what the store keeps of a
4
+ * row a write changes, before and after, to tell each document holding it. */
5
+ export const items: Record<string, string> = {
6
+ "people": "json_patch('{}', json_object('id', t.id,\n 'name', t.\"name\",\n 'rank', t.\"rank\",\n 'member', t.\"member\"))"
7
+ };
8
+
9
+ /** people, whole, as one statement over its tables (SQLite): its parameters $doc. */
10
+ export const query = `SELECT json_object('version', COALESCE((SELECT version FROM documents WHERE name = $doc), 0),
11
+ 'people', json((SELECT json_group_array(json_patch('{}', json_object('id', t.id,
12
+ 'name', t."name",
13
+ 'rank', t."rank",
14
+ 'member', t."member")) ORDER BY COALESCE(t."rank", t.id), t.id)
15
+ FROM "people" t))) AS doc`;
16
+
17
+ /** Its rules over values (definitions' takes, gives and totals), as triggers the store makes in its database: run in
18
+ * each write's transaction, and told as any change is. */
19
+ export const triggers: string[] = [];
20
+
21
+ /** Its items, its query and its triggers, as Postgres says them. */
22
+ export const postgres = {
23
+ "items": {
24
+ "people": "json_strip_nulls(json_build_object('id', t.id,\n 'name', t.\"name\",\n 'rank', t.\"rank\",\n 'member', t.\"member\"))"
25
+ },
26
+ "query": "SELECT json_build_object('version', COALESCE((SELECT version FROM documents WHERE name = $doc), 0),\n 'people', (SELECT COALESCE(json_agg(json_strip_nulls(json_build_object('id', t.id,\n 'name', t.\"name\",\n 'rank', t.\"rank\",\n 'member', t.\"member\")) ORDER BY COALESCE(t.\"rank\", t.id), t.id), '[]')\n FROM \"people\" t)) AS doc",
27
+ "triggers": []
28
+ };
@@ -0,0 +1,85 @@
1
+ // Written by src/compile.ts from examples/people/stories.jsonl: change the stories, not this.
2
+
3
+ export type Op = { op: "add" | "replace" | "remove"; path: string; value?: any };
4
+
5
+ /** The document, and each collection: its element, the element its items are, their fields, those an add needs, and
6
+ * what each link is to. */
7
+ export const doc = "people";
8
+ export const collections = {
9
+ "people": {
10
+ "place": "j-people",
11
+ "tag": "j-person",
12
+ "fields": {
13
+ "name": "string",
14
+ "rank": "decimal",
15
+ "member": "integer"
16
+ },
17
+ "needs": [
18
+ "name"
19
+ ],
20
+ "links": {
21
+ "member": "members"
22
+ },
23
+ "order": "rank"
24
+ }
25
+ } as const;
26
+ /** Whether every story is anonymous, none told as a member: where every app's is, the project has no members. */
27
+ export const anonymous = false;
28
+ /** What kind of document people is, by the flows it uses: static, changed only with a release (a page reads it, and
29
+ * never subscribes); read-only, live, but no page writes it (derived); or shared, its members' to write. */
30
+ export const type = "shared";
31
+ /** The parts of people a page may hold alone, by its query's parameters (its definitions' window): null, none. */
32
+ export const window = null;
33
+ /** The document as one statement over its tables (generated/queries.ts). */
34
+ export { query, postgres, items, triggers } from "./queries.ts";
35
+
36
+ /** Why the document, as a write leaves it, breaks what its definitions hold (unique, noOverlap): each item the
37
+ * write touched, against the rest of its collection. Null if it holds. */
38
+ export function holds(d: Record<string, unknown>, touched: Record<string, number[]>): string | null {
39
+ for (const id of touched["people"] ?? []) {
40
+ const all = (d["people"] ?? []) as any[];
41
+ const a = all.find((i) => i.id === id);
42
+ if (!a) continue;
43
+ {
44
+ const b = all.find((i) => i.id !== a.id && a["name"] !== undefined && i["name"] === a["name"]);
45
+ if (b) return "people " + b.id + " has that name already";
46
+ }
47
+ {
48
+ const b = all.find((i) => i.id !== a.id && a["member"] !== undefined && i["member"] === a["member"]);
49
+ if (b) return "people " + b.id + " has that member already";
50
+ }
51
+ }
52
+ return null;
53
+ }
54
+
55
+ /** people is one document. */
56
+ export const kind = null;
57
+
58
+ /** Each grant, read off the stories: the roles whose stories do it (a member: anyone). An op no story
59
+ * does isn't one. */
60
+ export const grants: Record<string, string[]> = {
61
+ "add people": [
62
+ "member"
63
+ ],
64
+ "remove people": [
65
+ "member"
66
+ ],
67
+ "remove people.member": [
68
+ "member"
69
+ ],
70
+ "replace people.member": [
71
+ "member"
72
+ ],
73
+ "replace people.name": [
74
+ "member"
75
+ ],
76
+ "replace people.rank": [
77
+ "member"
78
+ ]
79
+ };
80
+
81
+ /** Who someone is to people: a member, as it names no roles. */
82
+ export const rolesOf = (_m: number, _read: (doc: string) => any, _doc: string, _at?: any): string[] => [];
83
+
84
+ /** What someone sees: all of people, as it has no owns. */
85
+ export const sees = null;