Repository navigation
Studio: enforce package namespace prefix at authoring time (companion to framework#2694) #2349
Description
Console-side companion to framework#2694 (publish-time namespace-prefix enforcement). Give authors the compliant namespace at design time in Studio's dialogs, so they never build a prefix-less object and only discover it when publish rejects the batch.
Framework side (framework#2694)
-
New writable packages: if the manifest has no
namespace, one is derived from the last id segment (com.example.leave→leave) and persisted; an explicitly declared namespace always wins (HotCRMcrmuntouched). -
publishPackageDraftsrejects any draft whose object name lacks the<namespace>_prefix — errorObject 'ticket' is missing the package namespace prefix. Rename it to 'hr_ticket' (namespace = 'hr')., codeNAMESPACE_PREFIX, whole batch fails atomically. -
Two reusable helpers live in
packages/spec/src/kernel/namespace-prefix.ts, exported from@objectstack/spec/kernel:deriveNamespaceFromPackageId(packageId): string | null— last dot-segment, lowercased and sanitized to^[a-z][a-z0-9_]{1,19}$.validateObjectNamespacePrefix(objectName, namespace): string | null— returns an actionable message ornull; allowssys_*, flags legacy<ns>__<short>FQNs.
objectui must reuse these two — do not re-implement the rule (AGENTS.md #0/#0.1: one spec-owned contract, no second de-facto dialect).
⛔ Blocked on: spec publish
These helpers are not yet in any published @objectstack/spec (npm latest is @objectstack/spec@12.6.0; this repo depends on ^12.3.0 — neither has them). framework#2694 is a minor bump, so they'll land in a new version (likely 12.7.0). Do not start until that version is published to npm — importing @objectstack/spec/kernel before then breaks typecheck/build/tests and can't be browser-verified or merged.
objectui changes needed (once spec publishes)
-
Bump the dep — raise
@objectstack/specinpackages/app-shell/package.jsonto the version containing the helpers (mind the AGENTS.md version-alignment rule for the fixed release group). -
New-package dialogs — add a
namespacefield (both writable-base creation entry points):packages/app-shell/src/views/studio-design/BuilderLanding.tsx— the inline name+id creator (createBasePackage); this is the "只有名称+包 ID 两个字段" surface from the task.packages/app-shell/src/views/metadata-admin/PackagesPage.tsxCreatePackageDialog— the top-bar package-switcher "+ new" (POSTs{ manifest: {...} }).packages/app-shell/src/views/studio-design/packages-io.ts— thread anamespaceparam throughcreateBasePackage(id, name)into the POST body.- Field behavior: default =
deriveNamespaceFromPackageId(packageId), live-updating with the package-id input until the user edits it; editable; validated against^[a-z][a-z0-9_]{1,19}$(2–20 chars); hint text "所有对象名将以<namespace>_开头(如leave_request)". Putnamespaceinto the POST/api/v1/packagesmanifest (framework also back-derives, but sending it explicitly is clearer).
-
New-object dialog — auto-prefix the identifier —
StudioDesignSurface.tsx"+ new object" (~L1825, viaCreateItemDialog). On submit, runvalidateObjectNamespacePrefix(name, namespace); if non-compliant, prepend<namespace>_(don't double-prefix an already-compliant name). Read the current package's namespace from its manifest viaGET /api/v1/packages. Goal: an author can never produce a prefix-less object, and never eats aNAMESPACE_PREFIXrejection at publish. -
Publish-failure display — verify that a
failed[]entry withcode: NAMESPACE_PREFIXshows itserrorcopy inline in the publish result (should already be covered by the inline-error work in feat(types)!: adopt @objectstack/spec 15; drop value-erased spec/ui…Schemare-exports (#2561) #2589/fix(studio): surface spec-validation failures on the field at save/publish #2234 — confirm, don't rebuild).
Acceptance
- New writable package: the
namespacefield defaults to the id-derived value, tracks the id input until touched, and is editable + validated. - New object: the identifier is auto-prefixed with the current package's namespace; already-compliant names are not double-prefixed.
- Bypassing the UI (create a prefix-less object directly via API) and publishing surfaces the
NAMESPACE_PREFIXerror message inline in the publish result. - No renderer-side re-implementation of the derive/validate rule — both come from
@objectstack/spec/kernel.
Refs framework#2694.
Activity
feat(studio): enforce package namespace prefix at authoring time (fra…