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

Commit 43c0152

Browse files
author
Dr. Safi
committed
Working on new implementation for shellscript nestedUnit.
Added controller, nestedUnit, unit implementations and support for related execution methods in nestedUnit module.
1 parent 44b5f5d commit 43c0152

File tree

8 files changed

+145
-2
lines changed

8 files changed

+145
-2
lines changed

module/reusableNestedUnit/Controller.class.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { mix } from 'mixwith'
1414
*/
1515
export default ({
1616
methodInstanceName,
17-
Superclass,
17+
Superclass = Object,
1818
mixin
1919
}) => {
2020
let mixinArray = [/*commonMethod*/]

module/reusableNestedUnit/NestedUnit.class.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ export default ({ Superclass }) => {
8181
if (returned) break
8282
}
8383
return returned;
84+
break;
85+
case 'executeScript':
86+
for (let insertionPoint of this.insertionPoint) {
87+
// [1] get children immediate & relating to this insertion position.
88+
let children = await this.filterAndOrderChildren({ insertionPointKey: insertionPoint.key })
89+
// let children = await this.filterChildrenOfCurrentInsertionPoint({ insertionPointKey: insertionPoint.key })
90+
await this.initializeInsertionPoint({ insertionPoint, children })
91+
}
92+
break;
8493
default:
8594
console.log(`"${type}" type doesn\'t match any kind.`)
8695
break;
@@ -190,6 +199,9 @@ export default ({ Superclass }) => {
190199
// [2] check type of subtrees execution: race first, all ... .
191200
let callback;
192201
switch(insertionPoint.executionType) { // execution type callback name
202+
case 'allPromise':
203+
callback = 'initializeNestedUnitInAllPromiseExecutionType'
204+
break;
193205
case 'raceFirstPromise':
194206
callback = 'initializeNestedUnitInRaceExecutionType'
195207
break;
@@ -259,6 +271,36 @@ export default ({ Superclass }) => {
259271
return callback ? callback : false;
260272
}
261273

274+
async initializeNestedUnitInAllPromiseExecutionType(children) {
275+
let promiseArray = []
276+
promiseArray = children.map(conditionTreeChild => {
277+
return new Promise(async (resolve, reject) => {
278+
// Add the rest of the immediate children to the next tree as additional children. propagate children to the next tree.
279+
280+
if(this.children.length != 0) {
281+
await Array.prototype.push.apply(this.children, this.additionalChildNestedUnit)
282+
} else {
283+
this.children = await this.additionalChildNestedUnit.slice()
284+
}
285+
286+
await this.initializeNestedUnit({
287+
nestedUnitKey: conditionTreeChild.nestedUnit,
288+
additionalChildNestedUnit: this.children,
289+
pathPointerKey: conditionTreeChild.pathPointerKey
290+
})
291+
resolve()
292+
})
293+
})
294+
295+
await Promise.all(promiseArray).then(() => {
296+
}).catch(reason => {
297+
if(process.env.SZN_DEBUG == 'true') console.log(`🔀⚠️ promiseProperRace rejected because: ${reason}`)
298+
process.exit(1)
299+
})
300+
return;
301+
}
302+
303+
262304
}
263305

264306
return self

module/reusableNestedUnit/entrypoint.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let counter = [] // allows to have a unique set of relations among different nes
2323
* @return {Object} Related Classes
2424
*/
2525
function createStaticInstanceClasses({
26-
Superclass, /* Usually the higher Application class */
26+
Superclass = Object, /* Usually the higher Application class */
2727
implementationType,
2828
cacheName = false /* {Boolean || String} */
2929
}) {
@@ -46,6 +46,9 @@ function createStaticInstanceClasses({
4646
case 'Template':
4747
implementationConfig = require('./implementation/template')
4848
break;
49+
case 'Shellscript':
50+
implementationConfig = require('./implementation/shellscript')
51+
break;
4952

5053
default:
5154
console.log('⚠️ No implementation chosen for building class tree in ReusableNestedUnit.')
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import r from 'rethinkdb'
2+
import { classDecorator as prototypeChainDebug} from 'appscript/module/prototypeChainDebug'
3+
import { add, execute, applyMixin, conditional } from 'appscript/utilityFunction/decoratorUtility.js'
4+
import promiseProperRace from 'appscript/utilityFunction/promiseProperRace.js'
5+
import { extendedSubclassPattern } from 'appscript/utilityFunction/extendedSubclassPattern.js'
6+
import { curried as getTableDocumentCurried } from "appscript/utilityFunction/database/query/getTableDocument.query.js";
7+
8+
let getDocument = {
9+
NestedUnit: getTableDocumentCurried({ documentId: 'shellscript_nestedUnit'})
10+
}
11+
12+
export default ({ Superclass }) => {
13+
let self =
14+
@conditional({ decorator: prototypeChainDebug, condition: process.env.SZN_DEBUG })
15+
@execute({
16+
staticMethod: 'initializeStaticClass',
17+
args: [ getDocument['NestedUnit'] ]
18+
})
19+
@extendedSubclassPattern.Subclass()
20+
class NestedUnit extends Superclass {
21+
}
22+
23+
return self
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { classDecorator as prototypeChainDebug} from 'appscript/module/prototypeChainDebug'
2+
import { add, execute, applyMixin, conditional } from 'appscript/utilityFunction/decoratorUtility.js'
3+
import { extendedSubclassPattern } from 'appscript/utilityFunction/extendedSubclassPattern.js'
4+
import { curried as getTableDocumentCurried } from "appscript/utilityFunction/database/query/getTableDocument.query.js";
5+
6+
let getDocument = {
7+
'Unit': getTableDocumentCurried({ documentId: 'shellscript_unit' })
8+
}
9+
10+
export default ({ Superclass }) => {
11+
let self =
12+
@conditional({ decorator: prototypeChainDebug, condition: process.env.SZN_DEBUG })
13+
@execute({
14+
staticMethod: 'initializeStaticClass',
15+
args: [ getDocument['Unit'] ]
16+
})
17+
@extendedSubclassPattern.Subclass()
18+
class Unit extends Superclass {
19+
async executeScript() {
20+
console.log(this)
21+
}
22+
}
23+
return self
24+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Mixin } from 'mixwith'
2+
import { classDecorator as prototypeChainDebug} from 'appscript/module/prototypeChainDebug'
3+
import { add, execute, applyMixin, conditional } from 'appscript/utilityFunction/decoratorUtility.js'
4+
5+
/**
6+
* @description Extends a class by super class and adds some common functionality.
7+
*/
8+
export default Mixin(({ Superclass }) => {
9+
let self =
10+
@conditional({ decorator: prototypeChainDebug, condition: process.env.SZN_DEBUG })
11+
class ShellscriptMixin extends Superclass {
12+
13+
/**
14+
* @description when first called "this" context is assigned to the AppInstance for the comming request. And on subsequest calls it is assigned to the nestedUnit instance.
15+
*
16+
* @param {any} {nestedUnitKey}
17+
* @returns { Object || False } Object containing instruction settings to be used through an implementing module.
18+
*/
19+
async initializeNestedUnit({ nestedUnitKey, additionalChildNestedUnit = [], pathPointerKey = null}) { // Entrypoint Instance
20+
// [1] get nestedUnit
21+
let nestedUnitInstance = await this.getNestedUnit({ nestedUnitKey, additionalChildNestedUnit, pathPointerKey })
22+
23+
if(nestedUnitInstance.unit) {
24+
let { unit: unitKey} = nestedUnitInstance
25+
let unitInstance = await this.getUnit({ unitKey })
26+
// execute command
27+
await unitInstance.executeScript()
28+
}
29+
30+
// [3] Iterate over insertion points
31+
await nestedUnitInstance.loopInsertionPoint({ type: 'executeScript' })
32+
}
33+
}
34+
35+
return self
36+
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import ControllerMixin from './controllerMixin.mixin'
2+
import NestedUnitFunction from './NestedUnit.class.js'
3+
import UnitFunction from './Unit.class.js'
4+
5+
export default {
6+
ControllerMixin,
7+
NestedUnitFunction,
8+
UnitFunction
9+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "middleware",
3+
"version": "0.1.0",
4+
"main": "entrypoint.js"
5+
}

0 commit comments

Comments
 (0)