@nanobpm/urban 0.79.0 → 0.81.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.
Files changed (52) hide show
  1. package/dist/runtime/core/manifest.d.ts +44 -11
  2. package/dist/runtime/core/modules/cancel.d.ts +13 -8
  3. package/dist/runtime/core/modules/cancel.js +40 -21
  4. package/dist/runtime/core/modules/datasource.js +7 -4
  5. package/dist/runtime/core/modules/formjs.gen.d.ts +1 -0
  6. package/dist/runtime/core/modules/formjs.gen.js +5 -0
  7. package/dist/runtime/core/modules/forms.d.ts +22 -0
  8. package/dist/runtime/core/modules/forms.js +59 -0
  9. package/dist/runtime/core/modules/gateway.js +5 -4
  10. package/dist/runtime/core/modules/instance-status-read-model.d.ts +56 -0
  11. package/dist/runtime/core/modules/instance-status-read-model.js +127 -0
  12. package/dist/runtime/core/modules/instance-tracking.d.ts +47 -19
  13. package/dist/runtime/core/modules/instance-tracking.js +451 -123
  14. package/dist/runtime/core/modules/open-user-tasks-store.d.ts +5 -0
  15. package/dist/runtime/core/modules/open-user-tasks-store.js +8 -0
  16. package/dist/runtime/core/modules/pages.js +42 -4
  17. package/dist/runtime/core/modules/runtime.gen.js +1 -1
  18. package/dist/runtime/core/modules/surfaces.js +18 -124
  19. package/dist/runtime/core/read-model.d.ts +28 -0
  20. package/dist/runtime/core/read-model.js +44 -4
  21. package/dist/runtime/core/validate.js +192 -0
  22. package/dist/runtime/index.d.ts +2 -1
  23. package/dist/runtime/index.js +5 -0
  24. package/package.json +1 -1
  25. package/src/runtime/browser/fake-dom.test-utils.ts +114 -0
  26. package/src/runtime/browser/formjs.browser.js +192 -0
  27. package/src/runtime/browser/formjs.browser.test.ts +136 -0
  28. package/src/runtime/browser/runtime.browser.js +101 -1
  29. package/src/runtime/browser/runtime.engineform.test.ts +158 -0
  30. package/src/runtime/core/manifest.ts +44 -11
  31. package/src/runtime/core/modules/cancel.test.ts +112 -38
  32. package/src/runtime/core/modules/cancel.ts +42 -22
  33. package/src/runtime/core/modules/datasource.ts +7 -4
  34. package/src/runtime/core/modules/formjs.gen.ts +6 -0
  35. package/src/runtime/core/modules/forms.test.ts +122 -0
  36. package/src/runtime/core/modules/forms.ts +67 -0
  37. package/src/runtime/core/modules/gateway.ts +7 -4
  38. package/src/runtime/core/modules/gen-artifacts.test.ts +41 -0
  39. package/src/runtime/core/modules/instance-status-read-model.ts +156 -0
  40. package/src/runtime/core/modules/instance-tracking.test.ts +589 -60
  41. package/src/runtime/core/modules/instance-tracking.ts +469 -126
  42. package/src/runtime/core/modules/open-user-tasks-store.test.ts +11 -0
  43. package/src/runtime/core/modules/open-user-tasks-store.ts +11 -0
  44. package/src/runtime/core/modules/pages.test.ts +99 -0
  45. package/src/runtime/core/modules/pages.ts +44 -5
  46. package/src/runtime/core/modules/runtime.gen.ts +1 -1
  47. package/src/runtime/core/modules/surfaces.ts +19 -121
  48. package/src/runtime/core/read-model.test.ts +69 -0
  49. package/src/runtime/core/read-model.ts +43 -4
  50. package/src/runtime/core/validate.test.ts +341 -0
  51. package/src/runtime/core/validate.ts +188 -0
  52. package/src/runtime/index.ts +15 -0
@@ -1,5 +1,7 @@
1
1
  import type { AppApi, Mounted, RuntimeContext } from "../context.ts";
2
- import { type InstanceTracking } from "../manifest.ts";
2
+ import type { UserTaskSummary } from "../host.ts";
3
+ import { InstanceStateStore } from "./instance-state-store.ts";
4
+ import { OpenUserTasksStore } from "./open-user-tasks-store.ts";
3
5
  import { type SchedulerDeps } from "./scheduler.ts";
4
6
  /** Default poll interval when a binding does not set `pollMs`. */
5
7
  export declare const DEFAULT_INSTANCE_TRACKING_POLL_MS = 15000;
@@ -13,24 +15,50 @@ export interface InstanceTrackingHandle extends Mounted {
13
15
  /** `table.keyField` labels of the armed bindings, for `inspect()`. */
14
16
  readonly bindings: string[];
15
17
  }
