@dudousxd/nestjs-durable-core 0.62.0 → 0.63.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/index.cjs CHANGED
@@ -2676,6 +2676,7 @@ var WorkflowEngine = class {
2676
2676
  onEvent: opts?.onEvent,
2677
2677
  eventBatch: opts?.eventBatch,
2678
2678
  requires: opts?.requires,
2679
+ origin: opts?.origin,
2679
2680
  // A real, retained in-process body — so `workflowBody` can hand it to an in-app worker, and so
2680
2681
  // it is NOT confused with the throwing stub `registerRemote` installs for a body-less remote.
2681
2682
  hasBody: true
@@ -2902,6 +2903,11 @@ var WorkflowEngine = class {
2902
2903
  workflowVersion: registered.version,
2903
2904
  status: "pending",
2904
2905
  namespace: opts?.namespace ?? this.namespace,
2906
+ // DERIVED from the registration, exactly like `namespace` is derived from this engine — there is
2907
+ // deliberately no `opts.origin`, so a caller cannot label its run as another package's work.
2908
+ // `undefined` when the registration carried none (remote/convention/synthesized child, or a
2909
+ // registrar that could not resolve the declaring package): unknown, not "the app".
2910
+ origin: registered.origin,
2905
2911
  input,
2906
2912
  tags,
2907
2913
  searchAttributes: opts?.searchAttributes,
@@ -5776,6 +5782,43 @@ __name(collectMetrics, "collectMetrics");
5776
5782
 
5777
5783
  // src/scheduler.ts
5778
5784
  var import_node_module = require("module");
5785
+
5786
+ // src/cron-compat.ts
5787
+ function isIndexable(value) {
5788
+ return typeof value === "object" && value !== null || typeof value === "function";
5789
+ }
5790
+ __name(isIndexable, "isIndexable");
5791
+ function unwrapDefault(module_) {
5792
+ if (!isIndexable(module_)) return module_;
5793
+ if (Reflect.get(module_, "parseExpression") !== void 0) return module_;
5794
+ if (Reflect.get(module_, "CronExpressionParser") !== void 0) return module_;
5795
+ const inner = Reflect.get(module_, "default");
5796
+ return inner === void 0 ? module_ : inner;
5797
+ }
5798
+ __name(unwrapDefault, "unwrapDefault");
5799
+ function v4Entry(module_) {
5800
+ if (!isIndexable(module_)) return void 0;
5801
+ const parse = Reflect.get(module_, "parseExpression");
5802
+ if (typeof parse !== "function") return void 0;
5803
+ return (expr, options) => parse.call(module_, expr, options);
5804
+ }
5805
+ __name(v4Entry, "v4Entry");
5806
+ function v5Entry(module_) {
5807
+ if (!isIndexable(module_)) return void 0;
5808
+ const parser = Reflect.get(module_, "CronExpressionParser");
5809
+ if (!isIndexable(parser)) return void 0;
5810
+ const parse = Reflect.get(parser, "parse");
5811
+ if (typeof parse !== "function") return void 0;
5812
+ return (expr, options) => parse.call(parser, expr, options);
5813
+ }
5814
+ __name(v5Entry, "v5Entry");
5815
+ function resolveCronParse(module_) {
5816
+ const resolved = unwrapDefault(module_);
5817
+ return v4Entry(resolved) ?? v5Entry(resolved);
5818
+ }
5819
+ __name(resolveCronParse, "resolveCronParse");
5820
+
5821
+ // src/scheduler.ts
5779
5822
  var nodeRequire = (0, import_node_module.createRequire)(__importMetaUrl);
5780
5823
  var defaultSleep = /* @__PURE__ */ __name((ms) => new Promise((r) => setTimeout(r, ms)), "defaultSleep");
5781
5824
  function scheduledRunId(key, everyMs, nowMs) {
@@ -5784,7 +5827,7 @@ function scheduledRunId(key, everyMs, nowMs) {
5784
5827
  __name(scheduledRunId, "scheduledRunId");
5785
5828
  var cronParser;
5786
5829
  function loadCronParser() {
5787
- if (cronParser) return cronParser;
5830
+ if (cronParser !== void 0) return cronParser;
5788
5831
  try {
5789
5832
  cronParser = nodeRequire("cron-parser");
5790
5833
  } catch {
@@ -5794,12 +5837,14 @@ function loadCronParser() {
5794
5837
  }
5795
5838
  __name(loadCronParser, "loadCronParser");
5796
5839
  function prevCronFireMs(expr, nowMs, timezone = "UTC") {
5797
- const parser = loadCronParser();
5798
- const it = parser.parseExpression(expr, {
5840
+ const parse = resolveCronParse(loadCronParser());
5841
+ if (!parse) {
5842
+ throw new Error(`the installed "cron-parser" exposes neither v4's parseExpression nor v5's CronExpressionParser.parse \u2014 the supported range is ^4.0.0 || ^5.0.0.`);
5843
+ }
5844
+ return parse(expr, {
5799
5845
  currentDate: new Date(nowMs + 1),
5800
5846
  tz: timezone
5801
- });
5802
- return it.prev().toDate().getTime();
5847
+ }).prev().toDate().getTime();
5803
5848
  }
5804
5849
  __name(prevCronFireMs, "prevCronFireMs");
5805
5850
  function scheduleRunIdAt(s, nowMs) {
@@ -6208,6 +6253,7 @@ var InMemoryStateStore = class {
6208
6253
  if (query.statuses) runs = runs.filter((r) => query.statuses?.includes(r.status));
6209
6254
  if (query.tag) runs = runs.filter((r) => r.tags?.includes(query.tag));
6210
6255
  if (query.namespace !== void 0) runs = runs.filter((r) => r.namespace === query.namespace);
6256
+ if (query.origin !== void 0) runs = runs.filter((r) => r.origin === query.origin);
6211
6257
  if (query.attributes?.length) {
6212
6258
  let candidates = null;
6213
6259
  for (const f of query.attributes) {