Core - v1.0.0
    Preparing search index...

    Class ServiceAbstract

    Base class for every service — an adapter's and an application's alike.

    A service holds no per-request state: the runtime handle arrives as an argument to each method, so one instance can be created at module scope and reused. What this base contributes is the response contract — every method returns an APIResponse, built through Service.ok or Service.fail rather than assembled by hand, so a caller can map success onto a status code without reading each service.

    export class ProfileService extends Service {
    public async get(env: Env, id: string): Promise<APIResponse> {
    const profile = await cache.get<Profile>(env, `profile:${id}`)

    return profile ? this.ok('Profile found', profile) : this.fail(`Profile ${id} not found`)
    }
    }

    Bayu Dwiyan Satria

    1.0.0

    1.0.0

    Index
    • Builds a failed response.

      Reserved for outcomes the caller asked for and did not get — a missing row, an absent object. Faults the caller cannot act on should throw instead, so they surface as a 500 rather than a well-formed false.

      Type Parameters

      • T = unknown

      Parameters

      • message: string

        Human-readable description of what went wrong.

      • data: T = null

        Payload returned to the caller.

      Returns APIResponse

      The response, with success set to false.

    • Builds a successful response.

      Type Parameters

      • T = unknown

      Parameters

      • message: string

        Human-readable description of what happened.

      • data: T = null

        Payload returned to the caller.

      Returns APIResponse

      The response, with success set to true.