Releases: DimaCrafter/dc-api-core
Releases · DimaCrafter/dc-api-core
TypeScript support & Validators
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
- 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
v0.3.4 Added experimental DB model syntax
Added routing & improvements
- 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 andsuccess
boolean, only serialized message.
File upload support
v0.2.2-8 Now using X-Real-IP header in docker
Controller context fixes
v0.2.1-4 Now session stores token
Now using μWS.js
v0.2.0-4 Small changes
Added plugin system
v0.1.9-3 Added db connections reusing
v0.1.8-2
devMode now deprecated
Added HTTPS support
v0.1.7 Added HTTPS support