Skip to content

Commit

Permalink
added support for TS, specifying controller dir on instantiation etc.…
Browse files Browse the repository at this point in the history
… TS support is currently experimental!
  • Loading branch information
smiffy6969 committed Aug 1, 2023
1 parent 436b758 commit cdeb933
Show file tree
Hide file tree
Showing 60 changed files with 1,609 additions and 53 deletions.
12 changes: 12 additions & 0 deletions Base/Controller.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Core from '../System/Core';

/**
* @module cerberus-mvc/Base/Controller
* @class Controller
* @extends Core
* @description System class to give a base for creating controllers, exposing services and base methods
* @author Paul Smith (ulsmith) <[email protected]> <pa.ulsmith.net>
* @copyright 2020 Paul Smith (ulsmith) all rights reserved
* @license MIT
*/
export default abstract class Controller<T> extends Core<T> {};
2 changes: 1 addition & 1 deletion Base/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const Core = require('../System/Core.js');

/**
* @namespace MVC/Base
* @module cerberus-mvc/Base/Controller
* @class Controller
* @extends Core
* @description System class to give a base for creating controllers, exposing services and base methods
Expand Down
12 changes: 12 additions & 0 deletions Base/Middleware.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Core from '../System/Core';

/**
* @modle cerberus-mvc/Base/Middleware
* @class Middleware
* @extends Core
* @description System class to give a base for creating middleware, exposing services and base methods
* @author Paul Smith (ulsmith) <[email protected]> <pa.ulsmith.net>
* @copyright 2020 Paul Smith (ulsmith) all rights reserved
* @license MIT
*/
export default abstract class Middleware<T> extends Core<T> {}
2 changes: 1 addition & 1 deletion Base/Middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const Core = require('../System/Core.js');

/**
* @namespace MVC/Base
* @modle cerberus-mvc/Base/Middleware
* @class Middleware
* @extends Core
* @description System class to give a base for creating middleware, exposing services and base methods
Expand Down
57 changes: 57 additions & 0 deletions Base/Model.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import Core from '../System/Core';

/**
* @module cerberus-mvc/Base/Model
* @class Model
* @extends Core
* @description System class to give a base for creating models, exposing the knex DB service and giving base methods
* @author Paul Smith (ulsmith) <[email protected]> <pa.ulsmith.net>
* @copyright 2020 Paul Smith (ulsmith) all rights reserved
* @license MIT
* @deprecated [Model.js] removal estimated in V1.1, switch to ModelKnex or use Model[DB Engine] for raw model access
*/
export default abstract class Model<T> extends Core<T> {
/**
* @public @method constructor
* @description Base method when instantiating class
*/
constructor(dbname: string, table: string);

get db(): any;

get model(): any;

get(id: any): any;

find(where: any): any;

all(): any;

transaction(func: any): any;

insert(data: any, returning: any): any;

transactInsert(trx: any, data: any, returning: any): any;

update(where: any, data: any, returning: any): any;

transactUpdate(trx: any, where: any, data: any, returning: any): any;

delete(id: any): any;

transactDelete(trx: any, id: any): any;

softDelete(id: any): any;

softRestore(id: any): any;

mapDataToColumn(data: any, partial: any): any;

mapDataArrayToColumn(data: any, partial: any): any;

parseError(error: any): any;

checkColumnsStrict(data: any): any;

private cleanIncommingData(data: any): any;
}
118 changes: 118 additions & 0 deletions Base/ModelDynamo.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import Core from '../System/Core';
import Dynamo from '../Service/Dynamo';

