|
| 1 | +--- |
| 2 | +"@objectstack/service-datasource": minor |
| 3 | +"@objectstack/runtime": minor |
| 4 | +"@objectstack/spec": minor |
| 5 | +--- |
| 6 | + |
| 7 | +feat(datasource): auto-connect declared external datasources (ADR-0062 Phase 1, D1/D2/D5) |
| 8 | + |
| 9 | +A declared external datasource is now connected to a live ObjectQL driver and its |
| 10 | +federated objects are queryable **with zero app code** — no `onEnable` driver |
| 11 | +wiring. Implements ADR-0062 Phase 1. |
| 12 | + |
| 13 | +- **D1 — one connect path.** New `DatasourceConnectionService` in |
| 14 | + `@objectstack/service-datasource` owns the single "definition → live driver" |
| 15 | + path: build via the injected driver factory → resolve `external.credentialsRef` |
| 16 | + via the `SecretBinder` → connect → `engine.registerDriver` under the datasource |
| 17 | + name → register the datasource def → sync each bound federated object's read |
| 18 | + metadata (DDL-free). Both origins converge on it: the runtime-admin |
| 19 | + `registerPool` now delegates here, and `AppPlugin` auto-connects code-defined |
| 20 | + datasources. Exposed as the `'datasource-connection'` kernel service. |
| 21 | +- **D2 — opt-in-safe gate.** A declared datasource auto-connects only when it is |
| 22 | + `external`, an object **explicitly** binds to it via `object.datasource`, or it |
| 23 | + sets the new `autoConnect: true` flag. A managed datasource that nothing |
| 24 | + explicitly binds (incl. ones referenced only by a `datasourceMapping` rule, e.g. |
| 25 | + `examples/app-crm`'s `:memory:` datasources) stays metadata-only — existing apps |
| 26 | + are byte-for-byte unchanged. See the ADR-0062 D2 implementation note. |
| 27 | +- **D5 — lifecycle, ordering & policy.** Connect happens in `AppPlugin.start()` |
| 28 | + (before the `kernel:ready` validation gate, relying on the kernel's |
| 29 | + init-all-then-start-all ordering). Fail-fast for a declared `external` datasource |
| 30 | + with `validation.onMismatch: 'fail'`; degrade-with-warning otherwise (and always |
| 31 | + for runtime-admin/rehydrate, so a UI action or replica blip never bricks the |
| 32 | + server). Adds a host-injectable `DatasourceConnectPolicy` (open-core default |
| 33 | + allows; a multi-tenant host binds a stricter fail-closed policy for egress |
| 34 | + isolation) consulted before every connect — one connect path, no cloud fork. |
| 35 | + |
| 36 | +Adds `datasource.autoConnect` to the spec. The legacy `onEnable` + |
| 37 | +`ctx.drivers.register` bridge remains supported as an escape hatch (idempotent vs. |
| 38 | +auto-connect). No behavior change for managed apps. |
0 commit comments