@nanobpm/urban 0.77.4 → 0.78.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/runtime/core/modules/workers.js +28 -0
- package/dist/runtime/core/read-model.d.ts +267 -0
- package/dist/runtime/core/read-model.js +792 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.js +13 -0
- package/package.json +1 -1
- package/src/runtime/core/modules/workers.ts +28 -0
- package/src/runtime/core/read-model.test.ts +943 -0
- package/src/runtime/core/read-model.ts +1025 -0
- package/src/runtime/index.ts +65 -0
package/dist/runtime/index.d.ts
CHANGED
|
@@ -40,6 +40,8 @@ export { applyAmbientLineage, buildLineageTree, deriveLineage, LINEAGE_KEY, LINE
|
|
|
40
40
|
export type { ApplyLineageOptions, LineageAttachment, LineageEdge, LineageEdgeType, LineageEnvelope, LineageNode, LineageTree, } from "./core/lineage.ts";
|
|
41
41
|
export { LINEAGE_ATTACHMENTS_TABLE, LINEAGE_EDGES_TABLE, LINEAGE_SCHEMA_SQL, LineageStore, systemClock as lineageSystemClock, } from "./core/modules/lineage-store.ts";
|
|
42
42
|
export type { Clock as LineageClock, LineageJobLike, LineageStoreOptions, } from "./core/modules/lineage-store.ts";
|
|
43
|
+
export { and, assertReadModelParity, assertSqlIdentifier, caseWhen, col, compileToFn, compileToSqlSelect, defineReadModel, deriveReadModelViewDdl, eq, exists, gt, gte, lit, lt, lte, neq, not, or, pcol, ProjectionRegistry, projectionRegistry, ReadModelRegistry, readModelRegistry, when, } from "./core/read-model.ts";
|
|
44
|
+
export type { AndExpr, BaseRow, CaseExpr, ColExpr, CompareExpr, CompareOp, DerivationFn, ExistsExpr, Expr, Literal, LitExpr, NotExpr, OrExpr, ParityDb, ParityOptions, ParitySample, ProjColExpr, ProjectionRows, ProjectionSource, ReadModel, ReadModelDecl, SqlCompileOptions, WhenClause, } from "./core/read-model.ts";
|
|
43
45
|
export { buildScopeIndex, derivePhase, deriveInstancePhases, furthestReached, rollupLineagePhase, SCOPE_CONTAINERS, } from "./core/phase.ts";
|
|
44
46
|
export type { CrumbKind, CrumbSource, DerivePhaseOptions, FurthestReached, InstancePhase, LineagePhaseRollup, Phase, PhaseCrumb, PhaseGranularity, ProvenanceProgressRow, ScopeElement, ScopeIndex, } from "./core/phase.ts";
|
|
45
47
|
export { deployModels, RESOURCES_DIR } from "./core/modules/deploy.ts";
|
package/dist/runtime/index.js
CHANGED
|
@@ -40,6 +40,19 @@ export { evalCorrelation } from "./core/modules/triggers.js";
|
|
|
40
40
|
// progress (a root request → the instances/PRs/tasks it causes).
|
|
41
41
|
export { applyAmbientLineage, buildLineageTree, deriveLineage, LINEAGE_KEY, LINEAGE_NAMESPACE, mintRootRequestKey, readLineage, writeLineage, } from "./core/lineage.js";
|
|
42
42
|
export { LINEAGE_ATTACHMENTS_TABLE, LINEAGE_EDGES_TABLE, LINEAGE_SCHEMA_SQL, LineageStore, systemClock as lineageSystemClock, } from "./core/modules/lineage-store.js";
|
|
43
|
+
// ─────────────────────────────────────────── Read models ────────────────────────────────────────
|
|
44
|
+
// The declare-once, compile-to-both derived read-model primitive (ADR 0065): a closed expression DSL
|
|
45
|
+
// (`col`/`lit`/comparisons/`and`/`or`/`not`/`caseWhen`/`exists`) declared ONCE via `defineReadModel`,
|
|
46
|
+
// compiled to BOTH a SQLite VIEW select-list (`compileToSqlSelect`) and an in-process TS function
|
|
47
|
+
// (`compileToFn`) from the SAME AST, plus the framework-derived managed VIEW DDL and the parity guard
|
|
48
|
+
// that replaces per-projection hand-written parity tests.
|
|
49
|
+
//
|
|
50
|
+
// SIBLING REGISTRATION POINTS (ADR 0065 rollout — see core/read-model.ts for the full seam docs):
|
|
51
|
+
// • `readModelRegistry` — register a `defineReadModel(...)` result; the boot path (core/modules/
|
|
52
|
+
// workers.ts) applies its managed VIEW. The `writer-source-inversion` task registers here.
|
|
53
|
+
// • `projectionRegistry` — register a canonical engine-truth projection NAME usable in `exists(...)`.
|
|
54
|
+
// The `canonical-projections` task registers `urban_open_user_tasks` / `urban_instance_state`.
|
|
55
|
+
export { and, assertReadModelParity, assertSqlIdentifier, caseWhen, col, compileToFn, compileToSqlSelect, defineReadModel, deriveReadModelViewDdl, eq, exists, gt, gte, lit, lt, lte, neq, not, or, pcol, ProjectionRegistry, projectionRegistry, ReadModelRegistry, readModelRegistry, when, } from "./core/read-model.js";
|
|
43
56
|
// Phase — the framework-level *domain phase* primitive (issue #266): derive "which phase is this
|
|
44
57
|
// instance in?" from the BPMN scope hierarchy + write-provenance (Tier 0, zero declaration), an
|
|
45
58
|
// optional `nano:phase` override (Tier 1), and a lineage rollup for the epic frontier (Tier 2).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nanobpm/urban",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.78.0",
|
|
4
4
|
"description": "Urban: build and run code-first apps on Nano — runtime, derivation toolkit, and CLI in one. Author durable processes with @nanobpm/workflow (defineFlow), a typed datasource, forms, triggers and surfaces from a nano.app.json manifest, on Node or Deno.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -11,6 +11,7 @@ import { runInJobContext } from "../execContext.ts";
|
|
|
11
11
|
import type { JobExecContext } from "../execContext.ts";
|
|
12
12
|
import { readLineage } from "../lineage.ts";
|
|
13
13
|
import { LineageStore } from "./lineage-store.ts";
|
|
14
|
+
import { readModelRegistry } from "../read-model.ts";
|
|
14
15
|
import { defaultScheduler, schedulerClock, type SchedulerDeps } from "./scheduler.ts";
|
|
15
16
|
|
|
16
17
|
/** The subset of the engine SDK the LLM decision-rails need: evaluate a DMN decision,
|
|
@@ -135,6 +136,28 @@ function tryLineageStore(app: AppApi, log: RuntimeContext["host"]["log"]): Linea
|
|
|
135
136
|
}
|
|
136
137
|
}
|
|
137
138
|
|
|
139
|
+
/**
|
|
140
|
+
* Apply every managed read-model VIEW registered in the process-wide `readModelRegistry` to the app's
|
|
141
|
+
* DEFAULT data source (ADR 0065, surface #3). A `defineReadModel(...)` declaration compiles to a
|
|
142
|
+
* managed SQLite VIEW; provisioning it here — the same per-source boot path `tryLineageStore` uses —
|
|
143
|
+
* means an app (or a canonical-projection sidecar) that registers a read model gets its VIEW created
|
|
144
|
+
* for free, with no hand-written migration. The registry is empty until a sibling task registers into
|
|
145
|
+
* it, so this is a silent no-op in the base framework. Absent- and error-safe like lineage: an app
|
|
146
|
+
* with no datasource provisions nothing, and a VIEW-provisioning failure never breaks a worker mount.
|
|
147
|
+
*/
|
|
148
|
+
function tryProvisionReadModelViews(app: AppApi, log: RuntimeContext["host"]["log"]): void {
|
|
149
|
+
if (readModelRegistry.all().length === 0) return;
|
|
150
|
+
if (!app.data.hasDefaultSource()) {
|
|
151
|
+
log("debug", "read-models: no default data source; managed VIEW provisioning skipped");
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
readModelRegistry.ensureViews(app.data.source().db);
|
|
156
|
+
} catch (err) {
|
|
157
|
+
log("warn", "read-models: failed to provision managed VIEWs", { error: String(err) });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
138
161
|
/** Record an activated job's lineage edge, never letting a projection write break the job. */
|
|
139
162
|
function recordJobLineage(store: LineageStore, job: EngineJob, log: RuntimeContext["host"]["log"]): void {
|
|
140
163
|
try {
|
|
@@ -192,6 +215,11 @@ export async function mountWorkers(
|
|
|
192
215
|
// app configures no default data source.
|
|
193
216
|
const lineageStore = tryLineageStore(app, ctx.host.log);
|
|
194
217
|
|
|
218
|
+
// The framework read-model VIEWs (ADR 0065): apply every registered managed VIEW to the app's
|
|
219
|
+
// default data source, the same per-source boot path lineage uses. A no-op until a sibling task
|
|
220
|
+
// registers a read model into `readModelRegistry`.
|
|
221
|
+
tryProvisionReadModelViews(app, ctx.host.log);
|
|
222
|
+
|
|
195
223
|
// Cache module loads so a multi-type handler module is imported once.
|
|
196
224
|
const moduleCache = new Map<string, Record<string, unknown>>();
|
|
197
225
|
const joinRoot = (p: string): string =>
|