@milaboratories/pl-middle-layer 1.73.10 → 1.74.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.
@@ -332,6 +332,28 @@ export declare class MiddleLayer {
332
332
  * @param description what the template is for; blank or absent stores none
333
333
  */
334
334
  saveProjectAsTemplate(projectId: ProjectId$1, label?: string, description?: string): Promise<SaveProjectAsTemplateOutcome>;
335
+ /**
336
+ * Stores a template brought in from outside — a template file the user picked — so it can be
337
+ * seen, applied and shared like one saved from a project.
338
+ *
339
+ * The document's description becomes the template's own, which stays editable; the stored
340
+ * document keeps only the blocks, without the label and description it was written with, so
341
+ * there is one name and one description to edit and nothing to drift.
342
+ *
343
+ * The template lands in `folder`, or at the top level, under `label` made free among the
344
+ * templates already there. A folder deleted meanwhile costs the template its placement, not its
345
+ * existence.
346
+ *
347
+ * @param document the parsed template to store
348
+ * @param options.label the name to store it under — usually the document's own label, which
349
+ * the caller weighs against whatever else it knows, such as the file's name; suffixed when a
350
+ * template there carries it
351
+ * @param options.folder where it lands; the top level when absent
352
+ */
353
+ importTemplate(document: ProjectTemplateV1, options: {
354
+ label: string;
355
+ folder?: FolderId;
356
+ }): Promise<TemplateId$1>;
335
357
  /**
336
358
  * Changes a template's label. The stored document is immutable and stays untouched —
337
359
  * improving a template means saving a new one.
@@ -1 +1 @@
1
- {"version":3,"file":"middle_layer.d.ts","names":[],"sources":["../../src/middle_layer/middle_layer.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiLiB;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;m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;UA2CA;;;;;;;;;;;;;UAoBA;;;;;;;EAkBD,YAAY,SAAS,UAAU;;;;;;;UAiB9B;;;;;;;;;;;UA0BA;;;;;;;;;;;;;;;;EAwBD,UACX,UAAU,WACV,cAAc,WACb;IACD,UAAU;IACV,WAAW;IACX;MAAU,SAAS;MAAS;;;;;;;;EA8JjB,UAAU,SAAS,UAAU;;EAW7B,YAAY,SAAS,UAAU;0BAapB;UAChB;;UAGA;;;UAWM;mBAsCG;;;mBAIA;UAET;;;;;;;UAWM;;EAgBD,YAAY,IAAI,cAAY;;EAQ5B,aAAa,IAAI,cAAY;;EAmBnC,iBAAiB,IAAI,cAAY;;EAOjC,gBAAgB,IAAI;;;;MAOhB,qBAAqB,SAAS;;;;;;EAS5B,SAAK;;EAkBL,4BAAwB;;;SAMvB;;MAKH,wBAAwB;;SAKf,KAClB,IAAI,UACJ,iBACA,MAAM,4BACL,QAAQ"}
@@ -27,7 +27,7 @@ import { RuntimeCapabilities, ensureError, extractConfig } from "@platforma-sdk/
27
27
  import { foldersNameTaken, foldersUniqueName, inheritedFolder, normalizeDescription } from "@milaboratories/pl-model-middle-layer";
28
28
  import { RetryAgent } from "undici";
29
29
  import { BlockEventDispatcher, HmacSha256Signer } from "@milaboratories/ts-helpers";
30
- import { REQUIRES_PFRAMES_VERSION, asProjectId, asTemplateId, registerServiceCapabilities } from "@milaboratories/pl-model-common";
30
+ import { REQUIRES_PFRAMES_VERSION, asProjectId, asTemplateId, registerServiceCapabilities, withTemplateMeta } from "@milaboratories/pl-model-common";
31
31
  import { GrantType, field, isNullSignedResourceId, resourceIdToString } from "@milaboratories/pl-client";
32
32
  import { LRUCache } from "lru-cache";
33
33
  import { WatchableValue } from "@milaboratories/computable";
@@ -659,6 +659,49 @@ var MiddleLayer = class MiddleLayer {
659
659
  };
660
660
  }
661
661
  /**
662
+ * Stores a template brought in from outside — a template file the user picked — so it can be
663
+ * seen, applied and shared like one saved from a project.
664
+ *
665
+ * The document's description becomes the template's own, which stays editable; the stored
666
+ * document keeps only the blocks, without the label and description it was written with, so
667
+ * there is one name and one description to edit and nothing to drift.
668
+ *
669
+ * The template lands in `folder`, or at the top level, under `label` made free among the
670
+ * templates already there. A folder deleted meanwhile costs the template its placement, not its
671
+ * existence.
672
+ *
673
+ * @param document the parsed template to store
674
+ * @param options.label the name to store it under — usually the document's own label, which
675
+ * the caller weighs against whatever else it knows, such as the file's name; suffixed when a
676
+ * template there carries it
677
+ * @param options.folder where it lands; the top level when absent
678
+ */
679
+ async importTemplate(document, options) {
680
+ const { folder } = options;
681
+ const signedRid = await this.pl.withWriteTx("MLImportTemplate", async (tx) => {
682
+ const tree = await openFoldersTx(tx, this.foldersRids);
683
+ const destination = folder !== void 0 && tree.view.folders.some((candidate) => candidate.id === folder) ? folder : void 0;
684
+ const name = foldersUniqueName(options.label.trim(), tree.namesTakenIn(destination, "template"));
685
+ const created = await createTemplate(tx, this.templateListResourceId, {
686
+ label: name,
687
+ description: document.description
688
+ }, {
689
+ schemaVersion: 1,
690
+ document: withTemplateMeta(document, {})
691
+ }).globalId;
692
+ if (destination !== void 0) tree.place([{
693
+ kind: "template",
694
+ id: asTemplateId(resourceIdToString(created))
695
+ }], destination);
696
+ await tx.commit();
697
+ return created;
698
+ });
699
+ await Promise.all([this.templateListTree.refreshState(), ...folder === void 0 ? [] : [this.foldersTree.refreshState()]]);
700
+ const templateId = asTemplateId(resourceIdToString(signedRid));
701
+ this.templateIdCache.set(templateId, signedRid);
702
+ return templateId;
703
+ }
704
+ /**
662
705
  * Changes a template's label. The stored document is immutable and stays untouched —
663
706
  * improving a template means saving a new one.
664
707
  *