@milaboratories/pl-model-middle-layer 1.33.0 → 1.34.1

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.
Files changed (41) hide show
  1. package/dist/folders/commit.d.ts +1 -1
  2. package/dist/folders/index.d.ts +1 -1
  3. package/dist/folders/inheritance.cjs +4 -4
  4. package/dist/folders/inheritance.cjs.map +1 -1
  5. package/dist/folders/inheritance.d.ts +4 -4
  6. package/dist/folders/inheritance.js +4 -4
  7. package/dist/folders/inheritance.js.map +1 -1
  8. package/dist/folders/invariants.cjs +9 -9
  9. package/dist/folders/invariants.cjs.map +1 -1
  10. package/dist/folders/invariants.d.ts +5 -3
  11. package/dist/folders/invariants.d.ts.map +1 -1
  12. package/dist/folders/invariants.js +9 -9
  13. package/dist/folders/invariants.js.map +1 -1
  14. package/dist/folders/naming.cjs +5 -4
  15. package/dist/folders/naming.cjs.map +1 -1
  16. package/dist/folders/naming.d.ts +5 -4
  17. package/dist/folders/naming.d.ts.map +1 -1
  18. package/dist/folders/naming.js +5 -4
  19. package/dist/folders/naming.js.map +1 -1
  20. package/dist/folders/planner.cjs +8 -3
  21. package/dist/folders/planner.cjs.map +1 -1
  22. package/dist/folders/planner.d.ts.map +1 -1
  23. package/dist/folders/planner.js +8 -3
  24. package/dist/folders/planner.js.map +1 -1
  25. package/dist/folders/view.cjs +7 -5
  26. package/dist/folders/view.cjs.map +1 -1
  27. package/dist/folders/view.d.ts +8 -3
  28. package/dist/folders/view.d.ts.map +1 -1
  29. package/dist/folders/view.js +7 -5
  30. package/dist/folders/view.js.map +1 -1
  31. package/dist/index.d.ts +1 -1
  32. package/package.json +4 -4
  33. package/src/folders/inheritance.test.ts +11 -6
  34. package/src/folders/inheritance.ts +7 -6
  35. package/src/folders/invariants.test.ts +15 -6
  36. package/src/folders/invariants.ts +15 -11
  37. package/src/folders/naming.ts +5 -4
  38. package/src/folders/planner.test.ts +20 -6
  39. package/src/folders/planner.ts +10 -7
  40. package/src/folders/view.test.ts +17 -6
  41. package/src/folders/view.ts +15 -5
@@ -53,7 +53,7 @@ describe("planFoldersMove", () => {
53
53
  expect(plan.entries[0]).toMatchObject({ name: "Run (Copy)", renamed: true });
54
54
  });
55
55
 
