fable 3.1.4 → 3.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,27 +27,27 @@ _Fable.log.info(`Beginning Run-through for Set of Test Expressions....`);
27
27
  // An array of equations with expected values
28
28
  let _Equations = require(`./Equations.json`);
29
29
  // The application state is a plain javascript object we pass into the solver to pull variables from
30
- let _AppData = require(`./AppData.json`);
31
- // The manifest is a Manyfest which describes hashes for complex addresses in the application state object
32
- // For example you can't use "Student[0].Age" as a variable in the expression
33
- // ...but you can use "Student[0].Age" as an address in the manifest with a hash of "StudentAge"
34
- // ...and then reference "StudentAge" in the expression.
35
- let tmpManifestConfiguration = { "Scope":"None", "Descriptors":[] };
36
- let tmpManifest = _Fable.newManyfest(tmpManifestConfiguration);
37
- // Run each expression in the Equations.json file through the expression parser.
38
- for (let i = 0; i < _Equations.Expressions.length; i++)
39
- {
40
- let tmpResultObject = {};
41
- let tmpResultValue = _ExpressionParser.solve(_Equations.Expressions[i].Equation, _AppData, tmpResultObject, tmpManifest);
42
- console.log(`Expression [${i}]: [${_Equations.Expressions[i].Equation}] ==> ${tmpResultValue}`);
43
- console.log(` Expected: ${_Equations.Expressions[i].ExpectedResult}`);
44
- //_Fable.ExpressionParser.Messaging.logFunctionOutcome(tmpResultObject);
30
+ // let _AppData = require(`./AppData.json`);
31
+ // // The manifest is a Manyfest which describes hashes for complex addresses in the application state object
32
+ // // For example you can't use "Student[0].Age" as a variable in the expression
33
+ // // ...but you can use "Student[0].Age" as an address in the manifest with a hash of "StudentAge"
34
+ // // ...and then reference "StudentAge" in the expression.
35
+ // let tmpManifestConfiguration = { "Scope":"None", "Descriptors":[] };
36
+ // let tmpManifest = _Fable.newManyfest(tmpManifestConfiguration);
37
+ // // Run each expression in the Equations.json file through the expression parser.
38
+ // for (let i = 0; i < _Equations.Expressions.length; i++)
39
+ // {
40
+ // let tmpResultObject = {};
41
+ // let tmpResultValue = _ExpressionParser.solve(_Equations.Expressions[i].Equation, _AppData, tmpResultObject, tmpManifest);
42
+ // console.log(`Expression [${i}]: [${_Equations.Expressions[i].Equation}] ==> ${tmpResultValue}`);
43
+ // console.log(` Expected: ${_Equations.Expressions[i].ExpectedResult}`);
44
+ // //_Fable.ExpressionParser.Messaging.logFunctionOutcome(tmpResultObject);
45
45
 
46
- if (tmpResultValue !== _Equations.Expressions[i].ExpectedResult)
47
- {
48
- console.log(`Error: Equation ${_Equations.Expressions[i].Equation} expected [${_Equations.Expressions[i].ExpectedResult}] but got [${tmpResultValue}]`);
49
- }
50
- }
46
+ // if (tmpResultValue !== _Equations.Expressions[i].ExpectedResult)
47
+ // {
48
+ // console.log(`Error: Equation ${_Equations.Expressions[i].Equation} expected [${_Equations.Expressions[i].ExpectedResult}] but got [${tmpResultValue}]`);
49
+ // }
50
+ // }
51
51
 
52
52
 
