@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
@@ -1,8 +1,8 @@
1
- import { NovaRenderKey, NovaShellKey, provideShellHead, useShellRenderTree, RenderTree, useShell, useCanvasRenderTree, registerNovaVueComponents } from '../../chunk-VU6NNCEJ.js';
2
- export { ErrorMarker, NovaRenderKey, NovaShellKey, RenderNodeView, RenderTree, isNovaComponent, useActionData, useActionStatus, useCanvas, useCanvasRenderTree, useNovaDispatch, useNovaPublish, useNovaRegistry, useRenderTree, useShell, useShellRenderTree, useShellState, useSlotWrapper } from '../../chunk-VU6NNCEJ.js';
3
- import '../../chunk-UDCXGDLQ.js';
1
+ import { NovaRenderKey, NovaShellKey, provideShellHead, useShellRenderTree, RenderTree, useShell, useCanvasRenderTree, registerNovaVueComponents } from '../../chunk-F2H7WP6R.js';
2
+ export { ErrorMarker, NovaRenderKey, NovaShellKey, RenderNodeView, RenderTree, isNovaComponent, useActionData, useActionStatus, useCanvas, useCanvasRenderTree, useNovaDispatch, useNovaPublish, useNovaRegistry, useRenderTree, useShell, useShellRenderTree, useShellState, useSlotWrapper } from '../../chunk-F2H7WP6R.js';
3
+ import '../../chunk-VOD5JA4D.js';
4
4
  import '../../chunk-V4BPFFFV.js';
5
- import '../../chunk-RYIIIXDX.js';
5
+ import '../../chunk-DU2VIJAF.js';
6
6
  import { CANVAS_SLOT_NAME } from '../../chunk-RFBIGRCI.js';
7
7
  import '../../chunk-Y6XVPRYH.js';
8
8
  import '../../chunk-OGD5CCMZ.js';
@@ -699,7 +699,16 @@ var executeSteps = async (steps, ctx) => {
699
699
  const channel = typeof resolvedChannel === "string" ? resolvedChannel : String(resolvedChannel ?? "");
700
700
  const payload = step.emit.payload === void 0 ? void 0 : resolve(step.emit.payload, chain, ctx.extras);
701
701
  const { messageBus, cause } = ctx;
702
- nextTask(() => messageBus.publish(channel, payload, cause));
702
+ const delivered = new Promise((resolve2) => {
703
+ nextTask(() => {
704
+ try {
705
+ messageBus.publish(channel, payload, cause);
706
+ } finally {
707
+ resolve2();
708
+ }
709
+ });
710
+ });
711
+ ctx.onChain?.(delivered);
703
712
  continue;
704
713
  }
