Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

Studio: enforce package namespace prefix at authoring time (companion to framework#2694) #2349

Closed

Description

@os-zhuang

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 (HotCRM crm untouched).

  • publishPackageDrafts rejects any draft whose object name lacks the <namespace>_ prefix — error Object 'ticket' is missing the package namespace prefix. Rename it to 'hr_ticket' (namespace = 'hr')., code NAMESPACE_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 or null; allows sys_*, 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)

  1. Bump the dep — raise @objectstack/spec in packages/app-shell/package.json to the version containing the helpers (mind the AGENTS.md version-alignment rule for the fixed release group).

  2. New-package dialogs — add a namespace field (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.tsx CreatePackageDialog — the top-bar package-switcher "+ new" (POSTs { manifest: {...} }).
    • packages/app-shell/src/views/studio-design/packages-io.ts — thread a namespace param through createBasePackage(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)". Put namespace into the POST /api/v1/packages manifest (framework also back-derives, but sending it explicitly is clearer).
  3. New-object dialog — auto-prefix the identifier — StudioDesignSurface.tsx "+ new object" (~L1825, via CreateItemDialog). On submit, run validateObjectNamespacePrefix(name, namespace); if non-compliant, prepend <namespace>_ (don't double-prefix an already-compliant name). Read the current package's namespace from its manifest via GET /api/v1/packages. Goal: an author can never produce a prefix-less object, and never eats a NAMESPACE_PREFIX rejection at publish.

  4. Publish-failure display — verify that a failed[] entry with code: NAMESPACE_PREFIX shows its error copy 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 …Schema re-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 namespace field 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_PREFIX error 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

  1. self-assigned this
    on Jul 15, 2026
  2. added a commit that references this issue on Jul 15, 2026
    6966e18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions