@camunda8/orchestration-cluster-api 10.0.0-alpha.30 → 10.0.0-alpha.31

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.
@@ -9219,19 +9219,24 @@ default, with local set to \`false\`, scope '1' will be { "foo": 5 } and scope '
9219
9219
  }
9220
9220
  });
9221
9221
 
9222
- // src/fp/index.ts
9223
- var fp_exports = {};
9224
- __export(fp_exports, {
9225
- classifyDomainError: () => classifyDomainError,
9226
- createCamundaFpClient: () => createCamundaFpClient,
9227
- eventuallyTE: () => eventuallyTE,
9228
- foldDomainError: () => foldDomainError,
9229
- isLeft: () => isLeft,
9230
- isRight: () => isRight,
9231
- retryTE: () => retryTE,
9232
- withTimeoutTE: () => withTimeoutTE
9222
+ // src/effect/index.ts
9223
+ var effect_exports = {};
9224
+ __export(effect_exports, {
9225
+ CamundaEffect: () => CamundaEffect,
9226
+ CamundaGenericError: () => CamundaGenericError,
9227
+ CamundaValidationError: () => CamundaValidationError2,
9228
+ EventualConsistencyTimeout: () => EventualConsistencyTimeout,
9229
+ HttpError: () => HttpError,
9230
+ createCamundaEffectClient: () => createCamundaEffectClient,
9231
+ eventually: () => eventually,
9232
+ layer: () => layer,
9233
+ retryWithBackoff: () => retryWithBackoff,
9234
+ withTimeout: () => withTimeout
9233
9235
  });
9234
- module.exports = __toCommonJS(fp_exports);
9236
+ module.exports = __toCommonJS(effect_exports);
9237
+
9238
+ // src/effect.ts
9239
+ var import_effect = require("effect");
9235
9240
 
9236
9241
  // src/gen/core/serverSentEvents.gen.ts
9237
9242
  var __STANDARD_REQUEST_INIT_KEYS = [
@@ -13783,7 +13788,7 @@ function createLogger(opts = {}) {
13783
13788
  }
13784
13789
 
13785
13790
  // src/runtime/version.ts
13786
- var packageVersion = "10.0.0-alpha.30";
13791
+ var packageVersion = "10.0.0-alpha.31";
13787
13792
 
13788
13793
  // src/runtime/supportLogger.ts
13789
13794
  var NoopSupportLogger = class {
@@ -14239,18 +14244,18 @@ function unwrapForInspection(s) {
14239
14244
  continue;
14240
14245
  }
14241
14246
  if (t === "ZodIntersection") {
14242
- const left2 = cur._def.left;
14243
- const right2 = cur._def.right;
14244
- if (left2?._def?.typeName === "ZodObject" && right2?._def?.typeName === "ZodObject") {
14247
+ const left = cur._def.left;
14248
+ const right = cur._def.right;
14249
+ if (left?._def?.typeName === "ZodObject" && right?._def?.typeName === "ZodObject") {
14245
14250
  try {
14246
- const leftShapeFn = left2._def.shape;
14247
- const rightShapeFn = right2._def.shape;
14251
+ const leftShapeFn = left._def.shape;
14252
+ const rightShapeFn = right._def.shape;
14248
14253
  const merged = { ...leftShapeFn(), ...rightShapeFn() };
14249
14254
  return import_zod.ZodObject.create(merged);
14250
14255
  } catch {
14251
14256
  }
14252
14257
  }
14253
- cur = left2;
14258
+ cur = left;
14254
14259
  continue;
14255
14260
  }
14256
14261
  break;
@@ -29957,54 +29962,73 @@ var CamundaClient = class {
29957
29962
  }
29958
29963
  };
29959
29964
 
29960
- // src/fp-ts.ts
29961
- var left = (e) => ({ _tag: "Left", left: e });
29962
- var right = (a) => ({ _tag: "Right", right: a });
29963
- var isLeft = (e) => e._tag === "Left";
29964
- var isRight = (e) => e._tag === "Right";
29965
+ // src/effect.ts
29966
+ var CamundaValidationError2 = class extends import_effect.Data.TaggedError("CamundaValidationError") {
29967
+ };
29968
+ var EventualConsistencyTimeout = class extends import_effect.Data.TaggedError("EventualConsistencyTimeout") {
29969
+ };
29970
+ var HttpError = class extends import_effect.Data.TaggedError("HttpError") {
29971
+ };
29972
+ var CamundaGenericError = class extends import_effect.Data.TaggedError("CamundaGenericError") {
29973
+ };
29965
29974
  function toDomainError(err) {
29966
- if (err instanceof CamundaValidationError) return err;
29967
- if (err instanceof EventualConsistencyTimeoutError) return err;
29968
- if (err instanceof Error) return err;
29969
- if (typeof err === "object") return err;
29970
- return { message: String(err) };
29971
- }
29972
- function classifyDomainError(err) {
29973
- if (err instanceof CamundaValidationError) return "validation";
29974
- if (err instanceof EventualConsistencyTimeoutError) return "timeout";
29975
- if (!(err instanceof Error) || err.status !== void 0) return "http";
29976
- return "generic";
29977
- }
29978
- function foldDomainError(handlers) {
29979
- return (err) => {
29980
- switch (classifyDomainError(err)) {
29981
- case "validation":
29982
- return handlers.validation(err);
29983
- case "timeout":
29984
- return handlers.timeout(err);
29985
- case "http":
29986
- return handlers.http(err);
29987
- case "generic":
29988
- return handlers.generic(err);
29989
- }
29990
- };
29975
+ if (err instanceof CamundaValidationError) {
29976
+ return new CamundaValidationError2({
29977
+ side: err.side,
29978
+ operationId: err.operationId,
29979
+ summary: err.summary,
29980
+ issues: err.issues,
29981
+ message: err.message,
29982
+ cause: err
29983
+ });
29984
+ }
29985
+ if (err instanceof EventualConsistencyTimeoutError) {
29986
+ return new EventualConsistencyTimeout({
29987
+ attempts: err.attempts,
29988
+ elapsedMs: err.elapsedMs,
29989
+ message: err.message,
29990
+ cause: err
29991
+ });
29992
+ }
29993
+ const anyErr = err;
29994
+ if (anyErr && typeof anyErr === "object" && typeof anyErr.status === "number") {
29995
+ return new HttpError({
29996
+ status: anyErr.status,
29997
+ body: anyErr.body,
29998
+ message: typeof anyErr.message === "string" ? anyErr.message : `HTTP ${anyErr.status}`,
29999
+ cause: err
30000
+ });
30001
+ }
30002
+ if (err instanceof Error) {
30003
+ return new CamundaGenericError({ message: err.message, cause: err });
30004
+ }
30005
+ return new CamundaGenericError({ message: String(err), cause: err });
29991
30006
  }
29992
30007
  function isPromiseLike(v) {
29993
- return v && typeof v.then === "function";
30008
+ return !!v && typeof v.then === "function";
29994
30009
  }
29995
- function createCamundaFpClient(options) {
30010
+ function createCamundaEffectClient(options) {
29996
30011
  const base = createCamundaClient(options);
29997
30012
  const cache = /* @__PURE__ */ new Map();
29998
30013
  function wrap(fn) {
29999
- return (...args) => async () => {
30014
+ return (...args) => import_effect.Effect.suspend(() => {
30015
+ let r;
30000
30016
  try {
30001
- const r = fn.apply(base, args);
30002
- const val = isPromiseLike(r) ? await r : r;
30003
- return right(val);
30017
+ r = fn.apply(base, args);
30004
30018
  } catch (e) {
30005
- return left(toDomainError(e));
30006
- }
30007
- };
30019
+ return import_effect.Effect.fail(toDomainError(e));
30020
+ }
30021
+ if (!isPromiseLike(r)) return import_effect.Effect.succeed(r);
30022
+ const promise = r;
30023
+ return import_effect.Effect.callback((resume) => {
30024
+ promise.then(
30025
+ (a) => resume(import_effect.Effect.succeed(a)),
30026
+ (e) => resume(import_effect.Effect.fail(toDomainError(e)))
30027
+ );
30028
+ const cancel = r.cancel;
30029
+ return typeof cancel === "function" ? import_effect.Effect.sync(() => cancel.call(r)) : void 0;
30030
+ });
30031
+ });
30008
30032
  }
30009
30033
  const handler = {
30010
30034
  get(_t, prop) {
@@ -30022,71 +30046,66 @@ function createCamundaFpClient(options) {
30022
30046
  };
30023
30047
  return new Proxy({}, handler);
30024
30048
  }
30025
- function retryTE(task, opts) {
30026
- const { max, baseDelayMs = 100, shouldRetry } = opts;
30027
- return async () => {
30028
- let attempt = 0;
30029
- let lastLeft;
30030
- while (attempt < max) {
30031
- const res = await task();
30032
- if (isRight(res)) return res;
30033
- lastLeft = res;
30034
- attempt++;
30035
- const retry = attempt < max && (shouldRetry ? await shouldRetry(res.left, attempt) : true);
30036
- if (!retry) return res;
30037
- const delay = Math.min(2e3, baseDelayMs * 2 ** (attempt - 1));
30038
- await new Promise((r) => setTimeout(r, delay));
30039
- }
30040
- return lastLeft;
30041
- };
30049
+ function formatDuration(d) {
30050
+ try {
30051
+ return import_effect.Duration.format(import_effect.Duration.fromInputUnsafe(d));
30052
+ } catch {
30053
+ return String(d);
30054
+ }
30042
30055
  }
30043
- function withTimeoutTE(task, ms, onTimeout) {
30044
- return async () => {
30045
- let settled = false;
30046
- const t = task().then((r) => {
30047
- settled = true;
30048
- return r;
30049
- });
30050
- const timeout = new Promise(
30051
- (res) => setTimeout(() => {
30052
- if (!settled)
30053
- res(left(onTimeout ? onTimeout() : new Error(`Timeout after ${ms}ms`)));
30054
- }, ms)
30055
- );
30056
- return Promise.race([t, timeout]);
30057
- };
30056
+ function retryWithBackoff(effect, opts) {
30057
+ const backoff = import_effect.Schedule.exponential(opts.baseDelay ?? "100 millis").pipe(import_effect.Schedule.jittered);
30058
+ return import_effect.Effect.retry(effect, {
30059
+ schedule: backoff,
30060
+ times: Math.max(0, opts.max - 1),
30061
+ while: opts.while
30062
+ });
30058
30063
  }
30059
- function eventuallyTE(thunk, predicate, opts) {
30060
- const { intervalMs = 500, waitUpToMs } = opts;
30061
- return async () => {
30062
- const start = Date.now();
30063
- let attempt = 0;
30064
- while (true) {
30065
- attempt++;
30066
- try {
30067
- const val = await thunk();
30068
- if (await predicate(val)) return right(val);
30069
- } catch (e) {
30070
- return left(e);
30071
- }
30072
- const elapsed = Date.now() - start;
30073
- if (elapsed >= waitUpToMs)
30074
- return left(
30075
- new EventualConsistencyTimeoutError({ attempts: attempt, elapsedMs: elapsed })
30076
- );
30077
- await new Promise((r) => setTimeout(r, intervalMs));
30078
- }
30079
- };
30064
+ function withTimeout(effect, duration, onTimeout) {
30065
+ return import_effect.Effect.timeoutOrElse(effect, {
30066
+ duration,
30067
+ orElse: () => import_effect.Effect.fail(
30068
+ onTimeout ? onTimeout() : new EventualConsistencyTimeout({
30069
+ message: `Timed out after ${formatDuration(duration)}`
30070
+ })
30071
+ )
30072
+ });
30073
+ }
30074
+ function eventually(effect, predicate, opts) {
30075
+ const interval = opts.interval ?? "500 millis";
30076
+ const poll = import_effect.Effect.suspend(
30077
+ () => effect.pipe(
30078
+ import_effect.Effect.flatMap(
30079
+ (a) => predicate(a) ? import_effect.Effect.succeed(a) : import_effect.Effect.sleep(interval).pipe(import_effect.Effect.andThen(poll))
30080
+ )
30081
+ )
30082
+ );
30083
+ return withTimeout(
30084
+ poll,
30085
+ opts.waitUpTo,
30086
+ () => new EventualConsistencyTimeout({
30087
+ message: `Eventual consistency timeout after ${formatDuration(opts.waitUpTo)}`
30088
+ })
30089
+ );
30090
+ }
30091
+ var CamundaEffect = class extends import_effect.Context.Service()(
30092
+ "CamundaEffect"
30093
+ ) {
30094
+ };
30095
+ function layer(options) {
30096
+ return import_effect.Layer.sync(CamundaEffect, () => createCamundaEffectClient(options));
30080
30097
  }
30081
30098
  // Annotate the CommonJS export names for ESM import in node:
30082
30099
  0 && (module.exports = {
30083
- classifyDomainError,
30084
- createCamundaFpClient,
30085
- eventuallyTE,
30086
- foldDomainError,
30087
- isLeft,
30088
- isRight,
30089
- retryTE,
30090
- withTimeoutTE
30100
+ CamundaEffect,
30101
+ CamundaGenericError,
30102
+ CamundaValidationError,
30103
+ EventualConsistencyTimeout,
30104
+ HttpError,
30105
+ createCamundaEffectClient,
30106
+ eventually,
30107
+ layer,
30108
+ retryWithBackoff,
30109
+ withTimeout
30091
30110
  });
30092
30111
  //# sourceMappingURL=index.cjs.map