@thatopen/services 0.34.4 → 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 +111 -13
- package/dist/cli.js.map +1 -1
- package/dist/core/app-cache.d.ts +32 -0
- package/dist/core/app-cache.test.d.ts +1 -0
- package/dist/core/client.d.ts +27 -1
- package/dist/index.cjs.js +5 -5
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +2367 -2259
- package/dist/index.es.js.map +1 -1
- package/dist/types/context.d.ts +6 -0
- package/package.json +4 -4
- package/src/cli/templates/app/package.json +4 -4
- package/src/cli/templates/cloud-component/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -8847,8 +8847,50 @@ 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";
|
|
8893
|
+
const LOADED_AT_THE_LATEST_MS = 12e3;
|
|
8852
8894
|
const PROCESS_PATH = "processor";
|
|
8853
8895
|
const NPM_REGISTRY_PATH = "npm-registry";
|
|
8854
8896
|
const HIDDEN_PATH = "hidden";
|
|
@@ -8908,6 +8950,13 @@ class EngineServicesClient {
|
|
|
8908
8950
|
* Populated automatically when using {@link fromPlatformContext}.
|
|
8909
8951
|
*/
|
|
8910
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();
|
|
8911
8960
|
/**
|
|
8912
8961
|
* Creates a client from the platform context injected into
|
|
8913
8962
|
* `window.__THATOPEN_CONTEXT__` by the That Open Platform.
|
|
@@ -9148,13 +9197,15 @@ class EngineServicesClient {
|
|
|
9148
9197
|
}
|
|
9149
9198
|
);
|
|
9150
9199
|
}
|
|
9151
|
-
|
|
9200
|
+
const files = await this.#requestApi("GET", `${ITEM_PATH}`, {
|
|
9152
9201
|
query: {
|
|
9153
9202
|
itemType: ITEM_TYPE_FILE,
|
|
9154
9203
|
archived,
|
|
9155
9204
|
...projectId && { projectId }
|
|
9156
9205
|
}
|
|
9157
9206
|
});
|
|
9207
|
+
if (projectId && !archived) this.cache.keepAnswer("files", projectId, files);
|
|
9208
|
+
return files;
|
|
9158
9209
|
}
|
|
9159
9210
|
/**
|
|
9160
9211
|
* Every document descriptor of a project in one request, read by the
|
|
@@ -9176,9 +9227,11 @@ class EngineServicesClient {
|
|
|
9176
9227
|
}
|
|
9177
9228
|
#descriptorsAsked = /* @__PURE__ */ new Map();
|
|
9178
9229
|
async #listDocumentDescriptors(projectId) {
|
|
9179
|
-
|
|
9230
|
+
const answer = await this.#requestApi("GET", `${ITEM_PATH}/documents`, {
|
|
9180
9231
|
query: { projectId }
|
|
9181
9232
|
});
|
|
9233
|
+
this.cache.keepAnswer("documents", projectId, answer);
|
|
9234
|
+
return answer;
|
|
9182
9235
|
}
|
|
9183
9236
|
async exportProjectDocuments(projectId, options) {
|
|
9184
9237
|
if (options?.format === "csv") {
|
|
@@ -9643,9 +9696,64 @@ return main;`);
|
|
|
9643
9696
|
this.setBuiltInGlobals(globals);
|
|
9644
9697
|
await this.initBuiltInComponents(components, ...builtIns);
|
|
9645
9698
|
components.init();
|
|
9646
|
-
this
|
|
9699
|
+
if (globalThis.__thatOpenShellSaysLoaded && !this.#shellRelease) {
|
|
9700
|
+
this.#shellRelease = this.holdAppLoaded();
|
|
9701
|
+
}
|
|
9702
|
+
this.#setupDone = true;
|
|
9703
|
+
this.#reportLoaded();
|
|
9704
|
+
if (!this.#loadedReported) {
|
|
9705
|
+
const since = typeof performance !== "undefined" ? performance.now() : Date.now() - this.#bornAt;
|
|
9706
|
+
setTimeout(() => {
|
|
9707
|
+
this.#loadedHolds = 0;
|
|
9708
|
+
this.#reportLoaded();
|
|
9709
|
+
}, Math.max(0, LOADED_AT_THE_LATEST_MS - since));
|
|
9710
|
+
}
|
|
9647
9711
|
return { components };
|
|
9648
9712
|
}
|
|
9713
|
+
/**
|
|
9714
|
+
* 🔴 ONE LOADING SCREEN (Jesús 4-11: opening an app showed three, one after
|
|
9715
|
+
* the other). The platform keeps its own until the app says it is loaded,
|
|
9716
|
+
* and `setup` said so as soon as the components were made: the app's own
|
|
9717
|
+
* screens (its configuration, its viewer) then showed behind. Whatever is
|
|
9718
|
+
* still getting the app ready holds the word back with this, and lets it go
|
|
9719
|
+
* once it is: the platform's screen, the only one, stays until then.
|
|
9720
|
+
*
|
|
9721
|
+
* Returns the release; each is let go once. Held or not, the word goes 12 s
|
|
9722
|
+
* after this client was made at the latest, before the platform's own
|
|
9723
|
+
* deadline (15 s) calls the app dead.
|
|
9724
|
+
*/
|
|
9725
|
+
holdAppLoaded(maxMs = LOADED_AT_THE_LATEST_MS) {
|
|
9726
|
+
if (this.#loadedReported) return () => {
|
|
9727
|
+
};
|
|
9728
|
+
this.#loadedHolds++;
|
|
9729
|
+
let released = false;
|
|
9730
|
+
const release = () => {
|
|
9731
|
+
if (released) return;
|
|
9732
|
+
released = true;
|
|
9733
|
+
clearTimeout(timer);
|
|
9734
|
+
this.#loadedHolds--;
|
|
9735
|
+
this.#reportLoaded();
|
|
9736
|
+
};
|
|
9737
|
+
const timer = setTimeout(release, maxMs);
|
|
9738
|
+
return release;
|
|
9739
|
+
}
|
|
9740
|
+
/**
|
|
9741
|
+
* The app's shell saying it is ready to be looked at: the hold `setup` took
|
|
9742
|
+
* for it, let go. Nothing if it took none.
|
|
9743
|
+
*/
|
|
9744
|
+
appReady() {
|
|
9745
|
+
this.#shellRelease?.();
|
|
9746
|
+
}
|
|
9747
|
+
#shellRelease;
|
|
9748
|
+
#bornAt = Date.now();
|
|
9749
|
+
#setupDone = false;
|
|
9750
|
+
#loadedHolds = 0;
|
|
9751
|
+
#loadedReported = false;
|
|
9752
|
+
#reportLoaded() {
|
|
9753
|
+
if (this.#loadedReported || !this.#setupDone || this.#loadedHolds > 0) return;
|
|
9754
|
+
this.#loadedReported = true;
|
|
9755
|
+
this.context.appEventOrchestrator?.appLoaded?.();
|
|
9756
|
+
}
|
|
9649
9757
|
/**
|
|
9650
9758
|
* Reports an error to the platform via the {@link AppEventOrchestrator.appError} callback.
|
|
9651
9759
|
* @param code - Numeric error code.
|
|
@@ -10479,16 +10587,6 @@ const createCommand = new Command2("create").argument("<project-name>", 'Name of
|
|
|
10479
10587
|
console.error(`Unknown template "${opts.template}". Available: ${TEMPLATES.join(", ")}`);
|
|
10480
10588
|
process.exit(1);
|
|
10481
10589
|
}
|
|
10482
|
-
if (!opts.beta) {
|
|
10483
|
-
console.error(
|
|
10484
|
-
`Non-beta projects are not available yet.
|
|
10485
|
-
|
|
10486
|
-
thatopen create ${projectName} --beta
|
|
10487
|
-
|
|
10488
|
-
The templates currently require the beta engine libraries. Public (non-beta) engine support is coming with the October release.`
|
|
10489
|
-
);
|
|
10490
|
-
process.exit(1);
|
|
10491
|
-
}
|
|
10492
10590
|
const isCloud = template === "cloud-component";
|
|
10493
10591
|
const projectKind = isCloud ? "cloud component" : "app";
|
|
10494
10592
|
const useCurrentDir = projectName === ".";
|