705
714
  if ("push" in step) {
@@ -843,9 +852,10 @@ var fireTrigger = (trigger, buildContext, event, cause) => {
843
852
  }
844
853
  const base = { ...built, cause };
845
854
  const ctx = event === void 0 ? base : { ...base, extras: { ...base.extras, "@event": event } };
846
- void executeSteps(trigger.do, ctx).catch((err) => {
855
+ const chain = executeSteps(trigger.do, ctx).catch((err) => {
847
856
  ctx.onError(toNovaError(err));
848
857
  });
858
+ ctx.onChain?.(chain);
849
859
  };
850
860
  var eventOrigin = (event) => {
851
861
  if (!hasKey(event, "origin")) return void 0;
@@ -990,6 +1000,7 @@ var createActionRuntime = (config) => {
990
1000
  // the shell's telemetry — `runCall` only knows the endpoint, the runtime
991
1001
  // knows who made it.
992
1002
  ...config.onEndpoint === void 0 ? {} : { onEndpoint: (event) => config.onEndpoint({ ...event, instanceId: instance.id, canvasId: instance.canvasId }) },
1003
+ ...config.onChain === void 0 ? {} : { onChain: config.onChain },
993
1004
  calls,
994
1005
  extras: {},
995
1006
  initial: initialSnapshot,
@@ -1221,6 +1232,7 @@ var createRuntimeFactory = (deps) => (canvasId, definition, input) => createActi
1221
1232
  ...deps.endpointTimeoutMs === void 0 ? {} : { endpointTimeoutMs: deps.endpointTimeoutMs },
1222
1233
  onNavigate: (effect) => deps.onNavigate(canvasId, effect),
1223
1234
  ...deps.onEndpoint === void 0 ? {} : { onEndpoint: deps.onEndpoint },
1235
+ ...deps.onChain === void 0 ? {} : { onChain: deps.onChain },
1224
1236
  strict: deps.strict,
1225
1237
  ...deps.onError === void 0 ? {} : { onError: deps.onError },
1226
1238
  ...deps.i18n === void 0 ? {} : { i18n: deps.i18n },
@@ -1315,14 +1327,18 @@ var flattenNode = (node, shell) => {
1315
1327
 
1316
1328
  // src/shell/lifecycle-ops.ts
1317
1329
  var createLifecycleOps = (deps) => {
1318
- const { registry, onLifecycleError, onUnmount } = deps;
1330
+ const { registry, onLifecycleError, onUnmount, onChain } = deps;
1331
+ const detached = (hook) => {
1332
+ const chain = hook.catch(onLifecycleError);
1333
+ onChain?.(chain);
1334
+ };
1319
1335
  const unmounted = /* @__PURE__ */ new Set();
1320
1336
  const unmountInstance = (instanceId) => {
1321
1337
  if (unmounted.has(instanceId)) return;
1322
1338
  const runtime = registry.get(instanceId);
1323
1339
  if (runtime === void 0) return;
1324
1340
  unmounted.add(instanceId);
1325
- runtime.unmount().catch(onLifecycleError);
1341
+ detached(runtime.unmount());
1326
1342
  runtime.dispose();
1327
1343
  registry.unregister(instanceId);
1328
1344
  onUnmount?.(instanceId);
@@ -1333,17 +1349,37 @@ var createLifecycleOps = (deps) => {
1333
1349
  if (top === void 0) return;
1334
1350
  if (top.status === "suspended") return;
1335
1351
  const runtime = registry.get(top.id);
1336
- if (runtime !== void 0) runtime.suspend().catch(onLifecycleError);
1352
+ if (runtime !== void 0) detached(runtime.suspend());
1337
1353
  };
1338
1354
  const resumeTop = (canvas) => {
1339
1355
  const top = canvas.peek();
1340
1356
  if (top === void 0) return;
1341
1357
  const runtime = registry.get(top.id);
1342
- if (runtime !== void 0) runtime.resume().catch(onLifecycleError);
1358
+ if (runtime !== void 0) detached(runtime.resume());
1343
1359
  };
1344
1360
  return { unmountInstance, suspendTop, resumeTop };
1345
1361
  };
1346
1362
 
1363
+ // src/shell/chains.ts
1364
+ var createChainCount = () => {
1365
+ let count = 0;
1366
+ const release = () => {
1367
+ count -= 1;
1368
+ };
1369
+ return {
1370
+ hold: (chain) => {
1371
+ count += 1;
1372
+ chain.then(release, release);
1373
+ },
1374
+ inFlight: () => count
1375
+ };
1376
+ };
1377
+ var chainCounts = /* @__PURE__ */ new WeakMap();
1378
+ var rememberChainCount = (shell, count) => {
1379
+ chainCounts.set(shell, count);
1380
+ };
1381
+ var chainsInFlight = (shell) => chainCounts.get(shell)?.inFlight() ?? 0;
1382
+
1347
1383
  // src/shell/runtime-registry.ts
1348
1384
  var createRuntimeRegistry = () => {
1349
1385
  const runtimes = /* @__PURE__ */ new Map();
@@ -1456,9 +1492,11 @@ var createShell = (config) => {
1456
1492
  const origins = /* @__PURE__ */ new Map();
1457
1493
  const births = /* @__PURE__ */ new Map();
1458
1494
  const journal = createJournal(config.historyDepth ?? DEFAULT_HISTORY_DEPTH);
1495
+ const chains = createChainCount();
1459
1496
  const ops = createLifecycleOps({
1460
1497
  registry,
1461
1498
  onLifecycleError: handleLifecycleRejection,
1499
+ onChain: chains.hold,
1462
1500
  onUnmount: (instanceId) => {
1463
1501
  origins.delete(instanceId);
1464
1502
  births.delete(instanceId);
@@ -1644,7 +1682,8 @@ var createShell = (config) => {
1644
1682
  onNavigate: (cid, effect) => navigationHandler(cid, effect),
1645
1683
  // Every endpoint call an action makes flows to telemetry — the shell's one
1646
1684
  // observability surface (state, data, and now endpoints all land here).
1647
- onEndpoint: (event) => telemetry.fireEndpoint(event)
1685
+ onEndpoint: (event) => telemetry.fireEndpoint(event),
1686
+ onChain: chains.hold
1648
1687
  });
1649
1688
  const spawn = (canvasId, definition, input) => {
1650
1689
  const runtime = buildRuntime(canvasId, definition, input);
@@ -1973,6 +2012,7 @@ var createShell = (config) => {
1973
2012
  dispose
1974
2013
  };
1975
2014
  rememberShellRegistry(shell, registry);
2015
+ rememberChainCount(shell, chains);
1976
2016
  for (const cfg of config.canvases) seedCanvas(cfg);
1977
2017
  return shell;
1978
2018
  };
@@ -2023,10 +2063,8 @@ var shellView = (shell) => ({
2023
2063
  };
2024
2064
  }
2025
2065
  });
2026
- var DEFAULT_SETTLE_WAIT_MS = 300;
2027
- var shellSettled = async (shell, options = {}) => {
2066
+ var shellQuietWithin = async (shell, isBusy, options) => {
2028
2067
  const waitMs = options.waitMs ?? DEFAULT_SETTLE_WAIT_MS;
2029
- const mounting = () => Object.values(shell.getState().canvases).some((canvas) => canvas.stack.some((instance) => instance.status === "initializing"));
2030
2068
  let timer;
2031
2069
  const deadline = new Promise((resolve2) => {
2032
2070
  timer = setTimeout(() => resolve2(false), waitMs);
@@ -2034,9 +2072,9 @@ var shellSettled = async (shell, options = {}) => {
2034
2072
  const quiet = (async () => {
2035
2073
  for (; ; ) {
2036
2074
  if (options.stopped?.() === true) return false;
2037
- if (!mounting()) {
2075
+ if (!isBusy()) {
2038
2076
  await new Promise((resolve2) => setTimeout(resolve2, 0));
2039
- if (!mounting()) return true;
2077
+ if (!isBusy()) return true;
2040
2078
  }
2041
2079
  await new Promise((resolve2) => {
2042
2080
  const off = shell.onStateChange(() => {
@@ -2054,7 +2092,11 @@ var shellSettled = async (shell, options = {}) => {
2054
2092
  clearTimeout(timer);
2055
2093
  return settled;
2056
2094
  };
2095
+ var isMounting = (shell) => Object.values(shell.getState().canvases).some((canvas) => canvas.stack.some((instance) => instance.status === "initializing"));
2096
+ var DEFAULT_SETTLE_WAIT_MS = 300;
2097
+ var shellSettled = (shell, options = {}) => shellQuietWithin(shell, () => isMounting(shell), options);
2098
+ var shellIdle = (shell, options = {}) => shellQuietWithin(shell, () => isMounting(shell) || chainsInFlight(shell) > 0, options);
2057
2099
 
2058
- export { DEFAULT_HISTORY_DEPTH, DEFAULT_SETTLE_WAIT_MS, MessageEnvelopeSchema, NovaEventSchema, canvasTreeOf, createIdFactory, createShell, hasVisibleContent, navigatedChannel, reconcileCanvas, scopeDispatch, shellSettled, shellView };
2059
- //# sourceMappingURL=chunk-RYIIIXDX.js.map
2060
- //# sourceMappingURL=chunk-RYIIIXDX.js.map
2100
+ export { DEFAULT_HISTORY_DEPTH, DEFAULT_SETTLE_WAIT_MS, MessageEnvelopeSchema, NovaEventSchema, canvasTreeOf, createIdFactory, createShell, hasVisibleContent, navigatedChannel, reconcileCanvas, scopeDispatch, shellIdle, shellSettled, shellView };
2101
+ //# sourceMappingURL=chunk-DU2VIJAF.js.map
2102
+ //# sourceMappingURL=chunk-DU2VIJAF.js.map