@thatopen/services 0.33.0 → 0.34.3

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();
@@ -7286,10 +7283,8 @@ class FlowDoc {
7286
7283
  this.#filesAt = Date.now();
7287
7284
  this.#filesListed = (async () => {
7288
7285
  const folderId = await this.#folder(false);
7289
- const items2 = (await this.client.listFiles({ projectId: this.project.projectId })).filter((item) => {
7290
- const where = item;
7291
- return String(where.folderId ?? where.parentFolderId ?? "") === folderId;
7292
- });
7286
+ if (!folderId) return [];
7287
+ const items2 = await this.client.listFiles({ folderId, versions: true });
7293
7288
  return items2.map((item) => ({
7294
7289
  id: idOf$2(item),
7295
7290
  name: String(item.name ?? ""),
@@ -7455,11 +7450,12 @@ function mintGuid() {
7455
7450
  }
7456
7451
  const DOCUMENT_TYPES = {
7457
7452
  bim: { label: "BIM model", icon: "tabler:building" },
7458
- drawings: { label: "Drawings", icon: "tabler:layout-board" },
7453
+ // «Drawing set» (Antonio 25-10; was «Drawings», and «plan set» in the Planner). The key stays 'drawings'.
7454
+ drawings: { label: "Drawing set", icon: "tabler:layout-board" },
7459
7455
  reality: { label: "Reality capture", icon: "tabler:3d-cube-sphere" },
7460
7456
  // 🔴 The project's coordination record (Antonio, 22-10: «los topics sean su propio documento… no pertenecen a
7461
7457
  // 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).
7458
+ // as a drawing set is («Coordination set», Antonio 22-10).
7463
7459
  coordination: { label: "Coordination set", icon: "tabler:messages" },
7464
7460
  generic: { label: "Generic", icon: "tabler:file" }
7465
7461
  };
@@ -7574,13 +7570,20 @@ class ProjectDocuments {
7574
7570
  const item = await this.client.getFile(fileId);
7575
7571
  const fileName2 = String(item.name ?? "");
7576
7572
  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
7573
+ const wanted = options?.name ?? fileName2.replace(/\.[^.]+$/, "") ?? fileName2;
7574
+ const taken = new Set(
7575
+ (await this.list().catch(() => [])).map((d) => String(d.descriptor.name ?? "").toLowerCase())
7582
7576
  );
7583
- const folderId = idOf$1(folder);
7577
+ const parentId = item.folderId ? String(item.folderId) : void 0;
7578
+ let name = wanted;
7579
+ let folderId = "";
7580
+ for (let n = 1; n < 100; n++) {
7581
+ name = n === 1 ? wanted : `${wanted} (${n})`;
7582
+ if (taken.has(name.toLowerCase())) continue;
7583
+ const folder = await this.client.createFolder(name, parentId, this.projectId);
7584
+ folderId = idOf$1(folder);
7585
+ if (!await this.#descriptorFile(folderId)) break;
7586
+ }
7584
7587
  await this.client.updateFile(fileId, { parentFolderId: folderId });
7585
7588
  const views = [];
7586
7589
  const derivedId = await this.#derivedFileId(item);
@@ -7793,11 +7796,33 @@ class ProjectDocuments {
7793
7796
  const base = String(item.name ?? "").replace(/\.[^.]+$/, "").toLowerCase();
7794
7797
  if (!base) return void 0;
7795
7798
  listed ??= await this.client.listFiles({ projectId: this.projectId }).catch(() => []);
7796
- const twin = listed.find((one) => {
7799
+ const folderOf = (one) => String(one.folderId ?? one.parentFolderId ?? "");
7800
+ const inDocuments = new Set(
7801
+ listed.filter((one) => String(one.name ?? "") === DOCUMENT_FILE).map(folderOf)
7802
+ );
7803
+ const twins = listed.filter((one) => {
7797
7804
  const name = String(one.name ?? "").toLowerCase();
7798
- return name === `${base}.frag` && !one.archived && idOf$1(one) !== idOf$1(item);
7805
+ return name === `${base}.frag` && !one.archived && idOf$1(one) !== idOf$1(item) && !inDocuments.has(folderOf(one));
7799
7806
  });
7800
- return twin ? idOf$1(twin) : void 0;
7807
+ for (const twin of twins) {
7808
+ const source = await this.#sourceIfcOf(twin);
7809
+ if (source === void 0 || source === idOf$1(item)) return idOf$1(twin);
7810
+ }
7811
+ return void 0;
7812
+ }
7813
+ /** The IFC a processed frag says it was made from (`sourceIfcId` in its latest version's metadata), if it says. */
7814
+ async #sourceIfcOf(file) {
7815
+ const versions = file.versions ?? [];
7816
+ const latest = [...versions].sort(
7817
+ (a, b) => String(b.createdAt ?? "").localeCompare(String(a.createdAt ?? ""))
7818
+ )[0];
7819
+ if (!latest) return void 0;
7820
+ try {
7821
+ const metadata2 = await this.client.getFileVersionMetadata(idOf$1(file), latest.tag);
7822
+ return typeof metadata2?.sourceIfcId === "string" && metadata2.sourceIfcId ? metadata2.sourceIfcId : void 0;
7823
+ } catch {
7824
+ return void 0;
7825
+ }
7801
7826
  }
7802
7827
  async #derivedFromVersions(item, known) {
7803
7828
  const versions = [...known].sort(
@@ -7817,10 +7842,8 @@ class ProjectDocuments {
7817
7842
  return void 0;
7818
7843
  }
7819
7844
  async #descriptorFile(folderId) {
7820
- const items2 = (await this.client.listFiles({ projectId: this.projectId })).filter((item) => {
7821
- const where = item;
7822
- return String(where.folderId ?? where.parentFolderId ?? "") === folderId;
7823
- });
7845
+ if (!folderId) return void 0;
7846
+ const items2 = await this.client.listFiles({ folderId, versions: true });
7824
7847
  const found = items2.find(
7825
7848
  (item) => String(item.name ?? "") === DOCUMENT_FILE
7826
7849
  );
@@ -7958,7 +7981,11 @@ function normalize$1(parsed) {
7958
7981
  const native = raw.native;
7959
7982
  const hasNative = !!native && typeof native === "object" && typeof native.fileId === "string" && typeof native.format === "string";
7960
7983
  const type2 = typeof raw.type === "string" && raw.type in DOCUMENT_TYPES ? raw.type : void 0;
7984
+ const rest = { ...raw };
7985
+ delete rest.type;
7986
+ delete rest.native;
7961
7987
  return {
7988
+ ...rest,
7962
7989
  schema: DOCUMENT_SCHEMA,
7963
7990
  name: raw.name,
7964
7991
  ...type2 ? { type: type2 } : {},
@@ -7970,6 +7997,7 @@ const RESERVED = "flow:";
7970
7997
  const OP_KEY = "flow:op";
7971
7998
  const SOURCE_KEY = "flow:source";
7972
7999
  const HOST_KEY = "flow:host";
8000
+ const PRINT_KEY = "flow:print";
7973
8001
  const OP_SCHEMA = "revitflow/op@2";
7974
8002
  const CATEGORY_CHANGE = "REVITFLOWCHANGE";
7975
8003
  const CATEGORY_OPERATION = "REVITFLOWOPERATION";
@@ -8070,7 +8098,7 @@ class OperationBuilder {
8070
8098
  pack(attrs, placement) {
8071
8099
  const out = {};
8072
8100
  for (const [k, v] of Object.entries(attrs ?? {})) {
8073
- if (k.startsWith(RESERVED)) continue;
8101
+ if (k.startsWith(RESERVED) && k !== PRINT_KEY) continue;
8074
8102
  out[k] = String(v);
8075
8103
  }
8076
8104
  if (placement.position) out.Position = placement.position.map(num).join(",");
@@ -9106,12 +9134,18 @@ class EngineServicesClient {
9106
9134
  * @returns Array of file items.
9107
9135
  */
9108
9136
  async listFiles(filters) {
9109
- const { folderId, archived, projectId } = filters || {};
9137
+ const { folderId, archived, projectId, versions } = filters || {};
9110
9138
  if (folderId) {
9111
9139
  return await this.#requestApi(
9112
9140
  "GET",
9113
9141
  `${FOLDER_PATH}/${folderId}/items`,
9114
- { query: { itemType: ITEM_TYPE_FILE, archived } }
9142
+ {
9143
+ query: {
9144
+ itemType: ITEM_TYPE_FILE,
9145
+ archived,
9146
+ ...versions && { showVersions: true }
9147
+ }
9148
+ }
9115
9149
  );
9116
9150
  }
9117
9151
  return await this.#requestApi("GET", `${ITEM_PATH}`, {
@@ -9132,6 +9166,16 @@ class EngineServicesClient {
9132
9166
  async listDocumentDescriptors(projectId) {
9133
9167
  return await this.#requestApi("GET", `${ITEM_PATH}/documents`, { query: { projectId } });
9134
9168
  }
9169
+ async exportProjectDocuments(projectId, options) {
9170
+ if (options?.format === "csv") {
9171
+ const blob = await this.#requestApi("GET", `${ITEM_PATH}/export`, {
9172
+ query: { projectId, format: "csv" },
9173
+ responseType: "blob"
9174
+ });
9175
+ return (await blob.text()).replace(/^/, "");
9176
+ }
9177
+ return await this.#requestApi("GET", `${ITEM_PATH}/export`, { query: { projectId } });
9178
+ }
9135
9179
  /**
9136
9180
  * Gets a single file by ID, optionally including version history.
9137
9181
  * @param fileId - The file's unique identifier.
@@ -10070,12 +10114,13 @@ return main;`);
10070
10114
  formData.append("file", file);
10071
10115
  formData.append("versionTag", versionTag);
10072
10116
  extraProps && formData.append("extraProps", JSON.stringify(extraProps));
10073
- metadata2 && formData.append("metadata", JSON.stringify(metadata2));
10074
- return await this.#requestApi(
10117
+ const version2 = await this.#requestApi(
10075
10118
  "POST",
10076
10119
  `${ITEM_PATH}/${itemId}/version`,
10077
10120
  { body: formData }
10078
10121
  );
10122
+ if (metadata2) await this.updateFileVersionMetadata(itemId, version2?.tag ?? versionTag, metadata2);
10123
+ return version2;
10079
10124
  }
10080
10125
  /**
10081
10126
  * Lists versions of an item. Pass `archived: true` to fetch only archived
@@ -10247,7 +10292,6 @@ return main;`);
10247
10292
  formData.append("file", file);
10248
10293
  versionTag && formData.append("versionTag", versionTag);
10249
10294
  extraProps && formData.append("extraProps", JSON.stringify(extraProps));
10250
- metadata2 && formData.append("metadata", JSON.stringify(metadata2));
10251
10295
  version2 = await this.#requestApi(
10252
10296
  "POST",
10253
10297
  `${ITEM_PATH}/${itemId}/version`,
@@ -10255,6 +10299,8 @@ return main;`);
10255
10299
  body: formData
10256
10300
  }
10257
10301
  );
10302
+ const tag = version2?.tag ?? versionTag;
10303
+ if (metadata2 && tag) await this.updateFileVersionMetadata(itemId, tag, metadata2);
10258
10304
  }
10259
10305
  if (name || parentFolderId) {
10260
10306
  const body = {
@@ -14179,7 +14225,7 @@ function discoverAddin() {
14179
14225
  if (!require$$3$1.existsSync(file)) {
14180
14226
  console.error("");
14181
14227
  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.");
14228
+ console.error(" Open Revit (2024-2027, with the add-in installed) and try again.");
14183
14229
  console.error(" If it is not installed yet, install it and restart Revit.");
14184
14230
  console.error("");
14185
14231
  process.exit(1);
@@ -14239,18 +14285,23 @@ function isRevitRunning() {
14239
14285
  }
14240
14286
  }
14241
14287
  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
- }
14288
+ const root = "C:\\Program Files\\Autodesk";
14289
+ if (!require$$3$1.existsSync(root)) {
14290
+ console.log(" Could not find Revit.exe. Start Revit yourself and this will pick it up.");
14291
+ return;
14292
+ }
14293
+ 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();
14294
+ const appData = process.env.APPDATA ?? "";
14295
+ const withAddin = years.find(
14296
+ (year2) => require$$3$1.existsSync(require$$2.join(appData, "Autodesk", "Revit", "Addins", year2, "revitflow.addin"))
14297
+ );
14298
+ const year = withAddin ?? years[0];
14299
+ if (!year) {
14300
+ console.log(" Could not find Revit.exe. Start Revit yourself and this will pick it up.");
14301
+ return;
14252
14302
  }
14253
- console.log(" Could not find Revit.exe. Start Revit yourself and this will pick it up.");
14303
+ require$$1.spawn(require$$2.join(root, `Revit ${year}`, "Revit.exe"), [], { detached: true, stdio: "ignore" }).unref();
14304
+ console.log(` Started Revit ${year}.`);
14254
14305
  }
14255
14306
  const REVIT_ADDIN_PACKAGE = "@thatopen-platform/flow-revit";
14256
14307
  const revitCommand = new Command2("revit").description(