@milaboratories/pl-middle-layer 1.68.2 → 1.69.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 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.js +5 -2
- package/dist/middle_layer/build_stamp.cjs +1 -1
- package/dist/middle_layer/build_stamp.js +1 -1
- package/dist/middle_layer/index.cjs +2 -0
- package/dist/middle_layer/index.d.ts +2 -1
- package/dist/middle_layer/index.js +2 -1
- package/dist/middle_layer/middle_layer.cjs +333 -26
- package/dist/middle_layer/middle_layer.cjs.map +1 -1
- package/dist/middle_layer/middle_layer.d.ts +125 -7
- package/dist/middle_layer/middle_layer.d.ts.map +1 -1
- package/dist/middle_layer/middle_layer.js +335 -28
- package/dist/middle_layer/middle_layer.js.map +1 -1
- package/dist/middle_layer/project_list.d.ts +1 -1
- package/dist/middle_layer/sharing_list.cjs +13 -5
- package/dist/middle_layer/sharing_list.cjs.map +1 -1
- package/dist/middle_layer/sharing_list.d.ts +16 -2
- package/dist/middle_layer/sharing_list.d.ts.map +1 -1
- package/dist/middle_layer/sharing_list.js +14 -6
- package/dist/middle_layer/sharing_list.js.map +1 -1
- package/dist/middle_layer/template_list.cjs +72 -0
- package/dist/middle_layer/template_list.cjs.map +1 -0
- package/dist/middle_layer/template_list.d.ts +77 -0
- package/dist/middle_layer/template_list.d.ts.map +1 -0
- package/dist/middle_layer/template_list.js +64 -0
- package/dist/middle_layer/template_list.js.map +1 -0
- package/dist/model/index.cjs +8 -0
- package/dist/model/index.d.ts +5 -2
- package/dist/model/index.js +4 -2
- package/dist/model/sharing_model.cjs +59 -2
- package/dist/model/sharing_model.cjs.map +1 -1
- package/dist/model/sharing_model.d.ts +70 -7
- package/dist/model/sharing_model.d.ts.map +1 -1
- package/dist/model/sharing_model.js +57 -3
- package/dist/model/sharing_model.js.map +1 -1
- package/dist/model/template_serializer.d.ts +36 -0
- package/dist/model/template_serializer.d.ts.map +1 -1
- package/dist/model/template_share.cjs +42 -0
- package/dist/model/template_share.cjs.map +1 -0
- package/dist/model/template_share.d.ts +27 -0
- package/dist/model/template_share.d.ts.map +1 -0
- package/dist/model/template_share.js +42 -0
- package/dist/model/template_share.js.map +1 -0
- package/dist/mutator/project.cjs +2 -2
- package/dist/mutator/project.js +2 -2
- package/dist/mutator/sharing.cjs +40 -2
- package/dist/mutator/sharing.cjs.map +1 -1
- package/dist/mutator/sharing.js +40 -3
- package/dist/mutator/sharing.js.map +1 -1
- package/dist/mutator/template.cjs +54 -0
- package/dist/mutator/template.cjs.map +1 -0
- package/dist/mutator/template.js +52 -0
- package/dist/mutator/template.js.map +1 -0
- package/package.json +10 -10
- package/src/middle_layer/index.ts +9 -0
- package/src/middle_layer/middle_layer.ts +449 -36
- package/src/middle_layer/sharing_list.ts +37 -7
- package/src/middle_layer/template_list.ts +177 -0
- package/src/middle_layer/templates.test.ts +301 -0
- package/src/model/index.ts +14 -0
- package/src/model/sharing_model.test.ts +115 -1
- package/src/model/sharing_model.ts +134 -9
- package/src/model/template_share.test.ts +78 -0
- package/src/model/template_share.ts +52 -0
- package/src/mutator/sharing.ts +55 -3
- package/src/mutator/template.ts +75 -0
- package/src/test/with_ml.ts +38 -0
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { V2RegistryProvider } from "../block_registry/registry-v2-provider.js";
|
|
2
2
|
import { TemplateApplyReport } from "../model/template_apply.js";
|
|
3
|
-
import { BlockPackProvider } from "../model/template_resolve.js";
|
|
3
|
+
import { BlockPackProvider, TemplateResolveOutcome } from "../model/template_resolve.js";
|
|
4
4
|
import "../block_registry/index.js";
|
|
5
5
|
import { ProjectId as ProjectId$1, ProjectListEntry as ProjectListEntry$1 } from "../model/project_model.js";
|
|
6
|
+
import { TemplateShareProblem } from "../model/template_share.js";
|
|
7
|
+
import { ProjectChangeAction, ShareId, ShareProjectsOptions, ShareTemplateOptions } from "../model/sharing_model.js";
|
|
8
|
+
import { CreateProjectFromTemplateOutcome, SaveProjectAsTemplateOutcome, ShareTemplateOutcome, StoredTemplateData, TemplateId, TemplateListEntry } from "./template_list.js";
|
|
6
9
|
import { ProjectTemplateExportOutcome } from "../model/template_serializer.js";
|
|
7
|
-
import { ProjectChangeAction, ShareId, ShareProjectsOptions } from "../model/sharing_model.js";
|
|
8
10
|
import { OutgoingShare, PendingShare } from "./sharing_list.js";
|
|
9
11
|
import "../model/index.js";
|
|
10
12
|
import { BlockPackPreparer } from "../mutator/block-pack/block_pack.js";
|
|
@@ -62,16 +64,20 @@ export declare class MiddleLayer {
|
|
|
62
64
|
readonly driverKit: DriverKit;
|
|
63
65
|
readonly signer: Signer;
|
|
64
66
|
private readonly projectListResourceId;
|
|
67
|
+
private readonly templateListResourceId;
|
|
65
68
|
private readonly sharingOutboxResourceId;
|
|
66
69
|
private readonly sharingStateResourceId;
|
|
67
70
|
private readonly openedProjectsList;
|
|
68
71
|
private readonly projectListTree;
|
|
72
|
+
private readonly templateListTree;
|
|
69
73
|
private readonly sharingOutboxTree;
|
|
70
74
|
private readonly sharingStateTree;
|
|
71
75
|
private readonly pendingSharesTree;
|
|
72
76
|
readonly blockRegistryProvider: V2RegistryProvider;
|
|
73
77
|
/** Contains a reactive list of projects along with their meta information. */
|
|
74
78
|
readonly projectList: ComputableStableDefined<ProjectListEntry$1[]>;
|
|
79
|
+
/** Contains a reactive list of stored templates along with their labels and provenance. */
|
|
80
|
+
readonly templateList: ComputableStableDefined<TemplateListEntry[]>;
|
|
75
81
|
/** Reactive view of the donor's outbox — the shares this user has created.
|
|
76
82
|
* v1: API only, no UI. */
|
|
77
83
|
outgoingShares: Computable<OutgoingShare[] | undefined>;
|
|
@@ -209,6 +215,70 @@ export declare class MiddleLayer {
|
|
|
209
215
|
allowUnstable?: boolean;
|
|
210
216
|
author?: AuthorMarker;
|
|
211
217
|
}): Promise<TemplateApplyReport>;
|
|
218
|
+
/**
|
|
219
|
+
* Stages 1 and 2 of an apply — resolve every entry to a block pack, then prepare every
|
|
220
|
+
* block — for a document that may not have a project yet.
|
|
221
|
+
*
|
|
222
|
+
* Neither stage creates anything, which is what lets a caller run them before it decides to
|
|
223
|
+
* create a project at all: {@link createProjectFromTemplate} does exactly that, so an
|
|
224
|
+
* unapplicable template leaves no empty project behind.
|
|
225
|
+
*/
|
|
226
|
+
private prepareTemplateEntries;
|
|
227
|
+
/**
|
|
228
|
+
* Stage 3 of an apply — create the blocks in one transaction, all or nothing.
|
|
229
|
+
*
|
|
230
|
+
* An entry it cannot create throws, the transaction is never committed, and the project keeps
|
|
231
|
+
* none of the blocks the apply had placed.
|
|
232
|
+
*/
|
|
233
|
+
private applyPreparedEntries;
|
|
234
|
+
private readonly templateIdCache;
|
|
235
|
+
/**
|
|
236
|
+
* Saves a project as a template: a snapshot of its blocks and their params, no data.
|
|
237
|
+
*
|
|
238
|
+
* The document the export produced is what gets stored; the YAML it also rendered is a
|
|
239
|
+
* file format, and a stored template is rendered to it only on download.
|
|
240
|
+
*
|
|
241
|
+
* A block that cannot be expressed as a template entry stores nothing at all, and every
|
|
242
|
+
* such block is reported — fixing an unexportable project takes one pass, not one per block.
|
|
243
|
+
*
|
|
244
|
+
* @param projectId project to snapshot
|
|
245
|
+
* @param label label for the template; defaults to the project's own label
|
|
246
|
+
*/
|
|
247
|
+
saveProjectAsTemplate(projectId: ProjectId$1, label?: string): Promise<SaveProjectAsTemplateOutcome>;
|
|
248
|
+
/** Changes a template's label. The stored document is immutable and stays untouched —
|
|
249
|
+
* improving a template means saving a new one. */
|
|
250
|
+
renameTemplate(id: TemplateId, label: string): Promise<void>;
|
|
251
|
+
/** Permanently deletes a template from the template list. */
|
|
252
|
+
deleteTemplate(id: TemplateId): Promise<void>;
|
|
253
|
+
/** Reads a stored template: its document plus what was true when it was taken. */
|
|
254
|
+
getTemplateData(id: TemplateId): Promise<StoredTemplateData>;
|
|
255
|
+
/**
|
|
256
|
+
* Where each entry of a stored template would get its block from, and which entries have
|
|
257
|
+
* nowhere to get one — resolution creates nothing, so this is the preview a UI shows before
|
|
258
|
+
* offering Apply. {@link createProjectFromTemplate} runs the same stage itself.
|
|
259
|
+
*/
|
|
260
|
+
resolveTemplate(id: TemplateId, provider: BlockPackProvider, options?: {
|
|
261
|
+
allowUnstable?: boolean;
|
|
262
|
+
}): Promise<TemplateResolveOutcome>;
|
|
263
|
+
/**
|
|
264
|
+
* Creates one project holding every block the stored template lists, in the template's order.
|
|
265
|
+
*
|
|
266
|
+
* Resolution and preparation run before the project exists, so a template with an entry
|
|
267
|
+
* nothing can supply a block for leaves no empty project in the list. The one write that
|
|
268
|
+
* follows is all or nothing, and an entry it rejects takes the project with it.
|
|
269
|
+
*
|
|
270
|
+
* @param id template to apply
|
|
271
|
+
* @param label label for the new project
|
|
272
|
+
* @param provider where each entry's block comes from
|
|
273
|
+
* @param options `allowUnstable` widens resolution to pre-release implementations
|
|
274
|
+
*/
|
|
275
|
+
createProjectFromTemplate(id: TemplateId, label: string, provider: BlockPackProvider, options?: {
|
|
276
|
+
allowUnstable?: boolean;
|
|
277
|
+
author?: AuthorMarker;
|
|
278
|
+
}): Promise<CreateProjectFromTemplateOutcome>;
|
|
279
|
+
/** Resolves a TemplateId to a signed SignedResourceId.
|
|
280
|
+
* Uses LRU cache with TX-scan fallback. */
|
|
281
|
+
private resolveTemplateId;
|
|
212
282
|
/** Permanently deletes project from the project list, this will result in
|
|
213
283
|
* destruction of all attached objects, like files, analysis results etc. */
|
|
214
284
|
deleteProject(id: ProjectId$1): Promise<void>;
|
|
@@ -251,6 +321,42 @@ export declare class MiddleLayer {
|
|
|
251
321
|
* the mint-a-new-envelope branch.
|
|
252
322
|
*/
|
|
253
323
|
private createNewShare;
|
|
324
|
+
/**
|
|
325
|
+
* Grants one freshly built envelope inside the transaction that created it: a single make-public
|
|
326
|
+
* grant for an everyone-share (empty/ignored target, ANY_AUTHORISED — the backend rewrites the
|
|
327
|
+
* target to the everyone-user, gated by role + permission ceiling), or one grant per named
|
|
328
|
+
* recipient.
|
|
329
|
+
*
|
|
330
|
+
* `writable` is not a preference. A project pack needs a writable grant because accepting copies
|
|
331
|
+
* the snapshots out of the envelope, and the cross-color attach rule permits that only to a
|
|
332
|
+
* writable grant holder. A template share copies nothing — the document sits in the envelope's
|
|
333
|
+
* own immutable data — so it is granted read-only, and must be: a writable everyone-grant would
|
|
334
|
+
* hand every user on the server write access to the envelope.
|
|
335
|
+
*/
|
|
336
|
+
private grantShareEnvelope;
|
|
337
|
+
/**
|
|
338
|
+
* Shares one stored template. The envelope carries the document itself, so there is no project
|
|
339
|
+
* snapshot and no resource for the recipient to copy out — which is why the grant is read-only.
|
|
340
|
+
* The cost of that is the donor's receipt: nobody can write an acceptance onto a read-only
|
|
341
|
+
* envelope, so a template share never reports who accepted it.
|
|
342
|
+
*
|
|
343
|
+
* A template holding a block installed from a folder on this machine is refused rather than sent,
|
|
344
|
+
* with every offending entry named. {@link checkTemplateShareable} answers the same question
|
|
345
|
+
* without attempting the share, so a UI can state it on the template itself.
|
|
346
|
+
*
|
|
347
|
+
* @param id template to share
|
|
348
|
+
* @param options recipients XOR everyone, plus the title recipients see
|
|
349
|
+
*/
|
|
350
|
+
shareTemplate(id: TemplateId, options: ShareTemplateOptions): Promise<ShareTemplateOutcome>;
|
|
351
|
+
/**
|
|
352
|
+
* Every entry of a stored template that stands in the way of sharing it, empty for a template
|
|
353
|
+
* that can be shared. Reads the template and nothing else, so a UI can state the refusal on the
|
|
354
|
+
* template itself instead of only when the user tries to share it.
|
|
355
|
+
*/
|
|
356
|
+
checkTemplateShareable(id: TemplateId): Promise<readonly TemplateShareProblem[]>;
|
|
357
|
+
/** The document and the label of a template that may be shared, or every entry that stops it.
|
|
358
|
+
* The label is what the recipient's own list will show, so it travels with the document. */
|
|
359
|
+
private loadShareableTemplate;
|
|
254
360
|
/**
|
|
255
361
|
* Changes a share in place (same {@link ShareId}), in one write transaction: re-snapshots live
|
|
256
362
|
* source projects and carries deleted ones' snapshots forward; applies edited recipients/title;
|
|
@@ -266,12 +372,19 @@ export declare class MiddleLayer {
|
|
|
266
372
|
* existing snapshot (and its timestamp), `remove` drops the project from the pack. A project not
|
|
267
373
|
* in the map defaults to `keep`. Omit the whole map for the legacy auto behavior (live sources
|
|
268
374
|
* updated, gone ones kept) — the everyone-refresh path relies on that.
|
|
375
|
+
*
|
|
376
|
+
* `opts.templateId` is required for, and only used by, a share that carries a template: a stored
|
|
377
|
+
* template is immutable, so an improved one is a different template and the share cannot re-read
|
|
378
|
+
* the one it started from — the caller names the new target. Every other option means the same
|
|
379
|
+
* thing for both kinds of share. Sharing the named template must be permitted (see
|
|
380
|
+
* {@link checkTemplateShareable}) or this throws.
|
|
269
381
|
*/
|
|
270
382
|
changeShare(shareId: ShareId, opts?: {
|
|
271
383
|
recipients?: string[];
|
|
272
384
|
everyone?: boolean;
|
|
273
385
|
title?: string;
|
|
274
386
|
projectActions?: Record<ProjectId$1, ProjectChangeAction>;
|
|
387
|
+
templateId?: TemplateId;
|
|
275
388
|
}): Promise<void>;
|
|
276
389
|
/**
|
|
277
390
|
* Finds the donor's own outgoing envelopes built from any of the given source projects —
|
|
@@ -305,16 +418,21 @@ export declare class MiddleLayer {
|
|
|
305
418
|
*/
|
|
306
419
|
private resolveLiveEnvelopes;
|
|
307
420
|
/**
|
|
308
|
-
* Accepts one or more pending shares
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
421
|
+
* Accepts one or more pending shares. What accepting does depends on what the share carries: a
|
|
422
|
+
* pack of projects is duplicated into this user's project list, while a template is added to this
|
|
423
|
+
* user's own template list and builds nothing — the recipient decides later whether to apply it.
|
|
424
|
+
* Either way the decision is recorded per share, and a read-write share also gets the
|
|
425
|
+
* donor-visible acceptance written onto its envelope. Per-share failures (e.g. an expiry race)
|
|
426
|
+
* are collected, not short-circuited — the rest still get accepted. Accept-all = pass every
|
|
427
|
+
* current pending shareId.
|
|
312
428
|
*
|
|
313
429
|
* `rename` resolves label collisions (same callback contract as {@link duplicateProject}), but
|
|
314
|
-
* the source lives in the envelope tree, so accept calls the low-level mutator directly.
|
|
430
|
+
* the source lives in the envelope tree, so accept calls the low-level mutator directly. It does
|
|
431
|
+
* not apply to a template share, whose label is not required to be unique.
|
|
315
432
|
*/
|
|
316
433
|
acceptShare(shareIds: ShareId[], rename?: (previousLabel: string, existingLabels: string[]) => string): Promise<{
|
|
317
434
|
accepted: ProjectId$1[];
|
|
435
|
+
acceptedTemplates: TemplateId[];
|
|
318
436
|
failed: {
|
|
319
437
|
shareId: ShareId;
|
|
320
438
|
error: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middle_layer.d.ts","names":[],"sources":["../../src/middle_layer/middle_layer.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"middle_layer.d.ts","names":[],"sources":["../../src/middle_layer/middle_layer.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8IiB;EACf,WAAW;WACF,IAAI;WACJ,qBAAqB;WACrB,QAAQ;WACR,sBAAsB;WACtB,gBAAgB;WAChB,qBAAqB;WACrB,QAAQ;WACR,KAAK;WACL,YAAY;WACZ,wBAAwB;WACxB,oBAAoB;WACpB,SAAS;WACT,WAAW;WACX,iBAAiB;WACjB,eAAe;;;WAGf,gBAAgB;;;;;;;;;;;;;;qBAed;mBAIQ;WACD,WAAW;WACX,QAAQ;mBACP;mBACA;mBACA;mBACA;mBACA;mBACA;mBACA;mBACA;mBACA;mBACA;WACD,uBAAuB;;WAEvB,aAAa,wBAAwB;;WAErC,cAAc,wBAAwB;;;EAG/C,gBAAgB,WAAW;;;EAG3B,eAAe,WAAW;;;;mBAIhB;WA9BH,IAAI;UAEb;;;;;MAsCI,kBAAkB;;;;;;;MAUlB;;;;;MAQA;;;;;;;MAUA;;MAQA;;;;;MAQA,mBAAmB;;;;;;;MAUnB;;;;;;;;MAeA;;EAKJ,qBACL,aAAa,sBACb;;EAMK,wBAAwB,cAAc;;MAKlC,qBAAqB;;MAKrB,mBAAmB;mBAQb;;;UAI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