@yaks/member 0.0.0-stage → 0.2.36
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/LICENSE +202 -0
- package/README.md +471 -2
- package/_dist/asking.d.ts +4 -0
- package/_dist/asking.d.ts.map +1 -0
- package/_dist/comp.d.ts +14 -0
- package/_dist/comp.d.ts.map +1 -0
- package/_dist/deny.d.ts +19 -0
- package/_dist/deny.d.ts.map +1 -0
- package/_dist/graph.d.ts +4 -0
- package/_dist/graph.d.ts.map +1 -0
- package/_dist/guard.d.ts +45 -0
- package/_dist/guard.d.ts.map +1 -0
- package/_dist/keywords.d.ts +80 -0
- package/_dist/keywords.d.ts.map +1 -0
- package/_dist/mod.d.ts +112 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/owns.d.ts +18 -0
- package/_dist/owns.d.ts.map +1 -0
- package/_dist/pace.d.ts +48 -0
- package/_dist/pace.d.ts.map +1 -0
- package/_dist/personal.d.ts +46 -0
- package/_dist/personal.d.ts.map +1 -0
- package/_dist/plugin.d.ts +32 -0
- package/_dist/plugin.d.ts.map +1 -0
- package/_dist/policy.d.ts +35 -0
- package/_dist/policy.d.ts.map +1 -0
- package/_dist/privacy.d.ts +55 -0
- package/_dist/privacy.d.ts.map +1 -0
- package/_dist/roles.d.ts +20 -0
- package/_dist/roles.d.ts.map +1 -0
- package/_dist/vocab.d.ts +10 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/_dist/words.d.ts +53 -0
- package/_dist/words.d.ts.map +1 -0
- package/asking.js +65 -0
- package/asking.js.map +1 -0
- package/asking.ts +77 -0
- package/comp.js +43 -0
- package/comp.js.map +1 -0
- package/comp.ts +52 -0
- package/deno.json +1 -0
- package/deny.js +31 -0
- package/deny.js.map +1 -0
- package/deny.ts +45 -0
- package/graph.js +6 -0
- package/graph.js.map +1 -0
- package/graph.ts +16 -0
- package/guard.js +265 -0
- package/guard.js.map +1 -0
- package/guard.ts +327 -0
- package/keywords.js +170 -0
- package/keywords.js.map +1 -0
- package/keywords.ts +190 -0
- package/meta/member.vocab.json +70 -0
- package/mod.js +112 -0
- package/mod.js.map +1 -0
- package/mod.ts +113 -0
- package/owns.js +12 -0
- package/owns.js.map +1 -0
- package/owns.ts +23 -0
- package/pace.js +189 -0
- package/pace.js.map +1 -0
- package/pace.ts +195 -0
- package/package.json +33 -4
- package/personal.js +448 -0
- package/personal.js.map +1 -0
- package/personal.ts +550 -0
- package/plugin.js +63 -0
- package/plugin.js.map +1 -0
- package/plugin.ts +62 -0
- package/policy.js +115 -0
- package/policy.js.map +1 -0
- package/policy.ts +176 -0
- package/privacy.js +293 -0
- package/privacy.js.map +1 -0
- package/privacy.ts +379 -0
- package/roles.js +164 -0
- package/roles.js.map +1 -0
- package/roles.ts +245 -0
- package/vocab.js +19 -0
- package/vocab.js.map +1 -0
- package/vocab.json +272 -0
- package/vocab.ts +20 -0
- package/words.js +75 -0
- package/words.js.map +1 -0
- package/words.ts +123 -0
package/policy.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// The four questions, and the order they are answered in.
|
|
2
|
+
//
|
|
3
|
+
// Everything here follows from one idea: membership is not permission. A row on
|
|
4
|
+
// the roster does not, on its own, let you touch anything. So permission
|
|
5
|
+
// resolves in this order:
|
|
6
|
+
//
|
|
7
|
+
// 1. nobody at all → no level; the app's mode is the whole answer
|
|
8
|
+
// 2. the space's owner → owner on every app in it, never stored
|
|
9
|
+
// 3. a grant naming them → the level it confers
|
|
10
|
+
// 4. a member with no grant → no level; the app's mode again
|
|
11
|
+
//
|
|
12
|
+
// Steps 1 and 4 land in the same place, which is the point: a member without a
|
|
13
|
+
// grant reaches an app exactly as far as a stranger with the link does. That is
|
|
14
|
+
// what makes a roster safe to be generous with, and it is why removing someone
|
|
15
|
+
// is one row — delete the membership and every permission implied by it goes
|
|
16
|
+
// too.
|
|
17
|
+
//
|
|
18
|
+
// A share link is the fourth way in. A grant may name a `token` instead of a
|
|
19
|
+
// person; whoever opens that link acts as the grant, so the HTTP layer signs
|
|
20
|
+
// the bundles with the grant's own entity id. `levelOn` therefore checks the
|
|
21
|
+
// principal's own entity for a `grant` component before it looks for grants
|
|
22
|
+
// filed about the principal.
|
|
23
|
+
//
|
|
24
|
+
// The two rules themselves are `reads` and `edits` in words.ts — pure functions
|
|
25
|
+
// of a mode and a level — and everything here resolves the level to call them
|
|
26
|
+
// with. Stated once there, the read check at the HTTP layer, the write check in
|
|
27
|
+
// `apply()`, and a service that already knows both values cannot drift apart:
|
|
28
|
+
//
|
|
29
|
+
// read the mode is not `private`, or the principal holds any level
|
|
30
|
+
// write the mode is `open`, or the principal holds owner or editor
|
|
31
|
+
//
|
|
32
|
+
// Every function here threads @yaks/graph's synchronous pass-through: over a
|
|
33
|
+
// synchronous storage (a Map, an embedded database) none of them returns a
|
|
34
|
+
// promise.
|
|
35
|
+
import { after } from "@yaks/fp";
|
|
36
|
+
import { detached } from "@yaks/graph/storage";
|
|
37
|
+
import { and, eq, or } from "@yaks/query";
|
|
38
|
+
import { ACCESS, GRANT, MEMBER } from "./comp.js";
|
|
39
|
+
import { edits, level, mode, reads } from "./words.js";
|
|
40
|
+
// One component off a bundle, or undefined.
|
|
41
|
+
let of = (b, name)=>b?.[name];
|
|
42
|
+
/** The app's access mode, read through a transaction: its `access` and
|
|
43
|
+
* nothing else, since this runs on every request and a whole read of an
|
|
44
|
+
* entity can ask every table the vocabulary has. */ export let modeOn = (tx, app)=>after(tx.get([
|
|
45
|
+
app
|
|
46
|
+
], [
|
|
47
|
+
ACCESS
|
|
48
|
+
]), ([b])=>mode(of(b, ACCESS)?.mode));
|
|
49
|
+
/**
|
|
50
|
+
* Everything filed about this principal: their membership rows, their grants.
|
|
51
|
+
* Both are entities with a property pointing at the principal, so the two steps
|
|
52
|
+
* that would each have been a read are one backwards read (@yaks/graph
|
|
53
|
+
* `about`), and none at all when the gather already fetched them (@yaks/graph
|
|
54
|
+
* `wants`, declared by {@link https://jsr.io/@yaks/member/doc/~/members |
|
|
55
|
+
* members}).
|
|
56
|
+
*
|
|
57
|
+
* It reads a principal's whole file rather than the one row a given step needs,
|
|
58
|
+
* and the steps then pick out what they want. That is the trade the gather
|
|
59
|
+
* makes everywhere: a principal has as many of these rows as they have
|
|
60
|
+
* memberships and grants, which is a handful, and a handful in one response
|
|
61
|
+
* beats two round trips.
|
|
62
|
+
*/ let filed = (tx, who)=>tx.about ? tx.about([
|
|
63
|
+
who
|
|
64
|
+
], [
|
|
65
|
+
GRANT,
|
|
66
|
+
MEMBER
|
|
67
|
+
]) : tx.read(and(or(eq(`${GRANT}.person`, who), eq(`${MEMBER}.person`, who))));
|
|
68
|
+
/**
|
|
69
|
+
* What `who` holds on `app`, read through a transaction, following the
|
|
70
|
+
* resolution order above step by step. Returns `null` when they hold nothing —
|
|
71
|
+
* which is not a refusal, only the answer that the app's mode decides.
|
|
72
|
+
*/ export let levelOn = (tx, who, app, where = {})=>{
|
|
73
|
+
if (!who) return null;
|
|
74
|
+
return after(tx.get([
|
|
75
|
+
who
|
|
76
|
+
], [
|
|
77
|
+
GRANT
|
|
78
|
+
]), ([self])=>{
|
|
79
|
+
// A share link's bearer is the grant they opened.
|
|
80
|
+
let own = self && !where.ignore?.(self) ? of(self, GRANT) : undefined;
|
|
81
|
+
if (own && own.app == app) return level(own.access);
|
|
82
|
+
return after(filed(tx, who), (found)=>{
|
|
83
|
+
found = found.filter((row)=>!where.ignore?.(row));
|
|
84
|
+
// The space's owner, before any grant. Never stored per app — a space
|
|
85
|
+
// owner owns everything in it, and storing that would be a row to forget
|
|
86
|
+
// to write.
|
|
87
|
+
let owner = where.space && found.some((b)=>{
|
|
88
|
+
let m = of(b, MEMBER);
|
|
89
|
+
return m?.space == where.space && m?.person == who && m?.role == 'owner';
|
|
90
|
+
});
|
|
91
|
+
if (owner) return 'owner';
|
|
92
|
+
let g = found.map((b)=>of(b, GRANT)).find((c)=>c?.app == app && c.person == who);
|
|
93
|
+
return g ? level(g.access) : null;
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
/** May they read it? The mode is not `private`, or they hold something. */ export let readsOn = (tx, who, app, where = {})=>after(modeOn(tx, app), // Check the anonymous case first: a mode that admits nobody in particular
|
|
98
|
+
// admits everybody, and the permission lookup never runs.
|
|
99
|
+
(m)=>reads(m, null) || after(levelOn(tx, who, app, where), (l)=>reads(m, l)));
|
|
100
|
+
/** May they write it? The mode is `open`, or they hold owner or editor. */ export let writesOn = (tx, who, app, where = {})=>after(modeOn(tx, app), (m)=>edits(m, null) || after(levelOn(tx, who, app, where), (l)=>edits(m, l)));
|
|
101
|
+
/**
|
|
102
|
+
* The read-side helper, bound to a storage: what the HTTP layer calls before it
|
|
103
|
+
* answers a query, since a read never reaches `apply()` and so is never seen by
|
|
104
|
+
* the write guard: with `may = policy(storage, { space: club })`, a door
|
|
105
|
+
* answers 404 where `may.canRead(who, app)` is false.
|
|
106
|
+
*/ export let policy = (storage, where = {})=>{
|
|
107
|
+
let tx = detached(storage);
|
|
108
|
+
return {
|
|
109
|
+
modeOf: (app)=>modeOn(tx, app),
|
|
110
|
+
levelOf: (who, app)=>levelOn(tx, who, app, where),
|
|
111
|
+
canRead: (who, app)=>readsOn(tx, who, app, where),
|
|
112
|
+
canWrite: (who, app)=>writesOn(tx, who, app, where)
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
//# sourceMappingURL=policy.js.map
|
package/policy.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.js","sources":["./policy.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,EAAE;AACF,gFAAgF;AAChF,yEAAyE;AACzE,0BAA0B;AAC1B,EAAE;AACF,8EAA8E;AAC9E,wEAAwE;AACxE,sDAAsD;AACtD,gEAAgE;AAChE,EAAE;AACF,+EAA+E;AAC/E,gFAAgF;AAChF,+EAA+E;AAC/E,6EAA6E;AAC7E,OAAO;AACP,EAAE;AACF,6EAA6E;AAC7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IAAI,KAAK,KAAK;IAC7C,SAAS,CAAC,KAAK,MAAQ,QAAQ,IAAI,KAAK,KAAK;IAC7C,UAAU,CAAC,KAAK,MAAQ,SAAS,IAAI,KAAK,KAAK;EACjD;AACF,EAAC"}
|
package/policy.ts
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// The four questions, and the order they are answered in.
|
|
2
|
+
//
|
|
3
|
+
// Everything here follows from one idea: membership is not permission. A row on
|
|
4
|
+
// the roster does not, on its own, let you touch anything. So permission
|
|
5
|
+
// resolves in this order:
|
|
6
|
+
//
|
|
7
|
+
// 1. nobody at all → no level; the app's mode is the whole answer
|
|
8
|
+
// 2. the space's owner → owner on every app in it, never stored
|
|
9
|
+
// 3. a grant naming them → the level it confers
|
|
10
|
+
// 4. a member with no grant → no level; the app's mode again
|
|
11
|
+
//
|
|
12
|
+
// Steps 1 and 4 land in the same place, which is the point: a member without a
|
|
13
|
+
// grant reaches an app exactly as far as a stranger with the link does. That is
|
|
14
|
+
// what makes a roster safe to be generous with, and it is why removing someone
|
|
15
|
+
// is one row — delete the membership and every permission implied by it goes
|
|
16
|
+
// too.
|
|
17
|
+
//
|
|
18
|
+
// A share link is the fourth way in. A grant may name a `token` instead of a
|
|
19
|
+
// person; whoever opens that link acts as the grant, so the HTTP layer signs
|
|
20
|
+
// the bundles with the grant's own entity id. `levelOn` therefore checks the
|
|
21
|
+
// principal's own entity for a `grant` component before it looks for grants
|
|
22
|
+
// filed about the principal.
|
|
23
|
+
//
|
|
24
|
+
// The two rules themselves are `reads` and `edits` in words.ts — pure functions
|
|
25
|
+
// of a mode and a level — and everything here resolves the level to call them
|
|
26
|
+
// with. Stated once there, the read check at the HTTP layer, the write check in
|
|
27
|
+
// `apply()`, and a service that already knows both values cannot drift apart:
|
|
28
|
+
//
|
|
29
|
+
// read the mode is not `private`, or the principal holds any level
|
|
30
|
+
// write the mode is `open`, or the principal holds owner or editor
|
|
31
|
+
//
|
|
32
|
+
// Every function here threads @yaks/graph's synchronous pass-through: over a
|
|
33
|
+
// synchronous storage (a Map, an embedded database) none of them returns a
|
|
34
|
+
// promise.
|
|
35
|
+
|
|
36
|
+
import type { Bundle, Comp, Eid, ReadTx, Storage } from 'jsr:@yaks/graph@0.2.36'
|
|
37
|
+
import { after } from '@yaks/fp'
|
|
38
|
+
import { detached } from '@yaks/graph/storage'
|
|
39
|
+
import { and, eq, or } from '@yaks/query'
|
|
40
|
+
import { ACCESS, GRANT, MEMBER } from './comp.js'
|
|
41
|
+
import { edits, type Level, level, type Mode, mode, reads } from './words.js'
|
|
42
|
+
|
|
43
|
+
/** Who is acting: the entity the HTTP layer signed the request with, or `null`
|
|
44
|
+
* for nobody — an anonymous visitor with only the link. */
|
|
45
|
+
export type Viewer = Eid | null
|
|
46
|
+
|
|
47
|
+
/** Where the roster and the grants are read from, and which space's owners
|
|
48
|
+
* count. */
|
|
49
|
+
export type Where = {
|
|
50
|
+
/** the space whose owners own every app in it. Omit it and only grants
|
|
51
|
+
* count — a graph holding one app and no roster needs no space. */
|
|
52
|
+
space?: Eid
|
|
53
|
+
/** Standing rows superseded by an authoritative source are left out. Other
|
|
54
|
+
* stored grants and memberships still participate in the same policy. */
|
|
55
|
+
ignore?: (row: Bundle) => boolean
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The checks the HTTP layer and the write guard both call. Each returns a
|
|
59
|
+
* value rather than a promise over a synchronous storage. */
|
|
60
|
+
export type Policy = {
|
|
61
|
+
/** the app's mode — `private` when it has no `access` component */
|
|
62
|
+
modeOf: (app: Eid) => Mode | Promise<Mode>
|
|
63
|
+
/** what this principal holds on this app, or `null` for nothing */
|
|
64
|
+
levelOf: (who: Viewer, app: Eid) => Level | null | Promise<Level | null>
|
|
65
|
+
/** may they read it? */
|
|
66
|
+
canRead: (who: Viewer, app: Eid) => boolean | Promise<boolean>
|
|
67
|
+
/** may they write it? */
|
|
68
|
+
canWrite: (who: Viewer, app: Eid) => boolean | Promise<boolean>
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// One component off a bundle, or undefined.
|
|
72
|
+
let of = (b: Bundle | undefined, name: string): Comp | undefined =>
|
|
73
|
+
b?.[name] as Comp | undefined
|
|
74
|
+
|
|
75
|
+
/** The app's access mode, read through a transaction: its `access` and
|
|
76
|
+
* nothing else, since this runs on every request and a whole read of an
|
|
77
|
+
* entity can ask every table the vocabulary has. */
|
|
78
|
+
export let modeOn = (tx: ReadTx, app: Eid): Mode | Promise<Mode> =>
|
|
79
|
+
after(tx.get([app], [ACCESS]), ([b]) => mode(of(b, ACCESS)?.mode))
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Everything filed about this principal: their membership rows, their grants.
|
|
83
|
+
* Both are entities with a property pointing at the principal, so the two steps
|
|
84
|
+
* that would each have been a read are one backwards read (@yaks/graph
|
|
85
|
+
* `about`), and none at all when the gather already fetched them (@yaks/graph
|
|
86
|
+
* `wants`, declared by {@link https://jsr.io/@yaks/member/doc/~/members |
|
|
87
|
+
* members}).
|
|
88
|
+
*
|
|
89
|
+
* It reads a principal's whole file rather than the one row a given step needs,
|
|
90
|
+
* and the steps then pick out what they want. That is the trade the gather
|
|
91
|
+
* makes everywhere: a principal has as many of these rows as they have
|
|
92
|
+
* memberships and grants, which is a handful, and a handful in one response
|
|
93
|
+
* beats two round trips.
|
|
94
|
+
*/
|
|
95
|
+
let filed = (tx: ReadTx, who: Eid): Bundle[] | Promise<Bundle[]> =>
|
|
96
|
+
tx.about ? tx.about([who], [GRANT, MEMBER]) : tx.read(
|
|
97
|
+
and(or(eq(`${GRANT}.person`, who), eq(`${MEMBER}.person`, who))),
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* What `who` holds on `app`, read through a transaction, following the
|
|
102
|
+
* resolution order above step by step. Returns `null` when they hold nothing —
|
|
103
|
+
* which is not a refusal, only the answer that the app's mode decides.
|
|
104
|
+
*/
|
|
105
|
+
export let levelOn = (
|
|
106
|
+
tx: ReadTx,
|
|
107
|
+
who: Viewer,
|
|
108
|
+
app: Eid,
|
|
109
|
+
where: Where = {},
|
|
110
|
+
): Level | null | Promise<Level | null> => {
|
|
111
|
+
if (!who) return null
|
|
112
|
+
return after(tx.get([who], [GRANT]), ([self]) => {
|
|
113
|
+
// A share link's bearer is the grant they opened.
|
|
114
|
+
let own = self && !where.ignore?.(self) ? of(self, GRANT) : undefined
|
|
115
|
+
if (own && own.app == app) return level(own.access)
|
|
116
|
+
return after(filed(tx, who), (found) => {
|
|
117
|
+
found = found.filter((row) => !where.ignore?.(row))
|
|
118
|
+
// The space's owner, before any grant. Never stored per app — a space
|
|
119
|
+
// owner owns everything in it, and storing that would be a row to forget
|
|
120
|
+
// to write.
|
|
121
|
+
let owner = where.space && found.some((b) => {
|
|
122
|
+
let m = of(b, MEMBER)
|
|
123
|
+
return m?.space == where.space && m?.person == who &&
|
|
124
|
+
m?.role == 'owner'
|
|
125
|
+
})
|
|
126
|
+
if (owner) return 'owner' as Level
|
|
127
|
+
let g = found.map((b) => of(b, GRANT))
|
|
128
|
+
.find((c) => c?.app == app && c.person == who)
|
|
129
|
+
return g ? level(g.access) : null
|
|
130
|
+
})
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** May they read it? The mode is not `private`, or they hold something. */
|
|
135
|
+
export let readsOn = (
|
|
136
|
+
tx: ReadTx,
|
|
137
|
+
who: Viewer,
|
|
138
|
+
app: Eid,
|
|
139
|
+
where: Where = {},
|
|
140
|
+
): boolean | Promise<boolean> =>
|
|
141
|
+
after(
|
|
142
|
+
modeOn(tx, app),
|
|
143
|
+
// Check the anonymous case first: a mode that admits nobody in particular
|
|
144
|
+
// admits everybody, and the permission lookup never runs.
|
|
145
|
+
(m) =>
|
|
146
|
+
reads(m, null) || after(levelOn(tx, who, app, where), (l) => reads(m, l)),
|
|
147
|
+
) as boolean | Promise<boolean>
|
|
148
|
+
|
|
149
|
+
/** May they write it? The mode is `open`, or they hold owner or editor. */
|
|
150
|
+
export let writesOn = (
|
|
151
|
+
tx: ReadTx,
|
|
152
|
+
who: Viewer,
|
|
153
|
+
app: Eid,
|
|
154
|
+
where: Where = {},
|
|
155
|
+
): boolean | Promise<boolean> =>
|
|
156
|
+
after(
|
|
157
|
+
modeOn(tx, app),
|
|
158
|
+
(m) =>
|
|
159
|
+
edits(m, null) || after(levelOn(tx, who, app, where), (l) => edits(m, l)),
|
|
160
|
+
) as boolean | Promise<boolean>
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* The read-side helper, bound to a storage: what the HTTP layer calls before it
|
|
164
|
+
* answers a query, since a read never reaches `apply()` and so is never seen by
|
|
165
|
+
* the write guard: with `may = policy(storage, { space: club })`, a door
|
|
166
|
+
* answers 404 where `may.canRead(who, app)` is false.
|
|
167
|
+
*/
|
|
168
|
+
export let policy = (storage: Storage, where: Where = {}): Policy => {
|
|
169
|
+
let tx = detached(storage)
|
|
170
|
+
return {
|
|
171
|
+
modeOf: (app) => modeOn(tx, app),
|
|
172
|
+
levelOf: (who, app) => levelOn(tx, who, app, where),
|
|
173
|
+
canRead: (who, app) => readsOn(tx, who, app, where),
|
|
174
|
+
canWrite: (who, app) => writesOn(tx, who, app, where),
|
|
175
|
+
}
|
|
176
|
+
}
|
package/privacy.js
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
// Who may read each entity, kept on it as `_privacy{person, shut, signed,
|
|
2
|
+
// floor, hash}`, so a person's read is screened by one component rather than
|
|
3
|
+
// by every declaration a store holds. Asked per derived input, that screen was
|
|
4
|
+
// past what workerd's SQLite takes: an app store's `.session` read named it 38
|
|
5
|
+
// times, through a reference to what a page inherits from (T-156127).
|
|
6
|
+
//
|
|
7
|
+
// The privacy is what the declarations say of an entity's components (./
|
|
8
|
+
// personal.ts): each `personal` one names its person; each inherited one
|
|
9
|
+
// lends what its source's own components say, and one naming no source names
|
|
10
|
+
// nobody; each `readers` one asks a floor. An entity wearing none of them
|
|
11
|
+
// keeps no privacy; one wearing any keeps one, open or not, with the hash of
|
|
12
|
+
// the declarations it was reckoned under.
|
|
13
|
+
//
|
|
14
|
+
// The rule (`keeping`) writes it in the commit that makes or changes what it
|
|
15
|
+
// is read from, and rewrites what hangs on an entity whose own part moved. A
|
|
16
|
+
// store holding an entity whose privacy is missing or was reckoned under other
|
|
17
|
+
// declarations (`stale`) is read by the declarations themselves, until a pass
|
|
18
|
+
// has written them all.
|
|
19
|
+
import { after } from "@yaks/fp";
|
|
20
|
+
import { absent, and, eq, joined, line, or, sub } from "@yaks/query/core";
|
|
21
|
+
import { dead } from "@yaks/graph/bundle";
|
|
22
|
+
import { token } from "@yaks/graph/sha256";
|
|
23
|
+
import { asking, conditions } from "./asking.js";
|
|
24
|
+
import { LEVELS, reaches } from "./words.js";
|
|
25
|
+
/** The component an entity's privacy is kept in. */ export let PRIVACY = '_privacy';
|
|
26
|
+
let ref = (b, comp, prop)=>{
|
|
27
|
+
let v = b?.[comp]?.[prop];
|
|
28
|
+
return v == null ? undefined : String(v);
|
|
29
|
+
};
|
|
30
|
+
// Keep each lookup within the store's statement limits.
|
|
31
|
+
let fifties = (items)=>Array.from({
|
|
32
|
+
length: Math.ceil(items.length / 50)
|
|
33
|
+
}, (_, i)=>items.slice(i * 50, i * 50 + 50));
|
|
34
|
+
/**
|
|
35
|
+
* The privacy these declarations reckon, for a vocabulary that keeps it.
|
|
36
|
+
*
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { assertEquals } from '@std/assert'
|
|
39
|
+
* import { privacy } from '@yaks/member'
|
|
40
|
+
* let p = privacy({
|
|
41
|
+
* owners: [['draft', 'by']],
|
|
42
|
+
* through: [['page', 'document']],
|
|
43
|
+
* floors: [['order', 'editor']],
|
|
44
|
+
* })
|
|
45
|
+
* let docs = { d: { entity: { eid: 'd' }, draft: { by: 'ana' } } }
|
|
46
|
+
* let page = { entity: { eid: 'p' }, page: { document: 'd' }, order: {} }
|
|
47
|
+
* assertEquals(p.of(page, (eid) => docs[eid as 'd']), {
|
|
48
|
+
* person: 'ana',
|
|
49
|
+
* shut: null,
|
|
50
|
+
* signed: null,
|
|
51
|
+
* floor: 'editor',
|
|
52
|
+
* hash: p.hash,
|
|
53
|
+
* })
|
|
54
|
+
* assertEquals(p.of({ entity: { eid: 'n' }, note: {} }, () => undefined), null)
|
|
55
|
+
* ```
|
|
56
|
+
*/ export let privacy = (declared)=>{
|
|
57
|
+
// In one order, so that the same declarations hash the same however given.
|
|
58
|
+
let sorted = (pairs)=>pairs.toSorted(([a], [b])=>a < b ? -1 : a > b ? 1 : 0);
|
|
59
|
+
let owners = sorted(declared.owners), through = sorted(declared.through);
|
|
60
|
+
let floors = sorted(declared.floors);
|
|
61
|
+
let asks = new Map(floors.map(([name, asked])=>[
|
|
62
|
+
name,
|
|
63
|
+
asking(asked, declared.vocab)
|
|
64
|
+
]));
|
|
65
|
+
// A floor alone hashes as it always has; conditions, lowest floor first.
|
|
66
|
+
let hash = token({
|
|
67
|
+
owners,
|
|
68
|
+
through,
|
|
69
|
+
floors: floors.map(([name, asked])=>[
|
|
70
|
+
name,
|
|
71
|
+
typeof asked == 'string' ? asked : conditions(asked)
|
|
72
|
+
])
|
|
73
|
+
}).slice(0, 16);
|
|
74
|
+
/** What an entity's privacy is read from. */ let bearing = [
|
|
75
|
+
...new Set([
|
|
76
|
+
...owners,
|
|
77
|
+
...through,
|
|
78
|
+
...floors
|
|
79
|
+
].map(([name])=>name))
|
|
80
|
+
];
|
|
81
|
+
/** What a source lends the entities inheriting from it. */ let part = [
|
|
82
|
+
...new Set([
|
|
83
|
+
...owners,
|
|
84
|
+
...floors
|
|
85
|
+
].map(([name])=>name))
|
|
86
|
+
];
|
|
87
|
+
// Whom a source's components name, and the floors they ask.
|
|
88
|
+
let lend = (b, persons, asked)=>{
|
|
89
|
+
for (let [name, by] of owners){
|
|
90
|
+
let c = b[name];
|
|
91
|
+
if (c) persons.push(c[by] == null ? null : String(c[by]));
|
|
92
|
+
}
|
|
93
|
+
for (let [name] of floors){
|
|
94
|
+
let floor = b[name] && asks.get(name)(b);
|
|
95
|
+
if (floor) asked.add(floor);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
/** The privacy `e` makes, its sources read through `at`: none for an
|
|
99
|
+
* entity wearing nothing it is read from. */ let of = (e, at)=>{
|
|
100
|
+
if (!e || dead(e) || !bearing.some((name)=>e[name])) return null;
|
|
101
|
+
let persons = [], asked = new Set();
|
|
102
|
+
lend(e, persons, asked);
|
|
103
|
+
for (let [name, prop] of through){
|
|
104
|
+
if (!e[name]) continue;
|
|
105
|
+
let source = ref(e, name, prop);
|
|
106
|
+
if (!source) persons.push(null);
|
|
107
|
+
else {
|
|
108
|
+
let s = at(source);
|
|
109
|
+
if (s && !dead(s)) lend(s, persons, asked);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
let [first] = persons;
|
|
113
|
+
let one = first != null && persons.every((p)=>p == first);
|
|
114
|
+
let floor = LEVELS.findLast((l)=>asked.has(l)) ?? null;
|
|
115
|
+
return {
|
|
116
|
+
person: one ? first : null,
|
|
117
|
+
shut: persons.length && !one ? true : null,
|
|
118
|
+
signed: asked.has('person') ? true : null,
|
|
119
|
+
floor,
|
|
120
|
+
hash
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
let same = (a, b)=>!a == !b && (!a || [
|
|
124
|
+
'person',
|
|
125
|
+
'shut',
|
|
126
|
+
'signed',
|
|
127
|
+
'floor',
|
|
128
|
+
'hash'
|
|
129
|
+
].every((p)=>(a[p] ?? null) == (b[p] ?? null)));
|
|
130
|
+
/** The sources an entity inherits from. */ let sources = (e)=>through.flatMap(([name, prop])=>ref(e, name, prop) ?? []);
|
|
131
|
+
/** The privacy patches these entities owe, read through `get`: each whose
|
|
132
|
+
* kept privacy is not the one it makes. */ let reckon = (get, eids)=>{
|
|
133
|
+
if (!eids.length) return [];
|
|
134
|
+
return after(get(eids, [
|
|
135
|
+
...bearing,
|
|
136
|
+
PRIVACY
|
|
137
|
+
]), (rows)=>{
|
|
138
|
+
let wanted = [
|
|
139
|
+
...new Set(rows.filter((r)=>!dead(r)).flatMap(sources))
|
|
140
|
+
];
|
|
141
|
+
return after(wanted.length ? get(wanted, part) : [], (found)=>{
|
|
142
|
+
let held = new Map(found.map((b)=>[
|
|
143
|
+
b.entity.eid,
|
|
144
|
+
b
|
|
145
|
+
]));
|
|
146
|
+
return rows.filter((r)=>!dead(r)).flatMap((e)=>{
|
|
147
|
+
let want = of(e, (eid)=>held.get(eid));
|
|
148
|
+
let had = e[PRIVACY] ?? null;
|
|
149
|
+
return same(had, want) ? [] : [
|
|
150
|
+
{
|
|
151
|
+
entity: {
|
|
152
|
+
eid: e.entity.eid
|
|
153
|
+
},
|
|
154
|
+
[PRIVACY]: want
|
|
155
|
+
}
|
|
156
|
+
];
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
/** The entities whose privacy is missing or was reckoned under other
|
|
162
|
+
* declarations, as lines a store answers from an index each: what a pass
|
|
163
|
+
* writes, and what a store must hold none of to be read by its privacy. */ let stale = fifties([
|
|
164
|
+
...bearing.map((c)=>line`.${c}&!${PRIVACY}`),
|
|
165
|
+
line`.${PRIVACY}.hash<${hash}`,
|
|
166
|
+
line`.${PRIVACY}.hash>${hash}`
|
|
167
|
+
]).map((group)=>line`(${sub(joined(group, '|'))})`);
|
|
168
|
+
// Ask for any stale identity. Ordering the matches or fetching their
|
|
169
|
+
// components does extra work before the first scoped read.
|
|
170
|
+
let outstanding = stale.map((group)=>line`${sub(group)}&.limit=1&.fields=entity.eid`);
|
|
171
|
+
/** Whether a store, read through `read`, holds no entity whose privacy is
|
|
172
|
+
* stale. */ let current = (read, i = 0)=>i == outstanding.length || after(read(outstanding[i], {
|
|
173
|
+
unordered: true
|
|
174
|
+
}, [
|
|
175
|
+
'entity'
|
|
176
|
+
]), (rows)=>!rows.length && current(read, i + 1));
|
|
177
|
+
/** The entities `who`, holding `level`, may read by their privacy. */ let seen = (who, level)=>{
|
|
178
|
+
let at = (prop)=>`${PRIVACY}.${prop}`;
|
|
179
|
+
let reached = LEVELS.filter((l)=>reaches(level, l));
|
|
180
|
+
return and(or(absent(PRIVACY), and(who ? or(absent(at('person')), eq(at('person'), who)) : absent(at('person')), absent(at('shut')), ...who ? [] : [
|
|
181
|
+
absent(at('signed'))
|
|
182
|
+
], reached.length ? or(absent(at('floor')), ...reached.map((l)=>eq(at('floor'), l))) : absent(at('floor')))));
|
|
183
|
+
};
|
|
184
|
+
// The entities that hang on these, by every reference they inherit through.
|
|
185
|
+
let hanging = (tx, eids)=>{
|
|
186
|
+
let lines = through.flatMap(([name, prop])=>fifties(eids).map((list)=>line`.${name}.${prop}=${list}&.fields=entity.eid`));
|
|
187
|
+
let out = [];
|
|
188
|
+
let next = (i)=>i == lines.length ? out : after(tx.read(lines[i]), (rows)=>{
|
|
189
|
+
out.push(...rows.map((r)=>r.entity.eid));
|
|
190
|
+
return next(i + 1);
|
|
191
|
+
});
|
|
192
|
+
return next(0);
|
|
193
|
+
};
|
|
194
|
+
// An entity's own part in what inherits from it.
|
|
195
|
+
let partOf = (b)=>!b || dead(b) ? 'gone' : JSON.stringify(part.map((name)=>b[name] ?? null));
|
|
196
|
+
/**
|
|
197
|
+
* The rule that keeps every entity's privacy, in the commit that makes or
|
|
198
|
+
* changes it. Whatever a transaction writes, a caller's batch, a rule's, a
|
|
199
|
+
* cascade's, each entity it wrote privacy is read from on is given the
|
|
200
|
+
* privacy it now makes, and so is everything inheriting from one whose own
|
|
201
|
+
* part moved. The rule's own writes go beneath it, so a privacy anyone else
|
|
202
|
+
* writes is put back. `settling` hears each write that could leave no
|
|
203
|
+
* entity stale: one naming a privacy, as a pass's does, or a removal.
|
|
204
|
+
*/ let keeping = (tx, below = tx, settling = ()=>{})=>{
|
|
205
|
+
let before = new Map();
|
|
206
|
+
let dirty = new Set();
|
|
207
|
+
let looked = (eids)=>{
|
|
208
|
+
let fresh = [
|
|
209
|
+
...new Set(eids)
|
|
210
|
+
].filter((e)=>!before.has(e));
|
|
211
|
+
return after(fresh.length ? tx.get(fresh, part) : [], (rows)=>{
|
|
212
|
+
let by = new Map(rows.map((b)=>[
|
|
213
|
+
b.entity.eid,
|
|
214
|
+
b
|
|
215
|
+
]));
|
|
216
|
+
for (let e of fresh)before.set(e, partOf(by.get(e)));
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
let touches = (b, comps)=>comps.some((c)=>b[c] !== undefined);
|
|
220
|
+
let writes = [
|
|
221
|
+
...bearing,
|
|
222
|
+
PRIVACY
|
|
223
|
+
];
|
|
224
|
+
return {
|
|
225
|
+
tx: {
|
|
226
|
+
...below,
|
|
227
|
+
patch: (bundles)=>{
|
|
228
|
+
let bearing = bundles.filter((b)=>touches(b, writes));
|
|
229
|
+
for (let b of bearing)dirty.add(b.entity.eid);
|
|
230
|
+
if (bundles.some((b)=>b[PRIVACY] !== undefined || b.$delete)) {
|
|
231
|
+
settling();
|
|
232
|
+
}
|
|
233
|
+
let lending = bundles.filter((b)=>touches(b, part)).map((b)=>b.entity.eid);
|
|
234
|
+
return after(looked(lending), ()=>below.patch(bundles));
|
|
235
|
+
},
|
|
236
|
+
remove: (entities)=>{
|
|
237
|
+
for (let e of entities)dirty.add(e.eid);
|
|
238
|
+
settling();
|
|
239
|
+
return after(looked(entities.map((e)=>e.eid)), ()=>below.remove(entities));
|
|
240
|
+
},
|
|
241
|
+
revive: (eids)=>{
|
|
242
|
+
for (let e of eids)dirty.add(e);
|
|
243
|
+
return after(looked(eids), ()=>below.revive(eids));
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
flush: (bundles)=>{
|
|
247
|
+
if (!dirty.size) return bundles;
|
|
248
|
+
let wrote = [
|
|
249
|
+
...dirty
|
|
250
|
+
], was = new Map(before);
|
|
251
|
+
dirty.clear();
|
|
252
|
+
before.clear();
|
|
253
|
+
return after(was.size ? tx.get([
|
|
254
|
+
...was.keys()
|
|
255
|
+
], part) : [], (rows)=>{
|
|
256
|
+
let now = new Map(rows.map((b)=>[
|
|
257
|
+
b.entity.eid,
|
|
258
|
+
b
|
|
259
|
+
]));
|
|
260
|
+
let moved = [
|
|
261
|
+
...was
|
|
262
|
+
].filter(([e, p])=>partOf(now.get(e)) != p).map(([e])=>e);
|
|
263
|
+
return after(moved.length && through.length ? hanging(tx, moved) : [], (hung)=>after(reckon((e, c)=>tx.get(e, c), [
|
|
264
|
+
...new Set([
|
|
265
|
+
...wrote,
|
|
266
|
+
...hung
|
|
267
|
+
])
|
|
268
|
+
]), (patches)=>patches.length ? after(tx.patch(patches), ()=>[
|
|
269
|
+
...bundles,
|
|
270
|
+
...patches.map((b)=>({
|
|
271
|
+
...b,
|
|
272
|
+
$quiet: true
|
|
273
|
+
}))
|
|
274
|
+
]) : bundles));
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
};
|
|
279
|
+
return {
|
|
280
|
+
hash,
|
|
281
|
+
bearing,
|
|
282
|
+
part,
|
|
283
|
+
of,
|
|
284
|
+
sources,
|
|
285
|
+
reckon,
|
|
286
|
+
stale,
|
|
287
|
+
current,
|
|
288
|
+
seen,
|
|
289
|
+
keeping
|
|
290
|
+
};
|
|
291
|
+
};
|
|
292
|
+
/** Whether a vocabulary keeps privacy: it declares `_privacy`. */ export let kept = (vocab)=>!!vocab.comp(PRIVACY);
|
|
293
|
+
//# sourceMappingURL=privacy.js.map
|
package/privacy.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"privacy.js","sources":["./privacy.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,6EAA6E;AAC7E,+EAA+E;AAC/E,+EAA+E;AAC/E,sEAAsE;AACtE,EAAE;AACF,yEAAyE;AACzE,yEAAyE;AACzE,6EAA6E;AAC7E,0EAA0E;AAC1E,6EAA6E;AAC7E,0CAA0C;AAC1C,EAAE;AACF,6EAA6E;AAC7E,6EAA6E;AAC7E,+EAA+E;AAC/E,8EAA8E;A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