From 203cf3f1df6c3ee062b5a51e66f5c1951bec008e Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 10:01:48 +0000 Subject: [PATCH 01/12] wip(studio): one Studio address builder and its mapping table (#36895) Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01WGufzhpykmQZe1yMupC2CU --- .../src/views/studio-design/metadataArea.ts | 51 ++- .../studio-design/setupMetadataRedirect.ts | 16 +- .../src/views/studio-design/studioAddress.ts | 309 ++++++++++++++++++ .../views/studio-design/studioAddressTable.ts | 264 +++++++++++++++ .../views/studio-design/studioChangesLink.ts | 19 +- .../studio-design/studioInterfacesRetired.ts | 20 +- .../src/views/studio-design/studioScope.ts | 23 +- .../studio-design/switchedOffActionTargets.ts | 16 +- 8 files changed, 647 insertions(+), 71 deletions(-) create mode 100644 ui/packages/app-shell/src/views/studio-design/studioAddress.ts create mode 100644 ui/packages/app-shell/src/views/studio-design/studioAddressTable.ts diff --git a/ui/packages/app-shell/src/views/studio-design/metadataArea.ts b/ui/packages/app-shell/src/views/studio-design/metadataArea.ts index 210c946d846..73a8f99cba2 100644 --- a/ui/packages/app-shell/src/views/studio-design/metadataArea.ts +++ b/ui/packages/app-shell/src/views/studio-design/metadataArea.ts @@ -34,14 +34,24 @@ * link. {@link areaLocationRedirect} puts each URL on the leg its query names. */ -import { DESIGNER_SURFACE_PARAM, formatSurfaceParam } from '../metadata-admin/nav-selection.js'; import { CATALOG_SCOPE_PARAM, ENVIRONMENT_SCOPE } from '../metadata-admin/catalog-scope.js'; - -/** The area's route segment, beside the pillars' (`/studio//metadata`). */ -export const STUDIO_METADATA_AREA = 'metadata'; - -/** The reserved `/studio/` value for the area's cross-package leg. */ -export const STUDIO_ALL_PACKAGES_SEGMENT = '~all'; +import { + STUDIO_ALL_PACKAGES_SEGMENT, + STUDIO_ITEM_PILLAR, + STUDIO_ITEM_REVIEW_PARAM, + STUDIO_ITEM_REVIEW_VALUE, + studioItemPillar, + studioMetadataAreaAddress, + studioMetadataAreaRoot, + studioMetadataItemAddress, + studioPillarItemAddress, + type StudioPillarKey, +} from './studioAddress.js'; + +// objectstack#36895 — the area's segments are Studio address vocabulary, owned +// by `studioAddress.ts`; re-exported under their names here. +export { STUDIO_METADATA_AREA, STUDIO_ALL_PACKAGES_SEGMENT } from './studioAddress.js'; +export type { StudioPillarKey } from './studioAddress.js'; /** Whether a `/studio/:packageId` route segment names the cross-package leg. */ export function isStudioAllPackagesScope(segment: string | null | undefined): boolean { @@ -50,12 +60,9 @@ export function isStudioAllPackagesScope(segment: string | null | undefined): bo /** The area's root for a package, or for the cross-package leg with {@link STUDIO_ALL_PACKAGES_SEGMENT}. */ export function studioMetadataAreaPath(segment: string): string { - return `/studio/${encodeURIComponent(segment)}/${STUDIO_METADATA_AREA}`; + return studioMetadataAreaRoot(segment); } -/** The pillar keys a pillar type opens in (`StudioDesignSurface`'s `PILLARS`). */ -export type StudioPillarKey = 'data' | 'automations' | 'access'; - /** * ADR-0146 D1 — "A pillar type opened from the directory opens its pillar". * The types each pillar designs; every other type opens the area's generic @@ -66,15 +73,11 @@ export type StudioPillarKey = 'data' | 'automations' | 'access'; * and this area's generic item page is where they are read and, as a * fallback, edited as metadata. */ -export const AREA_PILLAR_FOR_TYPE: Readonly> = { - object: 'data', - flow: 'automations', - permission: 'access', -}; +export const AREA_PILLAR_FOR_TYPE: Readonly> = STUDIO_ITEM_PILLAR; /** The area's generic item page of one item of a package. */ export function studioMetadataItemPath(packageId: string, item: { type: string; name: string }): string { - return `${studioMetadataAreaPath(packageId)}/${encodeURIComponent(item.type)}/${encodeURIComponent(item.name)}`; + return studioMetadataItemAddress(packageId, item.type, item.name); } /** A pillar of a package, opened on one item through its `?surface=` deep link. */ @@ -83,7 +86,7 @@ export function studioPillarItemPath( pillar: StudioPillarKey, item: { type: string; name: string }, ): string { - return `/studio/${encodeURIComponent(packageId)}/${pillar}?${DESIGNER_SURFACE_PARAM}=${encodeURIComponent(formatSurfaceParam(item))}`; + return studioPillarItemAddress(packageId, pillar, item); } /** @@ -101,10 +104,10 @@ export function areaItemPillarPath(input: { name: string; search: URLSearchParams; }): string | null { - const pillar = AREA_PILLAR_FOR_TYPE[input.type]; + const pillar = studioItemPillar(input.type); if (!pillar || !input.packageId) return null; if (input.search.get(CATALOG_SCOPE_PARAM) === ENVIRONMENT_SCOPE) return null; - if (input.search.get('review') === '1') return null; + if (input.search.get(STUDIO_ITEM_REVIEW_PARAM) === STUDIO_ITEM_REVIEW_VALUE) return null; return studioPillarItemPath(input.packageId, pillar, { type: input.type, name: input.name }); } @@ -152,7 +155,7 @@ export function areaItemOpensFormEditor(input: { (input.readOnly === true && AREA_CUSTOMIZE_EDITOR_TYPES.includes(input.type)); if (!opens || !input.packageId) return false; if (input.search.get(CATALOG_SCOPE_PARAM) === ENVIRONMENT_SCOPE) return false; - return input.search.get('review') !== '1'; + return input.search.get(STUDIO_ITEM_REVIEW_PARAM) !== STUDIO_ITEM_REVIEW_VALUE; } /** `?package=all` is the metadata list's "every package" scope, not a package (`ResourceEditPage`'s `'all'` fold). */ @@ -181,11 +184,7 @@ const ALL_PACKAGES_VALUE = 'all'; export function areaLocationRedirect(segment: string, rest: string, search: string): string | null { const params = new URLSearchParams(search); const allLeg = isStudioAllPackagesScope(segment); - const tail = rest ? `/${rest}` : ''; - const at = (leg: string) => { - const qs = params.toString(); - return `${studioMetadataAreaPath(leg)}${tail}${qs ? `?${qs}` : ''}`; - }; + const at = (leg: string) => studioMetadataAreaAddress(leg, rest, { query: params }); if (params.get(CATALOG_SCOPE_PARAM) === ENVIRONMENT_SCOPE) { if (allLeg && !params.has('package')) return null; diff --git a/ui/packages/app-shell/src/views/studio-design/setupMetadataRedirect.ts b/ui/packages/app-shell/src/views/studio-design/setupMetadataRedirect.ts index 8cc96de9485..5bd5542fec2 100644 --- a/ui/packages/app-shell/src/views/studio-design/setupMetadataRedirect.ts +++ b/ui/packages/app-shell/src/views/studio-design/setupMetadataRedirect.ts @@ -17,7 +17,8 @@ * Datasources page, so redirecting it here would loop. */ -import { STUDIO_ALL_PACKAGES_SEGMENT, areaLocationRedirect, studioMetadataAreaPath } from './metadataArea.js'; +import { STUDIO_ALL_PACKAGES_SEGMENT, areaLocationRedirect } from './metadataArea.js'; +import { studioHomePath, studioLandingPath, studioMetadataAreaAddress, studioPillarPath } from './studioAddress.js'; /** The one metadata type whose Setup pages stay in Setup (ADR-0146 D1). */ export const SETUP_KEPT_METADATA_TYPE = 'datasource'; @@ -37,8 +38,7 @@ export function setupMetadataStudioPath(rest: string, search: string, hash = '') const tail = segments.join('/'); const onLeg = areaLocationRedirect(STUDIO_ALL_PACKAGES_SEGMENT, tail, search); if (onLeg) return `${onLeg}${hash}`; - const query = new URLSearchParams(search).toString(); - return `${studioMetadataAreaPath(STUDIO_ALL_PACKAGES_SEGMENT)}${tail ? `/${tail}` : ''}${query ? `?${query}` : ''}${hash}`; + return studioMetadataAreaAddress(STUDIO_ALL_PACKAGES_SEGMENT, tail, { query: new URLSearchParams(search), hash }); } /** @@ -68,10 +68,9 @@ export function setupMetadataRest(pathname: string): string | null { export function packagedAutomationStudioPath(search: string, hash = ''): string { const params = new URLSearchParams(search); const query = params.toString(); - const tail = `${query ? `?${query}` : ''}${hash}`; const pkg = params.get('package'); - if (pkg && pkg !== 'all') return `/studio/${encodeURIComponent(pkg)}/automations${tail}`; - return `${studioMetadataAreaPath(STUDIO_ALL_PACKAGES_SEGMENT)}/flow${tail}`; + if (pkg && pkg !== 'all') return studioPillarPath(pkg, 'automations', { query, hash }); + return studioMetadataAreaAddress(STUDIO_ALL_PACKAGES_SEGMENT, 'flow', { query, hash }); } /** @@ -88,8 +87,7 @@ export function packagedAutomationStudioPath(search: string, hash = ''): string export function packagedActionsStudioPath(search: string, hash = ''): string { const params = new URLSearchParams(search); const query = params.toString(); - const tail = `${query ? `?${query}` : ''}${hash}`; const pkg = params.get('package'); - if (pkg && pkg !== 'all') return `/studio/${encodeURIComponent(pkg)}/data${tail}`; - return `/studio${tail}`; + if (pkg && pkg !== 'all') return studioHomePath(pkg, { query, hash }); + return studioLandingPath({ query, hash }); } diff --git a/ui/packages/app-shell/src/views/studio-design/studioAddress.ts b/ui/packages/app-shell/src/views/studio-design/studioAddress.ts new file mode 100644 index 00000000000..1653ce006fc --- /dev/null +++ b/ui/packages/app-shell/src/views/studio-design/studioAddress.ts @@ -0,0 +1,309 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * The one builder of Studio addresses (objectstack#36895, Studio redesign + * epic #36890). Every place that produces a `/studio...` URL calls a builder + * here; nothing else spells one by hand, and + * `studioAddress.guard.test.ts` refuses a hand-built one anywhere under `ui/`. + * + * ## Why one builder first + * + * The epic moves objects, flows and permission sets from their pillar + * addresses (`/studio//data?surface=object:`) to metadata + * addresses (`/studio//metadata//`). Today the "All + * metadata" area sends a pillar type back to its pillar + * (`areaItemPillarPath`, read through {@link STUDIO_ITEM_PILLAR}), so + * redirecting the pillar address to the metadata one first would make the two + * rules bounce off each other. With every producer on this builder, a designer + * card switches its type in ONE place, {@link STUDIO_ITEM_PILLAR}, in the same + * PR that ships its full-screen designer: the producers and the area's + * redirect move together, so there is never a loop. + * + * ## Today's addresses, byte for byte + * + * This module changes no address. The producers it replaced did not agree on + * how to spell a `?surface=` value, and each spelling is kept, named by + * {@link StudioSurfaceSpelling}, because a changed byte is a changed address + * (a bookmark, a test pin, a link an AI was handed). The mapping table + * (`studioAddressTable.ts`) lists every address family, every `?surface=` + * spelling and every parameter carried verbatim, and is what the designer + * cards switch from. + * + * ## The server's two addresses + * + * The draft door's review links (the CLI's `os meta register` and the MCP + * authoring tools) are built by `studioChangesReviewRoute` and + * `studioItemReviewRoute` in `@objectstack/types`, which both server packages + * already depend on; the Console does not depend on that package, so + * {@link studioChangesReviewPath} and {@link studioItemReviewPath} are their + * Console halves, pinned to the same literals. + * + * Pure: no React, no router, so every rule is pinned without a render. + */ + +import { DESIGNER_SURFACE_PARAM, formatSurfaceParam } from '../metadata-admin/nav-selection.js'; + +// --------------------------------------------------------------------------- +// The vocabulary +// --------------------------------------------------------------------------- + +/** The root every Studio address starts with. */ +export const STUDIO_ROOT_PATH = '/studio'; + +/** The pillar a package's Studio opens on: its home. */ +export const STUDIO_HOME_PILLAR = 'data'; + +/** The "All metadata" area's route segment, beside the pillars' (`/studio//metadata`). */ +export const STUDIO_METADATA_AREA = 'metadata'; + +/** The reserved `/studio/` value for the "All metadata" area's cross-package leg. */ +export const STUDIO_ALL_PACKAGES_SEGMENT = '~all'; + +/** The reserved `/studio/` value for the package-less scope (`studioScope.ts`). */ +export const STUDIO_ORG_SCOPE_SEGMENT = '~org'; + +/** The one pillar the package-less scope offers. */ +export const STUDIO_ORG_SCOPE_PILLAR = 'automations'; + +/** The retired Interfaces pillar's route segment (objectstack#36502). No pillar answers to it any more. */ +export const RETIRED_INTERFACES_SEGMENT = 'interfaces'; + +/** The query key that opens Studio's Changes drawer (`studioChangesLink.ts`). */ +export const STUDIO_CHANGES_PARAM = 'changes'; + +/** The one {@link STUDIO_CHANGES_PARAM} value the surface acts on: review the pending drafts. */ +export const STUDIO_CHANGES_REVIEW = 'review'; + +/** The query key that opens an item page's draft review in the "All metadata" area. */ +export const STUDIO_ITEM_REVIEW_PARAM = 'review'; + +/** The one {@link STUDIO_ITEM_REVIEW_PARAM} value the item page acts on. */ +export const STUDIO_ITEM_REVIEW_VALUE = '1'; + +/** The pillar keys (`StudioDesignSurface`'s `PILLARS`). */ +export type StudioPillarKey = 'data' | 'automations' | 'access'; + +/** + * ADR-0146 D1 — "A pillar type opened from the directory opens its pillar". + * Where an item of each type opens TODAY: the pillar that designs it. Every + * type not listed opens the area's generic item page. + * + * ⭐ This is the per-type switch of the Studio redesign. A designer card that + * moves a type to its metadata address deletes that type's row here, in the + * PR that ships the designer: every producer that calls + * {@link studioItemPath}, and the area's own pillar redirect + * (`areaItemPillarPath`), then open the metadata address together. + * + * objectstack#36502 — pages, dashboards, reports and views have no pillar + * since the Interfaces pillar retired. + */ +export const STUDIO_ITEM_PILLAR: Readonly> = Object.freeze({ + object: 'data', + flow: 'automations', + permission: 'access', +}); + +/** The pillar an item of `type` opens in today, or `null` when it opens the area's generic item page. */ +export function studioItemPillar(type: string): StudioPillarKey | null { + return Object.prototype.hasOwnProperty.call(STUDIO_ITEM_PILLAR, type) ? STUDIO_ITEM_PILLAR[type] : null; +} + +// --------------------------------------------------------------------------- +// The one path builder +// --------------------------------------------------------------------------- + +/** How the first segment after `/studio` is written. */ +export type StudioSegmentEncoding = + /** `encodeURIComponent` — what every package-id producer does. The default. */ + | 'component' + /** As given: the segment is already in its URL form (a route param read back, a reserved `~` segment). */ + | 'verbatim'; + +/** The parts after the path. */ +export interface StudioPathOptions { + /** The query without its `?`, or a `URLSearchParams` (serialised as `toString()` does). Empty adds nothing. */ + query?: string | URLSearchParams | null; + /** + * A search string appended exactly as given, `?` included (`location.search`). + * For a producer that carries the current query over untouched; not with `query`. + */ + search?: string | null; + /** The fragment, `#` included. */ + hash?: string | null; + /** How the first segment is written. Default `'component'`. */ + segmentEncoding?: StudioSegmentEncoding; +} + +/** + * A Studio address: `/studio`, then the scope segment (a package id, `~org`, + * `~all`), then a section (a pillar key, `metadata`), then a rest path already + * in its URL form (`object/account`), then the query and the fragment. Every + * part is optional from the right; a part after an absent one is not allowed + * (a section names nothing without its scope). + */ +export function studioPath( + segment?: string | null, + section?: string | null, + rest?: string | null, + options: StudioPathOptions = {}, +): string { + let path = STUDIO_ROOT_PATH; + if (segment) { + path += `/${options.segmentEncoding === 'verbatim' ? segment : encodeURIComponent(segment)}`; + if (section) { + path += `/${section}`; + if (rest) path += `/${rest}`; + } + } + const query = typeof options.query === 'string' ? options.query : options.query ? options.query.toString() : ''; + if (query) path += `?${query}`; + if (options.search) path += options.search; + if (options.hash) path += options.hash; + return path; +} + +// --------------------------------------------------------------------------- +// Landing, package, pillar +// --------------------------------------------------------------------------- + +/** The Studio landing, `/studio`, optionally with a query (`new=package`). */ +export function studioLandingPath(options: Omit = {}): string { + return studioPath(null, null, null, options); +} + +/** A package's Studio, `/studio/`: the route lands it on {@link STUDIO_HOME_PILLAR}. */ +export function studioPackagePath(packageId: string): string { + return studioPath(packageId); +} + +/** One pillar (or other section) of a scope, `/studio//`. */ +export function studioPillarPath(segment: string, pillar: string, options: StudioPathOptions = {}): string { + return studioPath(segment, pillar, null, options); +} + +/** A package's Studio home, `/studio//data`. */ +export function studioHomePath(packageId: string, options: StudioPathOptions = {}): string { + return studioPillarPath(packageId, STUDIO_HOME_PILLAR, options); +} + +// --------------------------------------------------------------------------- +// The `?surface=` deep link +// --------------------------------------------------------------------------- + +/** + * How a producer writes a `?surface=:` value. Three spellings + * reach the same surface today, and each is kept byte for byte: + * + * - `'component'`: the whole value through `encodeURIComponent`, + * `surface=object%3Aaccount`. The default; most producers. + * - `'name'`: the type and colon as written, the name through + * `encodeURIComponent`, `surface=object:account` (the app → Studio bridge, + * `appStudioObjectPath`). + * - `'form'`: `URLSearchParams` serialisation, with any qualifiers after + * it in the order given, `surface=object%3Aaccount&action=approve` + * (`switchedOffActionPath`). It differs from `'component'` for a space + * (`+`) and for `!'()~`. + */ +export type StudioSurfaceSpelling = 'component' | 'name' | 'form'; + +/** The `?surface=` query of one item, in one {@link StudioSurfaceSpelling}, with optional qualifiers (`action`, `view`, `nav`). */ +export function studioSurfaceQuery( + item: { type: string; name: string }, + spelling: StudioSurfaceSpelling = 'component', + qualifiers?: Readonly>, +): string { + if (spelling === 'form') { + return new URLSearchParams({ [DESIGNER_SURFACE_PARAM]: formatSurfaceParam(item), ...qualifiers }).toString(); + } + const value = + spelling === 'name' + ? `${item.type}:${encodeURIComponent(item.name)}` + : encodeURIComponent(formatSurfaceParam(item)); + let query = `${DESIGNER_SURFACE_PARAM}=${value}`; + for (const [key, qualifier] of Object.entries(qualifiers ?? {})) { + query += `&${encodeURIComponent(key)}=${encodeURIComponent(qualifier)}`; + } + return query; +} + +/** Options of an item address. */ +export interface StudioItemOptions { + /** How the `?surface=` value is written, when the item opens a pillar. Default `'component'`. */ + spelling?: StudioSurfaceSpelling; + /** Qualifiers after `?surface=`, when the item opens a pillar: `action`, `view`, `nav`. */ + qualifiers?: Readonly>; + /** How the scope segment is written. Default `'component'`. */ + segmentEncoding?: StudioSegmentEncoding; +} + +/** A pillar of a scope, opened on one item through its `?surface=` deep link. */ +export function studioPillarItemAddress( + segment: string, + pillar: string, + item: { type: string; name: string }, + options: StudioItemOptions = {}, +): string { + return studioPath(segment, pillar, null, { + query: studioSurfaceQuery(item, options.spelling, options.qualifiers), + segmentEncoding: options.segmentEncoding, + }); +} + +// --------------------------------------------------------------------------- +// The "All metadata" area +// --------------------------------------------------------------------------- + +/** The area's root of a scope, `/studio//metadata`. */ +export function studioMetadataAreaRoot(segment: string): string { + return studioPath(segment, STUDIO_METADATA_AREA); +} + +/** + * A path below the area's root, `rest` already in its URL form (`flow`, + * `object/account`, `''` for the root itself). + */ +export function studioMetadataAreaAddress(segment: string, rest: string, options: StudioPathOptions = {}): string { + return studioPath(segment, STUDIO_METADATA_AREA, rest, options); +} + +/** A type's list in the area, `/studio//metadata/`. */ +export function studioMetadataTypePath(segment: string, type: string): string { + return studioMetadataAreaAddress(segment, encodeURIComponent(type)); +} + +/** An item's generic page in the area, `/studio//metadata//`. */ +export function studioMetadataItemAddress(segment: string, type: string, name: string, options: StudioPathOptions = {}): string { + return studioMetadataAreaAddress(segment, `${encodeURIComponent(type)}/${encodeURIComponent(name)}`, options); +} + +// --------------------------------------------------------------------------- +// The item address — what the designer cards switch +// --------------------------------------------------------------------------- + +/** + * Where one item of a package opens today: its pillar on a `?surface=` deep + * link when {@link STUDIO_ITEM_PILLAR} names one for its type, otherwise its + * page in the "All metadata" area. `spelling` and `qualifiers` apply to the + * pillar address only. + */ +export function studioItemPath(packageId: string, type: string, name: string, options: StudioItemOptions = {}): string { + const pillar = studioItemPillar(type); + if (pillar) return studioPillarItemAddress(packageId, pillar, { type, name }, options); + return studioMetadataItemAddress(packageId, type, name, { segmentEncoding: options.segmentEncoding }); +} + +// --------------------------------------------------------------------------- +// The draft review links +// --------------------------------------------------------------------------- + +/** A package's Changes drawer, opened from outside its Studio: `/studio//data?changes=review`. */ +export function studioChangesReviewPath(packageId: string): string { + return studioHomePath(packageId, { query: `${STUDIO_CHANGES_PARAM}=${STUDIO_CHANGES_REVIEW}` }); +} + +/** An item's draft review in the area: `/studio//metadata//?review=1`. */ +export function studioItemReviewPath(packageId: string, type: string, name: string): string { + return studioMetadataItemAddress(packageId, type, name, { + query: `${STUDIO_ITEM_REVIEW_PARAM}=${STUDIO_ITEM_REVIEW_VALUE}`, + }); +} diff --git a/ui/packages/app-shell/src/views/studio-design/studioAddressTable.ts b/ui/packages/app-shell/src/views/studio-design/studioAddressTable.ts new file mode 100644 index 00000000000..1bbbe33b109 --- /dev/null +++ b/ui/packages/app-shell/src/views/studio-design/studioAddressTable.ts @@ -0,0 +1,264 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * The Studio address mapping table (objectstack#36895, Studio redesign epic + * #36890): every address family Studio answers to today, every `?surface=` + * spelling, and every query parameter, with what each one becomes when a + * designer card moves its type to the metadata address. + * + * The builders are in `studioAddress.ts`; this is their map. It is data a + * card reads before it switches a type, and data the code reads where the + * table decides something: the retired `/interfaces` redirect keeps exactly + * the parameters this table marks as surviving it + * ({@link STUDIO_RETIRED_INTERFACES_KEPT_PARAMS}). + * + * ## How a designer card switches its type + * + * 1. Delete the type's row from `STUDIO_ITEM_PILLAR` (`studioAddress.ts`). + * Every producer calling `studioItemPath`, and the "All metadata" area's + * pillar redirect (`areaItemPillarPath`), then open the metadata address + * together, so the two never bounce. + * 2. Carry each qualifier its row below lists onto the metadata address, or + * drop it, as the row's `onMetadataAddress` says. + * 3. Add the redirect from the pillar address in that same PR. + * 4. Update the type's row here: `today` becomes the metadata address. + * + * `studioAddressTable.test.ts` holds each row's example equal to its + * builder's output, so the table cannot drift from the code. + */ + +import { DESIGNER_SURFACE_PARAM } from '../metadata-admin/nav-selection.js'; +import { CATALOG_SCOPE_PARAM, ENVIRONMENT_SCOPE } from '../metadata-admin/catalog-scope.js'; +import { + DESIGNER_SURFACE_ACTION_PARAM, + DESIGNER_SURFACE_NAV_PARAM, + DESIGNER_SURFACE_VIEW_PARAM, +} from './useSurfaceDeepLink.js'; +import { STUDIO_NEW_PACKAGE_VALUE, STUDIO_NEW_PARAM } from './studioNewPackage.js'; +import { + RETIRED_INTERFACES_SEGMENT, + STUDIO_CHANGES_PARAM, + STUDIO_CHANGES_REVIEW, + STUDIO_HOME_PILLAR, + STUDIO_ITEM_REVIEW_PARAM, + STUDIO_ITEM_REVIEW_VALUE, + type StudioPillarKey, + type StudioSurfaceSpelling, +} from './studioAddress.js'; + +// --------------------------------------------------------------------------- +// Address families +// --------------------------------------------------------------------------- + +/** One shape of Studio address, as it is today. */ +export interface StudioAddressFamily { + /** Stable id. */ + readonly id: string; + /** Today's shape; `<…>` marks a variable part. */ + readonly today: string; + /** The `studioAddress.ts` builder that produces it. */ + readonly builder: string; + /** What the shape is for. */ + readonly meaning: string; +} + +export const STUDIO_ADDRESS_FAMILIES: readonly StudioAddressFamily[] = Object.freeze([ + { id: 'landing', today: '/studio', builder: 'studioLandingPath', meaning: 'The front door: pick or create a writable package.' }, + { + id: 'landing-new-package', + today: `/studio?${STUDIO_NEW_PARAM}=${STUDIO_NEW_PACKAGE_VALUE}`, + builder: 'studioLandingPath', + meaning: 'The front door with its create-package dialog open.', + }, + { id: 'package', today: '/studio/', builder: 'studioPackagePath', meaning: `A package's Studio; the route lands it on its home pillar, \`${STUDIO_HOME_PILLAR}\`.` }, + { id: 'pillar', today: '/studio//', builder: 'studioPillarPath', meaning: 'One pillar of a package: data, automations or access.' }, + { + id: 'pillar-item', + today: `/studio//?${DESIGNER_SURFACE_PARAM}=:`, + builder: 'studioItemPath', + meaning: 'A pillar opened on one item. The family the designer cards move, one type at a time (STUDIO_ITEM_TYPES).', + }, + { id: 'org-scope', today: '/studio/~org/automations', builder: 'studioOrgScopePath', meaning: 'The package-less scope: the organization\'s own flows.' }, + { + id: 'org-scope-item', + today: `/studio/~org/automations?${DESIGNER_SURFACE_PARAM}=flow:`, + builder: 'studioOrgScopePath', + meaning: 'A package-less flow. It has no package, so no metadata address of a package; it moves with the flow designer card.', + }, + { id: 'area-root', today: '/studio//metadata', builder: 'studioMetadataAreaRoot', meaning: 'The "All metadata" area of a package, or across packages.' }, + { id: 'area-type', today: '/studio//metadata/', builder: 'studioMetadataTypePath', meaning: "A type's list in the area." }, + { + id: 'area-item', + today: '/studio//metadata//', + builder: 'studioMetadataItemAddress', + meaning: "An item's page in the area: the metadata address every type moves to.", + }, + { + id: 'changes-review', + today: `/studio//${STUDIO_HOME_PILLAR}?${STUDIO_CHANGES_PARAM}=${STUDIO_CHANGES_REVIEW}`, + builder: 'studioChangesReviewPath', + meaning: "A package's Changes drawer, opened from outside its Studio. The server's draft review link (studioChangesReviewRoute in @objectstack/types) spells the same address.", + }, + { + id: 'item-review', + today: `/studio//metadata//?${STUDIO_ITEM_REVIEW_PARAM}=${STUDIO_ITEM_REVIEW_VALUE}`, + builder: 'studioItemReviewPath', + meaning: "An item's draft review. The server's draft review link (studioItemReviewRoute in @objectstack/types) spells the same address.", + }, + { + id: 'retired-interfaces', + today: `/studio//${RETIRED_INTERFACES_SEGMENT}[?…]`, + builder: 'retiredInterfacesTarget', + meaning: `The retired Interfaces pillar (objectstack#36502). Redirects to the package's \`${STUDIO_HOME_PILLAR}\` pillar, keeping only STUDIO_RETIRED_INTERFACES_KEPT_PARAMS.`, + }, +]); + +// --------------------------------------------------------------------------- +// Item types: where each opens today, and what it switches to +// --------------------------------------------------------------------------- + +/** One `?surface=` type: the pillar it opens today and the metadata address it moves to. */ +export interface StudioItemTypeRow { + /** The `?surface=` type. */ + readonly type: string; + /** The pillar that opens it today. */ + readonly pillar: StudioPillarKey; + /** Today's `?surface=` value. */ + readonly surface: string; + /** The qualifiers that ride beside `?surface=` for this type today. */ + readonly qualifiers: readonly string[]; + /** The `?surface=` spellings producers write today (`StudioSurfaceSpelling`). */ + readonly spellings: readonly StudioSurfaceSpelling[]; + /** The metadata address it moves to, or `null` when it is a pillar page with no item of its own. */ + readonly onMetadataAddress: string | null; +} + +export const STUDIO_ITEM_TYPES: readonly StudioItemTypeRow[] = Object.freeze([ + { + type: 'object', + pillar: 'data', + surface: 'object:', + qualifiers: [DESIGNER_SURFACE_VIEW_PARAM, DESIGNER_SURFACE_ACTION_PARAM, DESIGNER_SURFACE_NAV_PARAM], + spellings: ['component', 'name', 'form'], + onMetadataAddress: '/studio//metadata/object/', + }, + { + type: 'flow', + pillar: 'automations', + surface: 'flow:', + qualifiers: [], + spellings: ['component'], + onMetadataAddress: '/studio//metadata/flow/', + }, + { + type: 'permission', + pillar: 'access', + surface: 'permission:', + qualifiers: [], + spellings: ['component'], + onMetadataAddress: '/studio//metadata/permission/', + }, + { + // The Access pillar's organization-wide defaults overview. Not a metadata + // item: the permission designer card decides where it lives. + type: 'owd', + pillar: 'access', + surface: 'owd:overview', + qualifiers: [], + spellings: ['component'], + onMetadataAddress: null, + }, +]); + +// --------------------------------------------------------------------------- +// Query parameters +// --------------------------------------------------------------------------- + +/** One query parameter a Studio address carries. */ +export interface StudioQueryParamRow { + readonly key: string; + /** The values it takes. */ + readonly values: string; + /** Where it is read, and what it means there. */ + readonly meaning: string; + /** + * What happens to it when an item moves to its metadata address: + * `verbatim` — carried as it is; `qualifier` — rides beside `?surface=`, and + * the designer card maps it onto its designer or drops it; `replaced` — the + * metadata address itself carries what it said. + */ + readonly onMetadataAddress: 'verbatim' | 'qualifier' | 'replaced'; + /** Whether the retired `/interfaces` redirect keeps it. */ + readonly keptOnRetiredInterfaces: boolean; +} + +export const STUDIO_QUERY_PARAMS: readonly StudioQueryParamRow[] = Object.freeze([ + { + key: DESIGNER_SURFACE_PARAM, + values: ':, owd:overview', + meaning: 'A pillar opened on one item (STUDIO_ITEM_TYPES).', + onMetadataAddress: 'replaced', + keptOnRetiredInterfaces: false, + }, + { + key: DESIGNER_SURFACE_VIEW_PARAM, + values: '.', + meaning: 'The list view an object surface shows (Data pillar).', + onMetadataAddress: 'qualifier', + keptOnRetiredInterfaces: false, + }, + { + key: DESIGNER_SURFACE_ACTION_PARAM, + values: '', + meaning: "An object surface opened on its Actions view at one action (Data pillar).", + onMetadataAddress: 'qualifier', + keptOnRetiredInterfaces: false, + }, + { + key: DESIGNER_SURFACE_NAV_PARAM, + values: '