मुख्य सामग्री पर जाएँ
Skillpedia
API और सर्वर (backend)8.1k · #12590

webiny-use-case-pattern

यह क्या करती है

यह स्किल आपके AI को Webiny बैकएंड में एक बिज़नेस ऑपरेशन लिखते समय मार्गदर्शन देती है। यह उन डेवलपर्स के लिए है जो यूज़ केस और उनके पीछे के repositories बना या बदल रहे हैं।

कब इस्तेमाल करें

  • ✓जब आपको कोई नया बिज़नेस ऑपरेशन चाहिए, जैसे कोई रिकॉर्ड बनाना या प्रकाशित करना।
  • ✓जब आप किसी मौजूदा यूज़ केस को बदलना या उसे decorate करना चाहें।
  • ✓जब किसी यूज़ केस को CMS repositories के ज़रिए डेटा सहेजना हो।

Skill का लिंक

https://github.com/webiny/webiny-js/blob/next/skills/user-skills/api/use-case-pattern/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/webiny/webiny-js/blob/next/skills/user-skills/api/use-case-pattern/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“एक यूज़ केस लिखिए जो CMS एंट्री प्रकाशित करे, और अगर वह पहले से प्रकाशित है तो साफ़ त्रुटि लौटाए।”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

स्किल एक execute method, टाइप्ड इनपुट, सफलता या विफलता बताने वाले नतीजे और कोड वाले error types समझाती है। वह यह भी दिखाती है कि यूज़ केस दूसरे कोड में कैसे inject होते हैं।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।

UseCase Pattern

What It Is

A UseCase is a single-method orchestrator that encapsulates one business operation (e.g., CreateTenantUseCase, PublishEntryUseCase). Each UseCase is a DI abstraction with an execute method that returns Result<T, E>.

Interface Shape

interface SomeUseCase.Interface {
    execute(input: Input): Promise<Result<ReturnType, ErrorType>>;
}
  • Input — a typed object specific to the use case
  • Result — always returns Result<T, E> from webiny/api
  • Error — extends BaseError with a unique code

How to Use a UseCase

UseCases are injected as dependencies into EventHandlers, other UseCases, or GraphQL resolvers via DI.

import { SomeUseCase } from "webiny/api/<category>";
import { SomeEventHandler } from "webiny/api/<category>";

class MyHandler implements SomeEventHandler.Interface {
  constructor(private someUseCase: SomeUseCase.Interface) {}

  async handle(event: SomeEventHandler.Event) {
    const result = await this.someUseCase.execute({/* input */});

    if (result.isFail()) {
      console.error(result.error.message);
      return;
    }

    const value = result.value;
    // ... use value
  }
}

export default SomeEventHandler.createImplementation({
  implementation: MyHandler,
  dependencies: [SomeUseCase]
});

How to Override a UseCase

To replace the default implementation, register your own:

import { SomeUseCase } from "webiny/api/<category>";

class CustomImplementation implements SomeUseCase.Interface {
  async execute(input) {
    // Custom logic
    return Result.ok(/* ... */);
  }
}

export default SomeUseCase.createImplementation({
  implementation: CustomImplementation,
  dependencies: []
});

Registration

YOU MUST include the full file path with the .ts extension in the src prop. For example, use src={"@/extensions/my-extension.ts"}, NOT src={"@/extensions/my-extension"}. Omitting the file extension will cause a build failure.

YOU MUST use export default for the createImplementation() call when the file is targeted directly by an Extension src prop. Using a named export (export const Foo = SomeFactory.createImplementation(...)) will cause a build failure. Named exports are only valid inside files registered via createFeature.

// In your app's configuration
<Api.Extension src={"@/extensions/my-extension.ts"} />

Deploy with: yarn webiny deploy api --env=dev


Error Handling Pattern

Domain-Specific Errors

Every feature defines errors extending BaseError. Never use generic Error for validation or business rule failures.

// domain/errors.ts
import { BaseError } from "webiny/api";

export class EntityNotFoundError extends BaseError {
  override readonly code = "Entity/NotFound" as const;
  constructor(id: string) {
    super({ message: `Entity with id "${id}" was not found!` });
  }
}

