@blueshed/joined 0.2.2 → 0.3.1
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.
- package/.claude/skills/joined/SKILL.md +9 -1
- package/.claude/skills/joined/reference.md +316 -63
- package/.claude/skills/joined-door/SKILL.md +57 -0
- package/README.md +19 -50
- package/docs/design.md +158 -37
- package/docs/introduction.md +27 -27
- package/docs/light-and-shadow.svg +2 -1
- package/docs/links-and-trust.svg +1 -0
- package/docs/stories-to-code.svg +2 -1
- package/docs/wire-op.svg +1 -0
- package/examples/README.md +20 -0
- package/examples/account/account.json +1 -0
- package/examples/account/derive.ts +41 -0
- package/examples/account/generated/elements.ts +52 -0
- package/examples/account/generated/rows.ts +22 -0
- package/examples/account/generated/rules.ts +32 -0
- package/examples/account/routes.ts +5 -0
- package/examples/app.css +11 -1
- package/examples/cafe/books.html +2 -2
- package/examples/cafe/cafe.css +96 -85
- package/examples/cafe/generated/books.rows.ts +22 -0
- package/examples/cafe/generated/books.rules.ts +3 -2
- package/examples/cafe/generated/kitchen.rows.ts +27 -0
- package/examples/cafe/generated/kitchen.rules.ts +11 -1
- package/examples/cafe/generated/menu.rows.ts +22 -0
- package/examples/cafe/generated/menu.rules.ts +3 -2
- package/examples/cafe/generated/order.rows.ts +27 -0
- package/examples/cafe/generated/order.rules.ts +11 -1
- package/examples/cafe/generated/staff.elements.ts +7 -2
- package/examples/cafe/generated/staff.rows.ts +22 -0
- package/examples/cafe/generated/staff.rules.ts +9 -1
- package/examples/cafe/generated/supplies.queries.ts +4 -2
- package/examples/cafe/generated/supplies.rows.ts +22 -0
- package/examples/cafe/generated/supplies.rules.ts +17 -1
- package/examples/cafe/generated/till.queries.ts +2 -0
- package/examples/cafe/generated/till.rows.ts +27 -0
- package/examples/cafe/generated/till.rules.ts +11 -1
- package/examples/cafe/index.html +14 -15
- package/examples/cafe/kitchen.css +11 -19
- package/examples/cafe/kitchen.ts +7 -3
- package/examples/cafe/look.ts +30 -0
- package/examples/cafe/menu.html +10 -26
- package/examples/cafe/menu.ts +8 -80
- package/examples/cafe/migrations/002-guard-supplies.ts +15 -0
- package/examples/cafe/order.html +8 -7
- package/examples/cafe/order.ts +6 -2
- package/examples/cafe/routes.ts +0 -1
- package/examples/cafe/staff.json +5 -0
- package/examples/cafe/stories.jsonl +6 -2
- package/examples/cafe/supplies.html +35 -34
- package/examples/cafe/supplies.ts +59 -39
- package/examples/cafe/till.ts +19 -11
- package/examples/cafe/views.ts +7 -5
- package/examples/chart/arches.ts +150 -0
- package/examples/chart/chart.css +11 -0
- package/examples/chart/chart.json +87 -0
- package/examples/chart/generated/elements.ts +105 -0
- package/examples/chart/generated/queries.ts +36 -0
- package/examples/chart/generated/rows.ts +27 -0
- package/examples/chart/generated/rules.ts +111 -0
- package/examples/chart/grid.ts +118 -0
- package/examples/chart/index.html +78 -0
- package/examples/chart/migrations/001-chart.ts +6 -0
- package/examples/chart/migrations/002-create-conditions.ts +6 -0
- package/examples/chart/page.ts +20 -0
- package/examples/chart/routes.ts +7 -0
- package/examples/chart/stories.jsonl +14 -0
- package/examples/chart/teeth.ts +57 -0
- package/examples/desk/desk.css +6 -10
- package/examples/desk/generated/elements.ts +1 -1
- package/examples/desk/generated/rows.ts +22 -0
- package/examples/desk/generated/rules.ts +34 -1
- package/examples/desk/index.html +10 -3
- package/examples/desk/lanes.css +21 -19
- package/examples/desk/routes.ts +0 -2
- package/examples/desk/stories.jsonl +4 -3
- package/examples/desk/tally.css +1 -1
- package/examples/desk/thumbs.ts +2 -2
- package/examples/docs.ts +7 -4
- package/examples/hello/generated/elements.ts +2 -2
- package/examples/hello/generated/rules.ts +3 -2
- package/examples/hello/hello.css +2 -4
- package/examples/hello/index.html +10 -3
- package/examples/hello/page.ts +4 -4
- package/examples/index.html +20 -12
- package/examples/notes/generated/elements.ts +112 -0
- package/examples/notes/generated/queries.ts +42 -0
- package/examples/notes/generated/rows.ts +27 -0
- package/examples/notes/generated/rules.ts +133 -0
- package/examples/notes/index.html +32 -0
- package/examples/notes/look.ts +41 -0
- package/examples/notes/migrations/001-notes.ts +7 -0
- package/examples/notes/notes.json +78 -0
- package/examples/notes/page.ts +21 -0
- package/examples/notes/routes.ts +6 -0
- package/examples/notes/stories.jsonl +24 -0
- package/examples/page.ts +9 -2
- package/examples/people/generated/rows.ts +22 -0
- package/examples/people/generated/rules.ts +11 -1
- package/examples/people/links.ts +8 -9
- package/examples/people/people.css +1 -1
- package/examples/people/routes.ts +1 -3
- package/examples/people/stories.jsonl +1 -0
- package/examples/people/view.ts +5 -2
- package/examples/trip/generated/elements.ts +5 -3
- package/examples/trip/generated/queries.ts +12 -1
- package/examples/trip/generated/rows.ts +27 -0
- package/examples/trip/generated/rules.ts +56 -2
- package/examples/trip/index.html +58 -12
- package/examples/trip/line.css +186 -0
- package/examples/trip/line.ts +51 -40
- package/examples/trip/page.ts +65 -71
- package/examples/trip/routes.ts +9 -5
- package/examples/trip/stays.css +13 -13
- package/examples/trip/stays.ts +15 -10
- package/examples/trip/stories.jsonl +2 -0
- package/examples/trip/told.ts +3 -26
- package/examples/trip/trip.css +16 -0
- package/examples/trips/generated/elements.ts +1 -1
- package/examples/trips/generated/rows.ts +22 -0
- package/examples/trips/generated/rules.ts +9 -1
- package/examples/trips/index.html +10 -10
- package/examples/trips/map.ts +3 -14
- package/examples/trips/new-trip.ts +14 -16
- package/examples/trips/trips.css +24 -23
- package/examples/weeks/generated/elements.ts +1 -1
- package/examples/weeks/generated/queries.ts +11 -0
- package/examples/weeks/generated/rows.ts +22 -0
- package/examples/weeks/generated/rules.ts +11 -5
- package/examples/weeks/routes.ts +3 -2
- package/examples/weeks/stories.jsonl +1 -0
- package/examples/welcome.css +43 -33
- package/package.json +8 -2
- package/src/attachment.ts +17 -2
- package/src/awesome.ts +103 -0
- package/src/board.css +76 -0
- package/src/board.ts +173 -0
- package/src/cli.ts +28 -3
- package/src/compile.ts +821 -109
- package/src/definitions.ts +113 -27
- package/src/demo.css +2 -5
- package/src/draft.ts +48 -27
- package/src/drawer.ts +248 -0
- package/src/engine.ts +253 -170
- package/src/fields.ts +341 -0
- package/src/file-value.ts +12 -2
- package/src/files.ts +113 -33
- package/src/ground.ts +110 -0
- package/src/icon-names.ts +19 -2
- package/src/keep.ts +16 -3
- package/src/kit.ts +51 -0
- package/src/link.ts +3 -3
- package/src/map.css +140 -0
- package/src/map.ts +200 -0
- package/src/mcp.ts +129 -24
- package/src/members/demo.ts +13 -12
- package/src/members/generated/rows.ts +22 -0
- package/src/members/generated/rules.ts +3 -2
- package/src/members/group.ts +105 -55
- package/src/members/keys.ts +95 -79
- package/src/members/panel.css +40 -35
- package/src/members/panel.ts +58 -37
- package/src/migrate.ts +178 -125
- package/src/migrations/005-change-kept.ts +7 -0
- package/src/month.css +129 -0
- package/src/month.ts +179 -0
- package/src/ops.ts +40 -1
- package/src/page.css +11 -2
- package/src/page.ts +68 -17
- package/src/parts.css +614 -230
- package/src/parts.ts +259 -36
- package/src/plane.css +61 -0
- package/src/plane.ts +153 -0
- package/src/postgres-server.ts +60 -0
- package/src/reading.css +73 -0
- package/src/reading.ts +238 -0
- package/src/rows.css +289 -0
- package/src/rows.ts +864 -0
- package/src/search.css +80 -0
- package/src/search.ts +130 -0
- package/src/server.ts +355 -137
- package/src/settings.ts +9 -4
- package/src/sheet.ts +116 -0
- package/src/skill.ts +40 -0
- package/src/slots.css +90 -0
- package/src/slots.ts +213 -0
- package/src/specs.ts +38 -0
- package/src/starter.ts +19 -2
- package/src/store.ts +224 -161
- package/src/stories.ts +43 -11
- package/src/surface.ts +164 -0
- package/src/time.ts +2 -0
- package/src/timeline.css +111 -0
- package/src/timeline.ts +235 -0
- package/src/toast.ts +21 -48
- package/src/together.ts +15 -24
- package/src/tokens.css +89 -3
- package/src/tokens.json +287 -7
- package/src/tool.ts +210 -0
- package/src/upkeep.ts +47 -22
- package/src/views.css +43 -0
- package/src/views.ts +111 -0
- package/src/week.css +150 -0
- package/src/week.ts +254 -0
- package/src/write.ts +326 -78
- package/starter/CHANGELOG.md +8 -0
- package/starter/CLAUDE.md +9 -3
- package/starter/bunfig +5 -0
- package/starter/githooks/pre-commit +13 -0
- package/starter/prettierignore +5 -0
- package/starter/tests/hello.test.ts +2 -0
- package/starter/tests/records.test.ts +40 -0
- package/starter/todo.jsonl +0 -0
- package/docs/learning.md +0 -76
- package/examples/cafe/trust.ts +0 -20
- package/examples/desk/trust.ts +0 -24
- package/examples/people/trust.ts +0 -14
- package/examples/trip/answer-rows.ts +0 -70
- package/examples/trip/bar.ts +0 -89
- package/examples/trip/calendar-map.css +0 -711
- package/examples/trip/calendar-map.ts +0 -249
- package/examples/trip/drags.ts +0 -143
- package/examples/trip/drawer.ts +0 -250
- package/examples/trip/event-form.ts +0 -200
- package/examples/trip/holding.ts +0 -61
- package/examples/trip/map.ts +0 -234
- package/examples/trip/month.ts +0 -87
- package/examples/trip/other-weeks.ts +0 -67
- package/examples/trip/peek.ts +0 -71
- package/examples/trip/people-chips.ts +0 -74
- package/examples/trip/shell.ts +0 -39
- package/examples/trip/trust.ts +0 -51
- package/examples/trip/week.ts +0 -237
- package/examples/trip/writes.ts +0 -91
- package/examples/trip/zones.ts +0 -16
- package/examples/weeks/derive.ts +0 -23
- package/src/scrim.ts +0 -81
package/src/write.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// A write, as the database's transaction holds it (docs/plan.md, The
|
|
1
|
+
// A write, as the database's transaction holds it (docs/plan.md, "The four flows": Write and Broadcast): what an app's
|
|
2
2
|
// own rules say (its trust.ts), what the stories grant, what the server fills and copies, the rows, what the
|
|
3
3
|
// definitions hold, the rules over values, and what follows (each app's reactions), whole or none of it. Then who is
|
|
4
4
|
// told: each document holding a row it changed, in its own paths (the store's), and each part of one a page holds
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// sees only some of (owns), or one read as each member has it, as they had it and have it now. The server names the
|
|
7
7
|
// member and passes the write on; it holds none of this.
|
|
8
8
|
|
|
9
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
9
10
|
import { grantOf } from "./definitions.ts";
|
|
10
11
|
import { docParts, parts, type Change, type Op } from "./ops.ts";
|
|
11
12
|
import { settled, settingsNow, type Settings } from "./settings.ts";
|
|
@@ -20,7 +21,8 @@ import {
|
|
|
20
21
|
type Rules as StoreRules,
|
|
21
22
|
type Store,
|
|
22
23
|
} from "./store.ts";
|
|
23
|
-
import {
|
|
24
|
+
import { named, type Part } from "./together.ts";
|
|
25
|
+
import { wallIn } from "./time.ts";
|
|
24
26
|
import { admits, guestRole, levelled } from "./visitors.ts";
|
|
25
27
|
|
|
26
28
|
/** A way to read any document as it is now: whole, or as a member sees it (owns). */
|
|
@@ -30,7 +32,17 @@ export type Read = (doc: string, member?: number) => Doc;
|
|
|
30
32
|
export type Rules = StoreRules & {
|
|
31
33
|
anonymous?: boolean;
|
|
32
34
|
derived?: readonly string[];
|
|
33
|
-
|
|
35
|
+
/** What its definitions hold among each collection's rows (`d`, by collection), each the write touched. */
|
|
36
|
+
holds?(d: Record<string, unknown>, touched: Record<string, number[]>): string | null;
|
|
37
|
+
/** What its lists hold as a write leaves them (definitions' within and apart), asked on SQLite: Postgres's triggers
|
|
38
|
+
* hold them, at the write's end (the store's settle). */
|
|
39
|
+
listsHold?(d: Doc, touched: Record<string, number[]>): string | null;
|
|
40
|
+
/** The lists that are each member's own (definitions' mine), by collection. */
|
|
41
|
+
mine?: Record<string, string[]>;
|
|
42
|
+
/** The words a write giving or taking another's is refused in, where its mine says them, by collection and field. */
|
|
43
|
+
mineSaid?: Record<string, Record<string, string>>;
|
|
44
|
+
/** The collections of values that are each member's own (definitions' mine, { of, by }), by collection. */
|
|
45
|
+
own?: Record<string, { of: string; by: string }>;
|
|
34
46
|
grants: Record<string, string[]>;
|
|
35
47
|
/** Who someone is to it: none, of a derived document. */
|
|
36
48
|
rolesOf?(m: number, read: Read, doc: string, at?: any): string[];
|
|
@@ -49,6 +61,9 @@ export type Rules = StoreRules & {
|
|
|
49
61
|
reads?: readonly string[];
|
|
50
62
|
/** Who may hold it at all (definitions' where), each a role: null, anyone. */
|
|
51
63
|
mayHold?: readonly string[] | null;
|
|
64
|
+
/** Each link whose every id names one who holds a role: that role, and the words another is refused in (definitions'
|
|
65
|
+
* links, holds). */
|
|
66
|
+
names?: Record<string, readonly [(m: number, read: Read, doc: string) => boolean, string]>;
|
|
52
67
|
type?: "static" | "read-only" | "shared";
|
|
53
68
|
};
|
|
54
69
|
/** An app's own rules for a write (its trust.ts), which no story can say: why it's refused, or null. Asked
|
|
@@ -67,6 +82,19 @@ export type Held = { windows: string[]; views: { topic: string; doc: string; mem
|
|
|
67
82
|
/** What a write tells, past its changes: to each topic a page holds, what changed of it. */
|
|
68
83
|
export type Told = { topic: string; change: Change & { doc: string } }[];
|
|
69
84
|
|
|
85
|
+
/** A document a rule read that isn't held yet: settle reads it, and asks again. */
|
|
86
|
+
class Missing {
|
|
87
|
+
constructor(
|
|
88
|
+
readonly doc: string,
|
|
89
|
+
readonly member?: number,
|
|
90
|
+
) {}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** A write kept while away that's made already, and the version it made. */
|
|
94
|
+
export class Made {
|
|
95
|
+
constructor(readonly version: number) {}
|
|
96
|
+
}
|
|
97
|
+
|
|
70
98
|
/** How many rounds of reactions a write may set off before it's refused as never settling. */
|
|
71
99
|
const ROUNDS = 10;
|
|
72
100
|
|
|
@@ -76,6 +104,7 @@ export function writes({
|
|
|
76
104
|
group,
|
|
77
105
|
trusts,
|
|
78
106
|
reacts,
|
|
107
|
+
open = true,
|
|
79
108
|
}: {
|
|
80
109
|
store: Store;
|
|
81
110
|
rules: Record<string, Rules>;
|
|
@@ -83,6 +112,8 @@ export function writes({
|
|
|
83
112
|
group: string;
|
|
84
113
|
trusts: Record<string, Trust>;
|
|
85
114
|
reacts: Record<string, Reactions>;
|
|
115
|
+
/** Whether the group is open (no ROOT_TOKEN): everyone is nobody, and what's granted any member is theirs. */
|
|
116
|
+
open?: boolean;
|
|
86
117
|
}) {
|
|
87
118
|
/** A document's rules: an instance of a kind's (shelf:1) are the kind's. */
|
|
88
119
|
const rulesOf = (doc: string) => rules[docParts(doc).name]!;
|
|
@@ -90,7 +121,36 @@ export function writes({
|
|
|
90
121
|
* holding an item by its own code) is as the grants say. */
|
|
91
122
|
const groupless = (doc: string, who: { member: number } | null | undefined) =>
|
|
92
123
|
!!(rulesOf(doc).anonymous || (!who && rulesOf(doc).guests));
|
|
93
|
-
|
|
124
|
+
/** The documents a rule reads, as they are now: each read once by the store (it waits for the database), then
|
|
125
|
+
* held while what asks it runs again; the rules themselves, the compiled ones, an app's trust.ts, its reactions and
|
|
126
|
+
* derive.ts, read as they always have, at once (settle). */
|
|
127
|
+
const reading = new AsyncLocalStorage<{ at: Read; wrote: boolean }>();
|
|
128
|
+
const read: Read = (doc, member) => {
|
|
129
|
+
const r = reading.getStore();
|
|
130
|
+
if (!r) throw new Error(`${doc} read outside settle`);
|
|
131
|
+
return r.at(doc, member);
|
|
132
|
+
};
|
|
133
|
+
/** What asks the documents (`fn`, at once, as the rules are), run until every document it reads is here: one it
|
|
134
|
+
* hasn't is read by the store, and it's asked again (it has changed nothing yet). Each settle reads afresh. */
|
|
135
|
+
async function settle<T>(fn: () => T): Promise<T> {
|
|
136
|
+
const held = new Map<string, Doc>();
|
|
137
|
+
const at: Read = (doc, member) => {
|
|
138
|
+
const d = held.get(`${doc}@${member ?? ""}`);
|
|
139
|
+
if (!d) throw new Missing(doc, member);
|
|
140
|
+
return d;
|
|
141
|
+
};
|
|
142
|
+
for (;;) {
|
|
143
|
+
const frame = { at, wrote: false };
|
|
144
|
+
try {
|
|
145
|
+
return await reading.run(frame, fn);
|
|
146
|
+
} catch (e) {
|
|
147
|
+
if (!(e instanceof Missing)) throw e;
|
|
148
|
+
// asked again, a route would write twice: it reads what it needs first
|
|
149
|
+
if (frame.wrote) throw new Error(`${e.doc} was read after a write: read every document before writing`);
|
|
150
|
+
held.set(`${e.doc}@${e.member ?? ""}`, await store.read(e.doc, e.member));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
94
154
|
|
|
95
155
|
/** The kind whose root's own document a page holds by an item's code (`boards?code=…`, a board's secret link, to
|
|
96
156
|
* draw the board): its guests name the root's code, given alone. None, held otherwise. */
|
|
@@ -117,7 +177,7 @@ export function writes({
|
|
|
117
177
|
return code && docParts(doc).params[code] !== undefined ? r.kind!.doc : rootKind(doc)?.kind!.doc;
|
|
118
178
|
};
|
|
119
179
|
/** Whether a document can be held: one of the store's, or a kind's root by an item's code. */
|
|
120
|
-
const exists = (doc: string) => store.exists(rootKind(doc) ? docParts(doc).base : doc);
|
|
180
|
+
const exists = (doc: string): Promise<boolean> => store.exists(rootKind(doc) ? docParts(doc).base : doc);
|
|
121
181
|
/** A document whole, as a person sees it (nobody: 0): all of it, but for one read as each member has it, or one
|
|
122
182
|
* each sees only some of (owns): its query, by its member; held by its root's code, all of it; the root's own held by
|
|
123
183
|
* an item's code, that item alone, past any owns (none: the code is no one's). */
|
|
@@ -129,13 +189,30 @@ export function writes({
|
|
|
129
189
|
item = codeItem(doc, k, whole);
|
|
130
190
|
return { version: whole.version, [k.kind!.root]: item ? [item] : [] };
|
|
131
191
|
}
|
|
132
|
-
return (r.member || r.sees) && !byCode(doc) ?
|
|
192
|
+
return (r.member || r.sees) && !byCode(doc) ? read(doc, member) : read(doc);
|
|
133
193
|
};
|
|
134
|
-
/** Whether what's granted anyone (member) is someone's: a member's
|
|
135
|
-
*
|
|
136
|
-
*
|
|
194
|
+
/** Whether what's granted anyone (member) is someone's: a member's; on an invite-only group, never a stranger's (a
|
|
195
|
+
* guest may do what's granted its guest alone); open, anyone's but a visitor who is nobody, holding an instance by its
|
|
196
|
+
* root's code at a level (src/visitors.ts), who may do what its level may alone, or the root's own by an item's
|
|
197
|
+
* code, where a guest may do nothing. */
|
|
137
198
|
const anyoneIs = (doc: string, member: number | null) =>
|
|
138
|
-
member !== null ||
|
|
199
|
+
member !== null || (open && (byCode(doc) ? !levelled(rulesOf(doc)) && !rootKind(doc) : !held(doc)));
|
|
200
|
+
/** Whether a page holds a document that isn't a kind by an item's code (`order?code=…`): its guest, who may do
|
|
201
|
+
* what a guest may, never what any member may. */
|
|
202
|
+
const held = (doc: string) => {
|
|
203
|
+
const { params } = docParts(doc);
|
|
204
|
+
return Object.values(rulesOf(doc).guests ?? {}).some((code) => params[code] !== undefined);
|
|
205
|
+
};
|
|
206
|
+
/** Whether the code a page holds a document by names one of its items: a made-up code holds nothing. */
|
|
207
|
+
const itsCode = (doc: string) => {
|
|
208
|
+
const { base, params } = docParts(doc),
|
|
209
|
+
whole = read(base);
|
|
210
|
+
return Object.entries(rulesOf(doc).guests ?? {}).some(
|
|
211
|
+
([coll, code]) =>
|
|
212
|
+
params[code] !== undefined &&
|
|
213
|
+
((whole[coll] ?? []) as Record<string, unknown>[]).some((i) => i[code] === params[code]),
|
|
214
|
+
);
|
|
215
|
+
};
|
|
139
216
|
|
|
140
217
|
/** Why a write does what no story does (an op of a form no path has, or one no story grants), or what the
|
|
141
218
|
* writer's roles may not; null if neither. `roles` null: the server's own write, or nobody's on an open group,
|
|
@@ -252,13 +329,17 @@ export function writes({
|
|
|
252
329
|
// granted any member, or anyone) and none moves it a step from where it is: said once, as "*"
|
|
253
330
|
const moved = r.moves?.[coll],
|
|
254
331
|
toItems = Object.entries(r.grants).filter(([g]) => itemToken(g, coll, {}, undefined) !== undefined);
|
|
332
|
+
// (nor where each item is one member's own, definitions' mine: another's is nobody else's to change)
|
|
333
|
+
const own = r.own?.[coll];
|
|
255
334
|
const same =
|
|
335
|
+
!own &&
|
|
256
336
|
(anyone || (everyone && toItems.every(([, to]) => to.includes("member")))) &&
|
|
257
337
|
!toItems.some(([g]) => moved && g.startsWith(`replace ${coll}.${moved}:`));
|
|
258
338
|
if (same) at["*"] = tokens(coll, {}, (g) => itemToken(g, coll, {}, moved));
|
|
259
339
|
else
|
|
260
340
|
for (const item of ((seen ??= view(doc, member ?? 0))[coll] ?? []) as Record<string, unknown>[])
|
|
261
|
-
at[String(item.id)] =
|
|
341
|
+
at[String(item.id)] =
|
|
342
|
+
own && item[own.by] !== member ? "" : tokens(coll, item, (g) => itemToken(g, coll, item, moved));
|
|
262
343
|
}
|
|
263
344
|
const said = Object.entries(at).filter(([, t]) => t);
|
|
264
345
|
if (said.length) may[coll] = Object.fromEntries(said);
|
|
@@ -325,6 +406,80 @@ export function writes({
|
|
|
325
406
|
}
|
|
326
407
|
return null;
|
|
327
408
|
}
|
|
409
|
+
/** Why a write names someone in a link who doesn't hold the role it names only holders of (definitions' links,
|
|
410
|
+
* holds: a supply's supplier, a seller), or null: each id it gives the field, as an item's or the field's own. */
|
|
411
|
+
function namedIn(doc: string, ops: Op[]) {
|
|
412
|
+
const r = rulesOf(doc);
|
|
413
|
+
if (!r.names) return null;
|
|
414
|
+
for (const o of ops) {
|
|
415
|
+
if (o.op === "remove") continue;
|
|
416
|
+
const { field } = parts(o.path);
|
|
417
|
+
// a field given its value, or an item given whole (an add, a replace)
|
|
418
|
+
const given: [string, unknown][] = field !== undefined ? [[field, o.value]] : Object.entries(o.value ?? {});
|
|
419
|
+
for (const [f, v] of given) {
|
|
420
|
+
const [is, refused] = r.names[f] ?? [];
|
|
421
|
+
if (is && [v ?? []].flat().some((id) => typeof id === "number" && !is(id, read, doc))) return refused!;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
return null;
|
|
425
|
+
}
|
|
426
|
+
/** Why a write links to what the document it's written to doesn't hold (a comment on another board's post, which
|
|
427
|
+
* nobody there could see, nor then remove the post), or null: each id it gives a link to one of the document's own
|
|
428
|
+
* collections is of an item in it, as the write leaves it (so one it adds is): in a kind, its instance's; held by an
|
|
429
|
+
* item's code, what the code holds. Its words, the table's. */
|
|
430
|
+
function beyond(doc: string, applied: Op[], member: number) {
|
|
431
|
+
const r = rulesOf(doc),
|
|
432
|
+
guest = byCode(doc) || held(doc);
|
|
433
|
+
let holds: Doc | undefined;
|
|
434
|
+
for (const o of applied) {
|
|
435
|
+
if (o.op === "remove") continue;
|
|
436
|
+
const { coll, field, link } = parts(o.path),
|
|
437
|
+
value = link !== undefined && /^[a-z]/.test(link) ? { [link]: o.value } : o.value,
|
|
438
|
+
item = field === undefined ? value : { [field]: value };
|
|
439
|
+
for (const [f, to] of Object.entries(r.collections[coll]?.links ?? {})) {
|
|
440
|
+
// (an object's field, terms.item)
|
|
441
|
+
const v = f.split(".").reduce<any>((at, k) => at?.[k], item);
|
|
442
|
+
if (v == null || !(to in r.collections)) continue;
|
|
443
|
+
const items = ((holds ??= guest ? view(doc, member) : read(docParts(doc).base))[to] ?? []) as { id: number }[];
|
|
444
|
+
if ([v].flat().some((id) => !items.some((i) => i.id === id)))
|
|
445
|
+
return `${f} links only to ${to} the ${r.doc} document holds`;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
return null;
|
|
449
|
+
}
|
|
450
|
+
/** Why a write gives or takes another's id in a list that's each member's own (definitions' mine), or null: an id
|
|
451
|
+
* added or taken, a list replaced or removed whole (the ids that changes), or an item added with one. */
|
|
452
|
+
function othersIn(doc: string, ops: Op[], member: number) {
|
|
453
|
+
for (const o of ops) {
|
|
454
|
+
const { coll, key, field, link } = parts(o.path);
|
|
455
|
+
for (const f of rulesOf(doc).mine?.[coll] ?? []) {
|
|
456
|
+
if (field === undefined ? o.op !== "add" : field !== f) continue;
|
|
457
|
+
// a list's ids, or a link's one
|
|
458
|
+
const ids = (v: unknown): number[] => [v ?? []].flat() as number[];
|
|
459
|
+
const had = ids(key !== "-" && link === undefined ? itemAt(doc, o)?.[f] : undefined);
|
|
460
|
+
const has = ids(o.op !== "remove" ? (field === undefined ? o.value?.[f] : o.value) : undefined);
|
|
461
|
+
const changed =
|
|
462
|
+
link !== undefined
|
|
463
|
+
? [o.op === "add" ? o.value : Number(link)]
|
|
464
|
+
: [...had, ...has].filter((m) => had.includes(m) !== has.includes(m));
|
|
465
|
+
if (changed.some((m) => m !== member))
|
|
466
|
+
return rulesOf(doc).mineSaid?.[coll]?.[f] ?? `${f} is each member's own to give`;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return null;
|
|
470
|
+
}
|
|
471
|
+
/** Why a write changes or removes another's value in a collection that's each member's own (definitions' mine,
|
|
472
|
+
* { of, by }), or null: an add is its writer's, whose it is being the server's to fill. */
|
|
473
|
+
function othersOwn(doc: string, ops: Op[], member: number) {
|
|
474
|
+
for (const o of ops) {
|
|
475
|
+
const { coll, key } = parts(o.path);
|
|
476
|
+
const own = rulesOf(doc).own?.[coll];
|
|
477
|
+
if (!own || key === "-") continue;
|
|
478
|
+
const whose = itemAt(doc, o)?.[own.by];
|
|
479
|
+
if (whose !== undefined && whose !== member) return `${coll} are each member's own to change`;
|
|
480
|
+
}
|
|
481
|
+
return null;
|
|
482
|
+
}
|
|
328
483
|
/** The items each collection's ops touched, by id: an add's the id it was given. */
|
|
329
484
|
function touchedBy(ops: Op[]) {
|
|
330
485
|
const touched: Record<string, number[]> = {};
|
|
@@ -339,13 +494,27 @@ export function writes({
|
|
|
339
494
|
btoa(String.fromCharCode(...crypto.getRandomValues(new Uint8Array(9))))
|
|
340
495
|
.replace(/\+/g, "-")
|
|
341
496
|
.replace(/\//g, "_");
|
|
342
|
-
/**
|
|
343
|
-
*
|
|
497
|
+
/** Now, on the clock of the zone a wall clock is on (the first said of its collection's clock: the item's own, its
|
|
498
|
+
* kind's root's, the document's own), or refused: there's none to say it on. */
|
|
499
|
+
function wallNow(doc: string, coll: string, f: string, value: Record<string, unknown>) {
|
|
500
|
+
const r = rulesOf(doc);
|
|
501
|
+
const zone = r.collections[coll]!.clock!.map(
|
|
502
|
+
(c) => (c === "item" ? value : c === "root" ? rootItem(r, doc, read) : read(doc))?.zone,
|
|
503
|
+
).find((z) => z !== undefined);
|
|
504
|
+
if (zone === undefined) throw new Refused(`${f} is now on its zone's clock, and no zone is said`);
|
|
505
|
+
try {
|
|
506
|
+
return wallIn(zone as string);
|
|
507
|
+
} catch {
|
|
508
|
+
throw new Refused(`${f} is now on its zone's clock, and ${zone} isn't a time zone`);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
/** A write's adds with the fields the server fills, where they don't give them: "now" is the instant (a wall clock,
|
|
512
|
+
* where the field is one), "random" a code no one can guess, "me" its writer (`by`); and those
|
|
344
513
|
* copied from what a link points at, as it is now (none, where it points at nothing: the table refuses that). */
|
|
345
514
|
function fill(doc: string, ops: Op[], by: number | null) {
|
|
346
515
|
return ops.map((o) => {
|
|
347
516
|
const { coll, key, field } = parts(o.path);
|
|
348
|
-
const { fills, copies } = rulesOf(doc).collections[coll] ?? {};
|
|
517
|
+
const { fills, copies, fields } = rulesOf(doc).collections[coll] ?? {};
|
|
349
518
|
if (copies && o.op === "add" && key === "-" && field === undefined) {
|
|
350
519
|
const from = (read(copies.at)[copies.to] as Record<string, unknown>[]).find(
|
|
351
520
|
(i) => i.id === o.value?.[copies.from],
|
|
@@ -360,7 +529,15 @@ export function writes({
|
|
|
360
529
|
...Object.fromEntries(
|
|
361
530
|
Object.entries(fills).map(([f, v]) => [
|
|
362
531
|
f,
|
|
363
|
-
v === "now"
|
|
532
|
+
v === "now"
|
|
533
|
+
? fields![f] === "date-time"
|
|
534
|
+
? wallNow(doc, coll, f, o.value ?? {})
|
|
535
|
+
: now
|
|
536
|
+
: v === "random"
|
|
537
|
+
? random()
|
|
538
|
+
: v === "me"
|
|
539
|
+
? by
|
|
540
|
+
: v,
|
|
364
541
|
]),
|
|
365
542
|
),
|
|
366
543
|
...o.value,
|
|
@@ -417,7 +594,9 @@ export function writes({
|
|
|
417
594
|
: byCode(doc) && !admits(r, guestOf(doc, r.kind!.root, undefined))
|
|
418
595
|
)
|
|
419
596
|
return "No access";
|
|
420
|
-
|
|
597
|
+
// an item's code that names none of its items: No access, as a kind's is
|
|
598
|
+
if (!k && !byCode(doc) && held(doc) && !itsCode(doc)) return "No access";
|
|
599
|
+
const guest = byCode(doc) || held(doc);
|
|
421
600
|
if (member === null && !open && !r.anonymous && !guest) return "sign in with your link first";
|
|
422
601
|
if (r.mayHold && !guest && !(member !== null && r.rolesOf!(member, read, doc).some((x) => r.mayHold!.includes(x))))
|
|
423
602
|
return "No access";
|
|
@@ -428,46 +607,65 @@ export function writes({
|
|
|
428
607
|
* what the stories do, and what the writer's roles may (the grants); of a kind, its root item's settings
|
|
429
608
|
* (src/settings.ts), so only someone the grants allow hears their words; and the group's rules, which say what lands
|
|
430
609
|
* with it (`within`). A derived document, or one read as each member has it, is written where it's read from. */
|
|
431
|
-
function ask(
|
|
610
|
+
async function ask(
|
|
432
611
|
doc: string,
|
|
433
612
|
ops: Op[],
|
|
434
613
|
why: string | undefined,
|
|
435
614
|
who: { member: number } | null,
|
|
436
|
-
group: (
|
|
615
|
+
group: (
|
|
616
|
+
doc: string,
|
|
617
|
+
ops: Op[],
|
|
618
|
+
) =>
|
|
619
|
+
| { ops: Op[]; within?: (applied: Op[]) => unknown }
|
|
620
|
+
| { refused: string }
|
|
621
|
+
| Promise<{ ops: Op[]; within?: (applied: Op[]) => unknown } | { refused: string }>,
|
|
437
622
|
undoing = false,
|
|
438
623
|
) {
|
|
439
624
|
const r = rulesOf(doc);
|
|
440
625
|
if (r.derived) throw new Refused(`${doc} is derived from ${r.derived.join(" and ")}: write that`);
|
|
441
626
|
if (r.member) throw new Refused(`${doc} is read off ${r.reads!.join(", ")}: write those`);
|
|
442
|
-
const roles = who ? r.rolesOf!(who.member, read, doc) : [];
|
|
443
627
|
// an anonymous document's writes are anyone's; any other's, each op's by who the writer is to its item
|
|
444
|
-
const ruled =
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
doc,
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
(
|
|
462
|
-
|
|
628
|
+
const ruled = await settle(() => {
|
|
629
|
+
const roles = who ? r.rolesOf!(who.member, read, doc) : [];
|
|
630
|
+
return (
|
|
631
|
+
trusts[r.doc]?.({ doc: docParts(doc).base, ops, why }, { member: who?.member ?? 0, roles }, read) ??
|
|
632
|
+
othersIn(doc, ops, who?.member ?? 0) ??
|
|
633
|
+
othersOwn(doc, ops, who?.member ?? 0) ??
|
|
634
|
+
// (an undo puts back what the server filled, as it was)
|
|
635
|
+
(undoing ? null : serversIn(doc, ops)) ??
|
|
636
|
+
// who the writer is to the item each op is to: a member's roles, and a guest's (a page holding the document by
|
|
637
|
+
// the item's own code: definitions' guests)
|
|
638
|
+
ungranted(
|
|
639
|
+
doc,
|
|
640
|
+
ops,
|
|
641
|
+
!who && r.anonymous ? null : (o) => rolesTo(doc, who?.member ?? null, parts(o.path).coll, itemAt(doc, o)),
|
|
642
|
+
anyoneIs(doc, who?.member ?? null),
|
|
643
|
+
undoing,
|
|
644
|
+
) ??
|
|
645
|
+
namedIn(doc, ops) ??
|
|
646
|
+
// of a kind, what its root item's settings say of a write the grants allow (a frozen board, one held for approval)
|
|
647
|
+
settled(
|
|
648
|
+
r,
|
|
649
|
+
// (an undo puts an item back at the step it had come to: frozen alone refuses it)
|
|
650
|
+
((now) => (undoing ? { ...now, first: {} } : now))(settingsNow(r, () => rootItem(r, doc, read))),
|
|
651
|
+
ops,
|
|
652
|
+
)
|
|
463
653
|
);
|
|
654
|
+
});
|
|
464
655
|
if (ruled) throw new Refused(ruled);
|
|
465
656
|
// a code it makes new, the server's (whatever the page gave), before it's kept
|
|
466
657
|
ops = renewed(doc, ops);
|
|
467
|
-
|
|
468
|
-
const write = group(docParts(doc).base, ops);
|
|
658
|
+
const write = groupless(doc, who) ? { ops } : await group(docParts(doc).base, ops);
|
|
469
659
|
if ("refused" in write) throw new Refused(write.refused);
|
|
470
|
-
|
|
660
|
+
// of a kind's instance, or held by an item's code, it links to nothing another holds: asked of it as made, before
|
|
661
|
+
// it's kept
|
|
662
|
+
if (!r.kind && !byCode(doc) && !held(doc)) return write;
|
|
663
|
+
const within = async (applied: Op[]) => {
|
|
664
|
+
const why = await settle(() => beyond(doc, applied, who?.member ?? 0));
|
|
665
|
+
if (why) throw new Refused(why);
|
|
666
|
+
if ("within" in write) await write.within?.(applied);
|
|
667
|
+
};
|
|
668
|
+
return { ops: write.ops, within };
|
|
471
669
|
}
|
|
472
670
|
|
|
473
671
|
/** A write and what follows from it (each app's reactions, round after round until none writes), in one
|
|
@@ -475,34 +673,57 @@ export function writes({
|
|
|
475
673
|
* turn, named by the adds before it. Its changes, the first the document written first's; each part's own (`parts`);
|
|
476
674
|
* what's told to each part of a document the pages hold (`held`); and the ops as its parts made them. `asked`: a
|
|
477
675
|
* page's write, each part asked its rules first, in the transaction; `undoes`, the version the write puts back, if
|
|
478
|
-
* it's an undo
|
|
479
|
-
|
|
676
|
+
* it's an undo; `kept`, the id a page gave a write it kept while away, kept with the first part's change (whose
|
|
677
|
+
* version is the write's). */
|
|
678
|
+
async function land(
|
|
480
679
|
writes: Part[],
|
|
481
680
|
by: number | null,
|
|
482
681
|
via: string | null,
|
|
483
682
|
{
|
|
484
683
|
undoes,
|
|
684
|
+
kept,
|
|
485
685
|
asked,
|
|
486
686
|
held,
|
|
487
687
|
}: {
|
|
488
688
|
undoes?: number;
|
|
489
|
-
|
|
689
|
+
kept?: string;
|
|
690
|
+
asked?: (doc: string, ops: Op[], why?: string) => Promise<{ ops: Op[]; within?: (applied: Op[]) => unknown }>;
|
|
490
691
|
held: Held;
|
|
491
692
|
},
|
|
492
693
|
) {
|
|
493
|
-
return store.db.transaction(() => {
|
|
694
|
+
return store.db.transaction(async () => {
|
|
695
|
+
// one a page kept while away, made already: looked for as it's made, in the same transaction, so two sent at
|
|
696
|
+
// once (two tabs, two servers) make it once
|
|
697
|
+
const made = kept === undefined ? undefined : await store.keptAs(kept);
|
|
698
|
+
if (made !== undefined) throw new Made(made);
|
|
494
699
|
// what each person holding a part of a document saw of it, before
|
|
495
|
-
const before = new Map(held.views.map((v) => [v.topic, view(v.doc, v.member)]));
|
|
700
|
+
const before = await settle(() => new Map(held.views.map((v) => [v.topic, view(v.doc, v.member)])));
|
|
496
701
|
const changes: Change[] = [],
|
|
497
702
|
rows: Record<string, Row[]> = {},
|
|
498
703
|
applied: Op[] = [],
|
|
499
704
|
own: Change[] = [];
|
|
500
|
-
const one =
|
|
705
|
+
const one = async (
|
|
706
|
+
d: string,
|
|
707
|
+
o: Op[],
|
|
708
|
+
b: number | null,
|
|
709
|
+
v: string | null,
|
|
710
|
+
w?: (applied: Op[]) => unknown,
|
|
711
|
+
u?: number,
|
|
712
|
+
k?: string,
|
|
713
|
+
) => {
|
|
501
714
|
// (an undo puts back what was, filled as it was then: a field cleared since stays clear)
|
|
502
|
-
const gone = withGone(d, o);
|
|
503
|
-
const
|
|
715
|
+
const gone = await settle(() => withGone(d, o));
|
|
716
|
+
const filled = u === undefined ? await settle(() => fill(d, gone, b)) : gone;
|
|
717
|
+
const made = await store.write(d, filled, b, v, w, { undoes: u, kept: k });
|
|
504
718
|
// what the definitions hold of it (unique, noOverlap), once the write is done: refused whole if not
|
|
505
|
-
const
|
|
719
|
+
const r = rulesOf(d),
|
|
720
|
+
touched = touchedBy(made.applied);
|
|
721
|
+
// (unique and noOverlap among every row of a collection's table, not only those its where holds)
|
|
722
|
+
const all: Record<string, Awaited<ReturnType<Store["rowsOf"]>>> = {};
|
|
723
|
+
if (r.holds) for (const c of Object.keys(touched)) all[c] = await store.rowsOf(d, c);
|
|
724
|
+
const held = await settle(
|
|
725
|
+
() => r.holds?.(all, touched) ?? (store.db.dialect === "sqlite" ? r.listsHold?.(read(d), touched) : null),
|
|
726
|
+
);
|
|
506
727
|
if (held) throw new Refused(held);
|
|
507
728
|
for (const [name, r] of Object.entries(made.rows)) (rows[name] ??= []).push(...r);
|
|
508
729
|
// a document read as each member has it moves its version with what it reads
|
|
@@ -511,36 +732,43 @@ export function writes({
|
|
|
511
732
|
const tables = new Set(made.tables);
|
|
512
733
|
for (const r of Object.values(rules))
|
|
513
734
|
if (r.reads?.some((t) => tables.has(t)) && !made.changes.some((c) => c.doc === r.doc))
|
|
514
|
-
changes.push({ doc: r.doc, version: store.moved(r.doc), ops: [], by: b, via: v });
|
|
735
|
+
changes.push({ doc: r.doc, version: await store.moved(r.doc), ops: [], by: b, via: v });
|
|
515
736
|
return made;
|
|
516
737
|
};
|
|
517
738
|
let next: Change[] = [];
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
739
|
+
// each part named as the write names it (src/together.ts), and landed in turn
|
|
740
|
+
const adds: { coll: string; id: number }[] = [];
|
|
741
|
+
for (const part of writes) {
|
|
742
|
+
const w = named(
|
|
743
|
+
part,
|
|
744
|
+
adds,
|
|
745
|
+
(name) => rules[name]?.kind?.root,
|
|
746
|
+
(name) => rules[name]?.collections,
|
|
747
|
+
);
|
|
748
|
+
// a page's write is asked first, here: refused, none of it lands
|
|
749
|
+
const { ops, within } = (await asked?.(w.doc, w.ops, w.why)) ?? { ops: w.ops };
|
|
750
|
+
const made = await one(docParts(w.doc).base, ops, by, via, within, undoes, own.length ? undefined : kept);
|
|
751
|
+
applied.push(...made.applied);
|
|
752
|
+
own.push(made.changes[0]!);
|
|
753
|
+
next.push(...made.changes);
|
|
754
|
+
for (const o of made.applied)
|
|
755
|
+
if (o.op === "add" && parts(o.path).key === "-" && parts(o.path).field === undefined)
|
|
756
|
+
adds.push({ coll: parts(o.path).coll, id: o.value.id });
|
|
757
|
+
}
|
|
531
758
|
for (let round = 0; next.length; round++) {
|
|
532
759
|
if (round === ROUNDS) throw new Error(`what follows from a write to ${writes[0]!.doc} never settles`);
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
760
|
+
const now: Change[] = [];
|
|
761
|
+
for (const c of next) {
|
|
762
|
+
const follows = await settle(() => reacts[docParts(c.doc).name]?.(c, read) ?? []);
|
|
763
|
+
for (const w of follows.filter((w) => w.ops.length)) {
|
|
764
|
+
if (docParts(w.doc).name === group || !(await store.exists(w.doc)))
|
|
765
|
+
throw new Error(`a reaction can't write ${w.doc}`);
|
|
766
|
+
const why = await settle(() => ungranted(w.doc, w.ops, null));
|
|
767
|
+
if (why) throw new Error(`a reaction wrote what no story does: ${why}`);
|
|
768
|
+
now.push(...(await one(w.doc, w.ops, null, null)).changes);
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
next = now;
|
|
544
772
|
}
|
|
545
773
|
const last = (name: string) => changes.findLast((c) => c.doc === name)?.version;
|
|
546
774
|
const told: Told = [];
|
|
@@ -565,14 +793,34 @@ export function writes({
|
|
|
565
793
|
for (const { topic, doc: d, member } of held.views) {
|
|
566
794
|
const version = last(docParts(d).base);
|
|
567
795
|
if (version === undefined) continue;
|
|
568
|
-
const ops = docOps(before.get(topic)!, view(d, member));
|
|
796
|
+
const ops = docOps(before.get(topic)!, await settle(() => view(d, member)));
|
|
569
797
|
if (ops.length) told.push({ topic, change: { doc: d, version, ops, by, via } });
|
|
570
798
|
}
|
|
571
799
|
return { changes, told, applied, parts: own };
|
|
572
|
-
})
|
|
800
|
+
});
|
|
573
801
|
}
|
|
574
802
|
|
|
575
|
-
return {
|
|
803
|
+
return {
|
|
804
|
+
land,
|
|
805
|
+
ask,
|
|
806
|
+
/** A document as a person sees it (view), read as it is now. */
|
|
807
|
+
view: (doc: string, member: number) => settle(() => view(doc, member)),
|
|
808
|
+
ungranted: (...args: Parameters<typeof ungranted>) => settle(() => ungranted(...args)),
|
|
809
|
+
mayOf: (doc: string, member: number | null) => settle(() => mayOf(doc, member)),
|
|
810
|
+
mayHold: (doc: string, member: number | null, open: boolean) => settle(() => mayHold(doc, member, open)),
|
|
811
|
+
/** A document read as it is now, whole, or as a member has it. */
|
|
812
|
+
read: (doc: string, member?: number) => store.read(doc, member),
|
|
813
|
+
/** What asks the documents (the rules, an app's derive.ts), given them as they are now. */
|
|
814
|
+
settle: <T>(fn: (read: Read) => T) => settle(() => fn(read)),
|
|
815
|
+
/** The documents read at once, as the rules read them: only inside settle. */
|
|
816
|
+
now: read,
|
|
817
|
+
/** A write made inside settle (a route's): a document read after it can't be asked again. */
|
|
818
|
+
wrote: () => void (reading.getStore() && (reading.getStore()!.wrote = true)),
|
|
819
|
+
rulesOf,
|
|
820
|
+
groupless,
|
|
821
|
+
byCode,
|
|
822
|
+
exists,
|
|
823
|
+
};
|
|
576
824
|
}
|
|
577
825
|
|
|
578
826
|
/** A grant as an item's `may` token (mayOf), or undefined where it isn't one to an item: `remove orders` is "remove",
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Where this app has been, newest first, a line in its entry as each change lands; what's open is in `todo.jsonl`.
|
|
4
|
+
|
|
5
|
+
## [Unreleased]
|
|
6
|
+
|
|
7
|
+
- **Begun from `bun create joined`**: hello, the joined skill, the scripts, and the record (this, `todo.jsonl`, and
|
|
8
|
+
`.githooks/pre-commit`, which refuses a commit that carries neither).
|
package/starter/CLAUDE.md
CHANGED
|
@@ -14,6 +14,8 @@ only the section of its `reference.md` your task needs. joined's own files (`src
|
|
|
14
14
|
- `apps/members.json`, once an app has members: the group's seed, its people by id and name (§11 of the skill).
|
|
15
15
|
- `tests/`: each app's stories told (`joined/stories`), its page's in a browser (`hello-page.test.ts`), and
|
|
16
16
|
anything else of the app's own.
|
|
17
|
+
- The record: `CHANGELOG.md` (where this app has been) and `todo.jsonl` (what's open, a JSON object a line, each
|
|
18
|
+
with its number, `n`).
|
|
17
19
|
- What the pages change is kept in `.data/` (`JOINED_DATA`); `.env` holds `ROOT_TOKEN` once an app has members.
|
|
18
20
|
|
|
19
21
|
## Rules
|
|
@@ -24,14 +26,18 @@ only the section of its `reference.md` your task needs. joined's own files (`src
|
|
|
24
26
|
- **The light DOM is the document; the shadow DOM is the display.** Only joined's applier writes a document's
|
|
25
27
|
elements; a view or a display changes one only through its element's ops. A display moves only what changed.
|
|
26
28
|
- **One concept a file, named for it, under 250 lines;** a display is a file that composes its parts (joined's
|
|
27
|
-
`examples/trip/
|
|
29
|
+
`examples/trip/line.ts`, a reading of the kit's).
|
|
28
30
|
- **An element is defined last in its module,** and a document's elements are named by the compiler's
|
|
29
31
|
collections, never by a tag typed out.
|
|
30
32
|
- **Never put `.env`, `.data/` or anyone's link in a commit,** nor in chat.
|
|
31
33
|
- **Look at a change in the page** (`bun run dev`) before calling it done. `dev` runs a demo on this machine: an
|
|
32
34
|
app's home page carries `<joined-demo>` (`import "joined/demo"`), a line to be anyone in the group, the BDFL first,
|
|
33
35
|
so looking as Nora always has a way back. The live site is never a demo.
|
|
34
|
-
- **The
|
|
35
|
-
`bun
|
|
36
|
+
- **The record.** Every commit stages `CHANGELOG.md` or `todo.jsonl` beside its change (`.githooks/pre-commit`
|
|
37
|
+
refuses one without; `bun install` wires it): a small fix is a line in the entry it belongs to. Every "Not yet" in
|
|
38
|
+
the CHANGELOG names its todo (`todo 4`), each part of it (`tests/records.test.ts`). When later work makes an entry
|
|
39
|
+
untrue, a new entry says so, and the old one stands. Never `--no-verify`.
|
|
40
|
+
- **The gate**, before a commit: `bun check` (the types: a link to one member may be none, once they've left),
|
|
41
|
+
`bun fmt --check` (`bun fmt` to format; what the compiler writes is left alone, `.prettierignore`) and `bun test`.
|
|
36
42
|
- **joined is upgraded by `bun run upgrade [version]`:** it moves the version, refreshes the skill and
|
|
37
43
|
compiles again.
|