@graview/core 0.1.69 → 0.1.70

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 (143) hide show
  1. package/dist/app-places.d.ts.map +1 -1
  2. package/dist/app-places.js +11 -0
  3. package/dist/app-places.js.map +1 -1
  4. package/dist/catalog.js +1 -1
  5. package/dist/catalog.js.map +1 -1
  6. package/dist/cli/describe.d.ts.map +1 -1
  7. package/dist/cli/describe.js +8 -1
  8. package/dist/cli/describe.js.map +1 -1
  9. package/dist/cli/doctor.d.ts +1 -1
  10. package/dist/cli/doctor.d.ts.map +1 -1
  11. package/dist/cli/doctor.js +15 -2
  12. package/dist/cli/doctor.js.map +1 -1
  13. package/dist/cli/index.d.ts +1 -1
  14. package/dist/cli/index.d.ts.map +1 -1
  15. package/dist/css/fonts.d.ts +23 -0
  16. package/dist/css/fonts.d.ts.map +1 -0
  17. package/dist/css/fonts.js +54 -0
  18. package/dist/css/fonts.js.map +1 -0
  19. package/dist/css/sanitize.d.ts.map +1 -1
  20. package/dist/css/sanitize.js +77 -7
  21. package/dist/css/sanitize.js.map +1 -1
  22. package/dist/css/tables.d.ts.map +1 -1
  23. package/dist/css/tables.js +2 -0
  24. package/dist/css/tables.js.map +1 -1
  25. package/dist/css.d.ts +2 -0
  26. package/dist/css.d.ts.map +1 -1
  27. package/dist/css.js +1 -0
  28. package/dist/css.js.map +1 -1
  29. package/dist/document/act-findings.d.ts.map +1 -1
  30. package/dist/document/act-findings.js +11 -0
  31. package/dist/document/act-findings.js.map +1 -1
  32. package/dist/document/brand-check.d.ts +8 -1
  33. package/dist/document/brand-check.d.ts.map +1 -1
  34. package/dist/document/brand-check.js +28 -2
  35. package/dist/document/brand-check.js.map +1 -1
  36. package/dist/document/brand.d.ts.map +1 -1
  37. package/dist/document/brand.js +4 -1
  38. package/dist/document/brand.js.map +1 -1
  39. package/dist/document/compiled.d.ts.map +1 -1
  40. package/dist/document/compiled.js +1 -0
  41. package/dist/document/compiled.js.map +1 -1
  42. package/dist/document/diff.js +5 -1
  43. package/dist/document/diff.js.map +1 -1
  44. package/dist/document/edit.d.ts.map +1 -1
  45. package/dist/document/edit.js +63 -7
  46. package/dist/document/edit.js.map +1 -1
  47. package/dist/document/schema.d.ts +20 -0
  48. package/dist/document/schema.d.ts.map +1 -1
  49. package/dist/document/schema.js +5 -1
  50. package/dist/document/schema.js.map +1 -1
  51. package/dist/document.schema.json +41 -2
  52. package/dist/field-sight.js +3 -3
  53. package/dist/field-sight.js.map +1 -1
  54. package/dist/history.d.ts +15 -0
  55. package/dist/history.d.ts.map +1 -1
  56. package/dist/history.js +5 -0
  57. package/dist/history.js.map +1 -1
  58. package/dist/import/rows.js +2 -2
  59. package/dist/import/rows.js.map +1 -1
  60. package/dist/index.d.ts +5 -2
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/index.js +2 -1
  63. package/dist/index.js.map +1 -1
  64. package/dist/mutations/define-mutation.d.ts +4 -0
  65. package/dist/mutations/define-mutation.d.ts.map +1 -1
  66. package/dist/mutations/define-mutation.js +19 -4
  67. package/dist/mutations/define-mutation.js.map +1 -1
  68. package/dist/mutations/types.d.ts +8 -0
  69. package/dist/mutations/types.d.ts.map +1 -1
  70. package/dist/ops/declines.d.ts +33 -4
  71. package/dist/ops/declines.d.ts.map +1 -1
  72. package/dist/ops/declines.js +73 -5
  73. package/dist/ops/declines.js.map +1 -1
  74. package/dist/ops/digest.d.ts +1 -1
  75. package/dist/ops/digest.d.ts.map +1 -1
  76. package/dist/ops/digest.js +4 -4
  77. package/dist/ops/digest.js.map +1 -1
  78. package/dist/ops/lineage.d.ts +16 -1
  79. package/dist/ops/lineage.d.ts.map +1 -1
  80. package/dist/ops/lineage.js +8 -1
  81. package/dist/ops/lineage.js.map +1 -1
  82. package/dist/ops/log.d.ts.map +1 -1
  83. package/dist/ops/log.js +5 -2
  84. package/dist/ops/log.js.map +1 -1
  85. package/dist/ops/tidying.d.ts +55 -0
  86. package/dist/ops/tidying.d.ts.map +1 -1
  87. package/dist/ops/tidying.js +21 -0
  88. package/dist/ops/tidying.js.map +1 -1
  89. package/dist/ops/types.d.ts +21 -0
  90. package/dist/ops/types.d.ts.map +1 -1
  91. package/dist/ops/undo.d.ts.map +1 -1
  92. package/dist/ops/undo.js +2 -1
  93. package/dist/ops/undo.js.map +1 -1
  94. package/dist/ops/withheld.d.ts.map +1 -1
  95. package/dist/ops/withheld.js +2 -1
  96. package/dist/ops/withheld.js.map +1 -1
  97. package/dist/permissions/policy.d.ts +55 -0
  98. package/dist/permissions/policy.d.ts.map +1 -1
  99. package/dist/permissions/policy.js +97 -6
  100. package/dist/permissions/policy.js.map +1 -1
  101. package/dist/permissions/sight.js +3 -3
  102. package/dist/permissions/sight.js.map +1 -1
  103. package/dist/scaffold/project.d.ts.map +1 -1
  104. package/dist/scaffold/project.js +38 -11
  105. package/dist/scaffold/project.js.map +1 -1
  106. package/dist/scaffold/ui.js +1 -1
  107. package/dist/seen.js +2 -2
  108. package/dist/seen.js.map +1 -1
  109. package/dist/store.d.ts +32 -0
  110. package/dist/store.d.ts.map +1 -1
  111. package/dist/store.js +170 -16
  112. package/dist/store.js.map +1 -1
  113. package/dist/suggestions-may-wait.d.ts +10 -0
  114. package/dist/suggestions-may-wait.d.ts.map +1 -0
  115. package/dist/suggestions-may-wait.js +16 -0
  116. package/dist/suggestions-may-wait.js.map +1 -0
  117. package/dist/theme/fonts.d.ts.map +1 -1
  118. package/dist/theme/fonts.js +2 -0
  119. package/dist/theme/fonts.js.map +1 -1
  120. package/dist/theme/types.d.ts +27 -3
  121. package/dist/theme/types.d.ts.map +1 -1
  122. package/dist/theme/types.js.map +1 -1
  123. package/dist/tidying.d.ts +50 -4
  124. package/dist/tidying.d.ts.map +1 -1
  125. package/dist/tidying.js +389 -7
  126. package/dist/tidying.js.map +1 -1
  127. package/dist/version.d.ts +1 -1
  128. package/dist/version.js +1 -1
  129. package/dist/viewer-state.d.ts +23 -0
  130. package/dist/viewer-state.d.ts.map +1 -0
  131. package/dist/viewer-state.js +2 -0
  132. package/dist/viewer-state.js.map +1 -0
  133. package/dist/views/display-options.d.ts +59 -0
  134. package/dist/views/display-options.d.ts.map +1 -0
  135. package/dist/views/display-options.js +9 -0
  136. package/dist/views/display-options.js.map +1 -0
  137. package/dist/views/types.d.ts +6 -0
  138. package/dist/views/types.d.ts.map +1 -1
  139. package/dist/who.d.ts +1 -1
  140. package/dist/who.d.ts.map +1 -1
  141. package/dist/who.js +8 -0
  142. package/dist/who.js.map +1 -1
  143. package/package.json +2 -2
