fable 3.0.18 → 3.0.21

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.
@@ -0,0 +1,11 @@
1
+ {
2
+ "EntrypointInputSourceFile": "./source/Fable-Browser-Shim.js",
3
+
4
+ "LibraryObjectName": "Fable",
5
+
6
+ "LibraryOutputFolder": "./dist/",
7
+
8
+ "LibraryUniminifiedFileName": "fable.compatible.js",
9
+
10
+ "LibraryMinifiedFileName": "fable.compatible.min.js"
11
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "EntrypointInputSourceFile": "./source/Fable-Browser-Shim.js",
3
+
4
+ "LibraryObjectName": "Fable",
5
+
6
+ "LibraryOutputFolder": "./dist/",
7
+
8
+ "LibraryUniminifiedFileName": "fable.compatible.js",
9
+
10
+ "LibraryMinifiedFileName": "fable.compatible.min.js"
11
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "EntrypointInputSourceFile": "./source/Fable-Browser-Shim.js",
3
+
4
+ "LibraryObjectName": "Fable",
5
+
6
+ "LibraryOutputFolder": "./dist/",
7
+
8
+ "LibraryUniminifiedFileName": "fable.js",
9
+
10
+ "LibraryMinifiedFileName": "fable.min.js"
11
+ }
package/gulpfile.js CHANGED
@@ -1,27 +1,108 @@
1
1
  'use strict';
2
2
 
