diff --git a/.changeset/30147-get-discovery-facet.md b/.changeset/30147-get-discovery-facet.md new file mode 100644 index 00000000000..4268e3b131f --- /dev/null +++ b/.changeset/30147-get-discovery-facet.md @@ -0,0 +1,11 @@ +--- +'@objectstack/metadata-protocol': patch +--- + +refactor(metadata-protocol): `getDiscovery` hands its body to its facet + +Clause-②: no +Metadata-protocol: none + +- `ObjectStackProtocolImplementation#getDiscovery` keeps its signature and return type on the class and delegates in one line to `ProtocolDiscoveryAndBasesFacet.getDiscovery`, which holds the body, moved unchanged except for the search probe: the class reads `this.searchAll` on the instance and hands it in, so `capabilities.search` still answers whether this protocol instance serves search. No behaviour changes and nothing to do on upgrade. +- The published `index.d.ts` and `index.d.cts` carry the same public surface. diff --git a/packages/metadata-protocol/src/protocol-discovery-and-bases.ts b/packages/metadata-protocol/src/protocol-discovery-and-bases.ts index 4ad531afa4a..60b999aee31 100644 --- a/packages/metadata-protocol/src/protocol-discovery-and-bases.ts +++ b/packages/metadata-protocol/src/protocol-discovery-and-bases.ts @@ -3,7 +3,7 @@ /** * [#29985 codemod] The "Discovery, types, diagnostics, packaged bases, * credential carry-forward" facet of `ObjectStackProtocolImplementation`: the - * bodies of `getProjectId`, `getMetaTypes`, + * bodies of `getProjectId`, `getDiscovery`, `getMetaTypes`, * `rethrowUnlessMetadataStoreUnprovisioned`, `getPackagedObjectBase`, * `getPackagedDashboardBase`, `getPackagedViewBase`, `getPackagedReportBase`, * `packagedArtifactBase`, `objectRegistrationRefusal`, @@ -37,7 +37,7 @@ import type { SysMetadataRepository } from './sys-metadata-repository.js'; import { PLURAL_TO_SINGULAR, SINGULAR_TO_PLURAL, unrecognisedMetaTypeRefusal } from '@objectstack/spec/shared'; import type { TranslationBundle } from '@objectstack/spec/system'; -import { readAuthoredTranslationLayer } from '@objectstack/core'; +import { engineCanRollBack, readAuthoredTranslationLayer } from '@objectstack/core'; import { restoreTranslatedEchoes } from './protocol-translated-echo.js'; import type { RestoredTranslatedSlot } from './protocol-translated-echo.js'; import { @@ -59,6 +59,20 @@ import { import type { SaveMetaItemRequest } from './protocol-door-requests.js'; import { isMissingTableError } from '@objectstack/metadata/errors'; import { metadataReadFailureError } from './protocol-client-failures.js'; +import { + CHANNEL_SURFACE_SLOTS, + isSubscribableChannel, + readAuthFamilies, + readChannelRoute, + readServiceSelfInfo, + resolveDiscoveryEnvironment, +} from '@objectstack/spec/api'; +import type { ApiRoutes, CapabilityDescriptor, ServiceInfo, WellKnownCapabilities } from '@objectstack/spec/api'; +// [commit 376c70f98] The derived `version` this facet's `getDiscovery()` serves as the +// `DiscoverySchema` "System Identity" field — never a literal again. +import { resolveDiscoveryVersion } from './discovery-version.js'; +import { CORE_SERVICE_PROVIDER, serviceUnavailableMessage } from '@objectstack/spec/system'; +import { SERVICE_CONFIG } from './protocol-discovery-services.js'; import type { ProtocolHost } from './protocol-host.js'; import { servedOverrideBaseOf } from './served-override.js'; import type { ObjectStackProtocolImplementation } from './protocol.js'; @@ -76,6 +90,521 @@ export class ProtocolDiscoveryAndBasesFacet { return host.environmentId; } + /** The body of `ObjectStackProtocolImplementation#getDiscovery`; the method's docblock there is its contract. */ + static async getDiscovery(host: Pick, searchAllOnInstance: unknown): Promise<{ + authFamilies?: { + admin: boolean; + } | undefined; + version: string; + name: string; + /** @deprecated Use `name`. Removed in protocol 18 (#4828). */ + apiName: string; + environment: "sandbox" | "production" | "development"; + routes: { + data: string; + metadata: string; + discovery?: string | undefined; + ui?: string | undefined; + auth?: string | undefined; + automation?: string | undefined; + storage?: string | undefined; + analytics?: string | undefined; + packages?: string | undefined; + datasources?: string | undefined; + email?: string | undefined; + approvals?: string | undefined; + realtime?: string | undefined; + notifications?: string | undefined; + ai?: string | undefined; + i18n?: string | undefined; + mcp?: string | undefined; + }; + locale: { + default: string; + supported: string[]; + timezone: string; + }; + services: Record; + capabilities: Record<"ai" | "automation" | "cron" | "analytics" | "files" | "search" | "export" | "i18n" | "notifications" | "comments" | "chunkedUpload" | "transactionalBatch" | "websockets", { + enabled: boolean; + features?: Record | undefined; + description?: string | undefined; + }>; + }> { + // Get registered services from kernel if available + const registeredServices = host.getServicesRegistry ? host.getServicesRegistry() : new Map(); + + // Build dynamic service info with proper typing. Analytics is NOT in + // this kernel-provided block: since the degraded ObjectQL fallback was + // retired (#3891) it is an ordinary optional service, computed from the + // registry via SERVICE_CONFIG below — absent means `unavailable`, and + // no route is advertised (the pre-#2462 hardcode here is exactly what + // the fallback was invented to make true). + // + // [#4089] The `metadata` slot is reported from whatever fills it, not + // hardcoded `available`. The kernel auto-registers `createMemoryMetadata` + // when no MetadataPlugin is present, and plugin-dev registers its own + // in-memory registry; both self-describe as `degraded` (D12), and + // hardcoding `available` here overstated them as exactly equivalent to a + // sys_metadata-backed registry. Absent or unmarked ⇒ `available`, which + // is what the real MetadataPlugin (carrying no marker) reports. + // + // This is also where the two builders stopped disagreeing: the runtime + // dispatcher hardcoded the opposite verdict for the same slot + // (`degraded` + "DB persistence pending"), so one host called a persisted + // registry degraded while the other called an in-memory one available. + // Both now compute it, and `handlerReady: true` is stated on both sides: + // `/api/v1/meta` is served by the protocol, not by this service, so it is + // mounted whichever implementation occupies the slot. + const metadataSelf = readServiceSelfInfo(registeredServices.get('metadata')); + + // [#4130] `data` was the last self-judging entry in this block. Same + // reasoning, one degree weaker: its hardcoded `available` is currently + // true, but only because ObjectQL is the slot's sole producer and + // plugin-dev (whose `data` stub declares `stub`) always loads + // ObjectQLPlugin as a child. That is a load-order convention in another + // package, not something this builder verifies — so verify it here. + // Unmarked implementation ⇒ `available` + `handlerReady: true`, i.e. + // exactly what the hardcode said, now derived rather than asserted. + const dataSelf = readServiceSelfInfo(registeredServices.get('data')); + + const services: Record = { + // --- Kernel-provided (objectql is an example kernel implementation) --- + metadata: { + enabled: true, + status: metadataSelf?.status ?? ('available' as const), + handlerReady: true, + route: '/api/v1/meta', + provider: 'objectql', + ...(metadataSelf?.message ? { message: metadataSelf.message } : {}), + }, + data: { + enabled: true, + status: dataSelf?.status ?? ('available' as const), + handlerReady: dataSelf?.handlerReady ?? true, + route: '/api/v1/data', + provider: 'objectql', + ...(dataSelf?.message ? { message: dataSelf.message } : {}), + }, + }; + + // [#4000, #4058] The dispatcher answers a self-declared non-handler in + // one of ITS domains' slots with the same 404/501 an empty slot gets + // (`isServiceServeable`, runtime/src/service-serveable.ts), so this + // builder must not advertise a route for one — that would be the + // `declared ≠ enforced` gap discovery exists to close. + // + // Scoped to the dispatcher-owned domains on purpose. For the other + // entries in SERVICE_CONFIG the route belongs to the plugin that + // registers the service (service-storage's own `/api/v1/storage` + // routes, plugin-search, plugin-graphql, …) rather than to a dispatcher + // domain, so `handlerReady` there says nothing about whether THAT route + // is mounted, and suppressing it would be a guess. `storage` stays + // listed as the one entry with no dispatcher domain behind it — #4087 + // retired the `/storage` bridge — because for that slot `handlerReady` + // is not a proxy for anything, it is the fact itself: an occupant that + // mounts no HTTP surface must not have `/api/v1/storage` advertised on + // its behalf. When service-storage is installed it registers a real + // (unmarked) service and mounts the routes, so the entry never fires. + const DISPATCHER_GATED_SERVICES = new Set([ + 'analytics', 'automation', 'notification', 'ai', 'i18n', 'storage', + ]); + const unserveable = (serviceName: string) => + DISPATCHER_GATED_SERVICES.has(serviceName) + && readServiceSelfInfo(registeredServices.get(serviceName))?.handlerReady === false; + const advertisedRoute = (serviceName: string, route?: string) => + unserveable(serviceName) ? undefined : route; + + // Check which services are actually registered + for (const [serviceName, config] of Object.entries(SERVICE_CONFIG)) { + if (registeredServices.has(serviceName)) { + // Registered — but honor a stub/dev/fallback self-description + // instead of blindly reporting 'available' (ADR-0076 D12). + const self = readServiceSelfInfo(registeredServices.get(serviceName)); + // [#14646] Channel slots answer a different question than every + // other row here. `enabled` elsewhere means "the slot is + // filled"; for a slot whose advertised capability IS a + // subscribable channel that reading is what let `/discovery` + // report `enabled: true` beside "no HTTP/WS realtime surface is + // mounted" — both true, one field, two meanings. Here `enabled` + // is the shared predicate itself, evaluated on the very entry a + // consumer reads, so the field and the definition are one + // computation. The route comes from the occupant because no + // builder in the open framework mounts a realtime transport. + if (CHANNEL_SURFACE_SLOTS.has(serviceName)) { + const channelRoute = readChannelRoute(registeredServices.get(serviceName)); + const handlerReady = channelRoute !== undefined; + services[serviceName] = { + enabled: isSubscribableChannel({ handlerReady, route: channelRoute }), + // A mounted channel makes an unmarked occupant plainly + // `available`; without one the slot keeps the reduced + // status its row declares (`degraded` for realtime — the + // capability it advertises IS the missing surface). + status: self?.status + ?? (handlerReady + ? ('available' as const) + : (config.noHttpSurface?.statusWhenUnmarked ?? ('available' as const))), + route: channelRoute, + provider: CORE_SERVICE_PROVIDER[serviceName] ?? undefined, + handlerReady, + // The "no surface" sentence is only true while there is + // no surface; a mounted channel drops it and keeps only + // whatever the occupant says about itself. + ...(self?.message + ? { message: self.message } + : !handlerReady && config.noHttpSurface + ? { message: config.noHttpSurface.message } + : {}), + }; + continue; + } + // No HTTP surface at all: the handler can never be ready, and + // the entry's own `noHttpSurface` declaration says whether that + // also degrades the slot (realtime) or not (cache/queue/job — + // in-process contracts, #4318). + const noHttpSurface = !config.route; + services[serviceName] = { + enabled: true, + status: self?.status ?? (config.noHttpSurface?.statusWhenUnmarked ?? ('available' as const)), + route: advertisedRoute(serviceName, config.route), + provider: CORE_SERVICE_PROVIDER[serviceName] ?? undefined, + ...(noHttpSurface || self?.handlerReady !== undefined + ? { handlerReady: noHttpSurface ? false : self?.handlerReady } + : {}), + ...(self?.message + ? { message: self.message } + : config.noHttpSurface + ? { message: config.noHttpSurface.message } + : {}), + }; + } else { + // Service is not registered + services[serviceName] = { + enabled: false, + status: 'unavailable' as const, + message: serviceUnavailableMessage(serviceName), + }; + } + } + + // [#9683] `file-storage` is the deprecated v17 alias of the `storage` + // slot, and it is a key existing consumers really read off this + // document (objectui's console endpoint catalog is keyed by it). The + // registry resolves both names to the same instance, so discovery + // mirrors the canonical row VERBATIM under the alias key until the + // alias retires at the next major — dropping the key would be the + // silent inside-a-major break the ruling forbids. Deliberately a + // byte-equal copy, not a second opinion: one slot, two spellings. + services['file-storage'] = { ...services['storage'] }; + + // Build routes from services — a flat convenience map for client routing + const serviceToRouteKey: Record = { + analytics: 'analytics', + auth: 'auth', + automation: 'automation', + ui: 'ui', + realtime: 'realtime', + notification: 'notifications', + ai: 'ai', + i18n: 'i18n', + storage: 'storage', + // [#6633] The package-management surface. `package` is NOT a + // CoreServiceName slot, so it must not enter SERVICE_CONFIG — a + // non-slot row there is the shape of the retired `graphql` defect, + // and it would also fabricate a `services` availability entry whose + // remedy line lies. Its route flows through the + // NON_SLOT_SERVICE_ROUTES loop below instead: same gate + // (registered service), same mapping table, one hop over. + package: 'packages', + }; + + // [#6633] Routes advertised for registered services that are not + // CoreServiceName slots. Advertised iff the service is registered — + // the same convention every SERVICE_CONFIG row uses, and for `package` + // it is exactly the predicate that decides the mount on both real host + // types: the @objectstack/rest direct-mount registrar is gated on this + // same service (`direct-mount-composition.ts`), and the runtime + // dispatcher — whose `/packages` domain is unconditional — answers + // discovery from its own `getDiscoveryInfo()`, never from this + // builder. + // + // `datasources` is deliberately NOT here (same reasoning as `mcp`, + // #5679): the federation mount belongs to the REST host, which this + // builder cannot see, and the runtime dispatcher serves no + // `/datasources` domain at all — advertising it from here would be the + // advertise-the-unmounted half of ADR-0076 D12. The REST discovery + // endpoint advertises it from its recorded direct mounts. + const NON_SLOT_SERVICE_ROUTES: Record = { + package: '/api/v1/packages', + }; + + const optionalRoutes: Partial = {}; + + // Add routes for available plugin services. Services without an HTTP + // surface (config.route undefined) advertise no route (D12, #2462). + for (const serviceName of Object.keys(SERVICE_CONFIG)) { + // [#14646] Read the route off the entry that was just built rather + // than re-deriving it from the table. Byte-identical for every + // table-routed slot, and it is the only spelling that stays correct + // for a channel slot, whose route comes from the occupant — two + // derivations of one fact is how `routes` and `services` drift. + const route = services[serviceName]?.route; + if (registeredServices.has(serviceName) && route) { + const routeKey = serviceToRouteKey[serviceName]; + if (routeKey) { + optionalRoutes[routeKey] = route; + } + } + } + + // [#6633] Same flow for the non-slot routed services declared above. + for (const [serviceName, route] of Object.entries(NON_SLOT_SERVICE_ROUTES)) { + if (registeredServices.has(serviceName)) { + const routeKey = serviceToRouteKey[serviceName]; + if (routeKey) { + optionalRoutes[routeKey] = route; + } + } + } + + const routes: ApiRoutes = { + data: '/api/v1/data', + metadata: '/api/v1/meta', + ...optionalRoutes, + }; + + // Build well-known capabilities from registered services. + // + // [#5672] `WellKnownCapabilitiesSchema` is THE capability vocabulary and + // `DiscoverySchema.capabilities` is now a closed object over it, so this + // literal must answer EVERY key — a capability this host does not + // deliver is `enabled: false`, never an absent key (maintainer ruling A, + // 2026-08-06). The `WellKnownCapabilities` annotation is what enforces + // that at compile time: adding a key to the vocabulary breaks this line + // until it is answered here. + // + // Each key's basis is recorded next to it. Where a capability is backed + // by a service slot, the predicate is deliberately the SAME one that + // decides whether the route is advertised (`advertisedRoute`/ + // `unserveable` above) — what we advertise and what we claim cannot + // disagree. + const capabilityServed = (serviceName: string) => + registeredServices.has(serviceName) && !unserveable(serviceName); + + const wellKnown: WellKnownCapabilities = { + // Comments/chatter are served by the `sys_comment` object via the generic + // data API (ADR-0052 §5) — not a dedicated service. The capability is true + // iff that object is loaded (the always-on audit slate provides it); this + // keeps declared === enforced (Prime Directive #10). #3180 + comments: !!host.engine.registry?.getObject?.('sys_comment'), + automation: registeredServices.has('automation'), + cron: registeredServices.has('job'), + // [#7541] Serveability-gated on the protocol's OWN search + // implementation, was slot presence. This is the same predicate the + // route refuses on: `registerSearchEndpoints` + // (packages/rest/src/rest-server.ts) 501s exactly when + // `typeof protocol.searchAll !== 'function'`, so the two ends can no + // longer answer the same question differently — the rule stated at + // the top of this block, applied to the key that was still exempt. + // + // The old predicate was wrong in the direction discovery exists to + // prevent: `searchAll` is implemented by this class unconditionally, + // nothing in either repository registers the `search` slot + // (CORE_SERVICE_PROVIDER records that, verified), so every REST host + // served `GET /api/v1/search` 200 while advertising + // `capabilities.search = false`. A conforming client — one that + // trusts the document instead of probing — skipped a working + // surface. Prime Directive #10 inverted. + // + // `services.search` is deliberately NOT collapsed into this. The + // slot is a distinct question with its own answer: `CoreServiceName` + // declares it "Search Engine (Elastic/Meili)" and `ISearchService` + // is an index/query contract, so `services.search` reports WHICH + // ENGINE occupies the slot while this bit reports WHETHER THE + // SURFACE IS SERVED (`WellKnownCapabilitiesSchema.search`: "whether + // the backend supports full-text search"). They may legitimately + // differ — an empty slot with a served endpoint is today's normal + // host — and `serviceUnavailableMessage('search')` now says so in + // the same document, the way `ui` does for the same shape (#4146). + search: typeof searchAllOnInstance === 'function', + export: registeredServices.has('automation') || registeredServices.has('queue'), + // [#5672] Serveability-gated, was presence-only. Two reasons, and + // the second is the binding one: + // 1. `declared === enforced` — a self-declared stub storage service + // mounts no HTTP surface, so this builder already withholds + // `routes.storage` from it; advertising chunked upload anyway + // promised an upload endpoint that cannot exist. + // 2. the runtime dispatcher answers this key `hasFiles`, i.e. + // `isServiceServeable(filesSvc)`. Leaving this one on presence + // would make the two producers give the SAME host opposite + // answers for the SAME key — a new dialect inside the + // vocabulary this issue exists to unify. + chunkedUpload: capabilityServed('storage'), + // Atomic cross-object batch (#3298 / #1604 / ADR-0034 item 4): the + // REST /batch endpoint runs its ops inside `engine.transaction()`, + // which only opens a real (all-or-nothing) transaction when the + // DEFAULT DRIVER can carry one — otherwise it takes its declared + // non-transactional path (ADR-0119 D1) and the batch degrades to a + // non-atomic passthrough. Advertise the capability iff the runtime + // can actually roll back, so `declared === enforced` (Prime + // Directive #10). The rest-server producer ANDs this with + // `api.enableBatch` so a server that doesn't mount the route reports + // `false` at its layer. + // + // [#18997] `engineCanRollBack`, NOT `typeof this.engine?.transaction + // === 'function'`. The refusal this advertisement exists to help a + // caller avoid — `runAtomicBatch`'s `501 NOT_IMPLEMENTED`, whose own + // remedy text says to probe `capabilities.transactionalBatch` on + // /discovery first — already asks `engineCanRollBack`, which asks the + // DRIVER as well as the engine. `engine.transaction` is a function on + // every real engine, so the engine-only probe answered `true` for the + // two compositions that 501: a default driver with no + // `beginTransaction` at all, and one that INHERITED it and declared + // `supports.transactionsUnsupported` (#18063). An advertised + // capability must answer the same question the refusal path asks, + // from the same predicate — two derivations of one capability is how + // these drifted. Narrowing only: this predicate is the engine probe + // AND a driver clause, so no composition newly advertises `true` + // (`protocol.discovery-transactional-batch-honesty.test.ts` pins both + // directions, and the driver clause is skipped where the registry is + // not inspectable, so a test double keeps its old answer). + transactionalBatch: engineCanRollBack(host.engine), + + // ── Joined the vocabulary with ruling A (#5672) ─────────────────── + // These six used to be the runtime dispatcher's half of the split. + // This builder can answer all of them from the services registry it + // already reads, so none of them is a "cannot deliver ⇒ false" + // placeholder — they are measured, per key: + + // [#14646] Derived, not stated. This flag and `services.realtime` + // answer the same question — "is there a channel to subscribe to?" + // — so it is the same predicate applied to the same entry + // (`isSubscribableChannel`), and a host that mounts a transport + // flips both in one step. It was a literal `false` beside an entry + // saying `enabled: true`: two constants that happened to be right + // are not agreement, they are two places to forget. False on every + // host the open framework ships, because `service-realtime` is an + // in-process pub/sub bus that names no channel route (ADR-0076 D12, + // #2462; maintainer ruling A, 2026-09-04). + websockets: isSubscribableChannel(services['realtime']), + // Storage: the `storage` slot (#9683), gated on serveability rather + // than presence — a self-declared stub mounts nothing, and this + // builder already withholds `routes.storage` from it. + files: capabilityServed('storage'), + analytics: capabilityServed('analytics'), + ai: capabilityServed('ai'), + // Slot is `notification` (singular, CoreServiceName); the capability + // and the route key are plural. Same slot, three spellings — the + // mapping is here so nothing has to guess it. + notifications: capabilityServed('notification'), + i18n: capabilityServed('i18n'), + }; + + // Convert flat booleans → hierarchical capability objects. + // + // [#5672] Keyed by the vocabulary, not by `string`. The old + // `Record` was assignable to the open record + // `DiscoverySchema.capabilities` used to be; against the closed shape + // it no longer is, and that is the closure doing its job — the compiler + // now refuses a producer whose capability map is not the whole + // vocabulary. Iterating `wellKnown`'s own keys means fullness is + // carried over from the annotated literal above rather than re-asserted. + const capabilities = {} as Record; + for (const key of Object.keys(wellKnown) as Array) { + capabilities[key] = { enabled: wellKnown[key] }; + } + + // [#4828] Locale, derived from the registered i18n service exactly the + // way the runtime dispatcher's `getDiscoveryInfo()` derives it — same + // accessors, same fallback. `DiscoverySchema` declares `locale` + // REQUIRED and this producer never emitted it, so the REST `/discovery` + // shape could not satisfy the schema at all; deriving it (rather than + // hardcoding `en`) keeps the answer honest on a stack that actually + // ships translations. + const i18nSvc = registeredServices.get('i18n'); + let locale = { default: 'en', supported: ['en'], timezone: 'UTC' }; + if (i18nSvc) { + const defaultLocale = typeof i18nSvc.getDefaultLocale === 'function' + ? i18nSvc.getDefaultLocale() : 'en'; + const locales = typeof i18nSvc.getLocales === 'function' + ? i18nSvc.getLocales() : []; + locale = { + default: defaultLocale, + supported: locales.length > 0 ? locales : [defaultLocale], + timezone: 'UTC', + }; + } + + // [#4828] `name` is the canonical identity key (`DiscoverySchema` + // requires it); `apiName` is the deprecated alias, emitted with the + // IDENTICAL value until its scheduled removal in protocol 18 (schedule + // in `GetDiscoveryResponseSchema`). Before this, the two discovery + // producers spelled the same concept differently and disjointly — this + // one emitted only `apiName`, the dispatcher only `name` — so no + // consumer had a key that worked against both. + const name = 'ObjectStack API'; + + // [#21046] Which optional `/auth` route families are mounted — the + // registered auth service's OWN public-config answer, the object + // `GET /auth/config` serves, through the one reader the runtime + // dispatcher's `getDiscoveryInfo()` calls too (`readAuthFamilies`, + // `@objectstack/spec/api`). This builder never re-derives "is the admin + // plugin on" itself. `undefined` — no `auth` service in this kernel + // (then no `routes.auth` either), or one that publishes no public + // config — emits no key; the REST `/discovery` passes the value through. + const authFamilies = readAuthFamilies(registeredServices.get('auth')); + + return { + // [commit 376c70f98] The serving system's identity, DERIVED — an injected + // `OS_RUNTIME_VERSION` stamp, falling back to this package's own + // resolved version. It was the literal `'1.0'` while the other + // `DiscoverySchema` producer (`HttpDispatcher.getDiscoveryInfo()` + // in `@objectstack/runtime`) carried its own literal `'1.0.0'` — + // two producers of the same field disagreeing with each other, + // which is what proves neither constant was ever a contract value. + // #10993 fixed that producer the same way; see + // {@link resolveDiscoveryVersion} for the derivation, the fallback, + // and why the resolver is a package-local copy rather than an + // import. + version: resolveDiscoveryVersion(), + name, + /** @deprecated Use `name`. Removed in protocol 18 (#4828). */ + apiName: name, + // [#5936] The operator's value, passed as read — no local default. + // What an ABSENT `NODE_ENV` advertises is decided once, inside + // `resolveDiscoveryEnvironment` (`production`, per the 2026-08-07 + // ruling, direction 1), so this producer and the runtime dispatcher + // cannot drift on it. Before that ruling the default lived at the + // dispatcher's own call site and this producer had no equivalent, so + // a deployment that forgot the variable was told `development` here + // and `production` there — the exact drift the shared mapper exists + // to prevent (#4828). Do not re-introduce a default here. + environment: resolveDiscoveryEnvironment( + (globalThis as { process?: { env?: Record } }) + .process?.env?.NODE_ENV, + ), + routes, + locale, + services, + capabilities, + ...(authFamilies ? { authFamilies } : {}), + }; + } + /** The body of `ObjectStackProtocolImplementation#getMetaTypes`; the method's docblock there is its contract. */ static async getMetaTypes(host: Pick): Promise { const allTypes = await host.listLiveMetadataTypes(); diff --git a/packages/metadata-protocol/src/protocol.ts b/packages/metadata-protocol/src/protocol.ts index 3d39d62d1b0..992c3cea93b 100644 --- a/packages/metadata-protocol/src/protocol.ts +++ b/packages/metadata-protocol/src/protocol.ts @@ -6,13 +6,10 @@ import type { MetadataProtocol, PackageProtocol, } from '@objectstack/spec/api'; -import { IDataEngine, engineCanRollBack, recordNotFoundError } from '@objectstack/core'; +import { IDataEngine, recordNotFoundError } from '@objectstack/core'; import { resolveThrownHttpError } from '@objectstack/types'; import { resolveQueryReadLimits } from '@objectstack/types'; import { type TenancyPosture } from '@objectstack/spec/security'; -// [commit 376c70f98] The derived `version` this file's `getDiscovery()` serves as the -// `DiscoverySchema` "System Identity" field — never a literal again. -import { resolveDiscoveryVersion } from './discovery-version.js'; import type { MetadataHostEngine } from './host-engine.js'; import { SDUI_MANIFEST_SERVICE, @@ -71,9 +68,8 @@ import type { // [ADR-0131 D6] The `unmanaged` install mode: its request is PARSED through // the published declaration, and the pure half of the import (what a package // body holds, what is copied, what is refused) lives beside this file. -import type { MetadataCacheRequest, MetadataCacheResponse, ServiceInfo, ApiRoutes, WellKnownCapabilities, CapabilityDescriptor } from '@objectstack/spec/api'; +import type { MetadataCacheRequest, MetadataCacheResponse } from '@objectstack/spec/api'; import type { SeedAppliedLandedParsed } from '@objectstack/spec/api'; -import { readServiceSelfInfo, readChannelRoute, readAuthFamilies, isSubscribableChannel, CHANNEL_SURFACE_SLOTS, resolveDiscoveryEnvironment } from '@objectstack/spec/api'; // [#24395] The save's authoring surface. import { REFERENCE_VALUE_TYPES, @@ -106,7 +102,7 @@ import { type I18nLabel } from '@objectstack/spec/ui'; // (curated entry, unchanged). import { type FormFieldInput } from '@objectstack/spec/ui'; export type { FormFieldInput }; -import { CORE_SERVICE_PROVIDER, serviceUnavailableMessage, type TranslationBundle } from '@objectstack/spec/system'; +import { type TranslationBundle } from '@objectstack/spec/system'; import { type RestoredTranslatedSlot, } from './protocol-translated-echo.js'; @@ -520,7 +516,6 @@ export { suggestFieldName, } from './protocol-list-query-params.js'; export type { StoredMetadataSearchSchema } from './protocol-list-query-params.js'; -import { SERVICE_CONFIG } from './protocol-discovery-services.js'; import type { MetadataWriteFace } from './protocol-write-face.js'; export { specValidationFindings } from './protocol-write-face.js'; export type { MetadataWriteFace } from './protocol-write-face.js'; @@ -2525,464 +2520,10 @@ export class ObjectStackProtocolImplementation implements description?: string | undefined; }>; }> { - // Get registered services from kernel if available - const registeredServices = this.getServicesRegistry ? this.getServicesRegistry() : new Map(); - - // Build dynamic service info with proper typing. Analytics is NOT in - // this kernel-provided block: since the degraded ObjectQL fallback was - // retired (#3891) it is an ordinary optional service, computed from the - // registry via SERVICE_CONFIG below — absent means `unavailable`, and - // no route is advertised (the pre-#2462 hardcode here is exactly what - // the fallback was invented to make true). - // - // [#4089] The `metadata` slot is reported from whatever fills it, not - // hardcoded `available`. The kernel auto-registers `createMemoryMetadata` - // when no MetadataPlugin is present, and plugin-dev registers its own - // in-memory registry; both self-describe as `degraded` (D12), and - // hardcoding `available` here overstated them as exactly equivalent to a - // sys_metadata-backed registry. Absent or unmarked ⇒ `available`, which - // is what the real MetadataPlugin (carrying no marker) reports. - // - // This is also where the two builders stopped disagreeing: the runtime - // dispatcher hardcoded the opposite verdict for the same slot - // (`degraded` + "DB persistence pending"), so one host called a persisted - // registry degraded while the other called an in-memory one available. - // Both now compute it, and `handlerReady: true` is stated on both sides: - // `/api/v1/meta` is served by the protocol, not by this service, so it is - // mounted whichever implementation occupies the slot. - const metadataSelf = readServiceSelfInfo(registeredServices.get('metadata')); - - // [#4130] `data` was the last self-judging entry in this block. Same - // reasoning, one degree weaker: its hardcoded `available` is currently - // true, but only because ObjectQL is the slot's sole producer and - // plugin-dev (whose `data` stub declares `stub`) always loads - // ObjectQLPlugin as a child. That is a load-order convention in another - // package, not something this builder verifies — so verify it here. - // Unmarked implementation ⇒ `available` + `handlerReady: true`, i.e. - // exactly what the hardcode said, now derived rather than asserted. - const dataSelf = readServiceSelfInfo(registeredServices.get('data')); - - const services: Record = { - // --- Kernel-provided (objectql is an example kernel implementation) --- - metadata: { - enabled: true, - status: metadataSelf?.status ?? ('available' as const), - handlerReady: true, - route: '/api/v1/meta', - provider: 'objectql', - ...(metadataSelf?.message ? { message: metadataSelf.message } : {}), - }, - data: { - enabled: true, - status: dataSelf?.status ?? ('available' as const), - handlerReady: dataSelf?.handlerReady ?? true, - route: '/api/v1/data', - provider: 'objectql', - ...(dataSelf?.message ? { message: dataSelf.message } : {}), - }, - }; - - // [#4000, #4058] The dispatcher answers a self-declared non-handler in - // one of ITS domains' slots with the same 404/501 an empty slot gets - // (`isServiceServeable`, runtime/src/service-serveable.ts), so this - // builder must not advertise a route for one — that would be the - // `declared ≠ enforced` gap discovery exists to close. - // - // Scoped to the dispatcher-owned domains on purpose. For the other - // entries in SERVICE_CONFIG the route belongs to the plugin that - // registers the service (service-storage's own `/api/v1/storage` - // routes, plugin-search, plugin-graphql, …) rather than to a dispatcher - // domain, so `handlerReady` there says nothing about whether THAT route - // is mounted, and suppressing it would be a guess. `storage` stays - // listed as the one entry with no dispatcher domain behind it — #4087 - // retired the `/storage` bridge — because for that slot `handlerReady` - // is not a proxy for anything, it is the fact itself: an occupant that - // mounts no HTTP surface must not have `/api/v1/storage` advertised on - // its behalf. When service-storage is installed it registers a real - // (unmarked) service and mounts the routes, so the entry never fires. - const DISPATCHER_GATED_SERVICES = new Set([ - 'analytics', 'automation', 'notification', 'ai', 'i18n', 'storage', - ]); - const unserveable = (serviceName: string) => - DISPATCHER_GATED_SERVICES.has(serviceName) - && readServiceSelfInfo(registeredServices.get(serviceName))?.handlerReady === false; - const advertisedRoute = (serviceName: string, route?: string) => - unserveable(serviceName) ? undefined : route; - - // Check which services are actually registered - for (const [serviceName, config] of Object.entries(SERVICE_CONFIG)) { - if (registeredServices.has(serviceName)) { - // Registered — but honor a stub/dev/fallback self-description - // instead of blindly reporting 'available' (ADR-0076 D12). - const self = readServiceSelfInfo(registeredServices.get(serviceName)); - // [#14646] Channel slots answer a different question than every - // other row here. `enabled` elsewhere means "the slot is - // filled"; for a slot whose advertised capability IS a - // subscribable channel that reading is what let `/discovery` - // report `enabled: true` beside "no HTTP/WS realtime surface is - // mounted" — both true, one field, two meanings. Here `enabled` - // is the shared predicate itself, evaluated on the very entry a - // consumer reads, so the field and the definition are one - // computation. The route comes from the occupant because no - // builder in the open framework mounts a realtime transport. - if (CHANNEL_SURFACE_SLOTS.has(serviceName)) { - const channelRoute = readChannelRoute(registeredServices.get(serviceName)); - const handlerReady = channelRoute !== undefined; - services[serviceName] = { - enabled: isSubscribableChannel({ handlerReady, route: channelRoute }), - // A mounted channel makes an unmarked occupant plainly - // `available`; without one the slot keeps the reduced - // status its row declares (`degraded` for realtime — the - // capability it advertises IS the missing surface). - status: self?.status - ?? (handlerReady - ? ('available' as const) - : (config.noHttpSurface?.statusWhenUnmarked ?? ('available' as const))), - route: channelRoute, - provider: CORE_SERVICE_PROVIDER[serviceName] ?? undefined, - handlerReady, - // The "no surface" sentence is only true while there is - // no surface; a mounted channel drops it and keeps only - // whatever the occupant says about itself. - ...(self?.message - ? { message: self.message } - : !handlerReady && config.noHttpSurface - ? { message: config.noHttpSurface.message } - : {}), - }; - continue; - } - // No HTTP surface at all: the handler can never be ready, and - // the entry's own `noHttpSurface` declaration says whether that - // also degrades the slot (realtime) or not (cache/queue/job — - // in-process contracts, #4318). - const noHttpSurface = !config.route; - services[serviceName] = { - enabled: true, - status: self?.status ?? (config.noHttpSurface?.statusWhenUnmarked ?? ('available' as const)), - route: advertisedRoute(serviceName, config.route), - provider: CORE_SERVICE_PROVIDER[serviceName] ?? undefined, - ...(noHttpSurface || self?.handlerReady !== undefined - ? { handlerReady: noHttpSurface ? false : self?.handlerReady } - : {}), - ...(self?.message - ? { message: self.message } - : config.noHttpSurface - ? { message: config.noHttpSurface.message } - : {}), - }; - } else { - // Service is not registered - services[serviceName] = { - enabled: false, - status: 'unavailable' as const, - message: serviceUnavailableMessage(serviceName), - }; - } - } - - // [#9683] `file-storage` is the deprecated v17 alias of the `storage` - // slot, and it is a key existing consumers really read off this - // document (objectui's console endpoint catalog is keyed by it). The - // registry resolves both names to the same instance, so discovery - // mirrors the canonical row VERBATIM under the alias key until the - // alias retires at the next major — dropping the key would be the - // silent inside-a-major break the ruling forbids. Deliberately a - // byte-equal copy, not a second opinion: one slot, two spellings. - services['file-storage'] = { ...services['storage'] }; - - // Build routes from services — a flat convenience map for client routing - const serviceToRouteKey: Record = { - analytics: 'analytics', - auth: 'auth', - automation: 'automation', - ui: 'ui', - realtime: 'realtime', - notification: 'notifications', - ai: 'ai', - i18n: 'i18n', - storage: 'storage', - // [#6633] The package-management surface. `package` is NOT a - // CoreServiceName slot, so it must not enter SERVICE_CONFIG — a - // non-slot row there is the shape of the retired `graphql` defect, - // and it would also fabricate a `services` availability entry whose - // remedy line lies. Its route flows through the - // NON_SLOT_SERVICE_ROUTES loop below instead: same gate - // (registered service), same mapping table, one hop over. - package: 'packages', - }; - - // [#6633] Routes advertised for registered services that are not - // CoreServiceName slots. Advertised iff the service is registered — - // the same convention every SERVICE_CONFIG row uses, and for `package` - // it is exactly the predicate that decides the mount on both real host - // types: the @objectstack/rest direct-mount registrar is gated on this - // same service (`direct-mount-composition.ts`), and the runtime - // dispatcher — whose `/packages` domain is unconditional — answers - // discovery from its own `getDiscoveryInfo()`, never from this - // builder. - // - // `datasources` is deliberately NOT here (same reasoning as `mcp`, - // #5679): the federation mount belongs to the REST host, which this - // builder cannot see, and the runtime dispatcher serves no - // `/datasources` domain at all — advertising it from here would be the - // advertise-the-unmounted half of ADR-0076 D12. The REST discovery - // endpoint advertises it from its recorded direct mounts. - const NON_SLOT_SERVICE_ROUTES: Record = { - package: '/api/v1/packages', - }; - - const optionalRoutes: Partial = {}; - - // Add routes for available plugin services. Services without an HTTP - // surface (config.route undefined) advertise no route (D12, #2462). - for (const serviceName of Object.keys(SERVICE_CONFIG)) { - // [#14646] Read the route off the entry that was just built rather - // than re-deriving it from the table. Byte-identical for every - // table-routed slot, and it is the only spelling that stays correct - // for a channel slot, whose route comes from the occupant — two - // derivations of one fact is how `routes` and `services` drift. - const route = services[serviceName]?.route; - if (registeredServices.has(serviceName) && route) { - const routeKey = serviceToRouteKey[serviceName]; - if (routeKey) { - optionalRoutes[routeKey] = route; - } - } - } - - // [#6633] Same flow for the non-slot routed services declared above. - for (const [serviceName, route] of Object.entries(NON_SLOT_SERVICE_ROUTES)) { - if (registeredServices.has(serviceName)) { - const routeKey = serviceToRouteKey[serviceName]; - if (routeKey) { - optionalRoutes[routeKey] = route; - } - } - } - - const routes: ApiRoutes = { - data: '/api/v1/data', - metadata: '/api/v1/meta', - ...optionalRoutes, - }; - - // Build well-known capabilities from registered services. - // - // [#5672] `WellKnownCapabilitiesSchema` is THE capability vocabulary and - // `DiscoverySchema.capabilities` is now a closed object over it, so this - // literal must answer EVERY key — a capability this host does not - // deliver is `enabled: false`, never an absent key (maintainer ruling A, - // 2026-08-06). The `WellKnownCapabilities` annotation is what enforces - // that at compile time: adding a key to the vocabulary breaks this line - // until it is answered here. - // - // Each key's basis is recorded next to it. Where a capability is backed - // by a service slot, the predicate is deliberately the SAME one that - // decides whether the route is advertised (`advertisedRoute`/ - // `unserveable` above) — what we advertise and what we claim cannot - // disagree. - const capabilityServed = (serviceName: string) => - registeredServices.has(serviceName) && !unserveable(serviceName); - - const wellKnown: WellKnownCapabilities = { - // Comments/chatter are served by the `sys_comment` object via the generic - // data API (ADR-0052 §5) — not a dedicated service. The capability is true - // iff that object is loaded (the always-on audit slate provides it); this - // keeps declared === enforced (Prime Directive #10). #3180 - comments: !!this.engine.registry?.getObject?.('sys_comment'), - automation: registeredServices.has('automation'), - cron: registeredServices.has('job'), - // [#7541] Serveability-gated on the protocol's OWN search - // implementation, was slot presence. This is the same predicate the - // route refuses on: `registerSearchEndpoints` - // (packages/rest/src/rest-server.ts) 501s exactly when - // `typeof protocol.searchAll !== 'function'`, so the two ends can no - // longer answer the same question differently — the rule stated at - // the top of this block, applied to the key that was still exempt. - // - // The old predicate was wrong in the direction discovery exists to - // prevent: `searchAll` is implemented by this class unconditionally, - // nothing in either repository registers the `search` slot - // (CORE_SERVICE_PROVIDER records that, verified), so every REST host - // served `GET /api/v1/search` 200 while advertising - // `capabilities.search = false`. A conforming client — one that - // trusts the document instead of probing — skipped a working - // surface. Prime Directive #10 inverted. - // - // `services.search` is deliberately NOT collapsed into this. The - // slot is a distinct question with its own answer: `CoreServiceName` - // declares it "Search Engine (Elastic/Meili)" and `ISearchService` - // is an index/query contract, so `services.search` reports WHICH - // ENGINE occupies the slot while this bit reports WHETHER THE - // SURFACE IS SERVED (`WellKnownCapabilitiesSchema.search`: "whether - // the backend supports full-text search"). They may legitimately - // differ — an empty slot with a served endpoint is today's normal - // host — and `serviceUnavailableMessage('search')` now says so in - // the same document, the way `ui` does for the same shape (#4146). - search: typeof this.searchAll === 'function', - export: registeredServices.has('automation') || registeredServices.has('queue'), - // [#5672] Serveability-gated, was presence-only. Two reasons, and - // the second is the binding one: - // 1. `declared === enforced` — a self-declared stub storage service - // mounts no HTTP surface, so this builder already withholds - // `routes.storage` from it; advertising chunked upload anyway - // promised an upload endpoint that cannot exist. - // 2. the runtime dispatcher answers this key `hasFiles`, i.e. - // `isServiceServeable(filesSvc)`. Leaving this one on presence - // would make the two producers give the SAME host opposite - // answers for the SAME key — a new dialect inside the - // vocabulary this issue exists to unify. - chunkedUpload: capabilityServed('storage'), - // Atomic cross-object batch (#3298 / #1604 / ADR-0034 item 4): the - // REST /batch endpoint runs its ops inside `engine.transaction()`, - // which only opens a real (all-or-nothing) transaction when the - // DEFAULT DRIVER can carry one — otherwise it takes its declared - // non-transactional path (ADR-0119 D1) and the batch degrades to a - // non-atomic passthrough. Advertise the capability iff the runtime - // can actually roll back, so `declared === enforced` (Prime - // Directive #10). The rest-server producer ANDs this with - // `api.enableBatch` so a server that doesn't mount the route reports - // `false` at its layer. - // - // [#18997] `engineCanRollBack`, NOT `typeof this.engine?.transaction - // === 'function'`. The refusal this advertisement exists to help a - // caller avoid — `runAtomicBatch`'s `501 NOT_IMPLEMENTED`, whose own - // remedy text says to probe `capabilities.transactionalBatch` on - // /discovery first — already asks `engineCanRollBack`, which asks the - // DRIVER as well as the engine. `engine.transaction` is a function on - // every real engine, so the engine-only probe answered `true` for the - // two compositions that 501: a default driver with no - // `beginTransaction` at all, and one that INHERITED it and declared - // `supports.transactionsUnsupported` (#18063). An advertised - // capability must answer the same question the refusal path asks, - // from the same predicate — two derivations of one capability is how - // these drifted. Narrowing only: this predicate is the engine probe - // AND a driver clause, so no composition newly advertises `true` - // (`protocol.discovery-transactional-batch-honesty.test.ts` pins both - // directions, and the driver clause is skipped where the registry is - // not inspectable, so a test double keeps its old answer). - transactionalBatch: engineCanRollBack(this.engine), - - // ── Joined the vocabulary with ruling A (#5672) ─────────────────── - // These six used to be the runtime dispatcher's half of the split. - // This builder can answer all of them from the services registry it - // already reads, so none of them is a "cannot deliver ⇒ false" - // placeholder — they are measured, per key: - - // [#14646] Derived, not stated. This flag and `services.realtime` - // answer the same question — "is there a channel to subscribe to?" - // — so it is the same predicate applied to the same entry - // (`isSubscribableChannel`), and a host that mounts a transport - // flips both in one step. It was a literal `false` beside an entry - // saying `enabled: true`: two constants that happened to be right - // are not agreement, they are two places to forget. False on every - // host the open framework ships, because `service-realtime` is an - // in-process pub/sub bus that names no channel route (ADR-0076 D12, - // #2462; maintainer ruling A, 2026-09-04). - websockets: isSubscribableChannel(services['realtime']), - // Storage: the `storage` slot (#9683), gated on serveability rather - // than presence — a self-declared stub mounts nothing, and this - // builder already withholds `routes.storage` from it. - files: capabilityServed('storage'), - analytics: capabilityServed('analytics'), - ai: capabilityServed('ai'), - // Slot is `notification` (singular, CoreServiceName); the capability - // and the route key are plural. Same slot, three spellings — the - // mapping is here so nothing has to guess it. - notifications: capabilityServed('notification'), - i18n: capabilityServed('i18n'), - }; - - // Convert flat booleans → hierarchical capability objects. - // - // [#5672] Keyed by the vocabulary, not by `string`. The old - // `Record` was assignable to the open record - // `DiscoverySchema.capabilities` used to be; against the closed shape - // it no longer is, and that is the closure doing its job — the compiler - // now refuses a producer whose capability map is not the whole - // vocabulary. Iterating `wellKnown`'s own keys means fullness is - // carried over from the annotated literal above rather than re-asserted. - const capabilities = {} as Record; - for (const key of Object.keys(wellKnown) as Array) { - capabilities[key] = { enabled: wellKnown[key] }; - } - - // [#4828] Locale, derived from the registered i18n service exactly the - // way the runtime dispatcher's `getDiscoveryInfo()` derives it — same - // accessors, same fallback. `DiscoverySchema` declares `locale` - // REQUIRED and this producer never emitted it, so the REST `/discovery` - // shape could not satisfy the schema at all; deriving it (rather than - // hardcoding `en`) keeps the answer honest on a stack that actually - // ships translations. - const i18nSvc = registeredServices.get('i18n'); - let locale = { default: 'en', supported: ['en'], timezone: 'UTC' }; - if (i18nSvc) { - const defaultLocale = typeof i18nSvc.getDefaultLocale === 'function' - ? i18nSvc.getDefaultLocale() : 'en'; - const locales = typeof i18nSvc.getLocales === 'function' - ? i18nSvc.getLocales() : []; - locale = { - default: defaultLocale, - supported: locales.length > 0 ? locales : [defaultLocale], - timezone: 'UTC', - }; - } - - // [#4828] `name` is the canonical identity key (`DiscoverySchema` - // requires it); `apiName` is the deprecated alias, emitted with the - // IDENTICAL value until its scheduled removal in protocol 18 (schedule - // in `GetDiscoveryResponseSchema`). Before this, the two discovery - // producers spelled the same concept differently and disjointly — this - // one emitted only `apiName`, the dispatcher only `name` — so no - // consumer had a key that worked against both. - const name = 'ObjectStack API'; - - // [#21046] Which optional `/auth` route families are mounted — the - // registered auth service's OWN public-config answer, the object - // `GET /auth/config` serves, through the one reader the runtime - // dispatcher's `getDiscoveryInfo()` calls too (`readAuthFamilies`, - // `@objectstack/spec/api`). This builder never re-derives "is the admin - // plugin on" itself. `undefined` — no `auth` service in this kernel - // (then no `routes.auth` either), or one that publishes no public - // config — emits no key; the REST `/discovery` passes the value through. - const authFamilies = readAuthFamilies(registeredServices.get('auth')); - - return { - // [commit 376c70f98] The serving system's identity, DERIVED — an injected - // `OS_RUNTIME_VERSION` stamp, falling back to this package's own - // resolved version. It was the literal `'1.0'` while the other - // `DiscoverySchema` producer (`HttpDispatcher.getDiscoveryInfo()` - // in `@objectstack/runtime`) carried its own literal `'1.0.0'` — - // two producers of the same field disagreeing with each other, - // which is what proves neither constant was ever a contract value. - // #10993 fixed that producer the same way; see - // {@link resolveDiscoveryVersion} for the derivation, the fallback, - // and why the resolver is a package-local copy rather than an - // import. - version: resolveDiscoveryVersion(), - name, - /** @deprecated Use `name`. Removed in protocol 18 (#4828). */ - apiName: name, - // [#5936] The operator's value, passed as read — no local default. - // What an ABSENT `NODE_ENV` advertises is decided once, inside - // `resolveDiscoveryEnvironment` (`production`, per the 2026-08-07 - // ruling, direction 1), so this producer and the runtime dispatcher - // cannot drift on it. Before that ruling the default lived at the - // dispatcher's own call site and this producer had no equivalent, so - // a deployment that forgot the variable was told `development` here - // and `production` there — the exact drift the shared mapper exists - // to prevent (#4828). Do not re-introduce a default here. - environment: resolveDiscoveryEnvironment( - (globalThis as { process?: { env?: Record } }) - .process?.env?.NODE_ENV, - ), - routes, - locale, - services, - capabilities, - ...(authFamilies ? { authFamilies } : {}), - }; + // [#29985 codemod] The body moved to `protocol-discovery-and-bases.ts`; it reaches this class through `protocol-host.ts`. + // [#30147 hand move] `capabilities.search` probes `typeof this.searchAll`; the host would forward the + // method through a closure that is always a function, so the stub reads it on the instance and hands it in. + return ProtocolDiscoveryAndBasesFacet.getDiscovery(protocolHost(this), this.searchAll); } /** diff --git a/scripts/check-facade-delegation-only.mjs b/scripts/check-facade-delegation-only.mjs index ebf9e4eba95..e64794c78ae 100644 --- a/scripts/check-facade-delegation-only.mjs +++ b/scripts/check-facade-delegation-only.mjs @@ -111,7 +111,10 @@ * Today's facade keeps shared state on the class, so a few hot bodies may stay * (ruling 6624345766 item 3). Each one is an `exceptions` row naming the file, * the member and the card that will move it (#30020, the state-owning facets - * card). The registry is refused, not trusted: + * card). A row may instead be an accepted terminal exception: its `reason` + * opens by citing the maintainer ruling that accepted it (6687801899 for the + * three #30147 rows), its `card` is the card that recorded it, and it stays + * after that card closes. The registry is refused, not trusted: * * • a row with no card, or a card that is not `#` → red * • a row naming a file that is not a registered facade → red diff --git a/scripts/facade-delegation-registry.json b/scripts/facade-delegation-registry.json index 0983ad1840c..8a84c6c0ea7 100644 --- a/scripts/facade-delegation-registry.json +++ b/scripts/facade-delegation-registry.json @@ -27,12 +27,6 @@ } ], "exceptions": [ - { - "file": "packages/metadata-protocol/src/protocol.ts", - "member": "getDiscovery", - "card": "#30147", - "reason": "codemod limit: closed-set, reads the instance method `searchAll` as a value (`typeof this.searchAll === 'function'` sets `capabilities.search`), and a host entry forwards a method through a closure that is always a function, so the moved probe would always answer true (#30518 PR2, measured by rest discovery-search-capability-agreement.test.ts)" - }, { "file": "packages/metadata-protocol/src/protocol.ts", "member": "publishPackageDrafts", @@ -43,7 +37,7 @@ "file": "packages/metadata-protocol/src/protocol.ts", "member": "triggerAutomation", "card": "#30147", - "reason": "accepted exception (#30147 phase 3): its body is one `throw` (no shorter than a stub), and its section (Batch and *Many data) has no facet module; the codemod's members pass adds to a written facet and never starts one, so a facet for one statement would be the only reason to start it" + "reason": "accepted terminal exception (ruling 6687801899): accepted exception (#30147 phase 3): its body is one `throw` (no shorter than a stub), and its section (Batch and *Many data) has no facet module; the codemod's members pass adds to a written facet and never starts one, so a facet for one statement would be the only reason to start it" }, { "file": "packages/metadata-protocol/src/protocol.ts", @@ -76,28 +70,28 @@ "file": "packages/objectql/src/engine.ts", "class": "ObjectQL", "member": "homeAmountServing", - "card": "#30147", + "card": "#30975", "reason": "codemod limit: field-call, it calls a field or accessor as a function (#29986 report)" }, { "file": "packages/objectql/src/engine.ts", "class": "ObjectQL", "member": "projectHomeAmountsOntoPatch", - "card": "#30147", + "card": "#30975", "reason": "codemod limit: gate reading, a parameter default computes (calls this.homeAmountServing)" }, { "file": "packages/objectql/src/engine.ts", "class": "ScopedContext", "member": "derive", - "card": "#30147", + "card": "#30975", "reason": "codemod limit: foreign-private, it writes `appAuthored` on another instance, which a module function cannot (#30052 report)" }, { "file": "packages/objectql/src/engine.ts", "class": "ScopedContext", "member": "[APP_AUTHORED_HOOK_API]", - "card": "#30147", + "card": "#30975", "reason": "codemod limit: not-identifier-name, a symbol-keyed method; it also writes `appAuthored` on another instance (#30052 report)" }, { @@ -124,13 +118,13 @@ "file": "packages/drivers/driver-sql/src/sql-driver.ts", "member": "static DIALECT_CONNECT_TIMEOUT", "card": "#30147", - "reason": "codemod limit: a static initializer runs while the class itself is evaluated, so a call into a facet module there could meet that module in its temporal dead zone (MOVED_FIELD_DEFAULTS takes instance fields only, #30147 phase 2a)" + "reason": "accepted terminal exception (ruling 6687801899): codemod limit: a static initializer runs while the class itself is evaluated, so a call into a facet module there could meet that module in its temporal dead zone (MOVED_FIELD_DEFAULTS takes instance fields only, #30147 phase 2a)" }, { "file": "packages/drivers/driver-sql/src/sql-driver.ts", "member": "get supports", "card": "#30147", - "reason": "codemod limit: inferred-return-type, a get accessor whose object type the base leaves inferred, with a docblock on each key (MOVED_ACCESSORS moves a getter whose type is written, #30147 phase 2a)" + "reason": "accepted terminal exception (ruling 6687801899): codemod limit: inferred-return-type, a get accessor whose object type the base leaves inferred, with a docblock on each key (MOVED_ACCESSORS moves a getter whose type is written, #30147 phase 2a)" } ] }