@graview/core 0.1.69 → 0.1.71
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/dist/app-places.d.ts.map +1 -1
- package/dist/app-places.js +11 -0
- package/dist/app-places.js.map +1 -1
- package/dist/catalog.js +1 -1
- package/dist/catalog.js.map +1 -1
- package/dist/cli/check/hidden-reads.d.ts.map +1 -1
- package/dist/cli/check/hidden-reads.js +7 -0
- package/dist/cli/check/hidden-reads.js.map +1 -1
- package/dist/cli/describe.d.ts.map +1 -1
- package/dist/cli/describe.js +8 -1
- package/dist/cli/describe.js.map +1 -1
- package/dist/cli/doctor.d.ts +1 -1
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +15 -2
- package/dist/cli/doctor.js.map +1 -1
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/css/fonts.d.ts +31 -0
- package/dist/css/fonts.d.ts.map +1 -0
- package/dist/css/fonts.js +62 -0
- package/dist/css/fonts.js.map +1 -0
- package/dist/css/sanitize.d.ts.map +1 -1
- package/dist/css/sanitize.js +77 -7
- package/dist/css/sanitize.js.map +1 -1
- package/dist/css/tables.d.ts.map +1 -1
- package/dist/css/tables.js +2 -0
- package/dist/css/tables.js.map +1 -1
- package/dist/css.d.ts +2 -0
- package/dist/css.d.ts.map +1 -1
- package/dist/css.js +1 -0
- package/dist/css.js.map +1 -1
- package/dist/document/act-findings.d.ts.map +1 -1
- package/dist/document/act-findings.js +62 -1
- package/dist/document/act-findings.js.map +1 -1
- package/dist/document/blocks.d.ts.map +1 -1
- package/dist/document/blocks.js +5 -1
- package/dist/document/blocks.js.map +1 -1
- package/dist/document/brand-check.d.ts +8 -1
- package/dist/document/brand-check.d.ts.map +1 -1
- package/dist/document/brand-check.js +28 -2
- package/dist/document/brand-check.js.map +1 -1
- package/dist/document/brand.d.ts.map +1 -1
- package/dist/document/brand.js +4 -1
- package/dist/document/brand.js.map +1 -1
- package/dist/document/compile-checked.d.ts.map +1 -1
- package/dist/document/compile-checked.js +2 -1
- package/dist/document/compile-checked.js.map +1 -1
- package/dist/document/compile.d.ts.map +1 -1
- package/dist/document/compile.js +9 -6
- package/dist/document/compile.js.map +1 -1
- package/dist/document/compiled.d.ts.map +1 -1
- package/dist/document/compiled.js +36 -9
- package/dist/document/compiled.js.map +1 -1
- package/dist/document/design-findings.d.ts.map +1 -1
- package/dist/document/design-findings.js +8 -2
- package/dist/document/design-findings.js.map +1 -1
- package/dist/document/diff.js +5 -1
- package/dist/document/diff.js.map +1 -1
- package/dist/document/edit.d.ts.map +1 -1
- package/dist/document/edit.js +97 -11
- package/dist/document/edit.js.map +1 -1
- package/dist/document/expr/analyze.d.ts.map +1 -1
- package/dist/document/expr/analyze.js +11 -3
- package/dist/document/expr/analyze.js.map +1 -1
- package/dist/document/expr/evaluate.d.ts +2 -0
- package/dist/document/expr/evaluate.d.ts.map +1 -1
- package/dist/document/expr/evaluate.js +46 -8
- package/dist/document/expr/evaluate.js.map +1 -1
- package/dist/document/expr/index.d.ts +1 -0
- package/dist/document/expr/index.d.ts.map +1 -1
- package/dist/document/expr/index.js +1 -0
- package/dist/document/expr/index.js.map +1 -1
- package/dist/document/expr/parse.d.ts.map +1 -1
- package/dist/document/expr/parse.js +7 -3
- package/dist/document/expr/parse.js.map +1 -1
- package/dist/document/expr/subject.d.ts +24 -0
- package/dist/document/expr/subject.d.ts.map +1 -0
- package/dist/document/expr/subject.js +21 -0
- package/dist/document/expr/subject.js.map +1 -0
- package/dist/document/expr/typing.d.ts.map +1 -1
- package/dist/document/expr/typing.js +6 -2
- package/dist/document/expr/typing.js.map +1 -1
- package/dist/document/guard-names.d.ts +11 -0
- package/dist/document/guard-names.d.ts.map +1 -0
- package/dist/document/guard-names.js +185 -0
- package/dist/document/guard-names.js.map +1 -0
- package/dist/document/rule-reads.d.ts.map +1 -1
- package/dist/document/rule-reads.js +7 -1
- package/dist/document/rule-reads.js.map +1 -1
- package/dist/document/schema.d.ts +20 -0
- package/dist/document/schema.d.ts.map +1 -1
- package/dist/document/schema.js +5 -1
- package/dist/document/schema.js.map +1 -1
- package/dist/document/template.d.ts +2 -0
- package/dist/document/template.d.ts.map +1 -1
- package/dist/document/template.js +5 -1
- package/dist/document/template.js.map +1 -1
- package/dist/document/views.d.ts.map +1 -1
- package/dist/document/views.js +4 -0
- package/dist/document/views.js.map +1 -1
- package/dist/document.schema.json +41 -2
- package/dist/field-sight.js +3 -3
- package/dist/field-sight.js.map +1 -1
- package/dist/graph/graph.d.ts +13 -0
- package/dist/graph/graph.d.ts.map +1 -1
- package/dist/graph/graph.js +13 -5
- package/dist/graph/graph.js.map +1 -1
- package/dist/history.d.ts +15 -0
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +5 -0
- package/dist/history.js.map +1 -1
- package/dist/import/rows.js +2 -2
- package/dist/import/rows.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/mutations/define-mutation.d.ts +6 -0
- package/dist/mutations/define-mutation.d.ts.map +1 -1
- package/dist/mutations/define-mutation.js +23 -8
- package/dist/mutations/define-mutation.js.map +1 -1
- package/dist/mutations/keep-link.js +2 -2
- package/dist/mutations/keep-link.js.map +1 -1
- package/dist/mutations/types.d.ts +8 -0
- package/dist/mutations/types.d.ts.map +1 -1
- package/dist/ops/declines.d.ts +33 -4
- package/dist/ops/declines.d.ts.map +1 -1
- package/dist/ops/declines.js +73 -5
- package/dist/ops/declines.js.map +1 -1
- package/dist/ops/digest.d.ts +1 -1
- package/dist/ops/digest.d.ts.map +1 -1
- package/dist/ops/digest.js +4 -4
- package/dist/ops/digest.js.map +1 -1
- package/dist/ops/lineage.d.ts +16 -1
- package/dist/ops/lineage.d.ts.map +1 -1
- package/dist/ops/lineage.js +8 -1
- package/dist/ops/lineage.js.map +1 -1
- package/dist/ops/log.d.ts.map +1 -1
- package/dist/ops/log.js +5 -2
- package/dist/ops/log.js.map +1 -1
- package/dist/ops/tidying.d.ts +55 -0
- package/dist/ops/tidying.d.ts.map +1 -1
- package/dist/ops/tidying.js +21 -0
- package/dist/ops/tidying.js.map +1 -1
- package/dist/ops/types.d.ts +21 -0
- package/dist/ops/types.d.ts.map +1 -1
- package/dist/ops/undo.d.ts.map +1 -1
- package/dist/ops/undo.js +2 -1
- package/dist/ops/undo.js.map +1 -1
- package/dist/ops/withheld.d.ts.map +1 -1
- package/dist/ops/withheld.js +2 -1
- package/dist/ops/withheld.js.map +1 -1
- package/dist/permissions/policy.d.ts +55 -0
- package/dist/permissions/policy.d.ts.map +1 -1
- package/dist/permissions/policy.js +97 -6
- package/dist/permissions/policy.js.map +1 -1
- package/dist/permissions/sight.js +3 -3
- package/dist/permissions/sight.js.map +1 -1
- package/dist/scaffold/project.d.ts.map +1 -1
- package/dist/scaffold/project.js +38 -11
- package/dist/scaffold/project.js.map +1 -1
- package/dist/scaffold/ui.js +1 -1
- package/dist/seen.js +2 -2
- package/dist/seen.js.map +1 -1
- package/dist/store.d.ts +76 -0
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +262 -17
- package/dist/store.js.map +1 -1
- package/dist/suggestions-may-wait.d.ts +10 -0
- package/dist/suggestions-may-wait.d.ts.map +1 -0
- package/dist/suggestions-may-wait.js +16 -0
- package/dist/suggestions-may-wait.js.map +1 -0
- package/dist/theme/fonts.d.ts.map +1 -1
- package/dist/theme/fonts.js +2 -0
- package/dist/theme/fonts.js.map +1 -1
- package/dist/theme/types.d.ts +27 -3
- package/dist/theme/types.d.ts.map +1 -1
- package/dist/theme/types.js.map +1 -1
- package/dist/tidying.d.ts +50 -4
- package/dist/tidying.d.ts.map +1 -1
- package/dist/tidying.js +389 -7
- package/dist/tidying.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/viewer-state.d.ts +23 -0
- package/dist/viewer-state.d.ts.map +1 -0
- package/dist/viewer-state.js +2 -0
- package/dist/viewer-state.js.map +1 -0
- package/dist/views/display-options.d.ts +59 -0
- package/dist/views/display-options.d.ts.map +1 -0
- package/dist/views/display-options.js +9 -0
- package/dist/views/display-options.js.map +1 -0
- package/dist/views/types.d.ts +6 -0
- package/dist/views/types.d.ts.map +1 -1
- package/dist/who.d.ts +1 -1
- package/dist/who.d.ts.map +1 -1
- package/dist/who.js +8 -0
- package/dist/who.js.map +1 -1
- package/package.json +2 -2
package/dist/store.js
CHANGED
|
@@ -22,14 +22,14 @@ 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";
|
|
31
31
|
import { nounOf } from "./schema/define-node.js";
|
|
32
|
-
import { behind, fieldsJudged, mayKeepField, partialSight, recordsOf } from "./permissions/sight.js";
|
|
32
|
+
import { behind, fieldsJudged, mayKeepField, partialSight, recordsOf, sees } from "./permissions/sight.js";
|
|
33
33
|
import { PermissionDeniedError } from "./permissions/types.js";
|
|
34
34
|
import { checkUndo, UndoBlockedError, undoneInverses, undoPrimitives } from "./ops/undo.js";
|
|
35
35
|
import { validateGraph } from "./validate-graph.js";
|
|
@@ -251,6 +251,8 @@ export class Store {
|
|
|
251
251
|
past;
|
|
252
252
|
/** How often `pastOf` keeps a point to fold from, in ops (`StoreOptions.pastEvery`). */
|
|
253
253
|
pastEvery;
|
|
254
|
+
/** What `version` reads: each time this store told its subscribers something, or would have. */
|
|
255
|
+
told = 0;
|
|
254
256
|
listeners = new Set();
|
|
255
257
|
constructor(options) {
|
|
256
258
|
this.pastEvery = Math.max(1, options.pastEvery ?? 64);
|
|
@@ -537,7 +539,7 @@ export class Store {
|
|
|
537
539
|
if (mutation !== undefined && mutation === this.typer) {
|
|
538
540
|
// 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
541
|
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 &&
|
|
542
|
+
const allows = (writer) => !this.mutationDisabled(writer) && wouldRun(writer, this.schema, served, call?.args["node"], call?.args["field"], principal && meIn(this.schema, principal));
|
|
541
543
|
return TYPING.via(this.schema, [...this.mutations.values()], this.subjectKindOf(call, principal), call?.args["field"], allows);
|
|
542
544
|
}
|
|
543
545
|
if (!mutation?.derived)
|
|
@@ -592,6 +594,25 @@ export class Store {
|
|
|
592
594
|
};
|
|
593
595
|
}
|
|
594
596
|
permits(call, principal = HUMAN) {
|
|
597
|
+
const verdict = this.judged(call, principal);
|
|
598
|
+
/*
|
|
599
|
+
* THE SAME ANSWER `apply` WOULD GIVE, FOR A PERSON NOT MADE YET. What an
|
|
600
|
+
* own-end grant reads of a call can be worked out only with the record
|
|
601
|
+
* `$me` will be, so it is rehearsed: nothing is kept, and asking makes nobody.
|
|
602
|
+
*/
|
|
603
|
+
if (verdict.ok && this.personFor(principal) && this.policy?.grants.some((grant) => grant.ownEnd)) {
|
|
604
|
+
try {
|
|
605
|
+
this.rehearsal().applying([call], { author: principal });
|
|
606
|
+
}
|
|
607
|
+
catch (error) {
|
|
608
|
+
if (error instanceof PermissionDeniedError)
|
|
609
|
+
return { ok: false, refusal: error.refusal };
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
return verdict;
|
|
613
|
+
}
|
|
614
|
+
/** What `permits` answers from the grants alone; on an undo, a call already made, so it asks no record of who took it back. */
|
|
615
|
+
judged(call, principal, undoing = false) {
|
|
595
616
|
call = this.spelledCall(call);
|
|
596
617
|
/*
|
|
597
618
|
* The same answer `apply` would give. A declared agent's `may` narrows
|
|
@@ -606,6 +627,9 @@ export class Store {
|
|
|
606
627
|
if (narrowed)
|
|
607
628
|
return { ok: false, refusal: narrowed };
|
|
608
629
|
const mutation = this.mutations.get(call.name) ?? (call.name === PUBLISH ? this.publisher : undefined);
|
|
630
|
+
const nobody = mutation && !undoing && this.noOneToBe(mutation, principal);
|
|
631
|
+
if (nobody)
|
|
632
|
+
return { ok: false, refusal: nobody };
|
|
609
633
|
// Publishing is the declaration's `publishers`, not a grant's.
|
|
610
634
|
if (mutation && mutation === this.publisher)
|
|
611
635
|
return PUBLISHING.verdict(this, principal);
|
|
@@ -640,11 +664,10 @@ export class Store {
|
|
|
640
664
|
*/
|
|
641
665
|
const kind = this.subjectKindOf(call, principal);
|
|
642
666
|
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
667
|
const far = this.namedIn(call, false);
|
|
645
668
|
try {
|
|
646
669
|
for (const one of compileMutation(this.graph, mutation, call.args, this.sighted(principal)).primitives)
|
|
647
|
-
if ("edge" in one && one.edge.from
|
|
670
|
+
if ("edge" in one && !ownsId(principal, one.edge.from) && !ownsId(principal, one.edge.to))
|
|
648
671
|
far.push(one.edge.to);
|
|
649
672
|
}
|
|
650
673
|
catch {
|
|
@@ -895,9 +918,14 @@ export class Store {
|
|
|
895
918
|
sighted(author) {
|
|
896
919
|
// Who `$me` is: the person, for an agent acting for one (Roadmap f-act-as-me).
|
|
897
920
|
const me = {
|
|
898
|
-
me: author &&
|
|
921
|
+
me: author && meIn(this.schema, author),
|
|
899
922
|
everHeld: (id) => recordsOf(this.log).kindOf(id) !== undefined,
|
|
900
923
|
keeps: (kind, field) => mayKeepField(this.policy?.sees, kind, field),
|
|
924
|
+
...(author && this.hasNoRecord(author, false) ? { noRecord: true } : {}),
|
|
925
|
+
// Kept from its own person by its sight: an act declared as done as its author is refused, in words; another act's `ctx.me` is as it was.
|
|
926
|
+
...(author && !this.hasNoRecord(author, false) && this.hasNoRecord(author) ? { selfUnseen: true } : {}),
|
|
927
|
+
// The host's own may ask for an id a seat may not: it could write the same through `applyPrimitives`.
|
|
928
|
+
...(author && isSystem(author) ? { hostsOwn: true } : {}),
|
|
901
929
|
};
|
|
902
930
|
if (author === undefined || !hidesFrom(this, author))
|
|
903
931
|
return me;
|
|
@@ -1054,7 +1082,8 @@ export class Store {
|
|
|
1054
1082
|
// A derived act is offered when the kind's own acts it rides are.
|
|
1055
1083
|
const derived = all.filter((mutation) => mutation.derived !== undefined &&
|
|
1056
1084
|
permits(this.policy, principal, mutation.name, mutation.derived.kind, this.viaOf(mutation), actingAs(principal).id).ok);
|
|
1057
|
-
|
|
1085
|
+
const offered = [...declared, ...publishing, ...derived];
|
|
1086
|
+
return offered.filter((mutation) => !this.noOneToBe(mutation, principal));
|
|
1058
1087
|
}
|
|
1059
1088
|
/**
|
|
1060
1089
|
* The kind a call acts on, read off the mutation's own subject binding.
|
|
@@ -1152,6 +1181,8 @@ export class Store {
|
|
|
1152
1181
|
const before = this.violations();
|
|
1153
1182
|
this.ticked = { day, on };
|
|
1154
1183
|
const moved = this.moved(before, this.violations());
|
|
1184
|
+
if (day !== was)
|
|
1185
|
+
this.told += 1;
|
|
1155
1186
|
if (day !== was && !this.rehearsing && this.quiet === 0)
|
|
1156
1187
|
for (const listener of this.listeners)
|
|
1157
1188
|
listener(EMPTY_DIFF, []);
|
|
@@ -1165,6 +1196,7 @@ export class Store {
|
|
|
1165
1196
|
* diff and no ops, so what reads through the link reads again.
|
|
1166
1197
|
*/
|
|
1167
1198
|
reread() {
|
|
1199
|
+
this.told += 1;
|
|
1168
1200
|
if (this.rehearsing || this.quiet > 0)
|
|
1169
1201
|
return;
|
|
1170
1202
|
for (const listener of this.listeners)
|
|
@@ -1237,6 +1269,67 @@ export class Store {
|
|
|
1237
1269
|
return true;
|
|
1238
1270
|
}
|
|
1239
1271
|
}
|
|
1272
|
+
/**
|
|
1273
|
+
* WHAT EACH CALL WOULD DO, REHEARSING NOTHING: change something, change
|
|
1274
|
+
* nothing, or be refused by the act itself — compiled under the author's
|
|
1275
|
+
* sight, as `wouldChange` is, but a call that cannot compile hands back
|
|
1276
|
+
* why rather than counting as a change. The author's sight is worked out
|
|
1277
|
+
* once for all of them and no copy of the log is made, so a face may ask
|
|
1278
|
+
* it of every record it shows. The author is the store's own, unsaid, as
|
|
1279
|
+
* `apply`'s is; a profile whose person is not made yet is judged as the
|
|
1280
|
+
* person `apply` would make first, on one copy of the graph for them all.
|
|
1281
|
+
*
|
|
1282
|
+
* It does not judge what only applying judges: the policy (`permits`
|
|
1283
|
+
* does), the records a call needs that a host has not loaded
|
|
1284
|
+
* (`missingFor`), a host's `admit`, the rules the change would break, and
|
|
1285
|
+
* what tidying refuses (a record left alone, a change a person declined).
|
|
1286
|
+
*/
|
|
1287
|
+
wouldDo(calls, author = this.by) {
|
|
1288
|
+
const as = withValidProfile(author);
|
|
1289
|
+
const person = this.personFor(as);
|
|
1290
|
+
return person ? this.withPersonMade(as, person.id).compiledEach(calls, as) : this.compiledEach(calls, as);
|
|
1291
|
+
}
|
|
1292
|
+
/**
|
|
1293
|
+
* THE STORE AS IT WOULD BE WITH A PROFILE'S PERSON MADE: one copy, kept
|
|
1294
|
+
* while this store's `version` stands, so every call a face asks of it in
|
|
1295
|
+
* one look — each act over every chosen record — is judged on the same copy.
|
|
1296
|
+
*/
|
|
1297
|
+
withPersonMade(author, person) {
|
|
1298
|
+
const key = JSON.stringify([this.version, this.log.length, actingAs(author).id, person, profileOf(author)?.name]);
|
|
1299
|
+
if (this.personMade?.key === key)
|
|
1300
|
+
return this.personMade.twin;
|
|
1301
|
+
const twin = this.rehearsal();
|
|
1302
|
+
const made = twin.personToMake(author, PREVIEW_BATCH, {});
|
|
1303
|
+
if (made) {
|
|
1304
|
+
twin.graph.applyPrimitives(made.primitives);
|
|
1305
|
+
twin.log.append(made);
|
|
1306
|
+
}
|
|
1307
|
+
this.personMade = { key, twin };
|
|
1308
|
+
return twin;
|
|
1309
|
+
}
|
|
1310
|
+
/** The copy `withPersonMade` keeps, and the store's version and person it was made for. */
|
|
1311
|
+
personMade;
|
|
1312
|
+
compiledEach(calls, author) {
|
|
1313
|
+
const sighted = this.sighted(author);
|
|
1314
|
+
return calls.map((call) => {
|
|
1315
|
+
try {
|
|
1316
|
+
return compileMutation(this.graph, this.mutation(call.name), call.args, sighted).primitives.length > 0 ? "changes" : "nothing";
|
|
1317
|
+
}
|
|
1318
|
+
catch (error) {
|
|
1319
|
+
return { refused: error };
|
|
1320
|
+
}
|
|
1321
|
+
});
|
|
1322
|
+
}
|
|
1323
|
+
/**
|
|
1324
|
+
* HOW MANY TIMES THIS STORE HAS TOLD ITS SUBSCRIBERS SOMETHING, or would
|
|
1325
|
+
* have: a change, an adopt, the day turning, something read beside the
|
|
1326
|
+
* graph answering. What a face that keeps an answer worked out from the
|
|
1327
|
+
* store keys it on: the same number, the same store as far as anybody
|
|
1328
|
+
* reading it can tell.
|
|
1329
|
+
*/
|
|
1330
|
+
get version() {
|
|
1331
|
+
return this.told;
|
|
1332
|
+
}
|
|
1240
1333
|
preview(call, context, options = {}) {
|
|
1241
1334
|
call = this.spelledCall(call);
|
|
1242
1335
|
const definition = this.mutation(call.name);
|
|
@@ -1301,6 +1394,7 @@ export class Store {
|
|
|
1301
1394
|
nextId: () => `${PREVIEW_BATCH}:${++made}`,
|
|
1302
1395
|
mintBatch: () => PREVIEW_BATCH,
|
|
1303
1396
|
rehearsing: true,
|
|
1397
|
+
personMade: undefined,
|
|
1304
1398
|
});
|
|
1305
1399
|
// Its own acts, so "Type text" reads the text back off the rehearsal's log, as the apply would off this one's.
|
|
1306
1400
|
const typer = this.typer && TYPING.typeText(twin);
|
|
@@ -1357,7 +1451,7 @@ export class Store {
|
|
|
1357
1451
|
const calls = asked.map((call) => this.spelledCall(call));
|
|
1358
1452
|
this.stillNow();
|
|
1359
1453
|
const batch = options.batch ?? this.mintBatch("batch");
|
|
1360
|
-
const author = options.author ?? this.by;
|
|
1454
|
+
const author = withValidProfile(options.author ?? this.by);
|
|
1361
1455
|
const lineage = lineageOf(options.lineage);
|
|
1362
1456
|
const ops = [];
|
|
1363
1457
|
const allPrimitives = [];
|
|
@@ -1389,7 +1483,7 @@ export class Store {
|
|
|
1389
1483
|
const permitted = (call, as = author) => {
|
|
1390
1484
|
// 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
1485
|
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.
|
|
1486
|
+
const verdict = this.policy || (this.publisher && call.name === PUBLISH) || voting || this.mutations.get(call.name) === this.proposer ? this.judged(call, as) : undefined;
|
|
1393
1487
|
// Rehearsing a proposal, an act its author may propose stands as the reviewer's would (Roadmap f-proposals-for-review).
|
|
1394
1488
|
if (verdict && !verdict.ok && !(this.proposing && this.mayPropose(call, as)))
|
|
1395
1489
|
this.refuse(verdict.refusal, as.id);
|
|
@@ -1422,6 +1516,8 @@ export class Store {
|
|
|
1422
1516
|
const automated = isAutomated(author);
|
|
1423
1517
|
if (automated)
|
|
1424
1518
|
this.refuseDeclined(calls, author);
|
|
1519
|
+
if (isTidyingActor(author))
|
|
1520
|
+
this.refuseStopped(calls, author, this.suggesting);
|
|
1425
1521
|
if (!this.rehearsing)
|
|
1426
1522
|
tellTheWatchOfAnAuthor(author.id);
|
|
1427
1523
|
/* The first record each call made, for a later call that names it (FR-193). */
|
|
@@ -1436,13 +1532,23 @@ export class Store {
|
|
|
1436
1532
|
const renamed = new Map();
|
|
1437
1533
|
const rename = (value) => (typeof value === "string" ? (renamed.get(value) ?? value) : Array.isArray(value) ? value.map(rename) : value);
|
|
1438
1534
|
try {
|
|
1535
|
+
/* 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. */
|
|
1536
|
+
const person = this.personToMake(author, batch, options);
|
|
1537
|
+
if (person) {
|
|
1538
|
+
this.graph.applyPrimitives(person.primitives);
|
|
1539
|
+
this.log.append(person);
|
|
1540
|
+
ops.push(person);
|
|
1541
|
+
allPrimitives.push(...person.primitives);
|
|
1542
|
+
writes.add(person.writes[0]);
|
|
1543
|
+
}
|
|
1439
1544
|
for (let at = 0; at < queue.length; at++) {
|
|
1440
1545
|
const { sent, as, lineage: lined, decided } = queue[at];
|
|
1441
1546
|
const named = at < naming.length ? naming[at] : namesMade(sent);
|
|
1442
1547
|
const { mintedHint: hint, ...plain } = sent;
|
|
1443
1548
|
const asked = renamed.size ? { ...plain, args: Object.fromEntries(Object.entries(plain.args).map(([key, value]) => [key, rename(value)])) } : plain;
|
|
1444
1549
|
const call = named ? resolveMade(asked, madeIds, at) : asked;
|
|
1445
|
-
|
|
1550
|
+
/* And again once a profile's person is here: what its act links could not be read before (`ownEnd`). */
|
|
1551
|
+
if (named || decided || person)
|
|
1446
1552
|
(permitted(call, as), declared(call, as));
|
|
1447
1553
|
const definition = this.mutation(call.name);
|
|
1448
1554
|
if (definition === this.publisher) {
|
|
@@ -1559,6 +1665,13 @@ export class Store {
|
|
|
1559
1665
|
writes.add(id);
|
|
1560
1666
|
intents.push(op.intent);
|
|
1561
1667
|
}
|
|
1668
|
+
/* A gesture that made nothing leaves nothing, a person with nothing done by them among it. */
|
|
1669
|
+
if (person && ops.length === 1) {
|
|
1670
|
+
this.putBack(rollback, kept);
|
|
1671
|
+
ops.length = 0;
|
|
1672
|
+
allPrimitives.length = 0;
|
|
1673
|
+
writes.clear();
|
|
1674
|
+
}
|
|
1562
1675
|
}
|
|
1563
1676
|
catch (error) {
|
|
1564
1677
|
// A batch refused part way keeps none of it: the graph, and the ops it had logged before the refusal.
|
|
@@ -1736,7 +1849,7 @@ export class Store {
|
|
|
1736
1849
|
applyPrimitives(primitives, options = {}) {
|
|
1737
1850
|
this.stillNow();
|
|
1738
1851
|
const batch = options.batch ?? this.mintBatch("batch");
|
|
1739
|
-
const author = options.author ?? this.by;
|
|
1852
|
+
const author = withValidProfile(options.author ?? this.by);
|
|
1740
1853
|
const before = this.violations();
|
|
1741
1854
|
const rollback = this.graph.snapshot();
|
|
1742
1855
|
const intent = options.intent ?? "Apply a change";
|
|
@@ -1836,6 +1949,8 @@ export class Store {
|
|
|
1836
1949
|
* agent's turn while keeping your own edits is a dependency check rather
|
|
1837
1950
|
* than a stack pop.
|
|
1838
1951
|
*/
|
|
1952
|
+
/** What the host says of stops this page's log does not hold (`ServedStops`). Never kept: a checkpoint keeps its own. */
|
|
1953
|
+
stopsServed;
|
|
1839
1954
|
undo(batchIds, options = {}) {
|
|
1840
1955
|
return this.undoing(batchIds, options);
|
|
1841
1956
|
}
|
|
@@ -1843,7 +1958,10 @@ export class Store {
|
|
|
1843
1958
|
undoing(batchIds, options) {
|
|
1844
1959
|
this.stillNow();
|
|
1845
1960
|
const ids = typeof batchIds === "string" ? [batchIds] : batchIds;
|
|
1846
|
-
const author = options.author ?? this.by;
|
|
1961
|
+
const author = withValidProfile(options.author ?? this.by);
|
|
1962
|
+
const lifted = DECLINES.lift?.(this, ids, options, author);
|
|
1963
|
+
if (lifted)
|
|
1964
|
+
return lifted;
|
|
1847
1965
|
/*
|
|
1848
1966
|
* JUDGED FIRST AS THIS SEAT SEES THE LOG (FR-16, FR-02). A change it
|
|
1849
1967
|
* may not see is not its to take back, and when one stands in the way
|
|
@@ -1864,7 +1982,7 @@ export class Store {
|
|
|
1864
1982
|
: check);
|
|
1865
1983
|
}
|
|
1866
1984
|
const batch = options.batch ?? this.mintBatch("undo");
|
|
1867
|
-
const lineage = lineageOf(options.lineage);
|
|
1985
|
+
const lineage = lineageOf(options.lineage, true);
|
|
1868
1986
|
/*
|
|
1869
1987
|
* Undo is a CHANGE, and it is judged like one.
|
|
1870
1988
|
*
|
|
@@ -1877,6 +1995,12 @@ export class Store {
|
|
|
1877
1995
|
const refused = this.undoRefusal(check.ops, author);
|
|
1878
1996
|
if (refused)
|
|
1879
1997
|
this.refuse(refused, author.id, true);
|
|
1998
|
+
// 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.
|
|
1999
|
+
if (lineage?.stopsKind === true) {
|
|
2000
|
+
const why = DECLINES.stopRefusal ? DECLINES.stopRefusal(this, check.ops, author) : "This store cannot be told not to suggest something.";
|
|
2001
|
+
if (why)
|
|
2002
|
+
this.refuse({ mutation: "undo", wouldNeed: [], message: why }, author.id, true);
|
|
2003
|
+
}
|
|
1880
2004
|
const rollback = this.graph.snapshot();
|
|
1881
2005
|
const before = this.violations();
|
|
1882
2006
|
const ops = [];
|
|
@@ -1927,6 +2051,9 @@ export class Store {
|
|
|
1927
2051
|
* one the store refuses.
|
|
1928
2052
|
*/
|
|
1929
2053
|
mayUndo(batchIds, principal = this.by) {
|
|
2054
|
+
const kept = DECLINES.liftRefusal?.(this, typeof batchIds === "string" ? [batchIds] : batchIds, principal);
|
|
2055
|
+
if (kept)
|
|
2056
|
+
return kept.refusal ? { ok: false, refusal: kept.refusal } : { ok: true };
|
|
1930
2057
|
const check = this.canUndo(batchIds);
|
|
1931
2058
|
if (!check.ok)
|
|
1932
2059
|
return { ok: false, check };
|
|
@@ -1935,6 +2062,10 @@ export class Store {
|
|
|
1935
2062
|
}
|
|
1936
2063
|
/** What refuses `author` taking these ops back, or nothing: what you may undo is what you may have done. */
|
|
1937
2064
|
undoRefusal(ops, author) {
|
|
2065
|
+
// Asked of `@graview/core/tidying`; a store that has not loaded it offers no way back it cannot judge.
|
|
2066
|
+
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;
|
|
2067
|
+
if (stop)
|
|
2068
|
+
return stop;
|
|
1938
2069
|
if (this.policy || this.publisher) {
|
|
1939
2070
|
for (const target of ops) {
|
|
1940
2071
|
/*
|
|
@@ -1960,8 +2091,13 @@ export class Store {
|
|
|
1960
2091
|
// 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
2092
|
if (judged.suggests && !isSystem(author) && (judged.author.kind !== author.kind || judged.author.id !== author.id)) {
|
|
1962
2093
|
const no = judged.suggests.map((call) => this.permits(call, author)).find((verdict) => !verdict.ok);
|
|
2094
|
+
/*
|
|
2095
|
+
* Said in one short sentence: who decides it, and what this seat
|
|
2096
|
+
* may do instead. The suggestion's own words name its records, and
|
|
2097
|
+
* the refusal of its change said "Not permitted" a second time.
|
|
2098
|
+
*/
|
|
1963
2099
|
if (no && !no.ok)
|
|
1964
|
-
return { ...no.refusal, message:
|
|
2100
|
+
return { ...no.refusal, message: this.suggestionWaits(target, no.refusal, author) };
|
|
1965
2101
|
continue;
|
|
1966
2102
|
}
|
|
1967
2103
|
if (!judged.mutation) {
|
|
@@ -1985,16 +2121,26 @@ export class Store {
|
|
|
1985
2121
|
* the same call by another would have done something else. "Vote for
|
|
1986
2122
|
* it" is everybody's to run, and undoing Ann's was taking back her vote.
|
|
1987
2123
|
*/
|
|
1988
|
-
|
|
2124
|
+
/* What the act wrote as them: the profile's person, where they were one. */
|
|
2125
|
+
const names = (value) => JSON.stringify(value).includes(JSON.stringify(meOf(judged.author)));
|
|
1989
2126
|
const verdict = by !== undefined && by !== actingAs(author).id && !isSystem(author) && !names(judged.mutation.args) && names(judged.primitives)
|
|
1990
2127
|
? { ok: false, refusal: { mutation: judged.mutation.name, wouldNeed: [], message: "it was done as somebody else." } }
|
|
1991
|
-
: this.
|
|
2128
|
+
: this.judged(judged.mutation, author, true);
|
|
1992
2129
|
if (!verdict.ok)
|
|
1993
2130
|
return { ...verdict.refusal, message: `Not permitted to undo "${target.intent}": ${verdict.refusal.message}` };
|
|
1994
2131
|
}
|
|
1995
2132
|
}
|
|
1996
2133
|
return undefined;
|
|
1997
2134
|
}
|
|
2135
|
+
/** Why a seat may not take back somebody else's suggestion: who decides it, and whether this seat has a vote on it instead. */
|
|
2136
|
+
suggestionWaits(target, refusal, author) {
|
|
2137
|
+
// Refused for something other than a role this seat lacks: that reason, which names no record.
|
|
2138
|
+
if (refusal.wouldNeed.length === 0 || refusal.wouldNeed.some((role) => author.roles?.includes(role)))
|
|
2139
|
+
return refusal.message;
|
|
2140
|
+
const decides = `That suggestion waits for ${rolesSaid(refusal.wouldNeed)} to decide.`;
|
|
2141
|
+
const votes = this.mutations.has(VOTE_SUGGESTION) && this.permits({ name: VOTE_SUGGESTION, args: { suggestion: target.id, vote: "for" } }, author).ok;
|
|
2142
|
+
return votes ? `${decides} You can vote on it, but not take it back.` : `${decides} You cannot take it back.`;
|
|
2143
|
+
}
|
|
1998
2144
|
/** 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
2145
|
rootOf(op) {
|
|
2000
2146
|
let at = op;
|
|
@@ -2002,6 +2148,95 @@ export class Store {
|
|
|
2002
2148
|
at = undone;
|
|
2003
2149
|
return at;
|
|
2004
2150
|
}
|
|
2151
|
+
/**
|
|
2152
|
+
* THE RECORD A PROFILE'S PERSON WOULD BE, where one can be made (`meOf`):
|
|
2153
|
+
* of the people kind, its name in the kind's name field. As Graview Cloud
|
|
2154
|
+
* makes a member's: the id and the name, and where the kind asks for more,
|
|
2155
|
+
* none, since nobody is there to answer. And none where this id was ever a
|
|
2156
|
+
* record: one removed stays removed.
|
|
2157
|
+
*/
|
|
2158
|
+
personFor(author) {
|
|
2159
|
+
const profile = profileOf(author);
|
|
2160
|
+
const id = meOf(author);
|
|
2161
|
+
if (!profile || id === undefined)
|
|
2162
|
+
return undefined;
|
|
2163
|
+
const people = this.schema.definitions.find((definition) => definition.people);
|
|
2164
|
+
if (!people || this.graph.has(id) || recordsOf(this.log).kindOf(id) !== undefined)
|
|
2165
|
+
return undefined;
|
|
2166
|
+
const fields = people.fields;
|
|
2167
|
+
const shape = fields.shape ?? {};
|
|
2168
|
+
const words = Object.keys(shape).filter((field) => shape[field].safeParse("x").success && !shape[field].safeParse(1).success);
|
|
2169
|
+
const named = words.includes("name") ? "name" : (words.find((field) => !shape[field].safeParse(undefined).success) ?? words[0]);
|
|
2170
|
+
const node = { ...people.defaults, id, kind: people.kind, ...(named ? { [named]: profile.name } : {}) };
|
|
2171
|
+
return fields.safeParse(node).success ? { id, name: profile.name, node } : undefined;
|
|
2172
|
+
}
|
|
2173
|
+
/**
|
|
2174
|
+
* A SEAT THAT CAN BE NOBODY HERE, where a kind is the people: a profile with
|
|
2175
|
+
* no person of that kind and none to be had (a record of another kind at its
|
|
2176
|
+
* id, from a restore or a host's own change, is not one), or an account whose
|
|
2177
|
+
* own id reads as a person's. With no people kind, nobody is asked to be one.
|
|
2178
|
+
*
|
|
2179
|
+
* AND A SEAT WHOSE SIGHT KEEPS ITS OWN PERSON FROM IT. An act runs under its
|
|
2180
|
+
* author's sight (`sighted`), where a record the author may not see is no
|
|
2181
|
+
* record: `$me` resolves to nothing there, so the act is not offered, and is
|
|
2182
|
+
* refused in the words it would refuse in, with a profile or without.
|
|
2183
|
+
*/
|
|
2184
|
+
hasNoRecord(author, bySight = true) {
|
|
2185
|
+
const people = this.schema.definitions.find((definition) => definition.people);
|
|
2186
|
+
if (!people)
|
|
2187
|
+
return false;
|
|
2188
|
+
// Kept from its own person by its sight: a seat with no id of its own sees one only through a sight of the whole kind.
|
|
2189
|
+
const kept = (person) => bySight && !this.seesOwnPerson(author, person);
|
|
2190
|
+
if (actingAs(author).id === undefined)
|
|
2191
|
+
return kept({ id: "", kind: people.kind });
|
|
2192
|
+
const id = meOf(author);
|
|
2193
|
+
if (id === undefined)
|
|
2194
|
+
return true;
|
|
2195
|
+
const kind = this.graph.getNode(id)?.kind;
|
|
2196
|
+
if (kind !== undefined && this.schema.tryDefinition(kind)?.people)
|
|
2197
|
+
return kept({ id, kind });
|
|
2198
|
+
if (!profileOf(author))
|
|
2199
|
+
return false;
|
|
2200
|
+
const person = this.personFor(author);
|
|
2201
|
+
return !person || kept({ id: person.id, kind: person.node.kind });
|
|
2202
|
+
}
|
|
2203
|
+
/** Whether a seat's sight shows it its own person, there or about to be made: one with no links yet is judged as one. */
|
|
2204
|
+
seesOwnPerson(author, person) {
|
|
2205
|
+
if (!hidesFrom(this, author))
|
|
2206
|
+
return true;
|
|
2207
|
+
if (this.modules.disabledKinds.has(person.kind) && !isSystem(author))
|
|
2208
|
+
return false;
|
|
2209
|
+
return this.graph.has(person.id) ? seesId(this, author)(person.id) : sees(this.policy, author, person, { out: () => [], in: () => [] }, recordsOf(this.log), fieldsJudged(this));
|
|
2210
|
+
}
|
|
2211
|
+
/**
|
|
2212
|
+
* WHY AN ACT DONE AS `$me` IS NOT THIS SEAT'S: its profile has no person
|
|
2213
|
+
* and can have none. Refused in the words the act would refuse in, and not
|
|
2214
|
+
* offered: an act offered and then refused is what nobody should meet.
|
|
2215
|
+
*/
|
|
2216
|
+
noOneToBe(mutation, principal) {
|
|
2217
|
+
if (!mutation.doneAsMe || !this.hasNoRecord(principal))
|
|
2218
|
+
return undefined;
|
|
2219
|
+
return { mutation: mutation.name, wouldNeed: [], message: `"${mutation.title ?? mutation.name}" is done as you, and you have no record here` };
|
|
2220
|
+
}
|
|
2221
|
+
/** 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. */
|
|
2222
|
+
personToMake(author, batch, options) {
|
|
2223
|
+
const person = this.personFor(author);
|
|
2224
|
+
if (!person)
|
|
2225
|
+
return undefined;
|
|
2226
|
+
return {
|
|
2227
|
+
id: this.nextId(),
|
|
2228
|
+
seq: this.log.length,
|
|
2229
|
+
batch,
|
|
2230
|
+
author,
|
|
2231
|
+
intent: `${person.name} joins`,
|
|
2232
|
+
mutation: null,
|
|
2233
|
+
primitives: [normalize({ op: "add-node", node: person.node })],
|
|
2234
|
+
reads: [],
|
|
2235
|
+
writes: [person.id],
|
|
2236
|
+
at: this.now(),
|
|
2237
|
+
...given("via", options.via),
|
|
2238
|
+
};
|
|
2239
|
+
}
|
|
2005
2240
|
/** 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
2241
|
grantsEveryAct(principal) {
|
|
2007
2242
|
const acting = actingAs(principal);
|
|
@@ -2020,6 +2255,13 @@ export class Store {
|
|
|
2020
2255
|
* (`DECLINES`), which every host that runs the actor loads — `dream`, `suggest`, a workflow, `@graview/ship`'s server.
|
|
2021
2256
|
* A page that never loads it (where the actor does not run) judges no declines.
|
|
2022
2257
|
*/
|
|
2258
|
+
/** 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. */
|
|
2259
|
+
refuseStopped(calls, author, asking) {
|
|
2260
|
+
const ask = (some) => DECLINES.stopped?.(this.log.all(), some, this.actMeanings(), this.log.horizonEpoch()?.declines);
|
|
2261
|
+
const stopped = asking ? ask(calls) : calls.map((call) => ask([call])).find(Boolean);
|
|
2262
|
+
if (stopped)
|
|
2263
|
+
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);
|
|
2264
|
+
}
|
|
2023
2265
|
refuseDeclined(calls, author) {
|
|
2024
2266
|
const declined = DECLINES.declined?.(this.log.all(), calls, this.actMeanings(), this.log.horizonEpoch()?.declines);
|
|
2025
2267
|
if (declined)
|
|
@@ -2076,6 +2318,9 @@ export class Store {
|
|
|
2076
2318
|
* is nothing to tell.
|
|
2077
2319
|
*/
|
|
2078
2320
|
notify(diff, ops) {
|
|
2321
|
+
this.told += 1;
|
|
2322
|
+
// A copy kept for a profile's person not made yet is the store as it was: let it go.
|
|
2323
|
+
this.personMade = undefined;
|
|
2079
2324
|
if (this.quiet > 0)
|
|
2080
2325
|
return;
|
|
2081
2326
|
if (ops.length === 0 && isEmptyDiff(diff))
|