react 0.2.4 → 0.2.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.
- package/README.md +4 -4
- package/lib/.#event-manager.js +1 -0
- package/lib/core.js +4 -4
- package/lib/event-manager.js +2 -1
- package/lib/validate.js +13 -4
- package/lib/vcon.js +2 -0
- package/package.json +1 -1
- package/test/validate.test.js +27 -1
package/README.md
CHANGED
|
@@ -242,7 +242,7 @@ fn(2, 3, function (err, m, s) {
|
|
|
242
242
|
|
|
243
243
|
## Status
|
|
244
244
|
|
|
245
|
-
- 2012-01-11 - Provide warning/error when name is skipped in default DSL (v0.2.
|
|
245
|
+
- 2012-01-11 - Provide warning/error when name is skipped in default DSL, literal check in validate (v0.2.5)
|
|
246
246
|
- 2012-01-10 - Create default DSL for react(), create error for missing variables, list remaining tasks when flow won't complete
|
|
247
247
|
- 2011-12-21 - Refactor from ground up with tests, changes to the interfaces
|
|
248
248
|
- 2011-10-26 - React is in active development and interface may change frequently in these early stages. Current code is functional but does not perform validation yet. Additional interfaces are planned to make it easy to define flows in a variety of ways. Documentation and examples forthcoming.
|
|
@@ -254,7 +254,7 @@ ok ast.test.js .................... 10/10
|
|
|
254
254
|
ok cb-task.test.js ................ 31/31
|
|
255
255
|
ok chain.test.js .................. 56/56
|
|
256
256
|
ok core.test.js ................... 98/98
|
|
257
|
-
ok dsl.test.js ....................
|
|
257
|
+
ok dsl.test.js .................... 63/63
|
|
258
258
|
ok event-manager.test.js .......... 13/13
|
|
259
259
|
ok exec-options.test.js ............. 3/3
|
|
260
260
|
ok finalcb-task.test.js ............. 5/5
|
|
@@ -266,9 +266,9 @@ ok ret-task.test.js ............... 31/31
|
|
|
266
266
|
ok task.test.js ..................... 1/1
|
|
267
267
|
ok validate-cb-task.test.js ......... 6/6
|
|
268
268
|
ok validate-ret-task.test.js ........ 7/7
|
|
269
|
-
ok validate.test.js ...............
|
|
269
|
+
ok validate.test.js ............... 31/31
|
|
270
270
|
ok vcon.test.js ................... 42/42
|
|
271
|
-
total ...........................
|
|
271
|
+
total ........................... 623/623
|
|
272
272
|
|
|
273
273
|
ok
|
|
274
274
|
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
barczewskij@ELSSTLM-184670.local.99357
|
package/lib/core.js
CHANGED
|
@@ -13,10 +13,10 @@ var inputParser = require('./input-parser.js');
|
|
|
13
13
|
var idGenerator = require('./id.js');
|
|
14
14
|
|
|
15
15
|
var reactOptions = {
|
|
16
|
-
stackTraceLimitMin: 30
|
|
16
|
+
stackTraceLimitMin: 30
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
var reactEmitter = EventManager.
|
|
19
|
+
var reactEmitter = EventManager.globalEventManager; // the top emitter
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
Creates react function which the AST can be manipulated and then
|
|
@@ -39,7 +39,7 @@ var reactEmitter = EventManager.create(); // the top emitter
|
|
|
39
39
|
*/
|
|
40
40
|
function reactFactory() {
|
|
41
41
|
if (arguments.length) throw new Error('react() takes no args, check API');
|
|
42
|
-
|
|
42
|
+
|
|
43
43
|
error.ensureStackTraceLimitSet(reactOptions.stackTraceLimitMin);
|
|
44
44
|
var flowEmitter = EventManager.create();
|
|
45
45
|
flowEmitter.parent = reactEmitter;
|
|
@@ -75,7 +75,7 @@ function reactFactory() {
|
|
|
75
75
|
if (outTask.isReady()) return outTask.exec(); // all tasks done, exec cb, return
|
|
76
76
|
tskutil.findReadyAndExec(vCon, tasks, tasksByName, handleError, contExec); //exec tasks that ready to run
|
|
77
77
|
}
|
|
78
|
-
|
|
78
|
+
|
|
79
79
|
tasks.forEach(function (t) {
|
|
80
80
|
t.id = idGenerator.createUniqueId();
|
|
81
81
|
t.flowEmitter = flowEmitter;
|
package/lib/event-manager.js
CHANGED
package/lib/validate.js
CHANGED
|
@@ -13,6 +13,9 @@ var LOCALS_NOTNULL = 'ast.locals should not be null';
|
|
|
13
13
|
var DUP_OUTPUTS = 'multiple tasks output the same param, must be unique. param';
|
|
14
14
|
var MISSING_INPUTS = 'missing or mispelled variable referenced in flow definition: %s';
|
|
15
15
|
|
|
16
|
+
// match any of our literals true, false, int, float, quoted strings, or is property (has dot)
|
|
17
|
+
var LITERAL_OR_PROP_RE = /^(true|false|\-?[0-9\.]+)$|'|"|\./i;
|
|
18
|
+
|
|
16
19
|
var validateInParams, validateTasks, validateOutTask, validateTaskNamesUnique;
|
|
17
20
|
var validateLocals, validateOuputsUnique, validateNoMissingNames;
|
|
18
21
|
|
|
@@ -20,10 +23,15 @@ function format_error(errmsg, obj) {
|
|
|
20
23
|
return sprintf('%s - %s', errmsg, util.inspect(obj));
|
|
21
24
|
}
|
|
22
25
|
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
/**
|
|
27
|
+
true if is a literal name
|
|
28
|
+
*/
|
|
29
|
+
function isLiteralOrProp(name) { // need to match what is in vcon.js, TODO consolidate?
|
|
30
|
+
return LITERAL_OR_PROP_RE.test(name);
|
|
25
31
|
}
|
|
26
32
|
|
|
33
|
+
|
|
34
|
+
|
|
27
35
|
/**
|
|
28
36
|
validate the AST return Errors
|
|
29
37
|
@example
|
|
@@ -105,6 +113,7 @@ function validateOuputsUnique(taskDefs) {
|
|
|
105
113
|
return errors;
|
|
106
114
|
}
|
|
107
115
|
|
|
116
|
+
|
|
108
117
|
/**
|
|
109
118
|
validate there are no missing or mispelled param names in any task inputs
|
|
110
119
|
or the final task output
|
|
@@ -134,14 +143,14 @@ function validateNoMissingNames(ast) {
|
|
|
134
143
|
// now we have all possible provided vars, check task inputs are accounted for
|
|
135
144
|
ast.tasks.reduce(function (accum, t) { // for all tasks
|
|
136
145
|
return t.a.reduce(function (innerAccum, p) { // for all in params, except property
|
|
137
|
-
if (!
|
|
146
|
+
if (!isLiteralOrProp(p) && !names[p]) innerAccum.push(sprintf(MISSING_INPUTS, p)); // add error if missing
|
|
138
147
|
return innerAccum;
|
|
139
148
|
}, accum);
|
|
140
149
|
}, errors);
|
|
141
150
|
|
|
142
151
|
// now check the final task outputs
|
|
143
152
|
ast.outTask.a.reduce(function (accum, p) { // for final task out params
|
|
144
|
-
if (!
|
|
153
|
+
if (!isLiteralOrProp(p) && !names[p]) accum.push(sprintf(MISSING_INPUTS, p)); // add error if missing
|
|
145
154
|
return accum;
|
|
146
155
|
}, errors);
|
|
147
156
|
return errors;
|
package/lib/vcon.js
CHANGED
|
@@ -9,9 +9,11 @@ VContext.prototype.getLastResults = function () { return this.getVar(LAST_RESULT
|
|
|
9
9
|
VContext.prototype.setLastResults = function (args) { this.setVar(LAST_RESULTS_KEY, args); };
|
|
10
10
|
|
|
11
11
|
VContext.prototype.getVar = function (name) { //name might be simple or obj.prop, also literals
|
|
12
|
+
/*jshint regexp: false */
|
|
12
13
|
var vConValues = this.values;
|
|
13
14
|
if (typeof(name) !== 'string') return name; // literal boolean or number
|
|
14
15
|
name = name.trim();
|
|
16
|
+
// literal checks need to match what is in validate.js
|
|
15
17
|
if (name === 'true') return true;
|
|
16
18
|
if (name === 'false') return false;
|
|
17
19
|
if (/^-?[0-9]+$/.test(name)) return parseInt(name, 10); //int
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react",
|
|
3
3
|
"description": "React is a javascript module to make it easier to work with asynchronous code, by reducing boilerplate code and improving error and exception handling while allowing variable and task dependencies when defining flow.",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.5",
|
|
5
5
|
"author": "Jeff Barczewski <jeff.barczewski@gmail.com>",
|
|
6
6
|
"repository": { "type": "git", "url": "http://github.com/jeffbski/react.git" },
|
|
7
7
|
"bugs" : { "url": "http://github.com/jeffbski/react/issues" },
|
package/test/validate.test.js
CHANGED
|
@@ -263,4 +263,30 @@ test('missing or mispelled final output variables', function (t) {
|
|
|
263
263
|
];
|
|
264
264
|
t.deepEqual(validate(ast), messages);
|
|
265
265
|
t.end();
|
|
266
|
-
});
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
test('missing or mispelled validation ignores properties', function (t) {
|
|
269
|
+
var ast = {
|
|
270
|
+
inParams: ['obj'],
|
|
271
|
+
tasks: [
|
|
272
|
+
{ f: foo, a: ['obj.foo'], out: [] },
|
|
273
|
+
{ f: bar, a: ['obj.bar'], out: [] }
|
|
274
|
+
],
|
|
275
|
+
outTask: { a: ['obj.cat'] }
|
|
276
|
+
};
|
|
277
|
+
t.deepEqual(validate(ast), []);
|
|
278
|
+
t.end();
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
test('missing or mispelled validation ignores literals', function (t) {
|
|
282
|
+
var ast = {
|
|
283
|
+
inParams: [],
|
|
284
|
+
tasks: [
|
|
285
|
+
{ f: foo, a: ['true', 'false', '123', '123.1'], out: [] },
|
|
286
|
+
{ f: bar, a: ['-123', '-123.4', '"wow"', "'hey'"], out: [] }
|
|
287
|
+
],
|
|
288
|
+
outTask: { a: [] }
|
|
289
|
+
};
|
|
290
|
+
t.deepEqual(validate(ast), []);
|
|
291
|
+
t.end();
|
|
292
|
+
});
|