meadow 1.0.29 → 1.0.32

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.
package/.travis.yml CHANGED
@@ -1,7 +1,12 @@
1
1
  language: node_js
2
2
  node_js:
3
- - "6"
4
3
  - "8"
4
+ - "10"
5
+ - "12"
6
+ - "14"
7
+ - "15"
8
+ services:
9
+ - mysql
5
10
  before_script:
6
11
  - mysql -e 'CREATE DATABASE FableTest;'
7
12
  addons:
@@ -13,4 +18,4 @@ after_script:
13
18
  - cat coverage/lcov.info | ./node_modules/codeclimate-test-reporter/bin/codeclimate.js
14
19
  - cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
15
20
  notifications:
16
- slack: paviateam:C1q99hL9XXpiPpau2PUrVZPC
21
+ slack: paviateam:C1q99hL9XXpiPpau2PUrVZPC
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meadow",
3
- "version": "1.0.29",
3
+ "version": "1.0.32",
4
4
  "description": "A data access library.",
5
5
  "main": "source/Meadow.js",
6
6
  "scripts": {
@@ -26,19 +26,19 @@
26
26
  },
27
27
  "homepage": "https://github.com/stevenvelozo/meadow",
28
28
  "devDependencies": {
29
+ "alasql": "^0.4.0",
29
30
  "chai": "3.5.0",
30
31
  "codeclimate-test-reporter": "0.4.1",
31
- "alasql": "^0.4.0",
32
- "mysql2": "1.2.0",
33
32
  "coveralls": "2.13.1",
34
33
  "groc": "^0.8.0",
35
34
  "istanbul": "0.4.5",
36
- "mocha": "3.4.1"
35
+ "mocha": "3.4.1",
36
+ "mysql2": "1.2.0"
37
37
  },
38
38
  "dependencies": {
39
39
  "async": "2.4.0",
40
40
  "fable": "~1.0.1",
41
- "foxhound": "~1.0.22",
41
+ "foxhound": "~1.0.34",
42
42
  "is-my-json-valid": "2.16.0",
43
43
  "underscore": "1.8.3"
44
44
  }
@@ -24,7 +24,7 @@ var MeadowRawQuery = function()
24
24
  function createNew(pMeadow)
25
25
  {
26
26
  // If a valid Fable object isn't passed in, return a constructor
27
- if ((typeof(pMeadow) !== 'object') || (!pMeadow.hasOwnProperty('fable')))
27
+ if ((typeof(pMeadow) !== 'object') || !('fable' in pMeadow))
28
28
  {
29
29
  return {new: createNew};
30
30
  }
package/source/Meadow.js CHANGED
@@ -16,7 +16,7 @@ var Meadow = function()
16
16
  function createNew(pFable, pScope, pJsonSchema, pSchema)
17
17
  {
18
18
  // If a valid Fable object isn't passed in, return a constructor
19
- if ((typeof(pFable) !== 'object') || (!pFable.hasOwnProperty('fable')))
19
+ if ((typeof(pFable) !== 'object') || !('fable' in pFable))
20
20
  {
21
21
  return {new: createNew};
22
22
  }
@@ -110,8 +110,8 @@ var Meadow = function()
110
110
  _IDUser = pIDUser;
111
111
  return this;
112
112
  };
113
-
114
-
113
+
114
+
115
115
  /**
116
116
  * Set the Provider for Query execution.
117
117
  *
@@ -126,7 +126,7 @@ var Meadow = function()
126
126
  {
127
127
  if (typeof(pProviderName) !== 'string')
128
128
  {
129
- return setProvider('None');
129
+ pProviderName = 'None';
130
130
  }
131
131
 
132
132
  var tmpProviderModuleFile = './providers/Meadow-Provider-'+pProviderName+'.js';
@@ -139,12 +139,11 @@ var Meadow = function()
139
139
  // Give the provider access to the schema object
140
140
  updateProviderState();
141
141
 
142
-
143
142
  _ProviderName = pProviderName;
144
143
  }
145
144
  catch (pError)
146
145
  {
147
- _Fable.log.error({ProviderModuleFile:tmpProviderModuleFile, InvalidProvider:pProviderName, error:pError}, 'Provider not set - require load problem');
146
+ _Fable.log.error('Provider not set - require load problem', {ProviderModuleFile:tmpProviderModuleFile, InvalidProvider:pProviderName, error:pError});
148
147
  //setProvider('None');
149
148
  }
150
149
 
@@ -280,14 +279,23 @@ var Meadow = function()
280
279
  /**
281
280
  * Get the role name for an index
282
281
  */
283
- var _RoleNames = [
284
- "Readonly",
285
- "User",
286
- "Manager",
287
- "Director",
288
- "Executive",
289
- "Administrator"
290
- ];
282
+ let _RoleNames;
283
+ if (Array.isArray(_Fable.settings.MeadowRoleNames))
284
+ {
285
+ _RoleNames = _Fable.settings.MeadowRoleNames;
286
+ }
287
+ else
288
+ {
289
+ _RoleNames =
290
+ [
291
+ 'Unauthenticated',
292
+ 'User',
293
+ 'Manager',
294
+ 'Director',
295
+ 'Executive',
296
+ 'Administrator',
297
+ ];
298
+ }
291
299
  var getRoleName = function(pRoleIndex)
292
300
  {
293
301
  if (pRoleIndex < 0 || pRoleIndex >= _RoleNames.length)
@@ -520,7 +528,32 @@ var Meadow = function()
520
528
  enumerable: true
521
529
  });
