Skip to content

v0.7.13

Choose a tag to compare

@github-actions github-actions released this 03 Oct 06:06
· 30 commits to main since this release

ExisJS Release v0.7.13

Release Date: 2026-10-02
Type: Feature Release & Schema Engine Upgrades
Affected Packages: exisjs, create-exisjs


Highlights

  • tex.discriminatedUnion Polymorphic Schema Branching:

    • Added first-class support for discriminated unions via tex.discriminatedUnion(discriminator, variants).
    • Performs high-performance synchronous and asynchronous variant dispatching by inspecting literal and enum discriminator tags.
    • Automatically translates to OpenAPI 3.1 oneOf with discriminator: { propertyName } mappings.
    • Provides clear diagnostic errors (MISSING_DISCRIMINATOR, INVALID_DISCRIMINATOR_VALUE) on malformed payloads.
  • tex Schema Composition (extend, merge, pick, omit):

    • schema.extend(extension): Extends an existing schema with additional or overridden field definitions while preserving type inference.
    • schema.merge(otherSchema): Deeply merges two TexEngine schemas into a unified validator.
    • schema.pick(keys) & schema.omit(keys): Selects or removes specific keys from existing schemas with zero boilerplate.
  • Field-Level and Schema-Level Data Transformations:

    • TexType.prototype.transform(fn): Executes post-validation field transformations (e.g. string sanitization, trimming, casing, mathematical operations).
    • TexEngine.prototype.transform(fn): Returns a TexTransformedEngine allowing full schema output reshaping.
  • Explicit Coercion Primitives (tex.coerce.*):

    • Added the tex.coerce namespace for clean coercion of incoming string query parameters, headers, and form-data: tex.coerce.number(), tex.coerce.boolean(), tex.coerce.date(), tex.coerce.string().
  • Universal Multi-Validator OpenAPI 3.1 Duck Typing:

    • schemaToOpenApi() now supports native TexEngine / TexType / TexDiscriminatedUnionEngine as well as third-party schema libraries like Zod (ZodString, ZodNumber, ZodBoolean, ZodDate, ZodEnum, ZodLiteral, ZodArray, ZodOptional, ZodNullable, ZodUnion, ZodDiscriminatedUnion, ZodRecord, ZodEffects, ZodObject), raw JSON Schema, and plain property maps with zero boilerplate.
    • Extracts field documentation metadata (.describe() and .example()), boundaries (min, max, minLength, maxLength), and formats (email, uuid, date-time).
  • Controller Pipe Evaluation & Query Coercion Fixes:

    • Fixed pipe resolution precedence in controller-registrar.ts so validation schemas (.parse()) are executed properly when passed to @Body(), @Query(), @Param(), avoiding conflicts with builder .transform() methods.
    • Added automatic query and path parameter string-to-number/boolean coercion when TexEngine schemas are injected as route pipes.
    • Resolved TS2300 duplicate identifier between internal storage and the .example() fluent builder method in TexType.
  • Raw Body Streaming & Controller Parameter Decorator (@RawBody() & req.buffer()):

    • Added @RawBody() decorator for OOP controllers to access raw request buffers or UTF-8 strings (@RawBody() buffer: Buffer or @RawBody('string') text: string).
    • Added req.buffer() helper on ExisRequest for high-throughput webhook payload handling (e.g. Stripe, GitHub, HMAC signing).
    • Ensured full compatibility with all HTTP method decorators (@All(), @Head(), @Options(), @Get(), @Post(), @Put(), @Patch(), @Delete()).
  • Dependency Injection & IoC Custom Providers & Contextual inject():

    • Added first-class support for custom provider objects:
      • Value Providers: { provide: Token, useValue: T }
      • Factory Providers with Injected Dependencies: { provide: Token, useFactory: (...deps) => T, inject: [DepToken1, DepToken2] }
      • Existing Token Aliases: { provide: Token, useExisting: TargetToken }
      • Class Providers: { provide: Token, useClass: ClassConstructor }
    • Extended app.provide(), @Module({ providers: [...] }), and defineModule({ providers: [...] }) to accept single provider objects in addition to [Token, def] tuples.
    • Re-exported contextual inject(Token) helper in exisjs/router and exisjs/di for clean functional dependency access.

Key Improvements & Details

1. Discriminated Unions

import { tex } from 'exisjs/validator'

const SquareSchema = tex.object({
  kind: tex.literal('square'),
  size: tex.number(),
})

const CircleSchema = tex.object({
  kind: tex.literal('circle'),
  radius: tex.number(),
})

export const ShapeSchema = tex.discriminatedUnion('kind', [
  SquareSchema,
  CircleSchema,
])

2. Schema Composition & Transformations

import { tex } from 'exisjs/validator'

const BaseUser = tex.object({
  id: tex.uuid(),
  name: tex.string({ min: 2 }),
  email: tex.email(),
})

// Extend with additional fields
export const AdminUser = BaseUser.extend({
  role: tex.enum(['admin', 'superadmin']),
  permissions: tex.array(tex.string()),
})

// Pick only public fields & transform output
export const PublicProfile = BaseUser.pick(['name', 'email']).transform((user) => ({
  ...user,
  displayName: user.name.toUpperCase(),
}))

3. Explicit Coercion Namespace

import { tex } from 'exisjs/validator'

export const QueryFilterSchema = tex.object({
  page: tex.coerce.number({ default: 1 }),
  active: tex.coerce.boolean({ default: true }),
  createdAfter: tex.coerce.date({ optional: true }),
})

4. Custom Providers & Dependency Injection

import { exis } from 'exisjs'
import { inject } from 'exisjs/di'

export default exis({
  onStart(app) {
    app.provide({
      provide: 'CONFIG',
      useValue: { port: 3000, region: 'us-east-1' },
    })

    app.provide({
      provide: 'DATABASE',
      useFactory: (cfg) => createPool(cfg),
      inject: ['CONFIG'],
    })

    app.provide({
      provide: 'DB',
      useExisting: 'DATABASE',
    })
  },
})

5. Raw Body Webhook Handling

import { Controller, Post, RawBody, Headers } from 'exisjs/decorators'

@Controller('/webhooks')
export class WebhookController {
  @Post('/stripe')
  handleStripe(
    @RawBody() payload: Buffer,
    @Headers('stripe-signature') signature: string
  ) {
    return stripe.webhooks.constructEvent(payload, signature, endpointSecret)
  }
}

What's Changed

  • fix(deps): bump uWebSockets.js from v20.70.0 to v20.71.0 by @dependabot[bot] in #58
  • fix(deps-dev): bump @napi-rs/cli from 3.10.4 to 3.10.5 by @dependabot[bot] in #59

Full Changelog: v0.7.12...v0.7.13