package/dist/store.js CHANGED
@@ -22,9 +22,9 @@ import { lineageOf } from "./ops/lineage.js";
22
22
  import { KEEP_LINK, keepLinkMutation, keepLinkVia } from "./mutations/keep-link.js";
23
23
  import { advisoryVoterOf, signedOutSeat, SIGN_IN_TO_VOTE, VOTE_SUGGESTION, VOTING, voteSuggestionMutation } from "./mutations/vote-suggestion.js";
24
24
  import { TYPE_TEXT, TYPING } from "./text/typing-hook.js";
25
- import { DECLINES, isAutomated, tidyingRefusal } from "./ops/tidying.js";
25
+ import { DECLINES, isAutomated, isTidyingActor, tidyingRefusal } from "./ops/tidying.js";
26
26
  import { nameOfAuthor } from "./who.js";
27
- import { actingAs, grantsTo, isSystem, permits, permittedMutations, proposes, subjectKinds } from "./permissions/policy.js";
27
+ import { actingAs, grantsTo, isSystem, meIn, meOf, ownsId, permits, profileOf, rolesSaid, withValidProfile, permittedMutations, proposes, subjectKinds } from "./permissions/policy.js";
28
28
  import { MOST_PROPOSED, PROPOSE_CHANGES, proposeChangesMutation } from "./mutations/propose-changes.js";