53
53
  /* * * * * * * * * * * * * * * * *
@@ -60,13 +60,16 @@ let _FruitData = require(`../data/Fruit-Data.json`);
60
60
  let _FruitManifestDescription = require(`../data/Fruit-Manyfest.json`);
61
61
  let _FruitManifest = _Fable.newManyfest(_FruitManifestDescription);
62
62
 
63
+ _Fable.AppData = _FruitData;
63
64
  _Fable.log.info(`Beginning Manual Solve with Embedded Fruit Data....`);
64
65
 
65
- // The expression we pass into the solver is just a string
66
+ // // The expression we pass into the solver is just a string
66
67
  let tmpExpression = 'HyperMax.HealthIndex = (SUM(Calories) / SUM(Sugar)) * MEDIAN(Fat) + (SQRT(AVG(Protein)) - (PI() + 99))';
68
+ //tmpExpression = `aggregationhistogram("AppData.FruityVice", "family", "nutritions.calories")`;
69
+ tmpExpression = 'Out.Match = FindFirstValueByStringIncludes("AppData.FruityVice", "name", "uria", "id")';
67
70
  _Fable.log.info(`Solving tmpExpression: [${tmpExpression}]`);
68
71
 
69
- // This is an object where the parser will write out the results of each phase of the compiler/parser/solver
72
+ // // This is an object where the parser will write out the results of each phase of the compiler/parser/solver
70
73
  let tmpExpressionParseOutcome = {};
71
74
  let tmpSolverResultsObject = {};
72
75
 
@@ -82,7 +85,8 @@ _ExpressionParser.substituteValuesInTokenizedObjects(tmpExpressionParseOutcome.P
82
85
  let tmpResultValue = _ExpressionParser.solvePostfixedExpression(tmpExpressionParseOutcome.PostfixSolveList, tmpSolverResultsObject, tmpExpressionParseOutcome, _FruitManifest);
83
86
 
84
87
  // Now that we have a solved expression and the mapped-in values, show the user the solution
85
- //_Fable.ExpressionParser.Messaging.logFunctionOutcome(tmpExpressionParseOutcome);
88
+ _Fable.ExpressionParser.Messaging.logFunctionOutcome(tmpExpressionParseOutcome);
89
+
86
90
 
87
91
  // Step 6: Look at the results.
88
92
  console.log(`Outcome object: ${JSON.stringify(tmpSolverResultsObject)}`);
package/package.json CHANGED
@@ -1,70 +1,70 @@
1
1
  {
2
- "name": "fable",
3
- "version": "3.1.4",
4
- "description": "A service dependency injection, configuration and logging library.",
5
- "main": "source/Fable.js",
6
- "scripts": {
7
- "start": "node source/Fable.js",
8
- "coverage": "./node_modules/.bin/nyc --reporter=lcov --reporter=text-lcov ./node_modules/mocha/bin/_mocha -- -u tdd -R spec",
9
- "test": "./node_modules/.bin/mocha -u tdd -R spec",
10
- "build": "npx quack build",
11
- "docker-dev-build": "docker build ./ -f Dockerfile_LUXURYCode -t fable-image:local",
12
- "docker-dev-run": "docker run -it -d --name fable-dev -p 30001:8080 -p 38086:8086 -v \"$PWD/.config:/home/coder/.config\" -v \"$PWD:/home/coder/fable\" -u \"$(id -u):$(id -g)\" -e \"DOCKER_USER=$USER\" fable-image:local",
13
- "docker-dev-shell": "docker exec -it fable-dev /bin/bash",
14
- "tests": "./node_modules/mocha/bin/_mocha -u tdd --exit -R spec --grep"
15
- },
16
- "mocha": {
17
- "diff": true,
18
- "extension": [
19
- "js"
20
- ],
21
- "package": "./package.json",
22
- "reporter": "spec",
23
- "slow": "75",
24
- "timeout": "5000",
25
- "ui": "tdd",
26
- "watch-files": [
27
- "source/**/*.js",
28
- "test/**/*.js"
29
- ],
30
- "watch-ignore": [
31
- "lib/vendor"
32
- ]
33
- },
34
- "browser": {
35
- "./source/service/Fable-Service-EnvironmentData.js": "./source/service/Fable-Service-EnvironmentData-Web.js",
36
- "./source/service/Fable-Service-FilePersistence.js": "./source/service/Fable-Service-FilePersistence-Web.js"
37
- },
38
- "repository": {
39
- "type": "git",
40
- "url": "https://github.com/stevenvelozo/fable.git"
41
- },
42
- "keywords": [
43
- "entity",
44
- "behavior"
2
+ "name": "fable",
3
+ "version": "3.1.5",
4
+ "description": "A service dependency injection, configuration and logging library.",
5
+ "main": "source/Fable.js",
6
+ "scripts": {
7
+ "start": "node source/Fable.js",
8
+ "coverage": "./node_modules/.bin/nyc --reporter=lcov --reporter=text-lcov ./node_modules/mocha/bin/_mocha -- -u tdd -R spec",
9
+ "test": "./node_modules/.bin/mocha -u tdd -R spec",
10
+ "build": "npx quack build",
11
+ "docker-dev-build": "docker build ./ -f Dockerfile_LUXURYCode -t fable-image:local",
12
+ "docker-dev-run": "docker run -it -d --name fable-dev -p 30001:8080 -p 38086:8086 -v \"$PWD/.config:/home/coder/.config\" -v \"$PWD:/home/coder/fable\" -u \"$(id -u):$(id -g)\" -e \"DOCKER_USER=$USER\" fable-image:local",
13
+ "docker-dev-shell": "docker exec -it fable-dev /bin/bash",
14
+ "tests": "./node_modules/mocha/bin/_mocha -u tdd --exit -R spec --grep"
15
+ },
16
+ "mocha": {
17
+ "diff": true,
18
+ "extension": [
19
+ "js"
45
20
  ],
46
- "author": "Steven Velozo <steven@velozo.com> (http://velozo.com/)",
47
- "license": "MIT",
48
- "bugs": {
49
- "url": "https://github.com/stevenvelozo/fable/issues"
50
- },
51
- "homepage": "https://github.com/stevenvelozo/fable",
52
- "devDependencies": {
53
- "quackage": "^1.0.41"
54
- },
55
- "dependencies": {
56
- "async.eachlimit": "^0.5.2",
57
- "async.waterfall": "^0.5.2",
58
- "big.js": "^6.2.2",
59
- "cachetrax": "^1.0.4",
60
- "cookie": "^0.6.0",
61
- "data-arithmatic": "^1.0.7",
62
- "dayjs": "^1.11.13",
63
- "fable-log": "^3.0.16",
64
- "fable-serviceproviderbase": "^3.0.15",
65
- "fable-settings": "^3.0.12",
66
- "fable-uuid": "^3.0.11",
67
- "manyfest": "^1.0.38",
68
- "simple-get": "^4.0.1"
69
- }
21
+ "package": "./package.json",
22
+ "reporter": "spec",
23
+ "slow": "75",
24
+ "timeout": "5000",
25
+ "ui": "tdd",
26
+ "watch-files": [
27
+ "source/**/*.js",
28
+ "test/**/*.js"
29
+ ],
30
+ "watch-ignore": [
31
+ "lib/vendor"
32
+ ]
33
+ },
34
+ "browser": {
35
+ "./source/service/Fable-Service-EnvironmentData.js": "./source/service/Fable-Service-EnvironmentData-Web.js",
36
+ "./source/service/Fable-Service-FilePersistence.js": "./source/service/Fable-Service-FilePersistence-Web.js"
37
+ },
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "https://github.com/stevenvelozo/fable.git"
41
+ },
42
+ "keywords": [
43
+ "entity",
44
+ "behavior"
45
+ ],
46
+ "author": "Steven Velozo <steven@velozo.com> (http://velozo.com/)",
47
+ "license": "MIT",
48
+ "bugs": {
49
+ "url": "https://github.com/stevenvelozo/fable/issues"
50
+ },
51
+ "homepage": "https://github.com/stevenvelozo/fable",
52
+ "devDependencies": {
53
+ "quackage": "^1.0.41"
54
+ },
55
+ "dependencies": {
56
+ "async.eachlimit": "^0.5.2",
57
+ "async.waterfall": "^0.5.2",
58
+ "big.js": "^6.2.2",
59
+ "cachetrax": "^1.0.4",
60
+ "cookie": "^0.6.0",
61
+ "data-arithmatic": "^1.0.7",
62
+ "dayjs": "^1.11.13",
63
+ "fable-log": "^3.0.16",
64
+ "fable-serviceproviderbase": "^3.0.15",
65
+ "fable-settings": "^3.0.12",
66
+ "fable-uuid": "^3.0.11",
67
+ "manyfest": "^1.0.38",
68
+ "simple-get": "^4.0.1"
69
+ }
70
70
  }