522
530
 
523
- _Fable.addServices(tmpNewMeadowObject);
531
+ // addServices removed in fable 2.x
532
+ if (typeof(_Fable.addServices) === 'function')
533
+ {
534
+ _Fable.addServices(tmpNewMeadowObject);
535
+ }
536
+ else
537
+ {
538
+ // bring over addServices implementation from Fable 1.x for backward compatibility
539
+ Object.defineProperty(tmpNewMeadowObject, 'fable',
540
+ {
541
+ get: function() { return _Fable; },
542
+ enumerable: false,
543
+ });
544
+
545
+ Object.defineProperty(tmpNewMeadowObject, 'settings',
546
+ {
547
+ get: function() { return _Fable.settings; },
548
+ enumerable: false,
549
+ });
550
+
551
+ Object.defineProperty(tmpNewMeadowObject, 'log',
552
+ {
553
+ get: function() { return _Fable.log; },
554
+ enumerable: false,
555
+ });
556
+ }
524
557
 
525
558
  return tmpNewMeadowObject;
526
559
  }
@@ -9,7 +9,7 @@ var MeadowProvider = function()
9
9
  function createNew(pFable)
10
10
  {
11
11
  // If a valid Fable object isn't passed in, return a constructor
12
- if ((typeof(pFable) !== 'object') || (!pFable.hasOwnProperty('fable')))
12
+ if ((typeof(pFable) !== 'object') || !('fable' in pFable))
13
13
  {
14
14
  return {new: createNew};
15
15
  }
@@ -164,7 +164,7 @@ suite
164
164
  function(pError, pQuery, pRecord)
165
165
  {
166
166
  // Can't really test update with NONE
167
-
167
+
168
168
  fDone();
169
169
  }
170
170
  )
@@ -194,7 +194,7 @@ suite
194
194
  testMeadow.doCount(testMeadow.query,
195
195
  function(pError, pQuery, pRecord)
196
196
  {
197
- libFable.log.info(pError, pRecord)
197
+ libFable.log.info(pError, pRecord);
198
198
  Expect(pQuery.parameters.result.executed).to.equal(true);
199
199
  fDone();
200
200
  }
@@ -204,4 +204,4 @@ suite
204
204
  }
205
205
  );
206
206
  }
207
- );
207
+ );
@@ -10,19 +10,7 @@ var Chai = require("chai");
10
10
  var Expect = Chai.expect;
11
11
  var Assert = Chai.assert;
12
12
 
13
- var libFable = require('fable').new({
14
- LogStreams:
15
- [
16
- {
17
- level: 'fatal',
18
- streamtype:'process.stdout',
19
- },
20
- {
21
- level: 'trace',
22
- path: __dirname+'/../tests.log'
23
- }
24
- ]
25
- });
13
+ var libFable = require('fable');
26
14
 
