@niscorp/nova 0.2.0 → 0.2.1

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/README.md +56 -13
  3. package/SHELL_DOCS.md +13 -4
  4. package/dist/adapters/dom/index.cjs.map +1 -1
  5. package/dist/adapters/dom/index.js +2 -2
  6. package/dist/adapters/dom/server.js +2 -2
  7. package/dist/adapters/react/components/index.js +3 -3
  8. package/dist/adapters/react/index.cjs.map +1 -1
  9. package/dist/adapters/react/index.js +3 -3
  10. package/dist/adapters/tty/index.js +1 -1
  11. package/dist/adapters/vue/components/index.js +3 -3
  12. package/dist/adapters/vue/index.cjs.map +1 -1
  13. package/dist/adapters/vue/index.js +4 -4
  14. package/dist/{chunk-RYIIIXDX.js → chunk-DU2VIJAF.js} +57 -15
  15. package/dist/chunk-DU2VIJAF.js.map +1 -0
  16. package/dist/{chunk-VU6NNCEJ.js → chunk-F2H7WP6R.js} +4 -4
  17. package/dist/{chunk-VU6NNCEJ.js.map → chunk-F2H7WP6R.js.map} +1 -1
  18. package/dist/{chunk-QXQCPH33.js → chunk-G4LSLLGI.js} +4 -4
  19. package/dist/{chunk-QXQCPH33.js.map → chunk-G4LSLLGI.js.map} +1 -1
  20. package/dist/{chunk-MHW5VEIM.js → chunk-SVNK5NIK.js} +3 -3
  21. package/dist/{chunk-MHW5VEIM.js.map → chunk-SVNK5NIK.js.map} +1 -1
  22. package/dist/{chunk-UDCXGDLQ.js → chunk-VOD5JA4D.js} +3 -3
  23. package/dist/{chunk-UDCXGDLQ.js.map → chunk-VOD5JA4D.js.map} +1 -1
  24. package/dist/chunk-XQTI4Q4I.js +178 -0
  25. package/dist/chunk-XQTI4Q4I.js.map +1 -0
  26. package/dist/examples/index.cjs +1186 -0
  27. package/dist/examples/index.cjs.map +1 -0
  28. package/dist/examples/index.d.cts +63 -0
  29. package/dist/examples/index.d.ts +63 -0
  30. package/dist/examples/index.js +1158 -0
  31. package/dist/examples/index.js.map +1 -0
  32. package/dist/i18n/index.js +2 -176
  33. package/dist/i18n/index.js.map +1 -1
  34. package/dist/index.cjs +55 -12
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.cts +5 -1
  37. package/dist/index.d.ts +5 -1
  38. package/dist/index.js +1 -1
  39. package/package.json +19 -8
  40. package/dist/chunk-RYIIIXDX.js.map +0 -1
package/dist/index.cjs CHANGED
@@ -2166,7 +2166,16 @@ var executeSteps = async (steps, ctx) => {
2166
2166
  const channel = typeof resolvedChannel === "string" ? resolvedChannel : String(resolvedChannel ?? "");
2167
2167
  const payload = step.emit.payload === void 0 ? void 0 : resolve(step.emit.payload, chain, ctx.extras);
2168
2168
  const { messageBus, cause } = ctx;
2169
- nextTask(() => messageBus.publish(channel, payload, cause));
2169
+ const delivered = new Promise((resolve2) => {
2170
+ nextTask(() => {
2171
+ try {
2172
+ messageBus.publish(channel, payload, cause);
2173
+ } finally {
2174
+ resolve2();
2175
+ }
2176
+ });
2177
+ });
2178
+ ctx.onChain?.(delivered);
2170
2179
  continue;
2171
2180
  }
