@cruba/crubal 0.1.0 → 0.3.0
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/README.md +30 -2
- package/dist/bin/crubal.js +70 -4
- package/dist/bin/crubal.js.map +1 -1
- package/dist/src/access.d.ts +126 -0
- package/dist/src/access.js +517 -0
- package/dist/src/access.js.map +1 -0
- package/dist/src/address.d.ts +29 -0
- package/dist/src/address.js +59 -0
- package/dist/src/address.js.map +1 -0
- package/dist/src/arrival.d.ts +55 -0
- package/dist/src/arrival.js +124 -0
- package/dist/src/arrival.js.map +1 -0
- package/dist/src/bundle.d.ts +66 -0
- package/dist/src/bundle.js +753 -0
- package/dist/src/bundle.js.map +1 -0
- package/dist/src/conditions.d.ts +7 -1
- package/dist/src/conditions.js +52 -11
- package/dist/src/conditions.js.map +1 -1
- package/dist/src/corpus.js +568 -34
- package/dist/src/corpus.js.map +1 -1
- package/dist/src/defs.d.ts +37 -2
- package/dist/src/defs.js +95 -14
- package/dist/src/defs.js.map +1 -1
- package/dist/src/dictionary.d.ts +15 -0
- package/dist/src/dictionary.js +72 -13
- package/dist/src/dictionary.js.map +1 -1
- package/dist/src/exchange.d.ts +204 -11
- package/dist/src/exchange.js +762 -45
- package/dist/src/exchange.js.map +1 -1
- package/dist/src/forms.d.ts +16 -0
- package/dist/src/forms.js +169 -0
- package/dist/src/forms.js.map +1 -0
- package/dist/src/index.d.ts +19 -6
- package/dist/src/index.js +18 -5
- package/dist/src/index.js.map +1 -1
- package/dist/src/lifecycle.d.ts +84 -0
- package/dist/src/lifecycle.js +415 -0
- package/dist/src/lifecycle.js.map +1 -0
- package/dist/src/log.d.ts +78 -0
- package/dist/src/log.js +506 -0
- package/dist/src/log.js.map +1 -0
- package/dist/src/migrate.d.ts +24 -1
- package/dist/src/migrate.js +104 -9
- package/dist/src/migrate.js.map +1 -1
- package/dist/src/model.d.ts +33 -1
- package/dist/src/model.js +158 -2
- package/dist/src/model.js.map +1 -1
- package/dist/src/packages.d.ts +44 -0
- package/dist/src/packages.js +137 -3
- package/dist/src/packages.js.map +1 -1
- package/dist/src/print-text.js +22 -0
- package/dist/src/print-text.js.map +1 -1
- package/dist/src/publish.d.ts +27 -0
- package/dist/src/publish.js +275 -0
- package/dist/src/publish.js.map +1 -0
- package/dist/src/read-text.d.ts +2 -0
- package/dist/src/read-text.js +72 -4
- package/dist/src/read-text.js.map +1 -1
- package/dist/src/records.d.ts +32 -0
- package/dist/src/records.js +104 -0
- package/dist/src/records.js.map +1 -0
- package/dist/src/review.d.ts +22 -0
- package/dist/src/review.js +198 -0
- package/dist/src/review.js.map +1 -0
- package/dist/src/rules.d.ts +38 -3
- package/dist/src/rules.js +184 -30
- package/dist/src/rules.js.map +1 -1
- package/dist/src/schedule.d.ts +24 -0
- package/dist/src/schedule.js +126 -0
- package/dist/src/schedule.js.map +1 -0
- package/dist/src/std-packages.d.ts +9 -0
- package/dist/src/std-packages.js +268 -0
- package/dist/src/std-packages.js.map +1 -0
- package/dist/src/store.d.ts +38 -7
- package/dist/src/store.js +166 -24
- package/dist/src/store.js.map +1 -1
- package/dist/src/tree.d.ts +3 -0
- package/dist/src/tree.js +36 -0
- package/dist/src/tree.js.map +1 -1
- package/dist/src/units-table.d.ts +1 -0
- package/dist/src/units-table.js +200 -0
- package/dist/src/units-table.js.map +1 -0
- package/dist/src/units.d.ts +42 -4
- package/dist/src/units.js +91 -30
- package/dist/src/units.js.map +1 -1
- package/dist/src/views.d.ts +116 -6
- package/dist/src/views.js +484 -74
- package/dist/src/views.js.map +1 -1
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
The CRUBAL reference implementation. Pure functions, JSON in and JSON out, so a compiled core can replace
|
|
4
4
|
the internals later behind the same API.
|
|
5
5
|
|
|
6
|
-
**Level reached: Views**, every chapter of the spec (1–
|
|
6
|
+
**Level reached: Views**, every chapter of the spec (1–14). Conformance claim: `CRUBAL 2 · Views · corpus 2026-10-19` (the gate, 2026-10-19; `CLAIM.md`).
|
|
7
7
|
|
|
8
8
|
- **Reader:** the text form and JSON both ways, facet types, unknown keys kept exactly, plain-words refusals
|
|
9
9
|
with line numbers.
|
|
@@ -32,7 +32,35 @@ the internals later behind the same API.
|
|
|
32
32
|
`shown to` rules (new and unknown values never public), roles that narrow an audience, the portable shape,
|
|
33
33
|
and read sets that decide which rows a write makes stale.
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
- **The backbone (chapters 1.12, 8.5, 9.2a, 10.7, 12.6, 14):** the log as effects, rebuild from the log
|
|
36
|
+
alone, `define` writes for the working package, and the journal that makes entries the only way state
|
|
37
|
+
changes (`log.ts`); arrival with bindings and strong and weak keys (`arrival.ts`); folded and owned keys
|
|
38
|
+
with attach, detach, archive, merge and instructions (`lifecycle.ts`); owners, edges, modes, the grantor
|
|
39
|
+
chain, permission menus, gates and emergency access (`access.ts`); partitioned views, the projection
|
|
40
|
+
stream and stream subscriptions with cursors and resets (`views.ts`, `exchange.ts`); the record set every
|
|
41
|
+
module reads through, so a backend that loads only what an operation needs can stand in for the memory
|
|
42
|
+
one (`records.ts`, docs/design/store.md); a package as one JSON document, printed back to the text form so
|
|
43
|
+
the text readers stay the one parser, hashed and signed (`bundle.ts`), and cut as a version with members by
|
|
44
|
+
diff, the change classifier of 4.8 and 5.11 and the recipe requirement (`publish.ts`, `crubal publish`;
|
|
45
|
+
docs/design/publishing.md); review decisions as writes, each one entry with the define, value or release it causes (`review.ts`); a held value
|
|
46
|
+
coming back when its verdict changes again; adopt, give back, clone and split (`lifecycle.ts`); a measurement contract landing observations, the first filling an empty
|
|
47
|
+
value, and the version split proposed at the threshold, never made (`exchange.ts`, `proposeSplit` in `store.ts`); hand-made lists (`select: list:` over the core facet `crubal:items`), page shapes whose slots hold
|
|
48
|
+
other views run with the page's record as context, dependent counts inside a filter's buckets, further
|
|
49
|
+
shapes under `shapes` and the core `crubal:jsonld` structured data for the public (`views.ts`); offer and take by the offer's mode: dump copies once, observed stores a link and no value, gathered takes
|
|
50
|
+
the presenter's updates over its own earlier values and never over the consumer's, controlled copies under
|
|
51
|
+
the presenter's terms (expires, reshare, revocable) and withdraws what the presenter stops giving; an
|
|
52
|
+
offer builder and an expiry sweep (`exchange.ts`); a person's arrival owned `domain:id` when the package lets a person
|
|
53
|
+
own that kind (14.1); dated keys, `keyFor` picking the key whose span holds an entry's moment (11.7); a form as data from a contract's needs, the record's answers and states and the caller's edges
|
|
54
|
+
(`forms.ts`, docs/design/index-and-forms.md); and a border that
|
|
55
|
+
consults access, journals every run, and grants a consumer's edge (`exchange.ts`).
|
|
56
|
+
|
|
57
|
+
A run applies the rules (7.4 step 6): a value a `must` rule won't have is parked as a contradiction citing
|
|
58
|
+
the rule and never lands, a `suggest` fills and a derivation lands with `origin: derived` and the rule as
|
|
59
|
+
its `via`, a changed verdict holds, and each is a logged effect.
|
|
60
|
+
|
|
61
|
+
It passes every corpus folder (198 cases; `crubal claim <corpus> --out CLAIM.md` runs every level and writes the claim, 13.3). The corpus and this package name no adopter and no third party:
|
|
62
|
+
`test.example` owns the data, `market:` stands for any marketplace, `bench` for any in-house tool, and
|
|
63
|
+
product, unit and the like are the test package's own kinds, never the core's.
|
|
36
64
|
|
|
37
65
|
Store also checks Ed25519 signatures against the owner's published key, replays intake records from their
|
|
38
66
|
kept bytes (deterministically, keeping earlier outcomes), reviews unknown and new values by key across all
|
package/dist/bin/crubal.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// crubal: read, print and test CRUBAL.
|
|
3
3
|
// crubal test <corpus> [--level reader] run a level's corpus folders
|
|
4
|
+
// crubal claim <corpus> [--level views] [--out CLAIM.md] run every level up to one and print the claim (13.3)
|
|
4
5
|
// crubal read <file> --defs <file>... text to JSON
|
|
5
6
|
// crubal print <file.json> --defs <file>... JSON to text
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
// crubal publish <dir> [--previous <package.json>] [--date YYYY-MM-DD] [--key <file>] [--out <dir>]
|
|
8
|
+
// cut a version: members by diff, recipes required, hash, signature
|
|
9
|
+
import { parseJson } from "../src/model.js";
|
|
10
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { canonical, emptyDictionary, printText, publish, readDefinitions, readText, runCorpus } from "../src/index.js";
|
|
8
13
|
const [cmd, target, ...rest] = process.argv.slice(2);
|
|
9
14
|
const flag = (name) => rest.flatMap((a, i) => (a === name ? [rest[i + 1]] : []));
|
|
10
15
|
function dictionary() {
|
|
@@ -22,16 +27,77 @@ if (cmd === "test" && target) {
|
|
|
22
27
|
console.log(`\n${results.length - failed}/${results.length} passed (${level})`);
|
|
23
28
|
process.exit(failed ? 1 : 0);
|
|
24
29
|
}
|
|
30
|
+
else if (cmd === "claim" && target) {
|
|
31
|
+
// A claim names the language version, the level and the corpus version it passed (13.3), and links the run.
|
|
32
|
+
const LEVELS = ["reader", "dictionary", "rules", "store", "exchange", "views"];
|
|
33
|
+
const upTo = flag("--level")[0] ?? "views";
|
|
34
|
+
if (!LEVELS.includes(upTo)) {
|
|
35
|
+
console.log(`unknown level ${upTo}; one of ${LEVELS.join(", ")}`);
|
|
36
|
+
process.exit(2);
|
|
37
|
+
}
|
|
38
|
+
const version = existsSync(join(target, "VERSION")) ? readFileSync(join(target, "VERSION"), "utf8").trim() : "unversioned";
|
|
39
|
+
const lines = [];
|
|
40
|
+
let failed = 0;
|
|
41
|
+
for (const level of LEVELS.slice(0, LEVELS.indexOf(upTo) + 1)) {
|
|
42
|
+
const results = runCorpus(target, level);
|
|
43
|
+
const bad = results.filter((r) => !r.pass);
|
|
44
|
+
failed += bad.length;
|
|
45
|
+
const name = level.charAt(0).toUpperCase() + level.slice(1);
|
|
46
|
+
lines.push(`${bad.length ? "FAILED" : "CRUBAL 2"} · ${name} · corpus ${version} (${results.length - bad.length}/${results.length})`);
|
|
47
|
+
for (const r of bad)
|
|
48
|
+
lines.push(` FAIL ${r.folder}/${r.name}${r.detail ? ` ${r.detail}` : ""}`);
|
|
49
|
+
}
|
|
50
|
+
for (const l of lines)
|
|
51
|
+
console.log(l);
|
|
52
|
+
const out = flag("--out")[0];
|
|
53
|
+
if (out && !failed) {
|
|
54
|
+
const today = new Date().toISOString().slice(0, 10);
|
|
55
|
+
writeFileSync(out, `# Conformance claim\n\n${lines.map((l) => `- ${l}`).join("\n")}\n\nRun on ${today} with \`crubal claim\` from this package against the corpus tagged \`corpus/${version}\` (spec 13.3, 13.4).\n`);
|
|
56
|
+
console.log(`written ${out}`);
|
|
57
|
+
}
|
|
58
|
+
process.exit(failed ? 1 : 0);
|
|
59
|
+
}
|
|
25
60
|
else if (cmd === "read" && target) {
|
|
26
61
|
const dict = dictionary();
|
|
27
62
|
const w = readText(readFileSync(target, "utf8"), dict);
|
|
28
63
|
console.log(rest.includes("--canonical") ? canonical(w, dict) : JSON.stringify(w, null, 2));
|
|
29
64
|
}
|
|
65
|
+
else if (cmd === "publish" && target) {
|
|
66
|
+
const dir = target;
|
|
67
|
+
const src = readFileSync(join(dir, "package.crubal"), "utf8");
|
|
68
|
+
const dict = emptyDictionary();
|
|
69
|
+
readDefinitions(src, dict);
|
|
70
|
+
// Reference records (11.1): every other .crubal file in the directory.
|
|
71
|
+
const records = readdirSync(dir).filter((f) => f.endsWith(".crubal") && f !== "package.crubal").flatMap((f) => readText(readFileSync(join(dir, f), "utf8"), dict).records);
|
|
72
|
+
const previousFile = flag("--previous")[0];
|
|
73
|
+
const previous = previousFile ? parseJson(readFileSync(previousFile, "utf8")) : undefined;
|
|
74
|
+
const keyFile = flag("--key")[0];
|
|
75
|
+
const keyJson = keyFile ? JSON.parse(readFileSync(keyFile, "utf8")) : undefined;
|
|
76
|
+
const date = flag("--date")[0] ?? new Date().toISOString().slice(0, 10);
|
|
77
|
+
const { bundle, changes } = publish(src, { date, ...(previous ? { previous } : {}), ...(records.length ? { records } : {}), ...(keyJson ? { key: { d: keyJson.private, x: keyJson.public } } : {}) });
|
|
78
|
+
for (const ch of changes)
|
|
79
|
+
if (ch.kind !== "unchanged")
|
|
80
|
+
console.error(` ${ch.kind.padEnd(9)} ${ch.member}${ch.why.length ? ` (${ch.why.join("; ")})` : ""}`);
|
|
81
|
+
const out = flag("--out")[0];
|
|
82
|
+
if (out) {
|
|
83
|
+
const at = join(out, String(bundle.package), String(bundle.version));
|
|
84
|
+
mkdirSync(at, { recursive: true });
|
|
85
|
+
writeFileSync(join(at, "package.json"), `${JSON.stringify(bundle, null, 2)}\n`);
|
|
86
|
+
writeFileSync(join(at, "package.crubal"), src);
|
|
87
|
+
const latest = join(out, String(bundle.package));
|
|
88
|
+
writeFileSync(join(latest, "package.json"), `${JSON.stringify(bundle, null, 2)}\n`);
|
|
89
|
+
writeFileSync(join(latest, "package.crubal"), src);
|
|
90
|
+
console.error(`published ${bundle.id} /${bundle.version} to ${at}${bundle.sig ? " (signed)" : " (unsigned)"}`);
|
|
91
|
+
}
|
|
92
|
+
else
|
|
93
|
+
console.log(JSON.stringify(bundle, null, 2));
|
|
94
|
+
void existsSync;
|
|
95
|
+
}
|
|
30
96
|
else if (cmd === "print" && target) {
|
|
31
|
-
console.log(printText(
|
|
97
|
+
console.log(printText(parseJson(readFileSync(target, "utf8")), dictionary(), rest.includes("--plain") ? "plain" : "full"));
|
|
32
98
|
}
|
|
33
99
|
else {
|
|
34
|
-
console.log("usage: crubal test <corpus> [--level reader] | crubal read <file> --defs <file> | crubal print <file.json> --defs <file>");
|
|
100
|
+
console.log("usage: crubal test <corpus> [--level reader] | crubal claim <corpus> [--level views] [--out CLAIM.md] | crubal read <file> --defs <file> | crubal print <file.json> --defs <file> | crubal publish <dir> [--previous <package.json>] [--date YYYY-MM-DD] [--key <file>] [--out <dir>]");
|
|
35
101
|
process.exit(2);
|
|
36
102
|
}
|
|
37
103
|
//# sourceMappingURL=crubal.js.map
|
package/dist/bin/crubal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crubal.js","sourceRoot":"","sources":["../../bin/crubal.ts"],"names":[],"mappings":";AACA,uCAAuC;AACvC,yEAAyE;AACzE,0DAA0D;AAC1D,2DAA2D;
|
|
1
|
+
{"version":3,"file":"crubal.js","sourceRoot":"","sources":["../../bin/crubal.ts"],"names":[],"mappings":";AACA,uCAAuC;AACvC,yEAAyE;AACzE,kHAAkH;AAClH,0DAA0D;AAC1D,2DAA2D;AAC3D,sGAAsG;AACtG,+GAA+G;AAE/G,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC1F,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,SAAS,EAAE,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGvH,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACrD,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAW,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAEnG,SAAS,UAAU;IACjB,MAAM,IAAI,GAAG,eAAe,EAAE,CAAC;IAC/B,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC;QAAE,eAAe,CAAC,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC;IAC/E,OAAO,IAAI,CA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type { Dictionary } from "./defs.ts";
|
|
2
|
+
import type { JsonObject, Record } from "./model.ts";
|
|
3
|
+
import type { RecordSet } from "./records.ts";
|
|
4
|
+
import { type ViewSet } from "./views.ts";
|
|
5
|
+
export declare const MODES: readonly ["none", "view", "consume", "control", "admin"];
|
|
6
|
+
export type Mode = (typeof MODES)[number];
|
|
7
|
+
export declare const VERBS: readonly ["see", "edit", "run", "review", "archive", "merge", "apply", "install", "grant"];
|
|
8
|
+
export type MenuItem = {
|
|
9
|
+
name: string;
|
|
10
|
+
verbs: {
|
|
11
|
+
[verb: string]: string[];
|
|
12
|
+
};
|
|
13
|
+
on?: string;
|
|
14
|
+
line: number;
|
|
15
|
+
};
|
|
16
|
+
export type Preset = {
|
|
17
|
+
name: string;
|
|
18
|
+
items: string[];
|
|
19
|
+
audience: string;
|
|
20
|
+
line: number;
|
|
21
|
+
};
|
|
22
|
+
export type Permissions = {
|
|
23
|
+
name?: string;
|
|
24
|
+
menu: Map<string, MenuItem>;
|
|
25
|
+
presets: Map<string, Preset>;
|
|
26
|
+
relations: Map<string, {
|
|
27
|
+
only: boolean;
|
|
28
|
+
}>;
|
|
29
|
+
/** `person` → the kinds and classes a person may own (14.1) */
|
|
30
|
+
ownership: Map<string, string[]>;
|
|
31
|
+
/** A platform's published emergency terms (11.7, 14.13). */
|
|
32
|
+
emergency?: {
|
|
33
|
+
approvers: number;
|
|
34
|
+
longest: string;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export type Edge = {
|
|
38
|
+
edge: string;
|
|
39
|
+
who: string;
|
|
40
|
+
relation: string;
|
|
41
|
+
mode: Mode;
|
|
42
|
+
on: string;
|
|
43
|
+
grants: string[];
|
|
44
|
+
where?: string;
|
|
45
|
+
until?: string;
|
|
46
|
+
gate?: string;
|
|
47
|
+
reviewer?: string;
|
|
48
|
+
by: string;
|
|
49
|
+
emergency?: JsonObject;
|
|
50
|
+
/** The package line an edge was declared on; an edge written to the log has none. */
|
|
51
|
+
line?: number;
|
|
52
|
+
};
|
|
53
|
+
export declare function emptyPermissions(): Permissions;
|
|
54
|
+
/** Read `permissions:`, `ownership:`, `emergency:` and `edge:` blocks. */
|
|
55
|
+
export declare function readAccess(source: string): {
|
|
56
|
+
perms: Permissions;
|
|
57
|
+
edges: Edge[];
|
|
58
|
+
};
|
|
59
|
+
/** Is `who` a caller of another owner? Local callers are bare IDs; foreign ones carry their owner's domain. */
|
|
60
|
+
export declare function foreign(who: string, owner: string): boolean;
|
|
61
|
+
export type Effective = {
|
|
62
|
+
mode: Mode;
|
|
63
|
+
items: Set<string>;
|
|
64
|
+
relations: Set<string>;
|
|
65
|
+
gated: boolean;
|
|
66
|
+
edges: Edge[];
|
|
67
|
+
};
|
|
68
|
+
export declare class Access {
|
|
69
|
+
/** The package's show rules (12.4), when the caller has them; without them every facet counts as public. */
|
|
70
|
+
views?: Pick<ViewSet, "shown" | "shownFor">;
|
|
71
|
+
/**
|
|
72
|
+
* May the caller see a facet of a record without an item: what the show rules give their audience,
|
|
73
|
+
* capped at member (12.4, default deny above member: a staff facet takes an item; admin and the owner see
|
|
74
|
+
* everything). A rule with a `for` covering the record decides over one for everywhere.
|
|
75
|
+
*/
|
|
76
|
+
visible(callerId: string, facet: string, recordId?: string): boolean;
|
|
77
|
+
/** The edges; a store that journals (chapter 8.5) points this at its draft's edges. */
|
|
78
|
+
edges: Map<string, Edge>;
|
|
79
|
+
readonly dict: Dictionary;
|
|
80
|
+
readonly perms: Permissions;
|
|
81
|
+
readonly records: RecordSet;
|
|
82
|
+
readonly owner: string;
|
|
83
|
+
readonly now: string | undefined;
|
|
84
|
+
constructor(dict: Dictionary, perms: Permissions, records: RecordSet, edges: Edge[], owner: string, now?: string);
|
|
85
|
+
/** The records up a record's `within` chain, nearest first (14.2). */
|
|
86
|
+
ancestors(id: string): string[];
|
|
87
|
+
/** Refuse a `within` cycle (14.12). `lineOf` names the line a record was written at, for the refusal. */
|
|
88
|
+
checkWithin(lineOf?: (id: string) => number | undefined): void;
|
|
89
|
+
/** A merged record resolves through `into` (1.12), for edges on it and reaches into it. */
|
|
90
|
+
surviving(id: string): string;
|
|
91
|
+
covers(e: Edge, recordId: string): boolean;
|
|
92
|
+
/** Does the edge's `where` hold for this record (14.4)? It narrows per record covered. */
|
|
93
|
+
holds(e: Edge, recordId: string): boolean;
|
|
94
|
+
/** Is an edge live (14.4, 14.5): not lapsed, and its grantor live and covering it? */
|
|
95
|
+
live(e: Edge, seen?: Set<string>): boolean;
|
|
96
|
+
/** Does the caller hold the key to this record: the owner, or a hosted person over a record they own? */
|
|
97
|
+
owns(callerId: string, recordId: string): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* The audience a caller belongs to (12.4, 14.4): the owner; staff for anyone with a control or admin
|
|
100
|
+
* edge, or an emergency edge; member for anyone the owner has admitted by any live edge; else public.
|
|
101
|
+
*/
|
|
102
|
+
audienceOf(callerId: string): string;
|
|
103
|
+
/** The menu items a list of grants expands to (presets open up). */
|
|
104
|
+
expand(grants: string[]): Set<string>;
|
|
105
|
+
/** A caller's access to a record from every live edge on it or an ancestor (14.4). */
|
|
106
|
+
effective(callerId: string, recordId: string): Effective;
|
|
107
|
+
/** Does the caller stand in a view's partition to the record (12.6, 14.10)? */
|
|
108
|
+
standsIn(callerId: string, recordId: string, partition: string): boolean;
|
|
109
|
+
private scopeOk;
|
|
110
|
+
/** May the caller do `verb` to `target` on the record (14.4, 14.6)? */
|
|
111
|
+
may(callerId: string, verb: string, target: string, recordId: string): boolean;
|
|
112
|
+
/** May the caller do `verb` to `target` on any record at all: by a live admin edge, or a control edge carrying it? */
|
|
113
|
+
mayAnywhere(callerId: string, verb: string, target: string): boolean;
|
|
114
|
+
/** The live gated edge a caller's access comes through, when every granting edge is gated (14.7). */
|
|
115
|
+
gated(callerId: string, recordId: string): Edge | null;
|
|
116
|
+
/** Refuse an edge the store may not write (14.12, 14.13). */
|
|
117
|
+
checkEdge(e: Edge): void;
|
|
118
|
+
/** Refuse an emergency edge outside the platform's published terms (14.13). */
|
|
119
|
+
checkEmergency(e: Edge): void;
|
|
120
|
+
/** Refuse a write that makes a record wear a class not for its kind, or classes whose meet is empty (5.5). */
|
|
121
|
+
checkWears(r: Record, line?: number): void;
|
|
122
|
+
/** Refuse a person owning a record the package doesn't let a person own (14.1, 14.12). */
|
|
123
|
+
checkOwnership(r: Record, line?: number): void;
|
|
124
|
+
}
|
|
125
|
+
/** Publish checks for a permission block (14.6). */
|
|
126
|
+
export declare function checkPermissions(perms: Permissions, dict: Dictionary, contracts?: Set<string>, views?: Set<string>): void;
|