Skip to content

Releases: DimaCrafter/dc-api-core

TypeScript support & Validators

22 Jun 19:50
Compare
Choose a tag to compare

TypeScript support:

  • Built-in TypeScript runner using ts-node
  • Database connection experimental typings
  • Some core typings

To enable TypeScript support install ts-node and typescript packages and add "typescript": true to your config.json.

Validators:

  • Basic experimental validator

Special Data<Validated> and Query<Validated> types are designed to be used as action parameters in any combination. Will be documented soon (I hope). Syntax can be changed in later releases.

Example validator class:

export class TestPayload extends Validated {
    // If this.data.a not passed, ValidationError will be returned.
    @whenEmpty('Parameter is required', 'a')
    // If this getter will throw error, ValidationError with original error's message will be returned.
    // You can replace "undefined" with desired response message.
    @whenError(undefined, 'a')
    get asyncOne () {
        if (this.raw.a == 'fail') {
            throw new Error('some error');
        }
        // If getter returns Promise, it will be awaited before calling getter below
        return sleep(1000, this.raw.a);
    }

    get asyncDependent () {
        // this.ctx contains awaited values of getters/fields above
        return `Wrapped: ${this.ctx.asyncOne**2}`;
    }
}

Usage:

import { Data, HttpController, Query } from 'dc-api-core'
import { TestPayload } from '../validators/test'

export class Test extends HttpController {
    // Core will call action with validated data only after successfully awaiting all getters/fields.
    // So, if payload is { a: 42 } someData will be equal to { asyncOne: 42, asyncDependent: 'Wrapped: 1764' }
    invokeMe (someData: Data<TestPayload>) {
        return { receivedData: someData.asyncDependent };
    }
}

Bundle generator:

Use dc-api-core --ts-build to create bundle. Available only within TypeScript setup.

Optional flag Description
--keep-uws Keep all versions of uWS.js binaries (not only for current environment)
--sourcemap Generate source map
--no-minify Disable bundle minification

Misc:

  • Removed legacy config key supportOldCase
  • Loaders refactoring
  • Exposed uWS application (dc-api-core/app)
  • Removed unused init command
  • Development mode fixes
  • Small controller's context fixes
  • Added sleep utility (dc-api-core/utils)

Improvements and remove of deprecations

22 Jun 19:21
Compare
Choose a tag to compare
  • Migrated query parser to URLSearchParams
  • Redirect CORS fix
  • Added simple typings for config
  • Added session stores
  • Deprecated hardcoded "Socket" controller, improved WebSockets handling
  • Improved error reporting, camelToKebab
  • Local plugins

Added experimental DB model syntax

23 Feb 18:05
Compare
Choose a tag to compare
v0.3.4

Added experimental DB model syntax

Added routing & improvements

05 Jul 09:40
Compare
Choose a tag to compare
  • Controllers improvements:
    • Added routing
    • Socket controller improvements
    • Session fix
    • Request dispatch and content-type matching fixes
    • Added header method to controller context
  • Database improvements:
    • Multi-database reusing fix
    • Added templated database connections
  • Misc:
    • Now port can be taken from environment
    • New development mode
    • New logger
      Better color matching (for different environments).
    • Removed response templating
      Now response doesn't contents HTTP status code and success boolean, only serialized message.

File upload support

08 Dec 12:15
Compare
Choose a tag to compare
v0.2.2-8

Now using X-Real-IP header in docker

Controller context fixes

16 Aug 09:28
Compare
Choose a tag to compare
v0.2.1-4

Now session stores token

Now using μWS.js

16 Aug 09:33
Compare
Choose a tag to compare
v0.2.0-4

Small changes

Added plugin system

19 Jan 10:51
Compare
Choose a tag to compare
v0.1.9-3

Added db connections reusing

v0.1.8-2

19 Jan 11:02
Compare
Choose a tag to compare
devMode now deprecated

Added HTTPS support

26 Oct 14:30
Compare
Choose a tag to compare
v0.1.7

Added HTTPS support