@north-light/api 0.3.764 → 0.3.765
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.
|
@@ -70,7 +70,9 @@ async function compare(stored) {
|
|
|
70
70
|
// The directory may still send the older `'user'`/`'app'` payer; the mirror stores it as a principal.
|
|
71
71
|
const liveSide = { ...live, payer: principalPayer(live['payer'], stored.sub, stored.grantee) };
|
|
72
72
|
const storedSide = { ...stored, resolved_scopes: compactLike(stored.resolved_scopes, live['resolved_scopes']) };
|
|
73
|
-
const fields = COMPARED.filter((key) =>
|
|
73
|
+
const fields = COMPARED.filter((key) => key === 'resolved_scopes'
|
|
74
|
+
? scopeSet(liveSide[key]) !== scopeSet(storedSide[key])
|
|
75
|
+
: canonicalJson(liveSide[key] ?? null) !== canonicalJson(storedSide[key] ?? null));
|
|
74
76
|
if (fields.length === 0) {
|
|
75
77
|
shadowCounts.agree++;
|
|
76
78
|
return;
|
|
@@ -78,8 +80,16 @@ async function compare(stored) {
|
|
|
78
80
|
shadowCounts.disagree++;
|
|
79
81
|
warn(`grant_shadow disagree ${JSON.stringify({ grant: stored.id, sub: stored.sub, rev: stored.rev, fields })}`);
|
|
80
82
|
}
|
|
83
|
+
// A resolved set is a set: the expanded and compact forms list scopes in different orders, so they compare as sorted `scope|mode` lists.
|
|
84
|
+
function scopeSet(value) {
|
|
85
|
+
if (!Array.isArray(value))
|
|
86
|
+
return canonicalJson(value ?? null);
|
|
87
|
+
return JSON.stringify([...new Set(value.map((entry) => `${entry.scope}|${entry.mode}`))].sort());
|
|
88
|
+
}
|
|
81
89
|
// The live answer may hold `<provider>:*` where the stored column still lists each group (phase 4). Fold the stored groups of each such
|
|
82
|
-
// provider into its wildcard
|
|
90
|
+
// provider into its wildcard so the two forms compare equal when they name the same providers. A group the live answer still names
|
|
91
|
+
// (an `own` group, or the app's own scopes) stays, and still counts as that provider's group: when every stored group of a provider is
|
|
92
|
+
// also named exactly, the expanded form deduplicated the held groups into those names, and the wildcard stands for them.
|
|
83
93
|
function compactLike(stored, live) {
|
|
84
94
|
if (!Array.isArray(live))
|
|
85
95
|
return stored;
|
|
@@ -91,15 +101,15 @@ function compactLike(stored, live) {
|
|
|
91
101
|
if (wild.size === 0)
|
|
92
102
|
return stored;
|
|
93
103
|
const seen = new Set();
|
|
94
|
-
|
|
104
|
+
const folded = stored.flatMap((entry) => {
|
|
95
105
|
const provider = entry.scope.slice(0, entry.scope.indexOf(':'));
|
|
96
|
-
if (provider === 'crtr' || !wild.has(provider)
|
|
106
|
+
if (provider === 'crtr' || !wild.has(provider))
|
|
97
107
|
return [entry];
|
|
98
|
-
|
|
99
|
-
return [];
|
|
108
|
+
const wildcard = seen.has(provider) ? [] : [{ ...entry, scope: `${provider}:*` }];
|
|
100
109
|
seen.add(provider);
|
|
101
|
-
return [
|
|
110
|
+
return named.has(entry.scope) ? [entry, ...wildcard] : wildcard;
|
|
102
111
|
});
|
|
112
|
+
return folded;
|
|
103
113
|
}
|
|
104
114
|
let summaryTimer;
|
|
105
115
|
let reported = { agree: 0, disagree: 0, lagging: 0, error: 0 };
|
|
@@ -167,10 +167,13 @@ async function ownerView(db, src, reposFn) {
|
|
|
167
167
|
const owner = src.owner == null ? null : await getById(db, src.owner);
|
|
168
168
|
if (src.deleted_at || src.home_machine !== null || !owner || owner.deleted_at)
|
|
169
169
|
return null;
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
170
|
+
if (owner.type === 'node')
|
|
171
|
+
return await readerForNode(db, owner.id, reposFn ?? (async () => []), liveLookups(db), true);
|
|
172
|
+
// A person's document resolves as that person: an object reader under a person owner holds no scopes, so it would see none of the person's documents.
|
|
173
|
+
if (owner.type === 'person')
|
|
174
|
+
return { class: 'person', person: owner };
|
|
175
|
+
return await readerForObject(db, src, reposFn).catch((error) => { if (error instanceof NoOwningAppError)
|
|
176
|
+
return null; throw error; });
|
|
174
177
|
}
|
|
175
178
|
/** `target` has just come into existence or gained a name. Every live document whose current revision holds an
|
|
176
179
|
* unresolved link that could name it re-resolves that link in its OWNER's view (not the caller's); the link gains its
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/api",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.765",
|
|
4
4
|
"description": "Typed crtrd /v1 API contract — DTOs, route builders, the error contract, the CrtrClient, and the command-plugin manifest format. Zero runtime dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/api/index.js",
|