farseer-cli 1.16.0 → 1.17.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 +328 -0
- package/dist/commands/code.js +104 -0
- package/dist/commands/code.js.map +7 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +2 -2
- package/dist/pipeline/service.js +1 -1
- package/dist/pipeline/service.js.map +2 -2
- package/dist/services/codefirst/api.js +269 -0
- package/dist/services/codefirst/api.js.map +7 -0
- package/dist/services/codefirst/binaryDisk.js +67 -0
- package/dist/services/codefirst/binaryDisk.js.map +7 -0
- package/dist/services/codefirst/byteHashes.js +129 -0
- package/dist/services/codefirst/byteHashes.js.map +7 -0
- package/dist/services/codefirst/documents.js +563 -0
- package/dist/services/codefirst/documents.js.map +7 -0
- package/dist/services/codefirst/layoutBinaryProjection.js +974 -0
- package/dist/services/codefirst/layoutBinaryProjection.js.map +7 -0
- package/dist/services/codefirst/layoutCompose.js +593 -0
- package/dist/services/codefirst/layoutCompose.js.map +7 -0
- package/dist/services/codefirst/layoutCore.js +260 -0
- package/dist/services/codefirst/layoutCore.js.map +7 -0
- package/dist/services/codefirst/layoutPaths.js +492 -0
- package/dist/services/codefirst/layoutPaths.js.map +7 -0
- package/dist/services/codefirst/layoutProjection.js +995 -0
- package/dist/services/codefirst/layoutProjection.js.map +7 -0
- package/dist/services/codefirst/layoutReadback.js +2552 -0
- package/dist/services/codefirst/layoutReadback.js.map +7 -0
- package/dist/services/codefirst/layoutReadbackPlacement.js +1517 -0
- package/dist/services/codefirst/layoutReadbackPlacement.js.map +7 -0
- package/dist/services/codefirst/layoutReceipt.js +1592 -0
- package/dist/services/codefirst/layoutReceipt.js.map +7 -0
- package/dist/services/codefirst/layoutScan.js +882 -0
- package/dist/services/codefirst/layoutScan.js.map +7 -0
- package/dist/services/codefirst/output.js +179 -0
- package/dist/services/codefirst/output.js.map +7 -0
- package/dist/services/codefirst/types.js +17 -0
- package/dist/services/codefirst/types.js.map +7 -0
- package/dist/services/codefirst/workflow.js +581 -0
- package/dist/services/codefirst/workflow.js.map +7 -0
- package/dist/services/codefirst/workspace.js +310 -0
- package/dist/services/codefirst/workspace.js.map +7 -0
- package/dist/services/codefirst/workspaceLock.js +148 -0
- package/dist/services/codefirst/workspaceLock.js.map +7 -0
- package/dist/services/codefirst/workspaceRoot.js +147 -0
- package/dist/services/codefirst/workspaceRoot.js.map +7 -0
- package/dist/utils/logger.js +9 -3
- package/dist/utils/logger.js.map +2 -2
- package/package.json +3 -2
|
@@ -0,0 +1,995 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var layoutProjection_exports = {};
|
|
20
|
+
__export(layoutProjection_exports, {
|
|
21
|
+
composeGroupedLayout: () => composeGroupedLayout,
|
|
22
|
+
decomposeGroupedLayout: () => decomposeGroupedLayout,
|
|
23
|
+
derivedSourceSelectorHash: () => derivedSourceSelectorHash
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(layoutProjection_exports);
|
|
26
|
+
var import_documents = require("./documents");
|
|
27
|
+
var import_layoutPaths = require("./layoutPaths");
|
|
28
|
+
var import_layoutCore = require("./layoutCore");
|
|
29
|
+
const OWNER_KINDS = /* @__PURE__ */ new Set(["folder", "variable", "dimension_table", "sheet", "dashboard", "file", "remote_job"]);
|
|
30
|
+
const GLOBAL_OWNER_KINDS = /* @__PURE__ */ new Set(["variable", "dimension_table"]);
|
|
31
|
+
const DOCUMENT_KINDS = /* @__PURE__ */ new Set([
|
|
32
|
+
"folder",
|
|
33
|
+
"variable",
|
|
34
|
+
"dimension_table",
|
|
35
|
+
"dimension_members",
|
|
36
|
+
"sheet",
|
|
37
|
+
"dashboard",
|
|
38
|
+
"share",
|
|
39
|
+
"user_group",
|
|
40
|
+
"user_permissions",
|
|
41
|
+
"label",
|
|
42
|
+
"settings",
|
|
43
|
+
"file",
|
|
44
|
+
"export_configuration",
|
|
45
|
+
"remote_job",
|
|
46
|
+
"dataset"
|
|
47
|
+
]);
|
|
48
|
+
function derivedSourceSelectorHash(document) {
|
|
49
|
+
return document.kind === "user_permissions" && (0, import_layoutCore.own)(document, "user") ? (0, import_layoutCore.canonicalFragmentHash)(document.user) : void 0;
|
|
50
|
+
}
|
|
51
|
+
function identityFrom(value, kind) {
|
|
52
|
+
if (typeof value.id === "string") return { kind, id: value.id };
|
|
53
|
+
if (typeof value.key === "string") return { kind, key: value.key };
|
|
54
|
+
return void 0;
|
|
55
|
+
}
|
|
56
|
+
function semanticSource(source, kind) {
|
|
57
|
+
if (source.type !== "resource") return source;
|
|
58
|
+
return "id" in source.resource ? { type: "resource", resource: { kind, id: source.resource.id } } : { type: "resource", resource: { kind, key: source.resource.key } };
|
|
59
|
+
}
|
|
60
|
+
function selectorSlot(selector) {
|
|
61
|
+
return selector.slot;
|
|
62
|
+
}
|
|
63
|
+
function submissionScopeKey(file, slot) {
|
|
64
|
+
return JSON.stringify([file, slot]);
|
|
65
|
+
}
|
|
66
|
+
function submissionEvidenceHash(fragment, container) {
|
|
67
|
+
return typeof fragment === "string" && fragment.length > 0 && typeof container === "string" && container.length > 0 ? (0, import_layoutCore.canonicalFragmentHash)({ fragmentHash: fragment, containerHash: container }) : void 0;
|
|
68
|
+
}
|
|
69
|
+
function sameSelectorLocation(left, right) {
|
|
70
|
+
if (left.slot !== right.slot || left.file !== right.file) return false;
|
|
71
|
+
if (left.slot !== "share-entry" || right.slot !== "share-entry") return true;
|
|
72
|
+
const a = left.identity;
|
|
73
|
+
const b = right.identity;
|
|
74
|
+
if ("id" in a && "id" in b) return a.id === b.id;
|
|
75
|
+
if ("key" in a && "key" in b) return a.key === b.key;
|
|
76
|
+
return "transient" in a && "transient" in b && a.transient === b.transient;
|
|
77
|
+
}
|
|
78
|
+
function composeGroupedLayout(input) {
|
|
79
|
+
const priorRoutes = input.priorRoutes ?? [];
|
|
80
|
+
const priorBySource = /* @__PURE__ */ new Map();
|
|
81
|
+
priorRoutes.forEach((route, index) => {
|
|
82
|
+
const key = (0, import_layoutCore.sourceIdentityKey)(route.source);
|
|
83
|
+
const list = priorBySource.get(key);
|
|
84
|
+
if (list) list.push({ route, index });
|
|
85
|
+
else priorBySource.set(key, [{ route, index }]);
|
|
86
|
+
});
|
|
87
|
+
const priorRoutesOf = (source) => priorBySource.get((0, import_layoutCore.sourceIdentityKey)(source)) ?? [];
|
|
88
|
+
const submissionProofs = input.submissionProofs ?? [];
|
|
89
|
+
const documents = [];
|
|
90
|
+
const sources = [];
|
|
91
|
+
const navigation = [];
|
|
92
|
+
const diagnostics = [];
|
|
93
|
+
const fragments = [];
|
|
94
|
+
const owners = /* @__PURE__ */ new Map();
|
|
95
|
+
const groups = /* @__PURE__ */ new Map();
|
|
96
|
+
const artifactPaths = /* @__PURE__ */ new Set();
|
|
97
|
+
const stableResources = /* @__PURE__ */ new Map();
|
|
98
|
+
const unclassifiedFiles = /* @__PURE__ */ new Set();
|
|
99
|
+
const usedTransientTokens = /* @__PURE__ */ new Set([
|
|
100
|
+
...submissionProofs.map((proof) => proof.source.token),
|
|
101
|
+
...input.reservedTransientTokens ?? []
|
|
102
|
+
]);
|
|
103
|
+
const normalizedSubmissionProofs = submissionProofs.map((proof) => ({
|
|
104
|
+
token: proof.source.token,
|
|
105
|
+
scopeKey: submissionScopeKey(proof.selector.file, proof.selector.slot),
|
|
106
|
+
sourcePath: proof.sourcePath,
|
|
107
|
+
evidenceHash: submissionEvidenceHash(proof.fragmentHash, proof.containerHash)
|
|
108
|
+
}));
|
|
109
|
+
let transientSequence = 0;
|
|
110
|
+
const diagnostic = (code, path, message, sourcePath, relatedPath) => diagnostics.push({
|
|
111
|
+
code,
|
|
112
|
+
path,
|
|
113
|
+
message,
|
|
114
|
+
...sourcePath ? { sourcePath } : {},
|
|
115
|
+
...relatedPath ? { relatedPath } : {}
|
|
116
|
+
});
|
|
117
|
+
const newTransient = () => {
|
|
118
|
+
const allocated = (0, import_layoutCore.allocateSubmissionToken)(usedTransientTokens, transientSequence);
|
|
119
|
+
transientSequence = allocated.sequence;
|
|
120
|
+
return { type: "transient", token: allocated.token };
|
|
121
|
+
};
|
|
122
|
+
const transientFor = (path, candidates, containerHash) => {
|
|
123
|
+
const match = (0, import_layoutCore.matchExactSubmissionProof)(
|
|
124
|
+
normalizedSubmissionProofs,
|
|
125
|
+
candidates.map((candidate) => ({
|
|
126
|
+
scopeKey: submissionScopeKey(path, candidate.slot),
|
|
127
|
+
sourcePath: candidate.sourcePath,
|
|
128
|
+
evidenceHash: submissionEvidenceHash(candidate.hash, containerHash)
|
|
129
|
+
}))
|
|
130
|
+
);
|
|
131
|
+
if (match.status === "matched") return { type: "transient", token: match.token };
|
|
132
|
+
if (match.status === "ambiguous")
|
|
133
|
+
diagnostic("ambiguous-source-correspondence", path, "Multiple transient routes match this fragment");
|
|
134
|
+
else if (match.status === "lost")
|
|
135
|
+
diagnostic("lost-source-correspondence", path, "The unchanged transient source can no longer be located");
|
|
136
|
+
return newTransient();
|
|
137
|
+
};
|
|
138
|
+
const canonicalTexts = /* @__PURE__ */ new Map();
|
|
139
|
+
const validatePath = (artifact) => {
|
|
140
|
+
(0, import_layoutPaths.parseWorkspacePointer)(artifact.path);
|
|
141
|
+
if (artifactPaths.has(artifact.path)) {
|
|
142
|
+
unclassifiedFiles.add(artifact.path);
|
|
143
|
+
diagnostic("duplicate-artifact-path", artifact.path, "Multiple artifacts use the same path");
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
artifactPaths.add(artifact.path);
|
|
147
|
+
try {
|
|
148
|
+
canonicalTexts.set(artifact, (0, import_documents.canonicalText)(artifact.value));
|
|
149
|
+
return true;
|
|
150
|
+
} catch (error) {
|
|
151
|
+
unclassifiedFiles.add(artifact.path);
|
|
152
|
+
diagnostic("invalid-json-value", artifact.path, error.message);
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const validateIdentity = (value, path) => {
|
|
157
|
+
if ((0, import_layoutCore.own)(value, "id") && (0, import_layoutCore.own)(value, "key")) {
|
|
158
|
+
diagnostic("duplicate-local-identity", path, "An artifact cannot contain both id and key");
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
if ((0, import_layoutCore.own)(value, "id") && (typeof value.id !== "string" || !import_layoutCore.RESOURCE_ID.test(value.id))) {
|
|
162
|
+
diagnostic("invalid-resource-id", path, "Resource id must be a canonical non-negative integer string");
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
if ((0, import_layoutCore.own)(value, "key") && (typeof value.key !== "string" || value.key.length === 0)) {
|
|
166
|
+
diagnostic("invalid-local-key", path, "Local key must be a nonempty string");
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
return true;
|
|
170
|
+
};
|
|
171
|
+
const addOwner = (owner) => {
|
|
172
|
+
if (!owner.selector) return;
|
|
173
|
+
const key = (0, import_layoutCore.ownerKey)(owner.selector);
|
|
174
|
+
owners.set(key, [...owners.get(key) ?? [], owner]);
|
|
175
|
+
};
|
|
176
|
+
const claimResource = (identity, path, sourcePath) => {
|
|
177
|
+
const key = (0, import_layoutCore.sourceIdentityKey)({ type: "resource", resource: identity });
|
|
178
|
+
const previous = stableResources.get(key);
|
|
179
|
+
if (!previous) {
|
|
180
|
+
stableResources.set(key, path);
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
unclassifiedFiles.add(path);
|
|
184
|
+
unclassifiedFiles.add(previous);
|
|
185
|
+
diagnostic(
|
|
186
|
+
identity.kind === "share" ? "duplicate-share-identity" : "duplicate-resource-identity",
|
|
187
|
+
path,
|
|
188
|
+
`A semantic resource identity occurs in both ${previous} and ${path}`,
|
|
189
|
+
sourcePath,
|
|
190
|
+
previous
|
|
191
|
+
);
|
|
192
|
+
return false;
|
|
193
|
+
};
|
|
194
|
+
const addNavigation = (owner) => {
|
|
195
|
+
if (!(0, import_layoutCore.own)(owner.value, "shares")) return;
|
|
196
|
+
if (!OWNER_KINDS.has(String(owner.value.kind))) {
|
|
197
|
+
unclassifiedFiles.add(owner.path);
|
|
198
|
+
diagnostic("unsupported-share-pointer", owner.path, "This resource kind cannot own a share group", [
|
|
199
|
+
"shares"
|
|
200
|
+
]);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (!owner.selector) {
|
|
204
|
+
unclassifiedFiles.add(owner.path);
|
|
205
|
+
diagnostic("missing-owner-key", owner.path, "A new owner with a share pointer requires a local key", [
|
|
206
|
+
"shares"
|
|
207
|
+
]);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const pointer = (0, import_layoutCore.object)(owner.value.shares);
|
|
211
|
+
if (!pointer || Object.keys(pointer).length !== 1 || typeof pointer.file !== "string") {
|
|
212
|
+
unclassifiedFiles.add(owner.path);
|
|
213
|
+
diagnostic("invalid-share-pointer", owner.path, "The shares pointer must contain only a file string", [
|
|
214
|
+
"shares"
|
|
215
|
+
]);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
let file;
|
|
219
|
+
try {
|
|
220
|
+
file = (0, import_layoutPaths.parseWorkspacePointer)(pointer.file);
|
|
221
|
+
} catch (error) {
|
|
222
|
+
unclassifiedFiles.add(owner.path);
|
|
223
|
+
diagnostic("invalid-share-pointer", owner.path, error.message, ["shares"]);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
owner.pointer = file;
|
|
227
|
+
const selector = { file: owner.path, slot: "owner-navigation" };
|
|
228
|
+
fragments.push({
|
|
229
|
+
source: owner.source,
|
|
230
|
+
selector,
|
|
231
|
+
sourcePath: ["shares"],
|
|
232
|
+
hash: (0, import_layoutCore.canonicalFragmentHash)({ file }),
|
|
233
|
+
containerHash: (0, import_layoutCore.canonicalFragmentHash)(owner.value),
|
|
234
|
+
contributor: false
|
|
235
|
+
});
|
|
236
|
+
navigation.push({
|
|
237
|
+
source: owner.source,
|
|
238
|
+
selector,
|
|
239
|
+
sourcePath: ["shares"],
|
|
240
|
+
groupFile: file,
|
|
241
|
+
owner: owner.selector
|
|
242
|
+
});
|
|
243
|
+
};
|
|
244
|
+
const addWireDocument = (document, source, selector, sourcePath, hash, metadata = {}) => {
|
|
245
|
+
const documentIndex = documents.length;
|
|
246
|
+
documents.push(document);
|
|
247
|
+
sources.push({ documentIndex, sourcePath, source, selector, ...metadata });
|
|
248
|
+
fragments.push({
|
|
249
|
+
source,
|
|
250
|
+
selector,
|
|
251
|
+
sourcePath,
|
|
252
|
+
hash,
|
|
253
|
+
...metadata.containerHash ? { containerHash: metadata.containerHash } : {},
|
|
254
|
+
...metadata.derivedSelectorHash ? { derivedSelectorHash: metadata.derivedSelectorHash } : {},
|
|
255
|
+
contributor: true
|
|
256
|
+
});
|
|
257
|
+
};
|
|
258
|
+
const priorProvesNavigation = (owner, groupFile) => owner.external ? owner.priorPointer === groupFile : priorRoutesOf(owner.source).some(
|
|
259
|
+
({ route }) => route.selector.file === owner.path && route.selector.slot === "owner-navigation"
|
|
260
|
+
);
|
|
261
|
+
const priorProvesGroup = (path, owner) => {
|
|
262
|
+
const source = { type: "group", owner };
|
|
263
|
+
return priorRoutesOf(source).some(
|
|
264
|
+
({ route }) => route.selector.file === path && route.selector.slot === "share-group-owner"
|
|
265
|
+
);
|
|
266
|
+
};
|
|
267
|
+
const validArtifacts = input.artifacts.filter(validatePath);
|
|
268
|
+
const containerHashOf = (artifact) => (0, import_layoutCore.hashCanonicalText)(canonicalTexts.get(artifact));
|
|
269
|
+
const derivedProofs = [];
|
|
270
|
+
const seenDerivedProofs = /* @__PURE__ */ new Set();
|
|
271
|
+
const addDerivedProof = (source, selectorHash, path, validSelector) => {
|
|
272
|
+
if (selectorHash === void 0) return;
|
|
273
|
+
if (source.type !== "resource" || source.resource.kind !== "user_permissions" || !("id" in source.resource) || !validSelector || typeof source.resource.id !== "string" || typeof selectorHash !== "string" || !import_layoutCore.RESOURCE_ID.test(source.resource.id) || !import_layoutCore.SHA256.test(selectorHash)) {
|
|
274
|
+
diagnostic(
|
|
275
|
+
"invalid-derived-source-proof",
|
|
276
|
+
path,
|
|
277
|
+
"A derived source proof must pair a canonical user-permissions ID with a selector hash"
|
|
278
|
+
);
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const proof = {
|
|
282
|
+
source: {
|
|
283
|
+
type: "resource",
|
|
284
|
+
resource: { kind: "user_permissions", id: source.resource.id }
|
|
285
|
+
},
|
|
286
|
+
selectorHash
|
|
287
|
+
};
|
|
288
|
+
const key = `${(0, import_layoutCore.sourceIdentityKey)(proof.source)}/${selectorHash}`;
|
|
289
|
+
if (!seenDerivedProofs.has(key)) {
|
|
290
|
+
seenDerivedProofs.add(key);
|
|
291
|
+
derivedProofs.push(proof);
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
for (const route of priorRoutes)
|
|
295
|
+
addDerivedProof(
|
|
296
|
+
route.source,
|
|
297
|
+
route.derivedSelectorHash,
|
|
298
|
+
route.selector.file,
|
|
299
|
+
route.selector.slot === "document"
|
|
300
|
+
);
|
|
301
|
+
for (const proof of input.derivedSourceProofs ?? [])
|
|
302
|
+
addDerivedProof(proof.source, proof.selectorHash, "source-provenance", true);
|
|
303
|
+
const derivedArtifactCounts = /* @__PURE__ */ new Map();
|
|
304
|
+
for (const artifact of validArtifacts) {
|
|
305
|
+
if (artifact.role === "share-group" || artifact.value.kind !== "user_permissions") continue;
|
|
306
|
+
const selectorHash = derivedSourceSelectorHash(artifact.value);
|
|
307
|
+
if (selectorHash) derivedArtifactCounts.set(selectorHash, (derivedArtifactCounts.get(selectorHash) ?? 0) + 1);
|
|
308
|
+
}
|
|
309
|
+
let unprovenDerivedArtifacts = 0;
|
|
310
|
+
for (const artifact of validArtifacts) {
|
|
311
|
+
if (artifact.role === "share-group") continue;
|
|
312
|
+
const value = artifact.value;
|
|
313
|
+
const containerHash = containerHashOf(artifact);
|
|
314
|
+
if (typeof value.kind !== "string" || !DOCUMENT_KINDS.has(value.kind)) {
|
|
315
|
+
unclassifiedFiles.add(artifact.path);
|
|
316
|
+
diagnostic("invalid-document-kind", artifact.path, "Grouped document has an unsupported kind");
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
if (value.kind === "share" || value.kind === "dimension_members") {
|
|
320
|
+
unclassifiedFiles.add(artifact.path);
|
|
321
|
+
diagnostic("invalid-grouped-role", artifact.path, `${value.kind} must use its grouped representation`);
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
if (artifact.role === "combined-table" && value.kind !== "dimension_table") {
|
|
325
|
+
unclassifiedFiles.add(artifact.path);
|
|
326
|
+
diagnostic("invalid-grouped-role", artifact.path, "A combined table must have kind dimension_table");
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
if (artifact.role === "document" && value.kind === "dimension_table") {
|
|
330
|
+
unclassifiedFiles.add(artifact.path);
|
|
331
|
+
diagnostic("invalid-grouped-role", artifact.path, "A dimension table must use the combined-table role");
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
if (!validateIdentity(value, artifact.path)) {
|
|
335
|
+
unclassifiedFiles.add(artifact.path);
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
if (value.kind === "user_permissions" && ((0, import_layoutCore.own)(value, "id") || (0, import_layoutCore.own)(value, "key"))) {
|
|
339
|
+
unclassifiedFiles.add(artifact.path);
|
|
340
|
+
diagnostic(
|
|
341
|
+
"unsupported-derived-identity",
|
|
342
|
+
artifact.path,
|
|
343
|
+
"User-permissions identity comes only from authoritative selector provenance"
|
|
344
|
+
);
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
const authoredIdentity = identityFrom(value, value.kind);
|
|
348
|
+
if (value.kind === "settings" && (authoredIdentity === void 0 || !("id" in authoredIdentity) || authoredIdentity.id !== "1") && ((0, import_layoutCore.own)(value, "id") || (0, import_layoutCore.own)(value, "key"))) {
|
|
349
|
+
unclassifiedFiles.add(artifact.path);
|
|
350
|
+
diagnostic("invalid-settings-identity", artifact.path, "Settings has the fixed identity settings/1");
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
const derivedSelectorHash = derivedSourceSelectorHash(value);
|
|
354
|
+
let identity = authoredIdentity;
|
|
355
|
+
if (value.kind === "settings") identity = { kind: "settings", id: "1" };
|
|
356
|
+
else if (value.kind === "user_permissions" && identity === void 0) {
|
|
357
|
+
const matches = derivedSelectorHash ? derivedProofs.filter((proof) => proof.selectorHash === derivedSelectorHash) : [];
|
|
358
|
+
const currentSelectorCount = derivedSelectorHash ? derivedArtifactCounts.get(derivedSelectorHash) ?? 0 : 0;
|
|
359
|
+
const unique = matches.length === 1 && currentSelectorCount === 1;
|
|
360
|
+
if (unique) identity = matches[0].source.resource;
|
|
361
|
+
else {
|
|
362
|
+
unprovenDerivedArtifacts += 1;
|
|
363
|
+
if (matches.length > 1 || currentSelectorCount > 1)
|
|
364
|
+
diagnostic(
|
|
365
|
+
"ambiguous-derived-source",
|
|
366
|
+
artifact.path,
|
|
367
|
+
"A user-permissions selector does not have one unique source proof"
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
if (identity && !claimResource(identity, artifact.path)) continue;
|
|
372
|
+
const definition = (0, import_layoutCore.without)(value, [
|
|
373
|
+
"key",
|
|
374
|
+
"shares",
|
|
375
|
+
...artifact.role === "combined-table" ? ["members"] : []
|
|
376
|
+
]);
|
|
377
|
+
if (artifact.role === "combined-table" && !Array.isArray(value.members)) {
|
|
378
|
+
unclassifiedFiles.add(artifact.path);
|
|
379
|
+
diagnostic("missing-table-members", artifact.path, "A combined dimension table requires members");
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
382
|
+
if (artifact.role === "combined-table" && typeof value.name !== "string") {
|
|
383
|
+
unclassifiedFiles.add(artifact.path);
|
|
384
|
+
diagnostic("invalid-table-name", artifact.path, "A combined dimension table requires a name");
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
const definitionHash = (0, import_layoutCore.canonicalFragmentHash)(definition);
|
|
388
|
+
const memberHash = artifact.role === "combined-table" ? (0, import_layoutCore.canonicalFragmentHash)({ members: value.members }) : void 0;
|
|
389
|
+
const baseSource = identity ? { type: "resource", resource: identity } : transientFor(
|
|
390
|
+
artifact.path,
|
|
391
|
+
[
|
|
392
|
+
{
|
|
393
|
+
slot: artifact.role === "combined-table" ? "table-definition" : "document",
|
|
394
|
+
sourcePath: [],
|
|
395
|
+
hash: definitionHash
|
|
396
|
+
},
|
|
397
|
+
...memberHash === void 0 ? [] : [{ slot: "member-set", sourcePath: ["members"], hash: memberHash }]
|
|
398
|
+
],
|
|
399
|
+
containerHash
|
|
400
|
+
);
|
|
401
|
+
const selector = {
|
|
402
|
+
file: artifact.path,
|
|
403
|
+
slot: artifact.role === "combined-table" ? "table-definition" : "document"
|
|
404
|
+
};
|
|
405
|
+
addWireDocument(definition, baseSource, selector, [], definitionHash, {
|
|
406
|
+
containerHash,
|
|
407
|
+
...derivedSelectorHash ? { derivedSelectorHash } : {}
|
|
408
|
+
});
|
|
409
|
+
const ownerSelector = identity ? "id" in identity ? { kind: value.kind, id: identity.id } : { kind: value.kind, key: identity.key } : void 0;
|
|
410
|
+
const owner = {
|
|
411
|
+
path: artifact.path,
|
|
412
|
+
value,
|
|
413
|
+
source: baseSource,
|
|
414
|
+
selector: OWNER_KINDS.has(value.kind) ? ownerSelector : void 0
|
|
415
|
+
};
|
|
416
|
+
addOwner(owner);
|
|
417
|
+
addNavigation(owner);
|
|
418
|
+
if (artifact.role === "combined-table") {
|
|
419
|
+
const memberSource = semanticSource(baseSource, "dimension_members");
|
|
420
|
+
const memberDocument = {
|
|
421
|
+
kind: "dimension_members",
|
|
422
|
+
table: identity && "id" in identity ? { id: identity.id } : value.name,
|
|
423
|
+
members: value.members
|
|
424
|
+
};
|
|
425
|
+
addWireDocument(
|
|
426
|
+
memberDocument,
|
|
427
|
+
memberSource,
|
|
428
|
+
{ file: artifact.path, slot: "member-set" },
|
|
429
|
+
["members"],
|
|
430
|
+
memberHash,
|
|
431
|
+
{ containerHash }
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
for (const external of input.externalOwners ?? []) {
|
|
436
|
+
const locationPath = [...external.location.path];
|
|
437
|
+
const expectedResource = external.source.resource;
|
|
438
|
+
const selectorMatches = expectedResource.kind === "file" && external.owner.kind === "file" && ("id" in expectedResource && "id" in external.owner && expectedResource.id === external.owner.id || "key" in expectedResource && "key" in external.owner && expectedResource.key === external.owner.key);
|
|
439
|
+
if (!selectorMatches || external.value.kind !== "file") {
|
|
440
|
+
diagnostic(
|
|
441
|
+
"invalid-external-owner",
|
|
442
|
+
external.location.file,
|
|
443
|
+
"External owner source, selector, and value must identify the same file",
|
|
444
|
+
locationPath
|
|
445
|
+
);
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
448
|
+
if (!claimResource(expectedResource, external.location.file, locationPath)) continue;
|
|
449
|
+
addOwner({
|
|
450
|
+
path: external.location.file,
|
|
451
|
+
value: external.value,
|
|
452
|
+
source: external.source,
|
|
453
|
+
selector: external.owner,
|
|
454
|
+
...external.currentGroupFile ? { pointer: external.currentGroupFile } : {},
|
|
455
|
+
...external.priorGroupFile ? { priorPointer: external.priorGroupFile } : {},
|
|
456
|
+
external: true,
|
|
457
|
+
locationPath
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
const groupArtifacts = validArtifacts.filter(
|
|
461
|
+
(artifact) => artifact.role === "share-group"
|
|
462
|
+
);
|
|
463
|
+
for (const artifact of groupArtifacts) {
|
|
464
|
+
const value = artifact.value;
|
|
465
|
+
const containerHash = containerHashOf(artifact);
|
|
466
|
+
if (Object.keys(value).some((field) => field !== "owner" && field !== "shares")) {
|
|
467
|
+
unclassifiedFiles.add(artifact.path);
|
|
468
|
+
diagnostic("unknown-group-field", artifact.path, "A share group can contain only owner and shares");
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
const ownerValue = (0, import_layoutCore.object)(value.owner);
|
|
472
|
+
if (!ownerValue || typeof ownerValue.kind !== "string" || !OWNER_KINDS.has(ownerValue.kind)) {
|
|
473
|
+
unclassifiedFiles.add(artifact.path);
|
|
474
|
+
diagnostic("invalid-group-owner", artifact.path, "A share group requires a supported owner");
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
477
|
+
const variants = ["id", "key", "dangling"].filter((field) => (0, import_layoutCore.own)(ownerValue, field));
|
|
478
|
+
if (Object.keys(ownerValue).length !== 2 || variants.length !== 1) {
|
|
479
|
+
unclassifiedFiles.add(artifact.path);
|
|
480
|
+
diagnostic(
|
|
481
|
+
"invalid-group-owner",
|
|
482
|
+
artifact.path,
|
|
483
|
+
"A share group owner requires exactly one tagged selector"
|
|
484
|
+
);
|
|
485
|
+
continue;
|
|
486
|
+
}
|
|
487
|
+
const variant = variants[0];
|
|
488
|
+
const selected = ownerValue[variant];
|
|
489
|
+
if (typeof selected !== "string" || selected.length === 0 || (variant === "id" || variant === "dangling") && !import_layoutCore.RESOURCE_ID.test(selected)) {
|
|
490
|
+
unclassifiedFiles.add(artifact.path);
|
|
491
|
+
diagnostic("invalid-group-owner", artifact.path, `Invalid share group owner ${variant}`);
|
|
492
|
+
continue;
|
|
493
|
+
}
|
|
494
|
+
const owner = { kind: ownerValue.kind, [variant]: selected };
|
|
495
|
+
const ownerIdentity = (0, import_layoutCore.ownerKey)(owner);
|
|
496
|
+
const previousGroup = groups.get(ownerIdentity);
|
|
497
|
+
if (previousGroup) {
|
|
498
|
+
unclassifiedFiles.add(artifact.path);
|
|
499
|
+
unclassifiedFiles.add(previousGroup.path);
|
|
500
|
+
diagnostic(
|
|
501
|
+
"duplicate-owner-group",
|
|
502
|
+
artifact.path,
|
|
503
|
+
"More than one share group has the same owner selector",
|
|
504
|
+
["owner"],
|
|
505
|
+
previousGroup.path
|
|
506
|
+
);
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
if (!Array.isArray(value.shares)) {
|
|
510
|
+
unclassifiedFiles.add(artifact.path);
|
|
511
|
+
diagnostic("invalid-share-list", artifact.path, "A share group requires a shares array", ["shares"]);
|
|
512
|
+
continue;
|
|
513
|
+
}
|
|
514
|
+
let wireOwner;
|
|
515
|
+
let ownerDocument;
|
|
516
|
+
let externalOwnerLocation;
|
|
517
|
+
if ("key" in owner) {
|
|
518
|
+
const matches = owners.get(ownerIdentity) ?? [];
|
|
519
|
+
if (matches.length !== 1) {
|
|
520
|
+
unclassifiedFiles.add(artifact.path);
|
|
521
|
+
diagnostic(
|
|
522
|
+
"unbound-owner-key",
|
|
523
|
+
artifact.path,
|
|
524
|
+
matches.length ? "A local owner key is ambiguous" : "A local owner key has no matching artifact",
|
|
525
|
+
["owner"]
|
|
526
|
+
);
|
|
527
|
+
continue;
|
|
528
|
+
}
|
|
529
|
+
const target = matches[0];
|
|
530
|
+
if (target.pointer !== artifact.path && !(target.pointer === void 0 && priorProvesNavigation(target, artifact.path))) {
|
|
531
|
+
unclassifiedFiles.add(artifact.path);
|
|
532
|
+
diagnostic(
|
|
533
|
+
"unlinked-owner-group",
|
|
534
|
+
artifact.path,
|
|
535
|
+
"A keyed owner must point to its share group",
|
|
536
|
+
["owner"],
|
|
537
|
+
target.path
|
|
538
|
+
);
|
|
539
|
+
continue;
|
|
540
|
+
}
|
|
541
|
+
const targetKind = String(target.value.kind);
|
|
542
|
+
if (!target.external)
|
|
543
|
+
ownerDocument = {
|
|
544
|
+
file: target.path,
|
|
545
|
+
kind: targetKind,
|
|
546
|
+
...Array.isArray(target.value.folder) ? { folderLength: target.value.folder.length } : {}
|
|
547
|
+
};
|
|
548
|
+
else externalOwnerLocation = { file: target.path, path: [...target.locationPath ?? []] };
|
|
549
|
+
if (targetKind === "folder" && Array.isArray(target.value.path))
|
|
550
|
+
wireOwner = { kind: targetKind, path: target.value.path };
|
|
551
|
+
else if (GLOBAL_OWNER_KINDS.has(targetKind) && typeof target.value.name === "string")
|
|
552
|
+
wireOwner = { kind: targetKind, name: target.value.name };
|
|
553
|
+
else if (["sheet", "dashboard", "file", "remote_job"].includes(targetKind) && Array.isArray(target.value.folder) && typeof target.value.name === "string")
|
|
554
|
+
wireOwner = { kind: targetKind, path: [...target.value.folder, target.value.name] };
|
|
555
|
+
else {
|
|
556
|
+
unclassifiedFiles.add(artifact.path);
|
|
557
|
+
diagnostic(
|
|
558
|
+
"unreadable-owner-key",
|
|
559
|
+
artifact.path,
|
|
560
|
+
"A new keyed owner needs a readable backend owner reference",
|
|
561
|
+
["owner"],
|
|
562
|
+
target.path
|
|
563
|
+
);
|
|
564
|
+
continue;
|
|
565
|
+
}
|
|
566
|
+
} else wireOwner = { ...owner };
|
|
567
|
+
groups.set(ownerIdentity, { path: artifact.path, owner });
|
|
568
|
+
const headerHash = (0, import_layoutCore.canonicalFragmentHash)(owner);
|
|
569
|
+
const headerSource = { type: "group", owner };
|
|
570
|
+
fragments.push({
|
|
571
|
+
source: headerSource,
|
|
572
|
+
selector: { file: artifact.path, slot: "share-group-owner" },
|
|
573
|
+
sourcePath: ["owner"],
|
|
574
|
+
hash: headerHash,
|
|
575
|
+
containerHash,
|
|
576
|
+
contributor: false
|
|
577
|
+
});
|
|
578
|
+
for (const [index, entryValue] of value.shares.entries()) {
|
|
579
|
+
const entry = (0, import_layoutCore.object)(entryValue);
|
|
580
|
+
const sourcePath = ["shares", index];
|
|
581
|
+
if (!entry) {
|
|
582
|
+
unclassifiedFiles.add(artifact.path);
|
|
583
|
+
diagnostic("invalid-share-entry", artifact.path, "A share entry must be an object", sourcePath);
|
|
584
|
+
continue;
|
|
585
|
+
}
|
|
586
|
+
if ((0, import_layoutCore.own)(entry, "kind") || (0, import_layoutCore.own)(entry, "owner")) {
|
|
587
|
+
unclassifiedFiles.add(artifact.path);
|
|
588
|
+
diagnostic(
|
|
589
|
+
"reserved-share-field",
|
|
590
|
+
artifact.path,
|
|
591
|
+
"A grouped share entry cannot contain kind or owner",
|
|
592
|
+
sourcePath
|
|
593
|
+
);
|
|
594
|
+
continue;
|
|
595
|
+
}
|
|
596
|
+
if (!validateIdentity(entry, artifact.path)) {
|
|
597
|
+
unclassifiedFiles.add(artifact.path);
|
|
598
|
+
continue;
|
|
599
|
+
}
|
|
600
|
+
const identity = identityFrom(entry, "share");
|
|
601
|
+
if (identity && !claimResource(identity, artifact.path, sourcePath)) continue;
|
|
602
|
+
const semanticEntry = (0, import_layoutCore.without)(entry, ["key"]);
|
|
603
|
+
const hashValue = { ...semanticEntry, kind: "share", owner: { ...owner } };
|
|
604
|
+
const entryHash = (0, import_layoutCore.canonicalFragmentHash)(hashValue);
|
|
605
|
+
if ("dangling" in owner && (!identity || !("id" in identity))) {
|
|
606
|
+
unclassifiedFiles.add(artifact.path);
|
|
607
|
+
diagnostic(
|
|
608
|
+
"missing-share-id",
|
|
609
|
+
artifact.path,
|
|
610
|
+
"A dangling-owner group can contain only existing share IDs",
|
|
611
|
+
sourcePath
|
|
612
|
+
);
|
|
613
|
+
continue;
|
|
614
|
+
}
|
|
615
|
+
const source = identity ? { type: "resource", resource: identity } : transientFor(artifact.path, [{ slot: "share-entry", sourcePath, hash: entryHash }], containerHash);
|
|
616
|
+
const entryIdentity = identity ? "id" in identity ? { id: identity.id } : { key: identity.key } : { transient: source.token };
|
|
617
|
+
const document = { ...semanticEntry, kind: "share", owner: wireOwner };
|
|
618
|
+
addWireDocument(
|
|
619
|
+
document,
|
|
620
|
+
source,
|
|
621
|
+
{ file: artifact.path, slot: "share-entry", identity: entryIdentity },
|
|
622
|
+
sourcePath,
|
|
623
|
+
entryHash,
|
|
624
|
+
{ containerHash, groupOwner: owner, ownerDocument, externalOwnerLocation, wireOwner }
|
|
625
|
+
);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
for (const matches of owners.values()) {
|
|
629
|
+
if (matches.length > 1)
|
|
630
|
+
for (const match of matches)
|
|
631
|
+
diagnostic(
|
|
632
|
+
"duplicate-owner-identity",
|
|
633
|
+
match.path,
|
|
634
|
+
"More than one local artifact has this owner identity"
|
|
635
|
+
);
|
|
636
|
+
}
|
|
637
|
+
for (const owner of [...owners.values()].flat()) {
|
|
638
|
+
if (!owner.pointer) continue;
|
|
639
|
+
const group = groups.get(owner.selector ? (0, import_layoutCore.ownerKey)(owner.selector) : "");
|
|
640
|
+
const trackedMissingGroup = !group && owner.selector !== void 0 && priorProvesGroup(owner.pointer, owner.selector);
|
|
641
|
+
if (!group && !trackedMissingGroup || group && group.path !== owner.pointer)
|
|
642
|
+
diagnostic(
|
|
643
|
+
"mismatched-share-pointer",
|
|
644
|
+
owner.path,
|
|
645
|
+
"The owner pointer and share group selector do not agree",
|
|
646
|
+
owner.locationPath ? [...owner.locationPath, "shares"] : ["shares"],
|
|
647
|
+
owner.pointer
|
|
648
|
+
);
|
|
649
|
+
}
|
|
650
|
+
for (const group of groups.values()) {
|
|
651
|
+
if ("dangling" in group.owner) continue;
|
|
652
|
+
const matches = owners.get((0, import_layoutCore.ownerKey)(group.owner)) ?? [];
|
|
653
|
+
const owner = matches[0];
|
|
654
|
+
const trackedMissingNavigation = matches.length === 1 && owner.pointer === void 0 && priorProvesNavigation(owner, group.path);
|
|
655
|
+
if (matches.length === 1 && owner.pointer !== group.path && !trackedMissingNavigation)
|
|
656
|
+
diagnostic(
|
|
657
|
+
"unlinked-owner-group",
|
|
658
|
+
group.path,
|
|
659
|
+
"The local owner does not point to this share group",
|
|
660
|
+
["owner"],
|
|
661
|
+
owner.path
|
|
662
|
+
);
|
|
663
|
+
}
|
|
664
|
+
const observations = [];
|
|
665
|
+
const matchedPrior = /* @__PURE__ */ new Set();
|
|
666
|
+
for (const fragment of fragments) {
|
|
667
|
+
const candidates = fragment.source.type === "transient" ? [] : priorRoutesOf(fragment.source).filter(
|
|
668
|
+
({ route }) => route.source.type !== "transient" && selectorSlot(route.selector) === selectorSlot(fragment.selector)
|
|
669
|
+
);
|
|
670
|
+
const prior = candidates.length === 1 ? candidates[0] : void 0;
|
|
671
|
+
if (candidates.length > 1)
|
|
672
|
+
diagnostic("ambiguous-fragment-route", fragment.selector.file, "Multiple prior routes match this fragment");
|
|
673
|
+
if (prior) matchedPrior.add(prior.index);
|
|
674
|
+
observations.push({
|
|
675
|
+
source: fragment.source,
|
|
676
|
+
selector: fragment.selector,
|
|
677
|
+
sourcePath: fragment.sourcePath,
|
|
678
|
+
currentHash: fragment.hash,
|
|
679
|
+
...prior ? { priorCleanHash: prior.route.priorCleanHash } : {},
|
|
680
|
+
...fragment.derivedSelectorHash ? { derivedSelectorHash: fragment.derivedSelectorHash } : {},
|
|
681
|
+
state: prior ? prior.route.priorCleanHash === fragment.hash ? "clean" : "dirty" : "new",
|
|
682
|
+
contributor: fragment.contributor
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
priorRoutes.forEach((route, index) => {
|
|
686
|
+
if (matchedPrior.has(index)) return;
|
|
687
|
+
observations.push({
|
|
688
|
+
source: route.source,
|
|
689
|
+
selector: route.selector,
|
|
690
|
+
sourcePath: route.sourcePath,
|
|
691
|
+
priorCleanHash: route.priorCleanHash,
|
|
692
|
+
...route.derivedSelectorHash ? { derivedSelectorHash: route.derivedSelectorHash } : {},
|
|
693
|
+
state: unclassifiedFiles.has(route.selector.file) || unprovenDerivedArtifacts > 0 && route.source.type === "resource" && route.source.resource.kind === "user_permissions" ? "present-unclassified" : "absent",
|
|
694
|
+
contributor: route.contributor
|
|
695
|
+
});
|
|
696
|
+
});
|
|
697
|
+
const submissions = fragments.flatMap(
|
|
698
|
+
(fragment) => fragment.source.type === "transient" && fragment.containerHash ? [
|
|
699
|
+
{
|
|
700
|
+
source: fragment.source,
|
|
701
|
+
selector: fragment.selector,
|
|
702
|
+
sourcePath: fragment.sourcePath,
|
|
703
|
+
fragmentHash: fragment.hash,
|
|
704
|
+
containerHash: fragment.containerHash
|
|
705
|
+
}
|
|
706
|
+
] : []
|
|
707
|
+
);
|
|
708
|
+
return { documents, sources, observations, submissions, navigation, diagnostics };
|
|
709
|
+
}
|
|
710
|
+
function currentGroupedIndex(current, artifacts) {
|
|
711
|
+
const observed = current.observations.filter((observation) => observation.currentHash !== void 0);
|
|
712
|
+
return {
|
|
713
|
+
observedBySource: (0, import_layoutCore.groupBySource)(observed, (observation) => (0, import_layoutCore.sourceIdentityKey)(observation.source)),
|
|
714
|
+
observedByFile: (0, import_layoutCore.groupBySource)(observed, (observation) => observation.selector.file),
|
|
715
|
+
artifactPaths: new Set(artifacts.map((artifact) => artifact.path))
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
function currentHash(index, selector) {
|
|
719
|
+
const matches = (index.observedByFile.get(selector.file) ?? []).filter(
|
|
720
|
+
(observation) => sameSelectorLocation(observation.selector, selector)
|
|
721
|
+
);
|
|
722
|
+
return matches.length === 1 ? matches[0].currentHash : void 0;
|
|
723
|
+
}
|
|
724
|
+
function decomposeGroupedLayout(input) {
|
|
725
|
+
const current = input.current;
|
|
726
|
+
const index = currentGroupedIndex(current, input.currentArtifacts);
|
|
727
|
+
const diagnostics = [...current.diagnostics];
|
|
728
|
+
const patches = [];
|
|
729
|
+
const usedDocuments = /* @__PURE__ */ new Set();
|
|
730
|
+
const patchedSelectors = /* @__PURE__ */ new Set();
|
|
731
|
+
const groupOwners = /* @__PURE__ */ new Map();
|
|
732
|
+
const vacating = new Set((input.vacating ?? []).map(import_layoutCore.sourceIdentityKey));
|
|
733
|
+
const diagnostic = (code, path, message) => diagnostics.push({ code, path, message });
|
|
734
|
+
const vacatedFile = (file) => {
|
|
735
|
+
const occupants = index.observedByFile.get(file) ?? [];
|
|
736
|
+
return occupants.length > 0 && occupants.every((observation) => vacating.has((0, import_layoutCore.sourceIdentityKey)(observation.source)));
|
|
737
|
+
};
|
|
738
|
+
const patchKey = (selector, source) => `${selector.file}/${selector.slot}/${selector.slot === "share-entry" ? JSON.stringify(selector.identity) : ""}/${(0, import_layoutCore.sourceIdentityKey)(source)}`;
|
|
739
|
+
const pushPatch = (patch) => {
|
|
740
|
+
const key = patchKey(patch.selector, patch.source);
|
|
741
|
+
if (patchedSelectors.has(key)) {
|
|
742
|
+
diagnostic(
|
|
743
|
+
"duplicate-patch-target",
|
|
744
|
+
patch.selector.file,
|
|
745
|
+
`More than one patch targets ${patch.selector.slot}`
|
|
746
|
+
);
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
749
|
+
patchedSelectors.add(key);
|
|
750
|
+
const expected = currentHash(index, patch.selector);
|
|
751
|
+
patches.push({ ...patch, ...expected ? { expectedCurrentHash: expected } : {} });
|
|
752
|
+
};
|
|
753
|
+
const transientMatchesCurrent = (mapping) => {
|
|
754
|
+
const source = mapping.source;
|
|
755
|
+
if (source.type !== "transient") return false;
|
|
756
|
+
const proofs = (input.submissionProofs ?? []).filter(
|
|
757
|
+
(proof2) => proof2.source.token === source.token && sameSelectorLocation(proof2.selector, mapping.selector) && JSON.stringify(proof2.sourcePath) === JSON.stringify(mapping.sourcePath)
|
|
758
|
+
);
|
|
759
|
+
if (proofs.length !== 1) return false;
|
|
760
|
+
const proof = proofs[0];
|
|
761
|
+
const match = (0, import_layoutCore.matchExactSubmissionProof)(
|
|
762
|
+
[
|
|
763
|
+
{
|
|
764
|
+
token: proof.source.token,
|
|
765
|
+
scopeKey: "mapping",
|
|
766
|
+
sourcePath: proof.sourcePath,
|
|
767
|
+
evidenceHash: submissionEvidenceHash(proof.fragmentHash, proof.containerHash)
|
|
768
|
+
}
|
|
769
|
+
],
|
|
770
|
+
current.submissions.filter(
|
|
771
|
+
(candidate) => candidate.source.token === proof.source.token && sameSelectorLocation(candidate.selector, proof.selector)
|
|
772
|
+
).map((candidate) => ({
|
|
773
|
+
scopeKey: "mapping",
|
|
774
|
+
sourcePath: candidate.sourcePath,
|
|
775
|
+
evidenceHash: submissionEvidenceHash(candidate.fragmentHash, candidate.containerHash)
|
|
776
|
+
}))
|
|
777
|
+
);
|
|
778
|
+
return match.status === "matched" && match.token === source.token && match.exactMatchCount === 1;
|
|
779
|
+
};
|
|
780
|
+
const currentGroupMatches = (mapping) => {
|
|
781
|
+
const expectedOwner = mapping.groupOwner;
|
|
782
|
+
return expectedOwner !== void 0 && (index.observedByFile.get(mapping.selector.file) ?? []).some(
|
|
783
|
+
(observation) => observation.selector.slot === "share-group-owner" && observation.source.type === "group" && (0, import_layoutCore.ownerKey)(observation.source.owner) === (0, import_layoutCore.ownerKey)(expectedOwner)
|
|
784
|
+
);
|
|
785
|
+
};
|
|
786
|
+
const currentStableDerivedMatch = (mapping) => {
|
|
787
|
+
const source = mapping.source;
|
|
788
|
+
if (source.type !== "resource" || source.resource.kind !== "user_permissions" || !("id" in source.resource))
|
|
789
|
+
return void 0;
|
|
790
|
+
const matches = (index.observedBySource.get((0, import_layoutCore.sourceIdentityKey)(source)) ?? []).filter(
|
|
791
|
+
(observation) => observation.selector.slot === "document"
|
|
792
|
+
);
|
|
793
|
+
return matches.length === 1 ? matches[0] : void 0;
|
|
794
|
+
};
|
|
795
|
+
const currentPromotedDerivedMatch = (mapping) => {
|
|
796
|
+
if (mapping.derivedSelectorHash === void 0) return void 0;
|
|
797
|
+
const key = input.documentKeys[mapping.documentIndex];
|
|
798
|
+
const separator = key?.indexOf("/") ?? -1;
|
|
799
|
+
if (separator < 0 || key?.slice(0, separator) !== "user_permissions") return void 0;
|
|
800
|
+
const id = key.slice(separator + 1);
|
|
801
|
+
if (!import_layoutCore.RESOURCE_ID.test(id)) return void 0;
|
|
802
|
+
const source = { type: "resource", resource: { kind: "user_permissions", id } };
|
|
803
|
+
const matches = (index.observedBySource.get((0, import_layoutCore.sourceIdentityKey)(source)) ?? []).filter(
|
|
804
|
+
(observation) => observation.selector.slot === "document" && observation.derivedSelectorHash === mapping.derivedSelectorHash
|
|
805
|
+
);
|
|
806
|
+
return matches.length === 1 ? matches[0] : void 0;
|
|
807
|
+
};
|
|
808
|
+
const sourceMatchesCurrent = (mapping) => {
|
|
809
|
+
if (mapping.source.type === "transient")
|
|
810
|
+
return transientMatchesCurrent(mapping) || currentPromotedDerivedMatch(mapping) !== void 0;
|
|
811
|
+
if (mapping.source.type === "resource" && mapping.source.resource.kind === "user_permissions" && "id" in mapping.source.resource) {
|
|
812
|
+
if (currentStableDerivedMatch(mapping)) return true;
|
|
813
|
+
if ([...index.observedBySource.values()].some(
|
|
814
|
+
(observations) => observations.some(
|
|
815
|
+
(observation) => observation.selector.slot === "document" && observation.derivedSelectorHash !== void 0 && observation.source.type === "transient"
|
|
816
|
+
)
|
|
817
|
+
))
|
|
818
|
+
return false;
|
|
819
|
+
return !index.artifactPaths.has(mapping.selector.file);
|
|
820
|
+
}
|
|
821
|
+
if (!index.artifactPaths.has(mapping.selector.file) || vacatedFile(mapping.selector.file)) return true;
|
|
822
|
+
const observed = index.observedBySource.get((0, import_layoutCore.sourceIdentityKey)(mapping.source)) ?? [];
|
|
823
|
+
const matchingLocation = observed.some(
|
|
824
|
+
(observation) => sameSelectorLocation(observation.selector, mapping.selector)
|
|
825
|
+
);
|
|
826
|
+
if (mapping.selector.slot !== "share-entry") return matchingLocation;
|
|
827
|
+
if (!currentGroupMatches(mapping)) return false;
|
|
828
|
+
if (matchingLocation) return true;
|
|
829
|
+
const conflictingLocation = observed.some((observation) => observation.selector.slot === "share-entry");
|
|
830
|
+
return !conflictingLocation && mapping.source.type === "resource" && mapping.source.resource.kind === "share" && "id" in mapping.source.resource;
|
|
831
|
+
};
|
|
832
|
+
const sourceMatchesDocument = (mapping, document) => {
|
|
833
|
+
const key = input.documentKeys[mapping.documentIndex];
|
|
834
|
+
if (!key) return false;
|
|
835
|
+
const separator = key.indexOf("/");
|
|
836
|
+
if (separator <= 0 || separator === key.length - 1) return false;
|
|
837
|
+
const kind = key.slice(0, separator);
|
|
838
|
+
const id = key.slice(separator + 1);
|
|
839
|
+
if (kind !== document.kind) return false;
|
|
840
|
+
if (mapping.source.type === "resource") {
|
|
841
|
+
if (mapping.source.resource.kind !== kind) return false;
|
|
842
|
+
if ("id" in mapping.source.resource && mapping.source.resource.id !== id) return false;
|
|
843
|
+
}
|
|
844
|
+
if (typeof document.id === "string" && import_layoutCore.RESOURCE_ID.test(document.id) && document.id !== id) return false;
|
|
845
|
+
if (document.kind === "user_permissions" && (mapping.derivedSelectorHash === void 0 || derivedSourceSelectorHash(document) !== mapping.derivedSelectorHash))
|
|
846
|
+
return false;
|
|
847
|
+
if (document.kind === "dimension_members") {
|
|
848
|
+
const selector = (0, import_layoutCore.object)(document.table);
|
|
849
|
+
if (selector && (Object.keys(selector).length !== 1 || selector.id !== id && selector.dangling !== id))
|
|
850
|
+
return false;
|
|
851
|
+
}
|
|
852
|
+
return true;
|
|
853
|
+
};
|
|
854
|
+
const assignedKeys = /* @__PURE__ */ new Map();
|
|
855
|
+
for (const mapping of input.sources) {
|
|
856
|
+
const document = input.documents[mapping.documentIndex];
|
|
857
|
+
const documentKey = input.documentKeys[mapping.documentIndex];
|
|
858
|
+
const separator = documentKey?.indexOf("/") ?? -1;
|
|
859
|
+
const assignedId = separator < 0 ? void 0 : documentKey.slice(separator + 1);
|
|
860
|
+
if (mapping.source.type !== "resource" || !("key" in mapping.source.resource) || !document || document.kind !== mapping.source.resource.kind || documentKey?.slice(0, separator) !== document.kind || assignedId === void 0 || !import_layoutCore.RESOURCE_ID.test(assignedId))
|
|
861
|
+
continue;
|
|
862
|
+
const key = (0, import_layoutCore.sourceIdentityKey)(mapping.source);
|
|
863
|
+
const prior = assignedKeys.get(key);
|
|
864
|
+
if (prior !== void 0 && prior !== assignedId)
|
|
865
|
+
diagnostic("ambiguous-key-assignment", mapping.selector.file, "A local key has conflicting assigned IDs");
|
|
866
|
+
else assignedKeys.set(key, assignedId);
|
|
867
|
+
}
|
|
868
|
+
for (const mapping of input.sources) {
|
|
869
|
+
const document = input.documents[mapping.documentIndex];
|
|
870
|
+
if (!document) throw new Error(`Source mapping ${mapping.documentIndex} has no wire document`);
|
|
871
|
+
if (!input.documentKeys[mapping.documentIndex])
|
|
872
|
+
throw new Error(`Source mapping ${mapping.documentIndex} has no wire document key`);
|
|
873
|
+
if (usedDocuments.has(mapping.documentIndex))
|
|
874
|
+
throw new Error(`Wire document ${mapping.documentIndex} has more than one source mapping`);
|
|
875
|
+
usedDocuments.add(mapping.documentIndex);
|
|
876
|
+
if (!sourceMatchesCurrent(mapping) || !sourceMatchesDocument(mapping, document)) {
|
|
877
|
+
diagnostic(
|
|
878
|
+
"stale-wire-source",
|
|
879
|
+
mapping.selector.file,
|
|
880
|
+
"The wire document does not match its current source identity"
|
|
881
|
+
);
|
|
882
|
+
continue;
|
|
883
|
+
}
|
|
884
|
+
if (mapping.selector.slot === "table-definition") {
|
|
885
|
+
if (document.kind !== "dimension_table") {
|
|
886
|
+
diagnostic("wire-kind-mismatch", mapping.selector.file, "A table patch requires dimension_table");
|
|
887
|
+
continue;
|
|
888
|
+
}
|
|
889
|
+
const value = mapping.source.type === "resource" && "key" in mapping.source.resource && !assignedKeys.has((0, import_layoutCore.sourceIdentityKey)(mapping.source)) ? { ...document, key: mapping.source.resource.key } : document;
|
|
890
|
+
pushPatch({ source: mapping.source, selector: mapping.selector, action: "set", value });
|
|
891
|
+
} else if (mapping.selector.slot === "member-set") {
|
|
892
|
+
if (document.kind !== "dimension_members" || !Array.isArray(document.members)) {
|
|
893
|
+
diagnostic("wire-kind-mismatch", mapping.selector.file, "A member patch requires dimension_members");
|
|
894
|
+
continue;
|
|
895
|
+
}
|
|
896
|
+
pushPatch({
|
|
897
|
+
source: mapping.source,
|
|
898
|
+
selector: mapping.selector,
|
|
899
|
+
action: "set",
|
|
900
|
+
value: document.members
|
|
901
|
+
});
|
|
902
|
+
} else if (mapping.selector.slot === "document") {
|
|
903
|
+
if (document.kind === "dimension_members" || document.kind === "share") {
|
|
904
|
+
diagnostic(
|
|
905
|
+
"wire-kind-mismatch",
|
|
906
|
+
mapping.selector.file,
|
|
907
|
+
"This wire document requires a grouped selector"
|
|
908
|
+
);
|
|
909
|
+
continue;
|
|
910
|
+
}
|
|
911
|
+
const value = mapping.source.type === "resource" && "key" in mapping.source.resource && !assignedKeys.has((0, import_layoutCore.sourceIdentityKey)(mapping.source)) ? { ...document, key: mapping.source.resource.key } : document;
|
|
912
|
+
const derivedMatch = currentStableDerivedMatch(mapping) ?? currentPromotedDerivedMatch(mapping);
|
|
913
|
+
pushPatch({
|
|
914
|
+
source: derivedMatch?.source ?? mapping.source,
|
|
915
|
+
selector: derivedMatch?.selector ?? mapping.selector,
|
|
916
|
+
action: "set",
|
|
917
|
+
value
|
|
918
|
+
});
|
|
919
|
+
} else if (mapping.selector.slot === "share-entry") {
|
|
920
|
+
if (document.kind !== "share" || !mapping.groupOwner) {
|
|
921
|
+
diagnostic("wire-kind-mismatch", mapping.selector.file, "A share entry patch requires a group owner");
|
|
922
|
+
continue;
|
|
923
|
+
}
|
|
924
|
+
const assignedOwner = "key" in mapping.groupOwner ? assignedKeys.get(
|
|
925
|
+
(0, import_layoutCore.sourceIdentityKey)({
|
|
926
|
+
type: "resource",
|
|
927
|
+
resource: { kind: mapping.groupOwner.kind, key: mapping.groupOwner.key }
|
|
928
|
+
})
|
|
929
|
+
) : void 0;
|
|
930
|
+
const resolvedOwner = assignedOwner ? { kind: mapping.groupOwner.kind, id: assignedOwner } : mapping.groupOwner;
|
|
931
|
+
const expectedOwner = assignedOwner ? resolvedOwner : mapping.wireOwner ?? ("key" in mapping.groupOwner ? void 0 : mapping.groupOwner);
|
|
932
|
+
const documentOwner = (0, import_layoutCore.object)(document.owner);
|
|
933
|
+
if (!expectedOwner || !documentOwner || (0, import_documents.canonicalText)(documentOwner) !== (0, import_documents.canonicalText)(expectedOwner)) {
|
|
934
|
+
diagnostic(
|
|
935
|
+
"group-owner-mismatch",
|
|
936
|
+
mapping.selector.file,
|
|
937
|
+
"The share document owner does not match its group header"
|
|
938
|
+
);
|
|
939
|
+
continue;
|
|
940
|
+
}
|
|
941
|
+
const groupKey = `${mapping.selector.file}/share-group-owner`;
|
|
942
|
+
const priorOwner = groupOwners.get(groupKey);
|
|
943
|
+
if (priorOwner && (0, import_layoutCore.ownerKey)(priorOwner) !== (0, import_layoutCore.ownerKey)(resolvedOwner)) {
|
|
944
|
+
diagnostic(
|
|
945
|
+
"group-owner-mismatch",
|
|
946
|
+
mapping.selector.file,
|
|
947
|
+
"Share documents disagree on their group owner"
|
|
948
|
+
);
|
|
949
|
+
continue;
|
|
950
|
+
}
|
|
951
|
+
if (!priorOwner) {
|
|
952
|
+
groupOwners.set(groupKey, resolvedOwner);
|
|
953
|
+
const headerSelector = { file: mapping.selector.file, slot: "share-group-owner" };
|
|
954
|
+
const headerSource = (index.observedByFile.get(headerSelector.file) ?? []).find(
|
|
955
|
+
(observation) => observation.selector.slot === headerSelector.slot
|
|
956
|
+
)?.source;
|
|
957
|
+
pushPatch({
|
|
958
|
+
source: headerSource ?? mapping.source,
|
|
959
|
+
selector: headerSelector,
|
|
960
|
+
action: "set",
|
|
961
|
+
value: resolvedOwner
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
const entry = (0, import_layoutCore.without)(document, ["kind", "owner"]);
|
|
965
|
+
if ("key" in mapping.selector.identity && !assignedKeys.has((0, import_layoutCore.sourceIdentityKey)(mapping.source)))
|
|
966
|
+
entry.key = mapping.selector.identity.key;
|
|
967
|
+
pushPatch({
|
|
968
|
+
source: mapping.source,
|
|
969
|
+
selector: mapping.selector,
|
|
970
|
+
action: "set",
|
|
971
|
+
value: entry
|
|
972
|
+
});
|
|
973
|
+
} else throw new Error(`Slot ${mapping.selector.slot} is not a wire document selector`);
|
|
974
|
+
}
|
|
975
|
+
input.documents.forEach((_document, index2) => {
|
|
976
|
+
if (!usedDocuments.has(index2)) throw new Error(`Wire document ${index2} has no source mapping`);
|
|
977
|
+
});
|
|
978
|
+
for (const route of input.navigation ?? [])
|
|
979
|
+
pushPatch({
|
|
980
|
+
source: route.source,
|
|
981
|
+
selector: route.selector,
|
|
982
|
+
action: "set",
|
|
983
|
+
value: { file: route.groupFile }
|
|
984
|
+
});
|
|
985
|
+
for (const removal of input.removals ?? [])
|
|
986
|
+
pushPatch({ source: removal.source, selector: removal.selector, action: "remove" });
|
|
987
|
+
return { patches, diagnostics };
|
|
988
|
+
}
|
|
989
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
990
|
+
0 && (module.exports = {
|
|
991
|
+
composeGroupedLayout,
|
|
992
|
+
decomposeGroupedLayout,
|
|
993
|
+
derivedSourceSelectorHash
|
|
994
|
+
});
|
|
995
|
+
//# sourceMappingURL=layoutProjection.js.map
|