Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 96e13d85fc | |||
| 5a9283ad85 | |||
| b1ea489ccb | |||
| c3f2779650 | |||
| 248b24e612 | |||
| b4a9057e2b | |||
| c078d695a8 | |||
| 55ffadc742 | |||
| 56574d43ce | |||
| e16f02ce12 | |||
| c34fad3502 | |||
| 156006053b | |||
| 22cf6aa953 | |||
| b35eb8d6a1 | |||
| 9ee4c42e43 |
@@ -22,7 +22,7 @@ steps:
|
|||||||
from_secret: docs_deploy_key
|
from_secret: docs_deploy_key
|
||||||
port: 22
|
port: 22
|
||||||
source: extollo_api_documentation.tar.gz
|
source: extollo_api_documentation.tar.gz
|
||||||
target: /var/nfs/general/static/sites/extollo
|
target: /var/nfs/storage/static/sites/extollo
|
||||||
when:
|
when:
|
||||||
event: promote
|
event: promote
|
||||||
target: docs
|
target: docs
|
||||||
@@ -38,7 +38,7 @@ steps:
|
|||||||
from_secret: docs_deploy_key
|
from_secret: docs_deploy_key
|
||||||
port: 22
|
port: 22
|
||||||
script:
|
script:
|
||||||
- cd /var/nfs/general/static/sites/extollo
|
- cd /var/nfs/storage/static/sites/extollo
|
||||||
- rm -rf docs
|
- rm -rf docs
|
||||||
- tar xzf extollo_api_documentation.tar.gz
|
- tar xzf extollo_api_documentation.tar.gz
|
||||||
- rm -rf extollo_api_documentation.tar.gz
|
- rm -rf extollo_api_documentation.tar.gz
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@extollo/lib",
|
"name": "@extollo/lib",
|
||||||
"version": "0.5.1",
|
"version": "0.5.7",
|
||||||
"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",
|
||||||
|
|||||||
@@ -169,8 +169,12 @@ export abstract class Directive extends AppClass {
|
|||||||
const optionValues = this.parseOptions(options, argv)
|
const optionValues = this.parseOptions(options, argv)
|
||||||
this.setOptionValues(optionValues)
|
this.setOptionValues(optionValues)
|
||||||
await this.handle(argv)
|
await this.handle(argv)
|
||||||
} catch (e) {
|
} catch (e: unknown) {
|
||||||
|
if ( e instanceof Error ) {
|
||||||
this.nativeOutput(e.message)
|
this.nativeOutput(e.message)
|
||||||
|
this.error(e)
|
||||||
|
}
|
||||||
|
|
||||||
if ( e instanceof OptionValidationError ) {
|
if ( e instanceof OptionValidationError ) {
|
||||||
// expecting, value, requirements
|
// expecting, value, requirements
|
||||||
if ( e.context.expecting ) {
|
if ( e.context.expecting ) {
|
||||||
@@ -187,6 +191,7 @@ export abstract class Directive extends AppClass {
|
|||||||
this.nativeOutput(` - ${e.context.value}`)
|
this.nativeOutput(` - ${e.context.value}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.nativeOutput('\nUse --help for more info.')
|
this.nativeOutput('\nUse --help for more info.')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,3 +11,5 @@ export * from './directive/options/PositionalOption'
|
|||||||
export * from './directive/ShellDirective'
|
export * from './directive/ShellDirective'
|
||||||
export * from './directive/TemplateDirective'
|
export * from './directive/TemplateDirective'
|
||||||
export * from './directive/UsageDirective'
|
export * from './directive/UsageDirective'
|
||||||
|
|
||||||
|
export * from './decorators'
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -259,9 +259,13 @@ export class Application extends Container {
|
|||||||
try {
|
try {
|
||||||
await this.up()
|
await this.up()
|
||||||
await this.down()
|
await this.down()
|
||||||
} catch (e) {
|
} catch (e: unknown) {
|
||||||
|
if ( e instanceof Error ) {
|
||||||
this.errorHandler(e)
|
this.errorHandler(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw e
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -306,10 +310,15 @@ export class Application extends Container {
|
|||||||
await unit.up()
|
await unit.up()
|
||||||
unit.status = UnitStatus.Started
|
unit.status = UnitStatus.Started
|
||||||
logging.info(`Started ${unit.constructor.name}.`)
|
logging.info(`Started ${unit.constructor.name}.`)
|
||||||
} catch (e) {
|
} catch (e: unknown) {
|
||||||
unit.status = UnitStatus.Error
|
unit.status = UnitStatus.Error
|
||||||
|
|
||||||
|
if ( e instanceof Error ) {
|
||||||
throw this.errorWrapContext(e, {unitName: unit.constructor.name})
|
throw this.errorWrapContext(e, {unitName: unit.constructor.name})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw e
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -327,7 +336,12 @@ export class Application extends Container {
|
|||||||
logging.info(`Stopped ${unit.constructor.name}.`)
|
logging.info(`Stopped ${unit.constructor.name}.`)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
unit.status = UnitStatus.Error
|
unit.status = UnitStatus.Error
|
||||||
|
|
||||||
|
if ( e instanceof Error ) {
|
||||||
throw this.errorWrapContext(e, {unitName: unit.constructor.name})
|
throw this.errorWrapContext(e, {unitName: unit.constructor.name})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw e
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,10 +79,13 @@ ${contextDisplay}
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.logging.error(errorString, true)
|
this.logging.error(errorString, true)
|
||||||
} catch (displayError) {
|
} catch (displayError: unknown) {
|
||||||
|
if ( displayError instanceof Error ) {
|
||||||
// The error display encountered an error...
|
// The error display encountered an error...
|
||||||
// just throw the original so it makes it out
|
// just throw the original so it makes it out
|
||||||
console.error('RunLevelErrorHandler encountered an error:', displayError.message) // eslint-disable-line no-console
|
console.error('RunLevelErrorHandler encountered an error:', displayError.message) // eslint-disable-line no-console
|
||||||
|
}
|
||||||
|
|
||||||
throw operativeError
|
throw operativeError
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import {Inject, Injectable} from '../di'
|
||||||
|
import {ConstraintType, DatabaseService, FieldType, Migration, Schema} from '../orm'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Migration that creates the sessions table used by the ORMSession backend.
|
||||||
|
*/
|
||||||
|
@Injectable()
|
||||||
|
export default class CreateSessionsTableMigration extends Migration {
|
||||||
|
@Inject()
|
||||||
|
protected readonly db!: DatabaseService
|
||||||
|
|
||||||
|
async up(): Promise<void> {
|
||||||
|
const schema: Schema = this.db.get().schema()
|
||||||
|
const table = await schema.table('sessions')
|
||||||
|
|
||||||
|
table.primaryKey('session_uuid', FieldType.varchar)
|
||||||
|
.required()
|
||||||
|
|
||||||
|
table.column('session_data')
|
||||||
|
.type(FieldType.json)
|
||||||
|
.required()
|
||||||
|
.default('{}')
|
||||||
|
|
||||||
|
table.constraint('session_uuid_ck')
|
||||||
|
.type(ConstraintType.Check)
|
||||||
|
.expression('LENGTH(session_uuid) > 0')
|
||||||
|
|
||||||
|
await schema.commit(table)
|
||||||
|
}
|
||||||
|
|
||||||
|
async down(): Promise<void> {
|
||||||
|
const schema: Schema = this.db.get().schema()
|
||||||
|
const table = await schema.table('sessions')
|
||||||
|
|
||||||
|
table.dropIfExists()
|
||||||
|
|
||||||
|
await schema.commit(table)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import {Inject, Injectable} from '../di'
|
||||||
|
import {DatabaseService, FieldType, Migration, Schema} from '../orm'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Migration that creates the users table used by @extollo/lib.auth.
|
||||||
|
*/
|
||||||
|
@Injectable()
|
||||||
|
export default class CreateUsersTableMigration extends Migration {
|
||||||
|
@Inject()
|
||||||
|
protected readonly db!: DatabaseService
|
||||||
|
|
||||||
|
async up(): Promise<void> {
|
||||||
|
const schema: Schema = this.db.get().schema()
|
||||||
|
const table = await schema.table('users')
|
||||||
|
|
||||||
|
table.primaryKey('user_id')
|
||||||
|
.required()
|
||||||
|
|
||||||
|
table.column('first_name')
|
||||||
|
.type(FieldType.varchar)
|
||||||
|
.nullable()
|
||||||
|
|
||||||
|
table.column('last_name')
|
||||||
|
.type(FieldType.varchar)
|
||||||
|
.nullable()
|
||||||
|
|
||||||
|
table.column('password_hash')
|
||||||
|
.type(FieldType.text)
|
||||||
|
.nullable()
|
||||||
|
|
||||||
|
table.column('username')
|
||||||
|
.type(FieldType.varchar)
|
||||||
|
.required()
|
||||||
|
.unique()
|
||||||
|
|
||||||
|
await schema.commit(table)
|
||||||
|
}
|
||||||
|
|
||||||
|
async down(): Promise<void> {
|
||||||
|
const schema: Schema = this.db.get().schema()
|
||||||
|
const table = await schema.table('users')
|
||||||
|
|
||||||
|
table.dropIfExists()
|
||||||
|
|
||||||
|
await schema.commit(table)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -63,11 +63,15 @@ export class PostgresConnection extends Connection {
|
|||||||
rowCount: result.rowCount,
|
rowCount: result.rowCount,
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if ( e instanceof Error ) {
|
||||||
throw this.app().errorWrapContext(e, {
|
throw this.app().errorWrapContext(e, {
|
||||||
query,
|
query,
|
||||||
connection: this.name,
|
connection: this.name,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw e
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async asTransaction<T>(closure: () => Awaitable<T>): Promise<T> {
|
public async asTransaction<T>(closure: () => Awaitable<T>): Promise<T> {
|
||||||
|
|||||||
@@ -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 ) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {Inject, Singleton} from '../di'
|
import {Inject, Singleton} from '../di'
|
||||||
import {HTTPStatus, withTimeout} from '../util'
|
import {ErrorWithContext, HTTPStatus, withTimeout} from '../util'
|
||||||
import {Unit} from '../lifecycle/Unit'
|
import {Unit} from '../lifecycle/Unit'
|
||||||
import {createServer, IncomingMessage, RequestListener, Server, ServerResponse} from 'http'
|
import {createServer, IncomingMessage, RequestListener, Server, ServerResponse} from 'http'
|
||||||
import {Logging} from './Logging'
|
import {Logging} from './Logging'
|
||||||
@@ -114,9 +114,13 @@ export class HTTPServer extends Unit {
|
|||||||
try {
|
try {
|
||||||
await this.kernel.handle(extolloReq)
|
await this.kernel.handle(extolloReq)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if ( e instanceof Error ) {
|
||||||
await error(e).write(extolloReq)
|
await error(e).write(extolloReq)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await error(new ErrorWithContext('Unknown error occurred.', { e }))
|
||||||
|
}
|
||||||
|
|
||||||
await extolloReq.response.send()
|
await extolloReq.response.send()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ export class BehaviorSubject<T> {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
if ( e instanceof UnsubscribeError ) {
|
if ( e instanceof UnsubscribeError ) {
|
||||||
this.subscribers = this.subscribers.filter(x => x !== subscriber)
|
this.subscribers = this.subscribers.filter(x => x !== subscriber)
|
||||||
} else if (subscriber.error) {
|
} else if (subscriber.error && e instanceof Error) {
|
||||||
await subscriber.error(e)
|
await subscriber.error(e)
|
||||||
} else {
|
} else {
|
||||||
throw e
|
throw e
|
||||||
@@ -181,7 +181,7 @@ export class BehaviorSubject<T> {
|
|||||||
try {
|
try {
|
||||||
await subscriber.complete(finalValue)
|
await subscriber.complete(finalValue)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if ( subscriber.error ) {
|
if ( subscriber.error && e instanceof Error ) {
|
||||||
await subscriber.error(e)
|
await subscriber.error(e)
|
||||||
} else {
|
} else {
|
||||||
throw e
|
throw e
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ export class LocalFilesystem extends Filesystem {
|
|||||||
isFile: stat.isFile(),
|
isFile: stat.isFile(),
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if ( e?.code === 'ENOENT' ) {
|
if ( (e as any)?.code === 'ENOENT' ) {
|
||||||
return {
|
return {
|
||||||
path: new UniversalPath(args.storePath, this),
|
path: new UniversalPath(args.storePath, this),
|
||||||
exists: false,
|
exists: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user