@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,79 @@
|
|
|
1
|
+
const require_planner = require("./planner.cjs");
|
|
2
|
+
const require_removal = require("./removal.cjs");
|
|
3
|
+
//#region src/folders/commit.ts
|
|
4
|
+
/**
|
|
5
|
+
* The one place a move plan turns into a write.
|
|
6
|
+
*
|
|
7
|
+
* A move that renames nothing commits without a confirmed plan, because there is nothing to
|
|
8
|
+
* confirm. A move that renames something needs one, and a confirmed plan must equal the plan
|
|
9
|
+
* recomputed here, or nothing is written and the fresh plan goes back to be confirmed. A move of
|
|
10
|
+
* nothing writes nothing.
|
|
11
|
+
*/
|
|
12
|
+
function commitFoldersMove(view, planned, confirmedPlan) {
|
|
13
|
+
if (!planned.ok) return { result: {
|
|
14
|
+
ok: false,
|
|
15
|
+
reason: "cannot-plan",
|
|
16
|
+
issues: planned.issues
|
|
17
|
+
} };
|
|
18
|
+
if (confirmedPlan !== void 0) {
|
|
19
|
+
if (!require_planner.foldersMovePlansEqual(planned.plan, confirmedPlan)) return { result: {
|
|
20
|
+
ok: false,
|
|
21
|
+
reason: "plan-changed",
|
|
22
|
+
plan: planned.plan
|
|
23
|
+
} };
|
|
24
|
+
} else if (planned.plan.entries.some((entry) => entry.renamed)) return { result: {
|
|
25
|
+
ok: false,
|
|
26
|
+
reason: "needs-confirmation",
|
|
27
|
+
plan: planned.plan
|
|
28
|
+
} };
|
|
29
|
+
if (planned.plan.entries.length === 0) return { result: {
|
|
30
|
+
ok: true,
|
|
31
|
+
plan: planned.plan
|
|
32
|
+
} };
|
|
33
|
+
const applied = require_planner.applyFoldersMove(view, planned.plan);
|
|
34
|
+
return {
|
|
35
|
+
result: {
|
|
36
|
+
ok: true,
|
|
37
|
+
plan: planned.plan
|
|
38
|
+
},
|
|
39
|
+
document: applied.document,
|
|
40
|
+
labelRenames: applied.labelRenames
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The one place a removal turns into a write.
|
|
45
|
+
*
|
|
46
|
+
* A deletion always needs a confirmed removal, however little it destroys: unlike a move, it has
|
|
47
|
+
* no harmless outcome to fall back on.
|
|
48
|
+
*/
|
|
49
|
+
function commitFoldersRemoval(view, planned, confirmed) {
|
|
50
|
+
if (!planned.ok) return { result: {
|
|
51
|
+
ok: false,
|
|
52
|
+
reason: "cannot-plan",
|
|
53
|
+
issues: planned.issues
|
|
54
|
+
} };
|
|
55
|
+
if (confirmed === void 0) return { result: {
|
|
56
|
+
ok: false,
|
|
57
|
+
reason: "needs-confirmation",
|
|
58
|
+
removal: planned.removal
|
|
59
|
+
} };
|
|
60
|
+
if (!require_removal.foldersRemovalsEqual(planned.removal, confirmed)) return { result: {
|
|
61
|
+
ok: false,
|
|
62
|
+
reason: "plan-changed",
|
|
63
|
+
removal: planned.removal
|
|
64
|
+
} };
|
|
65
|
+
return {
|
|
66
|
+
result: {
|
|
67
|
+
ok: true,
|
|
68
|
+
removal: planned.removal
|
|
69
|
+
},
|
|
70
|
+
document: require_removal.applyFoldersRemoval(view, planned.removal),
|
|
71
|
+
deletedProjects: planned.removal.projects,
|
|
72
|
+
deletedTemplates: planned.removal.templates
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
exports.commitFoldersMove = commitFoldersMove;
|
|
77
|
+
exports.commitFoldersRemoval = commitFoldersRemoval;
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=commit.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit.cjs","names":["foldersMovePlansEqual","applyFoldersMove","foldersRemovalsEqual","applyFoldersRemoval"],"sources":["../../src/folders/commit.ts"],"sourcesContent":["import type { ProjectId, TemplateId } from \"@milaboratories/pl-model-common\";\nimport type { FoldersDocument } from \"./document\";\nimport type {\n FoldersLabelRename,\n FoldersMoveIssue,\n FoldersMovePlan,\n FoldersMovePlanResult,\n} from \"./planner\";\nimport { applyFoldersMove, foldersMovePlansEqual } from \"./planner\";\nimport type { FoldersRemoval, FoldersRemovalIssue, FoldersRemovalPlanResult } from \"./removal\";\nimport { applyFoldersRemoval, foldersRemovalsEqual } from \"./removal\";\nimport type { FoldersView } from \"./view\";\n\n/** What one attempt of a folder write decided to do. */\nexport interface FoldersEdit<T> {\n /** Value handed back to the caller, whether or not anything is written. */\n readonly result: T;\n /** The document to persist. Absent means write nothing — a refused plan, or a no-op. */\n readonly document?: FoldersDocument;\n /** Project and template labels the edit changes; their names live in their own metadata. */\n readonly labelRenames?: readonly FoldersLabelRename[];\n /** Projects the edit destroys. A folder deletion is the only edit that sets this. */\n readonly deletedProjects?: readonly ProjectId[];\n /** Templates the edit destroys. A folder deletion is the only edit that sets this. */\n readonly deletedTemplates?: readonly TemplateId[];\n}\n\n/**\n * What a move did.\n *\n * `plan-changed` is the whole point of the confirm step: the plan was recomputed inside the write\n * transaction, it no longer matches the one the user confirmed, and nothing was written. The\n * fresh plan comes back to be confirmed again, so a confirmation dialog cannot lie about what an\n * item will end up called. `needs-confirmation` is the same guarantee reached from the other\n * side — a caller that supplied no plan at all for a move that renames something.\n *\n * All four cases have to be handled by whoever calls a move, which is why this type lives in this\n * package rather than in the node package.\n */\nexport type FoldersMoveOutcome =\n | { readonly ok: true; readonly plan: FoldersMovePlan }\n | { readonly ok: false; readonly reason: \"plan-changed\"; readonly plan: FoldersMovePlan }\n | {\n readonly ok: false;\n readonly reason: \"needs-confirmation\";\n readonly plan: FoldersMovePlan;\n }\n | {\n readonly ok: false;\n readonly reason: \"cannot-plan\";\n readonly issues: readonly FoldersMoveIssue[];\n };\n\n/** What a folder deletion did. */\nexport type FoldersRemovalOutcome =\n | { readonly ok: true; readonly removal: FoldersRemoval }\n | {\n readonly ok: false;\n readonly reason: \"plan-changed\";\n readonly removal: FoldersRemoval;\n }\n | {\n readonly ok: false;\n readonly reason: \"needs-confirmation\";\n readonly removal: FoldersRemoval;\n }\n | {\n readonly ok: false;\n readonly reason: \"cannot-plan\";\n readonly issues: readonly FoldersRemovalIssue[];\n };\n\n/**\n * The one place a move plan turns into a write.\n *\n * A move that renames nothing commits without a confirmed plan, because there is nothing to\n * confirm. A move that renames something needs one, and a confirmed plan must equal the plan\n * recomputed here, or nothing is written and the fresh plan goes back to be confirmed. A move of\n * nothing writes nothing.\n */\nexport function commitFoldersMove(\n view: FoldersView,\n planned: FoldersMovePlanResult,\n confirmedPlan: FoldersMovePlan | undefined,\n): FoldersEdit<FoldersMoveOutcome> {\n if (!planned.ok) return { result: { ok: false, reason: \"cannot-plan\", issues: planned.issues } };\n\n if (confirmedPlan !== undefined) {\n if (!foldersMovePlansEqual(planned.plan, confirmedPlan))\n return { result: { ok: false, reason: \"plan-changed\", plan: planned.plan } };\n } else if (planned.plan.entries.some((entry) => entry.renamed)) {\n return { result: { ok: false, reason: \"needs-confirmation\", plan: planned.plan } };\n }\n\n // A move of nothing changes nothing. Without this it still mints a value and re-points the\n // field, so an empty selection would conflict with whatever else is editing the tree and would\n // persist a heal nobody asked for.\n if (planned.plan.entries.length === 0) return { result: { ok: true, plan: planned.plan } };\n\n const applied = applyFoldersMove(view, planned.plan);\n return {\n result: { ok: true, plan: planned.plan },\n document: applied.document,\n labelRenames: applied.labelRenames,\n };\n}\n\n/**\n * The one place a removal turns into a write.\n *\n * A deletion always needs a confirmed removal, however little it destroys: unlike a move, it has\n * no harmless outcome to fall back on.\n */\nexport function commitFoldersRemoval(\n view: FoldersView,\n planned: FoldersRemovalPlanResult,\n confirmed: FoldersRemoval | undefined,\n): FoldersEdit<FoldersRemovalOutcome> {\n if (!planned.ok) return { result: { ok: false, reason: \"cannot-plan\", issues: planned.issues } };\n\n if (confirmed === undefined)\n return { result: { ok: false, reason: \"needs-confirmation\", removal: planned.removal } };\n\n if (!foldersRemovalsEqual(planned.removal, confirmed))\n return { result: { ok: false, reason: \"plan-changed\", removal: planned.removal } };\n\n return {\n result: { ok: true, removal: planned.removal },\n document: applyFoldersRemoval(view, planned.removal),\n deletedProjects: planned.removal.projects,\n deletedTemplates: planned.removal.templates,\n };\n}\n"],"mappings":";;;;;;;;;;;AAgFA,SAAgB,kBACd,MACA,SACA,eACiC;CACjC,IAAI,CAAC,QAAQ,IAAI,OAAO,EAAE,QAAQ;EAAE,IAAI;EAAO,QAAQ;EAAe,QAAQ,QAAQ;CAAO,EAAE;CAE/F,IAAI,kBAAkB,KAAA;MAChB,CAACA,gBAAAA,sBAAsB,QAAQ,MAAM,aAAa,GACpD,OAAO,EAAE,QAAQ;GAAE,IAAI;GAAO,QAAQ;GAAgB,MAAM,QAAQ;EAAK,EAAE;CAAA,OACxE,IAAI,QAAQ,KAAK,QAAQ,MAAM,UAAU,MAAM,OAAO,GAC3D,OAAO,EAAE,QAAQ;EAAE,IAAI;EAAO,QAAQ;EAAsB,MAAM,QAAQ;CAAK,EAAE;CAMnF,IAAI,QAAQ,KAAK,QAAQ,WAAW,GAAG,OAAO,EAAE,QAAQ;EAAE,IAAI;EAAM,MAAM,QAAQ;CAAK,EAAE;CAEzF,MAAM,UAAUC,gBAAAA,iBAAiB,MAAM,QAAQ,IAAI;CACnD,OAAO;EACL,QAAQ;GAAE,IAAI;GAAM,MAAM,QAAQ;EAAK;EACvC,UAAU,QAAQ;EAClB,cAAc,QAAQ;CACxB;AACF;;;;;;;AAQA,SAAgB,qBACd,MACA,SACA,WACoC;CACpC,IAAI,CAAC,QAAQ,IAAI,OAAO,EAAE,QAAQ;EAAE,IAAI;EAAO,QAAQ;EAAe,QAAQ,QAAQ;CAAO,EAAE;CAE/F,IAAI,cAAc,KAAA,GAChB,OAAO,EAAE,QAAQ;EAAE,IAAI;EAAO,QAAQ;EAAsB,SAAS,QAAQ;CAAQ,EAAE;CAEzF,IAAI,CAACC,gBAAAA,qBAAqB,QAAQ,SAAS,SAAS,GAClD,OAAO,EAAE,QAAQ;EAAE,IAAI;EAAO,QAAQ;EAAgB,SAAS,QAAQ;CAAQ,EAAE;CAEnF,OAAO;EACL,QAAQ;GAAE,IAAI;GAAM,SAAS,QAAQ;EAAQ;EAC7C,UAAUC,gBAAAA,oBAAoB,MAAM,QAAQ,OAAO;EACnD,iBAAiB,QAAQ,QAAQ;EACjC,kBAAkB,QAAQ,QAAQ;CACpC;AACF"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { FoldersDocument } from "./document.js";
|
|
2
|
+
import { FoldersLabelRename, FoldersMoveIssue, FoldersMovePlan, FoldersMovePlanResult } from "./planner.js";
|
|
3
|
+
import { FoldersView } from "./view.js";
|
|
4
|
+
import { FoldersRemoval, FoldersRemovalIssue, FoldersRemovalPlanResult } from "./removal.js";
|
|
5
|
+
import { ProjectId, TemplateId } from "@milaboratories/pl-model-common";
|
|
6
|
+
//#region src/folders/commit.d.ts
|
|
7
|
+
/** What one attempt of a folder write decided to do. */
|
|
8
|
+
export interface FoldersEdit<T> {
|
|
9
|
+
/** Value handed back to the caller, whether or not anything is written. */
|
|
10
|
+
readonly result: T;
|
|
11
|
+
/** The document to persist. Absent means write nothing — a refused plan, or a no-op. */
|
|
12
|
+
readonly document?: FoldersDocument;
|
|
13
|
+
/** Project and template labels the edit changes; their names live in their own metadata. */
|
|
14
|
+
readonly labelRenames?: readonly FoldersLabelRename[];
|
|
15
|
+
/** Projects the edit destroys. A folder deletion is the only edit that sets this. */
|
|
16
|
+
readonly deletedProjects?: readonly ProjectId[];
|
|
17
|
+
/** Templates the edit destroys. A folder deletion is the only edit that sets this. */
|
|
18
|
+
readonly deletedTemplates?: readonly TemplateId[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* What a move did.
|
|
22
|
+
*
|
|
23
|
+
* `plan-changed` is the whole point of the confirm step: the plan was recomputed inside the write
|
|
24
|
+
* transaction, it no longer matches the one the user confirmed, and nothing was written. The
|
|
25
|
+
* fresh plan comes back to be confirmed again, so a confirmation dialog cannot lie about what an
|
|
26
|
+
* item will end up called. `needs-confirmation` is the same guarantee reached from the other
|
|
27
|
+
* side — a caller that supplied no plan at all for a move that renames something.
|
|
28
|
+
*
|
|
29
|
+
* All four cases have to be handled by whoever calls a move, which is why this type lives in this
|
|
30
|
+
* package rather than in the node package.
|
|
31
|
+
*/
|
|
32
|
+
export type FoldersMoveOutcome = {
|
|
33
|
+
readonly ok: true;
|
|
34
|
+
readonly plan: FoldersMovePlan;
|
|
35
|
+
} | {
|
|
36
|
+
readonly ok: false;
|
|
37
|
+
readonly reason: "plan-changed";
|
|
38
|
+
readonly plan: FoldersMovePlan;
|
|
39
|
+
} | {
|
|
40
|
+
readonly ok: false;
|
|
41
|
+
readonly reason: "needs-confirmation";
|
|
42
|
+
readonly plan: FoldersMovePlan;
|
|
43
|
+
} | {
|
|
44
|
+
readonly ok: false;
|
|
45
|
+
readonly reason: "cannot-plan";
|
|
46
|
+
readonly issues: readonly FoldersMoveIssue[];
|
|
47
|
+
};
|
|
48
|
+
/** What a folder deletion did. */
|
|
49
|
+
export type FoldersRemovalOutcome = {
|
|
50
|
+
readonly ok: true;
|
|
51
|
+
readonly removal: FoldersRemoval;
|
|
52
|
+
} | {
|
|
53
|
+
readonly ok: false;
|
|
54
|
+
readonly reason: "plan-changed";
|
|
55
|
+
readonly removal: FoldersRemoval;
|
|
56
|
+
} | {
|
|
57
|
+
readonly ok: false;
|
|
58
|
+
readonly reason: "needs-confirmation";
|
|
59
|
+
readonly removal: FoldersRemoval;
|
|
60
|
+
} | {
|
|
61
|
+
readonly ok: false;
|
|
62
|
+
readonly reason: "cannot-plan";
|
|
63
|
+
readonly issues: readonly FoldersRemovalIssue[];
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* The one place a move plan turns into a write.
|
|
67
|
+
*
|
|
68
|
+
* A move that renames nothing commits without a confirmed plan, because there is nothing to
|
|
69
|
+
* confirm. A move that renames something needs one, and a confirmed plan must equal the plan
|
|
70
|
+
* recomputed here, or nothing is written and the fresh plan goes back to be confirmed. A move of
|
|
71
|
+
* nothing writes nothing.
|
|
72
|
+
*/
|
|
73
|
+
export declare function commitFoldersMove(view: FoldersView, planned: FoldersMovePlanResult, confirmedPlan: FoldersMovePlan | undefined): FoldersEdit<FoldersMoveOutcome>;
|
|
74
|
+
/**
|
|
75
|
+
* The one place a removal turns into a write.
|
|
76
|
+
*
|
|
77
|
+
* A deletion always needs a confirmed removal, however little it destroys: unlike a move, it has
|
|
78
|
+
* no harmless outcome to fall back on.
|
|
79
|
+
*/
|
|
80
|
+
export declare function commitFoldersRemoval(view: FoldersView, planned: FoldersRemovalPlanResult, confirmed: FoldersRemoval | undefined): FoldersEdit<FoldersRemovalOutcome>;
|
|
81
|
+
//#endregion
|
|
82
|
+
//# sourceMappingURL=commit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit.d.ts","names":[],"sources":["../../src/folders/commit.ts"],"mappings":";;;;;;;iBAciB,YAAY;;WAElB,QAAQ;;WAER,WAAW;;WAEX,wBAAwB;;WAExB,2BAA2B;;WAE3B,4BAA4B;;;;;;;;;;;;;;YAe3B;WACG;WAAmB,MAAM;;WACzB;WAAoB;WAAiC,MAAM;;WAE3D;WACA;WACA,MAAM;;WAGN;WACA;WACA,iBAAiB;;;YAIpB;WACG;WAAmB,SAAS;;WAE5B;WACA;WACA,SAAS;;WAGT;WACA;WACA,SAAS;;WAGT;WACA;WACA,iBAAiB;;;;;;;;;;wBAWhB,kBACd,MAAM,aACN,SAAS,uBACT,eAAe,8BACd,YAAY;;;;;;;wBA6BC,qBACd,MAAM,aACN,SAAS,0BACT,WAAW,6BACV,YAAY"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { applyFoldersMove, foldersMovePlansEqual } from "./planner.js";
|
|
2
|
+
import { applyFoldersRemoval, foldersRemovalsEqual } from "./removal.js";
|
|
3
|
+
//#region src/folders/commit.ts
|
|
4
|
+
/**
|
|
5
|
+
* The one place a move plan turns into a write.
|
|
6
|
+
*
|
|
7
|
+
* A move that renames nothing commits without a confirmed plan, because there is nothing to
|
|
8
|
+
* confirm. A move that renames something needs one, and a confirmed plan must equal the plan
|
|
9
|
+
* recomputed here, or nothing is written and the fresh plan goes back to be confirmed. A move of
|
|
10
|
+
* nothing writes nothing.
|
|
11
|
+
*/
|
|
12
|
+
function commitFoldersMove(view, planned, confirmedPlan) {
|
|
13
|
+
if (!planned.ok) return { result: {
|
|
14
|
+
ok: false,
|
|
15
|
+
reason: "cannot-plan",
|
|
16
|
+
issues: planned.issues
|
|
17
|
+
} };
|
|
18
|
+
if (confirmedPlan !== void 0) {
|
|
19
|
+
if (!foldersMovePlansEqual(planned.plan, confirmedPlan)) return { result: {
|
|
20
|
+
ok: false,
|
|
21
|
+
reason: "plan-changed",
|
|
22
|
+
plan: planned.plan
|
|
23
|
+
} };
|
|
24
|
+
} else if (planned.plan.entries.some((entry) => entry.renamed)) return { result: {
|
|
25
|
+
ok: false,
|
|
26
|
+
reason: "needs-confirmation",
|
|
27
|
+
plan: planned.plan
|
|
28
|
+
} };
|
|
29
|
+
if (planned.plan.entries.length === 0) return { result: {
|
|
30
|
+
ok: true,
|
|
31
|
+
plan: planned.plan
|
|
32
|
+
} };
|
|
33
|
+
const applied = applyFoldersMove(view, planned.plan);
|
|
34
|
+
return {
|
|
35
|
+
result: {
|
|
36
|
+
ok: true,
|
|
37
|
+
plan: planned.plan
|
|
38
|
+
},
|
|
39
|
+
document: applied.document,
|
|
40
|
+
labelRenames: applied.labelRenames
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The one place a removal turns into a write.
|
|
45
|
+
*
|
|
46
|
+
* A deletion always needs a confirmed removal, however little it destroys: unlike a move, it has
|
|
47
|
+
* no harmless outcome to fall back on.
|
|
48
|
+
*/
|
|
49
|
+
function commitFoldersRemoval(view, planned, confirmed) {
|
|
50
|
+
if (!planned.ok) return { result: {
|
|
51
|
+
ok: false,
|
|
52
|
+
reason: "cannot-plan",
|
|
53
|
+
issues: planned.issues
|
|
54
|
+
} };
|
|
55
|
+
if (confirmed === void 0) return { result: {
|
|
56
|
+
ok: false,
|
|
57
|
+
reason: "needs-confirmation",
|
|
58
|
+
removal: planned.removal
|
|
59
|
+
} };
|
|
60
|
+
if (!foldersRemovalsEqual(planned.removal, confirmed)) return { result: {
|
|
61
|
+
ok: false,
|
|
62
|
+
reason: "plan-changed",
|
|
63
|
+
removal: planned.removal
|
|
64
|
+
} };
|
|
65
|
+
return {
|
|
66
|
+
result: {
|
|
67
|
+
ok: true,
|
|
68
|
+
removal: planned.removal
|
|
69
|
+
},
|
|
70
|
+
document: applyFoldersRemoval(view, planned.removal),
|
|
71
|
+
deletedProjects: planned.removal.projects,
|
|
72
|
+
deletedTemplates: planned.removal.templates
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
export { commitFoldersMove, commitFoldersRemoval };
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=commit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit.js","names":[],"sources":["../../src/folders/commit.ts"],"sourcesContent":["import type { ProjectId, TemplateId } from \"@milaboratories/pl-model-common\";\nimport type { FoldersDocument } from \"./document\";\nimport type {\n FoldersLabelRename,\n FoldersMoveIssue,\n FoldersMovePlan,\n FoldersMovePlanResult,\n} from \"./planner\";\nimport { applyFoldersMove, foldersMovePlansEqual } from \"./planner\";\nimport type { FoldersRemoval, FoldersRemovalIssue, FoldersRemovalPlanResult } from \"./removal\";\nimport { applyFoldersRemoval, foldersRemovalsEqual } from \"./removal\";\nimport type { FoldersView } from \"./view\";\n\n/** What one attempt of a folder write decided to do. */\nexport interface FoldersEdit<T> {\n /** Value handed back to the caller, whether or not anything is written. */\n readonly result: T;\n /** The document to persist. Absent means write nothing — a refused plan, or a no-op. */\n readonly document?: FoldersDocument;\n /** Project and template labels the edit changes; their names live in their own metadata. */\n readonly labelRenames?: readonly FoldersLabelRename[];\n /** Projects the edit destroys. A folder deletion is the only edit that sets this. */\n readonly deletedProjects?: readonly ProjectId[];\n /** Templates the edit destroys. A folder deletion is the only edit that sets this. */\n readonly deletedTemplates?: readonly TemplateId[];\n}\n\n/**\n * What a move did.\n *\n * `plan-changed` is the whole point of the confirm step: the plan was recomputed inside the write\n * transaction, it no longer matches the one the user confirmed, and nothing was written. The\n * fresh plan comes back to be confirmed again, so a confirmation dialog cannot lie about what an\n * item will end up called. `needs-confirmation` is the same guarantee reached from the other\n * side — a caller that supplied no plan at all for a move that renames something.\n *\n * All four cases have to be handled by whoever calls a move, which is why this type lives in this\n * package rather than in the node package.\n */\nexport type FoldersMoveOutcome =\n | { readonly ok: true; readonly plan: FoldersMovePlan }\n | { readonly ok: false; readonly reason: \"plan-changed\"; readonly plan: FoldersMovePlan }\n | {\n readonly ok: false;\n readonly reason: \"needs-confirmation\";\n readonly plan: FoldersMovePlan;\n }\n | {\n readonly ok: false;\n readonly reason: \"cannot-plan\";\n readonly issues: readonly FoldersMoveIssue[];\n };\n\n/** What a folder deletion did. */\nexport type FoldersRemovalOutcome =\n | { readonly ok: true; readonly removal: FoldersRemoval }\n | {\n readonly ok: false;\n readonly reason: \"plan-changed\";\n readonly removal: FoldersRemoval;\n }\n | {\n readonly ok: false;\n readonly reason: \"needs-confirmation\";\n readonly removal: FoldersRemoval;\n }\n | {\n readonly ok: false;\n readonly reason: \"cannot-plan\";\n readonly issues: readonly FoldersRemovalIssue[];\n };\n\n/**\n * The one place a move plan turns into a write.\n *\n * A move that renames nothing commits without a confirmed plan, because there is nothing to\n * confirm. A move that renames something needs one, and a confirmed plan must equal the plan\n * recomputed here, or nothing is written and the fresh plan goes back to be confirmed. A move of\n * nothing writes nothing.\n */\nexport function commitFoldersMove(\n view: FoldersView,\n planned: FoldersMovePlanResult,\n confirmedPlan: FoldersMovePlan | undefined,\n): FoldersEdit<FoldersMoveOutcome> {\n if (!planned.ok) return { result: { ok: false, reason: \"cannot-plan\", issues: planned.issues } };\n\n if (confirmedPlan !== undefined) {\n if (!foldersMovePlansEqual(planned.plan, confirmedPlan))\n return { result: { ok: false, reason: \"plan-changed\", plan: planned.plan } };\n } else if (planned.plan.entries.some((entry) => entry.renamed)) {\n return { result: { ok: false, reason: \"needs-confirmation\", plan: planned.plan } };\n }\n\n // A move of nothing changes nothing. Without this it still mints a value and re-points the\n // field, so an empty selection would conflict with whatever else is editing the tree and would\n // persist a heal nobody asked for.\n if (planned.plan.entries.length === 0) return { result: { ok: true, plan: planned.plan } };\n\n const applied = applyFoldersMove(view, planned.plan);\n return {\n result: { ok: true, plan: planned.plan },\n document: applied.document,\n labelRenames: applied.labelRenames,\n };\n}\n\n/**\n * The one place a removal turns into a write.\n *\n * A deletion always needs a confirmed removal, however little it destroys: unlike a move, it has\n * no harmless outcome to fall back on.\n */\nexport function commitFoldersRemoval(\n view: FoldersView,\n planned: FoldersRemovalPlanResult,\n confirmed: FoldersRemoval | undefined,\n): FoldersEdit<FoldersRemovalOutcome> {\n if (!planned.ok) return { result: { ok: false, reason: \"cannot-plan\", issues: planned.issues } };\n\n if (confirmed === undefined)\n return { result: { ok: false, reason: \"needs-confirmation\", removal: planned.removal } };\n\n if (!foldersRemovalsEqual(planned.removal, confirmed))\n return { result: { ok: false, reason: \"plan-changed\", removal: planned.removal } };\n\n return {\n result: { ok: true, removal: planned.removal },\n document: applyFoldersRemoval(view, planned.removal),\n deletedProjects: planned.removal.projects,\n deletedTemplates: planned.removal.templates,\n };\n}\n"],"mappings":";;;;;;;;;;;AAgFA,SAAgB,kBACd,MACA,SACA,eACiC;CACjC,IAAI,CAAC,QAAQ,IAAI,OAAO,EAAE,QAAQ;EAAE,IAAI;EAAO,QAAQ;EAAe,QAAQ,QAAQ;CAAO,EAAE;CAE/F,IAAI,kBAAkB,KAAA;MAChB,CAAC,sBAAsB,QAAQ,MAAM,aAAa,GACpD,OAAO,EAAE,QAAQ;GAAE,IAAI;GAAO,QAAQ;GAAgB,MAAM,QAAQ;EAAK,EAAE;CAAA,OACxE,IAAI,QAAQ,KAAK,QAAQ,MAAM,UAAU,MAAM,OAAO,GAC3D,OAAO,EAAE,QAAQ;EAAE,IAAI;EAAO,QAAQ;EAAsB,MAAM,QAAQ;CAAK,EAAE;CAMnF,IAAI,QAAQ,KAAK,QAAQ,WAAW,GAAG,OAAO,EAAE,QAAQ;EAAE,IAAI;EAAM,MAAM,QAAQ;CAAK,EAAE;CAEzF,MAAM,UAAU,iBAAiB,MAAM,QAAQ,IAAI;CACnD,OAAO;EACL,QAAQ;GAAE,IAAI;GAAM,MAAM,QAAQ;EAAK;EACvC,UAAU,QAAQ;EAClB,cAAc,QAAQ;CACxB;AACF;;;;;;;AAQA,SAAgB,qBACd,MACA,SACA,WACoC;CACpC,IAAI,CAAC,QAAQ,IAAI,OAAO,EAAE,QAAQ;EAAE,IAAI;EAAO,QAAQ;EAAe,QAAQ,QAAQ;CAAO,EAAE;CAE/F,IAAI,cAAc,KAAA,GAChB,OAAO,EAAE,QAAQ;EAAE,IAAI;EAAO,QAAQ;EAAsB,SAAS,QAAQ;CAAQ,EAAE;CAEzF,IAAI,CAAC,qBAAqB,QAAQ,SAAS,SAAS,GAClD,OAAO,EAAE,QAAQ;EAAE,IAAI;EAAO,QAAQ;EAAgB,SAAS,QAAQ;CAAQ,EAAE;CAEnF,OAAO;EACL,QAAQ;GAAE,IAAI;GAAM,SAAS,QAAQ;EAAQ;EAC7C,UAAU,oBAAoB,MAAM,QAAQ,OAAO;EACnD,iBAAiB,QAAQ,QAAQ;EACjC,kBAAkB,QAAQ,QAAQ;CACpC;AACF"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
const require_document = require("./document.cjs");
|
|
2
|
+
//#region src/folders/decode.ts
|
|
3
|
+
/**
|
|
4
|
+
* Decode whatever the store holds for the folder document.
|
|
5
|
+
*
|
|
6
|
+
* An absent document is a user with no folders, and is writable. A document that is present but
|
|
7
|
+
* carries no bytes, or empty ones, is not the same thing: it exists and cannot be read here — a
|
|
8
|
+
* newer build keeping the tree in another shape, or a value this build cannot fetch — so it reads
|
|
9
|
+
* as no folders and is **not** writable, because writing an empty tree over one that is merely
|
|
10
|
+
* unreadable from this build destroys it.
|
|
11
|
+
*/
|
|
12
|
+
function decodeStoredFoldersDocument(stored) {
|
|
13
|
+
if (!stored.present) return readable(require_document.emptyFoldersDocument());
|
|
14
|
+
if (stored.raw === void 0 || stored.raw === "") return unreadable("the folder document is stored in a shape this build cannot read");
|
|
15
|
+
return decodeFoldersDocument(stored.raw);
|
|
16
|
+
}
|
|
17
|
+
/** Decode the stored JSON of a document that is present. */
|
|
18
|
+
function decodeFoldersDocument(raw) {
|
|
19
|
+
let parsed;
|
|
20
|
+
try {
|
|
21
|
+
parsed = JSON.parse(raw);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
return unreadable(`the folder document is not valid JSON: ${errorText(error)}`);
|
|
24
|
+
}
|
|
25
|
+
return decodeFoldersValue(parsed);
|
|
26
|
+
}
|
|
27
|
+
/** Serialise a document for storage. */
|
|
28
|
+
function encodeFoldersDocument(document) {
|
|
29
|
+
return JSON.stringify(document);
|
|
30
|
+
}
|
|
31
|
+
function decodeFoldersValue(value) {
|
|
32
|
+
if (!isMapping(value)) return unreadable("the folder document is not an object");
|
|
33
|
+
const version = value.schemaVersion;
|
|
34
|
+
if (typeof version !== "number" || !Number.isInteger(version) || version < 1) return unreadable("the folder document carries no usable schema version");
|
|
35
|
+
if (version > 1) return {
|
|
36
|
+
document: require_document.emptyFoldersDocument(),
|
|
37
|
+
writable: false,
|
|
38
|
+
problem: {
|
|
39
|
+
kind: "newer-schema",
|
|
40
|
+
documentSchemaVersion: version,
|
|
41
|
+
message: `the folder document was written by a newer version of the application (schema ${version}, this build understands 1)`
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const result = require_document.FoldersDocument.safeParse(value);
|
|
45
|
+
if (!result.success) return unreadable(`the folder document does not match schema 1: ` + result.error.issues.map(formatIssue).join("; "));
|
|
46
|
+
return readable(result.data);
|
|
47
|
+
}
|
|
48
|
+
function readable(document) {
|
|
49
|
+
return {
|
|
50
|
+
document,
|
|
51
|
+
writable: true
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function unreadable(message) {
|
|
55
|
+
return {
|
|
56
|
+
document: require_document.emptyFoldersDocument(),
|
|
57
|
+
writable: false,
|
|
58
|
+
problem: {
|
|
59
|
+
kind: "unreadable",
|
|
60
|
+
message
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function isMapping(value) {
|
|
65
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
66
|
+
}
|
|
67
|
+
function formatIssue(issue) {
|
|
68
|
+
const path = issue.path.map((segment) => String(segment)).join(".");
|
|
69
|
+
return path === "" ? issue.message : `${path}: ${issue.message}`;
|
|
70
|
+
}
|
|
71
|
+
function errorText(error) {
|
|
72
|
+
return error instanceof Error ? error.message : String(error);
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
exports.decodeFoldersDocument = decodeFoldersDocument;
|
|
76
|
+
exports.decodeStoredFoldersDocument = decodeStoredFoldersDocument;
|
|
77
|
+
exports.encodeFoldersDocument = encodeFoldersDocument;
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=decode.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode.cjs","names":["emptyFoldersDocument","FoldersDocument"],"sources":["../../src/folders/decode.ts"],"sourcesContent":["import { FOLDERS_SCHEMA_VERSION, FoldersDocument, emptyFoldersDocument } from \"./document\";\n\n/** Why a stored document could not be read as it stands. */\nexport type FoldersDocumentProblem =\n | {\n readonly kind: \"newer-schema\";\n /** Version found in the document, which is higher than this build understands. */\n readonly documentSchemaVersion: number;\n readonly message: string;\n }\n | {\n readonly kind: \"unreadable\";\n readonly message: string;\n };\n\n/**\n * A stored document as this build sees it.\n *\n * A document written by a newer build, or one that cannot be parsed at all, reads as no folders\n * so that the project list still renders, and turns `writable` off: an old build that both\n * degraded the read and kept writing would silently replace a newer build's tree with its own\n * truncated view of it. Every refusal says why.\n */\nexport type FoldersDecoded =\n | {\n readonly document: FoldersDocument;\n readonly writable: true;\n readonly problem?: undefined;\n }\n | {\n readonly document: FoldersDocument;\n /** Every folder write must be refused. */\n readonly writable: false;\n readonly problem: FoldersDocumentProblem;\n };\n\n/**\n * What the store holds for the folder document: nothing at all, or a stored value and its bytes\n * when they could be obtained.\n */\nexport type FoldersStoredDocument =\n | { readonly present: false }\n | {\n readonly present: true;\n /** The stored JSON; undefined when the value carries no bytes this build can fetch. */\n readonly raw: string | undefined;\n };\n\n/**\n * Decode whatever the store holds for the folder document.\n *\n * An absent document is a user with no folders, and is writable. A document that is present but\n * carries no bytes, or empty ones, is not the same thing: it exists and cannot be read here — a\n * newer build keeping the tree in another shape, or a value this build cannot fetch — so it reads\n * as no folders and is **not** writable, because writing an empty tree over one that is merely\n * unreadable from this build destroys it.\n */\nexport function decodeStoredFoldersDocument(stored: FoldersStoredDocument): FoldersDecoded {\n if (!stored.present) return readable(emptyFoldersDocument());\n if (stored.raw === undefined || stored.raw === \"\")\n return unreadable(\"the folder document is stored in a shape this build cannot read\");\n return decodeFoldersDocument(stored.raw);\n}\n\n/** Decode the stored JSON of a document that is present. */\nexport function decodeFoldersDocument(raw: string): FoldersDecoded {\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch (error: unknown) {\n return unreadable(`the folder document is not valid JSON: ${errorText(error)}`);\n }\n\n return decodeFoldersValue(parsed);\n}\n\n/** Serialise a document for storage. */\nexport function encodeFoldersDocument(document: FoldersDocument): string {\n return JSON.stringify(document);\n}\n\n//\n// Internals\n//\n\nfunction decodeFoldersValue(value: unknown): FoldersDecoded {\n if (!isMapping(value)) return unreadable(\"the folder document is not an object\");\n\n const version = value.schemaVersion;\n if (typeof version !== \"number\" || !Number.isInteger(version) || version < 1)\n return unreadable(\"the folder document carries no usable schema version\");\n\n if (version > FOLDERS_SCHEMA_VERSION)\n return {\n document: emptyFoldersDocument(),\n writable: false,\n problem: {\n kind: \"newer-schema\",\n documentSchemaVersion: version,\n message:\n `the folder document was written by a newer version of the application ` +\n `(schema ${version}, this build understands ${FOLDERS_SCHEMA_VERSION})`,\n },\n };\n\n const result = FoldersDocument.safeParse(value);\n if (!result.success)\n return unreadable(\n `the folder document does not match schema ${FOLDERS_SCHEMA_VERSION}: ` +\n result.error.issues.map(formatIssue).join(\"; \"),\n );\n\n return readable(result.data);\n}\n\nfunction readable(document: FoldersDocument): FoldersDecoded {\n return { document, writable: true };\n}\n\nfunction unreadable(message: string): FoldersDecoded {\n return {\n document: emptyFoldersDocument(),\n writable: false,\n problem: { kind: \"unreadable\", message },\n };\n}\n\nfunction isMapping(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction formatIssue(issue: {\n readonly path: readonly PropertyKey[];\n readonly message: string;\n}): string {\n const path = issue.path.map((segment) => String(segment)).join(\".\");\n return path === \"\" ? issue.message : `${path}: ${issue.message}`;\n}\n\nfunction errorText(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n"],"mappings":";;;;;;;;;;;AAyDA,SAAgB,4BAA4B,QAA+C;CACzF,IAAI,CAAC,OAAO,SAAS,OAAO,SAASA,iBAAAA,qBAAqB,CAAC;CAC3D,IAAI,OAAO,QAAQ,KAAA,KAAa,OAAO,QAAQ,IAC7C,OAAO,WAAW,iEAAiE;CACrF,OAAO,sBAAsB,OAAO,GAAG;AACzC;;AAGA,SAAgB,sBAAsB,KAA6B;CACjE,IAAI;CACJ,IAAI;EACF,SAAS,KAAK,MAAM,GAAG;CACzB,SAAS,OAAgB;EACvB,OAAO,WAAW,0CAA0C,UAAU,KAAK,GAAG;CAChF;CAEA,OAAO,mBAAmB,MAAM;AAClC;;AAGA,SAAgB,sBAAsB,UAAmC;CACvE,OAAO,KAAK,UAAU,QAAQ;AAChC;AAMA,SAAS,mBAAmB,OAAgC;CAC1D,IAAI,CAAC,UAAU,KAAK,GAAG,OAAO,WAAW,sCAAsC;CAE/E,MAAM,UAAU,MAAM;CACtB,IAAI,OAAO,YAAY,YAAY,CAAC,OAAO,UAAU,OAAO,KAAK,UAAU,GACzE,OAAO,WAAW,sDAAsD;CAE1E,IAAI,UAAA,GACF,OAAO;EACL,UAAUA,iBAAAA,qBAAqB;EAC/B,UAAU;EACV,SAAS;GACP,MAAM;GACN,uBAAuB;GACvB,SACE,iFACW,QAAQ;EACvB;CACF;CAEF,MAAM,SAASC,iBAAAA,gBAAgB,UAAU,KAAK;CAC9C,IAAI,CAAC,OAAO,SACV,OAAO,WACL,kDACE,OAAO,MAAM,OAAO,IAAI,WAAW,CAAC,CAAC,KAAK,IAAI,CAClD;CAEF,OAAO,SAAS,OAAO,IAAI;AAC7B;AAEA,SAAS,SAAS,UAA2C;CAC3D,OAAO;EAAE;EAAU,UAAU;CAAK;AACpC;AAEA,SAAS,WAAW,SAAiC;CACnD,OAAO;EACL,UAAUD,iBAAAA,qBAAqB;EAC/B,UAAU;EACV,SAAS;GAAE,MAAM;GAAc;EAAQ;CACzC;AACF;AAEA,SAAS,UAAU,OAAkD;CACnE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,YAAY,OAGV;CACT,MAAM,OAAO,MAAM,KAAK,KAAK,YAAY,OAAO,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG;CAClE,OAAO,SAAS,KAAK,MAAM,UAAU,GAAG,KAAK,IAAI,MAAM;AACzD;AAEA,SAAS,UAAU,OAAwB;CACzC,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAC9D"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { FoldersDocument } from "./document.js";
|
|
2
|
+
//#region src/folders/decode.d.ts
|
|
3
|
+
/** Why a stored document could not be read as it stands. */
|
|
4
|
+
export type FoldersDocumentProblem = {
|
|
5
|
+
readonly kind: "newer-schema";
|
|
6
|
+
/** Version found in the document, which is higher than this build understands. */
|
|
7
|
+
readonly documentSchemaVersion: number;
|
|
8
|
+
readonly message: string;
|
|
9
|
+
} | {
|
|
10
|
+
readonly kind: "unreadable";
|
|
11
|
+
readonly message: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A stored document as this build sees it.
|
|
15
|
+
*
|
|
16
|
+
* A document written by a newer build, or one that cannot be parsed at all, reads as no folders
|
|
17
|
+
* so that the project list still renders, and turns `writable` off: an old build that both
|
|
18
|
+
* degraded the read and kept writing would silently replace a newer build's tree with its own
|
|
19
|
+
* truncated view of it. Every refusal says why.
|
|
20
|
+
*/
|
|
21
|
+
export type FoldersDecoded = {
|
|
22
|
+
readonly document: FoldersDocument;
|
|
23
|
+
readonly writable: true;
|
|
24
|
+
readonly problem?: undefined;
|
|
25
|
+
} | {
|
|
26
|
+
readonly document: FoldersDocument;
|
|
27
|
+
/** Every folder write must be refused. */
|
|
28
|
+
readonly writable: false;
|
|
29
|
+
readonly problem: FoldersDocumentProblem;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* What the store holds for the folder document: nothing at all, or a stored value and its bytes
|
|
33
|
+
* when they could be obtained.
|
|
34
|
+
*/
|
|
35
|
+
export type FoldersStoredDocument = {
|
|
36
|
+
readonly present: false;
|
|
37
|
+
} | {
|
|
38
|
+
readonly present: true;
|
|
39
|
+
/** The stored JSON; undefined when the value carries no bytes this build can fetch. */
|
|
40
|
+
readonly raw: string | undefined;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Decode whatever the store holds for the folder document.
|
|
44
|
+
*
|
|
45
|
+
* An absent document is a user with no folders, and is writable. A document that is present but
|
|
46
|
+
* carries no bytes, or empty ones, is not the same thing: it exists and cannot be read here — a
|
|
47
|
+
* newer build keeping the tree in another shape, or a value this build cannot fetch — so it reads
|
|
48
|
+
* as no folders and is **not** writable, because writing an empty tree over one that is merely
|
|
49
|
+
* unreadable from this build destroys it.
|
|
50
|
+
*/
|
|
51
|
+
export declare function decodeStoredFoldersDocument(stored: FoldersStoredDocument): FoldersDecoded;
|
|
52
|
+
/** Decode the stored JSON of a document that is present. */
|
|
53
|
+
export declare function decodeFoldersDocument(raw: string): FoldersDecoded;
|
|
54
|
+
/** Serialise a document for storage. */
|
|
55
|
+
export declare function encodeFoldersDocument(document: FoldersDocument): string;
|
|
56
|
+
//#endregion
|
|
57
|
+
//# sourceMappingURL=decode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode.d.ts","names":[],"sources":["../../src/folders/decode.ts"],"mappings":";;;YAGY;WAEG;;WAEA;WACA;;WAGA;WACA;;;;;;;;;;YAWH;WAEG,UAAU;WACV;WACA;;WAGA,UAAU;;WAEV;WACA,SAAS;;;;;;YAOZ;WACG;;WAEA;;WAEA;;;;;;;;;;;wBAYC,4BAA4B,QAAQ,wBAAwB;;wBAQ5D,sBAAsB,cAAc;;wBAYpC,sBAAsB,UAAU"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { FoldersDocument, emptyFoldersDocument } from "./document.js";
|
|
2
|
+
//#region src/folders/decode.ts
|
|
3
|
+
/**
|
|
4
|
+
* Decode whatever the store holds for the folder document.
|
|
5
|
+
*
|
|
6
|
+
* An absent document is a user with no folders, and is writable. A document that is present but
|
|
7
|
+
* carries no bytes, or empty ones, is not the same thing: it exists and cannot be read here — a
|
|
8
|
+
* newer build keeping the tree in another shape, or a value this build cannot fetch — so it reads
|
|
9
|
+
* as no folders and is **not** writable, because writing an empty tree over one that is merely
|
|
10
|
+
* unreadable from this build destroys it.
|
|
11
|
+
*/
|
|
12
|
+
function decodeStoredFoldersDocument(stored) {
|
|
13
|
+
if (!stored.present) return readable(emptyFoldersDocument());
|
|
14
|
+
if (stored.raw === void 0 || stored.raw === "") return unreadable("the folder document is stored in a shape this build cannot read");
|
|
15
|
+
return decodeFoldersDocument(stored.raw);
|
|
16
|
+
}
|
|
17
|
+
/** Decode the stored JSON of a document that is present. */
|
|
18
|
+
function decodeFoldersDocument(raw) {
|
|
19
|
+
let parsed;
|
|
20
|
+
try {
|
|
21
|
+
parsed = JSON.parse(raw);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
return unreadable(`the folder document is not valid JSON: ${errorText(error)}`);
|
|
24
|
+
}
|
|
25
|
+
return decodeFoldersValue(parsed);
|
|
26
|
+
}
|
|
27
|
+
/** Serialise a document for storage. */
|
|
28
|
+
function encodeFoldersDocument(document) {
|
|
29
|
+
return JSON.stringify(document);
|
|
30
|
+
}
|
|
31
|
+
function decodeFoldersValue(value) {
|
|
32
|
+
if (!isMapping(value)) return unreadable("the folder document is not an object");
|
|
33
|
+
const version = value.schemaVersion;
|
|
34
|
+
if (typeof version !== "number" || !Number.isInteger(version) || version < 1) return unreadable("the folder document carries no usable schema version");
|
|
35
|
+
if (version > 1) return {
|
|
36
|
+
document: emptyFoldersDocument(),
|
|
37
|
+
writable: false,
|
|
38
|
+
problem: {
|
|
39
|
+
kind: "newer-schema",
|
|
40
|
+
documentSchemaVersion: version,
|
|
41
|
+
message: `the folder document was written by a newer version of the application (schema ${version}, this build understands 1)`
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const result = FoldersDocument.safeParse(value);
|
|
45
|
+
if (!result.success) return unreadable(`the folder document does not match schema 1: ` + result.error.issues.map(formatIssue).join("; "));
|
|
46
|
+
return readable(result.data);
|
|
47
|
+
}
|
|
48
|
+
function readable(document) {
|
|
49
|
+
return {
|
|
50
|
+
document,
|
|
51
|
+
writable: true
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function unreadable(message) {
|
|
55
|
+
return {
|
|
56
|
+
document: emptyFoldersDocument(),
|
|
57
|
+
writable: false,
|
|
58
|
+
problem: {
|
|
59
|
+
kind: "unreadable",
|
|
60
|
+
message
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function isMapping(value) {
|
|
65
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
66
|
+
}
|
|
67
|
+
function formatIssue(issue) {
|
|
68
|
+
const path = issue.path.map((segment) => String(segment)).join(".");
|
|
69
|
+
return path === "" ? issue.message : `${path}: ${issue.message}`;
|
|
70
|
+
}
|
|
71
|
+
function errorText(error) {
|
|
72
|
+
return error instanceof Error ? error.message : String(error);
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
export { decodeFoldersDocument, decodeStoredFoldersDocument, encodeFoldersDocument };
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=decode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode.js","names":[],"sources":["../../src/folders/decode.ts"],"sourcesContent":["import { FOLDERS_SCHEMA_VERSION, FoldersDocument, emptyFoldersDocument } from \"./document\";\n\n/** Why a stored document could not be read as it stands. */\nexport type FoldersDocumentProblem =\n | {\n readonly kind: \"newer-schema\";\n /** Version found in the document, which is higher than this build understands. */\n readonly documentSchemaVersion: number;\n readonly message: string;\n }\n | {\n readonly kind: \"unreadable\";\n readonly message: string;\n };\n\n/**\n * A stored document as this build sees it.\n *\n * A document written by a newer build, or one that cannot be parsed at all, reads as no folders\n * so that the project list still renders, and turns `writable` off: an old build that both\n * degraded the read and kept writing would silently replace a newer build's tree with its own\n * truncated view of it. Every refusal says why.\n */\nexport type FoldersDecoded =\n | {\n readonly document: FoldersDocument;\n readonly writable: true;\n readonly problem?: undefined;\n }\n | {\n readonly document: FoldersDocument;\n /** Every folder write must be refused. */\n readonly writable: false;\n readonly problem: FoldersDocumentProblem;\n };\n\n/**\n * What the store holds for the folder document: nothing at all, or a stored value and its bytes\n * when they could be obtained.\n */\nexport type FoldersStoredDocument =\n | { readonly present: false }\n | {\n readonly present: true;\n /** The stored JSON; undefined when the value carries no bytes this build can fetch. */\n readonly raw: string | undefined;\n };\n\n/**\n * Decode whatever the store holds for the folder document.\n *\n * An absent document is a user with no folders, and is writable. A document that is present but\n * carries no bytes, or empty ones, is not the same thing: it exists and cannot be read here — a\n * newer build keeping the tree in another shape, or a value this build cannot fetch — so it reads\n * as no folders and is **not** writable, because writing an empty tree over one that is merely\n * unreadable from this build destroys it.\n */\nexport function decodeStoredFoldersDocument(stored: FoldersStoredDocument): FoldersDecoded {\n if (!stored.present) return readable(emptyFoldersDocument());\n if (stored.raw === undefined || stored.raw === \"\")\n return unreadable(\"the folder document is stored in a shape this build cannot read\");\n return decodeFoldersDocument(stored.raw);\n}\n\n/** Decode the stored JSON of a document that is present. */\nexport function decodeFoldersDocument(raw: string): FoldersDecoded {\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch (error: unknown) {\n return unreadable(`the folder document is not valid JSON: ${errorText(error)}`);\n }\n\n return decodeFoldersValue(parsed);\n}\n\n/** Serialise a document for storage. */\nexport function encodeFoldersDocument(document: FoldersDocument): string {\n return JSON.stringify(document);\n}\n\n//\n// Internals\n//\n\nfunction decodeFoldersValue(value: unknown): FoldersDecoded {\n if (!isMapping(value)) return unreadable(\"the folder document is not an object\");\n\n const version = value.schemaVersion;\n if (typeof version !== \"number\" || !Number.isInteger(version) || version < 1)\n return unreadable(\"the folder document carries no usable schema version\");\n\n if (version > FOLDERS_SCHEMA_VERSION)\n return {\n document: emptyFoldersDocument(),\n writable: false,\n problem: {\n kind: \"newer-schema\",\n documentSchemaVersion: version,\n message:\n `the folder document was written by a newer version of the application ` +\n `(schema ${version}, this build understands ${FOLDERS_SCHEMA_VERSION})`,\n },\n };\n\n const result = FoldersDocument.safeParse(value);\n if (!result.success)\n return unreadable(\n `the folder document does not match schema ${FOLDERS_SCHEMA_VERSION}: ` +\n result.error.issues.map(formatIssue).join(\"; \"),\n );\n\n return readable(result.data);\n}\n\nfunction readable(document: FoldersDocument): FoldersDecoded {\n return { document, writable: true };\n}\n\nfunction unreadable(message: string): FoldersDecoded {\n return {\n document: emptyFoldersDocument(),\n writable: false,\n problem: { kind: \"unreadable\", message },\n };\n}\n\nfunction isMapping(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction formatIssue(issue: {\n readonly path: readonly PropertyKey[];\n readonly message: string;\n}): string {\n const path = issue.path.map((segment) => String(segment)).join(\".\");\n return path === \"\" ? issue.message : `${path}: ${issue.message}`;\n}\n\nfunction errorText(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n"],"mappings":";;;;;;;;;;;AAyDA,SAAgB,4BAA4B,QAA+C;CACzF,IAAI,CAAC,OAAO,SAAS,OAAO,SAAS,qBAAqB,CAAC;CAC3D,IAAI,OAAO,QAAQ,KAAA,KAAa,OAAO,QAAQ,IAC7C,OAAO,WAAW,iEAAiE;CACrF,OAAO,sBAAsB,OAAO,GAAG;AACzC;;AAGA,SAAgB,sBAAsB,KAA6B;CACjE,IAAI;CACJ,IAAI;EACF,SAAS,KAAK,MAAM,GAAG;CACzB,SAAS,OAAgB;EACvB,OAAO,WAAW,0CAA0C,UAAU,KAAK,GAAG;CAChF;CAEA,OAAO,mBAAmB,MAAM;AAClC;;AAGA,SAAgB,sBAAsB,UAAmC;CACvE,OAAO,KAAK,UAAU,QAAQ;AAChC;AAMA,SAAS,mBAAmB,OAAgC;CAC1D,IAAI,CAAC,UAAU,KAAK,GAAG,OAAO,WAAW,sCAAsC;CAE/E,MAAM,UAAU,MAAM;CACtB,IAAI,OAAO,YAAY,YAAY,CAAC,OAAO,UAAU,OAAO,KAAK,UAAU,GACzE,OAAO,WAAW,sDAAsD;CAE1E,IAAI,UAAA,GACF,OAAO;EACL,UAAU,qBAAqB;EAC/B,UAAU;EACV,SAAS;GACP,MAAM;GACN,uBAAuB;GACvB,SACE,iFACW,QAAQ;EACvB;CACF;CAEF,MAAM,SAAS,gBAAgB,UAAU,KAAK;CAC9C,IAAI,CAAC,OAAO,SACV,OAAO,WACL,kDACE,OAAO,MAAM,OAAO,IAAI,WAAW,CAAC,CAAC,KAAK,IAAI,CAClD;CAEF,OAAO,SAAS,OAAO,IAAI;AAC7B;AAEA,SAAS,SAAS,UAA2C;CAC3D,OAAO;EAAE;EAAU,UAAU;CAAK;AACpC;AAEA,SAAS,WAAW,SAAiC;CACnD,OAAO;EACL,UAAU,qBAAqB;EAC/B,UAAU;EACV,SAAS;GAAE,MAAM;GAAc;EAAQ;CACzC;AACF;AAEA,SAAS,UAAU,OAAkD;CACnE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,YAAY,OAGV;CACT,MAAM,OAAO,MAAM,KAAK,KAAK,YAAY,OAAO,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG;CAClE,OAAO,SAAS,KAAK,MAAM,UAAU,GAAG,KAAK,IAAI,MAAM;AACzD;AAEA,SAAS,UAAU,OAAwB;CACzC,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAC9D"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
let zod = require("zod");
|
|
2
|
+
//#region src/folders/document.ts
|
|
3
|
+
/**
|
|
4
|
+
* Schema version this build writes and fully understands.
|
|
5
|
+
*
|
|
6
|
+
* A document carrying a higher version is not readable here, and folder writes are refused rather
|
|
7
|
+
* than allowed to truncate whatever the newer build stored.
|
|
8
|
+
*/
|
|
9
|
+
const FOLDERS_SCHEMA_VERSION = 1;
|
|
10
|
+
/** Brands a string already known to be a folder id, such as one handed back by a caller. */
|
|
11
|
+
function asFolderId(id) {
|
|
12
|
+
return id;
|
|
13
|
+
}
|
|
14
|
+
const FolderEntry = zod.z.object({
|
|
15
|
+
id: folderId(),
|
|
16
|
+
name: zod.z.string().min(1),
|
|
17
|
+
parent: folderId().optional(),
|
|
18
|
+
description: zod.z.string().optional()
|
|
19
|
+
}).strict();
|
|
20
|
+
const FoldersDocument = zod.z.object({
|
|
21
|
+
schemaVersion: zod.z.literal(1),
|
|
22
|
+
folders: zod.z.array(FolderEntry),
|
|
23
|
+
assignments: zod.z.record(zod.z.string().min(1), folderId()),
|
|
24
|
+
templateAssignments: zod.z.record(zod.z.string().min(1), folderId())
|
|
25
|
+
}).strict();
|
|
26
|
+
/** The document of a user who has never made a folder. */
|
|
27
|
+
function emptyFoldersDocument() {
|
|
28
|
+
return {
|
|
29
|
+
schemaVersion: 1,
|
|
30
|
+
folders: [],
|
|
31
|
+
assignments: {},
|
|
32
|
+
templateAssignments: {}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Folder ids are plain strings on the wire; the brand exists so that a project id and a folder id
|
|
37
|
+
* cannot be swapped by accident in the code consuming them.
|
|
38
|
+
*/
|
|
39
|
+
function folderId() {
|
|
40
|
+
return zod.z.string().min(1).transform(asFolderId);
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
exports.FOLDERS_SCHEMA_VERSION = FOLDERS_SCHEMA_VERSION;
|
|
44
|
+
exports.FolderEntry = FolderEntry;
|
|
45
|
+
exports.FoldersDocument = FoldersDocument;
|
|
46
|
+
exports.asFolderId = asFolderId;
|
|
47
|
+
exports.emptyFoldersDocument = emptyFoldersDocument;
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=document.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.cjs","names":["z"],"sources":["../../src/folders/document.ts"],"sourcesContent":["import type { Branded } from \"@milaboratories/pl-model-common\";\nimport { z } from \"zod\";\n\n/**\n * Schema version this build writes and fully understands.\n *\n * A document carrying a higher version is not readable here, and folder writes are refused rather\n * than allowed to truncate whatever the newer build stored.\n */\nexport const FOLDERS_SCHEMA_VERSION = 1;\n\n/** Identifier of a folder, unique within one user's folder document. */\nexport type FolderId = Branded<string, \"FolderId\">;\n\n/** Brands a string already known to be a folder id, such as one handed back by a caller. */\nexport function asFolderId(id: string): FolderId {\n return id as FolderId;\n}\n\n/**\n * A folder as it is persisted: a name, a reference to the folder that contains it, and what the\n * user wrote about it.\n *\n * A folder nobody described carries no description at all rather than an empty one, so clearing\n * a description leaves the same document a folder that never had one has.\n */\nexport interface FolderEntry {\n readonly id: FolderId;\n readonly name: string;\n /** Absent for a top-level folder. */\n readonly parent?: FolderId;\n /** Free text the user wrote about the folder. Absent when there is none. */\n readonly description?: string;\n}\n\nexport const FolderEntry: z.ZodType<FolderEntry, z.ZodTypeDef, unknown> = z\n .object({\n id: folderId(),\n name: z.string().min(1),\n parent: folderId().optional(),\n description: z.string().optional(),\n })\n .strict();\n\n/**\n * The whole folder tree of one user, as one persisted document.\n *\n * Projects and templates live in the same tree, so one folder holds both, and each has its own\n * assignment map. They are separate maps rather than one because the two ids are looked up in\n * two different lists: merged, an id present in neither list could not be told apart from a\n * project that was deleted, and the dead-entry pruning a read performs would have nothing to go\n * on.\n *\n * Each map points from the item to the folder holding it, not the other way round: an item lives\n * in at most one folder, so one entry per item can never contradict itself, and an item the map\n * does not mention needs no entry at all — it is at the top level.\n */\nexport interface FoldersDocument {\n readonly schemaVersion: typeof FOLDERS_SCHEMA_VERSION;\n readonly folders: readonly FolderEntry[];\n /** Project id to the folder holding it. Projects at the top level are absent. */\n readonly assignments: Readonly<Record<string, FolderId>>;\n /** Template id to the folder holding it. Templates at the top level are absent. */\n readonly templateAssignments: Readonly<Record<string, FolderId>>;\n}\n\nexport const FoldersDocument: z.ZodType<FoldersDocument, z.ZodTypeDef, unknown> = z\n .object({\n schemaVersion: z.literal(FOLDERS_SCHEMA_VERSION),\n folders: z.array(FolderEntry),\n assignments: z.record(z.string().min(1), folderId()),\n templateAssignments: z.record(z.string().min(1), folderId()),\n })\n .strict();\n\n/** The document of a user who has never made a folder. */\nexport function emptyFoldersDocument(): FoldersDocument {\n return {\n schemaVersion: FOLDERS_SCHEMA_VERSION,\n folders: [],\n assignments: {},\n templateAssignments: {},\n };\n}\n\n//\n// Internals\n//\n\n/**\n * Folder ids are plain strings on the wire; the brand exists so that a project id and a folder id\n * cannot be swapped by accident in the code consuming them.\n */\nfunction folderId() {\n return z.string().min(1).transform(asFolderId);\n}\n"],"mappings":";;;;;;;;AASA,MAAa,yBAAyB;;AAMtC,SAAgB,WAAW,IAAsB;CAC/C,OAAO;AACT;AAkBA,MAAa,cAA6DA,IAAAA,EACvE,OAAO;CACN,IAAI,SAAS;CACb,MAAMA,IAAAA,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CACtB,QAAQ,SAAS,CAAC,CAAC,SAAS;CAC5B,aAAaA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS;AACnC,CAAC,CAAC,CACD,OAAO;AAwBV,MAAa,kBAAqEA,IAAAA,EAC/E,OAAO;CACN,eAAeA,IAAAA,EAAE,QAAA,CAA8B;CAC/C,SAASA,IAAAA,EAAE,MAAM,WAAW;CAC5B,aAAaA,IAAAA,EAAE,OAAOA,IAAAA,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;CACnD,qBAAqBA,IAAAA,EAAE,OAAOA,IAAAA,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;AAC7D,CAAC,CAAC,CACD,OAAO;;AAGV,SAAgB,uBAAwC;CACtD,OAAO;EACL,eAAA;EACA,SAAS,CAAC;EACV,aAAa,CAAC;EACd,qBAAqB,CAAC;CACxB;AACF;;;;;AAUA,SAAS,WAAW;CAClB,OAAOA,IAAAA,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,UAAU;AAC/C"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { Branded } from "@milaboratories/pl-model-common";
|
|
3
|
+
//#region src/folders/document.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Schema version this build writes and fully understands.
|
|
6
|
+
*
|
|
7
|
+
* A document carrying a higher version is not readable here, and folder writes are refused rather
|
|
8
|
+
* than allowed to truncate whatever the newer build stored.
|
|
9
|
+
*/
|
|
10
|
+
export declare const FOLDERS_SCHEMA_VERSION = 1;
|
|
11
|
+
/** Identifier of a folder, unique within one user's folder document. */
|
|
12
|
+
export type FolderId = Branded<string, "FolderId">;
|
|
13
|
+
/** Brands a string already known to be a folder id, such as one handed back by a caller. */
|
|
14
|
+
export declare function asFolderId(id: string): FolderId;
|
|
15
|
+
/**
|
|
16
|
+
* A folder as it is persisted: a name, a reference to the folder that contains it, and what the
|
|
17
|
+
* user wrote about it.
|
|
18
|
+
*
|
|
19
|
+
* A folder nobody described carries no description at all rather than an empty one, so clearing
|
|
20
|
+
* a description leaves the same document a folder that never had one has.
|
|
21
|
+
*/
|
|
22
|
+
export interface FolderEntry {
|
|
23
|
+
readonly id: FolderId;
|
|
24
|
+
readonly name: string;
|
|
25
|
+
/** Absent for a top-level folder. */
|
|
26
|
+
readonly parent?: FolderId;
|
|
27
|
+
/** Free text the user wrote about the folder. Absent when there is none. */
|
|
28
|
+
readonly description?: string;
|
|
29
|
+
}
|
|
30
|
+
export declare const FolderEntry: z.ZodType<FolderEntry, z.ZodTypeDef, unknown>;
|
|
31
|
+
/**
|
|
32
|
+
* The whole folder tree of one user, as one persisted document.
|
|
33
|
+
*
|
|
34
|
+
* Projects and templates live in the same tree, so one folder holds both, and each has its own
|
|
35
|
+
* assignment map. They are separate maps rather than one because the two ids are looked up in
|
|
36
|
+
* two different lists: merged, an id present in neither list could not be told apart from a
|
|
37
|
+
* project that was deleted, and the dead-entry pruning a read performs would have nothing to go
|
|
38
|
+
* on.
|
|
39
|
+
*
|
|
40
|
+
* Each map points from the item to the folder holding it, not the other way round: an item lives
|
|
41
|
+
* in at most one folder, so one entry per item can never contradict itself, and an item the map
|
|
42
|
+
* does not mention needs no entry at all — it is at the top level.
|
|
43
|
+
*/
|
|
44
|
+
export interface FoldersDocument {
|
|
45
|
+
readonly schemaVersion: typeof FOLDERS_SCHEMA_VERSION;
|
|
46
|
+
readonly folders: readonly FolderEntry[];
|
|
47
|
+
/** Project id to the folder holding it. Projects at the top level are absent. */
|
|
48
|
+
readonly assignments: Readonly<Record<string, FolderId>>;
|
|
49
|
+
/** Template id to the folder holding it. Templates at the top level are absent. */
|
|
50
|
+
readonly templateAssignments: Readonly<Record<string, FolderId>>;
|
|
51
|
+
}
|
|
52
|
+
export declare const FoldersDocument: z.ZodType<FoldersDocument, z.ZodTypeDef, unknown>;
|
|
53
|
+
/** The document of a user who has never made a folder. */
|
|
54
|
+
export declare function emptyFoldersDocument(): FoldersDocument;
|
|
55
|
+
//#endregion
|
|
56
|
+
//# sourceMappingURL=document.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.d.ts","names":[],"sources":["../../src/folders/document.ts"],"mappings":";;;;;;;;;qBASa;;YAGD,WAAW;;wBAGP,WAAW,aAAa;;;;;;;;iBAWvB;WACN,IAAI;WACJ;;WAEA,SAAS;;WAET;;qBAGE,aAAa,EAAE,QAAQ,aAAa,EAAE;;;;;;;;;;;;;;iBAsBlC;WACN,sBAAsB;WACtB,kBAAkB;;WAElB,aAAa,SAAS,eAAe;;WAErC,qBAAqB,SAAS,eAAe;;qBAG3C,iBAAiB,EAAE,QAAQ,iBAAiB,EAAE;;wBAU3C,wBAAwB"}
|