@thatopen/services 0.34.5 → 0.35.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 CHANGED
@@ -8847,6 +8847,47 @@ class RequestError extends Error {
8847
8847
  this.retryAfter = retryAfter ?? retryAfterFromDetails(parsed.details);
8848
8848
  }
8849
8849
  }
8850
+ const platform = () => {
8851
+ if (typeof window === "undefined") return null;
8852
+ const context = window.__THATOPEN_CONTEXT__;
8853
+ return context && typeof context.cacheSet === "function" ? context : null;
8854
+ };
8855
+ class AppCache {
8856
+ #memory = /* @__PURE__ */ new Map();
8857
+ /** What was kept under `key`, or undefined. */
8858
+ get(key) {
8859
+ const page = platform();
8860
+ if (page) return page.cache?.[key];
8861
+ return this.#memory.get(key);
8862
+ }
8863
+ /** Kept for the next time this app opens in this project (structured-cloneable values, bytes too). */
8864
+ set(key, value2) {
8865
+ const page = platform();
8866
+ if (page) page.cacheSet(key, value2);
8867
+ else this.#memory.set(key, value2);
8868
+ }
8869
+ delete(key) {
8870
+ const page = platform();
8871
+ if (page) page.cacheDelete?.(key);
8872
+ else this.#memory.delete(key);
8873
+ }
8874
+ /** One of the project's listings as it was last answered, if it is this project's. */
8875
+ answer(key, projectId) {
8876
+ const kept = this.get(key);
8877
+ return kept && kept.projectId === projectId ? kept : void 0;
8878
+ }
8879
+ /** @internal The client keeping a fresh listing. */
8880
+ keepAnswer(key, projectId, value2) {
8881
+ try {
8882
+ this.set(key, {
8883
+ projectId,
8884
+ value: value2,
8885
+ at: Date.now()
8886
+ });
8887
+ } catch {
8888
+ }
8889
+ }
8890
+ }
8850
8891
  const FOLDER_PATH = "item/folder";
8851
8892
  const ITEM_PATH = "item";
8852
8893
  const LOADED_AT_THE_LATEST_MS = 12e3;
@@ -8909,6 +8950,13 @@ class EngineServicesClient {
8909
8950
  * Populated automatically when using {@link fromPlatformContext}.
8910
8951
  */
8911
8952
  context;
8953
+ /**
8954
+ * What this app saw last time, to open on at once and correct afterwards
8955
+ * ({@link AppCache}): kept by the platform page, or in memory outside it. The
8956
+ * project's listings (`documents`, `files`, `projectData`) are kept here
8957
+ * whenever a fresh answer arrives; an app keeps its own under `app:` keys.
8958
+ */
8959
+ cache = new AppCache();
8912
8960
  /**
8913
8961
  * Creates a client from the platform context injected into
8914
8962
  * `window.__THATOPEN_CONTEXT__` by the That Open Platform.
@@ -9149,13 +9197,15 @@ class EngineServicesClient {
9149
9197
  }
9150
9198
  );
9151
9199
  }
9152
- return await this.#requestApi("GET", `${ITEM_PATH}`, {
9200
+ const files = await this.#requestApi("GET", `${ITEM_PATH}`, {
9153
9201
  query: {
9154
9202
  itemType: ITEM_TYPE_FILE,
9155
9203
  archived,
9156
9204
  ...projectId && { projectId }
9157
9205
  }
9158
9206
  });
9207
+ if (projectId && !archived) this.cache.keepAnswer("files", projectId, files);
9208
+ return files;
9159
9209
  }
9160
9210
  /**
9161
9211
  * Every document descriptor of a project in one request, read by the
@@ -9177,9 +9227,11 @@ class EngineServicesClient {
9177
9227
  }
9178
9228
  #descriptorsAsked = /* @__PURE__ */ new Map();
9179
9229
  async #listDocumentDescriptors(projectId) {
9180
- return await this.#requestApi("GET", `${ITEM_PATH}/documents`, {
9230
+ const answer = await this.#requestApi("GET", `${ITEM_PATH}/documents`, {
9181
9231
  query: { projectId }
9182
9232
  });
9233
+ this.cache.keepAnswer("documents", projectId, answer);
9234
+ return answer;
9183
9235
  }
9184
9236
  async exportProjectDocuments(projectId, options) {
9185
9237
  if (options?.format === "csv") {
@@ -10535,16 +10587,6 @@ const createCommand = new Command2("create").argument("<project-name>", 'Name of
10535
10587
  console.error(`Unknown template "${opts.template}". Available: ${TEMPLATES.join(", ")}`);
10536
10588
  process.exit(1);
10537
10589
  }
10538
- if (!opts.beta) {
10539
- console.error(
10540
- `Non-beta projects are not available yet.
10541
-
10542
- thatopen create ${projectName} --beta
10543
-
10544
- The templates currently require the beta engine libraries. Public (non-beta) engine support is coming with the October release.`
10545
- );
10546
- process.exit(1);
10547
- }
10548
10590
  const isCloud = template === "cloud-component";
10549
10591
  const projectKind = isCloud ? "cloud component" : "app";
10550
10592
  const useCurrentDir = projectName === ".";