@thatopen/services 0.32.0 → 0.33.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/cli.js +65 -3
- package/dist/cli.js.map +1 -1
- package/dist/core/client.d.ts +16 -0
- package/dist/core/documents.d.ts +5 -0
- package/dist/index.cjs.js +5 -5
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +948 -907
- package/dist/index.es.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -6810,6 +6810,7 @@ const HISTORY_FILE = "revitflow_history.json";
|
|
|
6810
6810
|
const LEGACY_MODEL_FILE = "revitflow_model.frag";
|
|
6811
6811
|
const INTERNAL_PREFIX = "revitflow_";
|
|
6812
6812
|
const LOCKS_ANCHOR = "bimterop-locks-anchor";
|
|
6813
|
+
const jsonReads = /* @__PURE__ */ new Map();
|
|
6813
6814
|
function childrenOf(folders, parentId) {
|
|
6814
6815
|
return folders.filter((f) => String(f.parentId ?? "") === parentId);
|
|
6815
6816
|
}
|
|
@@ -7291,7 +7292,8 @@ class FlowDoc {
|
|
|
7291
7292
|
});
|
|
7292
7293
|
return items2.map((item) => ({
|
|
7293
7294
|
id: idOf$2(item),
|
|
7294
|
-
name: String(item.name ?? "")
|
|
7295
|
+
name: String(item.name ?? ""),
|
|
7296
|
+
stamp: stampOf(item)
|
|
7295
7297
|
}));
|
|
7296
7298
|
})();
|
|
7297
7299
|
this.#filesListed.catch(() => {
|
|
@@ -7320,6 +7322,18 @@ class FlowDoc {
|
|
|
7320
7322
|
async #readJson(name) {
|
|
7321
7323
|
const file = await this.#file(name);
|
|
7322
7324
|
if (!file) return void 0;
|
|
7325
|
+
const kept = file.stamp ? jsonReads.get(file.id) : void 0;
|
|
7326
|
+
if (kept && kept.stamp === file.stamp) return structuredClone(await kept.value);
|
|
7327
|
+
const value2 = this.#downloadJson(file, name);
|
|
7328
|
+
if (file.stamp) {
|
|
7329
|
+
jsonReads.set(file.id, { stamp: file.stamp, value: value2 });
|
|
7330
|
+
value2.catch(() => {
|
|
7331
|
+
if (jsonReads.get(file.id)?.value === value2) jsonReads.delete(file.id);
|
|
7332
|
+
});
|
|
7333
|
+
}
|
|
7334
|
+
return structuredClone(await value2);
|
|
7335
|
+
}
|
|
7336
|
+
async #downloadJson(file, name) {
|
|
7323
7337
|
const response = await this.client.downloadFile(file.id);
|
|
7324
7338
|
if (!response.ok) throw new Error(`Reading ${name} answered ${response.status}`);
|
|
7325
7339
|
const text2 = await response.text();
|
|
@@ -7335,6 +7349,7 @@ class FlowDoc {
|
|
|
7335
7349
|
});
|
|
7336
7350
|
const existing = await this.#file(name);
|
|
7337
7351
|
if (existing) {
|
|
7352
|
+
jsonReads.delete(existing.id);
|
|
7338
7353
|
await this.client.updateFile(existing.id, {
|
|
7339
7354
|
file: blob,
|
|
7340
7355
|
versionTag: await this.client.nextVersionTag(existing.id)
|
|
@@ -7499,6 +7514,7 @@ function idOf$1(item) {
|
|
|
7499
7514
|
return String(item._id ?? item.id ?? "");
|
|
7500
7515
|
}
|
|
7501
7516
|
const descriptorReads = /* @__PURE__ */ new Map();
|
|
7517
|
+
let descriptorsRouteMissing = false;
|
|
7502
7518
|
const stampOf = (item) => {
|
|
7503
7519
|
const it = item;
|
|
7504
7520
|
const newest = [...it.versions ?? []].sort((a, b) => String(b.createdAt ?? "").localeCompare(String(a.createdAt ?? "")))[0];
|
|
@@ -7525,6 +7541,8 @@ class ProjectDocuments {
|
|
|
7525
7541
|
return all.filter((d) => types2.includes(documentTypeOf(d.descriptor)));
|
|
7526
7542
|
}
|
|
7527
7543
|
async #listAll() {
|
|
7544
|
+
const all = await this.#listAllAtOnce();
|
|
7545
|
+
if (all) return all;
|
|
7528
7546
|
const files = await this.client.listFiles({ projectId: this.projectId });
|
|
7529
7547
|
const descriptors = files.filter(
|
|
7530
7548
|
(item) => String(item.name ?? "") === DOCUMENT_FILE
|
|
@@ -7616,6 +7634,37 @@ class ProjectDocuments {
|
|
|
7616
7634
|
if (!file) return null;
|
|
7617
7635
|
return this.#readDescriptor(file.id, file.stamp);
|
|
7618
7636
|
}
|
|
7637
|
+
/**
|
|
7638
|
+
* Every descriptor from the platform in one request, or null when the
|
|
7639
|
+
* platform has no such route (one from before it: 404, or 400 taking
|
|
7640
|
+
* `documents` for an item id) and they are read one by one. Asked once per
|
|
7641
|
+
* page: a platform without it is not asked again. A 429 or a 5xx is an
|
|
7642
|
+
* error, never "no documents" (23-10).
|
|
7643
|
+
*/
|
|
7644
|
+
async #listAllAtOnce() {
|
|
7645
|
+
if (descriptorsRouteMissing) return null;
|
|
7646
|
+
let answer;
|
|
7647
|
+
try {
|
|
7648
|
+
answer = await this.client.listDocumentDescriptors(this.projectId);
|
|
7649
|
+
} catch (error2) {
|
|
7650
|
+
const status = error2.status;
|
|
7651
|
+
if (status === 404 || status === 400 || status === 405) {
|
|
7652
|
+
descriptorsRouteMissing = true;
|
|
7653
|
+
return null;
|
|
7654
|
+
}
|
|
7655
|
+
throw error2;
|
|
7656
|
+
}
|
|
7657
|
+
const found = [];
|
|
7658
|
+
for (const one of answer?.documents ?? []) {
|
|
7659
|
+
const descriptor = normalize$1(one.descriptor);
|
|
7660
|
+
if (!descriptor || !one.folderId) continue;
|
|
7661
|
+
if (one.fileId && one.versionTag) {
|
|
7662
|
+
descriptorReads.set(one.fileId, { stamp: one.versionTag, value: Promise.resolve(descriptor) });
|
|
7663
|
+
}
|
|
7664
|
+
found.push({ folderId: String(one.folderId), descriptor });
|
|
7665
|
+
}
|
|
7666
|
+
return found;
|
|
7667
|
+
}
|
|
7619
7668
|
/**
|
|
7620
7669
|
* 🔴 EACH DESCRIPTOR READ ONCE A VERSION (Antonio 23-10: the calls «siempre lo mínimo posible»): kept by its file and
|
|
7621
7670
|
* the moment its listing says it last changed, for every list and panel of the page (the Coordinator's start read
|
|
@@ -8781,6 +8830,9 @@ const ITEM_TYPE_APP = "APP";
|
|
|
8781
8830
|
const RETRY_BASE_DELAY_MS = 500;
|
|
8782
8831
|
const RETRY_MAX_DELAY_MS = 3e4;
|
|
8783
8832
|
const READ_SHARED_MS = 2e3;
|
|
8833
|
+
const LISTING_SHARED_MS = 15e3;
|
|
8834
|
+
const isAsking = (path2) => /^\/?project\/permissions\/check/.test(path2);
|
|
8835
|
+
const isListing = (path2) => /^\/?(item\/folder\/?$|item\/?$|item\/folder\/[^/]+\/items\/?$|project\/[^/]+\/data\/?$)/.test(path2);
|
|
8784
8836
|
const sharedReads = /* @__PURE__ */ new Map();
|
|
8785
8837
|
const RETRY_JITTER_RATIO = 0.25;
|
|
8786
8838
|
const sleep = (ms) => new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
@@ -8951,7 +9003,7 @@ class EngineServicesClient {
|
|
|
8951
9003
|
const key = `${this.#buildUrl(path2)}?${new URLSearchParams(this.#cleanData(requestData?.query)).toString()}`;
|
|
8952
9004
|
const now = Date.now();
|
|
8953
9005
|
const kept = sharedReads.get(key);
|
|
8954
|
-
if (kept && (kept.pending || now - kept.at < READ_SHARED_MS)) {
|
|
9006
|
+
if (kept && (kept.pending || now - kept.at < (isListing(path2) ? LISTING_SHARED_MS : READ_SHARED_MS))) {
|
|
8955
9007
|
return kept.answer.then((data) => data === void 0 ? data : structuredClone(data));
|
|
8956
9008
|
}
|
|
8957
9009
|
const entry = { at: now, pending: true, answer: this.#requestApiOnce(method, path2, requestData) };
|
|
@@ -8967,7 +9019,7 @@ class EngineServicesClient {
|
|
|
8967
9019
|
);
|
|
8968
9020
|
return entry.answer.then((data) => data === void 0 ? data : structuredClone(data));
|
|
8969
9021
|
}
|
|
8970
|
-
if (method !== "GET") sharedReads.clear();
|
|
9022
|
+
if (method !== "GET" && !isAsking(path2)) sharedReads.clear();
|
|
8971
9023
|
return this.#requestApiOnce(method, path2, requestData);
|
|
8972
9024
|
}
|
|
8973
9025
|
async #requestApiOnce(method, path2, requestData) {
|
|
@@ -9070,6 +9122,16 @@ class EngineServicesClient {
|
|
|
9070
9122
|
}
|
|
9071
9123
|
});
|
|
9072
9124
|
}
|
|
9125
|
+
/**
|
|
9126
|
+
* Every document descriptor of a project in one request, read by the
|
|
9127
|
+
* platform (`GET /item/documents`). Throws a {@link RequestError} like any
|
|
9128
|
+
* request; a platform from before the route answers 404 (or 400, taking
|
|
9129
|
+
* `documents` for an item id), which `documents.list()` reads as "ask one
|
|
9130
|
+
* by one".
|
|
9131
|
+
*/
|
|
9132
|
+
async listDocumentDescriptors(projectId) {
|
|
9133
|
+
return await this.#requestApi("GET", `${ITEM_PATH}/documents`, { query: { projectId } });
|
|
9134
|
+
}
|
|
9073
9135
|
/**
|
|
9074
9136
|
* Gets a single file by ID, optionally including version history.
|
|
9075
9137
|
* @param fileId - The file's unique identifier.
|