@kosdev-code/kos-ui-sdk 0.1.0-next.847 → 0.1.0-next.850

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/index.js CHANGED
@@ -1208,6 +1208,25 @@ function kosContext(_target, _propertyKey, descriptor) {
1208
1208
  return originalMethod.apply(this, args);
1209
1209
  };
1210
1210
  }
1211
+ async function executeServiceRequest(host, $ctx, params2) {
1212
+ const name = $ctx?.$name ?? "service request";
1213
+ if (!$ctx?.$request) {
1214
+ host.logger.error(
1215
+ `${name}: missing execution context — executeServiceRequest is for method-driven requests; a @kosServiceRequest with a lifecycle receives (error, data) instead and needs no helper`
1216
+ );
1217
+ return void 0;
1218
+ }
1219
+ const [error, data] = await $ctx.$request(params2);
1220
+ if (error) {
1221
+ host.logger.error(`${name}: request failed`, error);
1222
+ return void 0;
1223
+ }
1224
+ if (data == null) {
1225
+ host.logger.error(`${name}: no data returned`);
1226
+ return void 0;
1227
+ }
1228
+ return data;
1229
+ }
1211
1230
  const KOS_EXECUTION_CONTEXT = /* @__PURE__ */ Symbol("KosExecutionContext");
1212
1231
  function isKosExecutionContext(obj) {
1213
1232
  return obj && typeof obj === "object" && KOS_EXECUTION_CONTEXT in obj;
@@ -1582,11 +1601,13 @@ function kosServiceRequest$9(params2) {
1582
1601
  };
1583
1602
  if (isKosExecutionContext(lastArg)) {
1584
1603
  lastArg.$request = executor;
1604
+ lastArg.$name = String(propertyKey);
1585
1605
  return originalHandler.apply(this, args);
1586
1606
  } else {
1587
1607
  const context = {
1588
1608
  [KOS_EXECUTION_CONTEXT]: true,
1589
- $request: executor
1609
+ $request: executor,
1610
+ $name: String(propertyKey)
1590
1611
  };
1591
1612
  return originalHandler.apply(this, [...args, context]);
1592
1613
  }
@@ -9251,32 +9272,53 @@ const resolveSingleton = () => {
9251
9272
  };
9252
9273
  const kosMockRegistry = resolveSingleton();
9253
9274
  const KosMock = kosMockRegistry;
9254
- if (typeof window !== "undefined" && window.location?.search) {
9255
- const params2 = getQueryParams();
9256
- if (params2["kosMock"] === "standalone") {
9275
+ const PROFILE_MOCK = "studio.mock";
9276
+ const PROFILE_MOCK_STANDALONE = "studio.mock.standalone";
9277
+ const PROFILE_MOCK_RECORD = "studio.mock.record";
9278
+ const PROFILE_MOCK_FIXTURE_SERVER = "studio.mock.fixtureServer";
9279
+ const PROFILE_MOCK_FIXTURE = "studio.mock.fixture";
9280
+ const PROFILE_MOCK_SETUP = "studio.mock.setup";
9281
+ const profileValue = (name) => {
9282
+ const match = resolveKosProfiles().find(
9283
+ (profile) => profile === name || profile.startsWith(`${name}=`)
9284
+ );
9285
+ return match === void 0 ? void 0 : match.slice(name.length + 1);
9286
+ };
9287
+ if (typeof window !== "undefined") {
9288
+ const params2 = window.location?.search ? getQueryParams() : {};
9289
+ const setting = (param, profile) => params2[param] !== void 0 ? params2[param] : profileValue(profile);
9290
+ const mock = params2["kosMock"] !== void 0 ? params2["kosMock"] : hasKosProfile(PROFILE_MOCK_STANDALONE) ? "standalone" : hasKosProfile(PROFILE_MOCK) ? "on" : void 0;
9291
+ const record = setting("kosRecord", PROFILE_MOCK_RECORD);
9292
+ const fixtureServer = setting(
9293
+ "kosFixtureServer",
9294
+ PROFILE_MOCK_FIXTURE_SERVER
9295
+ );
9296
+ const fixture = setting("kosFixture", PROFILE_MOCK_FIXTURE);
9297
+ const setups = setting("kosSetup", PROFILE_MOCK_SETUP);
9298
+ if (mock === "standalone") {
9257
9299
  KosMock.configure({ standalone: true });
9258
- } else if (params2["kosMock"] === "on") {
9300
+ } else if (mock === "on") {
9259
9301
  KosMock.enable();
9260
9302
  }
9261
- if (params2["kosRecord"] !== void 0) {
9262
- KosMock.recorder.start({ name: params2["kosRecord"] || void 0 });
9303
+ if (record !== void 0) {
9304
+ KosMock.recorder.start({ name: record || void 0 });
9263
9305
  }
9264
- if (params2["kosFixtureServer"] !== void 0) {
9265
- KosMock.fixtures.useServer(params2["kosFixtureServer"] || true);
9306
+ if (fixtureServer !== void 0) {
9307
+ KosMock.fixtures.useServer(fixtureServer || true);
9266
9308
  }
9267
9309
  const bootLoads = [];
9268
- if (params2["kosFixture"]) {
9310
+ if (fixture) {
9269
9311
  bootLoads.push(
9270
- KosMock.fixtures.play(params2["kosFixture"]).then(() => void 0).catch(
9312
+ KosMock.fixtures.play(fixture).then(() => void 0).catch(
9271
9313
  (error) => KosLog.error(
9272
- `KosMock: boot fixture "${params2["kosFixture"]}" failed to load`,
9314
+ `KosMock: boot fixture "${fixture}" failed to load`,
9273
9315
  error?.message
9274
9316
  )
9275
9317
  )
9276
9318
  );
9277
9319
  }
9278
- if (params2["kosSetup"]) {
9279
- for (const name of params2["kosSetup"].split(",").filter(Boolean)) {
9320
+ if (setups) {
9321
+ for (const name of setups.split(",").filter(Boolean)) {
9280
9322
  bootLoads.push(
9281
9323
  KosMock.setups.load(name).then(() => void 0).catch(
9282
9324
  (error) => KosLog.error(
@@ -29208,6 +29250,7 @@ export {
29208
29250
  executeChildrenModelLifecycle,
29209
29251
  executeDependentModelLifecycle,
29210
29252
  executeListLifecycle,
29253
+ executeServiceRequest,
29211
29254
  fetchModel,
29212
29255
  findModel,
29213
29256
  findModels,