Setu-TS
    Preparing search index...

    Function installRequestIdentityGuard

    • Installs the single-write guard once on a request class's prototype, so every instance is guarded from construction and sealRequestIdentity has nothing to do per request.

      For the framework's own request classes — the runtime's served request, the kernel's inject() request and @setu-ts/testing's mock — each calls it first in its constructor; after the first construction the call is one Object.hasOwn check. (Not a static {} block: that would run at import, an effect a tree-shakeable package must not have.) Sealing every request instance separately cost 3% of request CPU on Bun. The accessors are inherited and non-enumerable, like any class getter: Object.keys(request) and JSON.stringify(request) do not list user, tenant or locale on such a request.

      An instance whose class extends the guarded one, or that holds its own user, tenant or locale property, is not covered by the prototype and is sealed per instance as before. A class must therefore declare those fields with declare, never as initialized class fields, which would create own properties.

      Parameters

      • prototype: object

        The prototype of a class whose instances are requests

      Returns void

      If the prototype is Object.prototype or Function.prototype — the guard is non-configurable, so it would bind every object or function in the process for good — or already defines user, tenant or locale

      0.11.0