@@ -129,6 +129,16 @@
129
129
  "Address": "fable.Utility.getInternalValueByHash"
130
130
  },
131
131
 
132
+ "findfirstvaluebyexactmatch": {
133
+ "Name": "find + map on array of objects?",
134
+ "Address": "fable.Utility.findFirstValueByExactMatchInternal"
135
+ },
136
+
137
+ "findfirstvaluebystringincludes": {
138
+ "Name": "find + map on array of objects?",
139
+ "Address": "fable.Utility.findFirstValueByStringIncludesInternal"
140
+ },
141
+
132
142
  "entryinset": {
133
143
  "Name": "Entry in Set",
134
144
  "Address": "fable.Math.entryInSet"
@@ -220,4 +230,4 @@
220
230
  "Name": "Create Value Object by Hashes",
221
231
  "Address": "fable.Utility.createValueObjectByHashes"
222
232
  }
223
- }
233
+ }
@@ -371,6 +371,31 @@ class FableServiceUtility extends libFableServiceBase
371
371
  return undefined;
372
372
  }
373
373
 
374
+ /**
375
+ * Find the first value in an object that contains a specific value
376
+ * @param {string} pFableAddress - The address in the fable object to pull the value from
377
+ * @param {string} pValueToMatchAddress - The manyfest hash/address of the value to match
378
+ * @param {string} pValueToMatch - The value to match
379
+ * @param {string} pValueAddress - The manyfest hash/address of the value to return
380
+ * @returns {any} - The value from the object
381
+ */
382
+ findFirstValueByStringIncludesInternal(pFableAddress, pValueToMatchAddress, pValueToMatch, pValueAddress)
383
+ {
384
+ // Lazily create a manifest if it doesn't exist
385
+ if (!this.manifest)
386
+ {
387
+ this.manifest = this.fable.newManyfest();
388
+ }
389
+
390
+ if (typeof(pFableAddress) != 'string')
391
+ {
392
+ return undefined;
393
+ }
394
+ let tmpObjectArray = this.manifest.getValueByHash(this.fable, pFableAddress);
395
+
396
+ return this.findFirstValueByStringIncludes(tmpObjectArray, pValueToMatchAddress, pValueToMatch, pValueAddress);
397
+ }
398
+
374
399
  /**
375
400
  * Find the first value in an object that contains a specific value
376
401
  * @param {array} pObjectArray - The array of objects to search
@@ -402,6 +427,31 @@ class FableServiceUtility extends libFableServiceBase
402
427
 
403
428
  return undefined;
404
429
  }
430
+
431
+ /**
432
+ * Find the first value in an object that contains a specific value
433
+ * @param {string} pFableAddress - The address in the fable object to pull the value from
434
+ * @param {string} pValueToMatchAddress - The manyfest hash/address of the value to match
435
+ * @param {string} pValueToMatch - The value to match
436
+ * @param {string} pValueAddress - The manyfest hash/address of the value to return
437
+ * @returns {any} - The value from the object
438
+ */
439
+ findFirstValueByExactMatchInternal(pFableAddress, pValueToMatchAddress, pValueToMatch, pValueAddress)
440
+ {
441
+ // Lazily create a manifest if it doesn't exist
442
+ if (!this.manifest)
443
+ {
444
+ this.manifest = this.fable.newManyfest();
445
+ }
446
+
447
+ if (typeof(pFableAddress) != 'string')
448
+ {
449
+ return undefined;
450
+ }
451
+ let tmpObjectArray = this.manifest.getValueByHash(this.fable, pFableAddress);
452
+
453
+ return this.findFirstValueByExactMatch(tmpObjectArray, pValueToMatchAddress, pValueToMatch, pValueAddress);
454
+ }
405
455
  }
406
456
 
407
457
  module.exports = FableServiceUtility;