27
15
  var _TestAnimalJsonSchema = (
28
16
  {
@@ -65,10 +53,25 @@ suite
65
53
  'Meadow',
66
54
  function()
67
55
  {
56
+ let _Fable;
68
57
  setup
69
58
  (
70
59
  function()
71
60
  {
61
+ _Fable = libFable.new(
62
+ {
63
+ LogStreams:
64
+ [
65
+ {
66
+ level: 'fatal',
67
+ streamtype:'process.stdout',
68
+ },
69
+ {
70
+ level: 'trace',
71
+ path: __dirname+'/../tests.log'
72
+ }
73
+ ]
74
+ });
72
75
  }
73
76
  );
74
77
 
@@ -91,7 +94,7 @@ suite
91
94
  'There should be some basic metadata on the class properties',
92
95
  function()
93
96
  {
94
- var testMeadow = require('../source/Meadow.js').new(libFable);
97
+ var testMeadow = require('../source/Meadow.js').new(_Fable);
95
98
  Expect(testMeadow).to.have.a.property('scope')
96
99
  .that.is.a('string'); // Scope is always a string
97
100
  Expect(testMeadow).to.have.a.property('defaultIdentifier')
@@ -105,7 +108,7 @@ suite
105
108
  'Initialize with values',
106
109
  function()
107
110
  {
108
- var testMeadow = require('../source/Meadow.js').new(libFable, 'Animal', _TestAnimalJsonSchema);
111
+ var testMeadow = require('../source/Meadow.js').new(_Fable, 'Animal', _TestAnimalJsonSchema);
109
112
  Expect(testMeadow.scope)
110
113
  .to.equal('Animal');
111
114
  Expect(testMeadow.jsonSchema.title)
@@ -117,7 +120,7 @@ suite
117
120
  'Try out some role names',
118
121
  function()
119
122
  {
120
- var testMeadow = require('../source/Meadow.js').new(libFable, 'Animal', _TestAnimalJsonSchema);
123
+ var testMeadow = require('../source/Meadow.js').new(_Fable, 'Animal', _TestAnimalJsonSchema);
121
124
  Expect(testMeadow.getRoleName(0))
122
125
  .to.equal('Unauthenticated');
123
126
  Expect(testMeadow.getRoleName(100))
@@ -133,7 +136,7 @@ suite
133
136
  'Alternative initialization',
134
137
  function()
135
138
  {
136
- var testMeadow = require('../source/Meadow.js').new(libFable)
139
+ var testMeadow = require('../source/Meadow.js').new(_Fable)
137
140
  .setScope('Animal')
138
141
  .setSchema(_TestAnimalJsonSchema);
139
142
  Expect(testMeadow.scope)
@@ -148,7 +151,7 @@ suite
148
151
  'Validate a proper animal',
149
152
  function()
150
153
  {
151
- var testMeadow = require('../source/Meadow.js').new(libFable, 'Animal', _TestAnimalJsonSchema);
154
+ var testMeadow = require('../source/Meadow.js').new(_Fable, 'Animal', _TestAnimalJsonSchema);
152
155
  var tmpValidationResults = testMeadow.validateObject({id:10, type:'bunny', name:'foofoo', age:3});
153
156
  Expect(tmpValidationResults.Valid)
154
157
  .to.equal(true);
@@ -159,10 +162,10 @@ suite
159
162
  'Validate a messed up animal',
160
163
  function()
161
164
  {
162
- var testMeadow = require('../source/Meadow.js').new(libFable, 'Animal', _TestAnimalJsonSchema);
165
+ var testMeadow = require('../source/Meadow.js').new(_Fable, 'Animal', _TestAnimalJsonSchema);
163
166
  // Our zombie needs a name!
164
167
  var tmpValidationResults = testMeadow.validateObject({id:9, type:'zombie', age:3});
165
- libFable.log.info('Bad Unnamed Zombie Validation Results', tmpValidationResults);
168
+ _Fable.log.info('Bad Unnamed Zombie Validation Results', tmpValidationResults);
166
169
  Expect(tmpValidationResults.Valid)
167
170
  .to.equal(false);
168
171
  }
@@ -172,7 +175,7 @@ suite
172
175
  'Change provider',
173
176
  function()
174
177
  {
175
- var testMeadow = require('../source/Meadow.js').new(libFable, 'Animal', _TestAnimalJsonSchema);
178
+ var testMeadow = require('../source/Meadow.js').new(_Fable, 'Animal', _TestAnimalJsonSchema);
176
179
  Expect(testMeadow.providerName)
177
180
  .to.equal('None');
178
181
  }
@@ -182,7 +185,7 @@ suite
182
185
  'Test log slow query method',
183
186
  function()
184
187
  {
185
- var testMeadow = require('../source/Meadow.js').new(libFable, 'Animal', _TestAnimalJsonSchema);
188
+ var testMeadow = require('../source/Meadow.js').new(_Fable, 'Animal', _TestAnimalJsonSchema);
186
189
  testMeadow.logSlowQuery(100, testMeadow.query);
187
190
  }
188
191
  );
@@ -191,7 +194,7 @@ suite
191
194
  'Try to change to a bad provider',
192
195
  function()
193
196
  {
194
- var testMeadow = require('../source/Meadow.js').new(libFable, 'Animal', _TestAnimalJsonSchema);
197
+ var testMeadow = require('../source/Meadow.js').new(_Fable, 'Animal', _TestAnimalJsonSchema);
195
198
  Expect(testMeadow.providerName)
196
199
  .to.equal('None');
197
200
  testMeadow.setProvider();
@@ -207,7 +210,7 @@ suite
207
210
  'Try to load from a json package',
208
211
  function()
209
212
  {
210
- var testMeadow = require('../source/Meadow.js').new(libFable).loadFromPackage(__dirname+'/Animal.json');
213
+ var testMeadow = require('../source/Meadow.js').new(_Fable).loadFromPackage(__dirname+'/Animal.json');
211
214
  Expect(testMeadow.scope)
212
215
  .to.equal('FableTest');
213
216
  }
@@ -217,7 +220,7 @@ suite
217
220
  'Try to load from an empty json package',
218
221
  function()
219
222
  {
220
- var testMeadow = require('../source/Meadow.js').new(libFable).loadFromPackage(__dirname+'/EmptyPackage.json');
223
+ var testMeadow = require('../source/Meadow.js').new(_Fable).loadFromPackage(__dirname+'/EmptyPackage.json');
221
224
  Expect(testMeadow.scope)
222
225
  .to.equal('Unknown');
223
226
  }
@@ -227,12 +230,44 @@ suite
227
230
  'Try to load from a bad json package',
228
231
  function()
229
232
  {
230
- var testMeadow = require('../source/Meadow.js').new(libFable).loadFromPackage(__dirname+'/BadAnimal.json');
233
+ var testMeadow = require('../source/Meadow.js').new(_Fable).loadFromPackage(__dirname+'/BadAnimal.json');
231
234
  Expect(testMeadow)
232
235
  .to.equal(false);
233
236
  }
234
237
  );
238
+
239
+ test
240
+ (
241
+ 'Able to override role names',
242
+ function()
243
+ {
244
+ // given
245
+ _Fable = libFable.new(
246
+ {
247
+ MeadowRoleNames: ['Cool', 'Bold', 'Tired'],
248
+ LogStreams:
249
+ [
250
+ {
251
+ level: 'fatal',
252
+ streamtype:'process.stdout',
253
+ },
254
+ {
255
+ level: 'trace',
256
+ path: __dirname+'/../tests.log'
257
+ }
258
+ ]
259
+ });
260
+
261
+ const meadow = require('../source/Meadow.js').new(_Fable);
262
+
263
+ // when
264
+ const roleNames = [0, 1, 2].map(i => meadow.getRoleName(i));
265
+
266
+ // then
267
+ Expect(roleNames).to.deep.equal(_Fable.settings.MeadowRoleNames);
268
+ }
269
+ );
235
270
  }
236
271
  );
237
272
  }
238
- );
273
+ );