Skip to content
This repository was archived by the owner on Feb 11, 2020. It is now read-only.

Commit 0f516e9

Browse files
author
Dr. Safi
committed
Merge branch 'shellScript_nestedUnitImplementation'
2 parents e21b0b5 + 25f410e commit 0f516e9

File tree

6 files changed

+73
-12
lines changed

6 files changed

+73
-12
lines changed

β€Žmodule/prototypeChainDebug/entrypoint.jsβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Returns a proxy with traps to add meta information.
44
*/
55
function prototypeChainDebug(Class) {
6+
67
// Static class
78
Class.meta = {
89
Class: `${Class.name}`,

β€Žmodule/reusableNestedUnit/Controller.class.jsβ€Ž

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const EventEmitter = require('events');
12
import commonMethod from './commonMethod.mixin'
23
import createInstance from 'appscript/module/createInstance.staticMethod'
34
import { usingGenericInstance as populateInstancePropertyFromJson, usingThis as populateInstancePropertyFromJson_this } from 'appscript/module/populateInstancePropertyFromJson.method'
@@ -14,12 +15,12 @@ import { mix } from 'mixwith'
1415
*/
1516
export default ({
1617
methodInstanceName,
17-
Superclass = Object,
18-
mixin
18+
Superclass = EventEmitter, // defaulting to EventEmitter and not Object / Function because extending Object/Function manipulates this prototype in new calls for some reason.
19+
mixin,
20+
rethinkdbConnection = Superclass.rethinkdbConnection
1921
}) => {
2022
let mixinArray = [/*commonMethod*/]
2123
let self =
22-
@conditional({ decorator: prototypeChainDebug, condition: process.env.SZN_DEBUG })
2324
@add({ to: 'static'}, {
2425
createInstance,
2526
populateInstancePropertyFromJson,
@@ -28,11 +29,14 @@ export default ({
2829
@add({ to: 'prototype'}, {
2930
populateInstancePropertyFromJson_this
3031
})
31-
@conditional({ condition: mixin, decorator: applyMixin({ mixin }) })
32+
@conditional({ decorator: prototypeChainDebug, condition: process.env.SZN_DEBUG })
3233
@extendedSubclassPattern.Superclass()
33-
@superclassInstanceContextPattern()
34-
@conditional({ decorator: extendedSubclassPattern.Subclass(), condition: (methodInstanceName && Superclass) })
34+
@conditional({ decorator: extendedSubclassPattern.Subclass(), condition: (methodInstanceName && Superclass && Superclass.addSubclass != undefined ) })
35+
@conditional({ condition: mixin, decorator: applyMixin({ mixin }) })
36+
@superclassInstanceContextPattern() // applied on the mixin i.e. specific controller.
3537
class ReusableController extends mix(Superclass).with(...mixinArray) {
38+
39+
static rethinkdbConnection = rethinkdbConnection
3640

3741
@cacheInstance({
3842
cacheArrayName: 'nestedUnit',

β€Žmodule/reusableNestedUnit/entrypoint.jsβ€Ž

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ let counter = [] // allows to have a unique set of relations among different nes
2323
* @return {Object} Related Classes
2424
*/
2525
function createStaticInstanceClasses({
26-
Superclass = Object, /* Usually the higher Application class */
26+
Superclass, /* Usually the higher Application class */
2727
implementationType,
28-
cacheName = false /* {Boolean || String} */
29-
}) {
28+
cacheName = false, /* {Boolean || String} */
29+
rethinkdbConnection
30+
} = {}) {
3031
// Used as caching key.
3132
let automaticCacheNaming;
3233
if(cacheName && typeof cacheName == 'boolean') {
@@ -88,7 +89,8 @@ function createStaticInstanceClasses({
8889
let Controller = ControllerFunc({
8990
methodInstanceName: cacheName,
9091
Superclass,
91-
mixin: implementationConfig.ControllerMixin
92+
mixin: implementationConfig.ControllerMixin,
93+
rethinkdbConnection
9294
})
9395
let NestedUnit = NestedUnitFunc({ Superclass: Controller })
9496
let Unit = UnitFunc({ Superclass: Controller })

β€Žmodule/reusableNestedUnit/implementation/shellscript/Unit.class.jsβ€Ž

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { classDecorator as prototypeChainDebug} from 'appscript/module/prototype
22
import { add, execute, applyMixin, conditional } from 'appscript/utilityFunction/decoratorUtility.js'
33
import { extendedSubclassPattern } from 'appscript/utilityFunction/extendedSubclassPattern.js'
44
import { curried as getTableDocumentCurried } from "appscript/utilityFunction/database/query/getTableDocument.query.js";
5+
import { exec, spawn, spawnSync } from 'child_process'
56

67
let getDocument = {
78
'Unit': getTableDocumentCurried({ documentId: 'shellscript_unit' })
@@ -17,7 +18,25 @@ export default ({ Superclass }) => {
1718
@extendedSubclassPattern.Subclass()
1819
class Unit extends Superclass {
1920
async executeScript() {
20-
console.log(this)
21+
let message = ` _____ _
22+
| ____|__ __ ___ ___ _ _ | |_ ___
23+
| _| \\ \\/ // _ \\ / __|| | | || __|/ _ \\
24+
| |___ > <| __/| (__ | |_| || |_| __/
25+
|_____|/_/\\_\\\\___| \\___| \\__,_| \\__|\\___|
26+
${this.command} ${this.argument}`;
27+
switch (this.implementation) {
28+
case 'spawn':
29+
console.log(message)
30+
spawnSync(this.command, this.argument, this.option)
31+
break;
32+
case 'spawnAsynchronous':
33+
console.log(message)
34+
spawn(this.command, this.argument, this.option)
35+
break;
36+
default:
37+
console.log('shellscriptUnit.implementation does not match any option.')
38+
break;
39+
}
2140
}
2241
}
2342
return self
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import rethinkDB from 'rethinkdb'
2+
3+
export async function createDatabase(databaseName, connection) {
4+
let databaseExists = await rethinkDB.dbList().contains(databaseName).run(connection);
5+
if(!databaseExists) {
6+
let dbCreationResponse = await rethinkDB.dbCreate(databaseName).run(connection)
7+
8+
// .do(function(databaseExists) {
9+
// return rethinkDB.branch(
10+
// databaseExists,
11+
// { dbs_created: 0 },
12+
// rethinkDB.dbCreate('webapp')
13+
// );
14+
// })
15+
16+
if(dbCreationResponse.dbs_created > 0) console.log(`πŸ“’ ${databaseName} database created !`)
17+
} else {
18+
console.log(`πŸ“’πŸ“ ${databaseName} database already exists !`)
19+
}
20+
}
21+
22+
export async function createTableAndInsertData(databaseName, databaseData, connection) {
23+
for (let tableData of databaseData) {
24+
await rethinkDB.db(databaseName).tableCreate(tableData.databaseTableName).run(connection)
25+
.then(async tableCreationResponse => {
26+
if(tableCreationResponse.tables_created > 0) console.log(`πŸ“’ ${tableData.databaseTableName} table created.`)
27+
await rethinkDB.db(databaseName).table(tableData.databaseTableName).insert(tableData.data).run(connection)
28+
.then(response => {
29+
console.log(`πŸ“’πŸ“₯ ${response.inserted} documents inserted to ${tableData.databaseTableName}.`)
30+
})
31+
.catch(error => console.log(error))
32+
})
33+
.catch(error => console.log(`πŸ“’ ${tableData.databaseTableName} table already exists.`))
34+
}
35+
}

β€ŽutilityFunction/superclassInstanceContextPattern.jsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function superclassInstanceContextPattern() {
1313

1414
// loop over arguments and add properties
1515
// contextInstance.portAppInstance // calling instance that contains the context
16-
Object.entries(argsObject).forEach(([key, value]) => {
16+
if(argsObject) Object.entries(argsObject).forEach(([key, value]) => {
1717
contextInstance[key] = value
1818
})
1919
// Add cache list

0 commit comments

Comments
Β (0)