3
- // We aren't abstracting this yet but here's the ... "Config"
4
- const _CONFIG = (
5
- {
6
- // The input source file that should be passed to browserify:
7
- // (if you need to auto-instantiate an object, for instance)
8
- EntrypointInputSourceFile: `${__dirname}/source/Fable-Browser-Shim.js`,
3
+ /*
4
+ After hours of reading and trying various ways of using gulp-env, environment variables
5
+ and babel browesrslistrc / package.json environments it is clear that the state of using
6
+ these tools is a mess. There are ways of getting it to work but none of them feel like
7
+ they will work well in the long term (all of the examples seem to be in bands of about
8
+ a year or two of working before the pattern changes entirely).
9
9
 
10
- // The name of the packaged object to be passed to browserify:
11
- // (browserify sets this to global scope and window.SOMEOBJECTNAMEHERE where SOMEOBJECTNAMEHERE is the string below)
12
- LibraryObjectName: `Fable`,
10
+ WHY did we need such a crazy compatible version? wkhtmltopdf is why. It uses a very
11
+ old incompatible version of the QT browser.
13
12
 
14
- // The folder to write the library files and maps out to:
15
- LibraryOutputFolder: `${__dirname}/dist/`,
13
+ Therefore, we will use a very old and simple method.
16
14
 
17
- // The name of the unminified version of the packaged library, for easy debugging:
18
- LibraryUniminifiedFileName: `fable.js`,
15
+ 1) There is a config file (gulpfile-config.json), documented here, describing the inputs and outputs for the build operation.
19
16
 
20
- // The name of the minified version of the packaged library, for production release:
21
- LibraryMinifiedFileName: `fable.min.js`
22
- });
17
+ const _CONFIG = (
18
+ {
19
+ // The input source file that should be passed to browserify:
20
+ // (if you need to auto-instantiate an object, for instance)
21
+ EntrypointInputSourceFile: `${__dirname}/source/Fable-Browser-Shim.js`,
22
+
23
+ // The name of the packaged object to be passed to browserify:
24
+ // (browserify sets this to global scope and window.SOMEOBJECTNAMEHERE where SOMEOBJECTNAMEHERE is the string below)
25
+ LibraryObjectName: `Fable`,
26
+
27
+ // The folder to write the library files and maps out to:
28
+ LibraryOutputFolder: `${__dirname}/dist/`,
29
+
30
+ // The name of the unminified version of the packaged library, for easy debugging:
31
+ LibraryUniminifiedFileName: `fable.js`,
32
+
33
+ // The name of the minified version of the packaged library, for production release:
34
+ LibraryMinifiedFileName: `fable.min.js`
35
+ });
36
+
37
+ 2) We are using a .browserslistrc file... this is what tells gulp-babel, through the
38
+ magic of the @babel/preset-env library, how to transpile the library into a compatible
39
+ enough format for our targets.
40
+
41
+ For example as of writing this, there are two targets we want:
42
+
43
+ * Modern browsers in the last five years, expressed as a .browserslistrc with the string "since 2018"
44
+ * Very old janky browsers expressed as a .browserslistrc with the string "> 0.01%"
45
+ ... which is interpreted as anything more than 0.01% of browsers in existence or something like that
46
+
47
+ 3) Because we want multiple outputs, and, the tools do fine if we want one output but some of
48
+ the toolchain doesn't like making different targets well, we're just going to have multiple
49
+ configurations and .browserslistrc files. So if our spec above says we need a ".browserslistrc"
50
+ file and a "gulpfile-config.json", we're going to make the following two sets of configuration:
51
+
52
+ * .browserslistrc_default, .gulpfile-config_default.json
53
+ * .browserslistrc_compatible, .gulpfile-config_compatible.json
54
+
55
+ 4) We will copy, synchronously, these files to where the rest of our toolchain expects
56
+ them, before we begin the build. This will be done by looking at the GULP_CUSTOM_BUILD_TARGET
57
+ environment variable. This allows us to create new targets to experiment by copying a couple files,
58
+ jimmying the settings and setting an environment variable before running the pipeline.
59
+
60
+ 5) We will run the toolchain and it will happily think it's just doing a single build and kinda work.
61
+
62
+ */
63
+ // BEGINNING OF STEP 3 and STEP 4 ABOVE
64
+ const libFS = require('fs');
65
+ const _GULP_CUSTOM_BUILD_TARGET = (typeof(process.env.GULP_CUSTOM_BUILD_TARGET) == 'undefined') ? 'default' : process.env.GULP_CUSTOM_BUILD_TARGET;
66
+ console.log(`--> Gulp custom build target set to: [${_GULP_CUSTOM_BUILD_TARGET}]`);
67
+ const _GULP_CONFIG = `./gulpfile-config_${_GULP_CUSTOM_BUILD_TARGET}.json`;
68
+ const _GULP_CONFIG_TARGET = `./gulpfile-config.json`;
69
+ console.log(` : Environment set gulp config [${_GULP_CONFIG}] will be copied to [${_GULP_CONFIG_TARGET}]`);
70
+ if (!libFS.existsSync(`./${_GULP_CONFIG}`))
71
+ {
72
+ console.log(`!!!> Enviromnent set gulp config doesn't exist!`);
73
+ process.exit(1);
74
+ }
75
+ else
76
+ {
77
+ libFS.copyFileSync(_GULP_CONFIG, _GULP_CONFIG_TARGET);
78
+ console.log(` > Environment Gulp Config copied`);
79
+ }
80
+ const _BROWSERSLISTRC = `./.browserslistrc_${_GULP_CUSTOM_BUILD_TARGET}`;
81
+ const _BROWSERSLISTRC_TARGET = `./.browserslistrc`;
82
+ console.log(` : Environment set browserslistrc [${_BROWSERSLISTRC}] will be copied to [${_BROWSERSLISTRC_TARGET}]`);
83
+ if (!libFS.existsSync(`./${_GULP_CONFIG}`))
84
+ {
85
+ console.log(`!!!> Enviromnent set browserslistrc doesn't exist!`);
86
+ process.exit(1);
87
+ }
88
+ else
89
+ {
90
+ libFS.copyFileSync(_BROWSERSLISTRC, _BROWSERSLISTRC_TARGET);
91
+ console.log(` > Environment Gulp Config copied`);
92
+ }
93
+ console.log(`---> The browserslistrc compatibility set is: ${libFS.readFileSync(_BROWSERSLISTRC_TARGET, 'utf8')}`);
94
+ // END OF STEP 3 and STEP 4 ABOVE
95
+
96
+
97
+ // ---> Now load the config and get on with building <--- \\
98
+ console.log(``);
99
+ console.log(`---> Loading the gulp config...`);
100
+ const _CONFIG = require('./gulpfile-config.json');
101
+ console.log(` > Building to [${_CONFIG.LibraryUniminifiedFileName}] and [${_CONFIG.LibraryMinifiedFileName}]`)
23
102
 
24
103
  // ---> Boilerplate Browser Uglification and Packaging <--- \\
104
+ console.log(``);
105
+ console.log(`--> Gulp is taking over!`);
25
106
 
26
107
  const libBrowserify = require('browserify');
27
108
  const libGulp = require('gulp');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fable",
3
- "version": "3.0.18",
3
+ "version": "3.0.21",
4
4
  "description": "An entity behavior management and API bundling library.",
5
5
  "main": "source/Fable.js",
6
6
  "scripts": {
@@ -8,6 +8,7 @@
8
8
  "coverage": "./node_modules/.bin/nyc --reporter=lcov --reporter=text-lcov ./node_modules/mocha/bin/_mocha -- -u tdd -R spec",
9
9
  "test": "./node_modules/.bin/mocha -u tdd -R spec",
10
10
  "build": "./node_modules/.bin/gulp build",
11
+ "build-compatible": "GULP_CUSTOM_BUILD_TARGET=compatible ./node_modules/.bin/gulp build",
11
12
  "docker-dev-build-image": "docker build ./ -f Dockerfile_LUXURYCode -t retold/fable:local",
12
13
  "docker-dev-run": "docker run -it -d --name retold-fable-dev -p 30001:8080 -v \"$PWD/.config:/home/coder/.config\" -v \"$PWD:/home/coder/fable\" -u \"$(id -u):$(id -g)\" -e \"DOCKER_USER=$USER\" retold/fable:local"
13
14
  },
@@ -44,10 +45,13 @@
44
45
  },
45
46
  "homepage": "https://github.com/stevenvelozo/fable",
46
47
  "devDependencies": {
48
+ "@babel/core": "^7.21.5",
49
+ "@babel/preset-env": "^7.21.5",
47
50
  "browserify": "^17.0.0",
48
51
  "chai": "4.3.7",
49
52
  "gulp": "^4.0.2",
50
53
  "gulp-babel": "^8.0.0",
54
+ "gulp-env": "^0.4.0",
51
55
  "gulp-sourcemaps": "^3.0.0",
52
56
  "gulp-terser": "^2.1.0",
53
57
  "gulp-util": "^3.0.8",
@@ -59,6 +63,7 @@
59
63
  "dependencies": {
60
64
  "async.eachlimit": "^0.5.2",
61
65
  "async.waterfall": "^0.5.2",
66
+ "data-arithmatic": "^1.0.3",
62
67
  "fable-log": "^3.0.6",
63
68
  "fable-settings": "^3.0.3",
64
69
  "fable-uuid": "^3.0.2"
@@ -0,0 +1,16 @@
1
+ const libFableServiceBase = require('./Fable-ServiceProviderBase.js');
2
+ const libDataArithmatic = require('data-arithmatic');
3
+
4
+ class FableServiceDataArithmatic extends libFableServiceBase
5
+ {
6
+ constructor(pFable, pOptions, pServiceHash)
7
+ {
8
+ super(pFable, pOptions, pServiceHash);
9
+
10
+ this.serviceType = 'DataArithmatic';
11
+
12
+ this._DataArithmaticLibrary = new libDataArithmatic();
13
+ }
14
+ }
15
+
16
+ module.exports = FableServiceDataArithmatic;
@@ -1,12 +1,24 @@
1
+ const libFableServiceBase = require('./Fable-ServiceProviderBase.js');
2
+
3
+
1
4
  // TODO: These are still pretty big -- consider the smaller polyfills
2
5
  const libAsyncWaterfall = require('async.waterfall');
3
6
  const libAsyncEachLimit = require('async.eachlimit');
4
7
 
5
- class FableUtility
8
+ class FableServiceUtility extends libFableServiceBase
6
9
  {
7
- constructor(pFable)
10
+ // Underscore and lodash have a behavior, _.template, which compiles a
11
+ // string-based template with code snippets into simple executable pieces,
12
+ // with the added twist of returning a precompiled function ready to go.
13
+ //
14
+ // NOTE: This does not implement underscore escape expressions
15
+ // NOTE: This does not implement underscore magic browser variable assignment
16
+ //
17
+ // This is an implementation of that.
18
+ // TODO: Make this use precedent, add configuration, add debugging.
19
+ constructor(pFable, pOptions, pServiceHash)
8
20
  {
9
- this.fable = pFable;
21
+ super(pFable, pOptions, pServiceHash);
10
22
 
11
23
  this.templates = {};
12
24
 
@@ -68,4 +80,4 @@ class FableUtility
68
80
  }
69
81
  }
70
82
 
71
- module.exports = FableUtility;
83
+ module.exports = FableServiceUtility;
package/source/Fable.js CHANGED
@@ -7,10 +7,11 @@ const libFableSettings = require('fable-settings');
7
7
  const libFableUUID = require('fable-uuid');
8
8
  const libFableLog = require('fable-log');
9
9
 
10
- const libFableUtility = require('./Fable-Utility.js');
11
10
  const libFableServiceManager = require('./Fable-ServiceManager.js');
12
11
 
12
+ const libFableServiceDataArithmatic = require('./Fable-Service-DataArithmatic.js');
13
13
  const libFableServiceTemplate = require('./Fable-Service-Template.js');
14
+ const libFableServiceUtility = require('./Fable-Service-Utility.js');
14
15
 
15
16
  const libFableOperation = require('./Fable-Operation.js');
16
17
 
@@ -28,9 +29,6 @@ class Fable
28
29
  this.log = new libFableLog(this.settingsManager.settings);
29
30
  this.log.initialize();
30
31
 
31
- // Built-in utility belt functions
32
- this.Utility = new libFableUtility(this);
33
-
34
32
  // Built-in dependencies
35
33
  this.Dependencies = (
36
34
  {
@@ -42,8 +40,20 @@ class Fable
42
40
 
43
41
  this.serviceManager = new libFableServiceManager(this);
44
42
 
43
+ // Initialize and instantiate the default baked-in Data Arithmatic service
44
+ this.serviceManager.addServiceType('DataArithmatic', libFableServiceDataArithmatic);
45
+ this.fable.serviceManager.instantiateServiceProvider('DataArithmatic', {}, 'Default-Service-DataArithmatic');
46
+ // This service is passing through the data arithmatic library
47
+ this.DataArithmatic = this.serviceManager.defaultServices.DataArithmatic._DataArithmaticLibrary;
48
+
49
+ // Initialize the template service
45
50
  this.serviceManager.addServiceType('Template', libFableServiceTemplate);
46
51
 
52
+ // Initialize and instantiate the default baked-in Utility service
53
+ this.serviceManager.addServiceType('Utility', libFableServiceUtility)
54
+ this.fable.serviceManager.instantiateServiceProvider('Utility', {}, 'Default-Service-Utility');
55
+ this.Utility = this.serviceManager.defaultServices.Utility;
56
+
47
57
  this.services = this.serviceManager.services;
48
58
  this.defaultServices = this.serviceManager.defaultServices;
49
59
  }
@@ -0,0 +1,223 @@
1
+ /**
2
+ * Unit tests for Fable's DataArithmatic service
3
+ *
4
+ * @license MIT
5
+ *
6
+ * @author Steven Velozo <steven@velozo.com>
7
+ */
8
+
9
+ var libFable = require('../source/Fable.js');
10
+
11
+ var Chai = require("chai");
12
+ var Expect = Chai.expect;
13
+
14
+ suite
15
+ (
16
+ 'DataArithmatic String',
17
+ function()
18
+ {
19
+ setup (()=> {} );
20
+
21
+ suite
22
+ (
23
+ 'Manipulate Strings',
24
+ ()=>
25
+ {
26
+ test
27
+ (
28
+ 'Reverse a String',
29
+ (fTestComplete)=>
30
+ {
31
+ let testFable = new libFable({LogStreams: false});
32
+ let _DataArithmatic = testFable.DataArithmatic;
33
+ Expect(_DataArithmatic
34
+ .stringReverse('Dogs'))
35
+ .to.equal('sgoD');
36
+ Expect(_DataArithmatic
37
+ .stringReverse('Florence and the Machine'))
38
+ .to.equal('enihcaM eht dna ecnerolF');
39
+ return fTestComplete();
40
+ }
41
+ )
42
+ test
43
+ (
44
+ 'Insecure String Hash',
45
+ (fTestComplete)=>
46
+ {
47
+ let testFable = new libFable({LogStreams: false});
48
+ let _DataArithmatic = testFable.DataArithmatic;
49
+ Expect(_DataArithmatic
50
+ .insecureStringHash('Dogs'))
51
+ .to.equal('HSH2135767');
52
+ Expect(_DataArithmatic
53
+ .insecureStringHash('Dogs1'))
54
+ .to.equal('HSH66208826');
55
+ Expect(_DataArithmatic
56
+ .insecureStringHash('This string is longer'))
57
+ .to.equal('HSH53260210');
58
+ // This repeat is intentional, to ensure stable hash generation after multiple runs.
59
+ Expect(_DataArithmatic
60
+ .insecureStringHash('Dogs'))
61
+ .to.equal('HSH2135767');
62
+ return fTestComplete();
63
+ }
64
+ )
65
+ test
66
+ (
67
+ 'Clean wrapping characters from a valid enclosure.',
68
+ (fTestComplete)=>
69
+ {
70
+ let testFable = new libFable({LogStreams: false});
71
+ let _DataArithmatic = testFable.DataArithmatic;
72
+ // Test the enclosure cleaning function
73
+ Expect(_DataArithmatic
74
+ .cleanEnclosureWrapCharacters('`', '`Dogs`'))
75
+ .to.equal('Dogs');
76
+ // Tests a cleaning where the enclosure is not wrapped with the expected character
77
+ Expect(_DataArithmatic
78
+ .cleanEnclosureWrapCharacters('"', '`Cats`'))
79
+ .to.equal('`Cats`');
80
+ // Tests a cleaning where the enclosure is not wrapped with the expected character
81
+ Expect(_DataArithmatic
82
+ .cleanEnclosureWrapCharacters('"', '"Dogs"'))
83
+ .to.equal('Dogs');
84
+ // Test cleaning an enclosure with multiple enclosures of the same type which are expected to stay intact
85
+ Expect(_DataArithmatic
86
+ .cleanEnclosureWrapCharacters('[', '[Array[with]weird other] Dogs in it['))
87
+ .to.equal('Array[with]weird other] Dogs in it');
88
+ // Test cleaning a string where the enclosure character is on one side but not the other
89
+ Expect(_DataArithmatic
90
+ .cleanEnclosureWrapCharacters('"', '"Dogs'))
91
+ .to.equal('"Dogs');
92
+ // Test cleaning a string where the enclosure character is on one side but not the other
93
+ Expect(_DataArithmatic
94
+ .cleanEnclosureWrapCharacters('"', 'Dogs"'))
95
+ .to.equal('Dogs"');
96
+ return fTestComplete();
97
+ }
98
+ );
99
+ test
100
+ (
101
+ 'Test if a string starts with a given substring - Javascript Engine startsWith',
102
+ (fTestComplete)=>
103
+ {
104
+ let testFable = new libFable({LogStreams: false});
105
+ let _DataArithmatic = testFable.DataArithmatic;
106
+ Expect(_DataArithmatic
107
+ .stringStartsWith('Dogs', 'Do'))
108
+ .to.equal(true);
109
+ Expect(_DataArithmatic
110
+ .stringStartsWith('Bats', 'Bats'))
111
+ .to.equal(true);
112
+ Expect(_DataArithmatic
113
+ .stringStartsWith('Dogs', 'Dogs are cool'))
114
+ .to.equal(false);
115
+ Expect(_DataArithmatic
116
+ .stringStartsWith('Dogs', 'Cats'))
117
+ .to.equal(false);
118
+ return fTestComplete();
119
+ }
120
+ );
121
+ test
122
+ (
123
+ 'Test if a string starts with a given substring - Internal startsWith',
124
+ (fTestComplete)=>
125
+ {
126
+ let testFable = new libFable({LogStreams: false});
127
+ let _DataArithmatic = testFable.DataArithmatic;
128
+ _DataArithmatic._UseEngineStringStartsWith = false;
129
+ Expect(_DataArithmatic
130
+ .stringStartsWith('Dogs', 'Do'))
131
+ .to.equal(true);
132
+ Expect(_DataArithmatic
133
+ .stringStartsWith('Bats', 'Bats'))
134
+ .to.equal(true);
135
+ Expect(_DataArithmatic
136
+ .stringStartsWith('Dogs', 'Dogs are cool'))
137
+ .to.equal(false);
138
+ Expect(_DataArithmatic
139
+ .stringStartsWith('Dogs', 'Cats'))
140
+ .to.equal(false);
141
+ return fTestComplete();
142
+ }
143
+ );
144
+ test
145
+ (
146
+ 'Test if a string ends with a given substring - Javascript Engine endsWith',
147
+ (fTestComplete)=>
148
+ {
149
+ let testFable = new libFable({LogStreams: false});
150
+ let _DataArithmatic = testFable.DataArithmatic;
151
+ Expect(_DataArithmatic
152
+ .stringEndsWith('Dogs', 'gs'))
153
+ .to.equal(true);
154
+ Expect(_DataArithmatic
155
+ .stringEndsWith('Bats', 'Bats'))
156
+ .to.equal(true);
157
+ Expect(_DataArithmatic
158
+ .stringEndsWith('Dogs', 'Dogs are cool'))
159
+ .to.equal(false);
160
+ Expect(_DataArithmatic
161
+ .stringEndsWith('Dogs', 'Cats'))
162
+ .to.equal(false);
163
+ return fTestComplete();
164
+ }
165
+ );
166
+ test
167
+ (
168
+ 'Test if a string ends with a given substring - Internal endsWith',
169
+ (fTestComplete)=>
170
+ {
171
+ let testFable = new libFable({LogStreams: false});
172
+ let _DataArithmatic = testFable.DataArithmatic;
173
+ _DataArithmatic._UseEngineStringEndsWith = false;
174
+ Expect(_DataArithmatic
175
+ .stringEndsWith('Dogs', 'gs'))
176
+ .to.equal(true);
177
+ Expect(_DataArithmatic
178
+ .stringEndsWith('Bats', 'Bats'))
179
+ .to.equal(true);
180
+ Expect(_DataArithmatic
181
+ .stringEndsWith('Dogs', 'Dogs are cool'))
182
+ .to.equal(false);
183
+ // We should be able to tell it a midpoint to "end" the string at
184
+ Expect(_DataArithmatic
185
+ .stringEndsWith('Start from a median point', 'median', 19))
186
+ .to.equal(true);
187
+ Expect(_DataArithmatic
188
+ .stringEndsWith('Start from a median point', 'median', 20))
189
+ .to.equal(false);
190
+ Expect(_DataArithmatic
191
+ .stringEndsWith('Dogs', 'Cats'))
192
+ .to.equal(false);
193
+ return fTestComplete();
194
+ }
195
+ );
196
+ test
197
+ (
198
+ 'Test cleaning nonalpha characters from a string',
199
+ (fTestComplete)=>
200
+ {
201
+ let testFable = new libFable({LogStreams: false});
202
+ let _DataArithmatic = testFable.DataArithmatic;
203
+ Expect(_DataArithmatic
204
+ .cleanNonAlphaCharacters('Dogs'))
205
+ .to.equal('Dogs');
206
+ Expect(_DataArithmatic
207
+ .cleanNonAlphaCharacters('Dogs are cool'))
208
+ .to.equal('Dogs_are_cool');
209
+ Expect(_DataArithmatic
210
+ .cleanNonAlphaCharacters('Dogs are cool!'))
211
+ .to.equal('Dogs_are_cool_');
212
+ // Test cleaning with no character
213
+ _DataArithmatic._Value_Clean_formatterCleanNonAlpha = '';
214
+ Expect(_DataArithmatic
215
+ .cleanNonAlphaCharacters('Dogs are cool!'))
216
+ .to.equal('Dogsarecool');
217
+ return fTestComplete();
218
+ }
219
+ );
220
+ }
221
+ );
222
+ }
223
+ );
@@ -10,7 +10,6 @@ var libFable = require('../source/Fable.js');
10
10
 
11
11
  var Chai = require("chai");
12
12
  var Expect = Chai.expect;
13
- var Assert = Chai.assert;
14
13
 
15
14
  suite
16
15
  (