@blueshed/joined 0.3.5 → 0.3.7
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/reference.md +27 -4
- package/.claude/skills/joined-door/SKILL.md +1 -1
- package/docs/stories.md +2 -0
- package/examples/cafe/generated/supplies.rules.ts +2 -0
- package/examples/cafe/stories.jsonl +3 -0
- package/package.json +1 -1
- package/src/compile.ts +33 -5
- package/src/definitions.ts +148 -45
- package/src/mcp.ts +29 -9
- package/src/server.ts +37 -8
- package/src/skill.ts +19 -10
- package/src/stories.ts +23 -6
- package/src/upload.ts +2 -1
- package/src/write.ts +19 -1
|
@@ -444,11 +444,19 @@ export const routes = (read: Read) => ({ "/trip/:n": page, "/trip/:n/trip.ics":
|
|
|
444
444
|
- **An open route** (`export const open = (read) => ({ "/card/:id": (req) => … })`) is anyone's, never guarded by
|
|
445
445
|
the group: a link's preview (og:title, og:image), a card for a stranger. Its `read` is as nobody (member 0):
|
|
446
446
|
owns and sees apply, so a part only some see isn't there, but the group's door doesn't: a document any member
|
|
447
|
-
sees whole is whole. So an open route shows only what it picks, and what it picks is public.
|
|
447
|
+
sees whole is whole. So an open route shows only what it picks, and what it picks is public. One that checks a
|
|
448
|
+
secret of its own (a mail's intake, a webhook) takes the server's `write` and `whole` too
|
|
449
|
+
(`open = (read, write, whole) => …`): `whole(doc)` is every item, as the server holds it, for it to find what it
|
|
450
|
+
needs (whose address a mail came to); what it answers is still its own to pick (`tests/apart/board/routes.ts`).
|
|
448
451
|
- **Two apps answering one path** are refused at start, open routes too.
|
|
449
452
|
- **The server writes** with the `write` a routes function is given beside `read` (`routes(read, write)`):
|
|
450
453
|
a webhook, an import, a job on the app's own timer. `write(doc, ops)` is shaped by the stories (only what
|
|
451
454
|
a story does), never asked of roles or `trust.ts`, by nobody, and told as any write; it throws `Refused`.
|
|
455
|
+
`write(doc, ops, { member, via, why, file })` is a member's write in place of nobody's (a paper a mail brought,
|
|
456
|
+
its member's): asked of their grants, the app's trust and the group's, as an agent's is, a member still in the
|
|
457
|
+
group; its change says `via` (a page shows "Peter via mail"), and its `why`; a `file` (`{ bytes, name }`) is kept
|
|
458
|
+
first, as a page's is (where they may put one, apart where the kind keeps them so), `"$file"` in the ops standing
|
|
459
|
+
for its value; answered `{ done, version, ids, file }`.
|
|
452
460
|
Never the group's document, and never a document's content from files at start: that's its seed (§13).
|
|
453
461
|
- **What follows from a write** is a rule over values where a definition can say it (`takes`: an order
|
|
454
462
|
taking stock, in the database, undone as the write is), and otherwise
|
|
@@ -620,8 +628,9 @@ Working: `src/icons.ts`; the members panel and every example.
|
|
|
620
628
|
kind's take `key`; a window isn't one (read the document). The door carries its own skill, how any document is
|
|
621
629
|
read and written there (`.claude/skills/joined-door/SKILL.md`, the one text, `src/skill.ts`): by MCP's skills
|
|
622
630
|
extension (`io.modelcontextprotocol/skills`, declared in `server/discover`; `skills/list`, `skills/get`, the
|
|
623
|
-
resource `skill://joined-door/SKILL.md`), and
|
|
624
|
-
|
|
631
|
+
resource `skill://joined-door/SKILL.md`), and by `read_skill`, a tool, which every client loads. Its instructions
|
|
632
|
+
are a few lines to every client, so none cuts them off (`opening`): its documents, who the agent acts as (its
|
|
633
|
+
member's id, so a field linking members is read), and where the skills are; nothing a skill says. Beside it each app has a skill of its own, served the same way
|
|
625
634
|
(`skill://<app>/SKILL.md`, written by `skillOf`): its words, then what each of its documents holds (its fields' types,
|
|
626
635
|
what a link is an id of, what an add needs, its tools), from the compiled rules as the tools are. Its words are its
|
|
627
636
|
`routes.ts`'s `instructions` (`examples/trip/routes.ts`), what's its own alone (what its documents mean, its people,
|
|
@@ -840,6 +849,12 @@ Working: `src/members/`; `tests/sign-in.test.ts`; `tests/mcp.test.ts` (the door)
|
|
|
840
849
|
stories: a `does` grants its ops to its teller's named role as the story finds them, its premise written on the
|
|
841
850
|
seeds (none: anyone).
|
|
842
851
|
The grants refuse the rest, in the write's transaction: "you may not add at /accounts/-".
|
|
852
|
+
A who-path follows a link to what it names: `[of=@]` is the item it's asked of, `[role=director,accountant]`
|
|
853
|
+
any of those, and `@who>…` asks the item `who` links to whatever follows, a term or a group in brackets. Who
|
|
854
|
+
keeps a firm, by its ties: `@member | firms/ties[of=@][role=director,accountant]@who>(@member |
|
|
855
|
+
firms/ties[of=@][role=employee]@who>@member)`, its own member, a director, an accountant and who works there.
|
|
856
|
+
Say it as one role, as the chain is written out: a role inside another would make a teller two roles to the
|
|
857
|
+
same item. `tests/fixtures/firms`, `tests/fixtures/firm`.
|
|
843
858
|
- `owns`: who sees what, one who-path for the document or one per collection (`@members` is the item's
|
|
844
859
|
own). A page is sent whole, and told, only what its person sees: an item they come to see is added to
|
|
845
860
|
their page, and one they see no longer (or that's gone) is removed. Back from away, it's sent whole again.
|
|
@@ -940,6 +955,14 @@ Working: `src/members/`; `tests/sign-in.test.ts`; `tests/mcp.test.ts` (the door)
|
|
|
940
955
|
- `addedWith`: an item added only in the write adding what a link of it points at, never after: `{"addedWith":
|
|
941
956
|
{"lines": {"order": "an order's lines are set when it's placed"}}}`. A trigger, in both: the item linked to is one
|
|
942
957
|
the write added (the rows a write changed, `joined_touched`).
|
|
958
|
+
- `person`: what's a person's alone, whatever their agent may otherwise do: `{"person": {"supplies": {"add": "an
|
|
959
|
+
order to a supplier is a person's to place"}}}`, by collection, each op (`add`, `remove`, or with its field:
|
|
960
|
+
`"replace price"`, `"add people[]"`) and its words. A write made via anything (the member's agent's link at the MCP
|
|
961
|
+
door, a route's write as a member) is refused in them, after the grants; on their own page it goes as the grants
|
|
962
|
+
say. Checked by a `cannot` story told `via` (`"as": "buyer", "via": "claude"`: sent by an agent's link made for the
|
|
963
|
+
teller, under that label), refused in its words; a `does` told `via` shows what an agent still may. Working: the
|
|
964
|
+
cafe's supplies. Not yet: a move to one value (`status>approved`), and the door's tools and `may` leaving the op
|
|
965
|
+
out (#259).
|
|
943
966
|
- `within` and `apart`: an item's lists as the write leaves them. `{"within": {"events": [{"lists": ["keen", "asked",
|
|
944
967
|
"declined"], "of": "people", "refused": "an answer is from someone on the event"}]}}`: each id of those lists is in
|
|
945
968
|
its `of` list too; `{"apart": {"events": [{"lists": ["keen", "asked", "declined"], "refused": "one answer each"}]}}`:
|
|
@@ -965,7 +988,7 @@ Working: `src/members/`; `tests/sign-in.test.ts`; `tests/mcp.test.ts` (the door)
|
|
|
965
988
|
when the group is open too, of nobody (`member` 0). The compiler can't read it, so write a `cannot` story,
|
|
966
989
|
`refused` in its words, for each rule in it: the stories told say so of one that refuses nothing they tell
|
|
967
990
|
(`<app>'s trust.ts refuses nothing its stories tell`), and no more than that. Look first for a definition that
|
|
968
|
-
says it (`mine`, `unique`, `noOverlap`, `notEmpty`, `moves`, `takes`, `frozen`, `addedWith`, `within`, `apart`): the examples
|
|
991
|
+
says it (`mine`, `unique`, `noOverlap`, `notEmpty`, `moves`, `takes`, `frozen`, `addedWith`, `within`, `apart`, `person`): the examples
|
|
969
992
|
have no `trust.ts` (Peter, 30 Nov: their rules said once, the database's on Postgres). One that truly can't be
|
|
970
993
|
declared is a trigger in each dialect's SQL, not TypeScript.
|
|
971
994
|
- **A story's words for them:** `premise` (each name's writes before it, in order; an anonymous story's, a list), `unseen` (who must not
|
|
@@ -9,7 +9,7 @@ An app on joined keeps its documents, and every page open on them, in step. Its
|
|
|
9
9
|
document your link may hold: `read_<doc>` and `write_<doc>` (a document you can't write has only its read). Their
|
|
10
10
|
descriptions say what each document holds and each op it takes: read them, they're written from the app's own rules.
|
|
11
11
|
A document that names files has `upload_<doc>` too. Each app has a skill of its own beside this one: its words, and
|
|
12
|
-
what each of its documents holds.
|
|
12
|
+
what each of its documents holds. Where your client doesn't load skills, `read_skill` reads any of them whole.
|
|
13
13
|
|
|
14
14
|
## Read first
|
|
15
15
|
|
package/docs/stories.md
CHANGED
|
@@ -50,6 +50,7 @@ Members add who writes, who sees, and who mustn't:
|
|
|
50
50
|
line := cast | story
|
|
51
51
|
cast := { "cast": { name: member | null, … } }
|
|
52
52
|
story += { "as": name,
|
|
53
|
+
"via"?: label, an agent's link's label: a-z, 0-9, spaces, hyphens
|
|
53
54
|
"seen"?: [name], "unseen"?: [name],
|
|
54
55
|
"premise"?: { name: [write] } } in place of the core's [write]
|
|
55
56
|
write += { "why"?: words }
|
|
@@ -59,6 +60,7 @@ name := a member's name, or a cast name
|
|
|
59
60
|
| Word | Means |
|
|
60
61
|
| ------- | ------------------------------------------------------ |
|
|
61
62
|
| as | the member who writes it |
|
|
63
|
+
| via | it's made by their agent's link, not on their page |
|
|
62
64
|
| seen | who must see the change |
|
|
63
65
|
| unseen | who must never see it |
|
|
64
66
|
| cast | other names for a member's pages, or `null` for nobody |
|
|
@@ -61,6 +61,8 @@ export const window = null;
|
|
|
61
61
|
export const names: Record<string, readonly [(m: number, read: (doc: string) => any, doc: string) => boolean, string]> = {
|
|
62
62
|
"supplier": [(m, read, doc) => (read("staff")["posts"] ?? []).some((i: any) => String(i["role"]) === "supplier" && (i["members"] === m || (Array.isArray(i["members"]) && i["members"].includes(m)))), "supplier names someone who isn't among staff's posts with role supplier"],
|
|
63
63
|
};
|
|
64
|
+
/** What's a person's alone, by collection: each op a write made via anything (an agent's link, a route) is refused, and the words (its definitions' person). */
|
|
65
|
+
export const person = {"supplies":{"add":"an order to a supplier is a person's to place"}};
|
|
64
66
|
/** The document as one statement over its tables (generated/supplies.queries.ts). */
|
|
65
67
|
export { query, postgres, items, triggers } from "./supplies.queries.ts";
|
|
66
68
|
|
|
@@ -14,10 +14,12 @@
|
|
|
14
14
|
{"documents":{"books":{"entries":{"from":"supplies","when":"delivered","sides":{"buyer":"bought","supplier":"sold"},"fields":["title","buyer","supplier"],"total":{"sum":"qty","times":"price"}}}}}
|
|
15
15
|
{"addedWith":{"lines":{"order":"an order's lines are set when it's placed"}}}
|
|
16
16
|
{"frozen":{"supplies":{"by":"delivered","fields":["price","terms"],"refused":"a delivered supply keeps its price and terms"}}}
|
|
17
|
+
{"person":{"supplies":{"add":"an order to a supplier is a person's to place"}}}
|
|
17
18
|
{"story":"Peter puts Dev in the kitchen too","as":"manager","does":{"doc":"staff","ops":[{"op":"add","path":"/posts/-","value":{"role":"kitchen","members":[4]}}]},"seen":["manager"]}
|
|
18
19
|
{"story":"Peter takes Nora off the till","as":"manager","does":{"doc":"staff","ops":[{"op":"replace","path":"/posts/2/members","value":[1]}]},"seen":["manager"]}
|
|
19
20
|
{"story":"Wai can't give anyone a role","as":"wai","cannot":{"doc":"staff","ops":[{"op":"add","path":"/posts/-","value":{"role":"till","members":[4]}}]},"refused":"you may not add at /posts/-"}
|
|
20
21
|
{"story":"Peter puts muffins on the menu","as":"manager","does":{"doc":"menu","ops":[{"op":"add","path":"/items/-","value":{"name":"Muffin","price":300,"stock":12}}]},"seen":["manager","wai"]}
|
|
22
|
+
{"story":"Peter's agent still puts scones on the menu","as":"manager","via":"claude","does":{"doc":"menu","ops":[{"op":"add","path":"/items/-","value":{"name":"Scone","price":280,"stock":8}}]},"seen":["manager","wai"]}
|
|
21
23
|
{"story":"Peter prices a latte at £3.80","as":"manager","does":{"doc":"menu","ops":[{"op":"replace","path":"/items/3/price","value":380}]},"seen":["manager","wai"]}
|
|
22
24
|
{"story":"Peter renames the flat white: it's oat milk now","as":"manager","does":{"doc":"menu","ops":[{"op":"replace","path":"/items/2/name","value":"Flat white, oat"}]},"seen":["manager","wai"]}
|
|
23
25
|
{"story":"Wai can't change a price","as":"wai","cannot":{"doc":"menu","ops":[{"op":"replace","path":"/items/3/price","value":1}]},"refused":"you may not replace at /items/3/price"}
|
|
@@ -36,6 +38,7 @@
|
|
|
36
38
|
{"story":"Bo can't cancel once the kitchen has started","cannot":{"doc":"order?code=Bo7pL2mRv8Yd","ops":[{"op":"replace","path":"/orders/2/status","value":"cancelled"}]},"refused":"that isn't a move you can make"}
|
|
37
39
|
{"story":"Ann can't touch Jo's order","cannot":{"doc":"order?code=q3Zt9xKcW1aB","ops":[{"op":"replace","path":"/orders/4/status","value":"cancelled"}]},"refused":"you may not replace at /orders/4/status"}
|
|
38
40
|
{"story":"Peter orders twenty croissants from Nick","as":"buyer","does":{"doc":"supplies","ops":[{"op":"add","path":"/supplies/-","value":{"title":"Croissants, Monday","item":5,"qty":20,"price":120,"buyer":1,"supplier":2,"terms":{"days":14,"by":"invoice"},"delivered":false}}]},"seen":["buyer","roaster"],"unseen":["wai"]}
|
|
41
|
+
{"story":"Peter's agent can't order from Nick: an order to a supplier is a person's to place","as":"buyer","via":"claude","cannot":{"doc":"supplies","ops":[{"op":"add","path":"/supplies/-","value":{"title":"Croissants, Tuesday","item":5,"qty":20,"price":120,"buyer":1,"supplier":2,"terms":{"days":14,"by":"invoice"},"delivered":false}}]},"refused":"an order to a supplier is a person's to place"}
|
|
39
42
|
{"story":"Nick sets his price","as":"roaster","does":{"doc":"supplies","ops":[{"op":"replace","path":"/supplies/1/price","value":110}]},"seen":["roaster","buyer"]}
|
|
40
43
|
{"story":"Nick gives thirty days to pay","as":"roaster","does":{"doc":"supplies","ops":[{"op":"replace","path":"/supplies/1/terms/days","value":30}]},"seen":["roaster","buyer"]}
|
|
41
44
|
{"story":"Peter can't set his own terms","as":"buyer","cannot":{"doc":"supplies","ops":[{"op":"replace","path":"/supplies/1/terms/days","value":90}]},"refused":"you may not replace at /supplies/1/terms/days"}
|
package/package.json
CHANGED
package/src/compile.ts
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
kindFrozen,
|
|
23
23
|
type Definitions,
|
|
24
24
|
type Frozen,
|
|
25
|
+
type LinkTo,
|
|
25
26
|
type Counted,
|
|
26
27
|
type Query,
|
|
27
28
|
type Where,
|
|
@@ -40,6 +41,8 @@ type Write = { doc: string; ops: Op[]; why?: string };
|
|
|
40
41
|
export type Story = {
|
|
41
42
|
story: string;
|
|
42
43
|
as?: string;
|
|
44
|
+
/** Made via something, by its label (the member's agent's link), never by their own hand on a page. */
|
|
45
|
+
via?: string;
|
|
43
46
|
does?: Write;
|
|
44
47
|
cannot?: Write;
|
|
45
48
|
seen?: string[];
|
|
@@ -1248,6 +1251,7 @@ export function definedFor(d: Definitions, m: Model, stories: Story[]): Definiti
|
|
|
1248
1251
|
"within",
|
|
1249
1252
|
"apart",
|
|
1250
1253
|
"notEmpty",
|
|
1254
|
+
"person",
|
|
1251
1255
|
] as const) {
|
|
1252
1256
|
const mine = has(d[k] as Record<string, unknown> | undefined);
|
|
1253
1257
|
if (mine && Object.keys(mine).length) out[k] = mine;
|
|
@@ -1378,6 +1382,7 @@ const DEFINED = [
|
|
|
1378
1382
|
"within",
|
|
1379
1383
|
"apart",
|
|
1380
1384
|
"notEmpty",
|
|
1385
|
+
"person",
|
|
1381
1386
|
];
|
|
1382
1387
|
|
|
1383
1388
|
/** Why a definition is checked by no story, or null: each must be, or it's a guess. A kind, by a story on an
|
|
@@ -1513,6 +1518,10 @@ export function unchecked(
|
|
|
1513
1518
|
] as const)
|
|
1514
1519
|
for (const words of all)
|
|
1515
1520
|
if (!refusing(words)) return `${key} is checked by no story: none cannot, refused in "${words}"`;
|
|
1521
|
+
// what's a person's alone, by a cannot told via something, refused in its words
|
|
1522
|
+
for (const words of Object.values(defs.person ?? {}).flatMap((ops) => Object.values(ops)))
|
|
1523
|
+
if (!stories.some((s) => s.cannot && s.via && s.refused === words))
|
|
1524
|
+
return `person is checked by no story: none told via an agent cannot, refused in "${words}"`;
|
|
1516
1525
|
return settingsUnchecked(defs, stories, grants) ?? visitorsRefused(defs, stories, rolesOfTeller);
|
|
1517
1526
|
}
|
|
1518
1527
|
|
|
@@ -1539,7 +1548,7 @@ ${names.join("\n")}
|
|
|
1539
1548
|
};
|
|
1540
1549
|
|
|
1541
1550
|
/** The stories language (docs/stories.md): the words a story, a write and an op may have, and no others. */
|
|
1542
|
-
const STORY = ["story", "as", "does", "cannot", "seen", "unseen", "refused", "then", "premise"],
|
|
1551
|
+
const STORY = ["story", "as", "via", "does", "cannot", "seen", "unseen", "refused", "then", "premise"],
|
|
1543
1552
|
WRITE = ["doc", "ops", "why"],
|
|
1544
1553
|
OP = ["op", "path", "value"];
|
|
1545
1554
|
|
|
@@ -1563,6 +1572,9 @@ export function unspoken(line: any): string | null {
|
|
|
1563
1572
|
if (odd) return `${odd} isn't a story's word: ${STORY.join(", ")}`;
|
|
1564
1573
|
if (typeof line.story !== "string") return "a story has its words";
|
|
1565
1574
|
if (line.as !== undefined && typeof line.as !== "string") return "as is a member's name";
|
|
1575
|
+
if (line.via !== undefined && line.as === undefined) return "via is a members' word: a story with it has as";
|
|
1576
|
+
if (line.via !== undefined && !(typeof line.via === "string" && /^[a-z0-9 -]{1,40}$/.test(line.via)))
|
|
1577
|
+
return "via is an agent's label: 1 to 40 of a-z, 0-9, spaces and hyphens";
|
|
1566
1578
|
if (!line.does === !line.cannot) return "a story does, or cannot: one of them";
|
|
1567
1579
|
if (line.refused !== undefined && !line.cannot) return "refused goes with cannot";
|
|
1568
1580
|
if (line.then !== undefined && !line.does) return "then goes with does";
|
|
@@ -1833,6 +1845,7 @@ export function compile(
|
|
|
1833
1845
|
fixed = false,
|
|
1834
1846
|
readOnly?: Query,
|
|
1835
1847
|
prefix = "",
|
|
1848
|
+
linkTo?: LinkTo,
|
|
1836
1849
|
): { rules: string; elements: string; rows: string | null } {
|
|
1837
1850
|
const HEAD = `// Written by src/compile.ts from ${from}: change ${derivedFrom ? "it and its example" : fixed ? "its seed" : "the stories"}, not this.\n`;
|
|
1838
1851
|
for (const name of Object.keys(collections)) {
|
|
@@ -1921,7 +1934,7 @@ export const member = true;
|
|
|
1921
1934
|
: ""
|
|
1922
1935
|
}/** The parts of ${doc} a page may hold alone, by its query's parameters (its definitions' window): null, none. */
|
|
1923
1936
|
export const window = ${JSON.stringify(defs.window ?? null)};
|
|
1924
|
-
${defs.window && !defs.where?.[doc] ? windowCode(defs.window) : ""}${namesCode(defs, Object.values(collections))}${defs.moves ? `/** Each field whose value moves only as the stories move it, each step by its roles (its definitions' moves). */\nexport const moves = ${JSON.stringify(defs.moves)};\n` : ""}${defs.guests ? `/** The field holding an item's own code: a page holding ${doc} by it is the item's guest (its definitions' guests). */\nexport const guests = ${JSON.stringify(defs.guests)};\n` : ""}${settingsCode(doc, defs)}${defs.visitors ? `/** The field of its kind's root holding the level its guest is, the role guest: that level (its definitions' visitors). */\nexport const visitors = ${JSON.stringify(defs.visitors)};\n` : ""}${derivedFrom ? "" : `/** The document as one statement over its tables (generated/${prefix}queries.ts). */\nexport { query, postgres${readOnly ? "" : ", items, triggers"} } from "./${prefix}queries.ts";\n`}${derivedFrom ? `/** The documents this one is derived from (its derive.ts): what the server derives it again on a write to. */\nexport const derived = ${JSON.stringify(derivedFrom)};\n` : ""}`;
|
|
1937
|
+
${defs.window && !defs.where?.[doc] ? windowCode(defs.window) : ""}${namesCode(defs, Object.values(collections))}${defs.moves ? `/** Each field whose value moves only as the stories move it, each step by its roles (its definitions' moves). */\nexport const moves = ${JSON.stringify(defs.moves)};\n` : ""}${defs.person ? `/** What's a person's alone, by collection: each op a write made via anything (an agent's link, a route) is refused, and the words (its definitions' person). */\nexport const person = ${JSON.stringify(defs.person)};\n` : ""}${defs.guests ? `/** The field holding an item's own code: a page holding ${doc} by it is the item's guest (its definitions' guests). */\nexport const guests = ${JSON.stringify(defs.guests)};\n` : ""}${settingsCode(doc, defs)}${defs.visitors ? `/** The field of its kind's root holding the level its guest is, the role guest: that level (its definitions' visitors). */\nexport const visitors = ${JSON.stringify(defs.visitors)};\n` : ""}${derivedFrom ? "" : `/** The document as one statement over its tables (generated/${prefix}queries.ts). */\nexport { query, postgres${readOnly ? "" : ", items, triggers"} } from "./${prefix}queries.ts";\n`}${derivedFrom ? `/** The documents this one is derived from (its derive.ts): what the server derives it again on a write to. */\nexport const derived = ${JSON.stringify(derivedFrom)};\n` : ""}`;
|
|
1925
1938
|
let elements = `${HEAD}
|
|
1926
1939
|
// Each collection is an element, defined here: on a page, it holds the document, and its items
|
|
1927
1940
|
// are put inside it. Each item is an element, defined by the page: as it is, or by a view that
|
|
@@ -2064,7 +2077,7 @@ export function write(from: Element, ops: ${Doc}Op[], why?: string) { return sen
|
|
|
2064
2077
|
rules += `\n/** The lists that are each member's own (its definitions' mine), or links to one: a member gives and takes only their own id. */\nexport const mine: Record<string, string[]> = ${JSON.stringify(own)};\n${Object.keys(mineSaid(defs)).length ? `/** The words a write giving or taking another's is refused in, where its mine says them. */\nexport const mineSaid: Record<string, Record<string, string>> = ${JSON.stringify(mineSaid(defs))};\n` : ""}`;
|
|
2065
2078
|
// a derived document is derived for each page, its member's: it has no roles, and is published to no topic
|
|
2066
2079
|
if (!derivedFrom && !readOnly)
|
|
2067
|
-
rules += whoRules(doc, Object.keys(collections), defs, grants, defs.kind && holders[defs.kind.root]);
|
|
2080
|
+
rules += whoRules(doc, Object.keys(collections), defs, grants, defs.kind && holders[defs.kind.root], linkTo);
|
|
2068
2081
|
// a derived or read-only document is rows too, which none may change: the kit reads it as any other (a timeline of
|
|
2069
2082
|
// a sequence derived from starts, results as rows)
|
|
2070
2083
|
const rows = fixed ? null : rowsOf({ doc, collections }, defs, link, HEAD, prefix, grants);
|
|
@@ -2482,7 +2495,20 @@ export async function compiled(dir = APPS) {
|
|
|
2482
2495
|
.filter(([a]) => a !== app)
|
|
2483
2496
|
.flatMap(([, m]) => Object.keys(m.collections).map((c) => [c, m.doc])),
|
|
2484
2497
|
);
|
|
2485
|
-
/**
|
|
2498
|
+
/** Where a link of a collection goes, by the links of the app whose document has it (a relation's who, to entities),
|
|
2499
|
+
* for a who-path's `@field>term`, in any app's. */
|
|
2500
|
+
const linkTo: LinkTo = (coll, field) => {
|
|
2501
|
+
const [app, c] =
|
|
2502
|
+
Object.entries(models).flatMap(([a, m]) =>
|
|
2503
|
+
Object.entries(m.collections)
|
|
2504
|
+
.filter(([name, x]) => (coll === undefined || name === coll) && x.fields[field])
|
|
2505
|
+
.map(([, x]) => [a, x] as const),
|
|
2506
|
+
)[0] ?? [];
|
|
2507
|
+
const l = app && defs[app]!.links?.[field];
|
|
2508
|
+
const to = typeof l === "string" ? l : l ? l.to : field;
|
|
2509
|
+
const at = c && Object.values(models).find((m) => m.collections[to]);
|
|
2510
|
+
return at ? { coll: to, doc: at.doc, list: c!.fields[field] === "ids" } : undefined;
|
|
2511
|
+
};
|
|
2486
2512
|
/** What each person sees of each of a document's collections (its owns), as SQL of a row, `t`: a collection owns
|
|
2487
2513
|
* doesn't name, everyone's. */
|
|
2488
2514
|
const ownsOf = (app: string): Record<string, string> => {
|
|
@@ -2496,6 +2522,7 @@ export async function compiled(dir = APPS) {
|
|
|
2496
2522
|
list: (c: string, f: string) => types(c)[f] === "ids",
|
|
2497
2523
|
own: Object.keys(m.collections),
|
|
2498
2524
|
...(kind ? { kind: { column: m.doc, root: kind.root } } : {}),
|
|
2525
|
+
link: linkTo,
|
|
2499
2526
|
};
|
|
2500
2527
|
return Object.fromEntries(
|
|
2501
2528
|
Object.entries(by).map(([c, path]) => [c, `(${whoSql(path, c, "t", who, `${app}'s owns`)})`]),
|
|
@@ -2507,7 +2534,7 @@ export async function compiled(dir = APPS) {
|
|
|
2507
2534
|
const grantsFor = (app: string) => {
|
|
2508
2535
|
if (granted[app]) return granted[app]!;
|
|
2509
2536
|
const roles = Object.entries(defs[app]!.roles ?? {}).map(
|
|
2510
|
-
([r, path]) => [r, whoFn(whoCode(path, defs[app]!.roles!, app, !!defs[app]!.kind, [r]))] as const,
|
|
2537
|
+
([r, path]) => [r, whoFn(whoCode(path, defs[app]!.roles!, app, !!defs[app]!.kind, [r], linkTo))] as const,
|
|
2511
2538
|
);
|
|
2512
2539
|
const memberOf = (name: string) => {
|
|
2513
2540
|
const as = name in casts[app]! ? casts[app]![name] : name;
|
|
@@ -2706,6 +2733,7 @@ export async function compiled(dir = APPS) {
|
|
|
2706
2733
|
statics.has(app),
|
|
2707
2734
|
readOnly[app],
|
|
2708
2735
|
split.has(app) ? `${app}.` : "",
|
|
2736
|
+
linkTo,
|
|
2709
2737
|
),
|
|
2710
2738
|
};
|
|
2711
2739
|
}
|
package/src/definitions.ts
CHANGED
|
@@ -59,6 +59,10 @@
|
|
|
59
59
|
// held as within is.
|
|
60
60
|
// notEmpty fields of words that are never none, nor only spaces: { notes: ["text"] }, refused "text cannot be empty"
|
|
61
61
|
// (a trigger). One a store holds already, from before it was said, is left until it's changed.
|
|
62
|
+
// person what's a person's alone, by collection: { supplies: { add: "an order to a supplier is a person's to place" } }.
|
|
63
|
+
// Each op (add, remove, or with its field: "replace price", "add people[]") is refused in those words to a
|
|
64
|
+
// write made via anything (the member's agent's link, a route), whatever their roles; by their own hand on
|
|
65
|
+
// a page it goes as the grants say (src/write.ts).
|
|
62
66
|
// waits { by: "moderated", posts: "waiting", refused: "…" }: in a kind, while the root item's field is true, an
|
|
63
67
|
// add to posts gives its field that moves (moves) as that first step, or it's refused in those words.
|
|
64
68
|
//
|
|
@@ -69,6 +73,9 @@
|
|
|
69
73
|
// holdings@members the members named by any item of a collection of this document; posts[role=trader]@members
|
|
70
74
|
// those of the items whose field is that; members[!inviter] the items with no inviter,
|
|
71
75
|
// themselves members; fund/posts@members, a collection of another document
|
|
76
|
+
// ties[of=@][role=director,accountant]@who>@member
|
|
77
|
+
// a link followed: the ties whose of is the item asked of, with either role, and the item who
|
|
78
|
+
// links to asked what follows `>`, a term or a group in brackets, ( … | … ): the member it names
|
|
72
79
|
|
|
73
80
|
import type { Op } from "./ops.ts";
|
|
74
81
|
|
|
@@ -115,6 +122,9 @@ export type Definitions = {
|
|
|
115
122
|
apart?: Record<string, { lists: string[]; refused: string }[]>;
|
|
116
123
|
/** Fields of words that are never none, nor only spaces: by collection. */
|
|
117
124
|
notEmpty?: Record<string, string[]>;
|
|
125
|
+
/** What's a person's alone: by collection, each op (add, remove, or with its field: "replace price") and the words
|
|
126
|
+
* it's refused in to a write made via anything (an agent's link, a route). */
|
|
127
|
+
person?: Record<string, Record<string, string>>;
|
|
118
128
|
/** In a kind, a yes-or-no field of the root item: while it's true, an add to each collection named gives its field
|
|
119
129
|
* that moves as this first step, or it's refused in these words (a board held for approval, a post waiting).
|
|
120
130
|
* src/settings.ts. */
|
|
@@ -158,17 +168,73 @@ export type Takes = { while: string; refused: string } & Record<string, string>;
|
|
|
158
168
|
* each of its lines' qty times its price. */
|
|
159
169
|
export type Total = { of: string; by: string; sum: string; times?: string };
|
|
160
170
|
|
|
171
|
+
/** A who-path's terms: split at each "|" outside a group's brackets. */
|
|
172
|
+
const termsOf = (path: string) => {
|
|
173
|
+
const out: string[] = [];
|
|
174
|
+
let depth = 0,
|
|
175
|
+
from = 0;
|
|
176
|
+
for (let i = 0; i < path.length; i++) {
|
|
177
|
+
if (path[i] === "(") depth++;
|
|
178
|
+
else if (path[i] === ")") depth--;
|
|
179
|
+
else if (path[i] === "|" && !depth) {
|
|
180
|
+
out.push(path.slice(from, i).trim());
|
|
181
|
+
from = i + 1;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return [...out, path.slice(from).trim()];
|
|
185
|
+
};
|
|
186
|
+
/** A term that's a group, `( … | … )`: the who-path inside it. */
|
|
187
|
+
const groupOf = (t: string) => (t.startsWith("(") && t.endsWith(")") ? t.slice(1, -1) : undefined);
|
|
188
|
+
/** A term of the item's own field: `@field`, the members it names, or `@field>term`, what it links to, asked a term. */
|
|
189
|
+
const FIELD = /^@([a-z][a-z0-9-]*)(?:>(.+))?$/s;
|
|
190
|
+
/** A term of a collection: `[doc/]collection`, any filters (`[field=value]`, `[field=a,b]` any of them, `[!field]`
|
|
191
|
+
* none, `[field=@]` the item it's asked of), then `@field`, the members it names, or `@field>term`: the item that one-id
|
|
192
|
+
* or list link of its points at, asked the term (a relation's who, `>@member`, the member who's that entity). */
|
|
193
|
+
export const TERM = /^(?:([a-z][a-z0-9-]*)\/)?([a-z][a-z0-9-]*)((?:\[[^\]]*\])*)(?:@([a-z][a-z0-9-]*)(?:>(.+))?)?$/s;
|
|
194
|
+
/** A filter of a term: a field none, any of some values, or the item a who-path is asked of. */
|
|
195
|
+
type Filter = { not: boolean; field: string; values?: string[]; self?: true };
|
|
196
|
+
/** A term of a collection, read; refused in words where it isn't one. */
|
|
197
|
+
export function termOf(t: string, where: string) {
|
|
198
|
+
const [, of, coll, fs = "", to, then] = t.match(TERM) ?? [];
|
|
199
|
+
const filters = [...fs.matchAll(/\[([^\]]*)\]/g)].map(([, f]): Filter | null => {
|
|
200
|
+
const [, not, field, value] = f!.match(/^(!?)([a-z][a-z0-9-]*)(?:=(.+))?$/) ?? [];
|
|
201
|
+
if (!field || !!not === (value !== undefined)) return null;
|
|
202
|
+
return {
|
|
203
|
+
not: !!not,
|
|
204
|
+
field,
|
|
205
|
+
...(value === "@" ? { self: true as const } : value ? { values: value.split(",") } : {}),
|
|
206
|
+
};
|
|
207
|
+
});
|
|
208
|
+
if (!coll || filters.includes(null)) throw new Error(`${where}: ${t} isn't a who-path`);
|
|
209
|
+
return { of, coll, filters: filters as Filter[], to, then };
|
|
210
|
+
}
|
|
161
211
|
/** A who-path of collections in words (links' holds): "staff's posts with role supplier". */
|
|
162
|
-
export const pathSaid = (path: string) =>
|
|
163
|
-
path
|
|
164
|
-
.split("|")
|
|
212
|
+
export const pathSaid = (path: string): string =>
|
|
213
|
+
termsOf(path)
|
|
165
214
|
.map((t) => {
|
|
166
|
-
const
|
|
167
|
-
|
|
215
|
+
const group = groupOf(t);
|
|
216
|
+
if (group !== undefined) return pathSaid(group);
|
|
217
|
+
const own = t.match(FIELD);
|
|
218
|
+
if (own) return own[2] ? `what its ${own[1]} is, ${pathSaid(own[2])}` : `its ${own[1]}`;
|
|
219
|
+
const { of, coll, filters, to, then } = termOf(t, "a who-path");
|
|
220
|
+
const said = filters.map((f) =>
|
|
221
|
+
f.not ? `with no ${f.field}` : f.self ? `whose ${f.field} is it` : `with ${f.field} ${f.values!.join(" or ")}`,
|
|
222
|
+
);
|
|
223
|
+
return `${of ? `${of}'s ` : ""}${coll}${said.length ? ` ${said.join(" and ")}` : ""}${then ? `, whose ${to} is ${pathSaid(then)}` : ""}`;
|
|
168
224
|
})
|
|
169
225
|
.join(" or ");
|
|
170
|
-
|
|
171
|
-
|
|
226
|
+
/** Where a link goes, for a who-path's `@field>term`: of a collection's field (none: whichever collection has the
|
|
227
|
+
* field), the collection it's to, the document that holds it, and whether the field is a list of ids. */
|
|
228
|
+
export type LinkTo = (
|
|
229
|
+
coll: string | undefined,
|
|
230
|
+
field: string,
|
|
231
|
+
) => { coll: string; doc: string; list: boolean } | undefined;
|
|
232
|
+
/** Where a term's `@field>` goes, refused in words where it's no link. */
|
|
233
|
+
function linked(t: string, coll: string | undefined, to: string, where: string, link?: LinkTo) {
|
|
234
|
+
const l = link?.(coll, to);
|
|
235
|
+
if (!l) throw new Error(`${where}: ${t}: ${to} isn't a link to a collection`);
|
|
236
|
+
return l;
|
|
237
|
+
}
|
|
172
238
|
|
|
173
239
|
/** The roles named on the way to a role named in a who-path, it last (`seen`, those before it); refused where it's
|
|
174
240
|
* one of them, as a role can't be itself. */
|
|
@@ -182,50 +248,63 @@ const onTo = (role: string, seen: string[], where: string) => {
|
|
|
182
248
|
|
|
183
249
|
/** A who-path as a JavaScript expression of m (the member), item, read and doc (this document), true when m
|
|
184
250
|
* is one of them: a role in it, that role's who-path (`roles`, each by name; `seen`, those named on the way to it);
|
|
185
|
-
* `item` the item a role's @field is of. In a kind (`kind`), `item` is the root's `
|
|
186
|
-
*
|
|
187
|
-
*
|
|
251
|
+
* `item` the item a role's @field is of, and `[field=@]`'s. In a kind (`kind`), `item` is the root's and `at` the item
|
|
252
|
+
* a write is to: an @field is the item's where it has that field (a post's author), else the root's (the board's
|
|
253
|
+
* owners). After `@field>`, the item that links to is `item`, as no kind's root. */
|
|
188
254
|
export function whoCode(
|
|
189
255
|
path: string,
|
|
190
256
|
roles: Record<string, string>,
|
|
191
257
|
where: string,
|
|
192
258
|
kind = false,
|
|
193
259
|
seen: string[] = [],
|
|
260
|
+
link?: LinkTo,
|
|
194
261
|
): string {
|
|
195
262
|
const names = (v: string) => `(${v} === m || (Array.isArray(${v}) && ${v}.includes(m)))`;
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
.
|
|
263
|
+
// the item (or items) an id or ids (`v`) of a link name, each asked a who-path as the item
|
|
264
|
+
const follow = (v: string, l: { coll: string; doc: string }, then: string) =>
|
|
265
|
+
`([] as unknown[]).concat(${v} ?? []).some((id: unknown) => ((item: any, at: any) => ${whoCode(then, roles, where, false, seen, link)})((read(${JSON.stringify(l.doc)})[${JSON.stringify(l.coll)}] ?? []).find((r: any) => r.id === id), undefined))`;
|
|
266
|
+
return termsOf(path)
|
|
199
267
|
.map((t) => {
|
|
200
268
|
if (t === "member") return "true";
|
|
201
|
-
if (roles[t] !== undefined) return `(${whoCode(roles[t], roles, where, kind, onTo(t, seen, where))})`;
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
269
|
+
if (roles[t] !== undefined) return `(${whoCode(roles[t], roles, where, kind, onTo(t, seen, where), link)})`;
|
|
270
|
+
const group = groupOf(t);
|
|
271
|
+
if (group !== undefined) return `(${whoCode(group, roles, where, kind, seen, link)})`;
|
|
272
|
+
const own = t.match(FIELD);
|
|
273
|
+
if (own) {
|
|
274
|
+
const f = JSON.stringify(own[1]);
|
|
275
|
+
const v = kind ? `(at != null && ${f} in at ? at : item)?.[${f}]` : `item?.[${f}]`;
|
|
276
|
+
if (own[2]) return follow(v, linked(t, undefined, own[1]!, where, link), own[2]);
|
|
277
|
+
return kind ? `((v: any) => v === m || (Array.isArray(v) && v.includes(m)))(${v})` : names(v);
|
|
207
278
|
}
|
|
208
|
-
const
|
|
209
|
-
if (!coll || (not && value)) throw new Error(`${where}: ${t} isn't a who-path`);
|
|
279
|
+
const { of, coll, filters, to, then } = termOf(t, where);
|
|
210
280
|
const at = (f: string) => `i[${JSON.stringify(f)}]`;
|
|
211
|
-
const cond =
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
281
|
+
const cond =
|
|
282
|
+
filters
|
|
283
|
+
.map((f) =>
|
|
284
|
+
f.not
|
|
285
|
+
? `${at(f.field)} === undefined`
|
|
286
|
+
: f.self
|
|
287
|
+
? `${at(f.field)} === item?.id`
|
|
288
|
+
: f.values!.length === 1
|
|
289
|
+
? `String(${at(f.field)}) === ${JSON.stringify(f.values![0])}`
|
|
290
|
+
: `${JSON.stringify(f.values)}.includes(String(${at(f.field)}))`,
|
|
291
|
+
)
|
|
292
|
+
.join(" && ") || "true";
|
|
293
|
+
const end = !to ? "i.id === m" : then ? follow(at(to), linked(t, coll, to, where, link), then) : names(at(to));
|
|
294
|
+
return `(read(${of ? JSON.stringify(of) : "doc"})[${JSON.stringify(coll)}] ?? []).some((i: any) => ${cond} && ${end})`;
|
|
217
295
|
})
|
|
218
296
|
.join(" || ");
|
|
219
297
|
}
|
|
220
298
|
|
|
221
299
|
/** What a who-path is asked of, as SQL: the roles (each a who-path), which fields are lists (a table of pairs), the
|
|
222
|
-
* document's own collections,
|
|
223
|
-
*
|
|
300
|
+
* document's own collections, of a kind, the column its rows are kept with their instance by and its root's table
|
|
301
|
+
* (`$key`, the instance), and where a link goes, for `@field>`. */
|
|
224
302
|
export type WhoOf = {
|
|
225
303
|
roles: Record<string, string>;
|
|
226
304
|
list: (coll: string, field: string) => boolean;
|
|
227
305
|
own: string[];
|
|
228
306
|
kind?: { column: string; root: string };
|
|
307
|
+
link?: LinkTo;
|
|
229
308
|
};
|
|
230
309
|
/** A who-path as SQL of a row (`at`, of collection `coll`): true when $member is one of them. The same path its code
|
|
231
310
|
* is written from (whoCode), so the query holds what's asked of an item. A role's @field is its kind's root item's. */
|
|
@@ -243,30 +322,53 @@ export function whoSql(
|
|
|
243
322
|
who.list(c, f)
|
|
244
323
|
? `EXISTS (SELECT 1 FROM ${q(`${c}_${f}`)} p WHERE p.${q(c)} = ${a}.id AND p.${q(f)} = $member)`
|
|
245
324
|
: `${a}.${q(f)} = $member`;
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
325
|
+
// the row (`w`, named apart from every row it's within) a link of a row of `c` names, asked a who-path as no kind's
|
|
326
|
+
// root: the row's id is `row`, its one id `one`
|
|
327
|
+
const n = /^w\d+$/.test(at) ? Number(at.slice(1)) + 1 : 1;
|
|
328
|
+
const follow = (t: string, c: string, f: string, row: string, one: string, then: string) => {
|
|
329
|
+
const l = linked(t, c, f, where, who.link),
|
|
330
|
+
w = `w${n}`;
|
|
331
|
+
const inner = whoSql(then, l.coll, w, { ...who, kind: undefined }, where, false, seen);
|
|
332
|
+
return l.list
|
|
333
|
+
? `EXISTS (SELECT 1 FROM ${q(`${c}_${f}`)} p${n} JOIN ${q(l.coll)} ${w} ON ${w}.id = p${n}.${q(f)} WHERE p${n}.${q(c)} = ${row} AND (${inner}))`
|
|
334
|
+
: `EXISTS (SELECT 1 FROM ${q(l.coll)} ${w} WHERE ${w}.id = ${one} AND (${inner}))`;
|
|
335
|
+
};
|
|
336
|
+
return termsOf(path)
|
|
249
337
|
.map((t) => {
|
|
250
338
|
if (t === "member") return "TRUE";
|
|
251
339
|
if (who.roles[t]) return `(${whoSql(who.roles[t]!, coll, at, who, where, true, onTo(t, seen, where))})`;
|
|
252
|
-
|
|
253
|
-
|
|
340
|
+
const group = groupOf(t);
|
|
341
|
+
if (group !== undefined) return `(${whoSql(group, coll, at, who, where, root, seen)})`;
|
|
342
|
+
const own = t.match(FIELD);
|
|
343
|
+
if (own) {
|
|
344
|
+
const f = own[1]!;
|
|
254
345
|
// in a role of a kind, the root item's field
|
|
255
|
-
if (root && who.kind)
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
346
|
+
if (root && who.kind) {
|
|
347
|
+
const r = who.kind.root;
|
|
348
|
+
if (own[2]) return follow(t, r, f, "$key", `(SELECT r.${q(f)} FROM ${q(r)} r WHERE r.id = $key)`, own[2]);
|
|
349
|
+
return who.list(r, f)
|
|
350
|
+
? `EXISTS (SELECT 1 FROM ${q(`${r}_${f}`)} p WHERE p.${q(r)} = $key AND p.${q(f)} = $member)`
|
|
351
|
+
: `(SELECT r.${q(f)} FROM ${q(r)} r WHERE r.id = $key) = $member`;
|
|
352
|
+
}
|
|
353
|
+
if (own[2]) return follow(t, coll, f, `${at}.id`, `${at}.${q(f)}`, own[2]);
|
|
259
354
|
return names(coll, at, f);
|
|
260
355
|
}
|
|
261
|
-
const
|
|
262
|
-
|
|
356
|
+
const { of, coll: c, filters, to, then } = termOf(t, where);
|
|
357
|
+
const text = (v: string) => `'${v.replaceAll("'", "''")}'`;
|
|
263
358
|
const cond = [
|
|
264
|
-
...(
|
|
265
|
-
|
|
266
|
-
|
|
359
|
+
...filters.map((f) =>
|
|
360
|
+
f.not
|
|
361
|
+
? `i.${q(f.field)} IS NULL`
|
|
362
|
+
: f.self
|
|
363
|
+
? // the item it's asked of: in a role of a kind, its root item, the instance's
|
|
364
|
+
`i.${q(f.field)} = ${root && who.kind ? "$key" : `${at}.id`}`
|
|
365
|
+
: f.values!.length === 1
|
|
366
|
+
? `CAST(i.${q(f.field)} AS TEXT) = ${text(f.values![0]!)}`
|
|
367
|
+
: `CAST(i.${q(f.field)} AS TEXT) IN (${f.values!.map(text).join(", ")})`,
|
|
368
|
+
),
|
|
267
369
|
// the document's own collection, of a kind: its instance's rows
|
|
268
370
|
...(!of && who.kind && who.own.includes(c) ? [`i.${q(who.kind.column)} = $key`] : []),
|
|
269
|
-
to ?
|
|
371
|
+
!to ? "i.id = $member" : then ? follow(t, c, to, "i.id", `i.${q(to)}`, then) : names(c, "i", to),
|
|
270
372
|
];
|
|
271
373
|
return `EXISTS (SELECT 1 FROM ${q(c)} i WHERE ${cond.join(" AND ")})`;
|
|
272
374
|
})
|
|
@@ -291,6 +393,7 @@ export function whoRules(
|
|
|
291
393
|
defs: Definitions,
|
|
292
394
|
grants: Record<string, string[]>,
|
|
293
395
|
root?: string,
|
|
396
|
+
link?: LinkTo,
|
|
294
397
|
) {
|
|
295
398
|
const roles = Object.keys(defs.roles ?? {});
|
|
296
399
|
const where = `${doc}'s definitions`;
|
|
@@ -312,7 +415,7 @@ export function whoRules(
|
|
|
312
415
|
? `(read(${JSON.stringify(root)})[${JSON.stringify(k.root)}] ?? []).find((i: any) => i.id === Number(doc.split(/[:?]/)[1]))`
|
|
313
416
|
: "at";
|
|
314
417
|
out += `\n/** Who someone is to ${doc} (and to an item of it, \`at\`), beyond a member: each role whose who-path finds them. */\n`;
|
|
315
|
-
out += `export function rolesOf(m: number, read: (doc: string) => any, doc: string, at?: any): string[] {\n const item: any = ${item};\n return [${roles.map((r) => `\n ${whoCode(defs.roles![r]!, defs.roles!, where, !!k, [r])} ? ${JSON.stringify(r)} : ""`).join(",")},\n ].filter(Boolean);\n}\n`;
|
|
418
|
+
out += `export function rolesOf(m: number, read: (doc: string) => any, doc: string, at?: any): string[] {\n const item: any = ${item};\n return [${roles.map((r) => `\n ${whoCode(defs.roles![r]!, defs.roles!, where, !!k, [r], link)} ? ${JSON.stringify(r)} : ""`).join(",")},\n ].filter(Boolean);\n}\n`;
|
|
316
419
|
return out + sight(doc, collections, defs, roles, where);
|
|
317
420
|
}
|
|
318
421
|
|
package/src/mcp.ts
CHANGED
|
@@ -8,15 +8,16 @@
|
|
|
8
8
|
// as the grants allow; a kind's (trip:1) take the instance's key. A window isn't a tool's: a document is read as its
|
|
9
9
|
// member sees it, whole or one collection's items (some, by id). How any document is read and written here is the
|
|
10
10
|
// door's own skill (src/skill.ts), served by MCP's skills extension beside each app's own (its words, its routes.ts's
|
|
11
|
-
// `instructions`, and what its documents hold, from their rules), and
|
|
11
|
+
// `instructions`, and what its documents hold, from their rules), and by read_skill, a tool, to a client that doesn't
|
|
12
|
+
// load skills. A document that names files
|
|
12
13
|
// has upload_<doc> too: a link the server makes for the agent's member to send a file by (src/upload.ts), since the
|
|
13
14
|
// agent never sees its own key. It speaks both eras of MCP: the modern (2026-07-28), each request saying its
|
|
14
15
|
// version and the client's capabilities in its _meta, its headers checked against its body, server/discover in place
|
|
15
|
-
// of a handshake, and the skills extension declared; and the legacy, opened by initialize.
|
|
16
|
-
//
|
|
16
|
+
// of a handshake, and the skills extension declared; and the legacy, opened by initialize. Its instructions are a few
|
|
17
|
+
// lines to every client, so none is cut off: its documents, who the agent acts as, and where the skills are.
|
|
17
18
|
|
|
18
19
|
import { FORMS, SAID } from "./compile.ts";
|
|
19
|
-
import {
|
|
20
|
+
import { opening, skill, skillOf, SKILLS } from "./skill.ts";
|
|
20
21
|
import type { Made } from "./upload.ts";
|
|
21
22
|
import { schemeOf } from "./proxy.ts";
|
|
22
23
|
import type { Who } from "./members/group.ts";
|
|
@@ -224,7 +225,7 @@ export function door(d: Door) {
|
|
|
224
225
|
return rules.length ? [skillOf(a.app, a.words, rules)] : [];
|
|
225
226
|
});
|
|
226
227
|
const skills = [skill, ...apps],
|
|
227
|
-
|
|
228
|
+
docs = d.rules.map((r) => (r.kind ? `${r.doc}:<key>` : r.doc));
|
|
228
229
|
const skillAt = (uri: unknown) => skills.find((s) => s.uri === uri);
|
|
229
230
|
|
|
230
231
|
/** The tools for a member's agent: each document's read and, where pages write it, its write; a kind's take its key. */
|
|
@@ -235,7 +236,24 @@ export function door(d: Door) {
|
|
|
235
236
|
inputSchema: Schema;
|
|
236
237
|
annotations: Schema;
|
|
237
238
|
run(args: any): Promise<Result> | Result;
|
|
238
|
-
}[] = [
|
|
239
|
+
}[] = [
|
|
240
|
+
{
|
|
241
|
+
name: "read_skill",
|
|
242
|
+
description: `One of this door's skills, its SKILL.md whole, for a client that doesn't load skills itself: ${skill.name}, how any document here is read and written${apps.length ? `; ${apps.map((a) => a.name).join(", ")}, what each app's documents hold and mean` : ""}. Read them before a write.`,
|
|
243
|
+
inputSchema: {
|
|
244
|
+
type: "object",
|
|
245
|
+
properties: { name: { type: "string", enum: skills.map((s) => s.name) } },
|
|
246
|
+
required: ["name"],
|
|
247
|
+
},
|
|
248
|
+
annotations: { readOnlyHint: true },
|
|
249
|
+
run: (args) => {
|
|
250
|
+
const asked = skills.find((s) => s.name === args.name);
|
|
251
|
+
return asked
|
|
252
|
+
? { content: [{ type: "text", text: asked.text }] }
|
|
253
|
+
: refused(`name: one of ${skills.map((s) => s.name).join(", ")}`);
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
];
|
|
239
257
|
for (const r of d.rules) {
|
|
240
258
|
// the document a call names: a kind's instance by its key (trip:1), or the one
|
|
241
259
|
const name = (args: { key?: unknown }) => (r.kind ? `${r.doc}:${args.key}` : r.doc);
|
|
@@ -371,9 +389,11 @@ export function door(d: Door) {
|
|
|
371
389
|
m.id,
|
|
372
390
|
modern ? { resultType: "complete", ...result, ...(kept ? { ttlMs: 0, cacheScope: kept } : {}) } : result,
|
|
373
391
|
);
|
|
374
|
-
// to
|
|
375
|
-
const
|
|
376
|
-
|
|
392
|
+
// the same few lines to every client: who the agent acts as, its member by id, so a document naming members is read
|
|
393
|
+
const as = d.anyone
|
|
394
|
+
? "anyone, as a stranger's page does"
|
|
395
|
+
: `member ${who.member}, by the link called ${JSON.stringify(who.agent?.label)}`;
|
|
396
|
+
const instructions = opening(apps, docs, as);
|
|
377
397
|
if (modern && m.method === "server/discover")
|
|
378
398
|
return done(
|
|
379
399
|
{
|
package/src/server.ts
CHANGED
|
@@ -23,7 +23,7 @@ import { doc as GROUP } from "./members/generated/rules.ts";
|
|
|
23
23
|
import { groupOf, say, type Data, type Who } from "./members/group.ts";
|
|
24
24
|
import { fromHere } from "./members/demo.ts";
|
|
25
25
|
import { door, type Written } from "./mcp.ts";
|
|
26
|
-
import { uploads, type Uploads } from "./upload.ts";
|
|
26
|
+
import { filled, uploads, type Uploads } from "./upload.ts";
|
|
27
27
|
import { bdflOf, type Asked, type Member } from "./members/trust.ts";
|
|
28
28
|
import {
|
|
29
29
|
attribute,
|
|
@@ -47,7 +47,7 @@ export { Refused };
|
|
|
47
47
|
export type { Reactions, Read, Trust };
|
|
48
48
|
import { upkeep, KEEP } from "./upkeep.ts";
|
|
49
49
|
import { folderOf } from "./file-value.ts";
|
|
50
|
-
import { filesAt, letGo, named, putsFile, routes as fileRoutes, type Files } from "./files.ts";
|
|
50
|
+
import { filesAt, keep, letGo, named, putsFile, routes as fileRoutes, type Files } from "./files.ts";
|
|
51
51
|
import { version } from "../package.json";
|
|
52
52
|
|
|
53
53
|
/** How many documents a page holds at once (each write views every one held): past it, one is let go first. */
|
|
@@ -148,8 +148,17 @@ const ICON = `${import.meta.dir}/icon.png`;
|
|
|
148
148
|
|
|
149
149
|
/** A write by the server itself, a route's or a job's: shaped as the stories say, but asked of no roles and no
|
|
150
150
|
* trust.ts, since it's the app's own; landed with what follows from it, and told. Its change, or Refused, once it
|
|
151
|
-
* has (await it). A route reads what it needs before it writes.
|
|
152
|
-
|
|
151
|
+
* has (await it). A route reads what it needs before it writes. Given `as`, it's a member's write in place of the
|
|
152
|
+
* server's (a paper a mail brought, its member's), made as an agent's is: under their grants, the app's trust and the
|
|
153
|
+
* group's, via the label it names, so every page says whose it is and how it came ("Peter via mail"); and with a file,
|
|
154
|
+
* the file kept first, as a page's is, where its member may put one, "$file" in the ops standing for it. Answered
|
|
155
|
+
* done, with its version, the ids it added, and the file's value; or Refused. */
|
|
156
|
+
export type Write = {
|
|
157
|
+
(doc: string, ops: Op[]): Promise<Change>;
|
|
158
|
+
(doc: string, ops: Op[], as: As): Promise<Written & { done: true; file?: string }>;
|
|
159
|
+
};
|
|
160
|
+
/** Whose a route's write is: a member of the group, via what (its label, as an agent's), why, and a file it brings. */
|
|
161
|
+
export type As = { member: number; via: string; why?: string; file?: { bytes: Uint8Array; name: string } };
|
|
153
162
|
/** A derived document (its app's derive.ts, exported from its routes.ts): what it is now, for a member (nobody, 0),
|
|
154
163
|
* read off the documents it's derived from. Read-only: its pages write the documents it's read from. */
|
|
155
164
|
export type Derive = (read: Read, member: number) => Record<string, { id: number }[]>;
|
|
@@ -188,8 +197,10 @@ type App = {
|
|
|
188
197
|
routes?: Routes | ((read: Read, write: Write) => Routes);
|
|
189
198
|
/** Routes anyone may ask, reading each document as nobody (member 0): owns and sees apply, so a part only some see
|
|
190
199
|
* isn't there, but the group's door doesn't, so a document any member sees whole is whole. An open route shows only
|
|
191
|
-
* what it picks, and what it picks is public.
|
|
192
|
-
|
|
200
|
+
* what it picks, and what it picks is public. One that checks a secret of its own (a mail's intake, a webhook) is
|
|
201
|
+
* given the server's write, and `whole`, each document as the server holds it, every item: what it answers is still
|
|
202
|
+
* its own to pick. */
|
|
203
|
+
open?: Open | ((read: Read, write: Write, whole: Read) => Open);
|
|
193
204
|
trust?: Trust;
|
|
194
205
|
reactions?: Reactions;
|
|
195
206
|
derive?: Derive;
|
|
@@ -462,7 +473,8 @@ export async function start({
|
|
|
462
473
|
const may = await asking;
|
|
463
474
|
if (fresh(ws, `may ${doc}`, JSON.stringify(may))) say(ws, { doc, may });
|
|
464
475
|
}
|
|
465
|
-
const write
|
|
476
|
+
const write = (async (doc: string, ops: Op[], as?: As) => {
|
|
477
|
+
if (as) return writeAs(doc, ops, as);
|
|
466
478
|
wrote();
|
|
467
479
|
if (docParts(doc).name === GROUP || !(await store.exists(doc))) throw new Refused(`the server can't write ${doc}`);
|
|
468
480
|
const why = await ungranted(doc, ops, null);
|
|
@@ -471,6 +483,23 @@ export async function start({
|
|
|
471
483
|
await tell(landed);
|
|
472
484
|
retime();
|
|
473
485
|
return landed.changes[0]!;
|
|
486
|
+
}) as Write;
|
|
487
|
+
/** A route's write as a member, via its label (Write's `as`): a member of the group still, the file kept first. */
|
|
488
|
+
const writeAs = async (doc: string, ops: Op[], as: As) => {
|
|
489
|
+
if (!members || !((await read(GROUP)).members as Member[]).some((m) => m.id === as.member))
|
|
490
|
+
throw new Refused(`member ${as.member} isn't in the group`);
|
|
491
|
+
const who: Who = { member: as.member, token: "", agent: { id: `via ${as.via}`, member: as.member, label: as.via } };
|
|
492
|
+
let file: string | undefined;
|
|
493
|
+
if (as.file) {
|
|
494
|
+
const no = await mayPutAs(doc, who);
|
|
495
|
+
if (no) throw new Refused(no);
|
|
496
|
+
const kept = await keep(filesKept, as.file.bytes, as.file.name, (await apart(doc)) ? folderOf(doc) : "");
|
|
497
|
+
if ("refused" in kept) throw new Refused(kept.refused);
|
|
498
|
+
file = kept.file;
|
|
499
|
+
}
|
|
500
|
+
const w = await written([{ doc, ops: file ? filled(ops, file) : ops, ...(as.why ? { why: as.why } : {}) }], who);
|
|
501
|
+
if ("why" in w) throw new Refused(w.why);
|
|
502
|
+
return file ? { ...w, file } : w;
|
|
474
503
|
};
|
|
475
504
|
/** A change undone: its inverse, guarded as delta's walk is (refused if a value it changed has been changed
|
|
476
505
|
* since), written as the server's own write, by whoever undoes it, and told as any change is; what the rules
|
|
@@ -698,7 +727,7 @@ export async function start({
|
|
|
698
727
|
// door doesn't), so each shows only what it picks
|
|
699
728
|
const nobody: Read = (doc) => now(doc, 0);
|
|
700
729
|
for (const { app, open: of = {} } of apps)
|
|
701
|
-
for (const [path, answer] of Object.entries(typeof of === "function" ? of(nobody) : of)) {
|
|
730
|
+
for (const [path, answer] of Object.entries(typeof of === "function" ? of(nobody, write, now) : of)) {
|
|
702
731
|
if (path in routes) throw new Error(`${app || "the root"} and another app both answer ${path}`);
|
|
703
732
|
routes[path] = typeof answer === "function" ? settled(answer) : answer;
|
|
704
733
|
}
|
package/src/skill.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// The door's skills, served as MCP's skills extension (SEP-2640, io.modelcontextprotocol/skills) says: each SKILL.md a
|
|
2
2
|
// resource at skill://<name>/SKILL.md, and its entry (its frontmatter as written, each file's sha256 digest and size)
|
|
3
3
|
// for skills/list and skills/get. The door's own (.claude/skills/joined-door): how any joined document is read and
|
|
4
|
-
// written, one text read from its file,
|
|
4
|
+
// written, one text read from its file, never kept apart from it. And each
|
|
5
5
|
// app's: what its documents hold and mean, its own words (its routes.ts's `instructions`) and its documents' shapes,
|
|
6
|
-
// written from their compiled rules as their tools are, so it says what the app holds and never another thing.
|
|
6
|
+
// written from their compiled rules as their tools are, so it says what the app holds and never another thing. What the
|
|
7
|
+
// door says as it opens says none of it: where they are, and who's acting.
|
|
7
8
|
|
|
8
9
|
import { createHash } from "node:crypto";
|
|
9
10
|
import type { Rules } from "./write.ts";
|
|
@@ -47,13 +48,19 @@ function served(text: string) {
|
|
|
47
48
|
/** The door's own skill. */
|
|
48
49
|
export const skill = served(await Bun.file(new URL("../.claude/skills/joined-door/SKILL.md", import.meta.url)).text());
|
|
49
50
|
|
|
50
|
-
/** What
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
/** What the door says as it opens, to every client alike: short, so no client cuts it, and nothing a skill says, so
|
|
52
|
+
* each fact is in one place. Its documents, who's acting, and where the skills are: as the client loads skills, or by
|
|
53
|
+
* read_skill, a tool, which every client loads. */
|
|
54
|
+
export const opening = (apps: Skill[], docs: string[], as: string) =>
|
|
55
|
+
[
|
|
56
|
+
`This is a joined app's door: its documents are ${docs.join(", ") || "none"}. You act as ${as}.`,
|
|
57
|
+
`How any document here is read and written is the skill ${skill.name}${
|
|
58
|
+
apps.length
|
|
59
|
+
? `, and what each app's documents hold and mean is its own skill: ${apps.map((a) => a.name).join(", ")}`
|
|
60
|
+
: ""
|
|
61
|
+
}. Load ${apps.length ? "them" : "it"} before a write, as your client loads skills, or by read_skill.`,
|
|
62
|
+
"Read before you write; a write is made whole or not at all.",
|
|
63
|
+
].join(" ");
|
|
57
64
|
|
|
58
65
|
type Collection = Rules["collections"][string] & { needs?: readonly string[] };
|
|
59
66
|
|
|
@@ -63,7 +70,9 @@ const fieldsOf = (c: Collection) =>
|
|
|
63
70
|
.filter(([f]) => !(f in (c.fills ?? {})))
|
|
64
71
|
.map(([f, t]) => {
|
|
65
72
|
const to = c.links?.[f];
|
|
66
|
-
|
|
73
|
+
// the group's members are no document's collection: said as who they are (the door says which the agent's is)
|
|
74
|
+
const member = t === "ids" ? "members' ids, people in the group" : "a member's id, a person in the group";
|
|
75
|
+
const said = to === "members" ? member : to ? (t === "ids" ? `ids of ${to}` : `an id of ${to}`) : t;
|
|
67
76
|
return `${f} (${said}${c.needs?.includes(f) ? ", needed" : ""})`;
|
|
68
77
|
})
|
|
69
78
|
.join(", ");
|
package/src/stories.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { tmpdir } from "node:os";
|
|
|
7
7
|
import { APPS, ENGINE, OWN, type Story } from "./compile.ts";
|
|
8
8
|
import type { Dialect } from "./engine.ts";
|
|
9
9
|
import { start } from "./server.ts";
|
|
10
|
+
import { openKeys } from "./members/keys.ts";
|
|
10
11
|
import type { Member } from "./members/trust.ts";
|
|
11
12
|
import type { Op } from "./ops.ts";
|
|
12
13
|
import { madeBy, partsOf, type Part, type Told } from "./together.ts";
|
|
@@ -64,14 +65,25 @@ export async function fresh({
|
|
|
64
65
|
);
|
|
65
66
|
const server = await start({ port: 0, dir, db, engine, keys, files, rootToken: open ? "" : root });
|
|
66
67
|
/** A name's token: a member's, by their name (or the cast's), or undefined for nobody. */
|
|
67
|
-
const
|
|
68
|
+
const memberFor = async (name: string, cast: Record<string, string | null>) => {
|
|
68
69
|
const as = name in cast ? cast[name] : name;
|
|
69
70
|
if (as === null) return undefined;
|
|
70
71
|
const m = ((await server.read("members")).members as Member[]).find(
|
|
71
72
|
(x) => x.name.toLowerCase() === as!.toLowerCase(),
|
|
72
73
|
);
|
|
73
74
|
if (!m) throw new Error(`no member named ${as}`);
|
|
74
|
-
return
|
|
75
|
+
return m.id;
|
|
76
|
+
};
|
|
77
|
+
const tokenFor = async (name: string, cast: Record<string, string | null> = {}) => {
|
|
78
|
+
const m = await memberFor(name, cast);
|
|
79
|
+
return m === undefined ? undefined : (await server.tokenOf(m))!;
|
|
80
|
+
};
|
|
81
|
+
/** A name's agent's link's token, made for them under a label: what a story told via it is sent by. */
|
|
82
|
+
const agentFor = async (name: string, label: string, cast: Record<string, string | null> = {}) => {
|
|
83
|
+
const m = (await memberFor(name, cast))!,
|
|
84
|
+
held = await openKeys(server.store.db, root);
|
|
85
|
+
await held.makeAgent(m, label);
|
|
86
|
+
return (await held.agents(m)).at(-1)!.token;
|
|
75
87
|
};
|
|
76
88
|
return {
|
|
77
89
|
server,
|
|
@@ -80,6 +92,7 @@ export async function fresh({
|
|
|
80
92
|
files,
|
|
81
93
|
root,
|
|
82
94
|
tokenFor,
|
|
95
|
+
agentFor,
|
|
83
96
|
stop: async () => {
|
|
84
97
|
await server.stop(true);
|
|
85
98
|
await server.store.close();
|
|
@@ -164,7 +177,7 @@ export async function tell(doc: string, dir = APPS, engine = ENGINE) {
|
|
|
164
177
|
for (const s of await toldOf(doc, dir)) {
|
|
165
178
|
const anonymous = s.as === undefined,
|
|
166
179
|
as = s.as ?? ANYONE;
|
|
167
|
-
const { server, tokenFor, stop } = await fresh({ dir, open: anonymous, engine });
|
|
180
|
+
const { server, tokenFor, agentFor, stop } = await fresh({ dir, open: anonymous, engine });
|
|
168
181
|
// the story's own document: of a kind, its instance (shelf:1); of several writes, its first's (src/together.ts),
|
|
169
182
|
// and each other's there is before it (not one the write makes, board:$1)
|
|
170
183
|
const write = s.does ?? s.cannot!,
|
|
@@ -176,7 +189,9 @@ export async function tell(doc: string, dir = APPS, engine = ENGINE) {
|
|
|
176
189
|
? s.premise.map((w) => [ANYONE, w] as const)
|
|
177
190
|
: Object.entries(s.premise ?? {}).flatMap(([n, ws]) => ws.map((w) => [n, w] as const));
|
|
178
191
|
const names = [...new Set([...premise.map(([n]) => n), as, ...(s.seen ?? []), ...(s.unseen ?? [])])];
|
|
179
|
-
|
|
192
|
+
// a story told via an agent is sent by its teller's agent's link, made for it under that label
|
|
193
|
+
const tokenOf = (n: string) =>
|
|
194
|
+
n === ANYONE ? undefined : n === as && s.via ? agentFor(n, s.via, cast) : tokenFor(n, cast);
|
|
180
195
|
// the premise's pages first; the story's own once the premise has run, so it may be someone the premise made
|
|
181
196
|
const pages: Record<string, Awaited<ReturnType<typeof page>>> = {};
|
|
182
197
|
const open = async (ns: string[]) => {
|
|
@@ -291,6 +306,7 @@ export async function tell(doc: string, dir = APPS, engine = ENGINE) {
|
|
|
291
306
|
const short = told === "whole" ? !m.ops.length : told ? !heard.length : heard.join() !== ops.join();
|
|
292
307
|
if (short) wrong.push(`${s.story}: ${n} heard only ${heard.join(", ")}`);
|
|
293
308
|
if (m.by !== writer) wrong.push(`${s.story}: ${n} heard it as by ${m.by}, not ${writer}`);
|
|
309
|
+
if ((m.via ?? null) !== (s.via ?? null)) wrong.push(`${s.story}: ${n} heard it as via ${m.via ?? "nothing"}`);
|
|
294
310
|
}
|
|
295
311
|
for (const n of (await Promise.all(unseen)).filter(Boolean)) wrong.push(`${s.story}: ${n} heard it, unseen`);
|
|
296
312
|
// what it leaves: each path as its teller holds it, on a page of theirs that holds the document anew
|
|
@@ -358,8 +374,9 @@ export async function inBrowser(app: string, path: (doc: string) => string | nul
|
|
|
358
374
|
const cast = await castOf(app, dir);
|
|
359
375
|
const wrong: string[] = [];
|
|
360
376
|
for (const s of await toldOf(app, dir)) {
|
|
361
|
-
// (a write of several documents is no one element's: a page sends it by together(), joined/page
|
|
362
|
-
|
|
377
|
+
// (a write of several documents is no one element's: a page sends it by together(), joined/page; one told via an
|
|
378
|
+
// agent is no page's)
|
|
379
|
+
const write = Array.isArray(s.does) || s.via ? undefined : s.does;
|
|
363
380
|
const at = write && path(write.doc);
|
|
364
381
|
if (!write || at === null || at === undefined) continue;
|
|
365
382
|
const name = write.doc.split(/[:?]/)[0]!;
|
package/src/upload.ts
CHANGED
|
@@ -34,7 +34,8 @@ type Link = { doc: string; who: Who | null; name: string; until: number; ops?: O
|
|
|
34
34
|
export type Made = { url: string; until: string } | { why: string };
|
|
35
35
|
|
|
36
36
|
/** A write's ops with the file's value where "$file" stood. */
|
|
37
|
-
const filled = (ops: Op[], file: string): Op[] =>
|
|
37
|
+
export const filled = (ops: Op[], file: string): Op[] =>
|
|
38
|
+
JSON.parse(JSON.stringify(ops), (_, v) => (v === FILE ? file : v));
|
|
38
39
|
|
|
39
40
|
const escaped = (s: string) =>
|
|
40
41
|
s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]!);
|
package/src/write.ts
CHANGED
|
@@ -52,6 +52,9 @@ export type Rules = StoreRules & {
|
|
|
52
52
|
moves?: Record<string, string>;
|
|
53
53
|
/** The field holding an item's own code, by collection: a page holding the document by it is the item's guest. */
|
|
54
54
|
guests?: Record<string, string>;
|
|
55
|
+
/** What's a person's alone (definitions' person): by collection, each op and the words it's refused in to a write
|
|
56
|
+
* made via anything. */
|
|
57
|
+
person?: Record<string, Record<string, string>>;
|
|
55
58
|
/** Of a kind, its root item's own fields that govern it (definitions' frozen and waits). */
|
|
56
59
|
settings?: Settings;
|
|
57
60
|
/** The field of a kind's root holding its guest's level (definitions' visitors, src/visitors.ts). */
|
|
@@ -274,6 +277,19 @@ export function writes({
|
|
|
274
277
|
}
|
|
275
278
|
return null;
|
|
276
279
|
}
|
|
280
|
+
/** Why a write made via something (an agent's link, a route) is refused, in its definitions' words, or null: an op
|
|
281
|
+
* that's a person's alone (definitions' person), theirs by their own hand on a page. */
|
|
282
|
+
function byHand(doc: string, ops: Op[]) {
|
|
283
|
+
const { person } = rulesOf(doc);
|
|
284
|
+
for (const o of ops) {
|
|
285
|
+
const { coll } = parts(o.path),
|
|
286
|
+
[op, at] = grantOf(o).split(" ") as [string, string],
|
|
287
|
+
field = at.slice(coll.length + 1);
|
|
288
|
+
const said = person?.[coll]?.[field ? `${op} ${field}` : op];
|
|
289
|
+
if (said) return said;
|
|
290
|
+
}
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
277
293
|
/** Why a write's value isn't the kind of thing its op takes (an item added is its fields; a list, ids), or null: asked
|
|
278
294
|
* before any rule reads it, so a rule may. */
|
|
279
295
|
function misshapen(doc: string, ops: Op[]) {
|
|
@@ -654,7 +670,7 @@ export function writes({
|
|
|
654
670
|
doc: string,
|
|
655
671
|
ops: Op[],
|
|
656
672
|
why: string | undefined,
|
|
657
|
-
who: { member: number } | null,
|
|
673
|
+
who: { member: number; agent?: unknown } | null,
|
|
658
674
|
group: (
|
|
659
675
|
doc: string,
|
|
660
676
|
ops: Op[],
|
|
@@ -687,6 +703,8 @@ export function writes({
|
|
|
687
703
|
anyoneIs(doc, who?.member ?? null),
|
|
688
704
|
undoing,
|
|
689
705
|
) ??
|
|
706
|
+
// what's a person's alone, of a write made via anything: after the grants, so only someone they allow hears it
|
|
707
|
+
(who?.agent ? byHand(doc, ops) : null) ??
|
|
690
708
|
namedIn(doc, ops) ??
|
|
691
709
|
// of a kind, what its root item's settings say of a write the grants allow (a frozen board, one held for approval)
|
|
692
710
|
settled(
|