@thatopen/services 0.33.0 → 0.34.2

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/cli.js CHANGED
@@ -7201,7 +7201,7 @@ class FlowDoc {
7201
7201
  ...head ? { parents: [head.guid] } : {},
7202
7202
  author: input.author,
7203
7203
  source: input.source,
7204
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
7204
+ timestamp: input.timestamp ?? (/* @__PURE__ */ new Date()).toISOString(),
7205
7205
  ...input.message ? { message: input.message } : {},
7206
7206
  ...input.userId ? { userId: input.userId } : {},
7207
7207
  ...input.kind ? { kind: input.kind } : {},
@@ -7216,16 +7216,13 @@ class FlowDoc {
7216
7216
  version2.full = true;
7217
7217
  }
7218
7218
  if (input.delta) {
7219
- const modelFile = await this.#modelFile();
7220
- if (!modelFile) {
7219
+ const hangsFrom = (await this.#modelFile())?.id ?? input.file?.fileId ?? void 0;
7220
+ if (!hangsFrom) {
7221
7221
  throw new Error(
7222
7222
  "A delta needs the model file to hang from: sync a full model first."
7223
7223
  );
7224
7224
  }
7225
- const hidden = await this.client.createHiddenFile(
7226
- input.delta,
7227
- modelFile.id
7228
- );
7225
+ const hidden = await this.client.createHiddenFile(input.delta, hangsFrom);
7229
7226
  version2.deltaId = hiddenIdOf(hidden);
7230
7227
  }
7231
7228
  const fresh = await this.#readHistory();
@@ -7455,11 +7452,12 @@ function mintGuid() {
7455
7452
  }
7456
7453
  const DOCUMENT_TYPES = {
7457
7454
  bim: { label: "BIM model", icon: "tabler:building" },
7458
- drawings: { label: "Drawings", icon: "tabler:layout-board" },
7455
+ // «Drawing set» (Antonio 25-10; was «Drawings», and «plan set» in the Planner). The key stays 'drawings'.
7456
+ drawings: { label: "Drawing set", icon: "tabler:layout-board" },
7459
7457
  reality: { label: "Reality capture", icon: "tabler:3d-cube-sphere" },
7460
7458
  // 🔴 The project's coordination record (Antonio, 22-10: «los topics sean su propio documento… no pertenecen a
7461
7459
  // ningún modelo, pueden hablar de varios a la vez»): its topics, as a BCF, with a history of their own. Named as a thing,
7462
- // as a plan set is («Coordination set», Antonio 22-10).
7460
+ // as a drawing set is («Coordination set», Antonio 22-10).
7463
7461
  coordination: { label: "Coordination set", icon: "tabler:messages" },
7464
7462
  generic: { label: "Generic", icon: "tabler:file" }
7465
7463
  };
@@ -7574,13 +7572,20 @@ class ProjectDocuments {
7574
7572
  const item = await this.client.getFile(fileId);
7575
7573
  const fileName2 = String(item.name ?? "");
7576
7574
  const format2 = formatOf(fileName2, item.fileExtension);
7577
- const name = options?.name ?? fileName2.replace(/\.[^.]+$/, "") ?? fileName2;
7578
- const folder = await this.client.createFolder(
7579
- name,
7580
- item.folderId ? String(item.folderId) : void 0,
7581
- this.projectId
7575
+ const wanted = options?.name ?? fileName2.replace(/\.[^.]+$/, "") ?? fileName2;
7576
+ const taken = new Set(
7577
+ (await this.list().catch(() => [])).map((d) => String(d.descriptor.name ?? "").toLowerCase())
7582
7578
  );
7583
- const folderId = idOf$1(folder);
7579
+ const parentId = item.folderId ? String(item.folderId) : void 0;
7580
+ let name = wanted;
7581
+ let folderId = "";
7582
+ for (let n = 1; n < 100; n++) {
7583
+ name = n === 1 ? wanted : `${wanted} (${n})`;
7584
+ if (taken.has(name.toLowerCase())) continue;
7585
+ const folder = await this.client.createFolder(name, parentId, this.projectId);
7586
+ folderId = idOf$1(folder);
7587
+ if (!await this.#descriptorFile(folderId)) break;
7588
+ }
7584
7589
  await this.client.updateFile(fileId, { parentFolderId: folderId });
7585
7590
  const views = [];
7586
7591
  const derivedId = await this.#derivedFileId(item);
@@ -7793,11 +7798,33 @@ class ProjectDocuments {
7793
7798
  const base = String(item.name ?? "").replace(/\.[^.]+$/, "").toLowerCase();
7794
7799
  if (!base) return void 0;
7795
7800
  listed ??= await this.client.listFiles({ projectId: this.projectId }).catch(() => []);
7796
- const twin = listed.find((one) => {
7801
+ const folderOf = (one) => String(one.folderId ?? one.parentFolderId ?? "");
7802
+ const inDocuments = new Set(
7803
+ listed.filter((one) => String(one.name ?? "") === DOCUMENT_FILE).map(folderOf)
7804
+ );
7805
+ const twins = listed.filter((one) => {
7797
7806
  const name = String(one.name ?? "").toLowerCase();
7798
- return name === `${base}.frag` && !one.archived && idOf$1(one) !== idOf$1(item);
7807
+ return name === `${base}.frag` && !one.archived && idOf$1(one) !== idOf$1(item) && !inDocuments.has(folderOf(one));
7799
7808
  });
7800
- return twin ? idOf$1(twin) : void 0;
7809
+ for (const twin of twins) {
7810
+ const source = await this.#sourceIfcOf(twin);
7811
+ if (source === void 0 || source === idOf$1(item)) return idOf$1(twin);
7812
+ }
7813
+ return void 0;
7814
+ }
7815
+ /** The IFC a processed frag says it was made from (`sourceIfcId` in its latest version's metadata), if it says. */
7816
+ async #sourceIfcOf(file) {
7817
+ const versions = file.versions ?? [];
7818
+ const latest = [...versions].sort(
7819
+ (a, b) => String(b.createdAt ?? "").localeCompare(String(a.createdAt ?? ""))
7820
+ )[0];
7821
+ if (!latest) return void 0;
7822
+ try {
7823
+ const metadata2 = await this.client.getFileVersionMetadata(idOf$1(file), latest.tag);
7824
+ return typeof metadata2?.sourceIfcId === "string" && metadata2.sourceIfcId ? metadata2.sourceIfcId : void 0;
7825
+ } catch {
7826
+ return void 0;
7827
+ }
7801
7828
  }
7802
7829
  async #derivedFromVersions(item, known) {
7803
7830
  const versions = [...known].sort(
@@ -7958,7 +7985,11 @@ function normalize$1(parsed) {
7958
7985
  const native = raw.native;
7959
7986
  const hasNative = !!native && typeof native === "object" && typeof native.fileId === "string" && typeof native.format === "string";
7960
7987
  const type2 = typeof raw.type === "string" && raw.type in DOCUMENT_TYPES ? raw.type : void 0;
7988
+ const rest = { ...raw };
7989
+ delete rest.type;
7990
+ delete rest.native;
7961
7991
  return {
7992
+ ...rest,
7962
7993
  schema: DOCUMENT_SCHEMA,
7963
7994
  name: raw.name,
7964
7995
  ...type2 ? { type: type2 } : {},
@@ -7970,6 +8001,7 @@ const RESERVED = "flow:";
7970
8001
  const OP_KEY = "flow:op";
7971
8002
  const SOURCE_KEY = "flow:source";
7972
8003
  const HOST_KEY = "flow:host";
8004
+ const PRINT_KEY = "flow:print";
7973
8005
  const OP_SCHEMA = "revitflow/op@2";
7974
8006
  const CATEGORY_CHANGE = "REVITFLOWCHANGE";
7975
8007
  const CATEGORY_OPERATION = "REVITFLOWOPERATION";
@@ -8070,7 +8102,7 @@ class OperationBuilder {
8070
8102
  pack(attrs, placement) {
8071
8103
  const out = {};
8072
8104
  for (const [k, v] of Object.entries(attrs ?? {})) {
8073
- if (k.startsWith(RESERVED)) continue;
8105
+ if (k.startsWith(RESERVED) && k !== PRINT_KEY) continue;
8074
8106
  out[k] = String(v);
8075
8107
  }
8076
8108
  if (placement.position) out.Position = placement.position.map(num).join(",");
@@ -9132,6 +9164,16 @@ class EngineServicesClient {
9132
9164
  async listDocumentDescriptors(projectId) {
9133
9165
  return await this.#requestApi("GET", `${ITEM_PATH}/documents`, { query: { projectId } });
9134
9166
  }
9167
+ async exportProjectDocuments(projectId, options) {
9168
+ if (options?.format === "csv") {
9169
+ const blob = await this.#requestApi("GET", `${ITEM_PATH}/export`, {
9170
+ query: { projectId, format: "csv" },
9171
+ responseType: "blob"
9172
+ });
9173
+ return (await blob.text()).replace(/^/, "");
9174
+ }
9175
+ return await this.#requestApi("GET", `${ITEM_PATH}/export`, { query: { projectId } });
9176
+ }
9135
9177
  /**
9136
9178
  * Gets a single file by ID, optionally including version history.
9137
9179
  * @param fileId - The file's unique identifier.
@@ -10070,12 +10112,13 @@ return main;`);
10070
10112
  formData.append("file", file);
10071
10113
  formData.append("versionTag", versionTag);
10072
10114
  extraProps && formData.append("extraProps", JSON.stringify(extraProps));
10073
- metadata2 && formData.append("metadata", JSON.stringify(metadata2));
10074
- return await this.#requestApi(
10115
+ const version2 = await this.#requestApi(
10075
10116
  "POST",
10076
10117
  `${ITEM_PATH}/${itemId}/version`,
10077
10118
  { body: formData }
10078
10119
  );
10120
+ if (metadata2) await this.updateFileVersionMetadata(itemId, version2?.tag ?? versionTag, metadata2);
10121
+ return version2;
10079
10122
  }
10080
10123
  /**
10081
10124
  * Lists versions of an item. Pass `archived: true` to fetch only archived
@@ -10247,7 +10290,6 @@ return main;`);
10247
10290
  formData.append("file", file);
10248
10291
  versionTag && formData.append("versionTag", versionTag);
10249
10292
  extraProps && formData.append("extraProps", JSON.stringify(extraProps));
10250
- metadata2 && formData.append("metadata", JSON.stringify(metadata2));
10251
10293
  version2 = await this.#requestApi(
10252
10294
  "POST",
10253
10295
  `${ITEM_PATH}/${itemId}/version`,
@@ -10255,6 +10297,8 @@ return main;`);
10255
10297
  body: formData
10256
10298
  }
10257
10299
  );
10300
+ const tag = version2?.tag ?? versionTag;
10301
+ if (metadata2 && tag) await this.updateFileVersionMetadata(itemId, tag, metadata2);
10258
10302
  }
10259
10303
  if (name || parentFolderId) {
10260
10304
  const body = {
@@ -14179,7 +14223,7 @@ function discoverAddin() {
14179
14223
  if (!require$$3$1.existsSync(file)) {
14180
14224
  console.error("");
14181
14225
  console.error(" The That Open Revit add-in is not running.");
14182
- console.error(" Open Revit 2026 (with the add-in installed) and try again.");
14226
+ console.error(" Open Revit (2024-2027, with the add-in installed) and try again.");
14183
14227
  console.error(" If it is not installed yet, install it and restart Revit.");
14184
14228
  console.error("");
14185
14229
  process.exit(1);
@@ -14239,18 +14283,23 @@ function isRevitRunning() {
14239
14283
  }
14240
14284
  }
14241
14285
  function startRevit() {
14242
- const roots = ["C:\\Program Files\\Autodesk"];
14243
- for (const root of roots) {
14244
- if (!require$$3$1.existsSync(root)) continue;
14245
- for (const dir of require$$3$1.readdirSync(root)) {
14246
- if (!/^Revit \d{4}$/.test(dir)) continue;
14247
- const exe = require$$2.join(root, dir, "Revit.exe");
14248
- if (!require$$3$1.existsSync(exe)) continue;
14249
- require$$1.spawn(exe, [], { detached: true, stdio: "ignore" }).unref();
14250
- return;
14251
- }
14286
+ const root = "C:\\Program Files\\Autodesk";
14287
+ if (!require$$3$1.existsSync(root)) {
14288
+ console.log(" Could not find Revit.exe. Start Revit yourself and this will pick it up.");
14289
+ return;
14290
+ }
14291
+ const years = require$$3$1.readdirSync(root).map((dir) => /^Revit (\d{4})$/.exec(dir)?.[1]).filter((year2) => !!year2 && require$$3$1.existsSync(require$$2.join(root, `Revit ${year2}`, "Revit.exe"))).sort().reverse();
14292
+ const appData = process.env.APPDATA ?? "";
14293
+ const withAddin = years.find(
14294
+ (year2) => require$$3$1.existsSync(require$$2.join(appData, "Autodesk", "Revit", "Addins", year2, "revitflow.addin"))
14295
+ );
14296
+ const year = withAddin ?? years[0];
14297
+ if (!year) {
14298
+ console.log(" Could not find Revit.exe. Start Revit yourself and this will pick it up.");
14299
+ return;
14252
14300
  }
14253
- console.log(" Could not find Revit.exe. Start Revit yourself and this will pick it up.");
14301
+ require$$1.spawn(require$$2.join(root, `Revit ${year}`, "Revit.exe"), [], { detached: true, stdio: "ignore" }).unref();
14302
+ console.log(` Started Revit ${year}.`);
14254
14303
  }
14255
14304
  const REVIT_ADDIN_PACKAGE = "@thatopen-platform/flow-revit";
14256
14305
  const revitCommand = new Command2("revit").description(