56
- test("folders and projects share one namespace inside a parent", () => {
56
+ test("a folder and a project may share a name inside a parent: each kind has its own namespace", () => {
57
57
  const tree = view(
58
58
  [
59
59
  { id: "a", name: "A" },
@@ -63,6 +63,20 @@ describe("planFoldersMove", () => {
63
63
  );
64
64
 
65
65
  const plan = planned(planFoldersMove(tree, [project("p1")], fid("a")));
66
+ expect(plan.entries[0]).toMatchObject({ name: "Run", renamed: false });
67
+ });
68
+
69
+ test("a moved folder is renamed against folders only", () => {
70
+ const tree = view(
71
+ [
72
+ { id: "a", name: "A" },
73
+ { id: "b", name: "Run", parent: "a" },
74
+ { id: "c", name: "Run" },
75
+ ],
76
+ [{ id: "p1", name: "Run", folder: "a" }],
77
+ );
78
+
79
+ const plan = planned(planFoldersMove(tree, [folder("c")], fid("a")));
66
80
  expect(plan.entries[0]).toMatchObject({ name: "Run (Copy)", renamed: true });
67
81
  });
68
82
 
@@ -258,7 +272,7 @@ describe("a selection holding a folder and something inside it", () => {
258
272
  });
259
273
 
260
274
  describe("moving a template", () => {
261
- test("a template arriving where a project carries its name is renamed", () => {
275
+ test("a template arriving where a project carries its name keeps it", () => {
262
276
  const tree = view(
263
277
  [
264
278
  { id: "a", name: "A" },
@@ -270,8 +284,8 @@ describe("moving a template", () => {
270
284
 
271
285
  const plan = planned(planFoldersMove(tree, [template("t1")], fid("b")));
272
286
  expect(plan.entries[0]).toMatchObject({
273
- name: "Run (Copy)",
274
- renamed: true,
287
+ name: "Run",
288
+ renamed: false,
275
289
  sourceFolder: "a",
276
290
  });
277
291
  });
@@ -296,7 +310,7 @@ describe("moving a template", () => {
296
310
  ]);
297
311
  });
298
312
 
299
- test("a project arriving where a template carries its name is renamed", () => {
313
+ test("a project arriving where a template carries its name keeps it", () => {
300
314
  const tree = view(
301
315
  [
302
316
  { id: "a", name: "A" },
@@ -307,7 +321,7 @@ describe("moving a template", () => {
307
321
  );
308
322
 
309
323
  const plan = planned(planFoldersMove(tree, [project("p1")], fid("b")));
310
- expect(plan.entries[0]).toMatchObject({ name: "Run (Copy)", renamed: true });
324
+ expect(plan.entries[0]).toMatchObject({ name: "Run", renamed: false });
311
325
  });
312
326
 
313
327
  test("applying the plan re-parents the template and touches nothing else", () => {
@@ -106,16 +106,19 @@ export function planFoldersMove(
106
106
 
107
107
  if (issues.length > 0) return { ok: false, issues };
108
108
 
109
- const taken = foldersSiblingNames(
110
- view,
111
- destination,
112
- moved.map(({ item }) => item.id),
113
- );
109
+ // Each kind is named against its own kind only: a moved folder never becomes "X (Copy)" for a
110
+ // project called X in the destination.
111
+ const movedIds = moved.map(({ item }) => item.id);
112
+ const taken: Record<FoldersItem["kind"], string[]> = {
113
+ folder: foldersSiblingNames(view, destination, movedIds, { kind: "folder" }),
114
+ project: foldersSiblingNames(view, destination, movedIds, { kind: "project" }),
115
+ template: foldersSiblingNames(view, destination, movedIds, { kind: "template" }),
116
+ };
114
117
 
115
118
  const entries: FoldersMoveEntry[] = [];
116
119
  for (const { item, name, sourceFolder } of moved.sort(byCanonicalOrder)) {
117
- const resulting = foldersUniqueName(name, taken);
118
- taken.push(resulting);
120
+ const resulting = foldersUniqueName(name, taken[item.kind]);
121
+ taken[item.kind].push(resulting);
119
122
  entries.push({
120
123
  item,
121
124
  currentName: name,
@@ -315,20 +315,31 @@ describe("view helpers", () => {
315
315
  expect(foldersChildren(view, fid("a")).projects.map((project) => project.id)).toEqual(["p1"]);
316
316
  });
317
317
 
318
- test("sibling names span folders and projects alike", () => {
319
- expect(foldersSiblingNames(view).sort()).toEqual(["A", "p2"]);
320
- expect(foldersSiblingNames(view, fid("a")).sort()).toEqual(["B", "p1"]);
318
+ test("sibling names are those of one kind", () => {
319
+ expect(foldersSiblingNames(view, undefined, [], { kind: "folder" })).toEqual(["A"]);
320
+ expect(foldersSiblingNames(view, undefined, [], { kind: "project" })).toEqual(["p2"]);
321
+ expect(foldersSiblingNames(view, fid("a"), [], { kind: "folder" })).toEqual(["B"]);
322
+ expect(foldersSiblingNames(view, fid("a"), [], { kind: "project" })).toEqual(["p1"]);
321
323
  });
322
324
 
323
- test("sibling names span templates too, and leave out the ids they are told to", () => {
325
+ test("sibling names without a kind are those of every kind", () => {
326
+ expect(foldersSiblingNames(view)).toEqual(["A", "p2"]);
327
+ expect(foldersSiblingNames(view, fid("a"))).toEqual(["B", "p1"]);
328
+ expect(foldersSiblingNames(view, fid("a"), ["b"])).toEqual(["p1"]);
329
+ });
330
+
331
+ test("template sibling names are the templates', less the ids they are told to leave out", () => {
324
332
  const withTemplates = foldersViewFromDocument(
325
333
  document([{ id: "a", name: "A" }], { p1: "a" }, { t1: "a" }),
326
334
  projects("p1"),
327
335
  [{ id: tid("t1"), name: "Snapshot" }],
328
336
  );
329
337
 
330
- expect(foldersSiblingNames(withTemplates, fid("a")).sort()).toEqual(["Snapshot", "p1"]);
331
- expect(foldersSiblingNames(withTemplates, fid("a"), ["t1"])).toEqual(["p1"]);
338
+ expect(foldersSiblingNames(withTemplates, fid("a"), [], { kind: "template" })).toEqual([
339
+ "Snapshot",
340
+ ]);
341
+ expect(foldersSiblingNames(withTemplates, fid("a"), ["t1"], { kind: "template" })).toEqual([]);
342
+ expect(foldersSiblingNames(withTemplates, fid("a"), [], { kind: "project" })).toEqual(["p1"]);
332
343
  });
333
344
 
334
345
  test("the view turns back into the document it stands for", () => {
@@ -3,6 +3,7 @@ import { normalizeDescription } from "../project";
3
3
  import type { FoldersDecoded, FoldersDocumentProblem } from "./decode";
4
4
  import type { FoldersDocument, FolderId } from "./document";
5
5
  import { emptyFoldersDocument } from "./document";
6
+ import type { FoldersItem } from "./planner";
6
7
 
7
8
  /** An item as the folder machinery needs to see it: an identity and the label shown to a user. */
8
9
  export interface FoldersItemInput<Id extends string> {
@@ -123,8 +124,10 @@ export function foldersChildren(
123
124
  /**
124
125
  * Names already taken directly inside a folder, or at the top level when no folder is given.
125
126
  *
126
- * Folders, projects and templates share one namespace: whatever kind two things beside each other
127
- * are, they never answer to one name. This is the one list every naming decision is made against.
127
+ * Each kind has its own namespace: two folders, two projects or two templates beside each other
128
+ * never answer to one name, but a folder, a project and a template may. With `kind` given, only the
129
+ * names of that kind are listed — the list a name for an item of that kind is checked against.
130
+ * Without it, the names of every kind are listed.
128
131
  *
129
132
  * `exclude` names the ids that must not count against themselves — the items being renamed or
130
133
  * moved.
@@ -133,12 +136,19 @@ export function foldersSiblingNames(
133
136
  view: FoldersView,
134
137
  parent?: FolderId,
135
138
  exclude: Iterable<string> = [],
139
+ options: { readonly kind?: FoldersItem["kind"] } = {},
136
140
  ): string[] {
137
141
  const skipped = new Set<string>(exclude);
138
142
  const children = foldersChildren(view, parent);
139
- return [...children.folders, ...children.projects, ...children.templates]
140
- .filter((item) => !skipped.has(item.id))
141
- .map((item) => item.name);
143
+ const listed: readonly { readonly id: string; readonly name: string }[] =
144
+ options.kind === "folder"
145
+ ? children.folders
146
+ : options.kind === "project"
147
+ ? children.projects
148
+ : options.kind === "template"
149
+ ? children.templates
150
+ : [...children.folders, ...children.projects, ...children.templates];
151
+ return listed.filter((item) => !skipped.has(item.id)).map((item) => item.name);
142
152
  }
143
153
 
144
154
  /** A folder and every folder beneath it, the folder itself first. */