Skip to content

Commit f085c3c

Browse files
committed
fix(service-datasource)!: refuse creating a datasource named after a route literal
`GET /datasources/drivers` (the driver catalog) is mounted before `GET /datasources/:name`, so a runtime datasource named `drivers` was created but its detail read never reached. assertValidName now refuses every literal the admin registrar mounts beside a same-method `/:name` route, from the one list the registrar mounts the literal from; `default` is unchanged and `test` stays creatable (no `POST /:name` sibling). Claude-Session: https://claude.ai/code/session_01ADHkmPjMhxWBYAk48z4Mam Co-authored-by: Claude <noreply@anthropic.com>
1 parent 41bae08 commit f085c3c

4 files changed

Lines changed: 32 additions & 2 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@objectstack/service-datasource': patch
3+
---
4+
5+
fix(service-datasource)!: creating a runtime datasource refuses `drivers`, the name the driver-catalog route answers, so a datasource is never created that its edit form cannot load (#29164)
6+
7+
Clause-②: no (narrowing) — `POST /api/v1/datasources` with `name: 'drivers'`, which answered 201 before, now answers 400 `DATASOURCE_ADMIN_ERROR` naming the reserved name. Nothing is widened.
8+
Metadata-protocol: none
9+
10+
<!-- adr-0087: not-required (no-migration-prescription) No schema key, export or stored shape changes: the runtime datasource-admin create door refuses one more name, the way it already refused `default`. A stored row of that name is not rewritten or refused, so there is nothing for a migration to rewrite and no tombstone. -->
11+
12+
**BREAKING** accept-set narrowing at the datasource-admin create door (`@objectstack/service-datasource`).
13+
14+
- **Before.** `GET /api/v1/datasources/drivers` is the driver catalog, mounted ahead of `GET /api/v1/datasources/:name`. A runtime datasource named `drivers` was created and listed, but its detail read always answered the catalog, so Setup → Datasources could never open its edit form.
15+
- **Now.** Create refuses every literal path segment the admin routes mount beside a same-method `/datasources/:name` route; today that is `drivers` alone. The refusal is the same 400 `DATASOURCE_ADMIN_ERROR` that `default` already answers. `test` stays creatable: `POST /datasources/test` (the unsaved-draft probe) sits beside no `POST /datasources/:name`, so a datasource named `test` keeps every by-name door.
16+
- **Stored rows.** A `drivers` row created before this release is not refused or rewritten. It stays listed, patchable, removable and probe-able by name; its detail read still answers the catalog.
17+
18+
**The remedy.** Create the datasource under another name. For a stored `drivers` row, create the same connection under another name, move the objects bound to `drivers` onto it, then remove `drivers` (`DELETE /api/v1/datasources/drivers`, which refuses while any object is still bound).

‎packages/services/service-datasource/src/__tests__/datasource-route-reserved-names.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ describe('a stored `drivers` row written before the refusal', () => {
201201
expect(records.find((r) => r.name === 'drivers')?.label).toBe('Old drivers');
202202

203203
const removed = await call(`${ROOT}/drivers`, 'DELETE');
204-
expect(removed.status).toBe(200);
204+
expect(removed.ok).toBe(true);
205205
expect(records.some((r) => r.name === 'drivers')).toBe(false);
206206
});
207207
});

‎packages/services/service-datasource/src/admin-routes.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import type { IAuthService, IDataEngine, IHttpServer } from '@objectstack/spec/c
4545
// The declared envelope is written in ONE place for the whole platform (#3973).
4646
import { inProcessSessionReadInput, sendOk, sendError } from '@objectstack/types';
4747
import { DRIVER_CATALOG } from './driver-catalog.js';
48+
import { DRIVER_CATALOG_SEGMENT } from './datasource-route-reserved-names.js';
4849
// [#27618] The package's one "no such datasource" refusal: GET answers an
4950
// unknown name in its words, as every other by-name door does.
5051
import { datasourceNotFoundError } from './datasource-admin-service.js';
@@ -692,7 +693,7 @@ export function registerDatasourceAdminRoutes(
692693
// Catalog of connection drivers + their JSON-Schema config (drives the
693694
// Studio connection form). Static metadata — no service dependency, so it
694695
// is always available even before any datasource-admin service is wired.
695-
server.get(`${root}/drivers`, async (req: any, res: any) => {
696+
server.get(`${root}/${DRIVER_CATALOG_SEGMENT}`, async (req: any, res: any) => {
696697
if (await requireDatasourceAdmin(req, res)) return;
697698
sendOk(res, { drivers: DRIVER_CATALOG });
698699
});

‎packages/services/service-datasource/src/datasource-admin-service.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { datasourceConnectivityChanged } from './datasource-connectivity-change.
4343
import { redactDatasourceConfig, restoreRedactedConfig } from './datasource-config-redaction.js';
4444
import { planCredentialMigration } from './datasource-credential-migration.js';
4545
import { borrowedConnectorOf } from './datasource-connector-credential.js';
46+
import { ROUTE_SHADOWED_DATASOURCE_NAMES } from './datasource-route-reserved-names.js';
4647
import type {
4748
IDatasourceAdminService,
4849
DatasourceDraft,
@@ -1385,6 +1386,16 @@ export class DatasourceAdminService implements IDatasourceAdminService {
13851386
throw new Error(
13861387
`Datasource name 'default' is reserved for the host's primary datasource. Pick another name.`,
13871388
);
1389+
} // Route-shadowed names (#29164): a literal the admin registrar mounts beside
1390+
// a same-method `/datasources/:name` route captures that path first, so a
1391+
// datasource of that name could never be read through its by-name door
1392+
// (`GET /datasources/drivers` is the driver catalog, not the edit form's
1393+
// detail read). The list is the one the registrar mounts from.
1394+
if (ROUTE_SHADOWED_DATASOURCE_NAMES.includes(name)) {
1395+
throw new Error(
1396+
`Datasource name '${name}' is reserved: the datasource admin API serves its own route at `
1397+
+ `'/datasources/${name}', so a datasource of that name could never be read by name. Pick another name.`,
1398+
);
13881399
}
13891400
}
13901401

0 commit comments

Comments
 (0)