|
| 1 | +--- |
| 2 | +'@objectstack/spec': minor |
| 3 | +'@objectstack/service-datasource': minor |
| 4 | +--- |
| 5 | + |
| 6 | +`datasource.config` is now validated against its driver's contract (#4410) |
| 7 | + |
| 8 | +`config` was the one authorable slot on a datasource with no gate at all. The |
| 9 | +schema's own comment claimed "the driver's own `configSchema` is what validates |
| 10 | +it" — nothing did: both bundled driver specs set `configSchema: {}`, no code read |
| 11 | +the field, and the per-driver zod schemas were not even exported from the |
| 12 | +package. So `config: { hostname: 'db.internal' }` (the key is `host`) was |
| 13 | +accepted in silence and the datasource connected to `localhost` while the parse, |
| 14 | +the save and the connection probe all reported success. |
| 15 | + |
| 16 | +`DatasourceSchema` now parses `config` — and each `readReplicas` entry — against |
| 17 | +the contract for the declared driver, and `DatasourceAdminService` |
| 18 | +(create/update/test, the Setup wizard's path) applies the same check. Both read |
| 19 | +one registry in `@objectstack/spec/data`, which also projects each contract to |
| 20 | +JSON Schema for `DriverDefinitionSchema.configSchema` and the Studio connection |
| 21 | +form, so the form offers exactly the fields the validator accepts. |
| 22 | + |
| 23 | +New exports from `@objectstack/spec/data`: `PostgresConfigSchema`, |
| 24 | +`MysqlConfigSchema`, `SqliteConfigSchema`, `SqliteWasmConfigSchema`, |
| 25 | +`MongoConfigSchema`, `MemoryConfigSchema`, plus `resolveDriverId`, |
| 26 | +`getDriverConfigSchema`, `getDriverConfigJsonSchemaById` and |
| 27 | +`validateDriverConfig`. A driver the platform ships no contract for (a plugin's |
| 28 | +`com.vendor.snowflake`) keeps an unvalidated `config`. |
| 29 | + |
| 30 | +**Migration.** A config that was silently ignored now fails with the correction |
| 31 | +in the message. The renames: |
| 32 | + |
| 33 | +| Wrote | Write instead | Driver | |
| 34 | +| --- | --- | --- | |
| 35 | +| `user` | `username` | postgres, mysql, mongo | |
| 36 | +| `connectionString` / `dsn` | `url` | postgres, mysql, mongo | |
| 37 | +| `uri` | `url` | mongo | |
| 38 | +| `file` / `path` / `database` | `filename` | sqlite, sqlite-wasm | |
| 39 | +| `hostname` | `host` | postgres, mysql, mongo | |
| 40 | +| `searchPath` | `schema` | postgres | |
| 41 | + |
| 42 | +And the relocations — keys that were never driver config: |
| 43 | + |
| 44 | +| Wrote in `config` | Write instead | |
| 45 | +| --- | --- | |
| 46 | +| `min` / `max` / `idleTimeoutMillis` / `connectionTimeoutMillis` | the datasource's own `pool` block | |
| 47 | +| `schemaMode` | next to `driver`, on the datasource | |
| 48 | +| `readOnly` | `capabilities: { readOnly: true }` | |
| 49 | +| `ssl: { ca, cert, key, rejectUnauthorized }` | the datasource's own `ssl` block — inside `config`, `ssl` is the on/off boolean shorthand | |
| 50 | + |
| 51 | +Two memory-driver keys are **removed**: `indexes` and `maxRecordsPerObject`. |
| 52 | +`InMemoryDriverConfig` has no field for either — the driver keeps no indexes and |
| 53 | +evicts nothing — so both were inert. Drop them; for real indexing use a driver |
| 54 | +that indexes. |
| 55 | + |
| 56 | +A postgres, mysql or mongo datasource must now name a connection target |
| 57 | +(`database`, or a `url` that carries it). An empty `config` used to mean "the |
| 58 | +client's own localhost default", which is the same defect in its most complete |
| 59 | +form. |
| 60 | + |
| 61 | +**Also fixed, because the contract can only be enforced where it is honoured.** |
| 62 | +These keys were declared and read by nothing; they now reach the driver: |
| 63 | + |
| 64 | +- `datasource.pool` is honoured by every SQL driver (it was declared, carried |
| 65 | + into the connection spec, then overwritten with a hardcoded `{ min: 0, max: 5 }`), |
| 66 | + and maps onto the Mongo client's `minPoolSize` / `maxPoolSize`. |
| 67 | +- `datasource.schemaMode` reaches the driver. It was dropped between the |
| 68 | + datasource record and the connection spec, so a `schemaMode: 'external'` |
| 69 | + database — one ObjectStack must never run DDL against — was constructed as |
| 70 | + `managed`. |
| 71 | +- `datasource.ssl` reaches the SQL clients, certificates and all. It stopped at |
| 72 | + the record — nothing put it on the connection spec — so a TLS block configured |
| 73 | + nothing, which is exactly what its own schema comment warns about ("a TLS |
| 74 | + setting that never took effect looked identical to one that did"). |
| 75 | +- postgres `schema` (knex `searchPath`), `applicationName` and `statementTimeout`. |
| 76 | +- mongo `password`, `authSource` and `options`. A mongo datasource carrying a |
| 77 | + `config.password` previously composed its URL with an **empty** password. |
0 commit comments