/**
* @module cerberus-mvc/Base/ModelDynamo
* @class ModelDynamo
* @extends Core
* @description System class to give a base for creating dynamo models
* @author Paul Smith (ulsmith) <[email protected]> <pa.ulsmith.net>
* @copyright 2020 Paul Smith (ulsmith) all rights reserved
* @license MIT
*/
export default abstract class ModelDynamo<T = object> extends Core<T> {

public dbname: string;
public params: object;

/**
* @public @method constructor
* @description Base method when instantiating class
*/
constructor(dbname: ModelDynamo['dbname'], table: string, params: ModelDynamo['params'])

/**
* @public @get dynamo
* @desciption Get the services available to the system
* @return {Knex} Knex service abstracted to dynamo
*/
get dynamo(): Dynamo['dynamo'];

/**
* @public @get db
* @desciption Get the services available to the system
* @return {Knex} Knex service abstracted to db
*/
get db(): Dynamo['client'];

/**
* @public @method create
* @description Create a new table resource
* @return {Promise} a resulting promise of data or error on failure
* @example
* let dynamoSource = new DynamoSourceModel();
* return dynamoSource.createTable();
*/
createTable(): Promise<any>;

/**
* @public @method get
* @description Get a single resource in a single table by table id
* @param {Mixed} key The key to the resource as a literal string/number (mapping to one key schema) or an object as Keys matching key schema ({ id: 123456, something: 'else' })
* @return {Promise} a resulting promise of data or error on failure
* @example
* let dynamoSource = new DynamoSourceModel();
* return dynamoSource.get('6ff98823-3c0b-4b09-a433-63fc55cfa6d0');
*/
get<T>(key: string | number | T): Promise<T>;

/**
* @public @method put
* @description Put a single resource into dynamo table
* @param {Object} item The data to put into the resource
* @return {Promise} a resulting promise of data or error on failure
* @example
* let dynamoSource = new DynamoSourceModel();
* return dynamoSource.put({
* id: '6ff98823-3c0b-4b09-a433-63fc55cfa6d0',
* product: [
* {
* title: 'Title Two',
* description: 'Description two... more stuff'
* }
* ],
* filter: {
* z: 'zzz'
* }
* });
*/
put<T>(item: T): Promise<T>;

/**
* @public @method update
* @description Update a single resource in dynamo table
* @param {Mixed} key The key to the resource as a literal string/number (mapping to one key schema) or an object as Keys matching key schema ({ id: 123456, something: 'else' })
* @param {Object} item The data to update in the resource { "some.path.to.property": "new value" }
* @return {Promise} a resulting promise of data or error on failure
* @example
* let dynamoSource = new DynamoSourceModel();
* return dynamoSource.update('9ff98823-3c0b-4b09-a433-63fc55cfa6d0', {
* product: [
* {
* title: 'Title Two',
* description: 'Description two... more stuff'
* }
* ]
* });
*/
update<T>(key: string | number | T, item: T): Promise<T>;

/**
* @public @method listAppend
* @description Append item to a property list in dynamo table
* @param {Mixed} key The key to the resource as a literal string/number (mapping to one key schema) or an object as Keys matching key schema ({ id: 123456, something: 'else' })
* @param {Mixed} item The data to append in the resource { "some.path.to.property": "new value" }
* @return {Promise} a resulting promise of data or error on failure
* @example
* let dynamoSource = new DynamoSourceModel();
* return dynamoSource.listAppend('9ff98823-3c0b-4b09-a433-63fc55cfa6d0', {
* product: [
* {
* title: 'Title Two',
* description: 'Description two... more stuff'
* }
* ]
* });
*/
listAppend<T>(key: string | number | T, item: T): Promise<T>;
}
4 changes: 2 additions & 2 deletions Base/ModelDynamo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const Core = require('cerberus-mvc/System/Core.js');
const ModelError = require('cerberus-mvc/Error/Model.js');

/**
* @namespace MVC/Base
* @class Model
* @module cerberus-mvc/Base/ModelDynamo
* @class ModelDynamo
* @extends Core
* @description System class to give a base for creating dynamo models
* @author Paul Smith (ulsmith) <[email protected]> <pa.ulsmith.net>
Expand Down
Loading

0 comments on commit cdeb933

Please sign in to comment.