Skip to content

feat(api-core): add injectable DateFormatter + StringFormatter/Slugify - #5526

Closed
adrians5j wants to merge 1 commit into
release/6.5.0from
claude/api-core-formatters
Closed

feat(api-core): add injectable DateFormatter + StringFormatter/Slugify#5526
adrians5j wants to merge 1 commit into
release/6.5.0from
claude/api-core-formatters

Conversation

@adrians5j

Copy link
Copy Markdown
Member

Summary

Backend counterpart to the admin-side formatting features (#5512, #5517). Brings DateFormatter, StringFormatter, and Slugify to @webiny/api-core so server code gets the same injectable, decoratable formatting.

Features (@webiny/api-core)

  • StringFormatter — consumer-facing string-transform API; exposes slugify() today, more methods later. Delegates to Slugify.
  • Slugify — single-method (execute()) feature holding Webiny's canonical slug options; the decorate seam behind StringFormatter.slugify().
  • DateFormatter — deterministic absolute date/time formatting (UTC, YYYY-MM-DD HH:mm), decoratable. No viewer-locale dependence, unlike the admin side.

All three register with ApiCoreFeature (always available). Same shape as the admin features, using api-core's @webiny/feature/api DI. No hooks (no React) — backend consumers inject the abstraction via a feature's dependencies.

Usage

class MyRepositoryImpl {
    constructor(private stringFormatter: StringFormatter.Interface) {}

    private makeSlug(name: string) {
        return this.stringFormatter.slugify(name);
    }
}
// dependencies: [..., StringFormatter]

Override (per project) — decorate the fine-grained seam

const MySlugify = Slugify.createDecorator(() => {
    return {
        execute: value => {
            return value.trim().toLowerCase().replace(/\s+/g, "_");
        }
    };
});

container.registerDecorator(MySlugify);

Migrated

  • CreateGroupRepository (api-headless-cms) now injects StringFormatter instead of importing the toSlug util.

Left as-is on purpose

  • The contentModelGroup zod validation schema keeps using the toSlug util directly — it is a pure schema factory with no DI seam (mirrors the admin-side pure-util exceptions like PagePath).

Docs

  • Added StringFormatter / Slugify / DateFormatter to ai-context/core-features-reference.md.

Testing

  • yarn check -p @webiny/api-core / -p @webiny/api-headless-cms
  • contentModelGroup.crud.test.ts — 9 passed (exercises group create → CreateGroupRepository resolving StringFormatter from the container and slugifying end-to-end).
  • helpers/toSlug.test.ts — 2 passed (util retained for the validation schema).
  • yarn lint / yarn format / yarn adio

🤖 Generated with Claude Code

Brings the same formatting utilities added on the admin side to the backend, so
server code gets the same injectable, decoratable formatting via api-core's DI.

- StringFormatter — consumer-facing string-transform API; exposes slugify()
  today, more methods later. Delegates to the fine-grained Slugify feature.
- Slugify — single-method feature (execute()) holding Webiny's canonical slug
  options; the decorate seam behind StringFormatter.slugify().
- DateFormatter — deterministic absolute date/time formatting (UTC), decoratable.
- All three register with ApiCoreFeature (always available) and are consumed by
  injecting the abstraction via a feature's `dependencies`.
- Migrated the DI-connected backend slug caller: CreateGroupRepository now injects
  StringFormatter instead of importing the toSlug util.
- Documented the new features in ai-context/core-features-reference.md.

Left as-is on purpose: the contentModelGroup zod validation schema keeps using
the toSlug util directly — it is a pure schema factory with no DI seam (mirrors
the admin-side pure-util exceptions).

Follows the admin-side PRs (#5512 DateFormatter, #5517 StringFormatter/Slugify).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@adrians5j
adrians5j force-pushed the claude/api-core-formatters branch from 8206e2d to 51f603b Compare July 31, 2026 15:37
@adrians5j adrians5j added this to the 6.5.0 milestone Aug 2, 2026
@adrians5j

Copy link
Copy Markdown
Member Author

/vitest

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

Vitest tests have been initiated (for more information, click here). ✨

Group Status
No storage ❌ 44/57 passed
DDB ✅ 17/17 passed
DDB+OS ❌ 18/19 passed
SQL ✅ 10/10 passed
PGlite ✅ 10/10 passed
❌ Failed packages

No storage

  • api-file-manager-s3
  • api-website-builder-workflows

@adrians5j

Copy link
Copy Markdown
Member Author

Superseded by #5549, which targets next (this targeted release/6.5.0). Rebased both admin and api-core changes into that single PR.

@adrians5j adrians5j closed this Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants