@kosdev-code/kos-ui-sdk 0.1.0-next.849 → 0.1.0-next.851
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/core/core/dependency-manager.d.ts +6 -0
- package/core/core/dependency-manager.d.ts.map +1 -1
- package/core/core/kosModelManager.d.ts.map +1 -1
- package/core/core/model/model-hook-cache.d.ts +30 -0
- package/core/core/model/model-hook-cache.d.ts.map +1 -0
- package/core/core/transport/mock/mock-registry.d.ts.map +1 -1
- package/core/index.d.ts +1 -0
- package/core/index.d.ts.map +1 -1
- package/index.cjs +97 -33
- package/index.cjs.map +1 -1
- package/index.js +97 -33
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/ui/hooks/use-kos-model.d.ts.map +1 -1
package/index.js
CHANGED
|
@@ -4190,6 +4190,33 @@ class KosDependencyManager {
|
|
|
4190
4190
|
uses.filter((id) => id !== dependencyId)
|
|
4191
4191
|
);
|
|
4192
4192
|
}
|
|
4193
|
+
/**
|
|
4194
|
+
* Drops every edge into and out of a model. Called when the model is
|
|
4195
|
+
* destroyed, so its dependencies are not left pinned by a model that is
|
|
4196
|
+
* gone and can never release them.
|
|
4197
|
+
*/
|
|
4198
|
+
removeAll(modelId) {
|
|
4199
|
+
for (const dependencyId of this._usesCache.get(modelId) ?? []) {
|
|
4200
|
+
const usedBy = this._usedByCache.get(dependencyId);
|
|
4201
|
+
if (usedBy) {
|
|
4202
|
+
this._usedByCache.set(
|
|
4203
|
+
dependencyId,
|
|
4204
|
+
usedBy.filter((id) => id !== modelId)
|
|
4205
|
+
);
|
|
4206
|
+
}
|
|
4207
|
+
}
|
|
4208
|
+
this._usesCache.delete(modelId);
|
|
4209
|
+
for (const dependentId of this._usedByCache.get(modelId) ?? []) {
|
|
4210
|
+
const uses = this._usesCache.get(dependentId);
|
|
4211
|
+
if (uses) {
|
|
4212
|
+
this._usesCache.set(
|
|
4213
|
+
dependentId,
|
|
4214
|
+
uses.filter((id) => id !== modelId)
|
|
4215
|
+
);
|
|
4216
|
+
}
|
|
4217
|
+
}
|
|
4218
|
+
this._usedByCache.delete(modelId);
|
|
4219
|
+
}
|
|
4193
4220
|
canDestroy(modelId) {
|
|
4194
4221
|
const usedBy = this._usedByCache.get(modelId);
|
|
4195
4222
|
if (usedBy?.length) {
|
|
@@ -4267,6 +4294,19 @@ class KosModelCache {
|
|
|
4267
4294
|
return this._preloaded;
|
|
4268
4295
|
}
|
|
4269
4296
|
}
|
|
4297
|
+
const cache$1 = /* @__PURE__ */ new Map();
|
|
4298
|
+
const modelHookCache = {
|
|
4299
|
+
has: (key) => cache$1.has(key),
|
|
4300
|
+
get: (key) => cache$1.get(key),
|
|
4301
|
+
set: (key, entry) => cache$1.set(key, entry),
|
|
4302
|
+
delete: (key) => cache$1.delete(key),
|
|
4303
|
+
clear: () => cache$1.clear()
|
|
4304
|
+
};
|
|
4305
|
+
const clearModelHookCacheEntry = (modelId) => {
|
|
4306
|
+
if (modelId) {
|
|
4307
|
+
cache$1.delete(modelId);
|
|
4308
|
+
}
|
|
4309
|
+
};
|
|
4270
4310
|
class KosModelError extends Error {
|
|
4271
4311
|
context;
|
|
4272
4312
|
originalCause;
|
|
@@ -9272,32 +9312,53 @@ const resolveSingleton = () => {
|
|
|
9272
9312
|
};
|
|
9273
9313
|
const kosMockRegistry = resolveSingleton();
|
|
9274
9314
|
const KosMock = kosMockRegistry;
|
|
9275
|
-
|
|
9276
|
-
|
|
9277
|
-
|
|
9315
|
+
const PROFILE_MOCK = "studio.mock";
|
|
9316
|
+
const PROFILE_MOCK_STANDALONE = "studio.mock.standalone";
|
|
9317
|
+
const PROFILE_MOCK_RECORD = "studio.mock.record";
|
|
9318
|
+
const PROFILE_MOCK_FIXTURE_SERVER = "studio.mock.fixtureServer";
|
|
9319
|
+
const PROFILE_MOCK_FIXTURE = "studio.mock.fixture";
|
|
9320
|
+
const PROFILE_MOCK_SETUP = "studio.mock.setup";
|
|
9321
|
+
const profileValue = (name) => {
|
|
9322
|
+
const match = resolveKosProfiles().find(
|
|
9323
|
+
(profile) => profile === name || profile.startsWith(`${name}=`)
|
|
9324
|
+
);
|
|
9325
|
+
return match === void 0 ? void 0 : match.slice(name.length + 1);
|
|
9326
|
+
};
|
|
9327
|
+
if (typeof window !== "undefined") {
|
|
9328
|
+
const params2 = window.location?.search ? getQueryParams() : {};
|
|
9329
|
+
const setting = (param, profile) => params2[param] !== void 0 ? params2[param] : profileValue(profile);
|
|
9330
|
+
const mock = params2["kosMock"] !== void 0 ? params2["kosMock"] : hasKosProfile(PROFILE_MOCK_STANDALONE) ? "standalone" : hasKosProfile(PROFILE_MOCK) ? "on" : void 0;
|
|
9331
|
+
const record = setting("kosRecord", PROFILE_MOCK_RECORD);
|
|
9332
|
+
const fixtureServer = setting(
|
|
9333
|
+
"kosFixtureServer",
|
|
9334
|
+
PROFILE_MOCK_FIXTURE_SERVER
|
|
9335
|
+
);
|
|
9336
|
+
const fixture = setting("kosFixture", PROFILE_MOCK_FIXTURE);
|
|
9337
|
+
const setups = setting("kosSetup", PROFILE_MOCK_SETUP);
|
|
9338
|
+
if (mock === "standalone") {
|
|
9278
9339
|
KosMock.configure({ standalone: true });
|
|
9279
|
-
} else if (
|
|
9340
|
+
} else if (mock === "on") {
|
|
9280
9341
|
KosMock.enable();
|
|
9281
9342
|
}
|
|
9282
|
-
if (
|
|
9283
|
-
KosMock.recorder.start({ name:
|
|
9343
|
+
if (record !== void 0) {
|
|
9344
|
+
KosMock.recorder.start({ name: record || void 0 });
|
|
9284
9345
|
}
|
|
9285
|
-
if (
|
|
9286
|
-
KosMock.fixtures.useServer(
|
|
9346
|
+
if (fixtureServer !== void 0) {
|
|
9347
|
+
KosMock.fixtures.useServer(fixtureServer || true);
|
|
9287
9348
|
}
|
|
9288
9349
|
const bootLoads = [];
|
|
9289
|
-
if (
|
|
9350
|
+
if (fixture) {
|
|
9290
9351
|
bootLoads.push(
|
|
9291
|
-
KosMock.fixtures.play(
|
|
9352
|
+
KosMock.fixtures.play(fixture).then(() => void 0).catch(
|
|
9292
9353
|
(error) => KosLog.error(
|
|
9293
|
-
`KosMock: boot fixture "${
|
|
9354
|
+
`KosMock: boot fixture "${fixture}" failed to load`,
|
|
9294
9355
|
error?.message
|
|
9295
9356
|
)
|
|
9296
9357
|
)
|
|
9297
9358
|
);
|
|
9298
9359
|
}
|
|
9299
|
-
if (
|
|
9300
|
-
for (const name of
|
|
9360
|
+
if (setups) {
|
|
9361
|
+
for (const name of setups.split(",").filter(Boolean)) {
|
|
9301
9362
|
bootLoads.push(
|
|
9302
9363
|
KosMock.setups.load(name).then(() => void 0).catch(
|
|
9303
9364
|
(error) => KosLog.error(
|
|
@@ -11721,6 +11782,8 @@ class KosModelManager {
|
|
|
11721
11782
|
if (model?.modelId && this.dependencies.canDestroy(model.modelId)) {
|
|
11722
11783
|
await model.unload?.();
|
|
11723
11784
|
this.removeModel(model);
|
|
11785
|
+
this.dependencies.removeAll(model.modelId);
|
|
11786
|
+
clearModelHookCacheEntry(model.modelId);
|
|
11724
11787
|
}
|
|
11725
11788
|
}
|
|
11726
11789
|
/**
|
|
@@ -26800,30 +26863,29 @@ const waitForRetry = (depth = 0) => new Promise((resolve) => {
|
|
|
26800
26863
|
resolve(true);
|
|
26801
26864
|
}, 2 ** depth * 10);
|
|
26802
26865
|
});
|
|
26803
|
-
const cache$1 = /* @__PURE__ */ new Map();
|
|
26804
26866
|
function fetchData$1(key, fetcher) {
|
|
26805
|
-
|
|
26806
|
-
|
|
26867
|
+
const entry = modelHookCache.get(key);
|
|
26868
|
+
if (entry) {
|
|
26807
26869
|
if (entry.status === "finished") {
|
|
26808
26870
|
const kosModel2 = KosCore.getInstance().modelManager.getModelById(key);
|
|
26809
26871
|
return { kosModel: kosModel2, model: kosModel2?.modelData };
|
|
26810
|
-
} else {
|
|
26811
|
-
throw entry.promise;
|
|
26812
26872
|
}
|
|
26813
|
-
|
|
26814
|
-
|
|
26815
|
-
|
|
26816
|
-
|
|
26817
|
-
},
|
|
26818
|
-
(error) => {
|
|
26819
|
-
cache$1.set(key, { status: "error", error });
|
|
26820
|
-
throw error;
|
|
26821
|
-
}
|
|
26822
|
-
);
|
|
26823
|
-
const entry = { status: "pending", promise };
|
|
26824
|
-
cache$1.set(key, entry);
|
|
26825
|
-
throw promise;
|
|
26873
|
+
if (entry.status === "error") {
|
|
26874
|
+
throw entry.error;
|
|
26875
|
+
}
|
|
26876
|
+
throw entry.promise;
|
|
26826
26877
|
}
|
|
26878
|
+
const promise = fetcher().then(
|
|
26879
|
+
() => {
|
|
26880
|
+
modelHookCache.set(key, { status: "finished", key });
|
|
26881
|
+
},
|
|
26882
|
+
(error) => {
|
|
26883
|
+
modelHookCache.set(key, { status: "error", error });
|
|
26884
|
+
throw error;
|
|
26885
|
+
}
|
|
26886
|
+
);
|
|
26887
|
+
modelHookCache.set(key, { status: "pending", promise });
|
|
26888
|
+
throw promise;
|
|
26827
26889
|
}
|
|
26828
26890
|
function useSuspenseData$1(key, fetcher) {
|
|
26829
26891
|
const data = fetchData$1(key, fetcher);
|
|
@@ -26914,7 +26976,7 @@ const useKosModel = (modelOptions) => {
|
|
|
26914
26976
|
if (destroyOnUnmount) {
|
|
26915
26977
|
const modelId2 = model.id;
|
|
26916
26978
|
destroyKosModel(model).then(() => {
|
|
26917
|
-
|
|
26979
|
+
clearModelHookCacheEntry(modelId2);
|
|
26918
26980
|
disposer?.();
|
|
26919
26981
|
});
|
|
26920
26982
|
}
|
|
@@ -26923,7 +26985,7 @@ const useKosModel = (modelOptions) => {
|
|
|
26923
26985
|
} else {
|
|
26924
26986
|
if (destroyOnUnmount && model) {
|
|
26925
26987
|
destroyKosModel(model).then(() => {
|
|
26926
|
-
|
|
26988
|
+
clearModelHookCacheEntry(modelId);
|
|
26927
26989
|
disposer?.();
|
|
26928
26990
|
});
|
|
26929
26991
|
}
|
|
@@ -29196,6 +29258,7 @@ export {
|
|
|
29196
29258
|
checkAppsStarted,
|
|
29197
29259
|
checkWildcardPattern,
|
|
29198
29260
|
clearAllServiceResponses,
|
|
29261
|
+
clearModelHookCacheEntry,
|
|
29199
29262
|
clearPath,
|
|
29200
29263
|
clearServiceResponse,
|
|
29201
29264
|
convert,
|
|
@@ -29354,6 +29417,7 @@ export {
|
|
|
29354
29417
|
mapUpdateDtoToConfigBeanModel,
|
|
29355
29418
|
modelEventTopicFactory,
|
|
29356
29419
|
modelFactory,
|
|
29420
|
+
modelHookCache,
|
|
29357
29421
|
modelTypeEventTopicFactory,
|
|
29358
29422
|
modifyConfigBean,
|
|
29359
29423
|
modifyFuture,
|