16
- /** Apply a binding's `onTerminated.set` patch to the single row keyed by `processInstanceKey`.
17
- * Only the binding whose table owns that key has a matching row, so callers can fan this over
18
- * every binding and let the no-match ones be no-ops. Returns rows changed. The single place that
19
- * writes the terminal patch (and logs the reconcile): both the poll reconciler below (`reconcileOnce`,
20
- * once per TERMINATED key it discovers) and the cancel primitive (immediately when it terminates an
21
- * instance) route through here, so the two can never drift on the patch or the log. */
22
- export declare function reconcileTerminatedKey(api: Pick<AppApi, "data" | "log">, bindings: InstanceTracking[], processInstanceKey: string): Promise<number>;
23
- /** Apply a binding's `onWaitingHuman.set` patch to the single row keyed by `processInstanceKey`
24
- * — the wait-on-human twin of {@link reconcileTerminatedKey} (issue #355). The caller establishes
25
- * the precondition (the instance is non-terminated and has an open user task); this is the single
26
- * place that writes `onWaitingHuman.set` and logs the reconcile. Bindings without an
27
- * `onWaitingHuman` edge are no-ops, so callers can fan this over every binding. It skips the write
28
- * when the row already carries the patch (quiet-idempotent — a long-parked instance is re-polled
29
- * every tick and must not re-log). Returns rows changed. */
30
- export declare function reconcileWaitingHumanKey(api: Pick<AppApi, "data" | "log">, bindings: InstanceTracking[], processInstanceKey: string): Promise<number>;
31
18
  /**
32
- * Mount the `instanceTracking` reconciler: arm one poll loop per binding. Each loop selects
33
- * the active rows, asks the engine which of their instances are terminated, and applies the
34
- * declared patch. `stop()` cancels every armed timer.
19
+ * The canonical engine-truth projections the reconciler feeds as a SOURCE (ADR 0065, the writer→source
20
+ * inversion): the instance-state projection (feeds the terminal edge) and the open-user-tasks projection
21
+ * (feeds the wait-on-human edge). Both are sidecars on the app's own default data source; the derived
22
+ * status read model `EXISTS`-derives its edges from them.
23
+ */
24
+ export interface InstanceProjections {
25
+ readonly instanceState: InstanceStateStore;
26
+ readonly openUserTasks: OpenUserTasksStore;
27
+ }
28
+ /**
29
+ * Construct the canonical projection stores over the app's default data source and ensure their schema
30
+ * (idempotent), exactly the per-source boot path `tryLineageStore` / `tryProvisionCanonicalProjections`
31
+ * use. Absent-safe: with no default source there is nothing to feed, so return `undefined` at `debug`
32
+ * (the expected sidecar-absent case). A genuine provisioning fault (missing named source, schema error)
33
+ * degrades to `undefined` at `warn` rather than breaking the mount — a projection feed must never break
34
+ * a job.
35
+ */
36
+ export declare function tryInstanceProjections(api: Pick<AppApi, "data" | "log">): InstanceProjections | undefined;
37
+ /** Record engine-truth that an instance is TERMINATED into the canonical `urban_instance_state`
38
+ * projection and retire its open-user-task rows — the writer→source replacement for the old
39
+ * `onTerminated.set` `table.update` patch (ADR 0065; #439-L1 / #318). The derived terminal status edge
40
+ * (a VIEW / function over the projection) reflects this on the next read, so there is no stored-derived
41
+ * column to tear from its inputs (nano-workforce#422). This is the SINGLE place that records the terminal
42
+ * source: both the poll reconciler (`reconcileOnce`, once per TERMINATED key it discovers) and the cancel
43
+ * primitive (`cancel.ts`, immediately when it terminates an instance) route through it, so the two can
44
+ * never drift. Absent-safe (no projections / blank key ⇒ 0) and never throws through — a projection write
45
+ * must never break a job or a cancel. Returns 1 when it recorded the terminal source, else 0. */
46
+ export declare function reconcileTerminatedKey(api: Pick<AppApi, "log">, projections: InstanceProjections | undefined, processInstanceKey: string): number;
47
+ /** Feed an instance's CURRENT open-user-task set into the canonical `urban_open_user_tasks` projection
48
+ * — the wait-on-human twin of {@link reconcileTerminatedKey} (issue #355). `syncInstance` is
49
+ * authoritative-per-instance: it inserts the still-open tasks and RETIRES any previously-projected task
50
+ * that is no longer open, so an answered/closed escalation makes the derived wait-on-human edge go false
51
+ * on the next read by construction (nano-workforce#422 — no stored column to leave stale). Passing an
52
+ * EMPTY `openTasks` clears the instance, which is exactly the answered-escalation transition; callers
53
+ * MUST therefore feed every probed non-terminated key, including those with no open task, or a retired
54
+ * task would linger and the edge would tear. Absent-safe (no projections / blank key ⇒ 0) and never
55
+ * throws through. Returns 1 when it fed the projection, else 0. */
56
+ export declare function reconcileWaitingHumanKey(api: Pick<AppApi, "log">, projections: InstanceProjections | undefined, processInstanceKey: string, openTasks: readonly UserTaskSummary[]): number;
57
+ /**
58
+ * Mount the `instanceTracking` reconciler: provision each binding's derived read-model VIEW, construct
59
+ * the canonical projection stores once, and arm one poll loop per binding. Each loop selects the active
60
+ * rows, asks the engine which of their instances are terminated / parked on a human, and FEEDS that
61
+ * engine truth into the canonical projections (never a base-row write — the status edges are DERIVED;
62
+ * ADR 0065). `stop()` cancels every armed timer.
35
63
  */
36
64
  export declare function mountInstanceTracking(ctx: RuntimeContext, api: AppApi, sched?: SchedulerDeps): InstanceTrackingHandle;