export class EntityPersistenceError extends BaseError<{ error: Error }> {
  override readonly code = "Entity/Persist" as const;
  constructor(error: Error) {
    super({ message: error.message, data: { error } });
  }
}

export class EntityValidationError extends BaseError<{ message: string }> {
  override readonly code = "Entity/Validation" as const;
  constructor(message: string) {
    super({ message, data: { message } });
  }
}

Typed Error Unions in Abstractions

Define an IErrors interface mapping error names to types, then create a union via [keyof IErrors]:

// features/createEntity/abstractions.ts
import { createAbstraction, Result } from "webiny/api";
import { NotAuthorizedError } from "webiny/api/security";
import {
  EntityPersistenceError,
  EntityModelNotFoundError,
  EntityCreationError
} from "~/api/domain/errors.js";

// REPOSITORY errors
export interface ICreateEntityRepositoryErrors {
  persistence: EntityPersistenceError;
  modelNotFound: EntityModelNotFoundError;
  creation: EntityCreationError;
}

type RepositoryError = ICreateEntityRepositoryErrors[keyof ICreateEntityRepositoryErrors];

export interface ICreateEntityRepository {
  execute(entity: Entity): Promise<Result<Entity, RepositoryError>>;
}

export const CreateEntityRepository = createAbstraction<ICreateEntityRepository>(
  "MyExt/CreateEntityRepository"
);

export namespace CreateEntityRepository {
  export type Interface = ICreateEntityRepository;
  export type Error = RepositoryError;
  export type Return = Promise<Result<Entity, RepositoryError>>;
}

// U
अक्सर पूछे जाने वाले सवाल

यूज़ केस क्या लौटाता है?

एक नतीजा जो या तो सफल मान होता है या error, इसलिए कॉलर को विफलता जाँचनी ही होती है।

क्या डिफ़ॉल्ट यूज़ केस बदला जा सकता है?

हाँ। स्किल बताती है कि नया विकल्प कैसे रजिस्टर करें।

repositories कैसे इस्तेमाल होते हैं?

स्किल CMS के ज़रिए डेटा सहेजने वाले repositories और entry mappers कवर करती है।

जानकारी

लेखक का मूल विवरण

UseCase implementation pattern — DI, Result handling, error types, decorators, CMS repositories, entry mappers, and schema-based permissions. Use this skill to implement, inject, override, or decorate any Webiny UseCase, or to build repositories that persist data via CMS.

repo: webiny/webiny-js

लोकप्रियता

GitHub स्टार
8.1k
रैंकिंग में स्थान
#12590
लाइसेंस
—
अपडेट की गई
2/11/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

prd-to-plan

8.1k

यह आपके एजेंट को प्रोडक्ट आवश्यकताओं के दस्तावेज़ को छोटे, एंड-टू-एंड स्लाइस की चरणबद्ध योजना में बदलने में मदद करती है, जो Markdown फ़ाइल में सहेजी जाती है।

प्रोडक्टिविटीटास्क और प्रोजेक्ट

webiny-admin-architect

8.1k

यह आपके एजेंट को Webiny प्लेटफ़ॉर्म के लिए एडमिन स्क्रीन बनाना सिखाती है, उसकी बिज़नेस लॉजिक परतों और presenter पैटर्न का उपयोग करके।

कोडिंगवेबसाइट और UI (frontend)

webiny-admin-permissions

8.1k

यह आपके एजेंट को Webiny एडमिन स्क्रीन में अनुमति नियंत्रण जोड़ना सिखाती है, जिसमें अपने-आप बनने वाले अनुमति फ़ॉर्म और दिखाने-छिपाने की जाँच शामिल हैं।

कोडिंगवेबसाइट और UI (frontend)

webiny-form-model

8.1k

यह आपके एजेंट को Webiny में declarative field builder, layouts, validation और शर्त वाले नियमों से फ़ॉर्म बनाना सिखाती है।

कोडिंगवेबसाइट और UI (frontend)

मिलती-जुलती skills