@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,94 @@
1
+ // A kind's settings: a yes-or-no field of the root item that governs its instance, as a board's settings govern its
2
+ // posts (definitions' frozen and waits). The compiler checks them and writes them into generated/rules.ts as data;
3
+ // a page's write the grants allow is asked them in its transaction, and what a page may do is asked them too.
4
+
5
+ import type { Story } from "./compile.ts";
6
+ import type { Definitions } from "./definitions.ts";
7
+ import { parts, type Op } from "./ops.ts";
8
+ import type { Rules } from "./write.ts";
9
+
10
+ /** A kind's settings as generated/rules.ts holds them: the root item's field that turns each on, and the words a write
11
+ * is refused in while it's on; waits' first step, by collection, of its field that moves (moves). */
12
+ export type Settings = {
13
+ frozen?: { by: string; refused: string };
14
+ waits?: { by: string; refused: string; first: Record<string, string> };
15
+ };
16
+ /** What an instance's settings say now: whether it's kept as it is, and the first step each add gives (none, while
17
+ * it isn't held for approval). */
18
+ export type Now = { frozen: boolean; first: Record<string, string> };
19
+
20
+ const KEYS = ["frozen", "waits"] as const;
21
+ const NONE: Now = { frozen: false, first: {} };
22
+
23
+ /** The collections waits names, and the first step each: its keys but by and refused. */
24
+ const waitsFor = (waits: NonNullable<Definitions["waits"]>) =>
25
+ Object.entries(waits).filter(([k]) => k !== "by" && k !== "refused");
26
+
27
+ /** Why a document's settings can't be, or null: each is a kind's, says its words, and is by a yes-or-no field of its
28
+ * root (`fields`, a collection's, wherever it's held); a collection waits by its field that moves. */
29
+ export function settingsSaid(defs: Definitions, fields: (coll: string) => Record<string, string> | undefined) {
30
+ for (const key of KEYS) {
31
+ const s = defs[key];
32
+ if (!s) continue;
33
+ if (!defs.kind) return `${key} is a kind's, its root item's setting, and there's no kind`;
34
+ if (typeof s.refused !== "string") return `${key} says the words a write is refused in: refused`;
35
+ if (fields(defs.kind.root)?.[s.by] !== "boolean")
36
+ return `${key} is by ${s.by}, which isn't a yes-or-no field of ${defs.kind.root}`;
37
+ }
38
+ for (const [coll] of defs.waits ? waitsFor(defs.waits) : [])
39
+ if (!defs.moves?.[coll]) return `waits names ${coll}, but none of its fields moves (moves)`;
40
+ return null;
41
+ }
42
+
43
+ /** Why a setting is checked by no story, or null: each by a cannot refused in its words; and each first step waits
44
+ * gives, by a story adding one so (its grant), or a held instance would take no add from anyone. */
45
+ export function settingsUnchecked(defs: Definitions, stories: Story[], grants: Record<string, string[]>) {
46
+ for (const key of KEYS)
47
+ if (defs[key] && !stories.some((s) => s.cannot && s.refused === defs[key]!.refused))
48
+ return `${key} is checked by no story: none cannot, refused in its words`;
49
+ for (const [coll, first] of defs.waits ? waitsFor(defs.waits) : [])
50
+ if (!grants[`add ${coll}.${defs.moves![coll]}:>${first}`])
51
+ return `waits gives ${coll} ${first}, but no story adds one so`;
52
+ return null;
53
+ }
54
+
55
+ /** generated/rules.ts's settings: none, where there are none. */
56
+ export function settingsCode(doc: string, defs: Definitions) {
57
+ const { frozen, waits } = defs;
58
+ if (!frozen && !waits) return "";
59
+ const settings: Settings = {
60
+ ...(frozen && { frozen }),
61
+ ...(waits && { waits: { by: waits.by, refused: waits.refused, first: Object.fromEntries(waitsFor(waits)) } }),
62
+ };
63
+ return `/** The root item's own fields that govern ${doc} (its definitions' frozen and waits): src/settings.ts. */\nexport const settings = ${JSON.stringify(settings)};\n`;
64
+ }
65
+
66
+ type Ruled = Pick<Rules, "settings" | "moves">;
67
+
68
+ /** What an instance's settings say now, of its root item as it is (`root`, read only where there are settings). */
69
+ export function settingsNow(r: Ruled, root: () => Record<string, unknown> | undefined): Now {
70
+ const { frozen, waits } = r.settings ?? {};
71
+ if (!frozen && !waits) return NONE;
72
+ const item = root();
73
+ return {
74
+ frozen: !!frozen && item?.[frozen.by] === true,
75
+ first: waits && item?.[waits.by] === true ? waits.first : {},
76
+ };
77
+ }
78
+
79
+ /** Why a write to an instance is refused by its settings now, or null: frozen, every write; held for approval, any add
80
+ * that doesn't give its first step, and so the write whole. */
81
+ export function settled(r: Ruled, now: Now, ops: Op[]) {
82
+ if (now.frozen) return r.settings!.frozen!.refused;
83
+ const skips = ops.some((o) => {
84
+ const { coll, key, field } = parts(o.path);
85
+ return (
86
+ o.op === "add" &&
87
+ key === "-" &&
88
+ field === undefined &&
89
+ coll in now.first &&
90
+ o.value?.[r.moves![coll]!] !== now.first[coll]
91
+ );
92
+ });
93
+ return skips ? r.settings!.waits!.refused : null;
94
+ }
package/src/starter.ts ADDED
@@ -0,0 +1,89 @@
1
+ // An app's folder, begun and kept up: `joined init` puts in a folder (a project taking joined as its dependency) what
2
+ // an app on joined starts from, never over what's there, and `joined upgrade` moves joined to another version.
3
+ // init hello (examples/hello, anyone's, no sign-in) in apps/, the apps' look, the skill, a CLAUDE.md, a
4
+ // .gitignore, a tsconfig, tests telling hello's stories (and its page's, in a browser), the scripts; then
5
+ // compiled
6
+ // upgrade joined at another version (the newest, a version, or any spec Bun takes: a tarball), the skill
7
+ // refreshed from it, and the apps compiled by it
8
+ // `bun create joined <dir>` (create/, the package create-joined) makes the folder and runs init in it.
9
+
10
+ import { basename } from "node:path";
11
+ import { writeAll } from "./compile.ts";
12
+
13
+ /** Where joined's own files are: the package's folder. */
14
+ const JOINED = `${import.meta.dir}/..`;
15
+ /** joined on npm: the name it's published under; an app has it as `joined`. */
16
+ export const PUBLISHED = "@blueshed/joined";
17
+ /** hello's routes in an app: its page at the root too, the first `bun run dev` shows (joined's own root is its
18
+ * welcome page, so its hello is at /hello alone). */
19
+ const ROUTES = `// hello: its document, and its page, at the root and at /hello.
20
+
21
+ import page from "./index.html";
22
+
23
+ export * as document from "./generated/rules.ts";
24
+ export const routes = { "/": page, "/hello": page };
25
+ `;
26
+ /** What an app's folder starts from: each file, from joined's (or written here), to the app's. */
27
+ const STARTER: [string | { text: string }, string][] = [
28
+ ...["stories.jsonl", "hello.json", "index.html", "page.ts", "hello.css"].map((f): [string, string] => [
29
+ `examples/hello/${f}`,
30
+ `apps/hello/${f}`,
31
+ ]),
32
+ [{ text: ROUTES }, "apps/hello/routes.ts"],
33
+ ["examples/app.css", "apps/app.css"],
34
+ [".claude/skills/joined/SKILL.md", ".claude/skills/joined/SKILL.md"],
35
+ [".claude/skills/joined/reference.md", ".claude/skills/joined/reference.md"],
36
+ ["starter/CLAUDE.md", "CLAUDE.md"],
37
+ ["starter/gitignore", ".gitignore"],
38
+ ["starter/tsconfig.json", "tsconfig.json"],
39
+ ["starter/tests/hello.test.ts", "tests/hello.test.ts"],
40
+ ["starter/tests/hello-page.test.ts", "tests/hello-page.test.ts"],
41
+ ];
42
+ /** The scripts an app runs, by joined's command. */
43
+ const SCRIPTS = {
44
+ // a demo on this machine: <joined-demo> offers to be anyone in the group (never live)
45
+ dev: "joined compile && JOINED_DEMO=1 joined start",
46
+ compile: "joined compile",
47
+ start: "joined start",
48
+ link: "joined link",
49
+ upgrade: "joined upgrade",
50
+ test: "bun test",
51
+ };
52
+
53
+ /** A folder begun as an app: what was made, and what was there already, said; then its apps compiled. */
54
+ export async function init(dir: string) {
55
+ const said: string[] = [];
56
+ for (const [from, to] of STARTER)
57
+ if (await Bun.file(`${dir}/${to}`).exists()) said.push(`kept ${to}: it's there already`);
58
+ // written by its path: a file Bun's asked exists() of takes a copy of another as nothing (Bun 1.4.4)
59
+ else
60
+ (await Bun.write(`${dir}/${to}`, typeof from === "string" ? Bun.file(`${JOINED}/${from}`) : from.text),
61
+ said.push(`made ${to}`));
62
+ const pkg = Bun.file(`${dir}/package.json`),
63
+ was = (await pkg.exists()) ? await pkg.json() : { name: basename(dir), private: true, type: "module" };
64
+ const scripts = { ...SCRIPTS, ...was.scripts };
65
+ await Bun.write(pkg, `${JSON.stringify({ ...was, scripts }, null, 2)}\n`);
66
+ said.push(`scripts: ${Object.keys(SCRIPTS).join(", ")} (any of the folder's own kept)`);
67
+ said.push(await writeAll(`${dir}/apps`));
68
+ return said;
69
+ }
70
+
71
+ /** What Bun is given for joined at a version: the newest, a version, or a spec of its own (a tarball, a path). */
72
+ export const specOf = (version = "latest") => (/[:/]/.test(version) ? version : `npm:${PUBLISHED}@${version}`);
73
+
74
+ /** joined moved to another version in an app's folder, the skill refreshed from it, and the apps compiled by it. */
75
+ export async function upgrade(version: string | undefined, dir: string) {
76
+ const step = async (cmd: string[]) => {
77
+ const p = Bun.spawn(cmd, { cwd: dir, stdout: "pipe", stderr: "pipe" });
78
+ const out = `${await new Response(p.stdout).text()}${await new Response(p.stderr).text()}`;
79
+ if ((await p.exited) !== 0) throw new Error(`${cmd.join(" ")} didn't pass:\n${out}`);
80
+ return out.trim();
81
+ };
82
+ await step(["bun", "add", `joined@${specOf(version)}`]);
83
+ const now = `${dir}/node_modules/joined`;
84
+ for (const f of ["SKILL.md", "reference.md"])
85
+ await Bun.write(`${dir}/.claude/skills/joined/${f}`, Bun.file(`${now}/.claude/skills/joined/${f}`));
86
+ const { version: v } = await Bun.file(`${now}/package.json`).json();
87
+ // the folder's own apps, named: never those a JOINED_APPS in the environment names
88
+ return [`joined ${v}`, "the skill refreshed", await step(["bun", `${now}/src/cli.ts`, "compile", `${dir}/apps`])];
89
+ }