@milaboratories/pl-model-middle-layer 1.32.2 → 1.34.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/dist/folders/commit.cjs +79 -0
- package/dist/folders/commit.cjs.map +1 -0
- package/dist/folders/commit.d.ts +82 -0
- package/dist/folders/commit.d.ts.map +1 -0
- package/dist/folders/commit.js +78 -0
- package/dist/folders/commit.js.map +1 -0
- package/dist/folders/decode.cjs +79 -0
- package/dist/folders/decode.cjs.map +1 -0
- package/dist/folders/decode.d.ts +57 -0
- package/dist/folders/decode.d.ts.map +1 -0
- package/dist/folders/decode.js +77 -0
- package/dist/folders/decode.js.map +1 -0
- package/dist/folders/document.cjs +49 -0
- package/dist/folders/document.cjs.map +1 -0
- package/dist/folders/document.d.ts +56 -0
- package/dist/folders/document.d.ts.map +1 -0
- package/dist/folders/document.js +45 -0
- package/dist/folders/document.js.map +1 -0
- package/dist/folders/index.cjs +37 -0
- package/dist/folders/index.d.ts +10 -0
- package/dist/folders/index.js +10 -0
- package/dist/folders/inheritance.cjs +23 -0
- package/dist/folders/inheritance.cjs.map +1 -0
- package/dist/folders/inheritance.d.ts +19 -0
- package/dist/folders/inheritance.d.ts.map +1 -0
- package/dist/folders/inheritance.js +23 -0
- package/dist/folders/inheritance.js.map +1 -0
- package/dist/folders/invariants.cjs +115 -0
- package/dist/folders/invariants.cjs.map +1 -0
- package/dist/folders/invariants.d.ts +50 -0
- package/dist/folders/invariants.d.ts.map +1 -0
- package/dist/folders/invariants.js +114 -0
- package/dist/folders/invariants.js.map +1 -0
- package/dist/folders/naming.cjs +54 -0
- package/dist/folders/naming.cjs.map +1 -0
- package/dist/folders/naming.d.ts +32 -0
- package/dist/folders/naming.d.ts.map +1 -0
- package/dist/folders/naming.js +52 -0
- package/dist/folders/naming.js.map +1 -0
- package/dist/folders/planner.cjs +192 -0
- package/dist/folders/planner.cjs.map +1 -0
- package/dist/folders/planner.d.ts +100 -0
- package/dist/folders/planner.d.ts.map +1 -0
- package/dist/folders/planner.js +190 -0
- package/dist/folders/planner.js.map +1 -0
- package/dist/folders/removal.cjs +47 -0
- package/dist/folders/removal.cjs.map +1 -0
- package/dist/folders/removal.d.ts +42 -0
- package/dist/folders/removal.d.ts.map +1 -0
- package/dist/folders/removal.js +45 -0
- package/dist/folders/removal.js.map +1 -0
- package/dist/folders/view.cjs +212 -0
- package/dist/folders/view.cjs.map +1 -0
- package/dist/folders/view.d.ts +98 -0
- package/dist/folders/view.d.ts.map +1 -0
- package/dist/folders/view.js +207 -0
- package/dist/folders/view.js.map +1 -0
- package/dist/index.cjs +43 -2
- package/dist/index.d.ts +12 -2
- package/dist/index.js +12 -1
- package/dist/project.cjs +23 -0
- package/dist/project.cjs.map +1 -0
- package/dist/project.d.ts +13 -0
- package/dist/project.d.ts.map +1 -1
- package/dist/project.js +22 -0
- package/dist/project.js.map +1 -0
- package/package.json +6 -3
- package/src/folders/commit.ts +133 -0
- package/src/folders/decode.test.ts +128 -0
- package/src/folders/decode.ts +142 -0
- package/src/folders/document.ts +96 -0
- package/src/folders/index.ts +9 -0
- package/src/folders/inheritance.test.ts +91 -0
- package/src/folders/inheritance.ts +33 -0
- package/src/folders/invariants.test.ts +166 -0
- package/src/folders/invariants.ts +159 -0
- package/src/folders/naming.test.ts +62 -0
- package/src/folders/naming.ts +59 -0
- package/src/folders/planner.test.ts +450 -0
- package/src/folders/planner.ts +279 -0
- package/src/folders/removal.test.ts +142 -0
- package/src/folders/removal.ts +77 -0
- package/src/folders/test_utils.ts +86 -0
- package/src/folders/view.test.ts +433 -0
- package/src/folders/view.ts +334 -0
- package/src/index.ts +1 -0
- package/src/project.ts +21 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//#region src/folders/naming.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The one naming rule for folders, projects and templates.
|
|
4
|
+
*
|
|
5
|
+
* Scope is always the children of one parent — a folder, or the top level, which is simply the
|
|
6
|
+
* folder with no parent — and one kind of item. No two folders, no two projects and no two
|
|
7
|
+
* templates inside the same parent can carry the same name, while a folder, a project and a
|
|
8
|
+
* template beside each other may: the list shows each kind under its own heading, so they are
|
|
9
|
+
* never mistaken for one another. Comparison ignores case and surrounding whitespace: `Samples`,
|
|
10
|
+
* `samples` and ` Samples ` are the same thing to the person looking at them.
|
|
11
|
+
*
|
|
12
|
+
* The rule auto-renames only where a machine chose the name — a move and a duplicate. Where a
|
|
13
|
+
* human typed the name, a caller uses {@link foldersNameTaken} and rejects the name with
|
|
14
|
+
* an error instead: a text field that quietly disagrees with what was typed is worse than one
|
|
15
|
+
* that says no.
|
|
16
|
+
*
|
|
17
|
+
* Names already stored are never rewritten. Accounts predating folders may hold collisions,
|
|
18
|
+
* because nothing enforced uniqueness before.
|
|
19
|
+
*/
|
|
20
|
+
/** True when a sibling already carries this name, compared as the rule above compares names. */
|
|
21
|
+
export declare function foldersNameTaken(name: string, siblingNames: Iterable<string>): boolean;
|
|
22
|
+
/** True when a name has nothing in it but whitespace; a folder cannot be called that. */
|
|
23
|
+
export declare function foldersNameBlank(name: string): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* The name to use for an item landing beside `siblingNames`.
|
|
26
|
+
*
|
|
27
|
+
* A free name is returned untouched. A taken one gains an `X (Copy)`, `X (Copy 2)` … suffix, and
|
|
28
|
+
* an existing copy suffix is replaced rather than stacked, so repeated copies stay readable.
|
|
29
|
+
*/
|
|
30
|
+
export declare function foldersUniqueName(desiredName: string, siblingNames: Iterable<string>): string;
|
|
31
|
+
//#endregion
|
|
32
|
+
//# sourceMappingURL=naming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"naming.d.ts","names":[],"sources":["../../src/folders/naming.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;wBAoBgB,iBAAiB,cAAc,cAAc;;wBAO7C,iBAAiB;;;;;;;wBAUjB,kBAAkB,qBAAqB,cAAc"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//#region src/folders/naming.ts
|
|
2
|
+
/**
|
|
3
|
+
* The one naming rule for folders, projects and templates.
|
|
4
|
+
*
|
|
5
|
+
* Scope is always the children of one parent — a folder, or the top level, which is simply the
|
|
6
|
+
* folder with no parent — and one kind of item. No two folders, no two projects and no two
|
|
7
|
+
* templates inside the same parent can carry the same name, while a folder, a project and a
|
|
8
|
+
* template beside each other may: the list shows each kind under its own heading, so they are
|
|
9
|
+
* never mistaken for one another. Comparison ignores case and surrounding whitespace: `Samples`,
|
|
10
|
+
* `samples` and ` Samples ` are the same thing to the person looking at them.
|
|
11
|
+
*
|
|
12
|
+
* The rule auto-renames only where a machine chose the name — a move and a duplicate. Where a
|
|
13
|
+
* human typed the name, a caller uses {@link foldersNameTaken} and rejects the name with
|
|
14
|
+
* an error instead: a text field that quietly disagrees with what was typed is worse than one
|
|
15
|
+
* that says no.
|
|
16
|
+
*
|
|
17
|
+
* Names already stored are never rewritten. Accounts predating folders may hold collisions,
|
|
18
|
+
* because nothing enforced uniqueness before.
|
|
19
|
+
*/
|
|
20
|
+
/** True when a sibling already carries this name, compared as the rule above compares names. */
|
|
21
|
+
function foldersNameTaken(name, siblingNames) {
|
|
22
|
+
const wanted = normalizeName(name);
|
|
23
|
+
for (const sibling of siblingNames) if (normalizeName(sibling) === wanted) return true;
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
/** True when a name has nothing in it but whitespace; a folder cannot be called that. */
|
|
27
|
+
function foldersNameBlank(name) {
|
|
28
|
+
return name.trim() === "";
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The name to use for an item landing beside `siblingNames`.
|
|
32
|
+
*
|
|
33
|
+
* A free name is returned untouched. A taken one gains an `X (Copy)`, `X (Copy 2)` … suffix, and
|
|
34
|
+
* an existing copy suffix is replaced rather than stacked, so repeated copies stay readable.
|
|
35
|
+
*/
|
|
36
|
+
function foldersUniqueName(desiredName, siblingNames) {
|
|
37
|
+
const taken = /* @__PURE__ */ new Set();
|
|
38
|
+
for (const sibling of siblingNames) taken.add(normalizeName(sibling));
|
|
39
|
+
if (!taken.has(normalizeName(desiredName))) return desiredName;
|
|
40
|
+
const base = desiredName.replace(COPY_SUFFIX, "");
|
|
41
|
+
let candidate = `${base} (Copy)`;
|
|
42
|
+
for (let index = 2; taken.has(normalizeName(candidate)); index++) candidate = `${base} (Copy ${index})`;
|
|
43
|
+
return candidate;
|
|
44
|
+
}
|
|
45
|
+
const COPY_SUFFIX = / \(Copy(?: \d+)?\)$/;
|
|
46
|
+
function normalizeName(name) {
|
|
47
|
+
return name.trim().toLowerCase();
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { foldersNameBlank, foldersNameTaken, foldersUniqueName };
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=naming.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"naming.js","names":[],"sources":["../../src/folders/naming.ts"],"sourcesContent":["/**\n * The one naming rule for folders, projects and templates.\n *\n * Scope is always the children of one parent — a folder, or the top level, which is simply the\n * folder with no parent — and one kind of item. No two folders, no two projects and no two\n * templates inside the same parent can carry the same name, while a folder, a project and a\n * template beside each other may: the list shows each kind under its own heading, so they are\n * never mistaken for one another. Comparison ignores case and surrounding whitespace: `Samples`,\n * `samples` and ` Samples ` are the same thing to the person looking at them.\n *\n * The rule auto-renames only where a machine chose the name — a move and a duplicate. Where a\n * human typed the name, a caller uses {@link foldersNameTaken} and rejects the name with\n * an error instead: a text field that quietly disagrees with what was typed is worse than one\n * that says no.\n *\n * Names already stored are never rewritten. Accounts predating folders may hold collisions,\n * because nothing enforced uniqueness before.\n */\n\n/** True when a sibling already carries this name, compared as the rule above compares names. */\nexport function foldersNameTaken(name: string, siblingNames: Iterable<string>): boolean {\n const wanted = normalizeName(name);\n for (const sibling of siblingNames) if (normalizeName(sibling) === wanted) return true;\n return false;\n}\n\n/** True when a name has nothing in it but whitespace; a folder cannot be called that. */\nexport function foldersNameBlank(name: string): boolean {\n return name.trim() === \"\";\n}\n\n/**\n * The name to use for an item landing beside `siblingNames`.\n *\n * A free name is returned untouched. A taken one gains an `X (Copy)`, `X (Copy 2)` … suffix, and\n * an existing copy suffix is replaced rather than stacked, so repeated copies stay readable.\n */\nexport function foldersUniqueName(desiredName: string, siblingNames: Iterable<string>): string {\n const taken = new Set<string>();\n for (const sibling of siblingNames) taken.add(normalizeName(sibling));\n\n if (!taken.has(normalizeName(desiredName))) return desiredName;\n\n const base = desiredName.replace(COPY_SUFFIX, \"\");\n let candidate = `${base} (Copy)`;\n for (let index = 2; taken.has(normalizeName(candidate)); index++)\n candidate = `${base} (Copy ${index})`;\n return candidate;\n}\n\n//\n// Internals\n//\n\nconst COPY_SUFFIX = / \\(Copy(?: \\d+)?\\)$/;\n\nfunction normalizeName(name: string): string {\n return name.trim().toLowerCase();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,iBAAiB,MAAc,cAAyC;CACtF,MAAM,SAAS,cAAc,IAAI;CACjC,KAAK,MAAM,WAAW,cAAc,IAAI,cAAc,OAAO,MAAM,QAAQ,OAAO;CAClF,OAAO;AACT;;AAGA,SAAgB,iBAAiB,MAAuB;CACtD,OAAO,KAAK,KAAK,MAAM;AACzB;;;;;;;AAQA,SAAgB,kBAAkB,aAAqB,cAAwC;CAC7F,MAAM,wBAAQ,IAAI,IAAY;CAC9B,KAAK,MAAM,WAAW,cAAc,MAAM,IAAI,cAAc,OAAO,CAAC;CAEpE,IAAI,CAAC,MAAM,IAAI,cAAc,WAAW,CAAC,GAAG,OAAO;CAEnD,MAAM,OAAO,YAAY,QAAQ,aAAa,EAAE;CAChD,IAAI,YAAY,GAAG,KAAK;CACxB,KAAK,IAAI,QAAQ,GAAG,MAAM,IAAI,cAAc,SAAS,CAAC,GAAG,SACvD,YAAY,GAAG,KAAK,SAAS,MAAM;CACrC,OAAO;AACT;AAMA,MAAM,cAAc;AAEpB,SAAS,cAAc,MAAsB;CAC3C,OAAO,KAAK,KAAK,CAAC,CAAC,YAAY;AACjC"}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
const require_view = require("./view.cjs");
|
|
2
|
+
const require_naming = require("./naming.cjs");
|
|
3
|
+
//#region src/folders/planner.ts
|
|
4
|
+
/**
|
|
5
|
+
* Plan a move of any mix of folders, projects and templates into one destination.
|
|
6
|
+
*
|
|
7
|
+
* The only function that decides what a moved item ends up called. The preview and the write both
|
|
8
|
+
* call it, over the same view, so the two cannot drift apart.
|
|
9
|
+
*
|
|
10
|
+
* A folder moves with everything inside it. When the selection holds a folder together with
|
|
11
|
+
* something inside it, that item travels with the folder and is not planned on its own: moving it
|
|
12
|
+
* separately as well would pull it out of the subtree it belongs to.
|
|
13
|
+
*/
|
|
14
|
+
function planFoldersMove(view, items, destination) {
|
|
15
|
+
const issues = [];
|
|
16
|
+
const destinationKnown = destination === void 0 || view.folders.some((folder) => folder.id === destination);
|
|
17
|
+
if (destination !== void 0 && !destinationKnown) issues.push({
|
|
18
|
+
kind: "unknown-destination",
|
|
19
|
+
folder: destination
|
|
20
|
+
});
|
|
21
|
+
const located = [];
|
|
22
|
+
const seen = /* @__PURE__ */ new Set();
|
|
23
|
+
for (const item of items) {
|
|
24
|
+
const key = `${item.kind}:${item.id}`;
|
|
25
|
+
if (seen.has(key)) continue;
|
|
26
|
+
seen.add(key);
|
|
27
|
+
const known = locate(view, item);
|
|
28
|
+
if (known === void 0) {
|
|
29
|
+
issues.push({
|
|
30
|
+
kind: "unknown-item",
|
|
31
|
+
item
|
|
32
|
+
});
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
located.push({
|
|
36
|
+
item,
|
|
37
|
+
...known
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const carried = new Set(located.flatMap(({ item }) => item.kind === "folder" ? require_view.foldersSubtree(view, item.id) : []));
|
|
41
|
+
const moved = located.filter(({ sourceFolder }) => sourceFolder === void 0 || !carried.has(sourceFolder));
|
|
42
|
+
if (destination !== void 0 && destinationKnown) for (const { item } of moved) {
|
|
43
|
+
if (item.kind !== "folder") continue;
|
|
44
|
+
if (require_view.foldersSubtree(view, item.id).includes(destination)) issues.push({
|
|
45
|
+
kind: "into-own-descendant",
|
|
46
|
+
folder: item.id,
|
|
47
|
+
destination
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
if (issues.length > 0) return {
|
|
51
|
+
ok: false,
|
|
52
|
+
issues
|
|
53
|
+
};
|
|
54
|
+
const movedIds = moved.map(({ item }) => item.id);
|
|
55
|
+
const taken = {
|
|
56
|
+
folder: require_view.foldersSiblingNames(view, destination, movedIds, { kind: "folder" }),
|
|
57
|
+
project: require_view.foldersSiblingNames(view, destination, movedIds, { kind: "project" }),
|
|
58
|
+
template: require_view.foldersSiblingNames(view, destination, movedIds, { kind: "template" })
|
|
59
|
+
};
|
|
60
|
+
const entries = [];
|
|
61
|
+
for (const { item, name, sourceFolder } of moved.sort(byCanonicalOrder)) {
|
|
62
|
+
const resulting = require_naming.foldersUniqueName(name, taken[item.kind]);
|
|
63
|
+
taken[item.kind].push(resulting);
|
|
64
|
+
entries.push({
|
|
65
|
+
item,
|
|
66
|
+
currentName: name,
|
|
67
|
+
name: resulting,
|
|
68
|
+
renamed: resulting !== name,
|
|
69
|
+
...sourceFolder === void 0 ? {} : { sourceFolder }
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
ok: true,
|
|
74
|
+
plan: {
|
|
75
|
+
...destination === void 0 ? {} : { destination },
|
|
76
|
+
entries
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** True when two plans say exactly the same thing. */
|
|
81
|
+
function foldersMovePlansEqual(a, b) {
|
|
82
|
+
if (a.destination !== b.destination) return false;
|
|
83
|
+
if (a.entries.length !== b.entries.length) return false;
|
|
84
|
+
return a.entries.every((entry, index) => {
|
|
85
|
+
const other = b.entries[index];
|
|
86
|
+
if (other === void 0) return false;
|
|
87
|
+
return entry.item.kind === other.item.kind && entry.item.id === other.item.id && entry.currentName === other.currentName && entry.name === other.name && entry.renamed === other.renamed && entry.sourceFolder === other.sourceFolder;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The document a plan produces, plus the project and template label renames it implies.
|
|
92
|
+
*
|
|
93
|
+
* Applying a plan is arithmetic on an already validated plan; whether that plan may be committed
|
|
94
|
+
* is the write path's decision.
|
|
95
|
+
*/
|
|
96
|
+
function applyFoldersMove(view, movePlan) {
|
|
97
|
+
const folderParents = /* @__PURE__ */ new Map();
|
|
98
|
+
const folderNames = /* @__PURE__ */ new Map();
|
|
99
|
+
const projectFolders = /* @__PURE__ */ new Map();
|
|
100
|
+
const templateFolders = /* @__PURE__ */ new Map();
|
|
101
|
+
const labelRenames = [];
|
|
102
|
+
for (const entry of movePlan.entries) switch (entry.item.kind) {
|
|
103
|
+
case "folder":
|
|
104
|
+
folderParents.set(entry.item.id, movePlan.destination);
|
|
105
|
+
folderNames.set(entry.item.id, entry.name);
|
|
106
|
+
break;
|
|
107
|
+
case "project":
|
|
108
|
+
projectFolders.set(entry.item.id, movePlan.destination);
|
|
109
|
+
if (entry.renamed) labelRenames.push({
|
|
110
|
+
item: entry.item,
|
|
111
|
+
name: entry.name
|
|
112
|
+
});
|
|
113
|
+
break;
|
|
114
|
+
case "template":
|
|
115
|
+
templateFolders.set(entry.item.id, movePlan.destination);
|
|
116
|
+
if (entry.renamed) labelRenames.push({
|
|
117
|
+
item: entry.item,
|
|
118
|
+
name: entry.name
|
|
119
|
+
});
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
const folders = view.folders.map((folder) => ({
|
|
123
|
+
...folder,
|
|
124
|
+
parent: folderParents.has(folder.id) ? folderParents.get(folder.id) : folder.parent,
|
|
125
|
+
name: folderNames.get(folder.id) ?? folder.name
|
|
126
|
+
}));
|
|
127
|
+
const projects = view.projects.map((project) => ({
|
|
128
|
+
...project,
|
|
129
|
+
folder: projectFolders.has(project.id) ? projectFolders.get(project.id) : project.folder
|
|
130
|
+
}));
|
|
131
|
+
const templates = view.templates.map((template) => ({
|
|
132
|
+
...template,
|
|
133
|
+
folder: templateFolders.has(template.id) ? templateFolders.get(template.id) : template.folder
|
|
134
|
+
}));
|
|
135
|
+
return {
|
|
136
|
+
document: require_view.foldersDocumentFromView({
|
|
137
|
+
...view,
|
|
138
|
+
folders,
|
|
139
|
+
projects,
|
|
140
|
+
templates
|
|
141
|
+
}),
|
|
142
|
+
labelRenames
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/** The name and containing folder of an item the view holds, whichever kind it is. */
|
|
146
|
+
function locate(view, item) {
|
|
147
|
+
switch (item.kind) {
|
|
148
|
+
case "folder": {
|
|
149
|
+
const folder = view.folders.find((candidate) => candidate.id === item.id);
|
|
150
|
+
return folder === void 0 ? void 0 : {
|
|
151
|
+
name: folder.name,
|
|
152
|
+
sourceFolder: folder.parent
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
case "project": {
|
|
156
|
+
const project = view.projects.find((candidate) => candidate.id === item.id);
|
|
157
|
+
return project === void 0 ? void 0 : {
|
|
158
|
+
name: project.name,
|
|
159
|
+
sourceFolder: project.folder
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
case "template": {
|
|
163
|
+
const template = view.templates.find((candidate) => candidate.id === item.id);
|
|
164
|
+
return template === void 0 ? void 0 : {
|
|
165
|
+
name: template.name,
|
|
166
|
+
sourceFolder: template.folder
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Folders, then projects, then templates; within a kind by name, then by id. The order of the
|
|
173
|
+
* items a caller hands in must not change the plan, or a preview and its write could differ over
|
|
174
|
+
* nothing.
|
|
175
|
+
*/
|
|
176
|
+
function byCanonicalOrder(a, b) {
|
|
177
|
+
if (a.item.kind !== b.item.kind) return KIND_ORDER[a.item.kind] - KIND_ORDER[b.item.kind];
|
|
178
|
+
const byName = a.name.toLowerCase().localeCompare(b.name.toLowerCase());
|
|
179
|
+
if (byName !== 0) return byName;
|
|
180
|
+
return String(a.item.id).localeCompare(String(b.item.id));
|
|
181
|
+
}
|
|
182
|
+
const KIND_ORDER = {
|
|
183
|
+
folder: 0,
|
|
184
|
+
project: 1,
|
|
185
|
+
template: 2
|
|
186
|
+
};
|
|
187
|
+
//#endregion
|
|
188
|
+
exports.applyFoldersMove = applyFoldersMove;
|
|
189
|
+
exports.foldersMovePlansEqual = foldersMovePlansEqual;
|
|
190
|
+
exports.planFoldersMove = planFoldersMove;
|
|
191
|
+
|
|
192
|
+
//# sourceMappingURL=planner.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner.cjs","names":["foldersSubtree","foldersSiblingNames","foldersUniqueName","foldersDocumentFromView"],"sources":["../../src/folders/planner.ts"],"sourcesContent":["import type { ProjectId, TemplateId } from \"@milaboratories/pl-model-common\";\nimport type { FoldersDocument, FolderId } from \"./document\";\nimport { foldersUniqueName } from \"./naming\";\nimport type { FoldersView } from \"./view\";\nimport { foldersDocumentFromView, foldersSiblingNames, foldersSubtree } from \"./view\";\n\n/** A folder, a project or a stored template, as something a move acts on. */\nexport type FoldersItem =\n | { readonly kind: \"folder\"; readonly id: FolderId }\n | { readonly kind: \"project\"; readonly id: ProjectId }\n | { readonly kind: \"template\"; readonly id: TemplateId };\n\n/** A tree item that is not a folder: a project or a stored template. */\nexport type FoldersLeafItem = Exclude<FoldersItem, { readonly kind: \"folder\" }>;\n\n/** What one item is called after the move, and what it was called before. */\nexport interface FoldersMoveEntry {\n readonly item: FoldersItem;\n readonly currentName: string;\n /** The name the item carries once the plan is applied. */\n readonly name: string;\n /** True when the destination already held that name and the item is being renamed. */\n readonly renamed: boolean;\n /** Folder the item is coming from; absent when it is at the top level. */\n readonly sourceFolder?: FolderId;\n}\n\n/**\n * Every item of a move and its resulting name.\n *\n * A plan is computed for the preview and recomputed inside the write, and the write commits only\n * when the two are identical, so a plan confirmed against state that has since changed is refused\n * rather than applied. Entries are in a canonical order for exactly that comparison.\n */\nexport interface FoldersMovePlan {\n /** Folder everything lands in; absent for the top level. */\n readonly destination?: FolderId;\n readonly entries: readonly FoldersMoveEntry[];\n}\n\n/** One reason a move cannot be planned. */\nexport type FoldersMoveIssue =\n | { readonly kind: \"unknown-destination\"; readonly folder: FolderId }\n | { readonly kind: \"unknown-item\"; readonly item: FoldersItem }\n | {\n readonly kind: \"into-own-descendant\";\n readonly folder: FolderId;\n readonly destination: FolderId;\n };\n\n/** A plan, or everything standing in the way of one. */\nexport type FoldersMovePlanResult =\n | { readonly ok: true; readonly plan: FoldersMovePlan }\n | { readonly ok: false; readonly issues: readonly FoldersMoveIssue[] };\n\n/**\n * Plan a move of any mix of folders, projects and templates into one destination.\n *\n * The only function that decides what a moved item ends up called. The preview and the write both\n * call it, over the same view, so the two cannot drift apart.\n *\n * A folder moves with everything inside it. When the selection holds a folder together with\n * something inside it, that item travels with the folder and is not planned on its own: moving it\n * separately as well would pull it out of the subtree it belongs to.\n */\nexport function planFoldersMove(\n view: FoldersView,\n items: readonly FoldersItem[],\n destination?: FolderId,\n): FoldersMovePlanResult {\n const issues: FoldersMoveIssue[] = [];\n\n const destinationKnown =\n destination === undefined || view.folders.some((folder) => folder.id === destination);\n if (destination !== undefined && !destinationKnown)\n issues.push({ kind: \"unknown-destination\", folder: destination });\n\n const located: Located[] = [];\n const seen = new Set<string>();\n for (const item of items) {\n const key = `${item.kind}:${item.id}`;\n if (seen.has(key)) continue;\n seen.add(key);\n\n const known = locate(view, item);\n if (known === undefined) {\n issues.push({ kind: \"unknown-item\", item });\n continue;\n }\n located.push({ item, ...known });\n }\n\n const carried = new Set<FolderId>(\n located.flatMap(({ item }) => (item.kind === \"folder\" ? foldersSubtree(view, item.id) : [])),\n );\n const moved = located.filter(\n ({ sourceFolder }) => sourceFolder === undefined || !carried.has(sourceFolder),\n );\n\n if (destination !== undefined && destinationKnown)\n for (const { item } of moved) {\n if (item.kind !== \"folder\") continue;\n if (foldersSubtree(view, item.id).includes(destination))\n issues.push({ kind: \"into-own-descendant\", folder: item.id, destination });\n }\n\n if (issues.length > 0) return { ok: false, issues };\n\n // Each kind is named against its own kind only: a moved folder never becomes \"X (Copy)\" for a\n // project called X in the destination.\n const movedIds = moved.map(({ item }) => item.id);\n const taken: Record<FoldersItem[\"kind\"], string[]> = {\n folder: foldersSiblingNames(view, destination, movedIds, { kind: \"folder\" }),\n project: foldersSiblingNames(view, destination, movedIds, { kind: \"project\" }),\n template: foldersSiblingNames(view, destination, movedIds, { kind: \"template\" }),\n };\n\n const entries: FoldersMoveEntry[] = [];\n for (const { item, name, sourceFolder } of moved.sort(byCanonicalOrder)) {\n const resulting = foldersUniqueName(name, taken[item.kind]);\n taken[item.kind].push(resulting);\n entries.push({\n item,\n currentName: name,\n name: resulting,\n renamed: resulting !== name,\n ...(sourceFolder === undefined ? {} : { sourceFolder }),\n });\n }\n\n return {\n ok: true,\n plan: { ...(destination === undefined ? {} : { destination }), entries },\n };\n}\n\n/** True when two plans say exactly the same thing. */\nexport function foldersMovePlansEqual(a: FoldersMovePlan, b: FoldersMovePlan): boolean {\n if (a.destination !== b.destination) return false;\n if (a.entries.length !== b.entries.length) return false;\n return a.entries.every((entry, index) => {\n const other = b.entries[index];\n if (other === undefined) return false;\n return (\n entry.item.kind === other.item.kind &&\n entry.item.id === other.item.id &&\n entry.currentName === other.currentName &&\n entry.name === other.name &&\n entry.renamed === other.renamed &&\n entry.sourceFolder === other.sourceFolder\n );\n });\n}\n\n/**\n * A project or a template the move gives a new name. Their names live in their own metadata, not\n * in the folder document, so the write path has to carry these out separately; a folder's name is\n * in the document and is renamed there.\n */\nexport interface FoldersLabelRename {\n readonly item: FoldersLeafItem;\n readonly name: string;\n}\n\n/** What applying a plan changes. */\nexport interface FoldersMoveApplication {\n /** The document to persist. */\n readonly document: FoldersDocument;\n /** Projects and templates whose label the move changes. */\n readonly labelRenames: readonly FoldersLabelRename[];\n}\n\n/**\n * The document a plan produces, plus the project and template label renames it implies.\n *\n * Applying a plan is arithmetic on an already validated plan; whether that plan may be committed\n * is the write path's decision.\n */\nexport function applyFoldersMove(\n view: FoldersView,\n movePlan: FoldersMovePlan,\n): FoldersMoveApplication {\n const folderParents = new Map<FolderId, FolderId | undefined>();\n const folderNames = new Map<FolderId, string>();\n const projectFolders = new Map<ProjectId, FolderId | undefined>();\n const templateFolders = new Map<TemplateId, FolderId | undefined>();\n const labelRenames: FoldersLabelRename[] = [];\n\n for (const entry of movePlan.entries) {\n switch (entry.item.kind) {\n case \"folder\":\n folderParents.set(entry.item.id, movePlan.destination);\n folderNames.set(entry.item.id, entry.name);\n break;\n case \"project\":\n projectFolders.set(entry.item.id, movePlan.destination);\n if (entry.renamed) labelRenames.push({ item: entry.item, name: entry.name });\n break;\n case \"template\":\n templateFolders.set(entry.item.id, movePlan.destination);\n if (entry.renamed) labelRenames.push({ item: entry.item, name: entry.name });\n break;\n }\n }\n\n const folders = view.folders.map((folder) => ({\n ...folder,\n parent: folderParents.has(folder.id) ? folderParents.get(folder.id) : folder.parent,\n name: folderNames.get(folder.id) ?? folder.name,\n }));\n\n const projects = view.projects.map((project) => ({\n ...project,\n folder: projectFolders.has(project.id) ? projectFolders.get(project.id) : project.folder,\n }));\n\n const templates = view.templates.map((template) => ({\n ...template,\n folder: templateFolders.has(template.id) ? templateFolders.get(template.id) : template.folder,\n }));\n\n const document = foldersDocumentFromView({ ...view, folders, projects, templates });\n return { document, labelRenames };\n}\n\n//\n// Internals\n//\n\n/** An item of the selection, with what the view says about it. */\ninterface Located {\n readonly item: FoldersItem;\n readonly name: string;\n /** Folder holding the item; absent when it is at the top level. */\n readonly sourceFolder?: FolderId;\n}\n\n/** The name and containing folder of an item the view holds, whichever kind it is. */\nfunction locate(\n view: FoldersView,\n item: FoldersItem,\n): { readonly name: string; readonly sourceFolder?: FolderId } | undefined {\n switch (item.kind) {\n case \"folder\": {\n const folder = view.folders.find((candidate) => candidate.id === item.id);\n return folder === undefined ? undefined : { name: folder.name, sourceFolder: folder.parent };\n }\n case \"project\": {\n const project = view.projects.find((candidate) => candidate.id === item.id);\n return project === undefined\n ? undefined\n : { name: project.name, sourceFolder: project.folder };\n }\n case \"template\": {\n const template = view.templates.find((candidate) => candidate.id === item.id);\n return template === undefined\n ? undefined\n : { name: template.name, sourceFolder: template.folder };\n }\n }\n}\n\n/**\n * Folders, then projects, then templates; within a kind by name, then by id. The order of the\n * items a caller hands in must not change the plan, or a preview and its write could differ over\n * nothing.\n */\nfunction byCanonicalOrder(a: Located, b: Located): number {\n if (a.item.kind !== b.item.kind) return KIND_ORDER[a.item.kind] - KIND_ORDER[b.item.kind];\n const byName = a.name.toLowerCase().localeCompare(b.name.toLowerCase());\n if (byName !== 0) return byName;\n return String(a.item.id).localeCompare(String(b.item.id));\n}\n\nconst KIND_ORDER: Readonly<Record<FoldersItem[\"kind\"], number>> = {\n folder: 0,\n project: 1,\n template: 2,\n};\n"],"mappings":";;;;;;;;;;;;;AAiEA,SAAgB,gBACd,MACA,OACA,aACuB;CACvB,MAAM,SAA6B,CAAC;CAEpC,MAAM,mBACJ,gBAAgB,KAAA,KAAa,KAAK,QAAQ,MAAM,WAAW,OAAO,OAAO,WAAW;CACtF,IAAI,gBAAgB,KAAA,KAAa,CAAC,kBAChC,OAAO,KAAK;EAAE,MAAM;EAAuB,QAAQ;CAAY,CAAC;CAElE,MAAM,UAAqB,CAAC;CAC5B,MAAM,uBAAO,IAAI,IAAY;CAC7B,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,MAAM,GAAG,KAAK,KAAK,GAAG,KAAK;EACjC,IAAI,KAAK,IAAI,GAAG,GAAG;EACnB,KAAK,IAAI,GAAG;EAEZ,MAAM,QAAQ,OAAO,MAAM,IAAI;EAC/B,IAAI,UAAU,KAAA,GAAW;GACvB,OAAO,KAAK;IAAE,MAAM;IAAgB;GAAK,CAAC;GAC1C;EACF;EACA,QAAQ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AAE,KAAK,SAAS,EAAE,KAAK,MAAM,OAAO,WAAW,EAAE,KAAK,QAAQ,WAAW,EAAE,KAAK;CACpF,MAAM,SAAS,EAAE,KAAK,YAAY,CAAC,CAAC,cAAc,EAAE,KAAK,YAAY,CAAC;CACtE,IAAI,WAAW,GAAG,OAAO;CACzB,OAAO,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,cAAc,OAAO,EAAE,KAAK,EAAE,CAAC;AAC1D;AAEA,MAAM,aAA4D;CAChE,QAAQ;CACR,SAAS;CACT,UAAU;AACZ"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { FolderId, FoldersDocument } from "./document.js";
|
|
2
|
+
import { FoldersView } from "./view.js";
|
|
3
|
+
import { ProjectId, TemplateId } from "@milaboratories/pl-model-common";
|
|
4
|
+
//#region src/folders/planner.d.ts
|
|
5
|
+
/** A folder, a project or a stored template, as something a move acts on. */
|
|
6
|
+
export type FoldersItem = {
|
|
7
|
+
readonly kind: "folder";
|
|
8
|
+
readonly id: FolderId;
|
|
9
|
+
} | {
|
|
10
|
+
readonly kind: "project";
|
|
11
|
+
readonly id: ProjectId;
|
|
12
|
+
} | {
|
|
13
|
+
readonly kind: "template";
|
|
14
|
+
readonly id: TemplateId;
|
|
15
|
+
};
|
|
16
|
+
/** A tree item that is not a folder: a project or a stored template. */
|
|
17
|
+
export type FoldersLeafItem = Exclude<FoldersItem, {
|
|
18
|
+
readonly kind: "folder";
|
|
19
|
+
}>;
|
|
20
|
+
/** What one item is called after the move, and what it was called before. */
|
|
21
|
+
export interface FoldersMoveEntry {
|
|
22
|
+
readonly item: FoldersItem;
|
|
23
|
+
readonly currentName: string;
|
|
24
|
+
/** The name the item carries once the plan is applied. */
|
|
25
|
+
readonly name: string;
|
|
26
|
+
/** True when the destination already held that name and the item is being renamed. */
|
|
27
|
+
readonly renamed: boolean;
|
|
28
|
+
/** Folder the item is coming from; absent when it is at the top level. */
|
|
29
|
+
readonly sourceFolder?: FolderId;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Every item of a move and its resulting name.
|
|
33
|
+
*
|
|
34
|
+
* A plan is computed for the preview and recomputed inside the write, and the write commits only
|
|
35
|
+
* when the two are identical, so a plan confirmed against state that has since changed is refused
|
|
36
|
+
* rather than applied. Entries are in a canonical order for exactly that comparison.
|
|
37
|
+
*/
|
|
38
|
+
export interface FoldersMovePlan {
|
|
39
|
+
/** Folder everything lands in; absent for the top level. */
|
|
40
|
+
readonly destination?: FolderId;
|
|
41
|
+
readonly entries: readonly FoldersMoveEntry[];
|
|
42
|
+
}
|
|
43
|
+
/** One reason a move cannot be planned. */
|
|
44
|
+
export type FoldersMoveIssue = {
|
|
45
|
+
readonly kind: "unknown-destination";
|
|
46
|
+
readonly folder: FolderId;
|
|
47
|
+
} | {
|
|
48
|
+
readonly kind: "unknown-item";
|
|
49
|
+
readonly item: FoldersItem;
|
|
50
|
+
} | {
|
|
51
|
+
readonly kind: "into-own-descendant";
|
|
52
|
+
readonly folder: FolderId;
|
|
53
|
+
readonly destination: FolderId;
|
|
54
|
+
};
|
|
55
|
+
/** A plan, or everything standing in the way of one. */
|
|
56
|
+
export type FoldersMovePlanResult = {
|
|
57
|
+
readonly ok: true;
|
|
58
|
+
readonly plan: FoldersMovePlan;
|
|
59
|
+
} | {
|
|
60
|
+
readonly ok: false;
|
|
61
|
+
readonly issues: readonly FoldersMoveIssue[];
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Plan a move of any mix of folders, projects and templates into one destination.
|
|
65
|
+
*
|
|
66
|
+
* The only function that decides what a moved item ends up called. The preview and the write both
|
|
67
|
+
* call it, over the same view, so the two cannot drift apart.
|
|
68
|
+
*
|
|
69
|
+
* A folder moves with everything inside it. When the selection holds a folder together with
|
|
70
|
+
* something inside it, that item travels with the folder and is not planned on its own: moving it
|
|
71
|
+
* separately as well would pull it out of the subtree it belongs to.
|
|
72
|
+
*/
|
|
73
|
+
export declare function planFoldersMove(view: FoldersView, items: readonly FoldersItem[], destination?: FolderId): FoldersMovePlanResult;
|
|
74
|
+
/** True when two plans say exactly the same thing. */
|
|
75
|
+
export declare function foldersMovePlansEqual(a: FoldersMovePlan, b: FoldersMovePlan): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* A project or a template the move gives a new name. Their names live in their own metadata, not
|
|
78
|
+
* in the folder document, so the write path has to carry these out separately; a folder's name is
|
|
79
|
+
* in the document and is renamed there.
|
|
80
|
+
*/
|
|
81
|
+
export interface FoldersLabelRename {
|
|
82
|
+
readonly item: FoldersLeafItem;
|
|
83
|
+
readonly name: string;
|
|
84
|
+
}
|
|
85
|
+
/** What applying a plan changes. */
|
|
86
|
+
export interface FoldersMoveApplication {
|
|
87
|
+
/** The document to persist. */
|
|
88
|
+
readonly document: FoldersDocument;
|
|
89
|
+
/** Projects and templates whose label the move changes. */
|
|
90
|
+
readonly labelRenames: readonly FoldersLabelRename[];
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The document a plan produces, plus the project and template label renames it implies.
|
|
94
|
+
*
|
|
95
|
+
* Applying a plan is arithmetic on an already validated plan; whether that plan may be committed
|
|
96
|
+
* is the write path's decision.
|
|
97
|
+
*/
|
|
98
|
+
export declare function applyFoldersMove(view: FoldersView, movePlan: FoldersMovePlan): FoldersMoveApplication;
|
|
99
|
+
//#endregion
|
|
100
|
+
//# sourceMappingURL=planner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner.d.ts","names":[],"sources":["../../src/folders/planner.ts"],"mappings":";;;;;YAOY;WACG;WAAyB,IAAI;;WAC7B;WAA0B,IAAI;;WAC9B;WAA2B,IAAI;;;YAGlC,kBAAkB,QAAQ;WAAwB;;;iBAG7C;WACN,MAAM;WACN;;WAEA;;WAEA;;WAEA,eAAe;;;;;;;;;iBAUT;;WAEN,cAAc;WACd,kBAAkB;;;YAIjB;WACG;WAAsC,QAAQ;;WAC9C;WAA+B,MAAM;;WAErC;WACA,QAAQ;WACR,aAAa;;;YAIhB;WACG;WAAmB,MAAM;;WACzB;WAAoB,iBAAiB;;;;;;;;;;;;wBAYpC,gBACd,MAAM,aACN,gBAAgB,eAChB,cAAc,WACb;;wBAoEa,sBAAsB,GAAG,iBAAiB,GAAG;;;;;;iBAsB5C;WACN,MAAM;WACN;;;iBAIM;;WAEN,UAAU;;WAEV,uBAAuB;;;;;;;;wBASlB,iBACd,MAAM,aACN,UAAU,kBACT"}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { foldersDocumentFromView, foldersSiblingNames, foldersSubtree } from "./view.js";
|
|
2
|
+
import { foldersUniqueName } from "./naming.js";
|
|
3
|
+
//#region src/folders/planner.ts
|
|
4
|
+
/**
|
|
5
|
+
* Plan a move of any mix of folders, projects and templates into one destination.
|
|
6
|
+
*
|
|
7
|
+
* The only function that decides what a moved item ends up called. The preview and the write both
|
|
8
|
+
* call it, over the same view, so the two cannot drift apart.
|
|
9
|
+
*
|
|
10
|
+
* A folder moves with everything inside it. When the selection holds a folder together with
|
|
11
|
+
* something inside it, that item travels with the folder and is not planned on its own: moving it
|
|
12
|
+
* separately as well would pull it out of the subtree it belongs to.
|
|
13
|
+
*/
|
|
14
|
+
function planFoldersMove(view, items, destination) {
|
|
15
|
+
const issues = [];
|
|
16
|
+
const destinationKnown = destination === void 0 || view.folders.some((folder) => folder.id === destination);
|
|
17
|
+
if (destination !== void 0 && !destinationKnown) issues.push({
|
|
18
|
+
kind: "unknown-destination",
|
|
19
|
+
folder: destination
|
|
20
|
+
});
|
|
21
|
+
const located = [];
|
|
22
|
+
const seen = /* @__PURE__ */ new Set();
|
|
23
|
+
for (const item of items) {
|
|
24
|
+
const key = `${item.kind}:${item.id}`;
|
|
25
|
+
if (seen.has(key)) continue;
|
|
26
|
+
seen.add(key);
|
|
27
|
+
const known = locate(view, item);
|
|
28
|
+
if (known === void 0) {
|
|
29
|
+
issues.push({
|
|
30
|
+
kind: "unknown-item",
|
|
31
|
+
item
|
|
32
|
+
});
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
located.push({
|
|
36
|
+
item,
|
|
37
|
+
...known
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const carried = new Set(located.flatMap(({ item }) => item.kind === "folder" ? foldersSubtree(view, item.id) : []));
|
|
41
|
+
const moved = located.filter(({ sourceFolder }) => sourceFolder === void 0 || !carried.has(sourceFolder));
|
|
42
|
+
if (destination !== void 0 && destinationKnown) for (const { item } of moved) {
|
|
43
|
+
if (item.kind !== "folder") continue;
|
|
44
|
+
if (foldersSubtree(view, item.id).includes(destination)) issues.push({
|
|
45
|
+
kind: "into-own-descendant",
|
|
46
|
+
folder: item.id,
|
|
47
|
+
destination
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
if (issues.length > 0) return {
|
|
51
|
+
ok: false,
|
|
52
|
+
issues
|
|
53
|
+
};
|
|
54
|
+
const movedIds = moved.map(({ item }) => item.id);
|
|
55
|
+
const taken = {
|
|
56
|
+
folder: foldersSiblingNames(view, destination, movedIds, { kind: "folder" }),
|
|
57
|
+
project: foldersSiblingNames(view, destination, movedIds, { kind: "project" }),
|
|
58
|
+
template: foldersSiblingNames(view, destination, movedIds, { kind: "template" })
|
|
59
|
+
};
|
|
60
|
+
const entries = [];
|
|
61
|
+
for (const { item, name, sourceFolder } of moved.sort(byCanonicalOrder)) {
|
|
62
|
+
const resulting = foldersUniqueName(name, taken[item.kind]);
|
|
63
|
+
taken[item.kind].push(resulting);
|
|
64
|
+
entries.push({
|
|
65
|
+
item,
|
|
66
|
+
currentName: name,
|
|
67
|
+
name: resulting,
|
|
68
|
+
renamed: resulting !== name,
|
|
69
|
+
...sourceFolder === void 0 ? {} : { sourceFolder }
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
ok: true,
|
|
74
|
+
plan: {
|
|
75
|
+
...destination === void 0 ? {} : { destination },
|
|
76
|
+
entries
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** True when two plans say exactly the same thing. */
|
|
81
|
+
function foldersMovePlansEqual(a, b) {
|
|
82
|
+
if (a.destination !== b.destination) return false;
|
|
83
|
+
if (a.entries.length !== b.entries.length) return false;
|
|
84
|
+
return a.entries.every((entry, index) => {
|
|
85
|
+
const other = b.entries[index];
|
|
86
|
+
if (other === void 0) return false;
|
|
87
|
+
return entry.item.kind === other.item.kind && entry.item.id === other.item.id && entry.currentName === other.currentName && entry.name === other.name && entry.renamed === other.renamed && entry.sourceFolder === other.sourceFolder;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The document a plan produces, plus the project and template label renames it implies.
|
|
92
|
+
*
|
|
93
|
+
* Applying a plan is arithmetic on an already validated plan; whether that plan may be committed
|
|
94
|
+
* is the write path's decision.
|
|
95
|
+
*/
|
|
96
|
+
function applyFoldersMove(view, movePlan) {
|
|
97
|
+
const folderParents = /* @__PURE__ */ new Map();
|
|
98
|
+
const folderNames = /* @__PURE__ */ new Map();
|
|
99
|
+
const projectFolders = /* @__PURE__ */ new Map();
|
|
100
|
+
const templateFolders = /* @__PURE__ */ new Map();
|
|
101
|
+
const labelRenames = [];
|
|
102
|
+
for (const entry of movePlan.entries) switch (entry.item.kind) {
|
|
103
|
+
case "folder":
|
|
104
|
+
folderParents.set(entry.item.id, movePlan.destination);
|
|
105
|
+
folderNames.set(entry.item.id, entry.name);
|
|
106
|
+
break;
|
|
107
|
+
case "project":
|
|
108
|
+
projectFolders.set(entry.item.id, movePlan.destination);
|
|
109
|
+
if (entry.renamed) labelRenames.push({
|
|
110
|
+
item: entry.item,
|
|
111
|
+
name: entry.name
|
|
112
|
+
});
|
|
113
|
+
break;
|
|
114
|
+
case "template":
|
|
115
|
+
templateFolders.set(entry.item.id, movePlan.destination);
|
|
116
|
+
if (entry.renamed) labelRenames.push({
|
|
117
|
+
item: entry.item,
|
|
118
|
+
name: entry.name
|
|
119
|
+
});
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
const folders = view.folders.map((folder) => ({
|
|
123
|
+
...folder,
|
|
124
|
+
parent: folderParents.has(folder.id) ? folderParents.get(folder.id) : folder.parent,
|
|
125
|
+
name: folderNames.get(folder.id) ?? folder.name
|
|
126
|
+
}));
|
|
127
|
+
const projects = view.projects.map((project) => ({
|
|
128
|
+
...project,
|
|
129
|
+
folder: projectFolders.has(project.id) ? projectFolders.get(project.id) : project.folder
|
|
130
|
+
}));
|
|
131
|
+
const templates = view.templates.map((template) => ({
|
|
132
|
+
...template,
|
|
133
|
+
folder: templateFolders.has(template.id) ? templateFolders.get(template.id) : template.folder
|
|
134
|
+
}));
|
|
135
|
+
return {
|
|
136
|
+
document: foldersDocumentFromView({
|
|
137
|
+
...view,
|
|
138
|
+
folders,
|
|
139
|
+
projects,
|
|
140
|
+
templates
|
|
141
|
+
}),
|
|
142
|
+
labelRenames
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/** The name and containing folder of an item the view holds, whichever kind it is. */
|
|
146
|
+
function locate(view, item) {
|
|
147
|
+
switch (item.kind) {
|
|
148
|
+
case "folder": {
|
|
149
|
+
const folder = view.folders.find((candidate) => candidate.id === item.id);
|
|
150
|
+
return folder === void 0 ? void 0 : {
|
|
151
|
+
name: folder.name,
|
|
152
|
+
sourceFolder: folder.parent
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
case "project": {
|
|
156
|
+
const project = view.projects.find((candidate) => candidate.id === item.id);
|
|
157
|
+
return project === void 0 ? void 0 : {
|
|
158
|
+
name: project.name,
|
|
159
|
+
sourceFolder: project.folder
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
case "template": {
|
|
163
|
+
const template = view.templates.find((candidate) => candidate.id === item.id);
|
|
164
|
+
return template === void 0 ? void 0 : {
|
|
165
|
+
name: template.name,
|
|
166
|
+
sourceFolder: template.folder
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Folders, then projects, then templates; within a kind by name, then by id. The order of the
|
|
173
|
+
* items a caller hands in must not change the plan, or a preview and its write could differ over
|
|
174
|
+
* nothing.
|
|
175
|
+
*/
|
|
176
|
+
function byCanonicalOrder(a, b) {
|
|
177
|
+
if (a.item.kind !== b.item.kind) return KIND_ORDER[a.item.kind] - KIND_ORDER[b.item.kind];
|
|
178
|
+
const byName = a.name.toLowerCase().localeCompare(b.name.toLowerCase());
|
|
179
|
+
if (byName !== 0) return byName;
|
|
180
|
+
return String(a.item.id).localeCompare(String(b.item.id));
|
|
181
|
+
}
|
|
182
|
+
const KIND_ORDER = {
|
|
183
|
+
folder: 0,
|
|
184
|
+
project: 1,
|
|
185
|
+
template: 2
|
|
186
|
+
};
|
|
187
|
+
//#endregion
|
|
188
|
+
export { applyFoldersMove, foldersMovePlansEqual, planFoldersMove };
|
|
189
|
+
|
|
190
|
+
//# sourceMappingURL=planner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner.js","names":[],"sources":["../../src/folders/planner.ts"],"sourcesContent":["import type { ProjectId, TemplateId } from \"@milaboratories/pl-model-common\";\nimport type { FoldersDocument, FolderId } from \"./document\";\nimport { foldersUniqueName } from \"./naming\";\nimport type { FoldersView } from \"./view\";\nimport { foldersDocumentFromView, foldersSiblingNames, foldersSubtree } from \"./view\";\n\n/** A folder, a project or a stored template, as something a move acts on. */\nexport type FoldersItem =\n | { readonly kind: \"folder\"; readonly id: FolderId }\n | { readonly kind: \"project\"; readonly id: ProjectId }\n | { readonly kind: \"template\"; readonly id: TemplateId };\n\n/** A tree item that is not a folder: a project or a stored template. */\nexport type FoldersLeafItem = Exclude<FoldersItem, { readonly kind: \"folder\" }>;\n\n/** What one item is called after the move, and what it was called before. */\nexport interface FoldersMoveEntry {\n readonly item: FoldersItem;\n readonly currentName: string;\n /** The name the item carries once the plan is applied. */\n readonly name: string;\n /** True when the destination already held that name and the item is being renamed. */\n readonly renamed: boolean;\n /** Folder the item is coming from; absent when it is at the top level. */\n readonly sourceFolder?: FolderId;\n}\n\n/**\n * Every item of a move and its resulting name.\n *\n * A plan is computed for the preview and recomputed inside the write, and the write commits only\n * when the two are identical, so a plan confirmed against state that has since changed is refused\n * rather than applied. Entries are in a canonical order for exactly that comparison.\n */\nexport interface FoldersMovePlan {\n /** Folder everything lands in; absent for the top level. */\n readonly destination?: FolderId;\n readonly entries: readonly FoldersMoveEntry[];\n}\n\n/** One reason a move cannot be planned. */\nexport type FoldersMoveIssue =\n | { readonly kind: \"unknown-destination\"; readonly folder: FolderId }\n | { readonly kind: \"unknown-item\"; readonly item: FoldersItem }\n | {\n readonly kind: \"into-own-descendant\";\n readonly folder: FolderId;\n readonly destination: FolderId;\n };\n\n/** A plan, or everything standing in the way of one. */\nexport type FoldersMovePlanResult =\n | { readonly ok: true; readonly plan: FoldersMovePlan }\n | { readonly ok: false; readonly issues: readonly FoldersMoveIssue[] };\n\n/**\n * Plan a move of any mix of folders, projects and templates into one destination.\n *\n * The only function that decides what a moved item ends up called. The preview and the write both\n * call it, over the same view, so the two cannot drift apart.\n *\n * A folder moves with everything inside it. When the selection holds a folder together with\n * something inside it, that item travels with the folder and is not planned on its own: moving it\n * separately as well would pull it out of the subtree it belongs to.\n */\nexport function planFoldersMove(\n view: FoldersView,\n items: readonly FoldersItem[],\n destination?: FolderId,\n): FoldersMovePlanResult {\n const issues: FoldersMoveIssue[] = [];\n\n const destinationKnown =\n destination === undefined || view.folders.some((folder) => folder.id === destination);\n if (destination !== undefined && !destinationKnown)\n issues.push({ kind: \"unknown-destination\", folder: destination });\n\n const located: Located[] = [];\n const seen = new Set<string>();\n for (const item of items) {\n const key = `${item.kind}:${item.id}`;\n if (seen.has(key)) continue;\n seen.add(key);\n\n const known = locate(view, item);\n if (known === undefined) {\n issues.push({ kind: \"unknown-item\", item });\n continue;\n }\n located.push({ item, ...known });\n }\n\n const carried = new Set<FolderId>(\n located.flatMap(({ item }) => (item.kind === \"folder\" ? foldersSubtree(view, item.id) : [])),\n );\n const moved = located.filter(\n ({ sourceFolder }) => sourceFolder === undefined || !carried.has(sourceFolder),\n );\n\n if (destination !== undefined && destinationKnown)\n for (const { item } of moved) {\n if (item.kind !== \"folder\") continue;\n if (foldersSubtree(view, item.id).includes(destination))\n issues.push({ kind: \"into-own-descendant\", folder: item.id, destination });\n }\n\n if (issues.length > 0) return { ok: false, issues };\n\n // Each kind is named against its own kind only: a moved folder never becomes \"X (Copy)\" for a\n // project called X in the destination.\n const movedIds = moved.map(({ item }) => item.id);\n const taken: Record<FoldersItem[\"kind\"], string[]> = {\n folder: foldersSiblingNames(view, destination, movedIds, { kind: \"folder\" }),\n project: foldersSiblingNames(view, destination, movedIds, { kind: \"project\" }),\n template: foldersSiblingNames(view, destination, movedIds, { kind: \"template\" }),\n };\n\n const entries: FoldersMoveEntry[] = [];\n for (const { item, name, sourceFolder } of moved.sort(byCanonicalOrder)) {\n const resulting = foldersUniqueName(name, taken[item.kind]);\n taken[item.kind].push(resulting);\n entries.push({\n item,\n currentName: name,\n name: resulting,\n renamed: resulting !== name,\n ...(sourceFolder === undefined ? {} : { sourceFolder }),\n });\n }\n\n return {\n ok: true,\n plan: { ...(destination === undefined ? {} : { destination }), entries },\n };\n}\n\n/** True when two plans say exactly the same thing. */\nexport function foldersMovePlansEqual(a: FoldersMovePlan, b: FoldersMovePlan): boolean {\n if (a.destination !== b.destination) return false;\n if (a.entries.length !== b.entries.length) return false;\n return a.entries.every((entry, index) => {\n const other = b.entries[index];\n if (other === undefined) return false;\n return (\n entry.item.kind === other.item.kind &&\n entry.item.id === other.item.id &&\n entry.currentName === other.currentName &&\n entry.name === other.name &&\n entry.renamed === other.renamed &&\n entry.sourceFolder === other.sourceFolder\n );\n });\n}\n\n/**\n * A project or a template the move gives a new name. Their names live in their own metadata, not\n * in the folder document, so the write path has to carry these out separately; a folder's name is\n * in the document and is renamed there.\n */\nexport interface FoldersLabelRename {\n readonly item: FoldersLeafItem;\n readonly name: string;\n}\n\n/** What applying a plan changes. */\nexport interface FoldersMoveApplication {\n /** The document to persist. */\n readonly document: FoldersDocument;\n /** Projects and templates whose label the move changes. */\n readonly labelRenames: readonly FoldersLabelRename[];\n}\n\n/**\n * The document a plan produces, plus the project and template label renames it implies.\n *\n * Applying a plan is arithmetic on an already validated plan; whether that plan may be committed\n * is the write path's decision.\n */\nexport function applyFoldersMove(\n view: FoldersView,\n movePlan: FoldersMovePlan,\n): FoldersMoveApplication {\n const folderParents = new Map<FolderId, FolderId | undefined>();\n const folderNames = new Map<FolderId, string>();\n const projectFolders = new Map<ProjectId, FolderId | undefined>();\n const templateFolders = new Map<TemplateId, FolderId | undefined>();\n const labelRenames: FoldersLabelRename[] = [];\n\n for (const entry of movePlan.entries) {\n switch (entry.item.kind) {\n case \"folder\":\n folderParents.set(entry.item.id, movePlan.destination);\n folderNames.set(entry.item.id, entry.name);\n break;\n case \"project\":\n projectFolders.set(entry.item.id, movePlan.destination);\n if (entry.renamed) labelRenames.push({ item: entry.item, name: entry.name });\n break;\n case \"template\":\n templateFolders.set(entry.item.id, movePlan.destination);\n if (entry.renamed) labelRenames.push({ item: entry.item, name: entry.name });\n break;\n }\n }\n\n const folders = view.folders.map((folder) => ({\n ...folder,\n parent: folderParents.has(folder.id) ? folderParents.get(folder.id) : folder.parent,\n name: folderNames.get(folder.id) ?? folder.name,\n }));\n\n const projects = view.projects.map((project) => ({\n ...project,\n folder: projectFolders.has(project.id) ? projectFolders.get(project.id) : project.folder,\n }));\n\n const templates = view.templates.map((template) => ({\n ...template,\n folder: templateFolders.has(template.id) ? templateFolders.get(template.id) : template.folder,\n }));\n\n const document = foldersDocumentFromView({ ...view, folders, projects, templates });\n return { document, labelRenames };\n}\n\n//\n// Internals\n//\n\n/** An item of the selection, with what the view says about it. */\ninterface Located {\n readonly item: FoldersItem;\n readonly name: string;\n /** Folder holding the item; absent when it is at the top level. */\n readonly sourceFolder?: FolderId;\n}\n\n/** The name and containing folder of an item the view holds, whichever kind it is. */\nfunction locate(\n view: FoldersView,\n item: FoldersItem,\n): { readonly name: string; readonly sourceFolder?: FolderId } | undefined {\n switch (item.kind) {\n case \"folder\": {\n const folder = view.folders.find((candidate) => candidate.id === item.id);\n return folder === undefined ? undefined : { name: folder.name, sourceFolder: folder.parent };\n }\n case \"project\": {\n const project = view.projects.find((candidate) => candidate.id === item.id);\n return project === undefined\n ? undefined\n : { name: project.name, sourceFolder: project.folder };\n }\n case \"template\": {\n const template = view.templates.find((candidate) => candidate.id === item.id);\n return template === undefined\n ? undefined\n : { name: template.name, sourceFolder: template.folder };\n }\n }\n}\n\n/**\n * Folders, then projects, then templates; within a kind by name, then by id. The order of the\n * items a caller hands in must not change the plan, or a preview and its write could differ over\n * nothing.\n */\nfunction byCanonicalOrder(a: Located, b: Located): number {\n if (a.item.kind !== b.item.kind) return KIND_ORDER[a.item.kind] - KIND_ORDER[b.item.kind];\n const byName = a.name.toLowerCase().localeCompare(b.name.toLowerCase());\n if (byName !== 0) return byName;\n return String(a.item.id).localeCompare(String(b.item.id));\n}\n\nconst KIND_ORDER: Readonly<Record<FoldersItem[\"kind\"], number>> = {\n folder: 0,\n project: 1,\n template: 2,\n};\n"],"mappings":";;;;;;;;;;;;;AAiEA,SAAgB,gBACd,MACA,OACA,aACuB;CACvB,MAAM,SAA6B,CAAC;CAEpC,MAAM,mBACJ,gBAAgB,KAAA,KAAa,KAAK,QAAQ,MAAM,WAAW,OAAO,OAAO,WAAW;CACtF,IAAI,gBAAgB,KAAA,KAAa,CAAC,kBAChC,OAAO,KAAK;EAAE,MAAM;EAAuB,QAAQ;CAAY,CAAC;CAElE,MAAM,UAAqB,CAAC;CAC5B,MAAM,uBAAO,IAAI,IAAY;CAC7B,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,MAAM,GAAG,KAAK,KAAK,GAAG,KAAK;EACjC,IAAI,KAAK,IAAI,GAAG,GAAG;EACnB,KAAK,IAAI,GAAG;EAEZ,MAAM,QAAQ,OAAO,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