2172
2181
  if ("push" in step) {
@@ -2310,9 +2319,10 @@ var fireTrigger = (trigger, buildContext, event, cause) => {
2310
2319
  }
2311
2320
  const base = { ...built, cause };
2312
2321
  const ctx = event === void 0 ? base : { ...base, extras: { ...base.extras, "@event": event } };
2313
- void executeSteps(trigger.do, ctx).catch((err) => {
2322
+ const chain = executeSteps(trigger.do, ctx).catch((err) => {
2314
2323
  ctx.onError(toNovaError(err));
2315
2324
  });
2325
+ ctx.onChain?.(chain);
2316
2326
  };
2317
2327
  var eventOrigin = (event) => {
2318
2328
  if (!hasKey(event, "origin")) return void 0;
@@ -2457,6 +2467,7 @@ var createActionRuntime = (config) => {
2457
2467
  // the shell's telemetry — `runCall` only knows the endpoint, the runtime
2458
2468
  // knows who made it.
2459
2469
  ...config.onEndpoint === void 0 ? {} : { onEndpoint: (event) => config.onEndpoint({ ...event, instanceId: instance.id, canvasId: instance.canvasId }) },
2470
+ ...config.onChain === void 0 ? {} : { onChain: config.onChain },
2460
2471
  calls,
2461
2472
  extras: {},
2462
2473
  initial: initialSnapshot,
@@ -2688,6 +2699,7 @@ var createRuntimeFactory = (deps) => (canvasId, definition, input) => createActi
2688
2699
  ...deps.endpointTimeoutMs === void 0 ? {} : { endpointTimeoutMs: deps.endpointTimeoutMs },
2689
2700
  onNavigate: (effect) => deps.onNavigate(canvasId, effect),
2690
2701
  ...deps.onEndpoint === void 0 ? {} : { onEndpoint: deps.onEndpoint },
2702
+ ...deps.onChain === void 0 ? {} : { onChain: deps.onChain },
2691
2703
  strict: deps.strict,
2692
2704
  ...deps.onError === void 0 ? {} : { onError: deps.onError },
2693
2705
  ...deps.i18n === void 0 ? {} : { i18n: deps.i18n },
@@ -2932,14 +2944,18 @@ var createJournal = (limit) => {
2932
2944
 
2933
2945
  // src/shell/lifecycle-ops.ts
2934
2946
  var createLifecycleOps = (deps) => {
2935
- const { registry, onLifecycleError, onUnmount } = deps;
2947
+ const { registry, onLifecycleError, onUnmount, onChain } = deps;
2948
+ const detached = (hook) => {
2949
+ const chain = hook.catch(onLifecycleError);
2950
+ onChain?.(chain);
2951
+ };
2936
2952
  const unmounted = /* @__PURE__ */ new Set();
2937
2953
  const unmountInstance = (instanceId) => {
2938
2954
  if (unmounted.has(instanceId)) return;
2939
2955
  const runtime = registry.get(instanceId);
2940
2956
  if (runtime === void 0) return;
2941
2957
  unmounted.add(instanceId);
2942
- runtime.unmount().catch(onLifecycleError);
2958
+ detached(runtime.unmount());
2943
2959
  runtime.dispose();
2944
2960
  registry.unregister(instanceId);
2945
2961
  onUnmount?.(instanceId);
@@ -2950,17 +2966,37 @@ var createLifecycleOps = (deps) => {
2950
2966
  if (top === void 0) return;
2951
2967
  if (top.status === "suspended") return;
2952
2968
  const runtime = registry.get(top.id);
2953
- if (runtime !== void 0) runtime.suspend().catch(onLifecycleError);
2969
+ if (runtime !== void 0) detached(runtime.suspend());
2954
2970
  };
2955
2971
  const resumeTop = (canvas) => {
2956
2972
  const top = canvas.peek();
2957
2973
  if (top === void 0) return;
2958
2974
  const runtime = registry.get(top.id);
2959
- if (runtime !== void 0) runtime.resume().catch(onLifecycleError);
2975
+ if (runtime !== void 0) detached(runtime.resume());
2960
2976
  };
2961
2977
  return { unmountInstance, suspendTop, resumeTop };
2962
2978
  };
2963
2979
 
2980
+ // src/shell/chains.ts
2981
+ var createChainCount = () => {
2982
+ let count = 0;
2983
+ const release = () => {
2984
+ count -= 1;
2985
+ };
2986
+ return {
2987
+ hold: (chain) => {
2988
+ count += 1;
2989
+ chain.then(release, release);
2990
+ },
2991
+ inFlight: () => count
2992
+ };
2993
+ };
2994
+ var chainCounts = /* @__PURE__ */ new WeakMap();
2995
+ var rememberChainCount = (shell, count) => {
2996
+ chainCounts.set(shell, count);
2997
+ };
2998
+ var chainsInFlight = (shell) => chainCounts.get(shell)?.inFlight() ?? 0;
2999
+
2964
3000
  // src/shell/navigation.ts
2965
3001
  var navigatedChannel = (canvasId) => `nova:navigated:${canvasId}`;
2966
3002
  var createNavigationHandler = (ops) => {
@@ -3115,9 +3151,11 @@ var createShell = (config) => {
3115
3151
  const origins = /* @__PURE__ */ new Map();
3116
3152
  const births = /* @__PURE__ */ new Map();
3117
3153
  const journal = createJournal(config.historyDepth ?? DEFAULT_HISTORY_DEPTH);
3154
+ const chains = createChainCount();
3118
3155
  const ops = createLifecycleOps({
3119
3156
  registry,
3120
3157
  onLifecycleError: handleLifecycleRejection,
3158
+ onChain: chains.hold,
3121
3159
  onUnmount: (instanceId) => {
3122
3160
  origins.delete(instanceId);
3123
3161
  births.delete(instanceId);
@@ -3303,7 +3341,8 @@ var createShell = (config) => {
3303
3341
  onNavigate: (cid, effect) => navigationHandler(cid, effect),
3304
3342
  // Every endpoint call an action makes flows to telemetry — the shell's one
3305
3343
  // observability surface (state, data, and now endpoints all land here).
3306
- onEndpoint: (event) => telemetry.fireEndpoint(event)
3344
+ onEndpoint: (event) => telemetry.fireEndpoint(event),
3345
+ onChain: chains.hold
3307
3346
  });
3308
3347
  const spawn = (canvasId, definition, input) => {
3309
3348
  const runtime = buildRuntime(canvasId, definition, input);
@@ -3632,6 +3671,7 @@ var createShell = (config) => {
3632
3671
  dispose
3633
3672
  };
3634
3673
  rememberShellRegistry(shell, registry);
3674
+ rememberChainCount(shell, chains);
3635
3675
  for (const cfg of config.canvases) seedCanvas(cfg);
3636
3676
  return shell;
3637
3677
  };
@@ -3800,10 +3840,8 @@ var shellView = (shell) => ({
3800
3840
  };
3801
3841
  }
3802
3842
  });
3803
- var DEFAULT_SETTLE_WAIT_MS = 300;
3804
- var shellSettled = async (shell, options = {}) => {
3843
+ var shellQuietWithin = async (shell, isBusy, options) => {
3805
3844
  const waitMs = options.waitMs ?? DEFAULT_SETTLE_WAIT_MS;
3806
- const mounting = () => Object.values(shell.getState().canvases).some((canvas) => canvas.stack.some((instance) => instance.status === "initializing"));
3807
3845
  let timer;
3808
3846
  const deadline = new Promise((resolve2) => {
3809
3847
  timer = setTimeout(() => resolve2(false), waitMs);
@@ -3811,9 +3849,9 @@ var shellSettled = async (shell, options = {}) => {
3811
3849
  const quiet = (async () => {
3812
3850
  for (; ; ) {
3813
3851
  if (options.stopped?.() === true) return false;
3814
- if (!mounting()) {
3852
+ if (!isBusy()) {
3815
3853
  await new Promise((resolve2) => setTimeout(resolve2, 0));
3816
- if (!mounting()) return true;
3854
+ if (!isBusy()) return true;
3817
3855
  }
3818
3856
  await new Promise((resolve2) => {
3819
3857
  const off = shell.onStateChange(() => {
@@ -3831,6 +3869,10 @@ var shellSettled = async (shell, options = {}) => {
3831
3869
  clearTimeout(timer);
3832
3870
  return settled;
3833
3871
  };
3872
+ var isMounting = (shell) => Object.values(shell.getState().canvases).some((canvas) => canvas.stack.some((instance) => instance.status === "initializing"));
3873
+ var DEFAULT_SETTLE_WAIT_MS = 300;
3874
+ var shellSettled = (shell, options = {}) => shellQuietWithin(shell, () => isMounting(shell), options);
3875
+ var shellIdle = (shell, options = {}) => shellQuietWithin(shell, () => isMounting(shell) || chainsInFlight(shell) > 0, options);
3834
3876
 
3835
3877
  exports.ACTION_SLOT_NAME = ACTION_SLOT_NAME;
3836
3878
  exports.ActionDefinitionSchema = ActionDefinitionSchema;
@@ -3909,6 +3951,7 @@ exports.renderLayout = renderLayout;
3909
3951
  exports.renderLayoutFromStore = renderLayoutFromStore;
3910
3952
  exports.renderNodeKey = renderNodeKey;
3911
3953
  exports.scopeDispatch = scopeDispatch;
3954
+ exports.shellIdle = shellIdle;
3912
3955
  exports.shellSettled = shellSettled;
3913
3956
  exports.shellView = shellView;
3914
3957
  //# sourceMappingURL=index.cjs.map