29
29
  import { namesUnseen, redact } from "./ops/withheld.js";
30
30
  import { writersBehind } from "./ops/writers.js";
@@ -537,7 +537,7 @@ export class Store {
537
537
  if (mutation !== undefined && mutation === this.typer) {
538
538
  // Through an act that could run on this record now: its module on, its own rule holding for the record as this principal is served it (`wouldRun`).
539
539
  const served = principal === undefined || isSystem(principal) ? this.graph : seenBy(this, principal).graph;
540
- const allows = (writer) => !this.mutationDisabled(writer) && wouldRun(writer, this.schema, served, call?.args["node"], call?.args["field"], principal && actingAs(principal).id);
540
+ const allows = (writer) => !this.mutationDisabled(writer) && wouldRun(writer, this.schema, served, call?.args["node"], call?.args["field"], principal && meIn(this.schema, principal));
541
541
  return TYPING.via(this.schema, [...this.mutations.values()], this.subjectKindOf(call, principal), call?.args["field"], allows);
542
542
  }
543
543
  if (!mutation?.derived)
@@ -592,6 +592,25 @@ export class Store {
592
592
  };
593
593
  }
594
594
  permits(call, principal = HUMAN) {
595
+ const verdict = this.judged(call, principal);
596
+ /*
597
+ * THE SAME ANSWER `apply` WOULD GIVE, FOR A PERSON NOT MADE YET. What an
598
+ * own-end grant reads of a call can be worked out only with the record
599
+ * `$me` will be, so it is rehearsed: nothing is kept, and asking makes nobody.
600
+ */
601
+ if (verdict.ok && this.personFor(principal) && this.policy?.grants.some((grant) => grant.ownEnd)) {
602
+ try {
603
+ this.rehearsal().applying([call], { author: principal });
604
+ }
605
+ catch (error) {
606
+ if (error instanceof PermissionDeniedError)
607
+ return { ok: false, refusal: error.refusal };
608
+ }
609
+ }
610
+ return verdict;
611
+ }
612
+ /** What `permits` answers from the grants alone; on an undo, a call already made, so it asks no record of who took it back. */
613
+ judged(call, principal, undoing = false) {
595
614
  call = this.spelledCall(call);
596
615
  /*
597
616
  * The same answer `apply` would give. A declared agent's `may` narrows
@@ -606,6 +625,9 @@ export class Store {
606
625
  if (narrowed)
607
626
  return { ok: false, refusal: narrowed };
608
627
  const mutation = this.mutations.get(call.name) ?? (call.name === PUBLISH ? this.publisher : undefined);
628
+ const nobody = mutation && !undoing && this.noOneToBe(mutation, principal);
629
+ if (nobody)
630
+ return { ok: false, refusal: nobody };
609
631
  // Publishing is the declaration's `publishers`, not a grant's.
610
632
  if (mutation && mutation === this.publisher)
611
633
  return PUBLISHING.verdict(this, principal);
@@ -640,11 +662,10 @@ export class Store {
640
662
  */
641
663
  const kind = this.subjectKindOf(call, principal);
642
664
  const verdict = permits(this.policy, principal, call.name, kind, this.viaOf(mutation, call, principal), typeof id === "string" ? id : undefined, this.words, () => {
643
- const me = actingAs(principal).id;
644
665
  const far = this.namedIn(call, false);
645
666
  try {
646
667
  for (const one of compileMutation(this.graph, mutation, call.args, this.sighted(principal)).primitives)
647
- if ("edge" in one && one.edge.from !== me && one.edge.to !== me)
668
+ if ("edge" in one && !ownsId(principal, one.edge.from) && !ownsId(principal, one.edge.to))
648
669
  far.push(one.edge.to);
649
670
  }
650
671
  catch {
@@ -895,9 +916,12 @@ export class Store {
895
916
  sighted(author) {
896
917
  // Who `$me` is: the person, for an agent acting for one (Roadmap f-act-as-me).
897
918
  const me = {
898
- me: author && actingAs(author).id,
919
+ me: author && meIn(this.schema, author),
899
920
  everHeld: (id) => recordsOf(this.log).kindOf(id) !== undefined,
900
921
  keeps: (kind, field) => mayKeepField(this.policy?.sees, kind, field),
922
+ ...(author && this.hasNoRecord(author) ? { noRecord: true } : {}),
923
+ // The host's own may ask for an id a seat may not: it could write the same through `applyPrimitives`.
924
+ ...(author && isSystem(author) ? { hostsOwn: true } : {}),
901
925
  };
902
926
  if (author === undefined || !hidesFrom(this, author))
903
927
  return me;
@@ -1054,7 +1078,8 @@ export class Store {
1054
1078
  // A derived act is offered when the kind's own acts it rides are.
1055
1079
  const derived = all.filter((mutation) => mutation.derived !== undefined &&
1056
1080
  permits(this.policy, principal, mutation.name, mutation.derived.kind, this.viaOf(mutation), actingAs(principal).id).ok);
1057
- return [...declared, ...publishing, ...derived];
1081
+ const offered = [...declared, ...publishing, ...derived];
1082
+ return profileOf(principal) ? offered.filter((mutation) => !this.noOneToBe(mutation, principal)) : offered;
1058
1083
  }
1059
1084
  /**
1060
1085
  * The kind a call acts on, read off the mutation's own subject binding.
@@ -1357,7 +1382,7 @@ export class Store {
1357
1382
  const calls = asked.map((call) => this.spelledCall(call));
1358
1383
  this.stillNow();
1359
1384
  const batch = options.batch ?? this.mintBatch("batch");
1360
- const author = options.author ?? this.by;
1385
+ const author = withValidProfile(options.author ?? this.by);
1361
1386
  const lineage = lineageOf(options.lineage);
1362
1387
  const ops = [];
1363
1388
  const allPrimitives = [];
@@ -1389,7 +1414,7 @@ export class Store {
1389
1414
  const permitted = (call, as = author) => {
1390
1415
  // A vote is judged with no policy too: a shared seat's vote is refused whether or not the app says who may do what (Roadmap f-votes-shared-seat).
1391
1416
  const voting = this.voter !== undefined && this.mutations.get(call.name) === this.voter;
1392
- const verdict = this.policy || (this.publisher && call.name === PUBLISH) || voting || this.mutations.get(call.name) === this.proposer ? this.permits(call, as) : undefined;
1417
+ const verdict = this.policy || (this.publisher && call.name === PUBLISH) || voting || this.mutations.get(call.name) === this.proposer ? this.judged(call, as) : undefined;
1393
1418
  // Rehearsing a proposal, an act its author may propose stands as the reviewer's would (Roadmap f-proposals-for-review).
1394
1419
  if (verdict && !verdict.ok && !(this.proposing && this.mayPropose(call, as)))
1395
1420
  this.refuse(verdict.refusal, as.id);
@@ -1422,6 +1447,8 @@ export class Store {
1422
1447
  const automated = isAutomated(author);
1423
1448
  if (automated)
1424
1449
  this.refuseDeclined(calls, author);
1450
+ if (isTidyingActor(author))
1451
+ this.refuseStopped(calls, author, this.suggesting);
1425
1452
  if (!this.rehearsing)
1426
1453
  tellTheWatchOfAnAuthor(author.id);
1427
1454
  /* The first record each call made, for a later call that names it (FR-193). */
@@ -1436,13 +1463,23 @@ export class Store {
1436
1463
  const renamed = new Map();
1437
1464
  const rename = (value) => (typeof value === "string" ? (renamed.get(value) ?? value) : Array.isArray(value) ? value.map(rename) : value);
1438
1465
  try {
1466
+ /* A PROFILE'S PERSON, MADE ON FIRST USE: its own op, in this batch, so a refused gesture keeps none of it and a client's optimism is rebased with the rest. */
1467
+ const person = this.personToMake(author, batch, options);
1468
+ if (person) {
1469
+ this.graph.applyPrimitives(person.primitives);
1470
+ this.log.append(person);
1471
+ ops.push(person);
1472
+ allPrimitives.push(...person.primitives);
1473
+ writes.add(person.writes[0]);
1474
+ }
1439
1475
  for (let at = 0; at < queue.length; at++) {
1440
1476
  const { sent, as, lineage: lined, decided } = queue[at];
1441
1477
  const named = at < naming.length ? naming[at] : namesMade(sent);
1442
1478
  const { mintedHint: hint, ...plain } = sent;
1443
1479
  const asked = renamed.size ? { ...plain, args: Object.fromEntries(Object.entries(plain.args).map(([key, value]) => [key, rename(value)])) } : plain;
1444
1480
  const call = named ? resolveMade(asked, madeIds, at) : asked;
1445
- if (named || decided)
1481
+ /* And again once a profile's person is here: what its act links could not be read before (`ownEnd`). */
1482
+ if (named || decided || person)
1446
1483
  (permitted(call, as), declared(call, as));
1447
1484
  const definition = this.mutation(call.name);
1448
1485
  if (definition === this.publisher) {
@@ -1559,6 +1596,13 @@ export class Store {
1559
1596
  writes.add(id);
1560
1597
  intents.push(op.intent);
1561
1598
  }
1599
+ /* A gesture that made nothing leaves nothing, a person with nothing done by them among it. */
1600
+ if (person && ops.length === 1) {
1601
+ this.putBack(rollback, kept);
1602
+ ops.length = 0;
1603
+ allPrimitives.length = 0;
1604
+ writes.clear();
1605
+ }
1562
1606
  }
1563
1607
  catch (error) {
1564
1608
  // A batch refused part way keeps none of it: the graph, and the ops it had logged before the refusal.
@@ -1736,7 +1780,7 @@ export class Store {
1736
1780
  applyPrimitives(primitives, options = {}) {
1737
1781
  this.stillNow();
1738
1782
  const batch = options.batch ?? this.mintBatch("batch");
1739
- const author = options.author ?? this.by;
1783
+ const author = withValidProfile(options.author ?? this.by);
1740
1784
  const before = this.violations();
1741
1785
  const rollback = this.graph.snapshot();
1742
1786
  const intent = options.intent ?? "Apply a change";
@@ -1836,6 +1880,8 @@ export class Store {
1836
1880
  * agent's turn while keeping your own edits is a dependency check rather
1837
1881
  * than a stack pop.
1838
1882
  */
1883
+ /** What the host says of stops this page's log does not hold (`ServedStops`). Never kept: a checkpoint keeps its own. */
1884
+ stopsServed;
1839
1885
  undo(batchIds, options = {}) {
1840
1886
  return this.undoing(batchIds, options);
1841
1887
  }
@@ -1843,7 +1889,10 @@ export class Store {
1843
1889
  undoing(batchIds, options) {
1844
1890
  this.stillNow();
1845
1891
  const ids = typeof batchIds === "string" ? [batchIds] : batchIds;
1846
- const author = options.author ?? this.by;
1892
+ const author = withValidProfile(options.author ?? this.by);
1893
+ const lifted = DECLINES.lift?.(this, ids, options, author);
1894
+ if (lifted)
1895
+ return lifted;
1847
1896
  /*
1848
1897
  * JUDGED FIRST AS THIS SEAT SEES THE LOG (FR-16, FR-02). A change it
1849
1898
  * may not see is not its to take back, and when one stands in the way
@@ -1864,7 +1913,7 @@ export class Store {
1864
1913
  : check);
1865
1914
  }
1866
1915
  const batch = options.batch ?? this.mintBatch("undo");
1867
- const lineage = lineageOf(options.lineage);
1916
+ const lineage = lineageOf(options.lineage, true);
1868
1917
  /*
1869
1918
  * Undo is a CHANGE, and it is judged like one.
1870
1919
  *
@@ -1877,6 +1926,12 @@ export class Store {
1877
1926
  const refused = this.undoRefusal(check.ops, author);
1878
1927
  if (refused)
1879
1928
  this.refuse(refused, author.id, true);
1929
+ // A stop is judged wherever it comes from: the lineage crosses the wire as a client says it, and a store that cannot judge it refuses it.
1930
+ if (lineage?.stopsKind === true) {
1931
+ const why = DECLINES.stopRefusal ? DECLINES.stopRefusal(this, check.ops, author) : "This store cannot be told not to suggest something.";
1932
+ if (why)
1933
+ this.refuse({ mutation: "undo", wouldNeed: [], message: why }, author.id, true);
1934
+ }
1880
1935
  const rollback = this.graph.snapshot();
1881
1936
  const before = this.violations();
1882
1937
  const ops = [];
@@ -1927,6 +1982,9 @@ export class Store {
1927
1982
  * one the store refuses.
1928
1983
  */
1929
1984
  mayUndo(batchIds, principal = this.by) {
1985
+ const kept = DECLINES.liftRefusal?.(this, typeof batchIds === "string" ? [batchIds] : batchIds, principal);
1986
+ if (kept)
1987
+ return kept.refusal ? { ok: false, refusal: kept.refusal } : { ok: true };
1930
1988
  const check = this.canUndo(batchIds);
1931
1989
  if (!check.ok)
1932
1990
  return { ok: false, check };
@@ -1935,6 +1993,10 @@ export class Store {
1935
1993
  }
1936
1994
  /** What refuses `author` taking these ops back, or nothing: what you may undo is what you may have done. */
1937
1995
  undoRefusal(ops, author) {
1996
+ // Asked of `@graview/core/tidying`; a store that has not loaded it offers no way back it cannot judge.
1997
+ const stop = DECLINES.undoRefusal ? DECLINES.undoRefusal(this, ops, author) : ops.some((target) => target.undoes !== undefined && target.mutation === null && (target.lineage?.stopsKind || target.lineage?.liftedStop)) ? { mutation: "undo", wouldNeed: [], message: "This cannot be taken back here yet." } : undefined;
1998
+ if (stop)
1999
+ return stop;
1938
2000
  if (this.policy || this.publisher) {
1939
2001
  for (const target of ops) {
1940
2002
  /*
@@ -1960,8 +2022,13 @@ export class Store {
1960
2022
  // A suggestion is taken back by who made it, or decided by whoever may make its change: a seat that may not has a vote.
1961
2023
  if (judged.suggests && !isSystem(author) && (judged.author.kind !== author.kind || judged.author.id !== author.id)) {
1962
2024
  const no = judged.suggests.map((call) => this.permits(call, author)).find((verdict) => !verdict.ok);
2025
+ /*
2026
+ * Said in one short sentence: who decides it, and what this seat
2027
+ * may do instead. The suggestion's own words name its records, and
2028
+ * the refusal of its change said "Not permitted" a second time.
2029
+ */
1963
2030
  if (no && !no.ok)
1964
- return { ...no.refusal, message: `Not permitted to undo "${target.intent}": ${no.refusal.message}` };
2031
+ return { ...no.refusal, message: this.suggestionWaits(target, no.refusal, author) };
1965
2032
  continue;
1966
2033
  }
1967
2034
  if (!judged.mutation) {
@@ -1985,16 +2052,26 @@ export class Store {
1985
2052
  * the same call by another would have done something else. "Vote for
1986
2053
  * it" is everybody's to run, and undoing Ann's was taking back her vote.
1987
2054
  */
1988
- const names = (value) => JSON.stringify(value).includes(JSON.stringify(by));
2055
+ /* What the act wrote as them: the profile's person, where they were one. */
2056
+ const names = (value) => JSON.stringify(value).includes(JSON.stringify(meOf(judged.author)));
1989
2057
  const verdict = by !== undefined && by !== actingAs(author).id && !isSystem(author) && !names(judged.mutation.args) && names(judged.primitives)
1990
2058
  ? { ok: false, refusal: { mutation: judged.mutation.name, wouldNeed: [], message: "it was done as somebody else." } }
1991
- : this.permits(judged.mutation, author);
2059
+ : this.judged(judged.mutation, author, true);
1992
2060
  if (!verdict.ok)
1993
2061
  return { ...verdict.refusal, message: `Not permitted to undo "${target.intent}": ${verdict.refusal.message}` };
1994
2062
  }
1995
2063
  }
1996
2064
  return undefined;
1997
2065
  }
2066
+ /** Why a seat may not take back somebody else's suggestion: who decides it, and whether this seat has a vote on it instead. */
2067
+ suggestionWaits(target, refusal, author) {
2068
+ // Refused for something other than a role this seat lacks: that reason, which names no record.
2069
+ if (refusal.wouldNeed.length === 0 || refusal.wouldNeed.some((role) => author.roles?.includes(role)))
2070
+ return refusal.message;
2071
+ const decides = `That suggestion waits for ${rolesSaid(refusal.wouldNeed)} to decide.`;
2072
+ const votes = this.mutations.has(VOTE_SUGGESTION) && this.permits({ name: VOTE_SUGGESTION, args: { suggestion: target.id, vote: "for" } }, author).ok;
2073
+ return votes ? `${decides} You can vote on it, but not take it back.` : `${decides} You cannot take it back.`;
2074
+ }
1998
2075
  /** The change an undo of an undo puts back: the op at the root of its chain, or the last undo the log still holds of it. */
1999
2076
  rootOf(op) {
2000
2077
  let at = op;
@@ -2002,6 +2079,76 @@ export class Store {
2002
2079
  at = undone;
2003
2080
  return at;
2004
2081
  }
2082
+ /**
2083
+ * THE RECORD A PROFILE'S PERSON WOULD BE, where one can be made (`meOf`):
2084
+ * of the people kind, its name in the kind's name field. As Graview Cloud
2085
+ * makes a member's: the id and the name, and where the kind asks for more,
2086
+ * none, since nobody is there to answer. And none where this id was ever a
2087
+ * record: one removed stays removed.
2088
+ */
2089
+ personFor(author) {
2090
+ const profile = profileOf(author);
2091
+ const id = meOf(author);
2092
+ if (!profile || id === undefined)
2093
+ return undefined;
2094
+ const people = this.schema.definitions.find((definition) => definition.people);
2095
+ if (!people || this.graph.has(id) || recordsOf(this.log).kindOf(id) !== undefined)
2096
+ return undefined;
2097
+ const fields = people.fields;
2098
+ const shape = fields.shape ?? {};
2099
+ const words = Object.keys(shape).filter((field) => shape[field].safeParse("x").success && !shape[field].safeParse(1).success);
2100
+ const named = words.includes("name") ? "name" : (words.find((field) => !shape[field].safeParse(undefined).success) ?? words[0]);
2101
+ const node = { ...people.defaults, id, kind: people.kind, ...(named ? { [named]: profile.name } : {}) };
2102
+ return fields.safeParse(node).success ? { id, name: profile.name, node } : undefined;
2103
+ }
2104
+ /**
2105
+ * A SEAT THAT CAN BE NOBODY HERE, where a kind is the people: a profile with
2106
+ * no person of that kind and none to be had (a record of another kind at its
2107
+ * id, from a restore or a host's own change, is not one), or an account whose
2108
+ * own id reads as a person's. With no people kind, nobody is asked to be one.
2109
+ */
2110
+ hasNoRecord(author) {
2111
+ if (!this.schema.definitions.some((definition) => definition.people))
2112
+ return false;
2113
+ if (actingAs(author).id === undefined)
2114
+ return false;
2115
+ const id = meOf(author);
2116
+ if (id === undefined)
2117
+ return true;
2118
+ if (!profileOf(author))
2119
+ return false;
2120
+ const kind = this.graph.getNode(id)?.kind;
2121
+ return !(kind !== undefined && this.schema.tryDefinition(kind)?.people) && !this.personFor(author);
2122
+ }
2123
+ /**
2124
+ * WHY AN ACT DONE AS `$me` IS NOT THIS SEAT'S: its profile has no person
2125
+ * and can have none. Refused in the words the act would refuse in, and not
2126
+ * offered: an act offered and then refused is what nobody should meet.
2127
+ */
2128
+ noOneToBe(mutation, principal) {
2129
+ if (!mutation.doneAsMe || !this.hasNoRecord(principal))
2130
+ return undefined;
2131
+ return { mutation: mutation.name, wouldNeed: [], message: `"${mutation.title ?? mutation.name}" is done as you, and you have no record here` };
2132
+ }
2133
+ /** The op that makes a profile's person on first use: by the account's own hand, so it is what the account made (`own`), and no other's. */
2134
+ personToMake(author, batch, options) {
2135
+ const person = this.personFor(author);
2136
+ if (!person)
2137
+ return undefined;
2138
+ return {
2139
+ id: this.nextId(),
2140
+ seq: this.log.length,
2141
+ batch,
2142
+ author,
2143
+ intent: `${person.name} joins`,
2144
+ mutation: null,
2145
+ primitives: [normalize({ op: "add-node", node: person.node })],
2146
+ reads: [],
2147
+ writes: [person.id],
2148
+ at: this.now(),
2149
+ ...given("via", options.via),
2150
+ };
2151
+ }
2005
2152
  /** Whether the policy grants this principal every act, on every record: what taking back a change no act made asks of anybody but its author. */
2006
2153
  grantsEveryAct(principal) {
2007
2154
  const acting = actingAs(principal);
@@ -2020,6 +2167,13 @@ export class Store {
2020
2167
  * (`DECLINES`), which every host that runs the actor loads — `dream`, `suggest`, a workflow, `@graview/ship`'s server.
2021
2168
  * A page that never loads it (where the actor does not run) judges no declines.
2022
2169
  */
2170
+ /** A suggestion is refused when all of it is stopped, since a person is still asked about the rest; a change it would make, when any of it is. */
2171
+ refuseStopped(calls, author, asking) {
2172
+ const ask = (some) => DECLINES.stopped?.(this.log.all(), some, this.actMeanings(), this.log.horizonEpoch()?.declines);
2173
+ const stopped = asking ? ask(calls) : calls.map((call) => ask([call])).find(Boolean);
2174
+ if (stopped)
2175
+ this.refuse({ mutation: calls[0].name, message: `${this.authorName(author)} may not suggest this kind of thing: a person said not to on ${stopped.at.slice(0, 10)}.`, wouldNeed: [] }, author.id);
2176
+ }
2023
2177
  refuseDeclined(calls, author) {
2024
2178
  const declined = DECLINES.declined?.(this.log.all(), calls, this.actMeanings(), this.log.horizonEpoch()?.declines);
2025
2179
  if (declined)