@milaboratories/pl-middle-layer 1.71.15 → 1.72.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/index.cjs +10 -5
- package/dist/index.d.ts +5 -4
- package/dist/index.js +3 -2
- package/dist/middle_layer/build_stamp.cjs +1 -1
- package/dist/middle_layer/build_stamp.js +1 -1
- package/dist/middle_layer/folders.cjs +631 -0
- package/dist/middle_layer/folders.cjs.map +1 -0
- package/dist/middle_layer/folders.d.ts +39 -0
- package/dist/middle_layer/folders.d.ts.map +1 -0
- package/dist/middle_layer/folders.js +613 -0
- package/dist/middle_layer/folders.js.map +1 -0
- package/dist/middle_layer/index.cjs +3 -0
- package/dist/middle_layer/index.d.ts +4 -3
- package/dist/middle_layer/index.js +2 -1
- package/dist/middle_layer/middle_layer.cjs +585 -370
- package/dist/middle_layer/middle_layer.cjs.map +1 -1
- package/dist/middle_layer/middle_layer.d.ts +215 -122
- package/dist/middle_layer/middle_layer.d.ts.map +1 -1
- package/dist/middle_layer/middle_layer.js +593 -378
- package/dist/middle_layer/middle_layer.js.map +1 -1
- package/dist/middle_layer/project_list.cjs +36 -19
- package/dist/middle_layer/project_list.cjs.map +1 -1
- package/dist/middle_layer/project_list.d.ts +1 -1
- package/dist/middle_layer/project_list.d.ts.map +1 -1
- package/dist/middle_layer/project_list.js +37 -21
- package/dist/middle_layer/project_list.js.map +1 -1
- package/dist/middle_layer/sharing_list.cjs +123 -93
- package/dist/middle_layer/sharing_list.cjs.map +1 -1
- package/dist/middle_layer/sharing_list.d.ts +43 -19
- package/dist/middle_layer/sharing_list.d.ts.map +1 -1
- package/dist/middle_layer/sharing_list.js +123 -93
- package/dist/middle_layer/sharing_list.js.map +1 -1
- package/dist/middle_layer/template_list.cjs +45 -20
- package/dist/middle_layer/template_list.cjs.map +1 -1
- package/dist/middle_layer/template_list.d.ts +7 -15
- package/dist/middle_layer/template_list.d.ts.map +1 -1
- package/dist/middle_layer/template_list.js +44 -21
- package/dist/middle_layer/template_list.js.map +1 -1
- package/dist/model/index.cjs +7 -5
- package/dist/model/index.d.ts +2 -2
- package/dist/model/index.js +2 -2
- package/dist/model/sharing_model.cjs +46 -20
- package/dist/model/sharing_model.cjs.map +1 -1
- package/dist/model/sharing_model.d.ts +125 -55
- package/dist/model/sharing_model.d.ts.map +1 -1
- package/dist/model/sharing_model.js +40 -16
- package/dist/model/sharing_model.js.map +1 -1
- package/dist/mutator/list.cjs +30 -0
- package/dist/mutator/list.cjs.map +1 -0
- package/dist/mutator/list.js +29 -0
- package/dist/mutator/list.js.map +1 -0
- package/dist/mutator/project.cjs +14 -1
- package/dist/mutator/project.cjs.map +1 -1
- package/dist/mutator/project.d.ts.map +1 -1
- package/dist/mutator/project.js +15 -2
- package/dist/mutator/project.js.map +1 -1
- package/dist/mutator/sharing.cjs +130 -76
- package/dist/mutator/sharing.cjs.map +1 -1
- package/dist/mutator/sharing.js +130 -76
- package/dist/mutator/sharing.js.map +1 -1
- package/dist/mutator/template.cjs +24 -17
- package/dist/mutator/template.cjs.map +1 -1
- package/dist/mutator/template.js +26 -20
- package/dist/mutator/template.js.map +1 -1
- package/package.json +18 -18
- package/src/middle_layer/folders.test.ts +1068 -0
- package/src/middle_layer/folders.ts +1059 -0
- package/src/middle_layer/folders_read.test.ts +359 -0
- package/src/middle_layer/index.ts +3 -2
- package/src/middle_layer/middle_layer.ts +813 -547
- package/src/middle_layer/project_list.test.ts +183 -0
- package/src/middle_layer/project_list.ts +58 -21
- package/src/middle_layer/sharing.test.ts +183 -0
- package/src/middle_layer/sharing_list.ts +208 -152
- package/src/middle_layer/template_list.test.ts +148 -0
- package/src/middle_layer/template_list.ts +72 -32
- package/src/middle_layer/templates.test.ts +76 -45
- package/src/model/sharing_model.test.ts +69 -2
- package/src/model/sharing_model.ts +161 -73
- package/src/mutator/list.ts +36 -0
- package/src/mutator/project-v3.test.ts +3 -1
- package/src/mutator/project.ts +13 -2
- package/src/mutator/sharing.ts +193 -120
- package/src/mutator/template.ts +37 -29
- package/src/test/with_ml.ts +73 -16
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FolderId } from "@milaboratories/pl-model-middle-layer";
|
|
2
|
+
import { Branded, ProjectId, ProjectTemplateV1, TemplateId } from "@milaboratories/pl-model-common";
|
|
2
3
|
import { ResourceType, Role } from "@milaboratories/pl-client";
|
|
3
4
|
//#region src/model/sharing_model.d.ts
|
|
4
5
|
/**
|
|
5
|
-
*
|
|
6
|
+
* Identity of one share. A donor-generated UUID string,
|
|
6
7
|
* branded so it cannot be silently confused with a project id, a login, or a raw field
|
|
7
8
|
* name. Minted once with {@link newShareId}; every other site receives it (from decoded
|
|
8
9
|
* {@link EnvelopeData} or by parsing a `decision/{shareId}` field name) and threads it
|
|
@@ -16,18 +17,17 @@ export declare function newShareId(): ShareId;
|
|
|
16
17
|
export declare function asShareId(id: string): ShareId;
|
|
17
18
|
/** Field on the donor's clientRoot holding the {@link SharingOutboxResourceType} resource. */
|
|
18
19
|
export declare const SharingOutboxField = "sharingOutbox";
|
|
19
|
-
/** Field on the
|
|
20
|
+
/** Field on the recipient's clientRoot holding the {@link SharingStateResourceType} resource. */
|
|
20
21
|
export declare const SharingStateField = "sharingState";
|
|
21
22
|
export declare const SharingOutboxResourceType: ResourceType;
|
|
22
23
|
export declare const SharedEnvelopeResourceType: ResourceType;
|
|
23
24
|
export declare const SharingStateResourceType: ResourceType;
|
|
24
25
|
export type EnvelopeMode = "copy" | "read-only" | "collaboration";
|
|
25
|
-
/** Per-project decision on change, matching the UI labels: re-snapshot the live source ("update"),
|
|
26
|
-
* carry the existing snapshot ("keep"), or drop the project from the pack ("remove"). */
|
|
27
|
-
export type ProjectChangeAction = "keep" | "update" | "remove";
|
|
28
26
|
/** Key of the per-project envelope maps: a uuid minted per snapshot to name the `project/{uuid}`
|
|
29
27
|
* field. Distinct from {@link ProjectId} — re-snapshotting one source yields a new uuid each time. */
|
|
30
28
|
export type ProjectFieldUuid = Branded<string, "ProjectFieldUuid">;
|
|
29
|
+
/** Mints a fresh {@link ProjectFieldUuid} for one snapshot. */
|
|
30
|
+
export declare function newProjectFieldUuid(): ProjectFieldUuid;
|
|
31
31
|
/**
|
|
32
32
|
* Whether a role may make a resource public (grant to everyone): true for controller,
|
|
33
33
|
* admin; false for workflow and unspecified. The middle layer carries no policy
|
|
@@ -51,6 +51,40 @@ export interface EnvelopeProject {
|
|
|
51
51
|
label: string;
|
|
52
52
|
source: ProjectId;
|
|
53
53
|
updatedAt: number;
|
|
54
|
+
/** What the project said about itself when it was snapshotted, carried for the same reason as
|
|
55
|
+
* `label`. Absent when it had none, and on envelopes written before it was carried. */
|
|
56
|
+
description?: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Identifier of a folder inside one envelope.
|
|
60
|
+
*
|
|
61
|
+
* Local to the envelope, because the recipient's own folder document mints its own ids and the
|
|
62
|
+
* donor's mean nothing there. What travels is the shape of the subtree, not its identity.
|
|
63
|
+
*/
|
|
64
|
+
export type EnvelopeFolderId = Branded<string, "EnvelopeFolderId">;
|
|
65
|
+
/** Mints a fresh {@link EnvelopeFolderId} for one folder of the envelope being built. */
|
|
66
|
+
export declare function newEnvelopeFolderId(): EnvelopeFolderId;
|
|
67
|
+
/** One folder of a shared subtree. */
|
|
68
|
+
export interface EnvelopeFolder {
|
|
69
|
+
name: string;
|
|
70
|
+
/** Absent for the subtree's root — the folder that was shared. */
|
|
71
|
+
parent?: EnvelopeFolderId;
|
|
72
|
+
/** What the donor wrote about the folder. Absent when there is none. */
|
|
73
|
+
description?: string;
|
|
74
|
+
}
|
|
75
|
+
/** A project of a shared subtree: an {@link EnvelopeProject} placed in the subtree. */
|
|
76
|
+
export interface EnvelopeFolderProject extends EnvelopeProject {
|
|
77
|
+
folder: EnvelopeFolderId;
|
|
78
|
+
}
|
|
79
|
+
/** A template of a shared subtree. The document rides here whole, exactly as a `template`
|
|
80
|
+
* payload carries it — a template is never snapshotted. */
|
|
81
|
+
export interface EnvelopeFolderTemplate {
|
|
82
|
+
document: ProjectTemplateV1;
|
|
83
|
+
/** Label to give the template among the recipient's templates. */
|
|
84
|
+
label: string;
|
|
85
|
+
/** What the template says about itself. Absent when the donor described it with nothing. */
|
|
86
|
+
description?: string;
|
|
87
|
+
folder: EnvelopeFolderId;
|
|
54
88
|
}
|
|
55
89
|
/**
|
|
56
90
|
* What a share carries. The discriminant is what a reader checks before anything else: a
|
|
@@ -66,9 +100,30 @@ export type EnvelopePayload = {
|
|
|
66
100
|
} | {
|
|
67
101
|
kind: "template";
|
|
68
102
|
document: ProjectTemplateV1;
|
|
69
|
-
/**
|
|
103
|
+
/** Donor's own id of the shared template; what a prior share of the same template is
|
|
104
|
+
* matched on. It names nothing in the recipient's tree, and envelopes written before it
|
|
105
|
+
* existed carry none — those match no later share of anything. */
|
|
106
|
+
source?: TemplateId;
|
|
107
|
+
/** Label to give the template among the recipient's templates. */
|
|
70
108
|
label: string;
|
|
71
|
-
/**
|
|
109
|
+
/** What the template says about itself, carried to the recipient's copy. Absent when the
|
|
110
|
+
* donor described it with nothing. */
|
|
111
|
+
description?: string;
|
|
112
|
+
/** Donor login, kept on each copy of the template as its provenance. */
|
|
113
|
+
from: string;
|
|
114
|
+
} | {
|
|
115
|
+
kind: "folder";
|
|
116
|
+
/** Donor's own id of the shared folder; what a prior share of the same folder is matched
|
|
117
|
+
* on. It names nothing in the recipient's tree. */
|
|
118
|
+
source: FolderId;
|
|
119
|
+
/** The shared subtree. Exactly one folder has no parent, and that one is its root. */
|
|
120
|
+
folders: Record<EnvelopeFolderId, EnvelopeFolder>;
|
|
121
|
+
/** Project snapshots, each tagged with the folder of the subtree holding it. Their
|
|
122
|
+
* `project/{uuid}` fields are the same ones a `projects` payload describes. */
|
|
123
|
+
projects: Record<ProjectFieldUuid, EnvelopeFolderProject>;
|
|
124
|
+
/** Templates of the subtree, documents and all. Nothing of a template is snapshotted. */
|
|
125
|
+
templates: EnvelopeFolderTemplate[];
|
|
126
|
+
/** Donor login, kept on each copied template as its provenance. */
|
|
72
127
|
from: string;
|
|
73
128
|
};
|
|
74
129
|
export type EnvelopePayloadKind = EnvelopePayload["kind"];
|
|
@@ -98,27 +153,33 @@ export interface EnvelopeData {
|
|
|
98
153
|
/** The project map of a projects-payload envelope, or `{}` for any other payload — the one
|
|
99
154
|
* place a project-shaped reader turns a payload into the map it expects. */
|
|
100
155
|
export declare function envelopeProjectMap(data: EnvelopeData): Record<ProjectFieldUuid, EnvelopeProject>;
|
|
101
|
-
/**
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
156
|
+
/**
|
|
157
|
+
* The shared folder itself: the one folder of the subtree that has no parent.
|
|
158
|
+
*
|
|
159
|
+
* Derived rather than stored, so it cannot disagree with the folders beside it. `undefined` for
|
|
160
|
+
* a subtree with no root or more than one, which is an envelope nothing can be reconstructed
|
|
161
|
+
* from — the copy reports it rather than guessing which folder was meant.
|
|
162
|
+
*/
|
|
163
|
+
export declare function envelopeFolderRoot(folders: Record<EnvelopeFolderId, EnvelopeFolder>): EnvelopeFolderId | undefined;
|
|
164
|
+
/**
|
|
165
|
+
* Dynamic field on SharingState, one per share this user has hidden, keyed by shareId.
|
|
166
|
+
*
|
|
167
|
+
* Hiding is private to the recipient and reversible: the field is written to put a share out of
|
|
168
|
+
* sight and removed to bring it back. It says nothing to the donor and nothing about whether
|
|
169
|
+
* anything was ever copied out of the share — a share can be copied from any number of times,
|
|
170
|
+
* before or after being hidden.
|
|
171
|
+
*
|
|
172
|
+
* The field name keeps its original `decision/` prefix. Records written before hiding replaced
|
|
173
|
+
* accept/reject carry a different value under the same key, and every reader treats the presence
|
|
174
|
+
* of the field as the whole answer: someone who accepted or rejected a share back then does not
|
|
175
|
+
* want to see it, which is exactly what hidden means.
|
|
176
|
+
*/
|
|
177
|
+
export declare const HiddenFieldPrefix = "decision/";
|
|
178
|
+
export declare const hiddenField: (shareId: ShareId) => string;
|
|
179
|
+
export declare const isHiddenField: (name: string) => boolean;
|
|
180
|
+
export declare const hiddenFieldShareId: (name: string) => ShareId;
|
|
181
|
+
export interface ShareHidden {
|
|
182
|
+
hidden: true;
|
|
122
183
|
timestamp: number;
|
|
123
184
|
}
|
|
124
185
|
/**
|
|
@@ -142,42 +203,51 @@ export declare function decodeEnvelopeData(data: Uint8Array): EnvelopeData | und
|
|
|
142
203
|
*/
|
|
143
204
|
export declare function normalizeEnvelopeData(raw: unknown): EnvelopeData | undefined;
|
|
144
205
|
/**
|
|
145
|
-
*
|
|
206
|
+
* Who a share is granted to: named recipients XOR everyone — two clean variants, not one struct
|
|
207
|
+
* with mutually exclusive optional fields.
|
|
146
208
|
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
* named recipient and the envelope expires after the default TTL.
|
|
209
|
+
* The everyone variant issues a single make-public grant, and the envelope's `expiresAt` is `null`,
|
|
210
|
+
* so it never expires. The recipients variant grants each named login, and the envelope expires
|
|
211
|
+
* after the default TTL.
|
|
151
212
|
*/
|
|
152
|
-
export type
|
|
213
|
+
export type ShareAudience = {
|
|
153
214
|
recipients: string[];
|
|
154
|
-
title: string;
|
|
155
|
-
mode: EnvelopeMode;
|
|
156
215
|
} | {
|
|
157
216
|
everyone: true;
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
replace: boolean;
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* Options every share takes: the audience, the title recipients see it under, and the prior
|
|
220
|
+
* shares it replaces.
|
|
221
|
+
*/
|
|
222
|
+
export type ShareOptions = ShareAudience & {
|
|
165
223
|
title: string;
|
|
166
|
-
|
|
224
|
+
replace?: ShareReplaceOption;
|
|
167
225
|
};
|
|
168
226
|
/**
|
|
169
|
-
*
|
|
227
|
+
* Prior shares the new one supersedes: each is deleted in the same transaction that creates the
|
|
228
|
+
* replacement, so the outbox never holds both.
|
|
170
229
|
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
230
|
+
* The set is the caller's, never inferred here. The author is shown the shares that will go and
|
|
231
|
+
* agrees to that list, so what was shown has to be what is deleted — an overlap rule computed on
|
|
232
|
+
* this side would diverge from it. Ids that no longer resolve are skipped: a share revoked between
|
|
233
|
+
* the dialog opening and the confirm is nothing to undo.
|
|
234
|
+
*
|
|
235
|
+
* The replacement is a new {@link ShareId}: a recipient who had hidden the old share sees the new
|
|
236
|
+
* one, and copies already taken from the old share are untouched.
|
|
174
237
|
*/
|
|
175
|
-
export type
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
238
|
+
export type ShareReplaceOption = ShareId[];
|
|
239
|
+
/** Options for {@link MiddleLayer.shareProjects}: the common ones, plus what the recipient's app
|
|
240
|
+
* does with the projects. */
|
|
241
|
+
export type ShareProjectsOptions = ShareOptions & {
|
|
242
|
+
mode: EnvelopeMode;
|
|
243
|
+
};
|
|
244
|
+
/** Options for {@link MiddleLayer.shareTemplate}. */
|
|
245
|
+
export type ShareTemplateOptions = ShareOptions;
|
|
246
|
+
/** Options for {@link MiddleLayer.shareFolder}. */
|
|
247
|
+
export type ShareFolderOptions = ShareOptions;
|
|
248
|
+
/** What creating a share hands back: the id of the share just created. */
|
|
249
|
+
export type ShareOutcome = {
|
|
250
|
+
readonly shareId: ShareId;
|
|
181
251
|
};
|
|
182
252
|
//#endregion
|
|
183
253
|
//# sourceMappingURL=sharing_model.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sharing_model.d.ts","names":[],"sources":["../../src/model/sharing_model.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"sharing_model.d.ts","names":[],"sources":["../../src/model/sharing_model.ts"],"mappings":";;;;;;;;;;;YAkBY,UAAU;;wBAGN,cAAc;;;wBAMd,UAAU,aAAa;;qBAY1B;;qBAEA;qBAEA,2BAA2B;qBAC3B,4BAA4B;qBAC5B,0BAA0B;YAE3B;;;YAIA,mBAAmB;;wBAGf,uBAAuB;;;;;;;wBAUvB,mBAAmB,MAAM;;;;;;;;;;wBAmBzB,eAAe,MAAM;;;iBAYpB;EACf;EACA,QAAQ;EACR;;;EAGA;;;;;;;;YASU,mBAAmB;;wBAGf,uBAAuB;;iBAKtB;EACf;;EAEA,SAAS;;EAET;;;iBAIe,8BAA8B;EAC7C,QAAQ;;;;iBAKO;EACf,UAAU;;EAEV;;EAEA;EACA,QAAQ;;;;;;;;;;YAWE;EACN;EAAkB,UAAU,OAAO,kBAAkB;;EAErD;EACA,UAAU;;;;EAIV,SAAS;;EAET;;;EAGA;;EAEA;;EAGA;;;EAGA,QAAQ;;EAER,SAAS,OAAO,kBAAkB;;;EAGlC,UAAU,OAAO,kBAAkB;;EAEnC,WAAW;;EAEX;;YAGM,sBAAsB;;;;YAKtB;;qBAGC;;;;;;;;iBASI;EACf,sBAAsB;EACtB,SAAS;EACT;EACA;EACA,MAAM;EACN;EACA;EACA,SAAS;;;;wBAKK,mBAAmB,MAAM,eAAe,OAAO,kBAAkB;;;;;;;;wBAWjE,mBACd,SAAS,OAAO,kBAAkB,kBACjC;;;;;;;;;;;;;;qBAoBU;qBACA,cAAW,SAAa;qBACxB,gBAAa;qBACb,qBAAkB,iBAAmB;iBAGjC;EACf;EACA;;;;;;;;;;;wBAYc,mBAAmB,MAAM,aAAa;;;;;;;;;;wBAatC,sBAAsB,eAAe;;;;;;;;;YA+BzC;EACN;;EACA;;;;;;YAMM,eAAe;EACzB;EACA,UAAU;;;;;;;;;;;;;;YAeA,qBAAqB;;;YAIrB,uBAAuB;EAAiB,MAAM;;;YAG9C,uBAAuB;;YAGvB,qBAAqB;;YAGrB;WAA0B,SAAS"}
|
|
@@ -12,7 +12,7 @@ function asShareId(id) {
|
|
|
12
12
|
}
|
|
13
13
|
/** Field on the donor's clientRoot holding the {@link SharingOutboxResourceType} resource. */
|
|
14
14
|
const SharingOutboxField = "sharingOutbox";
|
|
15
|
-
/** Field on the
|
|
15
|
+
/** Field on the recipient's clientRoot holding the {@link SharingStateResourceType} resource. */
|
|
16
16
|
const SharingStateField = "sharingState";
|
|
17
17
|
const SharingOutboxResourceType = {
|
|
18
18
|
name: "SharingOutbox",
|
|
@@ -26,6 +26,10 @@ const SharingStateResourceType = {
|
|
|
26
26
|
name: "SharingState",
|
|
27
27
|
version: "1"
|
|
28
28
|
};
|
|
29
|
+
/** Mints a fresh {@link ProjectFieldUuid} for one snapshot. */
|
|
30
|
+
function newProjectFieldUuid() {
|
|
31
|
+
return randomUUID();
|
|
32
|
+
}
|
|
29
33
|
/**
|
|
30
34
|
* Whether a role may make a resource public (grant to everyone): true for controller,
|
|
31
35
|
* admin; false for workflow and unspecified. The middle layer carries no policy
|
|
@@ -55,6 +59,10 @@ function canImpersonate(role) {
|
|
|
55
59
|
default: return false;
|
|
56
60
|
}
|
|
57
61
|
}
|
|
62
|
+
/** Mints a fresh {@link EnvelopeFolderId} for one folder of the envelope being built. */
|
|
63
|
+
function newEnvelopeFolderId() {
|
|
64
|
+
return randomUUID();
|
|
65
|
+
}
|
|
58
66
|
/** Version written into every new envelope. Bumped from 1 when the payload became discriminated. */
|
|
59
67
|
const EnvelopeSchemaVersionCurrent = 2;
|
|
60
68
|
/** The project map of a projects-payload envelope, or `{}` for any other payload — the one
|
|
@@ -62,19 +70,34 @@ const EnvelopeSchemaVersionCurrent = 2;
|
|
|
62
70
|
function envelopeProjectMap(data) {
|
|
63
71
|
return data.payload.kind === "projects" ? data.payload.projects : {};
|
|
64
72
|
}
|
|
65
|
-
/**
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
/**
|
|
74
|
+
* The shared folder itself: the one folder of the subtree that has no parent.
|
|
75
|
+
*
|
|
76
|
+
* Derived rather than stored, so it cannot disagree with the folders beside it. `undefined` for
|
|
77
|
+
* a subtree with no root or more than one, which is an envelope nothing can be reconstructed
|
|
78
|
+
* from — the copy reports it rather than guessing which folder was meant.
|
|
79
|
+
*/
|
|
80
|
+
function envelopeFolderRoot(folders) {
|
|
81
|
+
const roots = Object.keys(folders).filter((id) => folders[id].parent === void 0);
|
|
82
|
+
return roots.length === 1 ? roots[0] : void 0;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Dynamic field on SharingState, one per share this user has hidden, keyed by shareId.
|
|
86
|
+
*
|
|
87
|
+
* Hiding is private to the recipient and reversible: the field is written to put a share out of
|
|
88
|
+
* sight and removed to bring it back. It says nothing to the donor and nothing about whether
|
|
89
|
+
* anything was ever copied out of the share — a share can be copied from any number of times,
|
|
90
|
+
* before or after being hidden.
|
|
91
|
+
*
|
|
92
|
+
* The field name keeps its original `decision/` prefix. Records written before hiding replaced
|
|
93
|
+
* accept/reject carry a different value under the same key, and every reader treats the presence
|
|
94
|
+
* of the field as the whole answer: someone who accepted or rejected a share back then does not
|
|
95
|
+
* want to see it, which is exactly what hidden means.
|
|
96
|
+
*/
|
|
97
|
+
const HiddenFieldPrefix = "decision/";
|
|
98
|
+
const hiddenField = (shareId) => `${HiddenFieldPrefix}${shareId}`;
|
|
99
|
+
const isHiddenField = (name) => name.startsWith(HiddenFieldPrefix);
|
|
100
|
+
const hiddenFieldShareId = (name) => asShareId(name.slice(9));
|
|
78
101
|
/**
|
|
79
102
|
* Single owner of the raw-data → {@link EnvelopeData} decode. The envelope's immutable `data`
|
|
80
103
|
* blob is UTF-8 JSON set once at createEphemeral; every site that reads it from a raw resource
|
|
@@ -122,7 +145,8 @@ function normalizeEnvelopeData(raw) {
|
|
|
122
145
|
* teaching the decoder about it is a compile error, not a share that silently disappears. */
|
|
123
146
|
const KnownPayloadKinds = {
|
|
124
147
|
projects: true,
|
|
125
|
-
template: true
|
|
148
|
+
template: true,
|
|
149
|
+
folder: true
|
|
126
150
|
};
|
|
127
151
|
/** Every schema version {@link normalizeEnvelopeData} accepts. Keyed by
|
|
128
152
|
* {@link EnvelopeSchemaVersion}, so widening that union without deciding how the new shape
|
|
@@ -132,6 +156,6 @@ const ReadableSchemaVersions = {
|
|
|
132
156
|
2: true
|
|
133
157
|
};
|
|
134
158
|
//#endregion
|
|
135
|
-
export {
|
|
159
|
+
export { EnvelopeSchemaVersionCurrent, HiddenFieldPrefix, SharedEnvelopeResourceType, SharingOutboxField, SharingOutboxResourceType, SharingStateField, SharingStateResourceType, asShareId, canGrantToEveryone, canImpersonate, decodeEnvelopeData, envelopeFolderRoot, envelopeProjectMap, hiddenField, hiddenFieldShareId, isHiddenField, newEnvelopeFolderId, newProjectFieldUuid, newShareId, normalizeEnvelopeData };
|
|
136
160
|
|
|
137
161
|
//# sourceMappingURL=sharing_model.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sharing_model.js","names":["RoleEnum"],"sources":["../../src/model/sharing_model.ts"],"sourcesContent":["import type { ResourceType, Role } from \"@milaboratories/pl-client\";\nimport { Role as RoleEnum } from \"@milaboratories/pl-client\";\nimport type { Branded, ProjectId, ProjectTemplateV1 } from \"@milaboratories/pl-model-common\";\nimport { randomUUID } from \"node:crypto\";\n\n/**\n * Logical identity of a share, stable across replaces. A donor-generated UUID string,\n * branded so it cannot be silently confused with a project id, a login, or a raw field\n * name. Minted once with {@link newShareId}; every other site receives it (from decoded\n * {@link EnvelopeData} or by parsing a `decision/{shareId}` field name) and threads it\n * through unchanged.\n */\nexport type ShareId = Branded<string, \"ShareId\">;\n\n/** Mints a fresh {@link ShareId}. The single place a share's logical identity is created. */\nexport function newShareId(): ShareId {\n return randomUUID() as ShareId;\n}\n\n/** Brands a string already known to be a share id (e.g. parsed from a `decision/{shareId}`\n * field name) as a {@link ShareId}, without minting a new one. */\nexport function asShareId(id: string): ShareId {\n return id as ShareId;\n}\n\n//\n// Pl Model — Project Sharing\n//\n// All sharing structures are defined and managed by the middle layer; the\n// backend knows nothing about envelopes.\n//\n\n/** Field on the donor's clientRoot holding the {@link SharingOutboxResourceType} resource. */\nexport const SharingOutboxField = \"sharingOutbox\";\n/** Field on the acceptor's clientRoot holding the {@link SharingStateResourceType} resource. */\nexport const SharingStateField = \"sharingState\";\n\nexport const SharingOutboxResourceType: ResourceType = { name: \"SharingOutbox\", version: \"1\" };\nexport const SharedEnvelopeResourceType: ResourceType = { name: \"SharedEnvelope\", version: \"1\" };\nexport const SharingStateResourceType: ResourceType = { name: \"SharingState\", version: \"1\" };\n\nexport type EnvelopeMode = \"copy\" | \"read-only\" | \"collaboration\";\n\n/** Per-project decision on change, matching the UI labels: re-snapshot the live source (\"update\"),\n * carry the existing snapshot (\"keep\"), or drop the project from the pack (\"remove\"). */\nexport type ProjectChangeAction = \"keep\" | \"update\" | \"remove\";\n\n/** Key of the per-project envelope maps: a uuid minted per snapshot to name the `project/{uuid}`\n * field. Distinct from {@link ProjectId} — re-snapshotting one source yields a new uuid each time. */\nexport type ProjectFieldUuid = Branded<string, \"ProjectFieldUuid\">;\n\n/**\n * Whether a role may make a resource public (grant to everyone): true for controller,\n * admin; false for workflow and unspecified. The middle layer carries no policy\n * of its own here — a crafted call still hits the backend's role + permission-ceiling gate.\n * `null` (no-auth mode) returns false.\n */\nexport function canGrantToEveryone(role: Role | null): boolean {\n switch (role) {\n case RoleEnum.CONTROLLER:\n case RoleEnum.ADMIN:\n return true;\n default:\n return false;\n }\n}\n\n/**\n * Whether a role may impersonate another user: open/create another user's root and list\n * the resources that user can access. Mirrors the backend's authorization rule\n * `util/misecurity/role.go` `CanImpersonate` — true for controller and admin only. This is\n * the admin gate for the \"open another user's root\" feature and is intentionally stricter\n * than {@link canGrantToEveryone}, which also returns true for a regular user (a normal user\n * may share their own projects, but must never be offered impersonation). `null` (no-auth\n * mode) returns false.\n */\nexport function canImpersonate(role: Role | null): boolean {\n switch (role) {\n case RoleEnum.CONTROLLER:\n case RoleEnum.ADMIN:\n return true;\n default:\n return false;\n }\n}\n\n/** One project's snapshot inside an envelope, keyed by {@link ProjectFieldUuid} in a\n * `projects` {@link EnvelopePayload}. */\nexport interface EnvelopeProject {\n label: string; // carried so the pending-share UI renders without traversing into the project\n source: ProjectId; // donor's source projectId; supersedes a prior share and matches the snapshot to its live source on change\n updatedAt: number; // ms epoch of the last (re)snapshot\n}\n\n/**\n * What a share carries. The discriminant is what a reader checks before anything else: a\n * client that does not know a kind hides the share instead of offering something it cannot\n * act on.\n *\n * `projects` snapshots ride as `project/{uuid}` fields on the envelope and this map only\n * describes them; a `template` payload has no fields at all — the document is right here.\n */\nexport type EnvelopePayload =\n | { kind: \"projects\"; projects: Record<ProjectFieldUuid, EnvelopeProject> }\n | {\n kind: \"template\";\n document: ProjectTemplateV1;\n /** Label to give the template on the recipient's own shelf. */\n label: string;\n /** Donor login, kept on the accepted template as its provenance. */\n from: string;\n };\n\nexport type EnvelopePayloadKind = EnvelopePayload[\"kind\"];\n\n/** Every envelope schema version this build can read. Adding a version here is what makes\n * {@link normalizeEnvelopeData} accept it; bumping {@link EnvelopeSchemaVersionCurrent} to a\n * version missing from this union is a compile error. */\nexport type EnvelopeSchemaVersion = 1 | 2;\n\n/** Version written into every new envelope. Bumped from 1 when the payload became discriminated. */\nexport const EnvelopeSchemaVersionCurrent = 2 satisfies EnvelopeSchemaVersion;\n\n/**\n * Immutable `data` on a SharedEnvelope, set at createEphemeral, never mutated.\n *\n * Always the current version in memory: a v1 envelope (project map at the top level, no\n * `payload` field) is upcast on read by {@link normalizeEnvelopeData}, so no reader past the\n * decode has to know that two shapes ever existed.\n */\nexport interface EnvelopeData {\n schemaVersion: typeof EnvelopeSchemaVersionCurrent;\n shareId: ShareId; // donor-generated UUID; logical share identity, stable across changes\n sharedAt: number; // ms epoch; this instance's creation time — distinguishes instances of one shareId\n expiresAt: number | null; // ms epoch; sharedAt + ttl (default 14 days) for a targeted share; null for share-with-everybody (never expires)\n mode: EnvelopeMode; // what the acceptor's app should do with the contents\n sender: string; // donor login (informational; backend granted_by is authoritative)\n title: string; // display name shown to recipients; defaults to the first project's name\n payload: EnvelopePayload; // what the share carries\n}\n\n/** The project map of a projects-payload envelope, or `{}` for any other payload — the one\n * place a project-shaped reader turns a payload into the map it expects. */\nexport function envelopeProjectMap(data: EnvelopeData): Record<ProjectFieldUuid, EnvelopeProject> {\n return data.payload.kind === \"projects\" ? data.payload.projects : {};\n}\n\n/** Dynamic field on SharingState, one per handled share, keyed by shareId. */\nexport const decisionField = (shareId: ShareId) => `decision/${shareId}`;\n\nexport interface SharingDecision {\n decision: \"accepted\" | \"rejected\";\n timestamp: number; // ms epoch — when the acceptor acted\n envelopeSharedAt: number; // the acted-on envelope instance's sharedAt — pins which instance was handled (paired with the shareId key; the resource id is never stored)\n acceptedProjects: string[]; // ids of the projects created in the acceptor's list ([] for a rejected share, and for a template share, which creates none)\n}\n\n/** Dynamic field on SharedEnvelope, one per recipient who accepted or rejected, keyed\n * by recipient login. Written by the acceptor in read-write shares only (Copy & Share,\n * Live collaboration) — the acceptor's writable envelope grant is what permits the\n * write; read-only shares omit it. The donor reads these from its own outbox to see\n * who responded and when. Informational, not authoritative (a writable grant holder\n * could write under another login — same trust assumption as the sender field).\n * Copied forward when a share is changed. */\nexport const AcceptanceFieldPrefix = \"acceptance/\";\nexport const acceptanceField = (login: string) => `${AcceptanceFieldPrefix}${login}`;\nexport const isAcceptanceField = (name: string) => name.startsWith(AcceptanceFieldPrefix);\nexport const acceptanceFieldLogin = (name: string) => name.slice(AcceptanceFieldPrefix.length);\n\nexport interface EnvelopeAcceptance {\n action: \"accepted\" | \"rejected\";\n timestamp: number; // ms since epoch\n}\n\n/**\n * Single owner of the raw-data → {@link EnvelopeData} decode. The envelope's immutable `data`\n * blob is UTF-8 JSON set once at createEphemeral; every site that reads it from a raw resource\n * `data` byte buffer (the basic-resource read path) goes through here. The reactive tree-node\n * path decodes the same JSON with `getDataAsJson` and normalizes it with\n * {@link normalizeEnvelopeData} — both paths must, so neither sees the raw v1 shape.\n *\n * `undefined` for an envelope this build cannot act on; see {@link normalizeEnvelopeData}.\n */\nexport function decodeEnvelopeData(data: Uint8Array): EnvelopeData | undefined {\n return normalizeEnvelopeData(JSON.parse(Buffer.from(data).toString(\"utf-8\")));\n}\n\n/**\n * Brings a decoded envelope blob to the current shape, or reports that this build cannot act\n * on it by returning `undefined` — an unknown `schemaVersion` or an unknown payload kind. A\n * caller hides such a share rather than offering the recipient something it cannot handle.\n *\n * A v1 envelope carried its project map at the top level and had no `payload` field; it reads\n * here as a `projects` payload, so envelopes written before the discriminant existed keep\n * working unchanged.\n */\nexport function normalizeEnvelopeData(raw: unknown): EnvelopeData | undefined {\n if (typeof raw !== \"object\" || raw === null) return undefined;\n const e = raw as RawEnvelopeData;\n if (!Object.hasOwn(ReadableSchemaVersions, e.schemaVersion)) return undefined;\n\n const payload =\n e.payload ??\n (e.projects !== undefined ? ({ kind: \"projects\", projects: e.projects } as const) : undefined);\n if (payload === undefined) return undefined;\n if (!Object.hasOwn(KnownPayloadKinds, payload.kind)) return undefined;\n\n return {\n schemaVersion: EnvelopeSchemaVersionCurrent,\n shareId: e.shareId,\n sharedAt: e.sharedAt,\n expiresAt: e.expiresAt,\n mode: e.mode,\n sender: e.sender,\n title: e.title,\n payload,\n };\n}\n\n/**\n * Options for {@link MiddleLayer.shareProjects}.\n *\n * Recipients XOR everyone — two clean variants, not one struct with mutually exclusive\n * optional fields. The everyone variant issues a single make-public grant (the envelope's\n * `expiresAt` is set to `null`, so it never expires); the recipients variant grants each\n * named recipient and the envelope expires after the default TTL.\n */\nexport type ShareProjectsOptions =\n | {\n recipients: string[]; // recipient logins\n title: string; // display name shown to recipients; defaults to the first project's name\n mode: EnvelopeMode; // v1 UI always sends \"copy\"\n }\n | {\n everyone: true; // share with all users on the server\n /**\n * When true and an everyone-share of the same project already exists, refresh it under its\n * stable shareId (recipients who already accepted or rejected are not re-prompted) instead of\n * minting a new share. No-op when no prior everyone-share of the project exists. Callers that\n * don't care pass `false`.\n */\n replace: boolean;\n title: string;\n mode: EnvelopeMode;\n };\n\n/**\n * Options for {@link MiddleLayer.shareTemplate}.\n *\n * Recipients XOR everyone, exactly as {@link ShareProjectsOptions}, minus the mode: a template\n * share is always granted read-only, because the recipient copies no resource out of the\n * envelope — the document is in the envelope's own data.\n */\nexport type ShareTemplateOptions =\n | {\n recipients: string[]; // recipient logins\n title: string; // display name shown to recipients; defaults to the template's label\n }\n | {\n everyone: true; // share with all users on the server\n title: string;\n };\n\n//\n// Internals\n//\n\n/** Every payload kind this build can act on; anything else is hidden rather than offered.\n * Keyed by {@link EnvelopePayloadKind}, so adding a kind to {@link EnvelopePayload} without\n * teaching the decoder about it is a compile error, not a share that silently disappears. */\nconst KnownPayloadKinds: Record<EnvelopePayloadKind, true> = {\n projects: true,\n template: true,\n};\n\n/** Every schema version {@link normalizeEnvelopeData} accepts. Keyed by\n * {@link EnvelopeSchemaVersion}, so widening that union without deciding how the new shape\n * is upcast is a compile error. */\nconst ReadableSchemaVersions: Record<EnvelopeSchemaVersion, true> = {\n 1: true,\n 2: true,\n};\n\n/**\n * The envelope blob as it comes off the wire, before {@link normalizeEnvelopeData} decides\n * whether this build can act on it: the version is any number, the payload may be missing,\n * and `projects` is the v1 top-level project map.\n */\ntype RawEnvelopeData = Omit<EnvelopeData, \"schemaVersion\" | \"payload\"> & {\n schemaVersion: number;\n payload?: EnvelopePayload;\n projects?: Record<ProjectFieldUuid, EnvelopeProject>;\n};\n"],"mappings":";;;;AAeA,SAAgB,aAAsB;CACpC,OAAO,WAAW;AACpB;;;AAIA,SAAgB,UAAU,IAAqB;CAC7C,OAAO;AACT;;AAUA,MAAa,qBAAqB;;AAElC,MAAa,oBAAoB;AAEjC,MAAa,4BAA0C;CAAE,MAAM;CAAiB,SAAS;AAAI;AAC7F,MAAa,6BAA2C;CAAE,MAAM;CAAkB,SAAS;AAAI;AAC/F,MAAa,2BAAyC;CAAE,MAAM;CAAgB,SAAS;AAAI;;;;;;;AAkB3F,SAAgB,mBAAmB,MAA4B;CAC7D,QAAQ,MAAR;EACE,KAAKA,KAAS;EACd,KAAKA,KAAS,OACZ,OAAO;EACT,SACE,OAAO;CACX;AACF;;;;;;;;;;AAWA,SAAgB,eAAe,MAA4B;CACzD,QAAQ,MAAR;EACE,KAAKA,KAAS;EACd,KAAKA,KAAS,OACZ,OAAO;EACT,SACE,OAAO;CACX;AACF;;AAqCA,MAAa,+BAA+B;;;AAsB5C,SAAgB,mBAAmB,MAA+D;CAChG,OAAO,KAAK,QAAQ,SAAS,aAAa,KAAK,QAAQ,WAAW,CAAC;AACrE;;AAGA,MAAa,iBAAiB,YAAqB,YAAY;;;;;;;;AAgB/D,MAAa,wBAAwB;AACrC,MAAa,mBAAmB,UAAkB,GAAG,wBAAwB;AAC7E,MAAa,qBAAqB,SAAiB,KAAK,WAAW,qBAAqB;AACxF,MAAa,wBAAwB,SAAiB,KAAK,MAAM,EAA4B;;;;;;;;;;AAgB7F,SAAgB,mBAAmB,MAA4C;CAC7E,OAAO,sBAAsB,KAAK,MAAM,OAAO,KAAK,IAAI,CAAC,CAAC,SAAS,OAAO,CAAC,CAAC;AAC9E;;;;;;;;;;AAWA,SAAgB,sBAAsB,KAAwC;CAC5E,IAAI,OAAO,QAAQ,YAAY,QAAQ,MAAM,OAAO,KAAA;CACpD,MAAM,IAAI;CACV,IAAI,CAAC,OAAO,OAAO,wBAAwB,EAAE,aAAa,GAAG,OAAO,KAAA;CAEpE,MAAM,UACJ,EAAE,YACD,EAAE,aAAa,KAAA,IAAa;EAAE,MAAM;EAAY,UAAU,EAAE;CAAS,IAAc,KAAA;CACtF,IAAI,YAAY,KAAA,GAAW,OAAO,KAAA;CAClC,IAAI,CAAC,OAAO,OAAO,mBAAmB,QAAQ,IAAI,GAAG,OAAO,KAAA;CAE5D,OAAO;EACL,eAAA;EACA,SAAS,EAAE;EACX,UAAU,EAAE;EACZ,WAAW,EAAE;EACb,MAAM,EAAE;EACR,QAAQ,EAAE;EACV,OAAO,EAAE;EACT;CACF;AACF;;;;AAqDA,MAAM,oBAAuD;CAC3D,UAAU;CACV,UAAU;AACZ;;;;AAKA,MAAM,yBAA8D;CAClE,GAAG;CACH,GAAG;AACL"}
|
|
1
|
+
{"version":3,"file":"sharing_model.js","names":["RoleEnum"],"sources":["../../src/model/sharing_model.ts"],"sourcesContent":["import type { ResourceType, Role } from \"@milaboratories/pl-client\";\nimport { Role as RoleEnum } from \"@milaboratories/pl-client\";\nimport type {\n Branded,\n ProjectId,\n ProjectTemplateV1,\n TemplateId,\n} from \"@milaboratories/pl-model-common\";\nimport type { FolderId } from \"@milaboratories/pl-model-middle-layer\";\nimport { randomUUID } from \"node:crypto\";\n\n/**\n * Identity of one share. A donor-generated UUID string,\n * branded so it cannot be silently confused with a project id, a login, or a raw field\n * name. Minted once with {@link newShareId}; every other site receives it (from decoded\n * {@link EnvelopeData} or by parsing a `decision/{shareId}` field name) and threads it\n * through unchanged.\n */\nexport type ShareId = Branded<string, \"ShareId\">;\n\n/** Mints a fresh {@link ShareId}. The single place a share's logical identity is created. */\nexport function newShareId(): ShareId {\n return randomUUID() as ShareId;\n}\n\n/** Brands a string already known to be a share id (e.g. parsed from a `decision/{shareId}`\n * field name) as a {@link ShareId}, without minting a new one. */\nexport function asShareId(id: string): ShareId {\n return id as ShareId;\n}\n\n//\n// Pl Model — Project Sharing\n//\n// All sharing structures are defined and managed by the middle layer; the\n// backend knows nothing about envelopes.\n//\n\n/** Field on the donor's clientRoot holding the {@link SharingOutboxResourceType} resource. */\nexport const SharingOutboxField = \"sharingOutbox\";\n/** Field on the recipient's clientRoot holding the {@link SharingStateResourceType} resource. */\nexport const SharingStateField = \"sharingState\";\n\nexport const SharingOutboxResourceType: ResourceType = { name: \"SharingOutbox\", version: \"1\" };\nexport const SharedEnvelopeResourceType: ResourceType = { name: \"SharedEnvelope\", version: \"1\" };\nexport const SharingStateResourceType: ResourceType = { name: \"SharingState\", version: \"1\" };\n\nexport type EnvelopeMode = \"copy\" | \"read-only\" | \"collaboration\";\n\n/** Key of the per-project envelope maps: a uuid minted per snapshot to name the `project/{uuid}`\n * field. Distinct from {@link ProjectId} — re-snapshotting one source yields a new uuid each time. */\nexport type ProjectFieldUuid = Branded<string, \"ProjectFieldUuid\">;\n\n/** Mints a fresh {@link ProjectFieldUuid} for one snapshot. */\nexport function newProjectFieldUuid(): ProjectFieldUuid {\n return randomUUID() as ProjectFieldUuid;\n}\n\n/**\n * Whether a role may make a resource public (grant to everyone): true for controller,\n * admin; false for workflow and unspecified. The middle layer carries no policy\n * of its own here — a crafted call still hits the backend's role + permission-ceiling gate.\n * `null` (no-auth mode) returns false.\n */\nexport function canGrantToEveryone(role: Role | null): boolean {\n switch (role) {\n case RoleEnum.CONTROLLER:\n case RoleEnum.ADMIN:\n return true;\n default:\n return false;\n }\n}\n\n/**\n * Whether a role may impersonate another user: open/create another user's root and list\n * the resources that user can access. Mirrors the backend's authorization rule\n * `util/misecurity/role.go` `CanImpersonate` — true for controller and admin only. This is\n * the admin gate for the \"open another user's root\" feature and is intentionally stricter\n * than {@link canGrantToEveryone}, which also returns true for a regular user (a normal user\n * may share their own projects, but must never be offered impersonation). `null` (no-auth\n * mode) returns false.\n */\nexport function canImpersonate(role: Role | null): boolean {\n switch (role) {\n case RoleEnum.CONTROLLER:\n case RoleEnum.ADMIN:\n return true;\n default:\n return false;\n }\n}\n\n/** One project's snapshot inside an envelope, keyed by {@link ProjectFieldUuid} in a\n * `projects` {@link EnvelopePayload}. */\nexport interface EnvelopeProject {\n label: string; // carried so the share lists render without traversing into the project\n source: ProjectId; // donor's source projectId; what a prior share of the same project is matched on\n updatedAt: number; // ms epoch of the last (re)snapshot\n /** What the project said about itself when it was snapshotted, carried for the same reason as\n * `label`. Absent when it had none, and on envelopes written before it was carried. */\n description?: string;\n}\n\n/**\n * Identifier of a folder inside one envelope.\n *\n * Local to the envelope, because the recipient's own folder document mints its own ids and the\n * donor's mean nothing there. What travels is the shape of the subtree, not its identity.\n */\nexport type EnvelopeFolderId = Branded<string, \"EnvelopeFolderId\">;\n\n/** Mints a fresh {@link EnvelopeFolderId} for one folder of the envelope being built. */\nexport function newEnvelopeFolderId(): EnvelopeFolderId {\n return randomUUID() as EnvelopeFolderId;\n}\n\n/** One folder of a shared subtree. */\nexport interface EnvelopeFolder {\n name: string;\n /** Absent for the subtree's root — the folder that was shared. */\n parent?: EnvelopeFolderId;\n /** What the donor wrote about the folder. Absent when there is none. */\n description?: string;\n}\n\n/** A project of a shared subtree: an {@link EnvelopeProject} placed in the subtree. */\nexport interface EnvelopeFolderProject extends EnvelopeProject {\n folder: EnvelopeFolderId;\n}\n\n/** A template of a shared subtree. The document rides here whole, exactly as a `template`\n * payload carries it — a template is never snapshotted. */\nexport interface EnvelopeFolderTemplate {\n document: ProjectTemplateV1;\n /** Label to give the template among the recipient's templates. */\n label: string;\n /** What the template says about itself. Absent when the donor described it with nothing. */\n description?: string;\n folder: EnvelopeFolderId;\n}\n\n/**\n * What a share carries. The discriminant is what a reader checks before anything else: a\n * client that does not know a kind hides the share instead of offering something it cannot\n * act on.\n *\n * `projects` snapshots ride as `project/{uuid}` fields on the envelope and this map only\n * describes them; a `template` payload has no fields at all — the document is right here.\n */\nexport type EnvelopePayload =\n | { kind: \"projects\"; projects: Record<ProjectFieldUuid, EnvelopeProject> }\n | {\n kind: \"template\";\n document: ProjectTemplateV1;\n /** Donor's own id of the shared template; what a prior share of the same template is\n * matched on. It names nothing in the recipient's tree, and envelopes written before it\n * existed carry none — those match no later share of anything. */\n source?: TemplateId;\n /** Label to give the template among the recipient's templates. */\n label: string;\n /** What the template says about itself, carried to the recipient's copy. Absent when the\n * donor described it with nothing. */\n description?: string;\n /** Donor login, kept on each copy of the template as its provenance. */\n from: string;\n }\n | {\n kind: \"folder\";\n /** Donor's own id of the shared folder; what a prior share of the same folder is matched\n * on. It names nothing in the recipient's tree. */\n source: FolderId;\n /** The shared subtree. Exactly one folder has no parent, and that one is its root. */\n folders: Record<EnvelopeFolderId, EnvelopeFolder>;\n /** Project snapshots, each tagged with the folder of the subtree holding it. Their\n * `project/{uuid}` fields are the same ones a `projects` payload describes. */\n projects: Record<ProjectFieldUuid, EnvelopeFolderProject>;\n /** Templates of the subtree, documents and all. Nothing of a template is snapshotted. */\n templates: EnvelopeFolderTemplate[];\n /** Donor login, kept on each copied template as its provenance. */\n from: string;\n };\n\nexport type EnvelopePayloadKind = EnvelopePayload[\"kind\"];\n\n/** Every envelope schema version this build can read. Adding a version here is what makes\n * {@link normalizeEnvelopeData} accept it; bumping {@link EnvelopeSchemaVersionCurrent} to a\n * version missing from this union is a compile error. */\nexport type EnvelopeSchemaVersion = 1 | 2;\n\n/** Version written into every new envelope. Bumped from 1 when the payload became discriminated. */\nexport const EnvelopeSchemaVersionCurrent = 2 satisfies EnvelopeSchemaVersion;\n\n/**\n * Immutable `data` on a SharedEnvelope, set at createEphemeral, never mutated.\n *\n * Always the current version in memory: a v1 envelope (project map at the top level, no\n * `payload` field) is upcast on read by {@link normalizeEnvelopeData}, so no reader past the\n * decode has to know that two shapes ever existed.\n */\nexport interface EnvelopeData {\n schemaVersion: typeof EnvelopeSchemaVersionCurrent;\n shareId: ShareId; // donor-generated UUID; identity of this share alone\n sharedAt: number; // ms epoch; when the share was created\n expiresAt: number | null; // ms epoch; sharedAt + ttl (default 14 days) for a targeted share; null for share-with-everybody (never expires)\n mode: EnvelopeMode; // what the recipient's app should do with the contents\n sender: string; // donor login (informational; backend granted_by is authoritative)\n title: string; // display name shown to recipients; defaults to the first project's name\n payload: EnvelopePayload; // what the share carries\n}\n\n/** The project map of a projects-payload envelope, or `{}` for any other payload — the one\n * place a project-shaped reader turns a payload into the map it expects. */\nexport function envelopeProjectMap(data: EnvelopeData): Record<ProjectFieldUuid, EnvelopeProject> {\n return data.payload.kind === \"projects\" ? data.payload.projects : {};\n}\n\n/**\n * The shared folder itself: the one folder of the subtree that has no parent.\n *\n * Derived rather than stored, so it cannot disagree with the folders beside it. `undefined` for\n * a subtree with no root or more than one, which is an envelope nothing can be reconstructed\n * from — the copy reports it rather than guessing which folder was meant.\n */\nexport function envelopeFolderRoot(\n folders: Record<EnvelopeFolderId, EnvelopeFolder>,\n): EnvelopeFolderId | undefined {\n const roots = (Object.keys(folders) as EnvelopeFolderId[]).filter(\n (id) => folders[id].parent === undefined,\n );\n return roots.length === 1 ? roots[0] : undefined;\n}\n\n/**\n * Dynamic field on SharingState, one per share this user has hidden, keyed by shareId.\n *\n * Hiding is private to the recipient and reversible: the field is written to put a share out of\n * sight and removed to bring it back. It says nothing to the donor and nothing about whether\n * anything was ever copied out of the share — a share can be copied from any number of times,\n * before or after being hidden.\n *\n * The field name keeps its original `decision/` prefix. Records written before hiding replaced\n * accept/reject carry a different value under the same key, and every reader treats the presence\n * of the field as the whole answer: someone who accepted or rejected a share back then does not\n * want to see it, which is exactly what hidden means.\n */\nexport const HiddenFieldPrefix = \"decision/\";\nexport const hiddenField = (shareId: ShareId) => `${HiddenFieldPrefix}${shareId}`;\nexport const isHiddenField = (name: string) => name.startsWith(HiddenFieldPrefix);\nexport const hiddenFieldShareId = (name: string): ShareId =>\n asShareId(name.slice(HiddenFieldPrefix.length));\n\nexport interface ShareHidden {\n hidden: true;\n timestamp: number; // ms epoch — when the recipient hid it\n}\n\n/**\n * Single owner of the raw-data → {@link EnvelopeData} decode. The envelope's immutable `data`\n * blob is UTF-8 JSON set once at createEphemeral; every site that reads it from a raw resource\n * `data` byte buffer (the basic-resource read path) goes through here. The reactive tree-node\n * path decodes the same JSON with `getDataAsJson` and normalizes it with\n * {@link normalizeEnvelopeData} — both paths must, so neither sees the raw v1 shape.\n *\n * `undefined` for an envelope this build cannot act on; see {@link normalizeEnvelopeData}.\n */\nexport function decodeEnvelopeData(data: Uint8Array): EnvelopeData | undefined {\n return normalizeEnvelopeData(JSON.parse(Buffer.from(data).toString(\"utf-8\")));\n}\n\n/**\n * Brings a decoded envelope blob to the current shape, or reports that this build cannot act\n * on it by returning `undefined` — an unknown `schemaVersion` or an unknown payload kind. A\n * caller hides such a share rather than offering the recipient something it cannot handle.\n *\n * A v1 envelope carried its project map at the top level and had no `payload` field; it reads\n * here as a `projects` payload, so envelopes written before the discriminant existed keep\n * working unchanged.\n */\nexport function normalizeEnvelopeData(raw: unknown): EnvelopeData | undefined {\n if (typeof raw !== \"object\" || raw === null) return undefined;\n const e = raw as RawEnvelopeData;\n if (!Object.hasOwn(ReadableSchemaVersions, e.schemaVersion)) return undefined;\n\n const payload =\n e.payload ??\n (e.projects !== undefined ? ({ kind: \"projects\", projects: e.projects } as const) : undefined);\n if (payload === undefined) return undefined;\n if (!Object.hasOwn(KnownPayloadKinds, payload.kind)) return undefined;\n\n return {\n schemaVersion: EnvelopeSchemaVersionCurrent,\n shareId: e.shareId,\n sharedAt: e.sharedAt,\n expiresAt: e.expiresAt,\n mode: e.mode,\n sender: e.sender,\n title: e.title,\n payload,\n };\n}\n\n/**\n * Who a share is granted to: named recipients XOR everyone — two clean variants, not one struct\n * with mutually exclusive optional fields.\n *\n * The everyone variant issues a single make-public grant, and the envelope's `expiresAt` is `null`,\n * so it never expires. The recipients variant grants each named login, and the envelope expires\n * after the default TTL.\n */\nexport type ShareAudience =\n | { recipients: string[] } // recipient logins\n | { everyone: true }; // every user on the server\n\n/**\n * Options every share takes: the audience, the title recipients see it under, and the prior\n * shares it replaces.\n */\nexport type ShareOptions = ShareAudience & {\n title: string;\n replace?: ShareReplaceOption;\n};\n\n/**\n * Prior shares the new one supersedes: each is deleted in the same transaction that creates the\n * replacement, so the outbox never holds both.\n *\n * The set is the caller's, never inferred here. The author is shown the shares that will go and\n * agrees to that list, so what was shown has to be what is deleted — an overlap rule computed on\n * this side would diverge from it. Ids that no longer resolve are skipped: a share revoked between\n * the dialog opening and the confirm is nothing to undo.\n *\n * The replacement is a new {@link ShareId}: a recipient who had hidden the old share sees the new\n * one, and copies already taken from the old share are untouched.\n */\nexport type ShareReplaceOption = ShareId[];\n\n/** Options for {@link MiddleLayer.shareProjects}: the common ones, plus what the recipient's app\n * does with the projects. */\nexport type ShareProjectsOptions = ShareOptions & { mode: EnvelopeMode };\n\n/** Options for {@link MiddleLayer.shareTemplate}. */\nexport type ShareTemplateOptions = ShareOptions;\n\n/** Options for {@link MiddleLayer.shareFolder}. */\nexport type ShareFolderOptions = ShareOptions;\n\n/** What creating a share hands back: the id of the share just created. */\nexport type ShareOutcome = { readonly shareId: ShareId };\n\n//\n// Internals\n//\n\n/** Every payload kind this build can act on; anything else is hidden rather than offered.\n * Keyed by {@link EnvelopePayloadKind}, so adding a kind to {@link EnvelopePayload} without\n * teaching the decoder about it is a compile error, not a share that silently disappears. */\nconst KnownPayloadKinds: Record<EnvelopePayloadKind, true> = {\n projects: true,\n template: true,\n folder: true,\n};\n\n/** Every schema version {@link normalizeEnvelopeData} accepts. Keyed by\n * {@link EnvelopeSchemaVersion}, so widening that union without deciding how the new shape\n * is upcast is a compile error. */\nconst ReadableSchemaVersions: Record<EnvelopeSchemaVersion, true> = {\n 1: true,\n 2: true,\n};\n\n/**\n * The envelope blob as it comes off the wire, before {@link normalizeEnvelopeData} decides\n * whether this build can act on it: the version is any number, the payload may be missing,\n * and `projects` is the v1 top-level project map.\n */\ntype RawEnvelopeData = Omit<EnvelopeData, \"schemaVersion\" | \"payload\"> & {\n schemaVersion: number;\n payload?: EnvelopePayload;\n projects?: Record<ProjectFieldUuid, EnvelopeProject>;\n};\n"],"mappings":";;;;AAqBA,SAAgB,aAAsB;CACpC,OAAO,WAAW;AACpB;;;AAIA,SAAgB,UAAU,IAAqB;CAC7C,OAAO;AACT;;AAUA,MAAa,qBAAqB;;AAElC,MAAa,oBAAoB;AAEjC,MAAa,4BAA0C;CAAE,MAAM;CAAiB,SAAS;AAAI;AAC7F,MAAa,6BAA2C;CAAE,MAAM;CAAkB,SAAS;AAAI;AAC/F,MAAa,2BAAyC;CAAE,MAAM;CAAgB,SAAS;AAAI;;AAS3F,SAAgB,sBAAwC;CACtD,OAAO,WAAW;AACpB;;;;;;;AAQA,SAAgB,mBAAmB,MAA4B;CAC7D,QAAQ,MAAR;EACE,KAAKA,KAAS;EACd,KAAKA,KAAS,OACZ,OAAO;EACT,SACE,OAAO;CACX;AACF;;;;;;;;;;AAWA,SAAgB,eAAe,MAA4B;CACzD,QAAQ,MAAR;EACE,KAAKA,KAAS;EACd,KAAKA,KAAS,OACZ,OAAO;EACT,SACE,OAAO;CACX;AACF;;AAsBA,SAAgB,sBAAwC;CACtD,OAAO,WAAW;AACpB;;AA4EA,MAAa,+BAA+B;;;AAsB5C,SAAgB,mBAAmB,MAA+D;CAChG,OAAO,KAAK,QAAQ,SAAS,aAAa,KAAK,QAAQ,WAAW,CAAC;AACrE;;;;;;;;AASA,SAAgB,mBACd,SAC8B;CAC9B,MAAM,QAAS,OAAO,KAAK,OAAO,CAAC,CAAwB,QACxD,OAAO,QAAQ,GAAG,CAAC,WAAW,KAAA,CACjC;CACA,OAAO,MAAM,WAAW,IAAI,MAAM,KAAK,KAAA;AACzC;;;;;;;;;;;;;;AAeA,MAAa,oBAAoB;AACjC,MAAa,eAAe,YAAqB,GAAG,oBAAoB;AACxE,MAAa,iBAAiB,SAAiB,KAAK,WAAW,iBAAiB;AAChF,MAAa,sBAAsB,SACjC,UAAU,KAAK,MAAM,CAAwB,CAAC;;;;;;;;;;AAgBhD,SAAgB,mBAAmB,MAA4C;CAC7E,OAAO,sBAAsB,KAAK,MAAM,OAAO,KAAK,IAAI,CAAC,CAAC,SAAS,OAAO,CAAC,CAAC;AAC9E;;;;;;;;;;AAWA,SAAgB,sBAAsB,KAAwC;CAC5E,IAAI,OAAO,QAAQ,YAAY,QAAQ,MAAM,OAAO,KAAA;CACpD,MAAM,IAAI;CACV,IAAI,CAAC,OAAO,OAAO,wBAAwB,EAAE,aAAa,GAAG,OAAO,KAAA;CAEpE,MAAM,UACJ,EAAE,YACD,EAAE,aAAa,KAAA,IAAa;EAAE,MAAM;EAAY,UAAU,EAAE;CAAS,IAAc,KAAA;CACtF,IAAI,YAAY,KAAA,GAAW,OAAO,KAAA;CAClC,IAAI,CAAC,OAAO,OAAO,mBAAmB,QAAQ,IAAI,GAAG,OAAO,KAAA;CAE5D,OAAO;EACL,eAAA;EACA,SAAS,EAAE;EACX,UAAU,EAAE;EACZ,WAAW,EAAE;EACb,MAAM,EAAE;EACR,QAAQ,EAAE;EACV,OAAO,EAAE;EACT;CACF;AACF;;;;AAyDA,MAAM,oBAAuD;CAC3D,UAAU;CACV,UAAU;CACV,QAAQ;AACV;;;;AAKA,MAAM,yBAA8D;CAClE,GAAG;CACH,GAAG;AACL"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
let _milaboratories_pl_client = require("@milaboratories/pl-client");
|
|
2
|
+
//#region src/mutator/list.ts
|
|
3
|
+
/**
|
|
4
|
+
* Every entry of a list resource — the project list or the template list — keyed by the string
|
|
5
|
+
* form of the resource id it points at, which is what a project or template id is.
|
|
6
|
+
*
|
|
7
|
+
* A list field's name is a uuid unrelated to the id of what it holds, so an entry is only ever
|
|
8
|
+
* found by value. Fields that point at nothing yet are left out.
|
|
9
|
+
*/
|
|
10
|
+
async function listedById(tx, listRid) {
|
|
11
|
+
const data = await tx.getResourceData(listRid, true);
|
|
12
|
+
const entries = /* @__PURE__ */ new Map();
|
|
13
|
+
for (const f of data.fields) {
|
|
14
|
+
if ((0, _milaboratories_pl_client.isNullSignedResourceId)(f.value)) continue;
|
|
15
|
+
entries.set((0, _milaboratories_pl_client.resourceIdToString)(f.value), {
|
|
16
|
+
fieldName: f.name,
|
|
17
|
+
rid: f.value
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return entries;
|
|
21
|
+
}
|
|
22
|
+
/** What is thrown for an id the list does not hold, worded the same for every list. */
|
|
23
|
+
function notListedError(kind, id) {
|
|
24
|
+
return /* @__PURE__ */ new Error(`${kind} ${id} not found in the ${kind.toLowerCase()} list.`);
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
exports.listedById = listedById;
|
|
28
|
+
exports.notListedError = notListedError;
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=list.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.cjs","names":[],"sources":["../../src/mutator/list.ts"],"sourcesContent":["import type { PlTransaction, SignedResourceId } from \"@milaboratories/pl-client\";\nimport { isNullSignedResourceId, resourceIdToString } from \"@milaboratories/pl-client\";\n\n/** One entry of a list resource: the field holding it and the resource that field points at. */\nexport interface ListedEntry {\n readonly fieldName: string;\n readonly rid: SignedResourceId;\n}\n\n/** The kinds of list a root keeps, as a not-found message names them. */\nexport type ListedKind = \"Project\" | \"Template\";\n\n/**\n * Every entry of a list resource — the project list or the template list — keyed by the string\n * form of the resource id it points at, which is what a project or template id is.\n *\n * A list field's name is a uuid unrelated to the id of what it holds, so an entry is only ever\n * found by value. Fields that point at nothing yet are left out.\n */\nexport async function listedById(\n tx: PlTransaction,\n listRid: SignedResourceId,\n): Promise<Map<string, ListedEntry>> {\n const data = await tx.getResourceData(listRid, true);\n const entries = new Map<string, ListedEntry>();\n for (const f of data.fields) {\n if (isNullSignedResourceId(f.value)) continue;\n entries.set(resourceIdToString(f.value), { fieldName: f.name, rid: f.value });\n }\n return entries;\n}\n\n/** What is thrown for an id the list does not hold, worded the same for every list. */\nexport function notListedError(kind: ListedKind, id: string): Error {\n return new Error(`${kind} ${id} not found in the ${kind.toLowerCase()} list.`);\n}\n"],"mappings":";;;;;;;;;AAmBA,eAAsB,WACpB,IACA,SACmC;CACnC,MAAM,OAAO,MAAM,GAAG,gBAAgB,SAAS,IAAI;CACnD,MAAM,0BAAU,IAAI,IAAyB;CAC7C,KAAK,MAAM,KAAK,KAAK,QAAQ;EAC3B,KAAA,GAAA,0BAAA,uBAAA,CAA2B,EAAE,KAAK,GAAG;EACrC,QAAQ,KAAA,GAAA,0BAAA,mBAAA,CAAuB,EAAE,KAAK,GAAG;GAAE,WAAW,EAAE;GAAM,KAAK,EAAE;EAAM,CAAC;CAC9E;CACA,OAAO;AACT;;AAGA,SAAgB,eAAe,MAAkB,IAAmB;CAClE,uBAAO,IAAI,MAAM,GAAG,KAAK,GAAG,GAAG,oBAAoB,KAAK,YAAY,EAAE,OAAO;AAC/E"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { isNullSignedResourceId, resourceIdToString } from "@milaboratories/pl-client";
|
|
2
|
+
//#region src/mutator/list.ts
|
|
3
|
+
/**
|
|
4
|
+
* Every entry of a list resource — the project list or the template list — keyed by the string
|
|
5
|
+
* form of the resource id it points at, which is what a project or template id is.
|
|
6
|
+
*
|
|
7
|
+
* A list field's name is a uuid unrelated to the id of what it holds, so an entry is only ever
|
|
8
|
+
* found by value. Fields that point at nothing yet are left out.
|
|
9
|
+
*/
|
|
10
|
+
async function listedById(tx, listRid) {
|
|
11
|
+
const data = await tx.getResourceData(listRid, true);
|
|
12
|
+
const entries = /* @__PURE__ */ new Map();
|
|
13
|
+
for (const f of data.fields) {
|
|
14
|
+
if (isNullSignedResourceId(f.value)) continue;
|
|
15
|
+
entries.set(resourceIdToString(f.value), {
|
|
16
|
+
fieldName: f.name,
|
|
17
|
+
rid: f.value
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return entries;
|
|
21
|
+
}
|
|
22
|
+
/** What is thrown for an id the list does not hold, worded the same for every list. */
|
|
23
|
+
function notListedError(kind, id) {
|
|
24
|
+
return /* @__PURE__ */ new Error(`${kind} ${id} not found in the ${kind.toLowerCase()} list.`);
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { listedById, notListedError };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.js","names":[],"sources":["../../src/mutator/list.ts"],"sourcesContent":["import type { PlTransaction, SignedResourceId } from \"@milaboratories/pl-client\";\nimport { isNullSignedResourceId, resourceIdToString } from \"@milaboratories/pl-client\";\n\n/** One entry of a list resource: the field holding it and the resource that field points at. */\nexport interface ListedEntry {\n readonly fieldName: string;\n readonly rid: SignedResourceId;\n}\n\n/** The kinds of list a root keeps, as a not-found message names them. */\nexport type ListedKind = \"Project\" | \"Template\";\n\n/**\n * Every entry of a list resource — the project list or the template list — keyed by the string\n * form of the resource id it points at, which is what a project or template id is.\n *\n * A list field's name is a uuid unrelated to the id of what it holds, so an entry is only ever\n * found by value. Fields that point at nothing yet are left out.\n */\nexport async function listedById(\n tx: PlTransaction,\n listRid: SignedResourceId,\n): Promise<Map<string, ListedEntry>> {\n const data = await tx.getResourceData(listRid, true);\n const entries = new Map<string, ListedEntry>();\n for (const f of data.fields) {\n if (isNullSignedResourceId(f.value)) continue;\n entries.set(resourceIdToString(f.value), { fieldName: f.name, rid: f.value });\n }\n return entries;\n}\n\n/** What is thrown for an id the list does not hold, worded the same for every list. */\nexport function notListedError(kind: ListedKind, id: string): Error {\n return new Error(`${kind} ${id} not found in the ${kind.toLowerCase()} list.`);\n}\n"],"mappings":";;;;;;;;;AAmBA,eAAsB,WACpB,IACA,SACmC;CACnC,MAAM,OAAO,MAAM,GAAG,gBAAgB,SAAS,IAAI;CACnD,MAAM,0BAAU,IAAI,IAAyB;CAC7C,KAAK,MAAM,KAAK,KAAK,QAAQ;EAC3B,IAAI,uBAAuB,EAAE,KAAK,GAAG;EACrC,QAAQ,IAAI,mBAAmB,EAAE,KAAK,GAAG;GAAE,WAAW,EAAE;GAAM,KAAK,EAAE;EAAM,CAAC;CAC9E;CACA,OAAO;AACT;;AAGA,SAAgB,eAAe,MAAkB,IAAmB;CAClE,uBAAO,IAAI,MAAM,GAAG,KAAK,GAAG,GAAG,oBAAoB,KAAK,YAAY,EAAE,OAAO;AAC/E"}
|
package/dist/mutator/project.cjs
CHANGED
|
@@ -936,10 +936,23 @@ var ProjectMutator = class ProjectMutator {
|
|
|
936
936
|
}
|
|
937
937
|
/** Updates project metadata */
|
|
938
938
|
setMeta(meta) {
|
|
939
|
-
this.meta = meta;
|
|
939
|
+
this.meta = (0, _milaboratories_pl_model_middle_layer.normalizeProjectMeta)(meta);
|
|
940
940
|
this.metaChanged = true;
|
|
941
941
|
this.updateLastModified();
|
|
942
942
|
}
|
|
943
|
+
/**
|
|
944
|
+
* Updates the metadata fields the caller names, leaving the rest as they are.
|
|
945
|
+
*
|
|
946
|
+
* The merge happens against the metadata this mutator loaded inside the very transaction it
|
|
947
|
+
* writes in, so a rename and a description edit racing each other cannot make one of them
|
|
948
|
+
* revert the other's field.
|
|
949
|
+
*/
|
|
950
|
+
updateMeta(patch) {
|
|
951
|
+
this.setMeta({
|
|
952
|
+
...this.meta,
|
|
953
|
+
...patch
|
|
954
|
+
});
|
|
955
|
+
}
|
|
943
956
|
/** Background maintenance: render pending stagings + GC of Previous fields. */
|
|
944
957
|
doRefresh() {
|
|
945
958
|
this.refreshStagings();
|