nervur 0.7.5 → 0.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/being.mjs +31 -4
  2. package/package.json +1 -1
package/being.mjs CHANGED
@@ -39,15 +39,42 @@ const Compartment = ({ memory, voice, address, root, classOf }) => {
39
39
  });
40
40
  };
41
41
 
42
+ const grantable = (program) =>
43
+ (program?.rights ?? [...STRUCTURAL, 'MEMBER']).filter((one) => !STRUCTURAL.includes(one));
44
+
45
+ const referable = (mine, key, plain, program) => {
46
+ const rights = plain.rights ?? 'MEMBER';
47
+ if (!grantable(program).includes(rights)) {
48
+ return undefined;
49
+ }
50
+ if (key.startsWith('refs/pending/')) {
51
+ return { ...plain, rights };
52
+ }
53
+ const held = mine.read(key);
54
+ return {
55
+ ...plain,
56
+ nextPkHash: plain.nextPkHash ?? held?.nextPkHash ?? null,
57
+ rights,
58
+ seen: Math.max(plain.seen ?? 0, held?.seen ?? 0),
59
+ };
60
+ };
61
+
42
62
  const scoped = (mine, program) =>
43
63
  Object.freeze({
44
64
  classOf: mine.classOf,
45
65
  list: mine.list,
46
66
  read: mine.read,
47
- write: (key, plain) =>
48
- key.startsWith('refs/') || key.startsWith('handles/') || program?.declares(key) !== undefined
67
+ write: (key, plain) => {
68
+ if (key.startsWith('refs/') && plain !== undefined) {
69
+ const guarded = referable(mine, key, plain, program);
70
+ return guarded === undefined ? undefined : mine.write(key, guarded);
71
+ }
72
+ return key.startsWith('refs/') ||
73
+ key.startsWith('handles/') ||
74
+ program?.declares(key) !== undefined
49
75
  ? mine.write(key, plain)
50
- : undefined,
76
+ : undefined;
77
+ },
51
78
  });
52
79
 
53
80
  const rootFor = ({ memory, voice, address }) => {
@@ -305,7 +332,7 @@ const Registry = ({
305
332
  if (written !== undefined && (brought === undefined || settings === undefined)) {
306
333
  return undefined;
307
334
  }
308
- const allowed = written?.rights ?? [...STRUCTURAL, 'MEMBER'];
335
+ const allowed = grantable(written);
309
336
  if (refs.some((ref) => !allowed.includes(ref.rights ?? 'MEMBER'))) {
310
337
  return undefined;
311
338
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nervur",
3
- "version": "0.7.5",
3
+ "version": "0.7.6",
4
4
  "description": "A distributed system of sovereign beings — one door, one question: by whose authority.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Razvan Gherghina",