Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 589cb7d579 | |||
| 3680ad1914 | |||
| 96e13d85fc | |||
| 5a9283ad85 | |||
| b1ea489ccb | |||
| c3f2779650 |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@extollo/lib",
|
"name": "@extollo/lib",
|
||||||
"version": "0.5.5",
|
"version": "0.5.8",
|
||||||
"description": "The framework library that lifts up your code.",
|
"description": "The framework library that lifts up your code.",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"types": "lib/index.d.ts",
|
"types": "lib/index.d.ts",
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
/**
|
/**
|
||||||
* Base type for an API response format.
|
* Base type for an API response format.
|
||||||
*/
|
*/
|
||||||
export interface APIResponse {
|
export interface APIResponse<T> {
|
||||||
success: boolean,
|
success: boolean,
|
||||||
message?: string,
|
message?: string,
|
||||||
data?: any,
|
data?: T,
|
||||||
error?: {
|
error?: {
|
||||||
name: string,
|
name: string,
|
||||||
message: string,
|
message: string,
|
||||||
@@ -17,7 +17,7 @@ export interface APIResponse {
|
|||||||
* @param {string} displayMessage
|
* @param {string} displayMessage
|
||||||
* @return APIResponse
|
* @return APIResponse
|
||||||
*/
|
*/
|
||||||
export function message(displayMessage: string): APIResponse {
|
export function message(displayMessage: string): APIResponse<void> {
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
message: displayMessage,
|
message: displayMessage,
|
||||||
@@ -29,7 +29,7 @@ export function message(displayMessage: string): APIResponse {
|
|||||||
* @param record
|
* @param record
|
||||||
* @return APIResponse
|
* @return APIResponse
|
||||||
*/
|
*/
|
||||||
export function one(record: unknown): APIResponse {
|
export function one<T>(record: T): APIResponse<T> {
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
data: record,
|
data: record,
|
||||||
@@ -41,7 +41,7 @@ export function one(record: unknown): APIResponse {
|
|||||||
* @param {array} records
|
* @param {array} records
|
||||||
* @return APIResponse
|
* @return APIResponse
|
||||||
*/
|
*/
|
||||||
export function many(records: any[]): APIResponse {
|
export function many<T>(records: T[]): APIResponse<{records: T[], total: number}> {
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
data: {
|
data: {
|
||||||
@@ -56,7 +56,7 @@ export function many(records: any[]): APIResponse {
|
|||||||
* @return APIResponse
|
* @return APIResponse
|
||||||
* @param thrownError
|
* @param thrownError
|
||||||
*/
|
*/
|
||||||
export function error(thrownError: string | Error): APIResponse {
|
export function error(thrownError: string | Error): APIResponse<void> {
|
||||||
if ( typeof thrownError === 'string' ) {
|
if ( typeof thrownError === 'string' ) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
|
|||||||
@@ -230,7 +230,7 @@ export class PostgreSQLDialect extends SQLDialect {
|
|||||||
const table: string = tableString.split('.').map(x => `"${x}"`)
|
const table: string = tableString.split('.').map(x => `"${x}"`)
|
||||||
.join('.')
|
.join('.')
|
||||||
queryLines.push('INSERT INTO ' + (typeof source === 'string' ? table : `${table} AS "${source.alias}"`)
|
queryLines.push('INSERT INTO ' + (typeof source === 'string' ? table : `${table} AS "${source.alias}"`)
|
||||||
+ (columns.length ? ` (${columns.join(', ')})` : ''))
|
+ (columns.length ? ` (${columns.map(x => `"${x}"`).join(', ')})` : ''))
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( Array.isArray(data) && !data.length ) {
|
if ( Array.isArray(data) && !data.length ) {
|
||||||
|
|||||||
@@ -627,7 +627,7 @@ export abstract class Model<T extends Model<T>> extends AppClass implements Bus
|
|||||||
|
|
||||||
const data = result.rows.first()
|
const data = result.rows.first()
|
||||||
if ( data ) {
|
if ( data ) {
|
||||||
await this.assumeFromSource(result)
|
await this.assumeFromSource(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.dispatch(new ModelCreatedEvent<T>(this as any))
|
await this.dispatch(new ModelCreatedEvent<T>(this as any))
|
||||||
|
|||||||
Reference in New Issue
Block a user