id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
|
|---|---|---|---|---|---|---|---|---|---|---|---|
14,700
|
adrai/node-cqrs-domain
|
lib/aggregateModel.js
|
function (streamInfo) {
if (!streamInfo) {
return this.get('_revision');
}
streamInfo.context = streamInfo.context || '_general';
return this.get('_revisions')[streamInfo.context + '_' + streamInfo.aggregate + '_' + streamInfo.aggregateId] || 0;
}
|
javascript
|
function (streamInfo) {
if (!streamInfo) {
return this.get('_revision');
}
streamInfo.context = streamInfo.context || '_general';
return this.get('_revisions')[streamInfo.context + '_' + streamInfo.aggregate + '_' + streamInfo.aggregateId] || 0;
}
|
[
"function",
"(",
"streamInfo",
")",
"{",
"if",
"(",
"!",
"streamInfo",
")",
"{",
"return",
"this",
".",
"get",
"(",
"'_revision'",
")",
";",
"}",
"streamInfo",
".",
"context",
"=",
"streamInfo",
".",
"context",
"||",
"'_general'",
";",
"return",
"this",
".",
"get",
"(",
"'_revisions'",
")",
"[",
"streamInfo",
".",
"context",
"+",
"'_'",
"+",
"streamInfo",
".",
"aggregate",
"+",
"'_'",
"+",
"streamInfo",
".",
"aggregateId",
"]",
"||",
"0",
";",
"}"
] |
Returns the revision of this aggregate.
@param {Object} streamInfo The stream info.
@returns {Number}
|
[
"Returns",
"the",
"revision",
"of",
"this",
"aggregate",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/aggregateModel.js#L68-L74
|
|
14,701
|
adrai/node-cqrs-domain
|
lib/aggregateModel.js
|
function (data) {
if (arguments.length === 2) {
dotty.put(this.attributes, arguments[0], arguments[1]);
} else if (_.isObject(data)) {
for (var m in data) {
dotty.put(this.attributes, m, data[m]);
}
}
}
|
javascript
|
function (data) {
if (arguments.length === 2) {
dotty.put(this.attributes, arguments[0], arguments[1]);
} else if (_.isObject(data)) {
for (var m in data) {
dotty.put(this.attributes, m, data[m]);
}
}
}
|
[
"function",
"(",
"data",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
"===",
"2",
")",
"{",
"dotty",
".",
"put",
"(",
"this",
".",
"attributes",
",",
"arguments",
"[",
"0",
"]",
",",
"arguments",
"[",
"1",
"]",
")",
";",
"}",
"else",
"if",
"(",
"_",
".",
"isObject",
"(",
"data",
")",
")",
"{",
"for",
"(",
"var",
"m",
"in",
"data",
")",
"{",
"dotty",
".",
"put",
"(",
"this",
".",
"attributes",
",",
"m",
",",
"data",
"[",
"m",
"]",
")",
";",
"}",
"}",
"}"
] |
Sets attributes for the aggregate.
@example:
aggregate.set('firstname', 'Jack');
// or
aggregate.set({
firstname: 'Jack',
lastname: 'X-Man'
});
|
[
"Sets",
"attributes",
"for",
"the",
"aggregate",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/aggregateModel.js#L119-L127
|
|
14,702
|
adrai/node-cqrs-domain
|
lib/aggregateModel.js
|
function (data) {
if (data instanceof AggregateModel) {
this.attributes = data.toJSON();
} else {
this.attributes = _.cloneDeep(data || {});
}
this.attributes.id = this.id;
this.attributes._destroyed = this.attributes._destroyed || false;
this.attributes._revision = this.attributes._revision || 0;
}
|
javascript
|
function (data) {
if (data instanceof AggregateModel) {
this.attributes = data.toJSON();
} else {
this.attributes = _.cloneDeep(data || {});
}
this.attributes.id = this.id;
this.attributes._destroyed = this.attributes._destroyed || false;
this.attributes._revision = this.attributes._revision || 0;
}
|
[
"function",
"(",
"data",
")",
"{",
"if",
"(",
"data",
"instanceof",
"AggregateModel",
")",
"{",
"this",
".",
"attributes",
"=",
"data",
".",
"toJSON",
"(",
")",
";",
"}",
"else",
"{",
"this",
".",
"attributes",
"=",
"_",
".",
"cloneDeep",
"(",
"data",
"||",
"{",
"}",
")",
";",
"}",
"this",
".",
"attributes",
".",
"id",
"=",
"this",
".",
"id",
";",
"this",
".",
"attributes",
".",
"_destroyed",
"=",
"this",
".",
"attributes",
".",
"_destroyed",
"||",
"false",
";",
"this",
".",
"attributes",
".",
"_revision",
"=",
"this",
".",
"attributes",
".",
"_revision",
"||",
"0",
";",
"}"
] |
Resets the attributes for the aggregate.
|
[
"Resets",
"the",
"attributes",
"for",
"the",
"aggregate",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/aggregateModel.js#L157-L167
|
|
14,703
|
adrai/node-cqrs-domain
|
index.js
|
construct
|
function construct(klass, args) {
function T() {
klass.apply(this, arguments[0]);
}
T.prototype = klass.prototype;
return new T(args);
}
|
javascript
|
function construct(klass, args) {
function T() {
klass.apply(this, arguments[0]);
}
T.prototype = klass.prototype;
return new T(args);
}
|
[
"function",
"construct",
"(",
"klass",
",",
"args",
")",
"{",
"function",
"T",
"(",
")",
"{",
"klass",
".",
"apply",
"(",
"this",
",",
"arguments",
"[",
"0",
"]",
")",
";",
"}",
"T",
".",
"prototype",
"=",
"klass",
".",
"prototype",
";",
"return",
"new",
"T",
"(",
"args",
")",
";",
"}"
] |
Calls the constructor.
@param {Object} klass Constructor function.
@param {Array} args Arguments for the constructor function.
@return {Object} The new object.
|
[
"Calls",
"the",
"constructor",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/index.js#L22-L28
|
14,704
|
adrai/node-cqrs-domain
|
lib/defaultCommandHandler.js
|
randomBetween
|
function randomBetween(min, max) {
return Math.round(min + Math.random() * (max - min));
}
|
javascript
|
function randomBetween(min, max) {
return Math.round(min + Math.random() * (max - min));
}
|
[
"function",
"randomBetween",
"(",
"min",
",",
"max",
")",
"{",
"return",
"Math",
".",
"round",
"(",
"min",
"+",
"Math",
".",
"random",
"(",
")",
"*",
"(",
"max",
"-",
"min",
")",
")",
";",
"}"
] |
Returns a random number between passed values of min and max.
@param {Number} min The minimum value of the resulting random number.
@param {Number} max The maximum value of the resulting random number.
@returns {Number}
|
[
"Returns",
"a",
"random",
"number",
"between",
"passed",
"values",
"of",
"min",
"and",
"max",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/defaultCommandHandler.js#L19-L21
|
14,705
|
adrai/node-cqrs-domain
|
lib/defaultCommandHandler.js
|
function (aggregate) {
if (!aggregate || !_.isObject(aggregate)) {
var err = new Error('Please pass a valid aggregate!');
debug(err);
throw err;
}
this.aggregate = aggregate;
}
|
javascript
|
function (aggregate) {
if (!aggregate || !_.isObject(aggregate)) {
var err = new Error('Please pass a valid aggregate!');
debug(err);
throw err;
}
this.aggregate = aggregate;
}
|
[
"function",
"(",
"aggregate",
")",
"{",
"if",
"(",
"!",
"aggregate",
"||",
"!",
"_",
".",
"isObject",
"(",
"aggregate",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid aggregate!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"this",
".",
"aggregate",
"=",
"aggregate",
";",
"}"
] |
Injects the needed aggregate.
@param {Aggregate} aggregate The aggregate object to inject.
|
[
"Injects",
"the",
"needed",
"aggregate",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/defaultCommandHandler.js#L43-L50
|
|
14,706
|
adrai/node-cqrs-domain
|
lib/defaultCommandHandler.js
|
function (eventStore) {
if (!eventStore || !_.isObject(eventStore)) {
var err = new Error('Please pass a valid eventStore!');
debug(err);
throw err;
}
this.eventStore = eventStore;
}
|
javascript
|
function (eventStore) {
if (!eventStore || !_.isObject(eventStore)) {
var err = new Error('Please pass a valid eventStore!');
debug(err);
throw err;
}
this.eventStore = eventStore;
}
|
[
"function",
"(",
"eventStore",
")",
"{",
"if",
"(",
"!",
"eventStore",
"||",
"!",
"_",
".",
"isObject",
"(",
"eventStore",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid eventStore!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"this",
".",
"eventStore",
"=",
"eventStore",
";",
"}"
] |
Injects the needed eventStore.
@param {Object} eventStore The eventStore object to inject.
|
[
"Injects",
"the",
"needed",
"eventStore",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/defaultCommandHandler.js#L56-L63
|
|
14,707
|
adrai/node-cqrs-domain
|
lib/defaultCommandHandler.js
|
function (aggregateLock) {
if (!aggregateLock || !_.isObject(aggregateLock)) {
var err = new Error('Please pass a valid aggregateLock!');
debug(err);
throw err;
}
this.aggregateLock = aggregateLock;
}
|
javascript
|
function (aggregateLock) {
if (!aggregateLock || !_.isObject(aggregateLock)) {
var err = new Error('Please pass a valid aggregateLock!');
debug(err);
throw err;
}
this.aggregateLock = aggregateLock;
}
|
[
"function",
"(",
"aggregateLock",
")",
"{",
"if",
"(",
"!",
"aggregateLock",
"||",
"!",
"_",
".",
"isObject",
"(",
"aggregateLock",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid aggregateLock!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"this",
".",
"aggregateLock",
"=",
"aggregateLock",
";",
"}"
] |
Injects the needed aggregateLock.
@param {Object} aggregateLock The aggregateLock object to inject.
|
[
"Injects",
"the",
"needed",
"aggregateLock",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/defaultCommandHandler.js#L69-L76
|
|
14,708
|
adrai/node-cqrs-domain
|
lib/defaultCommandHandler.js
|
function (aggId, cmd, clb) {
if (!aggId || !_.isString(aggId)) {
var err = new Error('Please pass a valid aggregate id!');
debug(err);
throw err;
}
if (!cmd || !_.isObject(cmd)) {
var err = new Error('Please pass a valid command!');
debug(err);
throw err;
}
if (!clb || !_.isFunction(clb)) {
var err = new Error('Please pass a valid callback!');
debug(err);
throw err;
}
this.queue[aggId] = this.queue[aggId] || [];
this.queue[aggId].push({ command: cmd, callback: clb })
}
|
javascript
|
function (aggId, cmd, clb) {
if (!aggId || !_.isString(aggId)) {
var err = new Error('Please pass a valid aggregate id!');
debug(err);
throw err;
}
if (!cmd || !_.isObject(cmd)) {
var err = new Error('Please pass a valid command!');
debug(err);
throw err;
}
if (!clb || !_.isFunction(clb)) {
var err = new Error('Please pass a valid callback!');
debug(err);
throw err;
}
this.queue[aggId] = this.queue[aggId] || [];
this.queue[aggId].push({ command: cmd, callback: clb })
}
|
[
"function",
"(",
"aggId",
",",
"cmd",
",",
"clb",
")",
"{",
"if",
"(",
"!",
"aggId",
"||",
"!",
"_",
".",
"isString",
"(",
"aggId",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid aggregate id!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"if",
"(",
"!",
"cmd",
"||",
"!",
"_",
".",
"isObject",
"(",
"cmd",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid command!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"if",
"(",
"!",
"clb",
"||",
"!",
"_",
".",
"isFunction",
"(",
"clb",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid callback!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"this",
".",
"queue",
"[",
"aggId",
"]",
"=",
"this",
".",
"queue",
"[",
"aggId",
"]",
"||",
"[",
"]",
";",
"this",
".",
"queue",
"[",
"aggId",
"]",
".",
"push",
"(",
"{",
"command",
":",
"cmd",
",",
"callback",
":",
"clb",
"}",
")",
"}"
] |
Queues the passed command and its callback.
@param {String} aggId The passed aggregate id.
@param {Object} cmd The command to be queued.
@param {Function} clb The callback of this command.
|
[
"Queues",
"the",
"passed",
"command",
"and",
"its",
"callback",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/defaultCommandHandler.js#L84-L103
|
|
14,709
|
adrai/node-cqrs-domain
|
lib/defaultCommandHandler.js
|
function (aggId) {
if (!aggId || !_.isString(aggId)) {
var err = new Error('Please pass a valid aggregate id!');
debug(err);
throw err;
}
if (this.queue[aggId] && this.queue[aggId].length > 0) {
var nextCmd = this.queue[aggId][0];
return nextCmd;
}
return null;
}
|
javascript
|
function (aggId) {
if (!aggId || !_.isString(aggId)) {
var err = new Error('Please pass a valid aggregate id!');
debug(err);
throw err;
}
if (this.queue[aggId] && this.queue[aggId].length > 0) {
var nextCmd = this.queue[aggId][0];
return nextCmd;
}
return null;
}
|
[
"function",
"(",
"aggId",
")",
"{",
"if",
"(",
"!",
"aggId",
"||",
"!",
"_",
".",
"isString",
"(",
"aggId",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid aggregate id!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"if",
"(",
"this",
".",
"queue",
"[",
"aggId",
"]",
"&&",
"this",
".",
"queue",
"[",
"aggId",
"]",
".",
"length",
">",
"0",
")",
"{",
"var",
"nextCmd",
"=",
"this",
".",
"queue",
"[",
"aggId",
"]",
"[",
"0",
"]",
";",
"return",
"nextCmd",
";",
"}",
"return",
"null",
";",
"}"
] |
Returns next command in the queue
@param {String} aggId The passed aggregate id.
@returns {Object}
|
[
"Returns",
"next",
"command",
"in",
"the",
"queue"
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/defaultCommandHandler.js#L110-L123
|
|
14,710
|
adrai/node-cqrs-domain
|
lib/defaultCommandHandler.js
|
function (aggId, cmd) {
if (!aggId || !_.isString(aggId)) {
var err = new Error('Please pass a valid aggregate id!');
debug(err);
throw err;
}
_.remove(this.queue[aggId], function (c) {
return c.command === cmd;
});
}
|
javascript
|
function (aggId, cmd) {
if (!aggId || !_.isString(aggId)) {
var err = new Error('Please pass a valid aggregate id!');
debug(err);
throw err;
}
_.remove(this.queue[aggId], function (c) {
return c.command === cmd;
});
}
|
[
"function",
"(",
"aggId",
",",
"cmd",
")",
"{",
"if",
"(",
"!",
"aggId",
"||",
"!",
"_",
".",
"isString",
"(",
"aggId",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid aggregate id!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"_",
".",
"remove",
"(",
"this",
".",
"queue",
"[",
"aggId",
"]",
",",
"function",
"(",
"c",
")",
"{",
"return",
"c",
".",
"command",
"===",
"cmd",
";",
"}",
")",
";",
"}"
] |
Removes the passed command from the queue.
@param {String} aggId The passed aggregate id.
@param {Object} cmd The command to be queued.
|
[
"Removes",
"the",
"passed",
"command",
"from",
"the",
"queue",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/defaultCommandHandler.js#L130-L140
|
|
14,711
|
adrai/node-cqrs-domain
|
lib/defaultCommandHandler.js
|
function (aggregateId, callback) {
if (!aggregateId || !_.isString(aggregateId)) {
var err = new Error('Please pass a valid aggregateId!');
debug(err);
throw err;
}
if (!callback || !_.isFunction(callback)) {
var err = new Error('Please pass a valid callback!');
debug(err);
throw err;
}
this.aggregateLock.reserve(this.id, aggregateId, callback);
}
|
javascript
|
function (aggregateId, callback) {
if (!aggregateId || !_.isString(aggregateId)) {
var err = new Error('Please pass a valid aggregateId!');
debug(err);
throw err;
}
if (!callback || !_.isFunction(callback)) {
var err = new Error('Please pass a valid callback!');
debug(err);
throw err;
}
this.aggregateLock.reserve(this.id, aggregateId, callback);
}
|
[
"function",
"(",
"aggregateId",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"aggregateId",
"||",
"!",
"_",
".",
"isString",
"(",
"aggregateId",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid aggregateId!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"if",
"(",
"!",
"callback",
"||",
"!",
"_",
".",
"isFunction",
"(",
"callback",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid callback!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"this",
".",
"aggregateLock",
".",
"reserve",
"(",
"this",
".",
"id",
",",
"aggregateId",
",",
"callback",
")",
";",
"}"
] |
Locks the aggregate.
@param {String} aggregateId The passed aggregateId.
@param {Function} callback The function, that will be called when this action is completed.
`function(err){}`
|
[
"Locks",
"the",
"aggregate",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/defaultCommandHandler.js#L148-L160
|
|
14,712
|
adrai/node-cqrs-domain
|
lib/defaultCommandHandler.js
|
function (aggregate, stream, callback) {
if (!aggregate || !_.isObject(aggregate)) {
var err = new Error('Please pass a valid aggregate!');
debug(err);
throw err;
}
if (!stream || !_.isObject(stream)) {
var err = new Error('Please pass a valid aggregate!');
debug(err);
throw err;
}
var hasAggregateName = !!this.definitions.command.aggregate;
var hasContextName = !!this.definitions.command.context;
var query = {
aggregateId: aggregate.id
};
if (hasAggregateName) {
query.aggregate = this.aggregate.name;
}
if (hasContextName) {
query.context = this.aggregate.context.name;
}
query.data = aggregate.toJSON();
query.revision = stream.lastRevision;
query.version = this.aggregate.version;
var self = this;
process.nextTick(function() {
var transformer = self.aggregate.committingSnapshotTransformers[self.aggregate.context.name + '.' + self.aggregate.name + '.' + self.aggregate.version] || function (sn, cb) { cb(null, sn); };
transformer(query.data, function (err, snapData) {
if (err) {
debug(err);
if (callback) callback(err);
return;
}
query.data = snapData;
debug('cerate new snapshot');
self.eventStore.createSnapshot(query, function (err) {
if (err) {
debug(err);
if (callback) callback(err);
return;
}
debug('snapshot created');
if (callback) callback(null);
});
});
});
}
|
javascript
|
function (aggregate, stream, callback) {
if (!aggregate || !_.isObject(aggregate)) {
var err = new Error('Please pass a valid aggregate!');
debug(err);
throw err;
}
if (!stream || !_.isObject(stream)) {
var err = new Error('Please pass a valid aggregate!');
debug(err);
throw err;
}
var hasAggregateName = !!this.definitions.command.aggregate;
var hasContextName = !!this.definitions.command.context;
var query = {
aggregateId: aggregate.id
};
if (hasAggregateName) {
query.aggregate = this.aggregate.name;
}
if (hasContextName) {
query.context = this.aggregate.context.name;
}
query.data = aggregate.toJSON();
query.revision = stream.lastRevision;
query.version = this.aggregate.version;
var self = this;
process.nextTick(function() {
var transformer = self.aggregate.committingSnapshotTransformers[self.aggregate.context.name + '.' + self.aggregate.name + '.' + self.aggregate.version] || function (sn, cb) { cb(null, sn); };
transformer(query.data, function (err, snapData) {
if (err) {
debug(err);
if (callback) callback(err);
return;
}
query.data = snapData;
debug('cerate new snapshot');
self.eventStore.createSnapshot(query, function (err) {
if (err) {
debug(err);
if (callback) callback(err);
return;
}
debug('snapshot created');
if (callback) callback(null);
});
});
});
}
|
[
"function",
"(",
"aggregate",
",",
"stream",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"aggregate",
"||",
"!",
"_",
".",
"isObject",
"(",
"aggregate",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid aggregate!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"if",
"(",
"!",
"stream",
"||",
"!",
"_",
".",
"isObject",
"(",
"stream",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid aggregate!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"var",
"hasAggregateName",
"=",
"!",
"!",
"this",
".",
"definitions",
".",
"command",
".",
"aggregate",
";",
"var",
"hasContextName",
"=",
"!",
"!",
"this",
".",
"definitions",
".",
"command",
".",
"context",
";",
"var",
"query",
"=",
"{",
"aggregateId",
":",
"aggregate",
".",
"id",
"}",
";",
"if",
"(",
"hasAggregateName",
")",
"{",
"query",
".",
"aggregate",
"=",
"this",
".",
"aggregate",
".",
"name",
";",
"}",
"if",
"(",
"hasContextName",
")",
"{",
"query",
".",
"context",
"=",
"this",
".",
"aggregate",
".",
"context",
".",
"name",
";",
"}",
"query",
".",
"data",
"=",
"aggregate",
".",
"toJSON",
"(",
")",
";",
"query",
".",
"revision",
"=",
"stream",
".",
"lastRevision",
";",
"query",
".",
"version",
"=",
"this",
".",
"aggregate",
".",
"version",
";",
"var",
"self",
"=",
"this",
";",
"process",
".",
"nextTick",
"(",
"function",
"(",
")",
"{",
"var",
"transformer",
"=",
"self",
".",
"aggregate",
".",
"committingSnapshotTransformers",
"[",
"self",
".",
"aggregate",
".",
"context",
".",
"name",
"+",
"'.'",
"+",
"self",
".",
"aggregate",
".",
"name",
"+",
"'.'",
"+",
"self",
".",
"aggregate",
".",
"version",
"]",
"||",
"function",
"(",
"sn",
",",
"cb",
")",
"{",
"cb",
"(",
"null",
",",
"sn",
")",
";",
"}",
";",
"transformer",
"(",
"query",
".",
"data",
",",
"function",
"(",
"err",
",",
"snapData",
")",
"{",
"if",
"(",
"err",
")",
"{",
"debug",
"(",
"err",
")",
";",
"if",
"(",
"callback",
")",
"callback",
"(",
"err",
")",
";",
"return",
";",
"}",
"query",
".",
"data",
"=",
"snapData",
";",
"debug",
"(",
"'cerate new snapshot'",
")",
";",
"self",
".",
"eventStore",
".",
"createSnapshot",
"(",
"query",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"debug",
"(",
"err",
")",
";",
"if",
"(",
"callback",
")",
"callback",
"(",
"err",
")",
";",
"return",
";",
"}",
"debug",
"(",
"'snapshot created'",
")",
";",
"if",
"(",
"callback",
")",
"callback",
"(",
"null",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Creates a new snapshot.
@param {AggregateModel} aggregate The passed aggregate.
@param {Object} stream The event stream.
@param {Function} callback The function, that will be called when this action is completed. [optional]
`function(err){}`
|
[
"Creates",
"a",
"new",
"snapshot",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/defaultCommandHandler.js#L500-L556
|
|
14,713
|
adrai/node-cqrs-domain
|
lib/defaultCommandHandler.js
|
function (aggregate, cmd) {
if (!aggregate || !_.isObject(aggregate)) {
var err = new Error('Please pass a valid aggregate!');
debug(err);
throw err;
}
if (!cmd || !_.isObject(cmd)) {
var err = new Error('Please pass a valid command!');
debug(err);
throw err;
}
var contextName, aggregateName, aggregateId;
if (!!this.definitions.command.context) {
contextName = dotty.get(cmd, this.definitions.command.context);
}
if (!!this.definitions.command.aggregate) {
aggregateName = dotty.get(cmd, this.definitions.command.aggregate);
}
if (!!this.definitions.command.aggregateId) {
aggregateId = dotty.get(cmd, this.definitions.command.aggregateId);
}
var streamInfo = {
context: contextName,
aggregate: aggregateName,
aggregateId: aggregateId
};
if (aggregate.isDestroyed()) {
return new AggregateDestroyedError('Aggregate has already been destroyed!', {
aggregateId: aggregate.id,
aggregateRevision: aggregate.getRevision(streamInfo)
});
}
return null;
}
|
javascript
|
function (aggregate, cmd) {
if (!aggregate || !_.isObject(aggregate)) {
var err = new Error('Please pass a valid aggregate!');
debug(err);
throw err;
}
if (!cmd || !_.isObject(cmd)) {
var err = new Error('Please pass a valid command!');
debug(err);
throw err;
}
var contextName, aggregateName, aggregateId;
if (!!this.definitions.command.context) {
contextName = dotty.get(cmd, this.definitions.command.context);
}
if (!!this.definitions.command.aggregate) {
aggregateName = dotty.get(cmd, this.definitions.command.aggregate);
}
if (!!this.definitions.command.aggregateId) {
aggregateId = dotty.get(cmd, this.definitions.command.aggregateId);
}
var streamInfo = {
context: contextName,
aggregate: aggregateName,
aggregateId: aggregateId
};
if (aggregate.isDestroyed()) {
return new AggregateDestroyedError('Aggregate has already been destroyed!', {
aggregateId: aggregate.id,
aggregateRevision: aggregate.getRevision(streamInfo)
});
}
return null;
}
|
[
"function",
"(",
"aggregate",
",",
"cmd",
")",
"{",
"if",
"(",
"!",
"aggregate",
"||",
"!",
"_",
".",
"isObject",
"(",
"aggregate",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid aggregate!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"if",
"(",
"!",
"cmd",
"||",
"!",
"_",
".",
"isObject",
"(",
"cmd",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid command!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"var",
"contextName",
",",
"aggregateName",
",",
"aggregateId",
";",
"if",
"(",
"!",
"!",
"this",
".",
"definitions",
".",
"command",
".",
"context",
")",
"{",
"contextName",
"=",
"dotty",
".",
"get",
"(",
"cmd",
",",
"this",
".",
"definitions",
".",
"command",
".",
"context",
")",
";",
"}",
"if",
"(",
"!",
"!",
"this",
".",
"definitions",
".",
"command",
".",
"aggregate",
")",
"{",
"aggregateName",
"=",
"dotty",
".",
"get",
"(",
"cmd",
",",
"this",
".",
"definitions",
".",
"command",
".",
"aggregate",
")",
";",
"}",
"if",
"(",
"!",
"!",
"this",
".",
"definitions",
".",
"command",
".",
"aggregateId",
")",
"{",
"aggregateId",
"=",
"dotty",
".",
"get",
"(",
"cmd",
",",
"this",
".",
"definitions",
".",
"command",
".",
"aggregateId",
")",
";",
"}",
"var",
"streamInfo",
"=",
"{",
"context",
":",
"contextName",
",",
"aggregate",
":",
"aggregateName",
",",
"aggregateId",
":",
"aggregateId",
"}",
";",
"if",
"(",
"aggregate",
".",
"isDestroyed",
"(",
")",
")",
"{",
"return",
"new",
"AggregateDestroyedError",
"(",
"'Aggregate has already been destroyed!'",
",",
"{",
"aggregateId",
":",
"aggregate",
".",
"id",
",",
"aggregateRevision",
":",
"aggregate",
".",
"getRevision",
"(",
"streamInfo",
")",
"}",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Returns an error if the aggregate is destroyed.
@param {AggregateModel} aggregate The passed aggregate.
@param {Object} cmd The command.
@returns {AggregateDestroyedError}
|
[
"Returns",
"an",
"error",
"if",
"the",
"aggregate",
"is",
"destroyed",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/defaultCommandHandler.js#L564-L604
|
|
14,714
|
adrai/node-cqrs-domain
|
lib/defaultCommandHandler.js
|
function (aggregate, cmd) {
if (!aggregate || !_.isObject(aggregate)) {
var err = new Error('Please pass a valid aggregate!');
debug(err);
throw err;
}
if (!cmd || !_.isObject(cmd)) {
var err = new Error('Please pass a valid command!');
debug(err);
throw err;
}
var hasRevision = !!this.definitions.command.revision;
if (!hasRevision) {
return null;
}
var revisionInCommand = dotty.get(cmd, this.definitions.command.revision);
if (revisionInCommand === null || revisionInCommand === undefined) {
return null;
}
var contextName, aggregateName, aggregateId;
if (!!this.definitions.command.context) {
contextName = dotty.get(cmd, this.definitions.command.context);
}
if (!!this.definitions.command.aggregate) {
aggregateName = dotty.get(cmd, this.definitions.command.aggregate);
}
if (!!this.definitions.command.aggregateId) {
aggregateId = dotty.get(cmd, this.definitions.command.aggregateId);
}
var streamInfo = {
context: contextName,
aggregate: aggregateName,
aggregateId: aggregateId
};
if (revisionInCommand === aggregate.getRevision(streamInfo)) {
return null;
}
return new AggregateConcurrencyError('Actual revision in command is "' + revisionInCommand + '", but expected is "' + aggregate.getRevision(streamInfo) + '"!', {
aggregateId: aggregate.id,
aggregateRevision: aggregate.getRevision(streamInfo),
commandRevision: revisionInCommand
});
}
|
javascript
|
function (aggregate, cmd) {
if (!aggregate || !_.isObject(aggregate)) {
var err = new Error('Please pass a valid aggregate!');
debug(err);
throw err;
}
if (!cmd || !_.isObject(cmd)) {
var err = new Error('Please pass a valid command!');
debug(err);
throw err;
}
var hasRevision = !!this.definitions.command.revision;
if (!hasRevision) {
return null;
}
var revisionInCommand = dotty.get(cmd, this.definitions.command.revision);
if (revisionInCommand === null || revisionInCommand === undefined) {
return null;
}
var contextName, aggregateName, aggregateId;
if (!!this.definitions.command.context) {
contextName = dotty.get(cmd, this.definitions.command.context);
}
if (!!this.definitions.command.aggregate) {
aggregateName = dotty.get(cmd, this.definitions.command.aggregate);
}
if (!!this.definitions.command.aggregateId) {
aggregateId = dotty.get(cmd, this.definitions.command.aggregateId);
}
var streamInfo = {
context: contextName,
aggregate: aggregateName,
aggregateId: aggregateId
};
if (revisionInCommand === aggregate.getRevision(streamInfo)) {
return null;
}
return new AggregateConcurrencyError('Actual revision in command is "' + revisionInCommand + '", but expected is "' + aggregate.getRevision(streamInfo) + '"!', {
aggregateId: aggregate.id,
aggregateRevision: aggregate.getRevision(streamInfo),
commandRevision: revisionInCommand
});
}
|
[
"function",
"(",
"aggregate",
",",
"cmd",
")",
"{",
"if",
"(",
"!",
"aggregate",
"||",
"!",
"_",
".",
"isObject",
"(",
"aggregate",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid aggregate!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"if",
"(",
"!",
"cmd",
"||",
"!",
"_",
".",
"isObject",
"(",
"cmd",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid command!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"var",
"hasRevision",
"=",
"!",
"!",
"this",
".",
"definitions",
".",
"command",
".",
"revision",
";",
"if",
"(",
"!",
"hasRevision",
")",
"{",
"return",
"null",
";",
"}",
"var",
"revisionInCommand",
"=",
"dotty",
".",
"get",
"(",
"cmd",
",",
"this",
".",
"definitions",
".",
"command",
".",
"revision",
")",
";",
"if",
"(",
"revisionInCommand",
"===",
"null",
"||",
"revisionInCommand",
"===",
"undefined",
")",
"{",
"return",
"null",
";",
"}",
"var",
"contextName",
",",
"aggregateName",
",",
"aggregateId",
";",
"if",
"(",
"!",
"!",
"this",
".",
"definitions",
".",
"command",
".",
"context",
")",
"{",
"contextName",
"=",
"dotty",
".",
"get",
"(",
"cmd",
",",
"this",
".",
"definitions",
".",
"command",
".",
"context",
")",
";",
"}",
"if",
"(",
"!",
"!",
"this",
".",
"definitions",
".",
"command",
".",
"aggregate",
")",
"{",
"aggregateName",
"=",
"dotty",
".",
"get",
"(",
"cmd",
",",
"this",
".",
"definitions",
".",
"command",
".",
"aggregate",
")",
";",
"}",
"if",
"(",
"!",
"!",
"this",
".",
"definitions",
".",
"command",
".",
"aggregateId",
")",
"{",
"aggregateId",
"=",
"dotty",
".",
"get",
"(",
"cmd",
",",
"this",
".",
"definitions",
".",
"command",
".",
"aggregateId",
")",
";",
"}",
"var",
"streamInfo",
"=",
"{",
"context",
":",
"contextName",
",",
"aggregate",
":",
"aggregateName",
",",
"aggregateId",
":",
"aggregateId",
"}",
";",
"if",
"(",
"revisionInCommand",
"===",
"aggregate",
".",
"getRevision",
"(",
"streamInfo",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"new",
"AggregateConcurrencyError",
"(",
"'Actual revision in command is \"'",
"+",
"revisionInCommand",
"+",
"'\", but expected is \"'",
"+",
"aggregate",
".",
"getRevision",
"(",
"streamInfo",
")",
"+",
"'\"!'",
",",
"{",
"aggregateId",
":",
"aggregate",
".",
"id",
",",
"aggregateRevision",
":",
"aggregate",
".",
"getRevision",
"(",
"streamInfo",
")",
",",
"commandRevision",
":",
"revisionInCommand",
"}",
")",
";",
"}"
] |
Returns an error if the revision does not match.
@param {AggregateModel} aggregate The passed aggregate.
@param {Object} cmd The command.
@returns {AggregateConcurrencyError}
|
[
"Returns",
"an",
"error",
"if",
"the",
"revision",
"does",
"not",
"match",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/defaultCommandHandler.js#L612-L664
|
|
14,715
|
adrai/node-cqrs-domain
|
lib/defaultCommandHandler.js
|
function (cmd, callback) {
if (!cmd || !_.isObject(cmd)) {
debug(err);
return callback(new Error('Please pass a valid command!'), null);
}
return this.aggregate.validateCommand(cmd, callback);
}
|
javascript
|
function (cmd, callback) {
if (!cmd || !_.isObject(cmd)) {
debug(err);
return callback(new Error('Please pass a valid command!'), null);
}
return this.aggregate.validateCommand(cmd, callback);
}
|
[
"function",
"(",
"cmd",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"cmd",
"||",
"!",
"_",
".",
"isObject",
"(",
"cmd",
")",
")",
"{",
"debug",
"(",
"err",
")",
";",
"return",
"callback",
"(",
"new",
"Error",
"(",
"'Please pass a valid command!'",
")",
",",
"null",
")",
";",
"}",
"return",
"this",
".",
"aggregate",
".",
"validateCommand",
"(",
"cmd",
",",
"callback",
")",
";",
"}"
] |
Returns an error if the command is not valid.
@param {Object} cmd The command.
@returns {ValidationError}
|
[
"Returns",
"an",
"error",
"if",
"the",
"command",
"is",
"not",
"valid",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/defaultCommandHandler.js#L671-L677
|
|
14,716
|
adrai/node-cqrs-domain
|
lib/defaultCommandHandler.js
|
function (aggregate, cmd) {
if (!aggregate || !_.isObject(aggregate)) {
var err = new Error('Please pass a valid aggregate!');
debug(err);
throw err;
}
if (!cmd || !_.isObject(cmd)) {
var err = new Error('Please pass a valid command!');
debug(err);
throw err;
}
var reason = this.isAggregateDestroyed(aggregate, cmd);
if (reason) {
return reason;
}
if (this.aggregate.disablePersistence) return;
reason = this.isRevisionWrong(aggregate, cmd);
if (reason) {
return reason;
}
}
|
javascript
|
function (aggregate, cmd) {
if (!aggregate || !_.isObject(aggregate)) {
var err = new Error('Please pass a valid aggregate!');
debug(err);
throw err;
}
if (!cmd || !_.isObject(cmd)) {
var err = new Error('Please pass a valid command!');
debug(err);
throw err;
}
var reason = this.isAggregateDestroyed(aggregate, cmd);
if (reason) {
return reason;
}
if (this.aggregate.disablePersistence) return;
reason = this.isRevisionWrong(aggregate, cmd);
if (reason) {
return reason;
}
}
|
[
"function",
"(",
"aggregate",
",",
"cmd",
")",
"{",
"if",
"(",
"!",
"aggregate",
"||",
"!",
"_",
".",
"isObject",
"(",
"aggregate",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid aggregate!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"if",
"(",
"!",
"cmd",
"||",
"!",
"_",
".",
"isObject",
"(",
"cmd",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid command!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"var",
"reason",
"=",
"this",
".",
"isAggregateDestroyed",
"(",
"aggregate",
",",
"cmd",
")",
";",
"if",
"(",
"reason",
")",
"{",
"return",
"reason",
";",
"}",
"if",
"(",
"this",
".",
"aggregate",
".",
"disablePersistence",
")",
"return",
";",
"reason",
"=",
"this",
".",
"isRevisionWrong",
"(",
"aggregate",
",",
"cmd",
")",
";",
"if",
"(",
"reason",
")",
"{",
"return",
"reason",
";",
"}",
"}"
] |
Returns an error if verification fails.
@param {AggregateModel} aggregate The passed aggregate.
@param {Object} cmd The command.
@returns {Error}
|
[
"Returns",
"an",
"error",
"if",
"verification",
"fails",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/defaultCommandHandler.js#L689-L712
|
|
14,717
|
adrai/node-cqrs-domain
|
lib/defaultCommandHandler.js
|
function (aggregate, cmd, callback) {
if (!aggregate || !_.isObject(aggregate)) {
var err = new Error('Please pass a valid aggregate!');
debug(err);
throw err;
}
if (!cmd || !_.isObject(cmd)) {
var err = new Error('Please pass a valid command!');
debug(err);
throw err;
}
if (!callback || !_.isFunction(callback)) {
var err = new Error('Please pass a valid function!');
debug(err);
throw err;
}
this.aggregate.handle(aggregate, cmd, callback);
}
|
javascript
|
function (aggregate, cmd, callback) {
if (!aggregate || !_.isObject(aggregate)) {
var err = new Error('Please pass a valid aggregate!');
debug(err);
throw err;
}
if (!cmd || !_.isObject(cmd)) {
var err = new Error('Please pass a valid command!');
debug(err);
throw err;
}
if (!callback || !_.isFunction(callback)) {
var err = new Error('Please pass a valid function!');
debug(err);
throw err;
}
this.aggregate.handle(aggregate, cmd, callback);
}
|
[
"function",
"(",
"aggregate",
",",
"cmd",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"aggregate",
"||",
"!",
"_",
".",
"isObject",
"(",
"aggregate",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid aggregate!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"if",
"(",
"!",
"cmd",
"||",
"!",
"_",
".",
"isObject",
"(",
"cmd",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid command!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"if",
"(",
"!",
"callback",
"||",
"!",
"_",
".",
"isFunction",
"(",
"callback",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid function!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"this",
".",
"aggregate",
".",
"handle",
"(",
"aggregate",
",",
"cmd",
",",
"callback",
")",
";",
"}"
] |
Handles the command by passing it to the handle function of the aggregate.
@param {AggregateModel} aggregate The passed aggregate.
@param {Object} cmd The command.
@param {Function} callback The function, that will be called when this action is completed.
`function(err){}`
|
[
"Handles",
"the",
"command",
"by",
"passing",
"it",
"to",
"the",
"handle",
"function",
"of",
"the",
"aggregate",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/defaultCommandHandler.js#L721-L739
|
|
14,718
|
adrai/node-cqrs-domain
|
lib/defaultCommandHandler.js
|
function (aggregateId, callback) {
if (!aggregateId || !_.isString(aggregateId)) {
var err = new Error('Please pass a valid aggregateId!');
debug(err);
throw err;
}
if (!callback || !_.isFunction(callback)) {
var err = new Error('Please pass a valid callback!');
debug(err);
throw err;
}
var self = this;
this.aggregateLock.getAll(aggregateId, function (err, workerIds) {
if (err) {
return callback(err);
}
if (workerIds.length === 1 && workerIds[0] === self.id) {
return callback(null);
}
var err = new ConcurrencyError('Aggregate is locked by an other command handler!');
debug(err);
callback(err);
});
}
|
javascript
|
function (aggregateId, callback) {
if (!aggregateId || !_.isString(aggregateId)) {
var err = new Error('Please pass a valid aggregateId!');
debug(err);
throw err;
}
if (!callback || !_.isFunction(callback)) {
var err = new Error('Please pass a valid callback!');
debug(err);
throw err;
}
var self = this;
this.aggregateLock.getAll(aggregateId, function (err, workerIds) {
if (err) {
return callback(err);
}
if (workerIds.length === 1 && workerIds[0] === self.id) {
return callback(null);
}
var err = new ConcurrencyError('Aggregate is locked by an other command handler!');
debug(err);
callback(err);
});
}
|
[
"function",
"(",
"aggregateId",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"aggregateId",
"||",
"!",
"_",
".",
"isString",
"(",
"aggregateId",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid aggregateId!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"if",
"(",
"!",
"callback",
"||",
"!",
"_",
".",
"isFunction",
"(",
"callback",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid callback!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"var",
"self",
"=",
"this",
";",
"this",
".",
"aggregateLock",
".",
"getAll",
"(",
"aggregateId",
",",
"function",
"(",
"err",
",",
"workerIds",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"if",
"(",
"workerIds",
".",
"length",
"===",
"1",
"&&",
"workerIds",
"[",
"0",
"]",
"===",
"self",
".",
"id",
")",
"{",
"return",
"callback",
"(",
"null",
")",
";",
"}",
"var",
"err",
"=",
"new",
"ConcurrencyError",
"(",
"'Aggregate is locked by an other command handler!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"callback",
"(",
"err",
")",
";",
"}",
")",
";",
"}"
] |
Checks if the aggregate lock is ok.
@param {String} aggregateId The passed aggregateId.
@param {Function} callback The function, that will be called when this action is completed.
`function(err){}`
|
[
"Checks",
"if",
"the",
"aggregate",
"lock",
"is",
"ok",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/defaultCommandHandler.js#L747-L774
|
|
14,719
|
adrai/node-cqrs-domain
|
lib/defaultCommandHandler.js
|
function (aggregateId, callback) {
if (!aggregateId || !_.isString(aggregateId)) {
var err = new Error('Please pass a valid aggregateId!');
debug(err);
throw err;
}
if (!callback || !_.isFunction(callback)) {
var err = new Error('Please pass a valid callback!');
debug(err);
throw err;
}
this.aggregateLock.resolve(aggregateId, callback);
}
|
javascript
|
function (aggregateId, callback) {
if (!aggregateId || !_.isString(aggregateId)) {
var err = new Error('Please pass a valid aggregateId!');
debug(err);
throw err;
}
if (!callback || !_.isFunction(callback)) {
var err = new Error('Please pass a valid callback!');
debug(err);
throw err;
}
this.aggregateLock.resolve(aggregateId, callback);
}
|
[
"function",
"(",
"aggregateId",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"aggregateId",
"||",
"!",
"_",
".",
"isString",
"(",
"aggregateId",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid aggregateId!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"if",
"(",
"!",
"callback",
"||",
"!",
"_",
".",
"isFunction",
"(",
"callback",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid callback!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"this",
".",
"aggregateLock",
".",
"resolve",
"(",
"aggregateId",
",",
"callback",
")",
";",
"}"
] |
Resolves if the aggregate lock.
@param {String} aggregateId The passed aggregateId.
@param {Function} callback The function, that will be called when this action is completed.
`function(err){}`
|
[
"Resolves",
"if",
"the",
"aggregate",
"lock",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/defaultCommandHandler.js#L782-L795
|
|
14,720
|
adrai/node-cqrs-domain
|
lib/defaultCommandHandler.js
|
function (aggregate, streams, clb) {
debug('handle command');
self.letHandleCommandByAggregate(aggregate, cmd, function (err) { // err is a business rule error
if (err) {
return clb(err);
}
clb(null, aggregate, streams);
});
}
|
javascript
|
function (aggregate, streams, clb) {
debug('handle command');
self.letHandleCommandByAggregate(aggregate, cmd, function (err) { // err is a business rule error
if (err) {
return clb(err);
}
clb(null, aggregate, streams);
});
}
|
[
"function",
"(",
"aggregate",
",",
"streams",
",",
"clb",
")",
"{",
"debug",
"(",
"'handle command'",
")",
";",
"self",
".",
"letHandleCommandByAggregate",
"(",
"aggregate",
",",
"cmd",
",",
"function",
"(",
"err",
")",
"{",
"// err is a business rule error",
"if",
"(",
"err",
")",
"{",
"return",
"clb",
"(",
"err",
")",
";",
"}",
"clb",
"(",
"null",
",",
"aggregate",
",",
"streams",
")",
";",
"}",
")",
";",
"}"
] |
handle command and check business rules
|
[
"handle",
"command",
"and",
"check",
"business",
"rules"
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/defaultCommandHandler.js#L1015-L1023
|
|
14,721
|
adrai/node-cqrs-domain
|
lib/defaultCommandHandler.js
|
function (aggregate, streams, clb) {
if (hadNoAggregateId) return clb(null, aggregate, streams);
debug('check aggregate lock');
self.checkAggregateLock(concatenatedId, function (err) {
clb(err, aggregate, streams);
});
}
|
javascript
|
function (aggregate, streams, clb) {
if (hadNoAggregateId) return clb(null, aggregate, streams);
debug('check aggregate lock');
self.checkAggregateLock(concatenatedId, function (err) {
clb(err, aggregate, streams);
});
}
|
[
"function",
"(",
"aggregate",
",",
"streams",
",",
"clb",
")",
"{",
"if",
"(",
"hadNoAggregateId",
")",
"return",
"clb",
"(",
"null",
",",
"aggregate",
",",
"streams",
")",
";",
"debug",
"(",
"'check aggregate lock'",
")",
";",
"self",
".",
"checkAggregateLock",
"(",
"concatenatedId",
",",
"function",
"(",
"err",
")",
"{",
"clb",
"(",
"err",
",",
"aggregate",
",",
"streams",
")",
";",
"}",
")",
";",
"}"
] |
check aggregate lock
|
[
"check",
"aggregate",
"lock"
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/defaultCommandHandler.js#L1026-L1032
|
|
14,722
|
adrai/node-cqrs-domain
|
lib/defaultCommandHandler.js
|
function (cmd, callback) {
var getNewIdFn = this.eventStore.getNewId.bind(this.eventStore);
if (this.aggregate && this.aggregate.getNewAggregateId) {
getNewIdFn = this.aggregate.getNewAggregateId.bind(this.aggregate);
} else if (this.getNewAggregateIdFn) {
getNewIdFn = this.getNewAggregateIdFn.bind(this);
}
if (getNewIdFn.length === 2) {
return getNewIdFn(cmd, callback);
}
getNewIdFn(callback);
}
|
javascript
|
function (cmd, callback) {
var getNewIdFn = this.eventStore.getNewId.bind(this.eventStore);
if (this.aggregate && this.aggregate.getNewAggregateId) {
getNewIdFn = this.aggregate.getNewAggregateId.bind(this.aggregate);
} else if (this.getNewAggregateIdFn) {
getNewIdFn = this.getNewAggregateIdFn.bind(this);
}
if (getNewIdFn.length === 2) {
return getNewIdFn(cmd, callback);
}
getNewIdFn(callback);
}
|
[
"function",
"(",
"cmd",
",",
"callback",
")",
"{",
"var",
"getNewIdFn",
"=",
"this",
".",
"eventStore",
".",
"getNewId",
".",
"bind",
"(",
"this",
".",
"eventStore",
")",
";",
"if",
"(",
"this",
".",
"aggregate",
"&&",
"this",
".",
"aggregate",
".",
"getNewAggregateId",
")",
"{",
"getNewIdFn",
"=",
"this",
".",
"aggregate",
".",
"getNewAggregateId",
".",
"bind",
"(",
"this",
".",
"aggregate",
")",
";",
"}",
"else",
"if",
"(",
"this",
".",
"getNewAggregateIdFn",
")",
"{",
"getNewIdFn",
"=",
"this",
".",
"getNewAggregateIdFn",
".",
"bind",
"(",
"this",
")",
";",
"}",
"if",
"(",
"getNewIdFn",
".",
"length",
"===",
"2",
")",
"{",
"return",
"getNewIdFn",
"(",
"cmd",
",",
"callback",
")",
";",
"}",
"getNewIdFn",
"(",
"callback",
")",
";",
"}"
] |
IdGenerator function for aggregate id.
@param {Function} callback The function, that will be called when this action is completed.
`function(err, newId){}`
|
[
"IdGenerator",
"function",
"for",
"aggregate",
"id",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/defaultCommandHandler.js#L1200-L1213
|
|
14,723
|
adrai/node-cqrs-domain
|
lib/domain.js
|
function (fn) {
if (!fn || !_.isFunction(fn)) {
var err = new Error('Please pass a valid function!');
debug(err);
throw err;
}
this.structureLoader = customLoader(fn);
return this;
}
|
javascript
|
function (fn) {
if (!fn || !_.isFunction(fn)) {
var err = new Error('Please pass a valid function!');
debug(err);
throw err;
}
this.structureLoader = customLoader(fn);
return this;
}
|
[
"function",
"(",
"fn",
")",
"{",
"if",
"(",
"!",
"fn",
"||",
"!",
"_",
".",
"isFunction",
"(",
"fn",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid function!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"this",
".",
"structureLoader",
"=",
"customLoader",
"(",
"fn",
")",
";",
"return",
"this",
";",
"}"
] |
Inject custom structure loader function
@param {Function} fn The function to be injected.
@returns {Domain} to be able to chain...
|
[
"Inject",
"custom",
"structure",
"loader",
"function"
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/domain.js#L285-L295
|
|
14,724
|
adrai/node-cqrs-domain
|
lib/domain.js
|
function (cmd, err) {
if (!cmd || !_.isObject(cmd)) {
var err = new Error('Please pass a valid command!');
debug(err);
throw err;
}
if (!err || !_.isObject(err)) {
var err = new Error('Please pass a valid error!');
debug(err);
throw err;
}
var evt = {};
if (!!this.definitions.command.meta && !!this.definitions.event.meta) {
dotty.put(evt, this.definitions.event.meta, dotty.get(cmd, this.definitions.command.meta));
}
dotty.put(evt, this.definitions.event.correlationId, dotty.get(cmd, this.definitions.command.id));
dotty.put(evt, this.definitions.event.name, this.options.commandRejectedEventName);
dotty.put(evt, this.definitions.event.id, dotty.get(cmd, this.definitions.command.id) + '_rejected');
dotty.put(evt, this.definitions.event.aggregateId, dotty.get(cmd, this.definitions.command.aggregateId));
if (!!this.definitions.command.aggregate && !!this.definitions.event.aggregate) {
dotty.put(evt, this.definitions.event.aggregate, dotty.get(cmd, this.definitions.command.aggregate));
}
if (!!this.definitions.command.context && !!this.definitions.event.context) {
dotty.put(evt, this.definitions.event.context, dotty.get(cmd, this.definitions.command.context));
}
if (err instanceof ValidationError || err instanceof BusinessRuleError ||
err instanceof AggregateDestroyedError || err instanceof AggregateConcurrencyError ||
err instanceof DuplicateCommandError) {
dotty.put(evt, this.definitions.event.payload, {
command: cmd,
reason: {
name: err.name,
message: err.message,
more: err.more
}
});
if (!!this.definitions.event.revision && dotty.get(evt, this.definitions.event.revision) === undefined && err.more && err.more.aggregateRevision > -1) {
dotty.put(evt, this.definitions.event.revision, err.more.aggregateRevision);
}
} else {
evt = null;
}
return evt;
}
|
javascript
|
function (cmd, err) {
if (!cmd || !_.isObject(cmd)) {
var err = new Error('Please pass a valid command!');
debug(err);
throw err;
}
if (!err || !_.isObject(err)) {
var err = new Error('Please pass a valid error!');
debug(err);
throw err;
}
var evt = {};
if (!!this.definitions.command.meta && !!this.definitions.event.meta) {
dotty.put(evt, this.definitions.event.meta, dotty.get(cmd, this.definitions.command.meta));
}
dotty.put(evt, this.definitions.event.correlationId, dotty.get(cmd, this.definitions.command.id));
dotty.put(evt, this.definitions.event.name, this.options.commandRejectedEventName);
dotty.put(evt, this.definitions.event.id, dotty.get(cmd, this.definitions.command.id) + '_rejected');
dotty.put(evt, this.definitions.event.aggregateId, dotty.get(cmd, this.definitions.command.aggregateId));
if (!!this.definitions.command.aggregate && !!this.definitions.event.aggregate) {
dotty.put(evt, this.definitions.event.aggregate, dotty.get(cmd, this.definitions.command.aggregate));
}
if (!!this.definitions.command.context && !!this.definitions.event.context) {
dotty.put(evt, this.definitions.event.context, dotty.get(cmd, this.definitions.command.context));
}
if (err instanceof ValidationError || err instanceof BusinessRuleError ||
err instanceof AggregateDestroyedError || err instanceof AggregateConcurrencyError ||
err instanceof DuplicateCommandError) {
dotty.put(evt, this.definitions.event.payload, {
command: cmd,
reason: {
name: err.name,
message: err.message,
more: err.more
}
});
if (!!this.definitions.event.revision && dotty.get(evt, this.definitions.event.revision) === undefined && err.more && err.more.aggregateRevision > -1) {
dotty.put(evt, this.definitions.event.revision, err.more.aggregateRevision);
}
} else {
evt = null;
}
return evt;
}
|
[
"function",
"(",
"cmd",
",",
"err",
")",
"{",
"if",
"(",
"!",
"cmd",
"||",
"!",
"_",
".",
"isObject",
"(",
"cmd",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid command!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"if",
"(",
"!",
"err",
"||",
"!",
"_",
".",
"isObject",
"(",
"err",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid error!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"var",
"evt",
"=",
"{",
"}",
";",
"if",
"(",
"!",
"!",
"this",
".",
"definitions",
".",
"command",
".",
"meta",
"&&",
"!",
"!",
"this",
".",
"definitions",
".",
"event",
".",
"meta",
")",
"{",
"dotty",
".",
"put",
"(",
"evt",
",",
"this",
".",
"definitions",
".",
"event",
".",
"meta",
",",
"dotty",
".",
"get",
"(",
"cmd",
",",
"this",
".",
"definitions",
".",
"command",
".",
"meta",
")",
")",
";",
"}",
"dotty",
".",
"put",
"(",
"evt",
",",
"this",
".",
"definitions",
".",
"event",
".",
"correlationId",
",",
"dotty",
".",
"get",
"(",
"cmd",
",",
"this",
".",
"definitions",
".",
"command",
".",
"id",
")",
")",
";",
"dotty",
".",
"put",
"(",
"evt",
",",
"this",
".",
"definitions",
".",
"event",
".",
"name",
",",
"this",
".",
"options",
".",
"commandRejectedEventName",
")",
";",
"dotty",
".",
"put",
"(",
"evt",
",",
"this",
".",
"definitions",
".",
"event",
".",
"id",
",",
"dotty",
".",
"get",
"(",
"cmd",
",",
"this",
".",
"definitions",
".",
"command",
".",
"id",
")",
"+",
"'_rejected'",
")",
";",
"dotty",
".",
"put",
"(",
"evt",
",",
"this",
".",
"definitions",
".",
"event",
".",
"aggregateId",
",",
"dotty",
".",
"get",
"(",
"cmd",
",",
"this",
".",
"definitions",
".",
"command",
".",
"aggregateId",
")",
")",
";",
"if",
"(",
"!",
"!",
"this",
".",
"definitions",
".",
"command",
".",
"aggregate",
"&&",
"!",
"!",
"this",
".",
"definitions",
".",
"event",
".",
"aggregate",
")",
"{",
"dotty",
".",
"put",
"(",
"evt",
",",
"this",
".",
"definitions",
".",
"event",
".",
"aggregate",
",",
"dotty",
".",
"get",
"(",
"cmd",
",",
"this",
".",
"definitions",
".",
"command",
".",
"aggregate",
")",
")",
";",
"}",
"if",
"(",
"!",
"!",
"this",
".",
"definitions",
".",
"command",
".",
"context",
"&&",
"!",
"!",
"this",
".",
"definitions",
".",
"event",
".",
"context",
")",
"{",
"dotty",
".",
"put",
"(",
"evt",
",",
"this",
".",
"definitions",
".",
"event",
".",
"context",
",",
"dotty",
".",
"get",
"(",
"cmd",
",",
"this",
".",
"definitions",
".",
"command",
".",
"context",
")",
")",
";",
"}",
"if",
"(",
"err",
"instanceof",
"ValidationError",
"||",
"err",
"instanceof",
"BusinessRuleError",
"||",
"err",
"instanceof",
"AggregateDestroyedError",
"||",
"err",
"instanceof",
"AggregateConcurrencyError",
"||",
"err",
"instanceof",
"DuplicateCommandError",
")",
"{",
"dotty",
".",
"put",
"(",
"evt",
",",
"this",
".",
"definitions",
".",
"event",
".",
"payload",
",",
"{",
"command",
":",
"cmd",
",",
"reason",
":",
"{",
"name",
":",
"err",
".",
"name",
",",
"message",
":",
"err",
".",
"message",
",",
"more",
":",
"err",
".",
"more",
"}",
"}",
")",
";",
"if",
"(",
"!",
"!",
"this",
".",
"definitions",
".",
"event",
".",
"revision",
"&&",
"dotty",
".",
"get",
"(",
"evt",
",",
"this",
".",
"definitions",
".",
"event",
".",
"revision",
")",
"===",
"undefined",
"&&",
"err",
".",
"more",
"&&",
"err",
".",
"more",
".",
"aggregateRevision",
">",
"-",
"1",
")",
"{",
"dotty",
".",
"put",
"(",
"evt",
",",
"this",
".",
"definitions",
".",
"event",
".",
"revision",
",",
"err",
".",
"more",
".",
"aggregateRevision",
")",
";",
"}",
"}",
"else",
"{",
"evt",
"=",
"null",
";",
"}",
"return",
"evt",
";",
"}"
] |
Converts an error to the commandRejected event
@param {Object} cmd The command that was handled.
@param {Error} err The error that occurs.
@returns {Object} The resulting event.
|
[
"Converts",
"an",
"error",
"to",
"the",
"commandRejected",
"event"
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/domain.js#L328-L379
|
|
14,725
|
adrai/node-cqrs-domain
|
lib/domain.js
|
function (fn) {
if (!fn || !_.isFunction(fn) || fn.length !== 1) {
var err = new Error('Please pass a valid function!');
debug(err);
throw err;
}
this.validatorExtension = fn;
return this;
}
|
javascript
|
function (fn) {
if (!fn || !_.isFunction(fn) || fn.length !== 1) {
var err = new Error('Please pass a valid function!');
debug(err);
throw err;
}
this.validatorExtension = fn;
return this;
}
|
[
"function",
"(",
"fn",
")",
"{",
"if",
"(",
"!",
"fn",
"||",
"!",
"_",
".",
"isFunction",
"(",
"fn",
")",
"||",
"fn",
".",
"length",
"!==",
"1",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid function!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"this",
".",
"validatorExtension",
"=",
"fn",
";",
"return",
"this",
";",
"}"
] |
Extends the validator instance.
@param {Function} fn the function to be injected
@returns {Domain} to be able to chain...
|
[
"Extends",
"the",
"validator",
"instance",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/domain.js#L400-L410
|
|
14,726
|
adrai/node-cqrs-domain
|
lib/domain.js
|
function (callback) {
debug('prepare eventStore...');
self.eventStore.on('connect', function () {
self.emit('connect');
});
self.eventStore.on('disconnect', function () {
self.emit('disconnect');
});
self.eventStore.init(callback);
}
|
javascript
|
function (callback) {
debug('prepare eventStore...');
self.eventStore.on('connect', function () {
self.emit('connect');
});
self.eventStore.on('disconnect', function () {
self.emit('disconnect');
});
self.eventStore.init(callback);
}
|
[
"function",
"(",
"callback",
")",
"{",
"debug",
"(",
"'prepare eventStore...'",
")",
";",
"self",
".",
"eventStore",
".",
"on",
"(",
"'connect'",
",",
"function",
"(",
")",
"{",
"self",
".",
"emit",
"(",
"'connect'",
")",
";",
"}",
")",
";",
"self",
".",
"eventStore",
".",
"on",
"(",
"'disconnect'",
",",
"function",
"(",
")",
"{",
"self",
".",
"emit",
"(",
"'disconnect'",
")",
";",
"}",
")",
";",
"self",
".",
"eventStore",
".",
"init",
"(",
"callback",
")",
";",
"}"
] |
prepare eventStore...
|
[
"prepare",
"eventStore",
"..."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/domain.js#L447-L459
|
|
14,727
|
adrai/node-cqrs-domain
|
lib/domain.js
|
function (callback) {
debug('prepare aggregateLock...');
self.aggregateLock.on('connect', function () {
self.emit('connect');
});
self.aggregateLock.on('disconnect', function () {
self.emit('disconnect');
});
self.aggregateLock.connect(callback);
}
|
javascript
|
function (callback) {
debug('prepare aggregateLock...');
self.aggregateLock.on('connect', function () {
self.emit('connect');
});
self.aggregateLock.on('disconnect', function () {
self.emit('disconnect');
});
self.aggregateLock.connect(callback);
}
|
[
"function",
"(",
"callback",
")",
"{",
"debug",
"(",
"'prepare aggregateLock...'",
")",
";",
"self",
".",
"aggregateLock",
".",
"on",
"(",
"'connect'",
",",
"function",
"(",
")",
"{",
"self",
".",
"emit",
"(",
"'connect'",
")",
";",
"}",
")",
";",
"self",
".",
"aggregateLock",
".",
"on",
"(",
"'disconnect'",
",",
"function",
"(",
")",
"{",
"self",
".",
"emit",
"(",
"'disconnect'",
")",
";",
"}",
")",
";",
"self",
".",
"aggregateLock",
".",
"connect",
"(",
"callback",
")",
";",
"}"
] |
prepare aggregateLock...
|
[
"prepare",
"aggregateLock",
"..."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/domain.js#L462-L474
|
|
14,728
|
adrai/node-cqrs-domain
|
lib/domain.js
|
function (callback) {
if (!self.commandBumper) {
return callback(null);
}
debug('prepare commandBumper...');
self.commandBumper.on('connect', function () {
self.emit('connect');
});
self.commandBumper.on('disconnect', function () {
self.emit('disconnect');
});
self.commandBumper.connect(callback);
}
|
javascript
|
function (callback) {
if (!self.commandBumper) {
return callback(null);
}
debug('prepare commandBumper...');
self.commandBumper.on('connect', function () {
self.emit('connect');
});
self.commandBumper.on('disconnect', function () {
self.emit('disconnect');
});
self.commandBumper.connect(callback);
}
|
[
"function",
"(",
"callback",
")",
"{",
"if",
"(",
"!",
"self",
".",
"commandBumper",
")",
"{",
"return",
"callback",
"(",
"null",
")",
";",
"}",
"debug",
"(",
"'prepare commandBumper...'",
")",
";",
"self",
".",
"commandBumper",
".",
"on",
"(",
"'connect'",
",",
"function",
"(",
")",
"{",
"self",
".",
"emit",
"(",
"'connect'",
")",
";",
"}",
")",
";",
"self",
".",
"commandBumper",
".",
"on",
"(",
"'disconnect'",
",",
"function",
"(",
")",
"{",
"self",
".",
"emit",
"(",
"'disconnect'",
")",
";",
"}",
")",
";",
"self",
".",
"commandBumper",
".",
"connect",
"(",
"callback",
")",
";",
"}"
] |
prepare commandBumper...
|
[
"prepare",
"commandBumper",
"..."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/domain.js#L477-L492
|
|
14,729
|
adrai/node-cqrs-domain
|
lib/domain.js
|
function (cmd, callback) {
if (!cmd || !_.isObject(cmd) || !dotty.exists(cmd, this.definitions.command.name)) {
var err = new Error('Please pass a valid command!');
debug(err);
if (callback) callback(err);
return;
}
var self = this;
process.nextTick(function () {
if (callback && callback.length > 2) {
self.commandDispatcher.dispatch(cmd, function (err, eventsToDispatch, aggregateData, meta) {
self.onDispatched(cmd, err, eventsToDispatch, aggregateData, meta, callback);
});
return;
}
self.commandDispatcher.dispatch(cmd, function (err, eventsToDispatch) {
self.onDispatched(cmd, err, eventsToDispatch, null, null, callback);
});
});
}
|
javascript
|
function (cmd, callback) {
if (!cmd || !_.isObject(cmd) || !dotty.exists(cmd, this.definitions.command.name)) {
var err = new Error('Please pass a valid command!');
debug(err);
if (callback) callback(err);
return;
}
var self = this;
process.nextTick(function () {
if (callback && callback.length > 2) {
self.commandDispatcher.dispatch(cmd, function (err, eventsToDispatch, aggregateData, meta) {
self.onDispatched(cmd, err, eventsToDispatch, aggregateData, meta, callback);
});
return;
}
self.commandDispatcher.dispatch(cmd, function (err, eventsToDispatch) {
self.onDispatched(cmd, err, eventsToDispatch, null, null, callback);
});
});
}
|
[
"function",
"(",
"cmd",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"cmd",
"||",
"!",
"_",
".",
"isObject",
"(",
"cmd",
")",
"||",
"!",
"dotty",
".",
"exists",
"(",
"cmd",
",",
"this",
".",
"definitions",
".",
"command",
".",
"name",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid command!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"if",
"(",
"callback",
")",
"callback",
"(",
"err",
")",
";",
"return",
";",
"}",
"var",
"self",
"=",
"this",
";",
"process",
".",
"nextTick",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"callback",
"&&",
"callback",
".",
"length",
">",
"2",
")",
"{",
"self",
".",
"commandDispatcher",
".",
"dispatch",
"(",
"cmd",
",",
"function",
"(",
"err",
",",
"eventsToDispatch",
",",
"aggregateData",
",",
"meta",
")",
"{",
"self",
".",
"onDispatched",
"(",
"cmd",
",",
"err",
",",
"eventsToDispatch",
",",
"aggregateData",
",",
"meta",
",",
"callback",
")",
";",
"}",
")",
";",
"return",
";",
"}",
"self",
".",
"commandDispatcher",
".",
"dispatch",
"(",
"cmd",
",",
"function",
"(",
"err",
",",
"eventsToDispatch",
")",
"{",
"self",
".",
"onDispatched",
"(",
"cmd",
",",
"err",
",",
"eventsToDispatch",
",",
"null",
",",
"null",
",",
"callback",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Call this function to let the domain handle it.
@param {Object} cmd the command object
@param {Function} callback the function that will be called when this action has finished [optional]
`function(err, evts, aggregateData, meta){}` evts is of type Array, aggregateData and meta are an object
|
[
"Call",
"this",
"function",
"to",
"let",
"the",
"domain",
"handle",
"it",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/domain.js#L654-L674
|
|
14,730
|
adrai/node-cqrs-domain
|
lib/definitions/event.js
|
function (evt, aggregateModel) {
if (!this.evtFn) {
return;
}
if (!this.payload || this.payload === '') {
this.evtFn(evt, aggregateModel);
return;
}
var payload = dotty.get(evt, this.payload);
this.evtFn(payload, aggregateModel);
}
|
javascript
|
function (evt, aggregateModel) {
if (!this.evtFn) {
return;
}
if (!this.payload || this.payload === '') {
this.evtFn(evt, aggregateModel);
return;
}
var payload = dotty.get(evt, this.payload);
this.evtFn(payload, aggregateModel);
}
|
[
"function",
"(",
"evt",
",",
"aggregateModel",
")",
"{",
"if",
"(",
"!",
"this",
".",
"evtFn",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"this",
".",
"payload",
"||",
"this",
".",
"payload",
"===",
"''",
")",
"{",
"this",
".",
"evtFn",
"(",
"evt",
",",
"aggregateModel",
")",
";",
"return",
";",
"}",
"var",
"payload",
"=",
"dotty",
".",
"get",
"(",
"evt",
",",
"this",
".",
"payload",
")",
";",
"this",
".",
"evtFn",
"(",
"payload",
",",
"aggregateModel",
")",
";",
"}"
] |
Apply an event.
@param {Object} evt The event object.
@param {AggregateModel} aggregateModel The aggregate object.
|
[
"Apply",
"an",
"event",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/event.js#L40-L52
|
|
14,731
|
adrai/node-cqrs-domain
|
lib/validator.js
|
getValidator
|
function getValidator (options, schema) {
options = options || {};
options.schemas = options.schemas || {};
options.formats = options.formats || {};
if (!schema || !_.isObject(schema)) {
var err = new Error('Please pass a valid schema!');
debug(err);
throw err;
}
var tv4 = tv4Module.freshApi();
_.each(options.schemas, function (v, k) {
tv4.addSchema(k, v);
});
tv4.addFormat(options.formats);
return function (data) {
var validation = tv4.validateMultiple(data, schema);
if (validation.missing.length > 0) {
var missingString = validation.missing[0];
for (var m = 1, lenM = validation.missing.length; m < lenM; m++) {
missingString += ', ' + validation.missing[m];
}
var err = new Error('Validation schema(s) "' + missingString + '" missing!');
debug(err);
return err;
}
if (!validation.valid) {
var errors = validation.errors;
var firstError = validation.errors[0];
if (firstError.message.indexOf('not match any schemas') >= 0 && firstError.subErrors && firstError.subErrors.length > 0) {
firstError = firstError.subErrors[0];
errors = firstError.subErrors;
}
return new ValidationError(firstError.dataPath + ' => ' + firstError.message, errors);
}
return null;
};
}
|
javascript
|
function getValidator (options, schema) {
options = options || {};
options.schemas = options.schemas || {};
options.formats = options.formats || {};
if (!schema || !_.isObject(schema)) {
var err = new Error('Please pass a valid schema!');
debug(err);
throw err;
}
var tv4 = tv4Module.freshApi();
_.each(options.schemas, function (v, k) {
tv4.addSchema(k, v);
});
tv4.addFormat(options.formats);
return function (data) {
var validation = tv4.validateMultiple(data, schema);
if (validation.missing.length > 0) {
var missingString = validation.missing[0];
for (var m = 1, lenM = validation.missing.length; m < lenM; m++) {
missingString += ', ' + validation.missing[m];
}
var err = new Error('Validation schema(s) "' + missingString + '" missing!');
debug(err);
return err;
}
if (!validation.valid) {
var errors = validation.errors;
var firstError = validation.errors[0];
if (firstError.message.indexOf('not match any schemas') >= 0 && firstError.subErrors && firstError.subErrors.length > 0) {
firstError = firstError.subErrors[0];
errors = firstError.subErrors;
}
return new ValidationError(firstError.dataPath + ' => ' + firstError.message, errors);
}
return null;
};
}
|
[
"function",
"getValidator",
"(",
"options",
",",
"schema",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"options",
".",
"schemas",
"=",
"options",
".",
"schemas",
"||",
"{",
"}",
";",
"options",
".",
"formats",
"=",
"options",
".",
"formats",
"||",
"{",
"}",
";",
"if",
"(",
"!",
"schema",
"||",
"!",
"_",
".",
"isObject",
"(",
"schema",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid schema!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"var",
"tv4",
"=",
"tv4Module",
".",
"freshApi",
"(",
")",
";",
"_",
".",
"each",
"(",
"options",
".",
"schemas",
",",
"function",
"(",
"v",
",",
"k",
")",
"{",
"tv4",
".",
"addSchema",
"(",
"k",
",",
"v",
")",
";",
"}",
")",
";",
"tv4",
".",
"addFormat",
"(",
"options",
".",
"formats",
")",
";",
"return",
"function",
"(",
"data",
")",
"{",
"var",
"validation",
"=",
"tv4",
".",
"validateMultiple",
"(",
"data",
",",
"schema",
")",
";",
"if",
"(",
"validation",
".",
"missing",
".",
"length",
">",
"0",
")",
"{",
"var",
"missingString",
"=",
"validation",
".",
"missing",
"[",
"0",
"]",
";",
"for",
"(",
"var",
"m",
"=",
"1",
",",
"lenM",
"=",
"validation",
".",
"missing",
".",
"length",
";",
"m",
"<",
"lenM",
";",
"m",
"++",
")",
"{",
"missingString",
"+=",
"', '",
"+",
"validation",
".",
"missing",
"[",
"m",
"]",
";",
"}",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Validation schema(s) \"'",
"+",
"missingString",
"+",
"'\" missing!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"return",
"err",
";",
"}",
"if",
"(",
"!",
"validation",
".",
"valid",
")",
"{",
"var",
"errors",
"=",
"validation",
".",
"errors",
";",
"var",
"firstError",
"=",
"validation",
".",
"errors",
"[",
"0",
"]",
";",
"if",
"(",
"firstError",
".",
"message",
".",
"indexOf",
"(",
"'not match any schemas'",
")",
">=",
"0",
"&&",
"firstError",
".",
"subErrors",
"&&",
"firstError",
".",
"subErrors",
".",
"length",
">",
"0",
")",
"{",
"firstError",
"=",
"firstError",
".",
"subErrors",
"[",
"0",
"]",
";",
"errors",
"=",
"firstError",
".",
"subErrors",
";",
"}",
"return",
"new",
"ValidationError",
"(",
"firstError",
".",
"dataPath",
"+",
"' => '",
"+",
"firstError",
".",
"message",
",",
"errors",
")",
";",
"}",
"return",
"null",
";",
"}",
";",
"}"
] |
Returns a validator function.
@param {Object} options The options object.
@param {Object} schema The schema object.
@returns {Function}
|
[
"Returns",
"a",
"validator",
"function",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/validator.js#L12-L58
|
14,732
|
adrai/node-cqrs-domain
|
lib/commandDispatcher.js
|
function (cmd) {
if (!cmd || !_.isObject(cmd)) {
var err = new Error('Please pass a valid command!');
debug(err);
throw err;
}
var aggregateId = null;
if (dotty.exists(cmd, this.definition.aggregateId)) {
aggregateId = dotty.get(cmd, this.definition.aggregateId);
} else {
debug('no aggregateId found, seems to be for a new aggregate');
}
var name = dotty.get(cmd, this.definition.name);
var version = 0;
if (dotty.exists(cmd, this.definition.version)) {
version = dotty.get(cmd, this.definition.version);
} else {
debug('no version found, handling as version: 0');
}
var aggregate = null;
if (dotty.exists(cmd, this.definition.aggregate)) {
aggregate = dotty.get(cmd, this.definition.aggregate);
} else {
debug('no aggregate found, will lookup in all aggregates');
}
var context = null;
if (dotty.exists(cmd, this.definition.context)) {
context = dotty.get(cmd, this.definition.context);
} else {
debug('no aggregateName found, will lookup in all contexts');
}
return {
name: name,
aggregateId: aggregateId,
version: version,
aggregate: aggregate,
context: context
};
}
|
javascript
|
function (cmd) {
if (!cmd || !_.isObject(cmd)) {
var err = new Error('Please pass a valid command!');
debug(err);
throw err;
}
var aggregateId = null;
if (dotty.exists(cmd, this.definition.aggregateId)) {
aggregateId = dotty.get(cmd, this.definition.aggregateId);
} else {
debug('no aggregateId found, seems to be for a new aggregate');
}
var name = dotty.get(cmd, this.definition.name);
var version = 0;
if (dotty.exists(cmd, this.definition.version)) {
version = dotty.get(cmd, this.definition.version);
} else {
debug('no version found, handling as version: 0');
}
var aggregate = null;
if (dotty.exists(cmd, this.definition.aggregate)) {
aggregate = dotty.get(cmd, this.definition.aggregate);
} else {
debug('no aggregate found, will lookup in all aggregates');
}
var context = null;
if (dotty.exists(cmd, this.definition.context)) {
context = dotty.get(cmd, this.definition.context);
} else {
debug('no aggregateName found, will lookup in all contexts');
}
return {
name: name,
aggregateId: aggregateId,
version: version,
aggregate: aggregate,
context: context
};
}
|
[
"function",
"(",
"cmd",
")",
"{",
"if",
"(",
"!",
"cmd",
"||",
"!",
"_",
".",
"isObject",
"(",
"cmd",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid command!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"var",
"aggregateId",
"=",
"null",
";",
"if",
"(",
"dotty",
".",
"exists",
"(",
"cmd",
",",
"this",
".",
"definition",
".",
"aggregateId",
")",
")",
"{",
"aggregateId",
"=",
"dotty",
".",
"get",
"(",
"cmd",
",",
"this",
".",
"definition",
".",
"aggregateId",
")",
";",
"}",
"else",
"{",
"debug",
"(",
"'no aggregateId found, seems to be for a new aggregate'",
")",
";",
"}",
"var",
"name",
"=",
"dotty",
".",
"get",
"(",
"cmd",
",",
"this",
".",
"definition",
".",
"name",
")",
";",
"var",
"version",
"=",
"0",
";",
"if",
"(",
"dotty",
".",
"exists",
"(",
"cmd",
",",
"this",
".",
"definition",
".",
"version",
")",
")",
"{",
"version",
"=",
"dotty",
".",
"get",
"(",
"cmd",
",",
"this",
".",
"definition",
".",
"version",
")",
";",
"}",
"else",
"{",
"debug",
"(",
"'no version found, handling as version: 0'",
")",
";",
"}",
"var",
"aggregate",
"=",
"null",
";",
"if",
"(",
"dotty",
".",
"exists",
"(",
"cmd",
",",
"this",
".",
"definition",
".",
"aggregate",
")",
")",
"{",
"aggregate",
"=",
"dotty",
".",
"get",
"(",
"cmd",
",",
"this",
".",
"definition",
".",
"aggregate",
")",
";",
"}",
"else",
"{",
"debug",
"(",
"'no aggregate found, will lookup in all aggregates'",
")",
";",
"}",
"var",
"context",
"=",
"null",
";",
"if",
"(",
"dotty",
".",
"exists",
"(",
"cmd",
",",
"this",
".",
"definition",
".",
"context",
")",
")",
"{",
"context",
"=",
"dotty",
".",
"get",
"(",
"cmd",
",",
"this",
".",
"definition",
".",
"context",
")",
";",
"}",
"else",
"{",
"debug",
"(",
"'no aggregateName found, will lookup in all contexts'",
")",
";",
"}",
"return",
"{",
"name",
":",
"name",
",",
"aggregateId",
":",
"aggregateId",
",",
"version",
":",
"version",
",",
"aggregate",
":",
"aggregate",
",",
"context",
":",
"context",
"}",
";",
"}"
] |
Returns the target information of this command.
@param {Object} cmd The passed command.
@returns {{name: 'commandName', aggregateId: 'aggregateId', version: 0, aggregate: 'aggregateName', context: 'contextName'}}
|
[
"Returns",
"the",
"target",
"information",
"of",
"this",
"command",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/commandDispatcher.js#L39-L83
|
|
14,733
|
adrai/node-cqrs-domain
|
lib/commandDispatcher.js
|
function (cmd, callback) {
if (!cmd || !_.isObject(cmd)) {
var err = new Error('Please pass a valid command!');
debug(err);
throw err;
}
if (!callback || !_.isFunction(callback)) {
var err = new Error('Please pass a valid callback!');
debug(err);
throw err;
}
var target = this.getTargetInformation(cmd);
var commandHandler = this.tree.getCommandHandler(target);
// if (!commandHandler) {
// commandHandler = this.tree.getCommandHandlerByOldTarget(target);
// }
if (!commandHandler) {
var err = new Error('No command handler found for ' + target.name);
debug(err);
return callback(err);
}
if (!this.commandBumper) {
return commandHandler.handle(cmd, callback);
}
var key = target.context + target.aggregate + target.aggregateId + dotty.get(cmd, this.definition.id);
this.commandBumper.add(key, function (err, added) {
if (err) {
return callback(err);
}
if (!added) {
return callback(new DuplicateCommandError('Command already seen!'));
}
commandHandler.handle(cmd, callback);
});
}
|
javascript
|
function (cmd, callback) {
if (!cmd || !_.isObject(cmd)) {
var err = new Error('Please pass a valid command!');
debug(err);
throw err;
}
if (!callback || !_.isFunction(callback)) {
var err = new Error('Please pass a valid callback!');
debug(err);
throw err;
}
var target = this.getTargetInformation(cmd);
var commandHandler = this.tree.getCommandHandler(target);
// if (!commandHandler) {
// commandHandler = this.tree.getCommandHandlerByOldTarget(target);
// }
if (!commandHandler) {
var err = new Error('No command handler found for ' + target.name);
debug(err);
return callback(err);
}
if (!this.commandBumper) {
return commandHandler.handle(cmd, callback);
}
var key = target.context + target.aggregate + target.aggregateId + dotty.get(cmd, this.definition.id);
this.commandBumper.add(key, function (err, added) {
if (err) {
return callback(err);
}
if (!added) {
return callback(new DuplicateCommandError('Command already seen!'));
}
commandHandler.handle(cmd, callback);
});
}
|
[
"function",
"(",
"cmd",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"cmd",
"||",
"!",
"_",
".",
"isObject",
"(",
"cmd",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid command!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"if",
"(",
"!",
"callback",
"||",
"!",
"_",
".",
"isFunction",
"(",
"callback",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid callback!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"var",
"target",
"=",
"this",
".",
"getTargetInformation",
"(",
"cmd",
")",
";",
"var",
"commandHandler",
"=",
"this",
".",
"tree",
".",
"getCommandHandler",
"(",
"target",
")",
";",
"// if (!commandHandler) {",
"// commandHandler = this.tree.getCommandHandlerByOldTarget(target);",
"// }",
"if",
"(",
"!",
"commandHandler",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'No command handler found for '",
"+",
"target",
".",
"name",
")",
";",
"debug",
"(",
"err",
")",
";",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"if",
"(",
"!",
"this",
".",
"commandBumper",
")",
"{",
"return",
"commandHandler",
".",
"handle",
"(",
"cmd",
",",
"callback",
")",
";",
"}",
"var",
"key",
"=",
"target",
".",
"context",
"+",
"target",
".",
"aggregate",
"+",
"target",
".",
"aggregateId",
"+",
"dotty",
".",
"get",
"(",
"cmd",
",",
"this",
".",
"definition",
".",
"id",
")",
";",
"this",
".",
"commandBumper",
".",
"add",
"(",
"key",
",",
"function",
"(",
"err",
",",
"added",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"if",
"(",
"!",
"added",
")",
"{",
"return",
"callback",
"(",
"new",
"DuplicateCommandError",
"(",
"'Command already seen!'",
")",
")",
";",
"}",
"commandHandler",
".",
"handle",
"(",
"cmd",
",",
"callback",
")",
";",
"}",
")",
";",
"}"
] |
Dispatches a command.
@param {Object} cmd The passed command.
@param {Function} callback The function, that will be called when this action is completed.
`function(err, evts){}`
|
[
"Dispatches",
"a",
"command",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/commandDispatcher.js#L91-L135
|
|
14,734
|
adrai/node-cqrs-domain
|
lib/definitions/committingEventTransformer.js
|
function (evt, callback) {
var self = this;
var callbacked = false;
function handleError (err) {
debug(err);
callbacked = true;
callback(err);
}
try {
if (this.transformFn.length === 2) {
this.transformFn(_.cloneDeep(evt), function (err, newEvt) {
if (err) return handleError(err);
callbacked = true;
callback(null, newEvt);
});
} else {
var newEvt = this.transformFn(_.cloneDeep(evt));
callback(null, newEvt);
}
} catch (err) {
if (!callbacked) {
return handleError(err);
}
throw err;
}
}
|
javascript
|
function (evt, callback) {
var self = this;
var callbacked = false;
function handleError (err) {
debug(err);
callbacked = true;
callback(err);
}
try {
if (this.transformFn.length === 2) {
this.transformFn(_.cloneDeep(evt), function (err, newEvt) {
if (err) return handleError(err);
callbacked = true;
callback(null, newEvt);
});
} else {
var newEvt = this.transformFn(_.cloneDeep(evt));
callback(null, newEvt);
}
} catch (err) {
if (!callbacked) {
return handleError(err);
}
throw err;
}
}
|
[
"function",
"(",
"evt",
",",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"callbacked",
"=",
"false",
";",
"function",
"handleError",
"(",
"err",
")",
"{",
"debug",
"(",
"err",
")",
";",
"callbacked",
"=",
"true",
";",
"callback",
"(",
"err",
")",
";",
"}",
"try",
"{",
"if",
"(",
"this",
".",
"transformFn",
".",
"length",
"===",
"2",
")",
"{",
"this",
".",
"transformFn",
"(",
"_",
".",
"cloneDeep",
"(",
"evt",
")",
",",
"function",
"(",
"err",
",",
"newEvt",
")",
"{",
"if",
"(",
"err",
")",
"return",
"handleError",
"(",
"err",
")",
";",
"callbacked",
"=",
"true",
";",
"callback",
"(",
"null",
",",
"newEvt",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"var",
"newEvt",
"=",
"this",
".",
"transformFn",
"(",
"_",
".",
"cloneDeep",
"(",
"evt",
")",
")",
";",
"callback",
"(",
"null",
",",
"newEvt",
")",
";",
"}",
"}",
"catch",
"(",
"err",
")",
"{",
"if",
"(",
"!",
"callbacked",
")",
"{",
"return",
"handleError",
"(",
"err",
")",
";",
"}",
"throw",
"err",
";",
"}",
"}"
] |
transform an CommittingEventTransformer.
@param {Object} evt The CommittingEventTransformer object.
@param {Function} callback The function, that will be called when this action is completed.
`function(err, evt){}`
|
[
"transform",
"an",
"CommittingEventTransformer",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/committingEventTransformer.js#L39-L66
|
|
14,735
|
adrai/node-cqrs-domain
|
lib/definitions/aggregate.js
|
function (context) {
if (!context || !_.isObject(context)) {
var err = new Error('Please inject a valid context object!');
debug(err);
throw err;
}
this.context = context;
for (var r in this.snapshotConversionRegistrations) {
var reg = this.snapshotConversionRegistrations[r];
var meta = reg.meta;
var fn = reg.fn;
meta.context = meta.context || this.context.name;
meta.aggregate = meta.aggregate || this.name;
this.snapshotConversions[meta.context + '.' + meta.aggregate + '.' + meta.version] = fn;
}
for (var r in this.loadingSnapshotTransformerRegistrations) {
var reg = this.loadingSnapshotTransformerRegistrations[r];
var meta = reg.meta;
var fn = reg.fn;
meta.context = meta.context || this.context.name;
meta.aggregate = meta.aggregate || this.name;
this.loadingSnapshotTransformers[meta.context + '.' + meta.aggregate + '.' + meta.version] = fn;
}
for (var r in this.committingSnapshotTransformerRegistrations) {
var reg = this.committingSnapshotTransformerRegistrations[r];
var meta = reg.meta;
var fn = reg.fn;
meta.context = meta.context || this.context.name;
meta.aggregate = meta.aggregate || this.name;
this.committingSnapshotTransformers[meta.context + '.' + meta.aggregate + '.' + meta.version] = fn;
}
}
|
javascript
|
function (context) {
if (!context || !_.isObject(context)) {
var err = new Error('Please inject a valid context object!');
debug(err);
throw err;
}
this.context = context;
for (var r in this.snapshotConversionRegistrations) {
var reg = this.snapshotConversionRegistrations[r];
var meta = reg.meta;
var fn = reg.fn;
meta.context = meta.context || this.context.name;
meta.aggregate = meta.aggregate || this.name;
this.snapshotConversions[meta.context + '.' + meta.aggregate + '.' + meta.version] = fn;
}
for (var r in this.loadingSnapshotTransformerRegistrations) {
var reg = this.loadingSnapshotTransformerRegistrations[r];
var meta = reg.meta;
var fn = reg.fn;
meta.context = meta.context || this.context.name;
meta.aggregate = meta.aggregate || this.name;
this.loadingSnapshotTransformers[meta.context + '.' + meta.aggregate + '.' + meta.version] = fn;
}
for (var r in this.committingSnapshotTransformerRegistrations) {
var reg = this.committingSnapshotTransformerRegistrations[r];
var meta = reg.meta;
var fn = reg.fn;
meta.context = meta.context || this.context.name;
meta.aggregate = meta.aggregate || this.name;
this.committingSnapshotTransformers[meta.context + '.' + meta.aggregate + '.' + meta.version] = fn;
}
}
|
[
"function",
"(",
"context",
")",
"{",
"if",
"(",
"!",
"context",
"||",
"!",
"_",
".",
"isObject",
"(",
"context",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please inject a valid context object!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"this",
".",
"context",
"=",
"context",
";",
"for",
"(",
"var",
"r",
"in",
"this",
".",
"snapshotConversionRegistrations",
")",
"{",
"var",
"reg",
"=",
"this",
".",
"snapshotConversionRegistrations",
"[",
"r",
"]",
";",
"var",
"meta",
"=",
"reg",
".",
"meta",
";",
"var",
"fn",
"=",
"reg",
".",
"fn",
";",
"meta",
".",
"context",
"=",
"meta",
".",
"context",
"||",
"this",
".",
"context",
".",
"name",
";",
"meta",
".",
"aggregate",
"=",
"meta",
".",
"aggregate",
"||",
"this",
".",
"name",
";",
"this",
".",
"snapshotConversions",
"[",
"meta",
".",
"context",
"+",
"'.'",
"+",
"meta",
".",
"aggregate",
"+",
"'.'",
"+",
"meta",
".",
"version",
"]",
"=",
"fn",
";",
"}",
"for",
"(",
"var",
"r",
"in",
"this",
".",
"loadingSnapshotTransformerRegistrations",
")",
"{",
"var",
"reg",
"=",
"this",
".",
"loadingSnapshotTransformerRegistrations",
"[",
"r",
"]",
";",
"var",
"meta",
"=",
"reg",
".",
"meta",
";",
"var",
"fn",
"=",
"reg",
".",
"fn",
";",
"meta",
".",
"context",
"=",
"meta",
".",
"context",
"||",
"this",
".",
"context",
".",
"name",
";",
"meta",
".",
"aggregate",
"=",
"meta",
".",
"aggregate",
"||",
"this",
".",
"name",
";",
"this",
".",
"loadingSnapshotTransformers",
"[",
"meta",
".",
"context",
"+",
"'.'",
"+",
"meta",
".",
"aggregate",
"+",
"'.'",
"+",
"meta",
".",
"version",
"]",
"=",
"fn",
";",
"}",
"for",
"(",
"var",
"r",
"in",
"this",
".",
"committingSnapshotTransformerRegistrations",
")",
"{",
"var",
"reg",
"=",
"this",
".",
"committingSnapshotTransformerRegistrations",
"[",
"r",
"]",
";",
"var",
"meta",
"=",
"reg",
".",
"meta",
";",
"var",
"fn",
"=",
"reg",
".",
"fn",
";",
"meta",
".",
"context",
"=",
"meta",
".",
"context",
"||",
"this",
".",
"context",
".",
"name",
";",
"meta",
".",
"aggregate",
"=",
"meta",
".",
"aggregate",
"||",
"this",
".",
"name",
";",
"this",
".",
"committingSnapshotTransformers",
"[",
"meta",
".",
"context",
"+",
"'.'",
"+",
"meta",
".",
"aggregate",
"+",
"'.'",
"+",
"meta",
".",
"version",
"]",
"=",
"fn",
";",
"}",
"}"
] |
Inject the context module.
@param {Context} context The context module to be injected.
|
[
"Inject",
"the",
"context",
"module",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/aggregate.js#L189-L230
|
|
14,736
|
adrai/node-cqrs-domain
|
lib/definitions/aggregate.js
|
function (command) {
if (!command || !_.isObject(command)) {
var err = new Error('Please inject a valid command object!');
debug(err);
throw err;
}
if (!command.payload && command.payload !== '') {
command.payload = this.defaultCommandPayload;
}
command.defineAggregate(this);
if (this.commands.indexOf(command) < 0) {
this.commands.push(command);
}
}
|
javascript
|
function (command) {
if (!command || !_.isObject(command)) {
var err = new Error('Please inject a valid command object!');
debug(err);
throw err;
}
if (!command.payload && command.payload !== '') {
command.payload = this.defaultCommandPayload;
}
command.defineAggregate(this);
if (this.commands.indexOf(command) < 0) {
this.commands.push(command);
}
}
|
[
"function",
"(",
"command",
")",
"{",
"if",
"(",
"!",
"command",
"||",
"!",
"_",
".",
"isObject",
"(",
"command",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please inject a valid command object!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"if",
"(",
"!",
"command",
".",
"payload",
"&&",
"command",
".",
"payload",
"!==",
"''",
")",
"{",
"command",
".",
"payload",
"=",
"this",
".",
"defaultCommandPayload",
";",
"}",
"command",
".",
"defineAggregate",
"(",
"this",
")",
";",
"if",
"(",
"this",
".",
"commands",
".",
"indexOf",
"(",
"command",
")",
"<",
"0",
")",
"{",
"this",
".",
"commands",
".",
"push",
"(",
"command",
")",
";",
"}",
"}"
] |
Add command module.
@param {Command} command The command module to be injected.
|
[
"Add",
"command",
"module",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/aggregate.js#L236-L252
|
|
14,737
|
adrai/node-cqrs-domain
|
lib/definitions/aggregate.js
|
function (event) {
if (!event || !_.isObject(event)) {
var err = new Error('Please inject a valid event object!');
debug(err);
throw err;
}
if (!event.payload && event.payload !== '') {
event.payload = this.defaultEventPayload;
}
if (this.events.indexOf(event) < 0) {
this.events.push(event);
}
}
|
javascript
|
function (event) {
if (!event || !_.isObject(event)) {
var err = new Error('Please inject a valid event object!');
debug(err);
throw err;
}
if (!event.payload && event.payload !== '') {
event.payload = this.defaultEventPayload;
}
if (this.events.indexOf(event) < 0) {
this.events.push(event);
}
}
|
[
"function",
"(",
"event",
")",
"{",
"if",
"(",
"!",
"event",
"||",
"!",
"_",
".",
"isObject",
"(",
"event",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please inject a valid event object!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"if",
"(",
"!",
"event",
".",
"payload",
"&&",
"event",
".",
"payload",
"!==",
"''",
")",
"{",
"event",
".",
"payload",
"=",
"this",
".",
"defaultEventPayload",
";",
"}",
"if",
"(",
"this",
".",
"events",
".",
"indexOf",
"(",
"event",
")",
"<",
"0",
")",
"{",
"this",
".",
"events",
".",
"push",
"(",
"event",
")",
";",
"}",
"}"
] |
Add event module.
@param {Event} event The event module to be injected.
|
[
"Add",
"event",
"module",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/aggregate.js#L258-L272
|
|
14,738
|
adrai/node-cqrs-domain
|
lib/definitions/aggregate.js
|
function (businessRule) {
if (!businessRule || !_.isObject(businessRule)) {
var err = new Error('Please inject a valid businessRule object!');
debug(err);
throw err;
}
if (this.businessRules.indexOf(businessRule) < 0) {
businessRule.defineAggregate(this);
this.businessRules.push(businessRule);
this.businessRules = _.sortBy(this.businessRules, function(br) {
return br.priority;
});
}
}
|
javascript
|
function (businessRule) {
if (!businessRule || !_.isObject(businessRule)) {
var err = new Error('Please inject a valid businessRule object!');
debug(err);
throw err;
}
if (this.businessRules.indexOf(businessRule) < 0) {
businessRule.defineAggregate(this);
this.businessRules.push(businessRule);
this.businessRules = _.sortBy(this.businessRules, function(br) {
return br.priority;
});
}
}
|
[
"function",
"(",
"businessRule",
")",
"{",
"if",
"(",
"!",
"businessRule",
"||",
"!",
"_",
".",
"isObject",
"(",
"businessRule",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please inject a valid businessRule object!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"if",
"(",
"this",
".",
"businessRules",
".",
"indexOf",
"(",
"businessRule",
")",
"<",
"0",
")",
"{",
"businessRule",
".",
"defineAggregate",
"(",
"this",
")",
";",
"this",
".",
"businessRules",
".",
"push",
"(",
"businessRule",
")",
";",
"this",
".",
"businessRules",
"=",
"_",
".",
"sortBy",
"(",
"this",
".",
"businessRules",
",",
"function",
"(",
"br",
")",
"{",
"return",
"br",
".",
"priority",
";",
"}",
")",
";",
"}",
"}"
] |
Add businessRule module.
@param {BusinessRule} businessRule The businessRule module to be injected.
|
[
"Add",
"businessRule",
"module",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/aggregate.js#L278-L292
|
|
14,739
|
adrai/node-cqrs-domain
|
lib/definitions/aggregate.js
|
function (loadingEventTransformer) {
if (!loadingEventTransformer || !_.isObject(loadingEventTransformer)) {
var err = new Error('Please inject a valid loadingEventTransformer object!');
debug(err);
throw err;
}
if (this.loadingEventTransformers.indexOf(loadingEventTransformer) < 0) {
this.loadingEventTransformers.push(loadingEventTransformer);
}
}
|
javascript
|
function (loadingEventTransformer) {
if (!loadingEventTransformer || !_.isObject(loadingEventTransformer)) {
var err = new Error('Please inject a valid loadingEventTransformer object!');
debug(err);
throw err;
}
if (this.loadingEventTransformers.indexOf(loadingEventTransformer) < 0) {
this.loadingEventTransformers.push(loadingEventTransformer);
}
}
|
[
"function",
"(",
"loadingEventTransformer",
")",
"{",
"if",
"(",
"!",
"loadingEventTransformer",
"||",
"!",
"_",
".",
"isObject",
"(",
"loadingEventTransformer",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please inject a valid loadingEventTransformer object!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"if",
"(",
"this",
".",
"loadingEventTransformers",
".",
"indexOf",
"(",
"loadingEventTransformer",
")",
"<",
"0",
")",
"{",
"this",
".",
"loadingEventTransformers",
".",
"push",
"(",
"loadingEventTransformer",
")",
";",
"}",
"}"
] |
Add loadingEventTransformer module.
@param {LoadingEventTransformer} loadingEventTransformer The loadingEventTransformer module to be injected.
|
[
"Add",
"loadingEventTransformer",
"module",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/aggregate.js#L298-L308
|
|
14,740
|
adrai/node-cqrs-domain
|
lib/definitions/aggregate.js
|
function (committingEventTransformer) {
if (!committingEventTransformer || !_.isObject(committingEventTransformer)) {
var err = new Error('Please inject a valid committingEventTransformer object!');
debug(err);
throw err;
}
if (this.committingEventTransformers.indexOf(committingEventTransformer) < 0) {
this.committingEventTransformers.push(committingEventTransformer);
}
}
|
javascript
|
function (committingEventTransformer) {
if (!committingEventTransformer || !_.isObject(committingEventTransformer)) {
var err = new Error('Please inject a valid committingEventTransformer object!');
debug(err);
throw err;
}
if (this.committingEventTransformers.indexOf(committingEventTransformer) < 0) {
this.committingEventTransformers.push(committingEventTransformer);
}
}
|
[
"function",
"(",
"committingEventTransformer",
")",
"{",
"if",
"(",
"!",
"committingEventTransformer",
"||",
"!",
"_",
".",
"isObject",
"(",
"committingEventTransformer",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please inject a valid committingEventTransformer object!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"if",
"(",
"this",
".",
"committingEventTransformers",
".",
"indexOf",
"(",
"committingEventTransformer",
")",
"<",
"0",
")",
"{",
"this",
".",
"committingEventTransformers",
".",
"push",
"(",
"committingEventTransformer",
")",
";",
"}",
"}"
] |
Add committingEventTransformer module.
@param {CommittingEventTransformer} committingEventTransformer The committingEventTransformer module to be injected.
|
[
"Add",
"committingEventTransformer",
"module",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/aggregate.js#L314-L324
|
|
14,741
|
adrai/node-cqrs-domain
|
lib/definitions/aggregate.js
|
function (commandHandler) {
if (!commandHandler || !_.isObject(commandHandler) || !_.isFunction(commandHandler.useAggregate)) {
var err = new Error('Please inject a valid commandHandler object!');
debug(err);
throw err;
}
commandHandler.useAggregate(this);
if (this.commandHandlers.indexOf(commandHandler) < 0) {
this.commandHandlers.push(commandHandler);
}
}
|
javascript
|
function (commandHandler) {
if (!commandHandler || !_.isObject(commandHandler) || !_.isFunction(commandHandler.useAggregate)) {
var err = new Error('Please inject a valid commandHandler object!');
debug(err);
throw err;
}
commandHandler.useAggregate(this);
if (this.commandHandlers.indexOf(commandHandler) < 0) {
this.commandHandlers.push(commandHandler);
}
}
|
[
"function",
"(",
"commandHandler",
")",
"{",
"if",
"(",
"!",
"commandHandler",
"||",
"!",
"_",
".",
"isObject",
"(",
"commandHandler",
")",
"||",
"!",
"_",
".",
"isFunction",
"(",
"commandHandler",
".",
"useAggregate",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please inject a valid commandHandler object!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"commandHandler",
".",
"useAggregate",
"(",
"this",
")",
";",
"if",
"(",
"this",
".",
"commandHandlers",
".",
"indexOf",
"(",
"commandHandler",
")",
"<",
"0",
")",
"{",
"this",
".",
"commandHandlers",
".",
"push",
"(",
"commandHandler",
")",
";",
"}",
"}"
] |
Add commandHandler module.
@param {CommandHandler} commandHandler The commandHandler module to be injected.
|
[
"Add",
"commandHandler",
"module",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/aggregate.js#L330-L342
|
|
14,742
|
adrai/node-cqrs-domain
|
lib/definitions/aggregate.js
|
function (name) {
if (!name || !_.isString(name)) {
var err = new Error('Please pass a valid string as name!');
debug(err);
throw err;
}
return _.filter(this.commands, function (cmd) {
return cmd.name === name;
});
}
|
javascript
|
function (name) {
if (!name || !_.isString(name)) {
var err = new Error('Please pass a valid string as name!');
debug(err);
throw err;
}
return _.filter(this.commands, function (cmd) {
return cmd.name === name;
});
}
|
[
"function",
"(",
"name",
")",
"{",
"if",
"(",
"!",
"name",
"||",
"!",
"_",
".",
"isString",
"(",
"name",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid string as name!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"return",
"_",
".",
"filter",
"(",
"this",
".",
"commands",
",",
"function",
"(",
"cmd",
")",
"{",
"return",
"cmd",
".",
"name",
"===",
"name",
";",
"}",
")",
";",
"}"
] |
Returns the command modules by command name.
@param {String} name The command name.
@returns {Array}
|
[
"Returns",
"the",
"command",
"modules",
"by",
"command",
"name",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/aggregate.js#L349-L359
|
|
14,743
|
adrai/node-cqrs-domain
|
lib/definitions/aggregate.js
|
function (name, version) {
if (!name || !_.isString(name)) {
var err = new Error('Please pass a valid string as name!');
debug(err);
throw err;
}
version = version || 0;
if (!_.isNumber(version)) {
var err = new Error('Please pass a valid number as version!');
debug(err);
throw err;
}
return _.find(this.commands, function (cmd) {
return cmd.name === name && cmd.version === version;
});
}
|
javascript
|
function (name, version) {
if (!name || !_.isString(name)) {
var err = new Error('Please pass a valid string as name!');
debug(err);
throw err;
}
version = version || 0;
if (!_.isNumber(version)) {
var err = new Error('Please pass a valid number as version!');
debug(err);
throw err;
}
return _.find(this.commands, function (cmd) {
return cmd.name === name && cmd.version === version;
});
}
|
[
"function",
"(",
"name",
",",
"version",
")",
"{",
"if",
"(",
"!",
"name",
"||",
"!",
"_",
".",
"isString",
"(",
"name",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid string as name!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"version",
"=",
"version",
"||",
"0",
";",
"if",
"(",
"!",
"_",
".",
"isNumber",
"(",
"version",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid number as version!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"return",
"_",
".",
"find",
"(",
"this",
".",
"commands",
",",
"function",
"(",
"cmd",
")",
"{",
"return",
"cmd",
".",
"name",
"===",
"name",
"&&",
"cmd",
".",
"version",
"===",
"version",
";",
"}",
")",
";",
"}"
] |
Returns the command module by command name and command version.
@param {String} name The command name.
@param {Number} version The command version. [optional; default 0]
@returns {Command}
|
[
"Returns",
"the",
"command",
"module",
"by",
"command",
"name",
"and",
"command",
"version",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/aggregate.js#L367-L385
|
|
14,744
|
adrai/node-cqrs-domain
|
lib/definitions/aggregate.js
|
function (name, version) {
if (!name || !_.isString(name)) {
var err = new Error('Please pass a valid string as name!');
debug(err);
throw err;
}
version = version || 0;
if (!_.isNumber(version)) {
var err = new Error('Please pass a valid number as version!');
debug(err);
throw err;
}
return _.find(this.events, function (evt) {
return evt.name === name && evt.version === version;
});
}
|
javascript
|
function (name, version) {
if (!name || !_.isString(name)) {
var err = new Error('Please pass a valid string as name!');
debug(err);
throw err;
}
version = version || 0;
if (!_.isNumber(version)) {
var err = new Error('Please pass a valid number as version!');
debug(err);
throw err;
}
return _.find(this.events, function (evt) {
return evt.name === name && evt.version === version;
});
}
|
[
"function",
"(",
"name",
",",
"version",
")",
"{",
"if",
"(",
"!",
"name",
"||",
"!",
"_",
".",
"isString",
"(",
"name",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid string as name!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"version",
"=",
"version",
"||",
"0",
";",
"if",
"(",
"!",
"_",
".",
"isNumber",
"(",
"version",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid number as version!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"return",
"_",
".",
"find",
"(",
"this",
".",
"events",
",",
"function",
"(",
"evt",
")",
"{",
"return",
"evt",
".",
"name",
"===",
"name",
"&&",
"evt",
".",
"version",
"===",
"version",
";",
"}",
")",
";",
"}"
] |
Returns the event module by event name and event version.
@param {String} name The event name.
@param {Number} version The event version. [optional; default 0]
@returns {Event}
|
[
"Returns",
"the",
"event",
"module",
"by",
"event",
"name",
"and",
"event",
"version",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/aggregate.js#L401-L419
|
|
14,745
|
adrai/node-cqrs-domain
|
lib/definitions/aggregate.js
|
function (name, version) {
if (!name || !_.isString(name)) {
var err = new Error('Please pass a valid string as name!');
debug(err);
throw err;
}
version = version || 0;
if (!_.isNumber(version)) {
var err = new Error('Please pass a valid number as version!');
debug(err);
throw err;
}
var handler = _.find(this.commandHandlers, function (cmdHnd) {
return cmdHnd.name === name && cmdHnd.version === version;
});
if (handler) {
return handler;
}
if (!this.getCommand(name, version)) {
return null;
}
return this.defaultCommandHandler;
}
|
javascript
|
function (name, version) {
if (!name || !_.isString(name)) {
var err = new Error('Please pass a valid string as name!');
debug(err);
throw err;
}
version = version || 0;
if (!_.isNumber(version)) {
var err = new Error('Please pass a valid number as version!');
debug(err);
throw err;
}
var handler = _.find(this.commandHandlers, function (cmdHnd) {
return cmdHnd.name === name && cmdHnd.version === version;
});
if (handler) {
return handler;
}
if (!this.getCommand(name, version)) {
return null;
}
return this.defaultCommandHandler;
}
|
[
"function",
"(",
"name",
",",
"version",
")",
"{",
"if",
"(",
"!",
"name",
"||",
"!",
"_",
".",
"isString",
"(",
"name",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid string as name!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"version",
"=",
"version",
"||",
"0",
";",
"if",
"(",
"!",
"_",
".",
"isNumber",
"(",
"version",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid number as version!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"var",
"handler",
"=",
"_",
".",
"find",
"(",
"this",
".",
"commandHandlers",
",",
"function",
"(",
"cmdHnd",
")",
"{",
"return",
"cmdHnd",
".",
"name",
"===",
"name",
"&&",
"cmdHnd",
".",
"version",
"===",
"version",
";",
"}",
")",
";",
"if",
"(",
"handler",
")",
"{",
"return",
"handler",
";",
"}",
"if",
"(",
"!",
"this",
".",
"getCommand",
"(",
"name",
",",
"version",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"this",
".",
"defaultCommandHandler",
";",
"}"
] |
Returns the commandHandler module by command name and command version.
@param {String} name The command name.
@param {Number} version The command version. [optional; default 0]
@returns {CommandHandler}
|
[
"Returns",
"the",
"commandHandler",
"module",
"by",
"command",
"name",
"and",
"command",
"version",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/aggregate.js#L451-L479
|
|
14,746
|
adrai/node-cqrs-domain
|
lib/definitions/aggregate.js
|
function (name, version) {
if (!name || !_.isString(name)) {
var err = new Error('Please pass a valid string as name!');
debug(err);
throw err;
}
version = version || 0;
if (!_.isNumber(version)) {
var err = new Error('Please pass a valid number as version!');
debug(err);
throw err;
}
var found = _.find(this.loadingEventTransformers, function (evt) {
return evt.name === name && evt.version === version;
});
if (found) return found;
return _.find(this.loadingEventTransformers, function (evt) {
return evt.name === name && (evt.version === null || evt.version === undefined);
});
}
|
javascript
|
function (name, version) {
if (!name || !_.isString(name)) {
var err = new Error('Please pass a valid string as name!');
debug(err);
throw err;
}
version = version || 0;
if (!_.isNumber(version)) {
var err = new Error('Please pass a valid number as version!');
debug(err);
throw err;
}
var found = _.find(this.loadingEventTransformers, function (evt) {
return evt.name === name && evt.version === version;
});
if (found) return found;
return _.find(this.loadingEventTransformers, function (evt) {
return evt.name === name && (evt.version === null || evt.version === undefined);
});
}
|
[
"function",
"(",
"name",
",",
"version",
")",
"{",
"if",
"(",
"!",
"name",
"||",
"!",
"_",
".",
"isString",
"(",
"name",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid string as name!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"version",
"=",
"version",
"||",
"0",
";",
"if",
"(",
"!",
"_",
".",
"isNumber",
"(",
"version",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid number as version!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"var",
"found",
"=",
"_",
".",
"find",
"(",
"this",
".",
"loadingEventTransformers",
",",
"function",
"(",
"evt",
")",
"{",
"return",
"evt",
".",
"name",
"===",
"name",
"&&",
"evt",
".",
"version",
"===",
"version",
";",
"}",
")",
";",
"if",
"(",
"found",
")",
"return",
"found",
";",
"return",
"_",
".",
"find",
"(",
"this",
".",
"loadingEventTransformers",
",",
"function",
"(",
"evt",
")",
"{",
"return",
"evt",
".",
"name",
"===",
"name",
"&&",
"(",
"evt",
".",
"version",
"===",
"null",
"||",
"evt",
".",
"version",
"===",
"undefined",
")",
";",
"}",
")",
";",
"}"
] |
Returns the loadingEventTransformer module by event name and event version.
@param {String} name The event name.
@param {Number} version The event version. [optional; default 0]
@returns {Event}
|
[
"Returns",
"the",
"loadingEventTransformer",
"module",
"by",
"event",
"name",
"and",
"event",
"version",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/aggregate.js#L487-L511
|
|
14,747
|
adrai/node-cqrs-domain
|
lib/definitions/aggregate.js
|
function (id) {
if (!id || !_.isString(id)) {
var err = new Error('Please pass a valid string as id!');
debug(err);
throw err;
}
return new AggregateModel(id, this.modelInitValues);
}
|
javascript
|
function (id) {
if (!id || !_.isString(id)) {
var err = new Error('Please pass a valid string as id!');
debug(err);
throw err;
}
return new AggregateModel(id, this.modelInitValues);
}
|
[
"function",
"(",
"id",
")",
"{",
"if",
"(",
"!",
"id",
"||",
"!",
"_",
".",
"isString",
"(",
"id",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass a valid string as id!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"return",
"new",
"AggregateModel",
"(",
"id",
",",
"this",
".",
"modelInitValues",
")",
";",
"}"
] |
Returns a new aggregate model, to be used in the command and event functions.
@param {String} id The aggregate id.
@returns {AggregateModel}
|
[
"Returns",
"a",
"new",
"aggregate",
"model",
"to",
"be",
"used",
"in",
"the",
"command",
"and",
"event",
"functions",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/aggregate.js#L550-L558
|
|
14,748
|
adrai/node-cqrs-domain
|
lib/definitions/aggregate.js
|
function (cmd, callback) {
var cmdName = dotty.get(cmd, this.definitions.command.name);
var err;
if (!cmdName) {
err = new Error('command has no command name in ' + this.definitions.command.name);
debug(err);
return callback(err);
}
var version = 0;
if (!!this.definitions.command.version) {
version = dotty.get(cmd, this.definitions.command.version);
}
var command = this.getCommand(cmdName, version);
if (!command) {
err = new Error('Command "' + cmdName + '" not found!');
debug(err);
return callback(err);
}
if (command.validate.length >= 2) {
return command.validate(cmd, callback);
}
try {
callback(command.validate(cmd));
} catch (e) {
callback(e);
}
}
|
javascript
|
function (cmd, callback) {
var cmdName = dotty.get(cmd, this.definitions.command.name);
var err;
if (!cmdName) {
err = new Error('command has no command name in ' + this.definitions.command.name);
debug(err);
return callback(err);
}
var version = 0;
if (!!this.definitions.command.version) {
version = dotty.get(cmd, this.definitions.command.version);
}
var command = this.getCommand(cmdName, version);
if (!command) {
err = new Error('Command "' + cmdName + '" not found!');
debug(err);
return callback(err);
}
if (command.validate.length >= 2) {
return command.validate(cmd, callback);
}
try {
callback(command.validate(cmd));
} catch (e) {
callback(e);
}
}
|
[
"function",
"(",
"cmd",
",",
"callback",
")",
"{",
"var",
"cmdName",
"=",
"dotty",
".",
"get",
"(",
"cmd",
",",
"this",
".",
"definitions",
".",
"command",
".",
"name",
")",
";",
"var",
"err",
";",
"if",
"(",
"!",
"cmdName",
")",
"{",
"err",
"=",
"new",
"Error",
"(",
"'command has no command name in '",
"+",
"this",
".",
"definitions",
".",
"command",
".",
"name",
")",
";",
"debug",
"(",
"err",
")",
";",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"var",
"version",
"=",
"0",
";",
"if",
"(",
"!",
"!",
"this",
".",
"definitions",
".",
"command",
".",
"version",
")",
"{",
"version",
"=",
"dotty",
".",
"get",
"(",
"cmd",
",",
"this",
".",
"definitions",
".",
"command",
".",
"version",
")",
";",
"}",
"var",
"command",
"=",
"this",
".",
"getCommand",
"(",
"cmdName",
",",
"version",
")",
";",
"if",
"(",
"!",
"command",
")",
"{",
"err",
"=",
"new",
"Error",
"(",
"'Command \"'",
"+",
"cmdName",
"+",
"'\" not found!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"if",
"(",
"command",
".",
"validate",
".",
"length",
">=",
"2",
")",
"{",
"return",
"command",
".",
"validate",
"(",
"cmd",
",",
"callback",
")",
";",
"}",
"try",
"{",
"callback",
"(",
"command",
".",
"validate",
"(",
"cmd",
")",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"callback",
"(",
"e",
")",
";",
"}",
"}"
] |
Validates the requested command.
@param {Object} cmd The command object
@returns {ValidationError}
|
[
"Validates",
"the",
"requested",
"command",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/aggregate.js#L565-L596
|
|
14,749
|
adrai/node-cqrs-domain
|
lib/definitions/aggregate.js
|
function (cmd, callback) {
var cmdName = dotty.get(cmd, this.definitions.command.name);
if (!cmdName) {
var err = new Error('command has no command name in ' + this.definitions.command.name);
debug(err);
throw err;
}
var version = 0;
if (!!this.definitions.command.version) {
version = dotty.get(cmd, this.definitions.command.version);
}
var command = this.getCommand(cmdName, version);
if (!command) {
var err = new Error('Command "' + cmdName + '" not found!');
debug(err);
throw err;
}
command.checkPreLoadConditions(cmd, callback);
}
|
javascript
|
function (cmd, callback) {
var cmdName = dotty.get(cmd, this.definitions.command.name);
if (!cmdName) {
var err = new Error('command has no command name in ' + this.definitions.command.name);
debug(err);
throw err;
}
var version = 0;
if (!!this.definitions.command.version) {
version = dotty.get(cmd, this.definitions.command.version);
}
var command = this.getCommand(cmdName, version);
if (!command) {
var err = new Error('Command "' + cmdName + '" not found!');
debug(err);
throw err;
}
command.checkPreLoadConditions(cmd, callback);
}
|
[
"function",
"(",
"cmd",
",",
"callback",
")",
"{",
"var",
"cmdName",
"=",
"dotty",
".",
"get",
"(",
"cmd",
",",
"this",
".",
"definitions",
".",
"command",
".",
"name",
")",
";",
"if",
"(",
"!",
"cmdName",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'command has no command name in '",
"+",
"this",
".",
"definitions",
".",
"command",
".",
"name",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"var",
"version",
"=",
"0",
";",
"if",
"(",
"!",
"!",
"this",
".",
"definitions",
".",
"command",
".",
"version",
")",
"{",
"version",
"=",
"dotty",
".",
"get",
"(",
"cmd",
",",
"this",
".",
"definitions",
".",
"command",
".",
"version",
")",
";",
"}",
"var",
"command",
"=",
"this",
".",
"getCommand",
"(",
"cmdName",
",",
"version",
")",
";",
"if",
"(",
"!",
"command",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Command \"'",
"+",
"cmdName",
"+",
"'\" not found!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"command",
".",
"checkPreLoadConditions",
"(",
"cmd",
",",
"callback",
")",
";",
"}"
] |
Checks for pre-load-conditions. This check will be done BEFORE the aggregate is locked and loaded.
@param {Object} cmd The command that was handled.
@param {Function} callback The function, that will be called when this action is completed.
`function(err){}`
|
[
"Checks",
"for",
"pre",
"-",
"load",
"-",
"conditions",
".",
"This",
"check",
"will",
"be",
"done",
"BEFORE",
"the",
"aggregate",
"is",
"locked",
"and",
"loaded",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/aggregate.js#L603-L625
|
|
14,750
|
adrai/node-cqrs-domain
|
lib/definitions/aggregate.js
|
function (changed, previous, events, command, callback) {
async.eachSeries(this.getBusinessRules(), function (rule, callback) {
rule.check(changed, previous, events, command, callback);
}, callback);
}
|
javascript
|
function (changed, previous, events, command, callback) {
async.eachSeries(this.getBusinessRules(), function (rule, callback) {
rule.check(changed, previous, events, command, callback);
}, callback);
}
|
[
"function",
"(",
"changed",
",",
"previous",
",",
"events",
",",
"command",
",",
"callback",
")",
"{",
"async",
".",
"eachSeries",
"(",
"this",
".",
"getBusinessRules",
"(",
")",
",",
"function",
"(",
"rule",
",",
"callback",
")",
"{",
"rule",
".",
"check",
"(",
"changed",
",",
"previous",
",",
"events",
",",
"command",
",",
"callback",
")",
";",
"}",
",",
"callback",
")",
";",
"}"
] |
Checks business rules.
@param {Object} changed The new aggregate values.
@param {Object} previous The previous aggregate values.
@param {Array} events All new generated events.
@param {Object} command The command that was handled.
@param {Function} callback The function, that will be called when this action is completed.
`function(err){}`
|
[
"Checks",
"business",
"rules",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/aggregate.js#L667-L671
|
|
14,751
|
adrai/node-cqrs-domain
|
lib/definitions/aggregate.js
|
function (aggregateModel, cmd, callback) {
var cmdName = dotty.get(cmd, this.definitions.command.name);
if (!cmdName) {
var err = new Error('command has no command name in ' + this.definitions.command.name);
debug(err);
return callback(err);
}
var version = 0;
if (!!this.definitions.command.version) {
version = dotty.get(cmd, this.definitions.command.version);
}
var command = this.getCommand(cmdName, version);
if (!command) {
var err = new Error('Command "' + cmdName + '" not found!');
debug(err);
return callback(err);
}
var self = this;
aggregateModel.set = function () {
throw new Error('You are not allowed to set a value in this step!');
};
var previousModel = new AggregateModel(aggregateModel.id, aggregateModel);
this.checkPreConditions(cmd, aggregateModel, function (err) {
if (err) {
return callback(err);
}
// attach apply function
aggregateModel.apply = applyHelper(self, aggregateModel, cmd);
debug('handle command');
command.handle(cmd, aggregateModel);
// remove apply function
delete aggregateModel.apply;
var uncommittedEvents = aggregateModel.getUncommittedEvents();
async.each(uncommittedEvents, function (evt, callback) {
var isEvtIdDefined = !!dotty.get(evt, self.definitions.event.id);
if (isEvtIdDefined) {
debug('event id already defined');
return callback(null);
}
// generate new id for event
debug('generate new id for event');
self.getNewId(function (err, id) {
if (err) {
return callback(err);
}
dotty.put(evt, self.definitions.event.id, id);
callback(null);
});
}, function (err) {
if (err) {
return callback(err);
}
// check business rules
debug('check business rules');
self.checkBusinessRules(aggregateModel, previousModel, uncommittedEvents, cmd, function (err) {
if (!err) {
return callback(null);
}
// clean up...
aggregateModel.reset(previousModel);
aggregateModel.clearUncommittedEvents();
callback(err);
});
});
});
}
|
javascript
|
function (aggregateModel, cmd, callback) {
var cmdName = dotty.get(cmd, this.definitions.command.name);
if (!cmdName) {
var err = new Error('command has no command name in ' + this.definitions.command.name);
debug(err);
return callback(err);
}
var version = 0;
if (!!this.definitions.command.version) {
version = dotty.get(cmd, this.definitions.command.version);
}
var command = this.getCommand(cmdName, version);
if (!command) {
var err = new Error('Command "' + cmdName + '" not found!');
debug(err);
return callback(err);
}
var self = this;
aggregateModel.set = function () {
throw new Error('You are not allowed to set a value in this step!');
};
var previousModel = new AggregateModel(aggregateModel.id, aggregateModel);
this.checkPreConditions(cmd, aggregateModel, function (err) {
if (err) {
return callback(err);
}
// attach apply function
aggregateModel.apply = applyHelper(self, aggregateModel, cmd);
debug('handle command');
command.handle(cmd, aggregateModel);
// remove apply function
delete aggregateModel.apply;
var uncommittedEvents = aggregateModel.getUncommittedEvents();
async.each(uncommittedEvents, function (evt, callback) {
var isEvtIdDefined = !!dotty.get(evt, self.definitions.event.id);
if (isEvtIdDefined) {
debug('event id already defined');
return callback(null);
}
// generate new id for event
debug('generate new id for event');
self.getNewId(function (err, id) {
if (err) {
return callback(err);
}
dotty.put(evt, self.definitions.event.id, id);
callback(null);
});
}, function (err) {
if (err) {
return callback(err);
}
// check business rules
debug('check business rules');
self.checkBusinessRules(aggregateModel, previousModel, uncommittedEvents, cmd, function (err) {
if (!err) {
return callback(null);
}
// clean up...
aggregateModel.reset(previousModel);
aggregateModel.clearUncommittedEvents();
callback(err);
});
});
});
}
|
[
"function",
"(",
"aggregateModel",
",",
"cmd",
",",
"callback",
")",
"{",
"var",
"cmdName",
"=",
"dotty",
".",
"get",
"(",
"cmd",
",",
"this",
".",
"definitions",
".",
"command",
".",
"name",
")",
";",
"if",
"(",
"!",
"cmdName",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'command has no command name in '",
"+",
"this",
".",
"definitions",
".",
"command",
".",
"name",
")",
";",
"debug",
"(",
"err",
")",
";",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"var",
"version",
"=",
"0",
";",
"if",
"(",
"!",
"!",
"this",
".",
"definitions",
".",
"command",
".",
"version",
")",
"{",
"version",
"=",
"dotty",
".",
"get",
"(",
"cmd",
",",
"this",
".",
"definitions",
".",
"command",
".",
"version",
")",
";",
"}",
"var",
"command",
"=",
"this",
".",
"getCommand",
"(",
"cmdName",
",",
"version",
")",
";",
"if",
"(",
"!",
"command",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Command \"'",
"+",
"cmdName",
"+",
"'\" not found!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"var",
"self",
"=",
"this",
";",
"aggregateModel",
".",
"set",
"=",
"function",
"(",
")",
"{",
"throw",
"new",
"Error",
"(",
"'You are not allowed to set a value in this step!'",
")",
";",
"}",
";",
"var",
"previousModel",
"=",
"new",
"AggregateModel",
"(",
"aggregateModel",
".",
"id",
",",
"aggregateModel",
")",
";",
"this",
".",
"checkPreConditions",
"(",
"cmd",
",",
"aggregateModel",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"// attach apply function",
"aggregateModel",
".",
"apply",
"=",
"applyHelper",
"(",
"self",
",",
"aggregateModel",
",",
"cmd",
")",
";",
"debug",
"(",
"'handle command'",
")",
";",
"command",
".",
"handle",
"(",
"cmd",
",",
"aggregateModel",
")",
";",
"// remove apply function",
"delete",
"aggregateModel",
".",
"apply",
";",
"var",
"uncommittedEvents",
"=",
"aggregateModel",
".",
"getUncommittedEvents",
"(",
")",
";",
"async",
".",
"each",
"(",
"uncommittedEvents",
",",
"function",
"(",
"evt",
",",
"callback",
")",
"{",
"var",
"isEvtIdDefined",
"=",
"!",
"!",
"dotty",
".",
"get",
"(",
"evt",
",",
"self",
".",
"definitions",
".",
"event",
".",
"id",
")",
";",
"if",
"(",
"isEvtIdDefined",
")",
"{",
"debug",
"(",
"'event id already defined'",
")",
";",
"return",
"callback",
"(",
"null",
")",
";",
"}",
"// generate new id for event",
"debug",
"(",
"'generate new id for event'",
")",
";",
"self",
".",
"getNewId",
"(",
"function",
"(",
"err",
",",
"id",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"dotty",
".",
"put",
"(",
"evt",
",",
"self",
".",
"definitions",
".",
"event",
".",
"id",
",",
"id",
")",
";",
"callback",
"(",
"null",
")",
";",
"}",
")",
";",
"}",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"// check business rules",
"debug",
"(",
"'check business rules'",
")",
";",
"self",
".",
"checkBusinessRules",
"(",
"aggregateModel",
",",
"previousModel",
",",
"uncommittedEvents",
",",
"cmd",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"return",
"callback",
"(",
"null",
")",
";",
"}",
"// clean up...",
"aggregateModel",
".",
"reset",
"(",
"previousModel",
")",
";",
"aggregateModel",
".",
"clearUncommittedEvents",
"(",
")",
";",
"callback",
"(",
"err",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Handles the passed command and checks the business rules.
@param {AggregateModel} aggregateModel The aggregateModel that should be used.
@param {Object} cmd The command that was handled.
@param {Function} callback The function, that will be called when this action is completed.
`function(err){}`
|
[
"Handles",
"the",
"passed",
"command",
"and",
"checks",
"the",
"business",
"rules",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/aggregate.js#L715-L795
|
|
14,752
|
adrai/node-cqrs-domain
|
lib/definitions/aggregate.js
|
function (events, aggregateModel, notSameOrigin) {
if (!events) {
return;
}
if (!_.isArray(events)) {
events = [events];
}
var self = this;
events.forEach(function (evt) {
var evtName = dotty.get(evt, self.definitions.event.name);
if (!evtName) {
var err = new Error('event has no event name in ' + self.definitions.event.name);
debug(err);
throw err;
}
var version = 0;
if (!!self.definitions.event.version) {
version = dotty.get(evt, self.definitions.event.version);
}
var event = self.getEvent(evtName, version);
if (!event) {
if (notSameOrigin) {
debug('You don\'t want to handle event "' + evtName + '" of other event stream');
return;
}
var err = new Error('Event "' + evtName + '" not found!');
debug(err);
throw err;
}
event.apply(evt, aggregateModel);
});
}
|
javascript
|
function (events, aggregateModel, notSameOrigin) {
if (!events) {
return;
}
if (!_.isArray(events)) {
events = [events];
}
var self = this;
events.forEach(function (evt) {
var evtName = dotty.get(evt, self.definitions.event.name);
if (!evtName) {
var err = new Error('event has no event name in ' + self.definitions.event.name);
debug(err);
throw err;
}
var version = 0;
if (!!self.definitions.event.version) {
version = dotty.get(evt, self.definitions.event.version);
}
var event = self.getEvent(evtName, version);
if (!event) {
if (notSameOrigin) {
debug('You don\'t want to handle event "' + evtName + '" of other event stream');
return;
}
var err = new Error('Event "' + evtName + '" not found!');
debug(err);
throw err;
}
event.apply(evt, aggregateModel);
});
}
|
[
"function",
"(",
"events",
",",
"aggregateModel",
",",
"notSameOrigin",
")",
"{",
"if",
"(",
"!",
"events",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"_",
".",
"isArray",
"(",
"events",
")",
")",
"{",
"events",
"=",
"[",
"events",
"]",
";",
"}",
"var",
"self",
"=",
"this",
";",
"events",
".",
"forEach",
"(",
"function",
"(",
"evt",
")",
"{",
"var",
"evtName",
"=",
"dotty",
".",
"get",
"(",
"evt",
",",
"self",
".",
"definitions",
".",
"event",
".",
"name",
")",
";",
"if",
"(",
"!",
"evtName",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'event has no event name in '",
"+",
"self",
".",
"definitions",
".",
"event",
".",
"name",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"var",
"version",
"=",
"0",
";",
"if",
"(",
"!",
"!",
"self",
".",
"definitions",
".",
"event",
".",
"version",
")",
"{",
"version",
"=",
"dotty",
".",
"get",
"(",
"evt",
",",
"self",
".",
"definitions",
".",
"event",
".",
"version",
")",
";",
"}",
"var",
"event",
"=",
"self",
".",
"getEvent",
"(",
"evtName",
",",
"version",
")",
";",
"if",
"(",
"!",
"event",
")",
"{",
"if",
"(",
"notSameOrigin",
")",
"{",
"debug",
"(",
"'You don\\'t want to handle event \"'",
"+",
"evtName",
"+",
"'\" of other event stream'",
")",
";",
"return",
";",
"}",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Event \"'",
"+",
"evtName",
"+",
"'\" not found!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"event",
".",
"apply",
"(",
"evt",
",",
"aggregateModel",
")",
";",
"}",
")",
";",
"}"
] |
Applies the passed events to the passed aggregateModel.
@param {Array || Object} events The events that should be applied.
@param {AggregateModel} aggregateModel The aggregateModel that should be used.
@param {boolean} notSameOrigin If true it's an indication to not throw if event handler not found.
|
[
"Applies",
"the",
"passed",
"events",
"to",
"the",
"passed",
"aggregateModel",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/aggregate.js#L803-L841
|
|
14,753
|
adrai/node-cqrs-domain
|
lib/definitions/aggregate.js
|
function (aggregateModel, snapshot, events, loadingTime, stream, streams, notSameOrigin) {
var self = this;
var isSnapshotNeeded = false;
if (snapshot) {
// load snapshot
debug('load snapshot ' + snapshot.id + ' from history', _.pick(snapshot, ['context', 'aggregate', 'version']), {
context: this.context.name,
aggregate: this.name,
version: this.version
});
if ((snapshot.context === this.context.name || !snapshot.context && this.context.name === '_general') &&
(snapshot.aggregate === this.name || !snapshot.aggregate) &&
snapshot.version === this.version) {
aggregateModel.set(snapshot.data);
} else {
if (!this.snapshotConversions[snapshot.context + '.' + snapshot.aggregate + '.' + snapshot.version]) {
var err = new Error('No snapshot conversion defined!');
debug(err);
throw err;
}
debug('convert snapshot from history');
this.snapshotConversions[snapshot.context + '.' + snapshot.aggregate + '.' + snapshot.version](snapshot.data, aggregateModel);
isSnapshotNeeded = true;
}
aggregateModel.setRevision({
context: stream.context,
aggregate: stream.aggregate,
aggregateId: stream.aggregateId
}, snapshot.revision + 1);
}
if (events && events.length > 0) {
// load events
debug('load events from history');
var maxRevision = _.reduce(events, function (res, evt) {
var rev = dotty.get(evt, self.definitions.event.revision);
if (rev > res) {
return rev;
}
return res;
}, 0);
if (!this.skipHistory || (this.skipHistory && this.applyLastEvent)) {
this.apply(events, aggregateModel, notSameOrigin);
}
aggregateModel.setRevision({
context: stream.context,
aggregate: stream.aggregate,
aggregateId: stream.aggregateId
}, maxRevision);
if (!isSnapshotNeeded) {
if (this.isSnapshotNeeded.length > 2) {
isSnapshotNeeded = this.isSnapshotNeeded(loadingTime, events, aggregateModel.toJSON(), streams);
} else {
isSnapshotNeeded = this.isSnapshotNeeded(loadingTime, events);
}
}
}
return isSnapshotNeeded;
}
|
javascript
|
function (aggregateModel, snapshot, events, loadingTime, stream, streams, notSameOrigin) {
var self = this;
var isSnapshotNeeded = false;
if (snapshot) {
// load snapshot
debug('load snapshot ' + snapshot.id + ' from history', _.pick(snapshot, ['context', 'aggregate', 'version']), {
context: this.context.name,
aggregate: this.name,
version: this.version
});
if ((snapshot.context === this.context.name || !snapshot.context && this.context.name === '_general') &&
(snapshot.aggregate === this.name || !snapshot.aggregate) &&
snapshot.version === this.version) {
aggregateModel.set(snapshot.data);
} else {
if (!this.snapshotConversions[snapshot.context + '.' + snapshot.aggregate + '.' + snapshot.version]) {
var err = new Error('No snapshot conversion defined!');
debug(err);
throw err;
}
debug('convert snapshot from history');
this.snapshotConversions[snapshot.context + '.' + snapshot.aggregate + '.' + snapshot.version](snapshot.data, aggregateModel);
isSnapshotNeeded = true;
}
aggregateModel.setRevision({
context: stream.context,
aggregate: stream.aggregate,
aggregateId: stream.aggregateId
}, snapshot.revision + 1);
}
if (events && events.length > 0) {
// load events
debug('load events from history');
var maxRevision = _.reduce(events, function (res, evt) {
var rev = dotty.get(evt, self.definitions.event.revision);
if (rev > res) {
return rev;
}
return res;
}, 0);
if (!this.skipHistory || (this.skipHistory && this.applyLastEvent)) {
this.apply(events, aggregateModel, notSameOrigin);
}
aggregateModel.setRevision({
context: stream.context,
aggregate: stream.aggregate,
aggregateId: stream.aggregateId
}, maxRevision);
if (!isSnapshotNeeded) {
if (this.isSnapshotNeeded.length > 2) {
isSnapshotNeeded = this.isSnapshotNeeded(loadingTime, events, aggregateModel.toJSON(), streams);
} else {
isSnapshotNeeded = this.isSnapshotNeeded(loadingTime, events);
}
}
}
return isSnapshotNeeded;
}
|
[
"function",
"(",
"aggregateModel",
",",
"snapshot",
",",
"events",
",",
"loadingTime",
",",
"stream",
",",
"streams",
",",
"notSameOrigin",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"isSnapshotNeeded",
"=",
"false",
";",
"if",
"(",
"snapshot",
")",
"{",
"// load snapshot",
"debug",
"(",
"'load snapshot '",
"+",
"snapshot",
".",
"id",
"+",
"' from history'",
",",
"_",
".",
"pick",
"(",
"snapshot",
",",
"[",
"'context'",
",",
"'aggregate'",
",",
"'version'",
"]",
")",
",",
"{",
"context",
":",
"this",
".",
"context",
".",
"name",
",",
"aggregate",
":",
"this",
".",
"name",
",",
"version",
":",
"this",
".",
"version",
"}",
")",
";",
"if",
"(",
"(",
"snapshot",
".",
"context",
"===",
"this",
".",
"context",
".",
"name",
"||",
"s",
"napshot.",
"c",
"ontext ",
"& ",
"his.",
"c",
"ontext.",
"n",
"ame ",
"== ",
"_general')",
" ",
"&",
"(",
"snapshot",
".",
"aggregate",
"===",
"this",
".",
"name",
"||",
"!",
"snapshot",
".",
"aggregate",
")",
"&&",
"snapshot",
".",
"version",
"===",
"this",
".",
"version",
")",
"{",
"aggregateModel",
".",
"set",
"(",
"snapshot",
".",
"data",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"this",
".",
"snapshotConversions",
"[",
"snapshot",
".",
"context",
"+",
"'.'",
"+",
"snapshot",
".",
"aggregate",
"+",
"'.'",
"+",
"snapshot",
".",
"version",
"]",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'No snapshot conversion defined!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"debug",
"(",
"'convert snapshot from history'",
")",
";",
"this",
".",
"snapshotConversions",
"[",
"snapshot",
".",
"context",
"+",
"'.'",
"+",
"snapshot",
".",
"aggregate",
"+",
"'.'",
"+",
"snapshot",
".",
"version",
"]",
"(",
"snapshot",
".",
"data",
",",
"aggregateModel",
")",
";",
"isSnapshotNeeded",
"=",
"true",
";",
"}",
"aggregateModel",
".",
"setRevision",
"(",
"{",
"context",
":",
"stream",
".",
"context",
",",
"aggregate",
":",
"stream",
".",
"aggregate",
",",
"aggregateId",
":",
"stream",
".",
"aggregateId",
"}",
",",
"snapshot",
".",
"revision",
"+",
"1",
")",
";",
"}",
"if",
"(",
"events",
"&&",
"events",
".",
"length",
">",
"0",
")",
"{",
"// load events",
"debug",
"(",
"'load events from history'",
")",
";",
"var",
"maxRevision",
"=",
"_",
".",
"reduce",
"(",
"events",
",",
"function",
"(",
"res",
",",
"evt",
")",
"{",
"var",
"rev",
"=",
"dotty",
".",
"get",
"(",
"evt",
",",
"self",
".",
"definitions",
".",
"event",
".",
"revision",
")",
";",
"if",
"(",
"rev",
">",
"res",
")",
"{",
"return",
"rev",
";",
"}",
"return",
"res",
";",
"}",
",",
"0",
")",
";",
"if",
"(",
"!",
"this",
".",
"skipHistory",
"||",
"(",
"this",
".",
"skipHistory",
"&&",
"this",
".",
"applyLastEvent",
")",
")",
"{",
"this",
".",
"apply",
"(",
"events",
",",
"aggregateModel",
",",
"notSameOrigin",
")",
";",
"}",
"aggregateModel",
".",
"setRevision",
"(",
"{",
"context",
":",
"stream",
".",
"context",
",",
"aggregate",
":",
"stream",
".",
"aggregate",
",",
"aggregateId",
":",
"stream",
".",
"aggregateId",
"}",
",",
"maxRevision",
")",
";",
"if",
"(",
"!",
"isSnapshotNeeded",
")",
"{",
"if",
"(",
"this",
".",
"isSnapshotNeeded",
".",
"length",
">",
"2",
")",
"{",
"isSnapshotNeeded",
"=",
"this",
".",
"isSnapshotNeeded",
"(",
"loadingTime",
",",
"events",
",",
"aggregateModel",
".",
"toJSON",
"(",
")",
",",
"streams",
")",
";",
"}",
"else",
"{",
"isSnapshotNeeded",
"=",
"this",
".",
"isSnapshotNeeded",
"(",
"loadingTime",
",",
"events",
")",
";",
"}",
"}",
"}",
"return",
"isSnapshotNeeded",
";",
"}"
] |
Loads the aggregateModel with the data of the snapshot and the events.
And returns true if a new snapshot should be done.
@param {AggregateModel} aggregateModel The aggregateModel that should be used.
@param {Object} snapshot The snapshot object.
@param {Array} events The events that should be applied.
@param {Number} loadingTime The loading time in ms of the eventstore data.
@param {Object} stream The eventstream.
@param {Array} streams All loaded eventstreams for this aggregate.
@param {boolean} notSameOrigin If true it's an indication to not throw if event handler not found.
@returns {boolean}
|
[
"Loads",
"the",
"aggregateModel",
"with",
"the",
"data",
"of",
"the",
"snapshot",
"and",
"the",
"events",
".",
"And",
"returns",
"true",
"if",
"a",
"new",
"snapshot",
"should",
"be",
"done",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/aggregate.js#L855-L919
|
|
14,754
|
adrai/node-cqrs-domain
|
lib/definitions/aggregate.js
|
function (meta, fn) {
if (!_.isObject(meta) || meta.version === undefined || meta.version === null || !_.isNumber(meta.version)) {
throw new Error('Please pass in a version');
}
if (!_.isFunction(fn)) {
throw new Error('Please pass in a function');
}
var wrappedFn;
if (fn.length === 1) {
wrappedFn = function (s, cb) {
try {
cb(null, fn(s));
} catch (err) {
cb(err);
}
};
} else {
wrappedFn = fn;
}
this.loadingSnapshotTransformerRegistrations.push({ meta: meta, fn: wrappedFn });
return this;
}
|
javascript
|
function (meta, fn) {
if (!_.isObject(meta) || meta.version === undefined || meta.version === null || !_.isNumber(meta.version)) {
throw new Error('Please pass in a version');
}
if (!_.isFunction(fn)) {
throw new Error('Please pass in a function');
}
var wrappedFn;
if (fn.length === 1) {
wrappedFn = function (s, cb) {
try {
cb(null, fn(s));
} catch (err) {
cb(err);
}
};
} else {
wrappedFn = fn;
}
this.loadingSnapshotTransformerRegistrations.push({ meta: meta, fn: wrappedFn });
return this;
}
|
[
"function",
"(",
"meta",
",",
"fn",
")",
"{",
"if",
"(",
"!",
"_",
".",
"isObject",
"(",
"meta",
")",
"||",
"meta",
".",
"version",
"===",
"undefined",
"||",
"meta",
".",
"version",
"===",
"null",
"||",
"!",
"_",
".",
"isNumber",
"(",
"meta",
".",
"version",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Please pass in a version'",
")",
";",
"}",
"if",
"(",
"!",
"_",
".",
"isFunction",
"(",
"fn",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Please pass in a function'",
")",
";",
"}",
"var",
"wrappedFn",
";",
"if",
"(",
"fn",
".",
"length",
"===",
"1",
")",
"{",
"wrappedFn",
"=",
"function",
"(",
"s",
",",
"cb",
")",
"{",
"try",
"{",
"cb",
"(",
"null",
",",
"fn",
"(",
"s",
")",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"cb",
"(",
"err",
")",
";",
"}",
"}",
";",
"}",
"else",
"{",
"wrappedFn",
"=",
"fn",
";",
"}",
"this",
".",
"loadingSnapshotTransformerRegistrations",
".",
"push",
"(",
"{",
"meta",
":",
"meta",
",",
"fn",
":",
"wrappedFn",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Defines a new loading transform function for snapshot.
@param {Object} meta Meta infos like: { version: 10 }
@param {Function} fn Function containing the transform function
`function(snapshotData, callback){}`
@returns {Aggregate}
|
[
"Defines",
"a",
"new",
"loading",
"transform",
"function",
"for",
"snapshot",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/aggregate.js#L928-L951
|
|
14,755
|
adrai/node-cqrs-domain
|
lib/definitions/aggregate.js
|
function (loadingTime, events) {
var snapshotThreshold = 100;
if (this.options.snapshotThreshold) {
snapshotThreshold = this.options.snapshotThreshold;
}
if (this.options.snapshotThresholdMs) {
return loadingTime >= this.options.snapshotThresholdMs;
}
return events.length >= snapshotThreshold;
}
|
javascript
|
function (loadingTime, events) {
var snapshotThreshold = 100;
if (this.options.snapshotThreshold) {
snapshotThreshold = this.options.snapshotThreshold;
}
if (this.options.snapshotThresholdMs) {
return loadingTime >= this.options.snapshotThresholdMs;
}
return events.length >= snapshotThreshold;
}
|
[
"function",
"(",
"loadingTime",
",",
"events",
")",
"{",
"var",
"snapshotThreshold",
"=",
"100",
";",
"if",
"(",
"this",
".",
"options",
".",
"snapshotThreshold",
")",
"{",
"snapshotThreshold",
"=",
"this",
".",
"options",
".",
"snapshotThreshold",
";",
"}",
"if",
"(",
"this",
".",
"options",
".",
"snapshotThresholdMs",
")",
"{",
"return",
"loadingTime",
">=",
"this",
".",
"options",
".",
"snapshotThresholdMs",
";",
"}",
"return",
"events",
".",
"length",
">=",
"snapshotThreshold",
";",
"}"
] |
Returns true if a new snapshot should be done.
@param {Number} loadingTime The loading time in ms of the eventstore data.
@param {Array} events The loaded events.
@param {Object} aggregateModel The aggregate json object. [could be used for other algorithms]
@param {Array} streams All loaded eventstreams for this aggregate.
@returns {boolean}
|
[
"Returns",
"true",
"if",
"a",
"new",
"snapshot",
"should",
"be",
"done",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/aggregate.js#L993-L1004
|
|
14,756
|
adrai/node-cqrs-domain
|
lib/definitions/aggregate.js
|
function (snapshot) {
if (!this.snapshotIgnores[snapshot.version]) {
return false;
}
return this.snapshotIgnores[snapshot.version](snapshot.data);
}
|
javascript
|
function (snapshot) {
if (!this.snapshotIgnores[snapshot.version]) {
return false;
}
return this.snapshotIgnores[snapshot.version](snapshot.data);
}
|
[
"function",
"(",
"snapshot",
")",
"{",
"if",
"(",
"!",
"this",
".",
"snapshotIgnores",
"[",
"snapshot",
".",
"version",
"]",
")",
"{",
"return",
"false",
";",
"}",
"return",
"this",
".",
"snapshotIgnores",
"[",
"snapshot",
".",
"version",
"]",
"(",
"snapshot",
".",
"data",
")",
";",
"}"
] |
Checks if a snapshot should be ignored.
@param {Object} snapshot The the snapshot.
@returns {boolean}
|
[
"Checks",
"if",
"a",
"snapshot",
"should",
"be",
"ignored",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/aggregate.js#L1011-L1017
|
|
14,757
|
adrai/node-cqrs-domain
|
lib/definitions/aggregate.js
|
function (meta, fn) {
if (!_.isObject(meta) || meta.version === undefined || meta.version === null || !_.isNumber(meta.version)) {
throw new Error('Please pass in a version');
}
if (!_.isFunction(fn)) {
throw new Error('Please pass in a function');
}
this.snapshotConversionRegistrations.push({ meta: meta, fn: fn });
return this;
}
|
javascript
|
function (meta, fn) {
if (!_.isObject(meta) || meta.version === undefined || meta.version === null || !_.isNumber(meta.version)) {
throw new Error('Please pass in a version');
}
if (!_.isFunction(fn)) {
throw new Error('Please pass in a function');
}
this.snapshotConversionRegistrations.push({ meta: meta, fn: fn });
return this;
}
|
[
"function",
"(",
"meta",
",",
"fn",
")",
"{",
"if",
"(",
"!",
"_",
".",
"isObject",
"(",
"meta",
")",
"||",
"meta",
".",
"version",
"===",
"undefined",
"||",
"meta",
".",
"version",
"===",
"null",
"||",
"!",
"_",
".",
"isNumber",
"(",
"meta",
".",
"version",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Please pass in a version'",
")",
";",
"}",
"if",
"(",
"!",
"_",
".",
"isFunction",
"(",
"fn",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Please pass in a function'",
")",
";",
"}",
"this",
".",
"snapshotConversionRegistrations",
".",
"push",
"(",
"{",
"meta",
":",
"meta",
",",
"fn",
":",
"fn",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Defines a new conversion function for older snapshot versions.
@param {Object} meta Meta infos like: { version: 10 }
@param {Function} fn Function containing the conversion rule
`function(snapshotData, aggregateModel){}`
@returns {Aggregate}
|
[
"Defines",
"a",
"new",
"conversion",
"function",
"for",
"older",
"snapshot",
"versions",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/aggregate.js#L1040-L1050
|
|
14,758
|
adrai/node-cqrs-domain
|
lib/definitions/aggregate.js
|
function (meta, fn) {
if (!_.isObject(meta) || meta.version === undefined || meta.version === null || !_.isNumber(meta.version)) {
throw new Error('Please pass in a version');
}
if (!fn) {
this.snapshotIgnores[meta.version] = function () {
return true;
};
return this;
}
if (_.isBoolean(fn)) {
this.snapshotIgnores[meta.version] = function () {
return fn;
};
return this;
}
this.snapshotIgnores[meta.version] = fn;
return this;
}
|
javascript
|
function (meta, fn) {
if (!_.isObject(meta) || meta.version === undefined || meta.version === null || !_.isNumber(meta.version)) {
throw new Error('Please pass in a version');
}
if (!fn) {
this.snapshotIgnores[meta.version] = function () {
return true;
};
return this;
}
if (_.isBoolean(fn)) {
this.snapshotIgnores[meta.version] = function () {
return fn;
};
return this;
}
this.snapshotIgnores[meta.version] = fn;
return this;
}
|
[
"function",
"(",
"meta",
",",
"fn",
")",
"{",
"if",
"(",
"!",
"_",
".",
"isObject",
"(",
"meta",
")",
"||",
"meta",
".",
"version",
"===",
"undefined",
"||",
"meta",
".",
"version",
"===",
"null",
"||",
"!",
"_",
".",
"isNumber",
"(",
"meta",
".",
"version",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Please pass in a version'",
")",
";",
"}",
"if",
"(",
"!",
"fn",
")",
"{",
"this",
".",
"snapshotIgnores",
"[",
"meta",
".",
"version",
"]",
"=",
"function",
"(",
")",
"{",
"return",
"true",
";",
"}",
";",
"return",
"this",
";",
"}",
"if",
"(",
"_",
".",
"isBoolean",
"(",
"fn",
")",
")",
"{",
"this",
".",
"snapshotIgnores",
"[",
"meta",
".",
"version",
"]",
"=",
"function",
"(",
")",
"{",
"return",
"fn",
";",
"}",
";",
"return",
"this",
";",
"}",
"this",
".",
"snapshotIgnores",
"[",
"meta",
".",
"version",
"]",
"=",
"fn",
";",
"return",
"this",
";",
"}"
] |
Defines a if a snapshot should be ignored. -> if true it will loads all events
@param {Object} meta Meta infos like: { version: 10 }
@param {Function} fn Function containing the check function [optional], default return true
`function(snapshotData){ return true; }`
@returns {Aggregate}
|
[
"Defines",
"a",
"if",
"a",
"snapshot",
"should",
"be",
"ignored",
".",
"-",
">",
"if",
"true",
"it",
"will",
"loads",
"all",
"events"
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/aggregate.js#L1059-L1080
|
|
14,759
|
adrai/node-cqrs-domain
|
lib/definitions/aggregate.js
|
function (fn) {
if (fn.length === 0) throw new Error('Please define your function to accept the command!');
if (fn.length === 1) {
var orgFn = fn;
fn = function(cmd, callback) {
callback(null, orgFn(cmd));
};
}
this.getNewAggregateId = fn;
return this;
}
|
javascript
|
function (fn) {
if (fn.length === 0) throw new Error('Please define your function to accept the command!');
if (fn.length === 1) {
var orgFn = fn;
fn = function(cmd, callback) {
callback(null, orgFn(cmd));
};
}
this.getNewAggregateId = fn;
return this;
}
|
[
"function",
"(",
"fn",
")",
"{",
"if",
"(",
"fn",
".",
"length",
"===",
"0",
")",
"throw",
"new",
"Error",
"(",
"'Please define your function to accept the command!'",
")",
";",
"if",
"(",
"fn",
".",
"length",
"===",
"1",
")",
"{",
"var",
"orgFn",
"=",
"fn",
";",
"fn",
"=",
"function",
"(",
"cmd",
",",
"callback",
")",
"{",
"callback",
"(",
"null",
",",
"orgFn",
"(",
"cmd",
")",
")",
";",
"}",
";",
"}",
"this",
".",
"getNewAggregateId",
"=",
"fn",
";",
"return",
"this",
";",
"}"
] |
Inject idGenerator function for aggregate id that is command aware.
@param {Function} fn The function to be injected.
@returns {Aggregate} to be able to chain...
|
[
"Inject",
"idGenerator",
"function",
"for",
"aggregate",
"id",
"that",
"is",
"command",
"aware",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/aggregate.js#L1105-L1117
|
|
14,760
|
adrai/node-cqrs-domain
|
lib/definitions/command.js
|
function (preCond) {
if (!preCond || !_.isObject(preCond)) {
var err = new Error('Please inject a valid preCondition object!');
debug(err);
throw err;
}
if (!preCond.payload && preCond.payload !== '') {
preCond.payload = this.aggregate.defaultPreConditionPayload;
}
if (this.preConditions.indexOf(preCond) < 0) {
preCond.defineAggregate(this.aggregate);
this.preConditions.push(preCond);
this.preConditions = _.sortBy(this.preConditions, function(pc) {
return pc.priority;
});
}
}
|
javascript
|
function (preCond) {
if (!preCond || !_.isObject(preCond)) {
var err = new Error('Please inject a valid preCondition object!');
debug(err);
throw err;
}
if (!preCond.payload && preCond.payload !== '') {
preCond.payload = this.aggregate.defaultPreConditionPayload;
}
if (this.preConditions.indexOf(preCond) < 0) {
preCond.defineAggregate(this.aggregate);
this.preConditions.push(preCond);
this.preConditions = _.sortBy(this.preConditions, function(pc) {
return pc.priority;
});
}
}
|
[
"function",
"(",
"preCond",
")",
"{",
"if",
"(",
"!",
"preCond",
"||",
"!",
"_",
".",
"isObject",
"(",
"preCond",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please inject a valid preCondition object!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"if",
"(",
"!",
"preCond",
".",
"payload",
"&&",
"preCond",
".",
"payload",
"!==",
"''",
")",
"{",
"preCond",
".",
"payload",
"=",
"this",
".",
"aggregate",
".",
"defaultPreConditionPayload",
";",
"}",
"if",
"(",
"this",
".",
"preConditions",
".",
"indexOf",
"(",
"preCond",
")",
"<",
"0",
")",
"{",
"preCond",
".",
"defineAggregate",
"(",
"this",
".",
"aggregate",
")",
";",
"this",
".",
"preConditions",
".",
"push",
"(",
"preCond",
")",
";",
"this",
".",
"preConditions",
"=",
"_",
".",
"sortBy",
"(",
"this",
".",
"preConditions",
",",
"function",
"(",
"pc",
")",
"{",
"return",
"pc",
".",
"priority",
";",
"}",
")",
";",
"}",
"}"
] |
Injects the pre-condition function.
@param {Function} preCond The pre-condition function that should be injected
|
[
"Injects",
"the",
"pre",
"-",
"condition",
"function",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/command.js#L67-L85
|
|
14,761
|
adrai/node-cqrs-domain
|
lib/definitions/command.js
|
function (preLoadCond) {
if (!preLoadCond || !_.isObject(preLoadCond)) {
var err = new Error('Please inject a valid preCondition object!');
debug(err);
throw err;
}
if (!preLoadCond.payload) {
preLoadCond.payload = this.aggregate.defaultPreLoadConditionPayload;
}
if (this.preLoadConditions.indexOf(preLoadCond) < 0) {
preLoadCond.defineAggregate(this.aggregate);
this.preLoadConditions.push(preLoadCond);
this.preLoadConditions = _.sortBy(this.preLoadConditions, function(pc) {
return pc.priority;
});
}
}
|
javascript
|
function (preLoadCond) {
if (!preLoadCond || !_.isObject(preLoadCond)) {
var err = new Error('Please inject a valid preCondition object!');
debug(err);
throw err;
}
if (!preLoadCond.payload) {
preLoadCond.payload = this.aggregate.defaultPreLoadConditionPayload;
}
if (this.preLoadConditions.indexOf(preLoadCond) < 0) {
preLoadCond.defineAggregate(this.aggregate);
this.preLoadConditions.push(preLoadCond);
this.preLoadConditions = _.sortBy(this.preLoadConditions, function(pc) {
return pc.priority;
});
}
}
|
[
"function",
"(",
"preLoadCond",
")",
"{",
"if",
"(",
"!",
"preLoadCond",
"||",
"!",
"_",
".",
"isObject",
"(",
"preLoadCond",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please inject a valid preCondition object!'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"if",
"(",
"!",
"preLoadCond",
".",
"payload",
")",
"{",
"preLoadCond",
".",
"payload",
"=",
"this",
".",
"aggregate",
".",
"defaultPreLoadConditionPayload",
";",
"}",
"if",
"(",
"this",
".",
"preLoadConditions",
".",
"indexOf",
"(",
"preLoadCond",
")",
"<",
"0",
")",
"{",
"preLoadCond",
".",
"defineAggregate",
"(",
"this",
".",
"aggregate",
")",
";",
"this",
".",
"preLoadConditions",
".",
"push",
"(",
"preLoadCond",
")",
";",
"this",
".",
"preLoadConditions",
"=",
"_",
".",
"sortBy",
"(",
"this",
".",
"preLoadConditions",
",",
"function",
"(",
"pc",
")",
"{",
"return",
"pc",
".",
"priority",
";",
"}",
")",
";",
"}",
"}"
] |
Injects the pre-load-condition function.
@param {Function} preLoadCond The pre-load-condition function that should be injected
|
[
"Injects",
"the",
"pre",
"-",
"load",
"-",
"condition",
"function",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/command.js#L91-L109
|
|
14,762
|
adrai/node-cqrs-domain
|
lib/definitions/command.js
|
function (validator) {
if (!_.isFunction(validator)) {
var err = new Error('Please pass in a function');
debug(err);
throw err;
}
if (validator.length == 2) {
return this.validator = validator;
}
this.validator = function (data, callback) {
callback(validator(data));
};
return this.validator;
}
|
javascript
|
function (validator) {
if (!_.isFunction(validator)) {
var err = new Error('Please pass in a function');
debug(err);
throw err;
}
if (validator.length == 2) {
return this.validator = validator;
}
this.validator = function (data, callback) {
callback(validator(data));
};
return this.validator;
}
|
[
"function",
"(",
"validator",
")",
"{",
"if",
"(",
"!",
"_",
".",
"isFunction",
"(",
"validator",
")",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Please pass in a function'",
")",
";",
"debug",
"(",
"err",
")",
";",
"throw",
"err",
";",
"}",
"if",
"(",
"validator",
".",
"length",
"==",
"2",
")",
"{",
"return",
"this",
".",
"validator",
"=",
"validator",
";",
"}",
"this",
".",
"validator",
"=",
"function",
"(",
"data",
",",
"callback",
")",
"{",
"callback",
"(",
"validator",
"(",
"data",
")",
")",
";",
"}",
";",
"return",
"this",
".",
"validator",
";",
"}"
] |
Injects the validator function.
@param {Function} validator The validator function that should be injected
|
[
"Injects",
"the",
"validator",
"function",
"."
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/command.js#L115-L130
|
|
14,763
|
adrai/node-cqrs-domain
|
lib/definitions/command.js
|
function (cmd, callback) {
if (this.preLoadConditions.length === 0) {
debug('no pre-load-condition for ' + this.name);
return callback(null);
}
var self = this;
async.eachSeries(this.preLoadConditions, function (preLoadCondition, callback) {
if (preLoadCondition.version === undefined || preLoadCondition.version === null || preLoadCondition.version === self.version) {
return preLoadCondition.check(cmd, callback);
}
callback(null);
}, callback);
}
|
javascript
|
function (cmd, callback) {
if (this.preLoadConditions.length === 0) {
debug('no pre-load-condition for ' + this.name);
return callback(null);
}
var self = this;
async.eachSeries(this.preLoadConditions, function (preLoadCondition, callback) {
if (preLoadCondition.version === undefined || preLoadCondition.version === null || preLoadCondition.version === self.version) {
return preLoadCondition.check(cmd, callback);
}
callback(null);
}, callback);
}
|
[
"function",
"(",
"cmd",
",",
"callback",
")",
"{",
"if",
"(",
"this",
".",
"preLoadConditions",
".",
"length",
"===",
"0",
")",
"{",
"debug",
"(",
"'no pre-load-condition for '",
"+",
"this",
".",
"name",
")",
";",
"return",
"callback",
"(",
"null",
")",
";",
"}",
"var",
"self",
"=",
"this",
";",
"async",
".",
"eachSeries",
"(",
"this",
".",
"preLoadConditions",
",",
"function",
"(",
"preLoadCondition",
",",
"callback",
")",
"{",
"if",
"(",
"preLoadCondition",
".",
"version",
"===",
"undefined",
"||",
"preLoadCondition",
".",
"version",
"===",
"null",
"||",
"preLoadCondition",
".",
"version",
"===",
"self",
".",
"version",
")",
"{",
"return",
"preLoadCondition",
".",
"check",
"(",
"cmd",
",",
"callback",
")",
";",
"}",
"callback",
"(",
"null",
")",
";",
"}",
",",
"callback",
")",
";",
"}"
] |
Checks for pre-load conditions
@param {Object} cmd The command object.
@param {Function} callback The function, that will be called when this action is completed.
`function(err){}`
|
[
"Checks",
"for",
"pre",
"-",
"load",
"conditions"
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/command.js#L151-L164
|
|
14,764
|
adrai/node-cqrs-domain
|
lib/definitions/command.js
|
function (cmd, aggregateModel, callback) {
if (this.existing === true && aggregateModel.get('_revision') === 0) {
var err = new BusinessRuleError('This command only wants to be handled, if aggregate already existing!', {
type: 'AggregateNotExisting',
aggregateId: aggregateModel.id,
aggregateRevision: aggregateModel.get('_revision')
});
debug(err);
return callback(err);
}
if (this.existing === false && aggregateModel.get('_revision') !== 0) {
var err = new BusinessRuleError('This command only wants to be handled, if aggregate not existing!', {
type: 'AggregateAlreadyExisting',
aggregateId: aggregateModel.id,
aggregateRevision: aggregateModel.get('_revision')
});
debug(err);
return callback(err);
}
if (this.preConditions.length === 0) {
debug('no pre-condition for ' + this.name);
return callback(null);
}
var self = this;
async.eachSeries(this.preConditions, function (preCondition, callback) {
if (preCondition.version === undefined || preCondition.version === null || preCondition.version === self.version) {
return preCondition.check(cmd, aggregateModel, callback);
}
callback(null);
}, callback);
}
|
javascript
|
function (cmd, aggregateModel, callback) {
if (this.existing === true && aggregateModel.get('_revision') === 0) {
var err = new BusinessRuleError('This command only wants to be handled, if aggregate already existing!', {
type: 'AggregateNotExisting',
aggregateId: aggregateModel.id,
aggregateRevision: aggregateModel.get('_revision')
});
debug(err);
return callback(err);
}
if (this.existing === false && aggregateModel.get('_revision') !== 0) {
var err = new BusinessRuleError('This command only wants to be handled, if aggregate not existing!', {
type: 'AggregateAlreadyExisting',
aggregateId: aggregateModel.id,
aggregateRevision: aggregateModel.get('_revision')
});
debug(err);
return callback(err);
}
if (this.preConditions.length === 0) {
debug('no pre-condition for ' + this.name);
return callback(null);
}
var self = this;
async.eachSeries(this.preConditions, function (preCondition, callback) {
if (preCondition.version === undefined || preCondition.version === null || preCondition.version === self.version) {
return preCondition.check(cmd, aggregateModel, callback);
}
callback(null);
}, callback);
}
|
[
"function",
"(",
"cmd",
",",
"aggregateModel",
",",
"callback",
")",
"{",
"if",
"(",
"this",
".",
"existing",
"===",
"true",
"&&",
"aggregateModel",
".",
"get",
"(",
"'_revision'",
")",
"===",
"0",
")",
"{",
"var",
"err",
"=",
"new",
"BusinessRuleError",
"(",
"'This command only wants to be handled, if aggregate already existing!'",
",",
"{",
"type",
":",
"'AggregateNotExisting'",
",",
"aggregateId",
":",
"aggregateModel",
".",
"id",
",",
"aggregateRevision",
":",
"aggregateModel",
".",
"get",
"(",
"'_revision'",
")",
"}",
")",
";",
"debug",
"(",
"err",
")",
";",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"if",
"(",
"this",
".",
"existing",
"===",
"false",
"&&",
"aggregateModel",
".",
"get",
"(",
"'_revision'",
")",
"!==",
"0",
")",
"{",
"var",
"err",
"=",
"new",
"BusinessRuleError",
"(",
"'This command only wants to be handled, if aggregate not existing!'",
",",
"{",
"type",
":",
"'AggregateAlreadyExisting'",
",",
"aggregateId",
":",
"aggregateModel",
".",
"id",
",",
"aggregateRevision",
":",
"aggregateModel",
".",
"get",
"(",
"'_revision'",
")",
"}",
")",
";",
"debug",
"(",
"err",
")",
";",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"if",
"(",
"this",
".",
"preConditions",
".",
"length",
"===",
"0",
")",
"{",
"debug",
"(",
"'no pre-condition for '",
"+",
"this",
".",
"name",
")",
";",
"return",
"callback",
"(",
"null",
")",
";",
"}",
"var",
"self",
"=",
"this",
";",
"async",
".",
"eachSeries",
"(",
"this",
".",
"preConditions",
",",
"function",
"(",
"preCondition",
",",
"callback",
")",
"{",
"if",
"(",
"preCondition",
".",
"version",
"===",
"undefined",
"||",
"preCondition",
".",
"version",
"===",
"null",
"||",
"preCondition",
".",
"version",
"===",
"self",
".",
"version",
")",
"{",
"return",
"preCondition",
".",
"check",
"(",
"cmd",
",",
"aggregateModel",
",",
"callback",
")",
";",
"}",
"callback",
"(",
"null",
")",
";",
"}",
",",
"callback",
")",
";",
"}"
] |
Checks for pre-conditions
@param {Object} cmd The command object.
@param {AggregateModel} aggregateModel The aggregate object.
@param {Function} callback The function, that will be called when this action is completed.
`function(err){}`
|
[
"Checks",
"for",
"pre",
"-",
"conditions"
] |
4e70105b11a444b02c12f2850c61242b4998361c
|
https://github.com/adrai/node-cqrs-domain/blob/4e70105b11a444b02c12f2850c61242b4998361c/lib/definitions/command.js#L173-L206
|
|
14,765
|
jshttp/etag
|
index.js
|
entitytag
|
function entitytag (entity) {
if (entity.length === 0) {
// fast-path empty
return '"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"'
}
// compute hash of entity
var hash = crypto
.createHash('sha1')
.update(entity, 'utf8')
.digest('base64')
.substring(0, 27)
// compute length of entity
var len = typeof entity === 'string'
? Buffer.byteLength(entity, 'utf8')
: entity.length
return '"' + len.toString(16) + '-' + hash + '"'
}
|
javascript
|
function entitytag (entity) {
if (entity.length === 0) {
// fast-path empty
return '"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"'
}
// compute hash of entity
var hash = crypto
.createHash('sha1')
.update(entity, 'utf8')
.digest('base64')
.substring(0, 27)
// compute length of entity
var len = typeof entity === 'string'
? Buffer.byteLength(entity, 'utf8')
: entity.length
return '"' + len.toString(16) + '-' + hash + '"'
}
|
[
"function",
"entitytag",
"(",
"entity",
")",
"{",
"if",
"(",
"entity",
".",
"length",
"===",
"0",
")",
"{",
"// fast-path empty",
"return",
"'\"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk\"'",
"}",
"// compute hash of entity",
"var",
"hash",
"=",
"crypto",
".",
"createHash",
"(",
"'sha1'",
")",
".",
"update",
"(",
"entity",
",",
"'utf8'",
")",
".",
"digest",
"(",
"'base64'",
")",
".",
"substring",
"(",
"0",
",",
"27",
")",
"// compute length of entity",
"var",
"len",
"=",
"typeof",
"entity",
"===",
"'string'",
"?",
"Buffer",
".",
"byteLength",
"(",
"entity",
",",
"'utf8'",
")",
":",
"entity",
".",
"length",
"return",
"'\"'",
"+",
"len",
".",
"toString",
"(",
"16",
")",
"+",
"'-'",
"+",
"hash",
"+",
"'\"'",
"}"
] |
Generate an entity tag.
@param {Buffer|string} entity
@return {string}
@private
|
[
"Generate",
"an",
"entity",
"tag",
"."
] |
4664b6e53c85a56521076f9c5004dd9626ae10c8
|
https://github.com/jshttp/etag/blob/4664b6e53c85a56521076f9c5004dd9626ae10c8/index.js#L39-L58
|
14,766
|
jshttp/etag
|
index.js
|
etag
|
function etag (entity, options) {
if (entity == null) {
throw new TypeError('argument entity is required')
}
// support fs.Stats object
var isStats = isstats(entity)
var weak = options && typeof options.weak === 'boolean'
? options.weak
: isStats
// validate argument
if (!isStats && typeof entity !== 'string' && !Buffer.isBuffer(entity)) {
throw new TypeError('argument entity must be string, Buffer, or fs.Stats')
}
// generate entity tag
var tag = isStats
? stattag(entity)
: entitytag(entity)
return weak
? 'W/' + tag
: tag
}
|
javascript
|
function etag (entity, options) {
if (entity == null) {
throw new TypeError('argument entity is required')
}
// support fs.Stats object
var isStats = isstats(entity)
var weak = options && typeof options.weak === 'boolean'
? options.weak
: isStats
// validate argument
if (!isStats && typeof entity !== 'string' && !Buffer.isBuffer(entity)) {
throw new TypeError('argument entity must be string, Buffer, or fs.Stats')
}
// generate entity tag
var tag = isStats
? stattag(entity)
: entitytag(entity)
return weak
? 'W/' + tag
: tag
}
|
[
"function",
"etag",
"(",
"entity",
",",
"options",
")",
"{",
"if",
"(",
"entity",
"==",
"null",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'argument entity is required'",
")",
"}",
"// support fs.Stats object",
"var",
"isStats",
"=",
"isstats",
"(",
"entity",
")",
"var",
"weak",
"=",
"options",
"&&",
"typeof",
"options",
".",
"weak",
"===",
"'boolean'",
"?",
"options",
".",
"weak",
":",
"isStats",
"// validate argument",
"if",
"(",
"!",
"isStats",
"&&",
"typeof",
"entity",
"!==",
"'string'",
"&&",
"!",
"Buffer",
".",
"isBuffer",
"(",
"entity",
")",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'argument entity must be string, Buffer, or fs.Stats'",
")",
"}",
"// generate entity tag",
"var",
"tag",
"=",
"isStats",
"?",
"stattag",
"(",
"entity",
")",
":",
"entitytag",
"(",
"entity",
")",
"return",
"weak",
"?",
"'W/'",
"+",
"tag",
":",
"tag",
"}"
] |
Create a simple ETag.
@param {string|Buffer|Stats} entity
@param {object} [options]
@param {boolean} [options.weak]
@return {String}
@public
|
[
"Create",
"a",
"simple",
"ETag",
"."
] |
4664b6e53c85a56521076f9c5004dd9626ae10c8
|
https://github.com/jshttp/etag/blob/4664b6e53c85a56521076f9c5004dd9626ae10c8/index.js#L70-L94
|
14,767
|
jshttp/etag
|
index.js
|
isstats
|
function isstats (obj) {
// genuine fs.Stats
if (typeof Stats === 'function' && obj instanceof Stats) {
return true
}
// quack quack
return obj && typeof obj === 'object' &&
'ctime' in obj && toString.call(obj.ctime) === '[object Date]' &&
'mtime' in obj && toString.call(obj.mtime) === '[object Date]' &&
'ino' in obj && typeof obj.ino === 'number' &&
'size' in obj && typeof obj.size === 'number'
}
|
javascript
|
function isstats (obj) {
// genuine fs.Stats
if (typeof Stats === 'function' && obj instanceof Stats) {
return true
}
// quack quack
return obj && typeof obj === 'object' &&
'ctime' in obj && toString.call(obj.ctime) === '[object Date]' &&
'mtime' in obj && toString.call(obj.mtime) === '[object Date]' &&
'ino' in obj && typeof obj.ino === 'number' &&
'size' in obj && typeof obj.size === 'number'
}
|
[
"function",
"isstats",
"(",
"obj",
")",
"{",
"// genuine fs.Stats",
"if",
"(",
"typeof",
"Stats",
"===",
"'function'",
"&&",
"obj",
"instanceof",
"Stats",
")",
"{",
"return",
"true",
"}",
"// quack quack",
"return",
"obj",
"&&",
"typeof",
"obj",
"===",
"'object'",
"&&",
"'ctime'",
"in",
"obj",
"&&",
"toString",
".",
"call",
"(",
"obj",
".",
"ctime",
")",
"===",
"'[object Date]'",
"&&",
"'mtime'",
"in",
"obj",
"&&",
"toString",
".",
"call",
"(",
"obj",
".",
"mtime",
")",
"===",
"'[object Date]'",
"&&",
"'ino'",
"in",
"obj",
"&&",
"typeof",
"obj",
".",
"ino",
"===",
"'number'",
"&&",
"'size'",
"in",
"obj",
"&&",
"typeof",
"obj",
".",
"size",
"===",
"'number'",
"}"
] |
Determine if object is a Stats object.
@param {object} obj
@return {boolean}
@api private
|
[
"Determine",
"if",
"object",
"is",
"a",
"Stats",
"object",
"."
] |
4664b6e53c85a56521076f9c5004dd9626ae10c8
|
https://github.com/jshttp/etag/blob/4664b6e53c85a56521076f9c5004dd9626ae10c8/index.js#L104-L116
|
14,768
|
jshttp/etag
|
index.js
|
stattag
|
function stattag (stat) {
var mtime = stat.mtime.getTime().toString(16)
var size = stat.size.toString(16)
return '"' + size + '-' + mtime + '"'
}
|
javascript
|
function stattag (stat) {
var mtime = stat.mtime.getTime().toString(16)
var size = stat.size.toString(16)
return '"' + size + '-' + mtime + '"'
}
|
[
"function",
"stattag",
"(",
"stat",
")",
"{",
"var",
"mtime",
"=",
"stat",
".",
"mtime",
".",
"getTime",
"(",
")",
".",
"toString",
"(",
"16",
")",
"var",
"size",
"=",
"stat",
".",
"size",
".",
"toString",
"(",
"16",
")",
"return",
"'\"'",
"+",
"size",
"+",
"'-'",
"+",
"mtime",
"+",
"'\"'",
"}"
] |
Generate a tag for a stat.
@param {object} stat
@return {string}
@private
|
[
"Generate",
"a",
"tag",
"for",
"a",
"stat",
"."
] |
4664b6e53c85a56521076f9c5004dd9626ae10c8
|
https://github.com/jshttp/etag/blob/4664b6e53c85a56521076f9c5004dd9626ae10c8/index.js#L126-L131
|
14,769
|
epoberezkin/ajv-keywords
|
index.js
|
defineKeywords
|
function defineKeywords(ajv, keyword) {
if (Array.isArray(keyword)) {
for (var i=0; i<keyword.length; i++)
get(keyword[i])(ajv);
return ajv;
}
if (keyword) {
get(keyword)(ajv);
return ajv;
}
for (keyword in KEYWORDS) get(keyword)(ajv);
return ajv;
}
|
javascript
|
function defineKeywords(ajv, keyword) {
if (Array.isArray(keyword)) {
for (var i=0; i<keyword.length; i++)
get(keyword[i])(ajv);
return ajv;
}
if (keyword) {
get(keyword)(ajv);
return ajv;
}
for (keyword in KEYWORDS) get(keyword)(ajv);
return ajv;
}
|
[
"function",
"defineKeywords",
"(",
"ajv",
",",
"keyword",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"keyword",
")",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"keyword",
".",
"length",
";",
"i",
"++",
")",
"get",
"(",
"keyword",
"[",
"i",
"]",
")",
"(",
"ajv",
")",
";",
"return",
"ajv",
";",
"}",
"if",
"(",
"keyword",
")",
"{",
"get",
"(",
"keyword",
")",
"(",
"ajv",
")",
";",
"return",
"ajv",
";",
"}",
"for",
"(",
"keyword",
"in",
"KEYWORDS",
")",
"get",
"(",
"keyword",
")",
"(",
"ajv",
")",
";",
"return",
"ajv",
";",
"}"
] |
Defines one or several keywords in ajv instance
@param {Ajv} ajv validator instance
@param {String|Array<String>|undefined} keyword keyword(s) to define
@return {Ajv} ajv instance (for chaining)
|
[
"Defines",
"one",
"or",
"several",
"keywords",
"in",
"ajv",
"instance"
] |
9ebcae203fac7a78c391bfc7076497f591fe0be6
|
https://github.com/epoberezkin/ajv-keywords/blob/9ebcae203fac7a78c391bfc7076497f591fe0be6/index.js#L14-L26
|
14,770
|
efeiefei/node-file-manager
|
lib/public/js/angular-file.js
|
function(file) {
var deferred = $q.defer();
var reader = angular.extend(new FileReader(), {
onload: function(e) {
deferred.resolve(e.target.result);
if (!$rootScope.$$phase) $rootScope.$apply();
},
onerror: function(e) {
deferred.reject(e);
if (!$rootScope.$$phase) $rootScope.$apply();
},
onabort: function(e) {
deferred.reject(e);
if (!$rootScope.$$phase) $rootScope.$apply();
}
// onprogress: Gee, it'd be great to get some progress support from $q...
});
reader.readAsDataURL(file);
return angular.extend(deferred.promise, {
abort: function() { reader.abort(); }
});
}
|
javascript
|
function(file) {
var deferred = $q.defer();
var reader = angular.extend(new FileReader(), {
onload: function(e) {
deferred.resolve(e.target.result);
if (!$rootScope.$$phase) $rootScope.$apply();
},
onerror: function(e) {
deferred.reject(e);
if (!$rootScope.$$phase) $rootScope.$apply();
},
onabort: function(e) {
deferred.reject(e);
if (!$rootScope.$$phase) $rootScope.$apply();
}
// onprogress: Gee, it'd be great to get some progress support from $q...
});
reader.readAsDataURL(file);
return angular.extend(deferred.promise, {
abort: function() { reader.abort(); }
});
}
|
[
"function",
"(",
"file",
")",
"{",
"var",
"deferred",
"=",
"$q",
".",
"defer",
"(",
")",
";",
"var",
"reader",
"=",
"angular",
".",
"extend",
"(",
"new",
"FileReader",
"(",
")",
",",
"{",
"onload",
":",
"function",
"(",
"e",
")",
"{",
"deferred",
".",
"resolve",
"(",
"e",
".",
"target",
".",
"result",
")",
";",
"if",
"(",
"!",
"$rootScope",
".",
"$$phase",
")",
"$rootScope",
".",
"$apply",
"(",
")",
";",
"}",
",",
"onerror",
":",
"function",
"(",
"e",
")",
"{",
"deferred",
".",
"reject",
"(",
"e",
")",
";",
"if",
"(",
"!",
"$rootScope",
".",
"$$phase",
")",
"$rootScope",
".",
"$apply",
"(",
")",
";",
"}",
",",
"onabort",
":",
"function",
"(",
"e",
")",
"{",
"deferred",
".",
"reject",
"(",
"e",
")",
";",
"if",
"(",
"!",
"$rootScope",
".",
"$$phase",
")",
"$rootScope",
".",
"$apply",
"(",
")",
";",
"}",
"// onprogress: Gee, it'd be great to get some progress support from $q...",
"}",
")",
";",
"reader",
".",
"readAsDataURL",
"(",
"file",
")",
";",
"return",
"angular",
".",
"extend",
"(",
"deferred",
".",
"promise",
",",
"{",
"abort",
":",
"function",
"(",
")",
"{",
"reader",
".",
"abort",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Loads a file as a data URL and returns a promise representing the file's value.
|
[
"Loads",
"a",
"file",
"as",
"a",
"data",
"URL",
"and",
"returns",
"a",
"promise",
"representing",
"the",
"file",
"s",
"value",
"."
] |
b28dd01f22796658d245d7a3a9c05f784c4b959e
|
https://github.com/efeiefei/node-file-manager/blob/b28dd01f22796658d245d7a3a9c05f784c4b959e/lib/public/js/angular-file.js#L128-L151
|
|
14,771
|
efeiefei/node-file-manager
|
lib/public/js/angular-file.js
|
function(file) {
return {
name: file.name,
size: file.size,
lastModifiedDate: file.lastModifiedDate
};
}
|
javascript
|
function(file) {
return {
name: file.name,
size: file.size,
lastModifiedDate: file.lastModifiedDate
};
}
|
[
"function",
"(",
"file",
")",
"{",
"return",
"{",
"name",
":",
"file",
".",
"name",
",",
"size",
":",
"file",
".",
"size",
",",
"lastModifiedDate",
":",
"file",
".",
"lastModifiedDate",
"}",
";",
"}"
] |
Returns the metadata from a File object, including the name, size and last modified date.
|
[
"Returns",
"the",
"metadata",
"from",
"a",
"File",
"object",
"including",
"the",
"name",
"size",
"and",
"last",
"modified",
"date",
"."
] |
b28dd01f22796658d245d7a3a9c05f784c4b959e
|
https://github.com/efeiefei/node-file-manager/blob/b28dd01f22796658d245d7a3a9c05f784c4b959e/lib/public/js/angular-file.js#L156-L162
|
|
14,772
|
efeiefei/node-file-manager
|
lib/public/js/angular-file.js
|
function(data) {
var extras = {};
if (data instanceof File) {
extras = this.meta(data);
data = data.toDataURL();
}
var parts = data.split(","), headers = parts[0].split(":"), body;
if (parts.length !== 2 || headers.length !== 2 || headers[0] !== "data") {
throw new Error("Invalid data URI.");
}
headers = headers[1].split(";");
body = (headers[1] === "base64") ? atob(parts[1]) : decodeURI(parts[1]);
var length = body.length, buffer = new ArrayBuffer(length), bytes = new Uint8Array(buffer);
for (var i = 0; i < length; i++) {
bytes[i] = body.charCodeAt(i);
}
return angular.extend(new Blob([bytes], { type: headers[0] }), extras);
}
|
javascript
|
function(data) {
var extras = {};
if (data instanceof File) {
extras = this.meta(data);
data = data.toDataURL();
}
var parts = data.split(","), headers = parts[0].split(":"), body;
if (parts.length !== 2 || headers.length !== 2 || headers[0] !== "data") {
throw new Error("Invalid data URI.");
}
headers = headers[1].split(";");
body = (headers[1] === "base64") ? atob(parts[1]) : decodeURI(parts[1]);
var length = body.length, buffer = new ArrayBuffer(length), bytes = new Uint8Array(buffer);
for (var i = 0; i < length; i++) {
bytes[i] = body.charCodeAt(i);
}
return angular.extend(new Blob([bytes], { type: headers[0] }), extras);
}
|
[
"function",
"(",
"data",
")",
"{",
"var",
"extras",
"=",
"{",
"}",
";",
"if",
"(",
"data",
"instanceof",
"File",
")",
"{",
"extras",
"=",
"this",
".",
"meta",
"(",
"data",
")",
";",
"data",
"=",
"data",
".",
"toDataURL",
"(",
")",
";",
"}",
"var",
"parts",
"=",
"data",
".",
"split",
"(",
"\",\"",
")",
",",
"headers",
"=",
"parts",
"[",
"0",
"]",
".",
"split",
"(",
"\":\"",
")",
",",
"body",
";",
"if",
"(",
"parts",
".",
"length",
"!==",
"2",
"||",
"headers",
".",
"length",
"!==",
"2",
"||",
"headers",
"[",
"0",
"]",
"!==",
"\"data\"",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Invalid data URI.\"",
")",
";",
"}",
"headers",
"=",
"headers",
"[",
"1",
"]",
".",
"split",
"(",
"\";\"",
")",
";",
"body",
"=",
"(",
"headers",
"[",
"1",
"]",
"===",
"\"base64\"",
")",
"?",
"atob",
"(",
"parts",
"[",
"1",
"]",
")",
":",
"decodeURI",
"(",
"parts",
"[",
"1",
"]",
")",
";",
"var",
"length",
"=",
"body",
".",
"length",
",",
"buffer",
"=",
"new",
"ArrayBuffer",
"(",
"length",
")",
",",
"bytes",
"=",
"new",
"Uint8Array",
"(",
"buffer",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"bytes",
"[",
"i",
"]",
"=",
"body",
".",
"charCodeAt",
"(",
"i",
")",
";",
"}",
"return",
"angular",
".",
"extend",
"(",
"new",
"Blob",
"(",
"[",
"bytes",
"]",
",",
"{",
"type",
":",
"headers",
"[",
"0",
"]",
"}",
")",
",",
"extras",
")",
";",
"}"
] |
Converts a File object or data URL to a Blob.
|
[
"Converts",
"a",
"File",
"object",
"or",
"data",
"URL",
"to",
"a",
"Blob",
"."
] |
b28dd01f22796658d245d7a3a9c05f784c4b959e
|
https://github.com/efeiefei/node-file-manager/blob/b28dd01f22796658d245d7a3a9c05f784c4b959e/lib/public/js/angular-file.js#L167-L187
|
|
14,773
|
Zod-/jsVideoUrlParser
|
lib/util.js
|
getLetterTime
|
function getLetterTime(timeString) {
var totalSeconds = 0;
var timeValues = {
's': 1,
'm': 1 * 60,
'h': 1 * 60 * 60,
'd': 1 * 60 * 60 * 24,
'w': 1 * 60 * 60 * 24 * 7,
};
var timePairs;
//expand to "1 h 30 m 20 s" and split
timeString = timeString.replace(/([smhdw])/g, ' $1 ').trim();
timePairs = timeString.split(' ');
for (var i = 0; i < timePairs.length; i += 2) {
totalSeconds += parseInt(timePairs[i], 10) *
timeValues[timePairs[i + 1] || 's'];
}
return totalSeconds;
}
|
javascript
|
function getLetterTime(timeString) {
var totalSeconds = 0;
var timeValues = {
's': 1,
'm': 1 * 60,
'h': 1 * 60 * 60,
'd': 1 * 60 * 60 * 24,
'w': 1 * 60 * 60 * 24 * 7,
};
var timePairs;
//expand to "1 h 30 m 20 s" and split
timeString = timeString.replace(/([smhdw])/g, ' $1 ').trim();
timePairs = timeString.split(' ');
for (var i = 0; i < timePairs.length; i += 2) {
totalSeconds += parseInt(timePairs[i], 10) *
timeValues[timePairs[i + 1] || 's'];
}
return totalSeconds;
}
|
[
"function",
"getLetterTime",
"(",
"timeString",
")",
"{",
"var",
"totalSeconds",
"=",
"0",
";",
"var",
"timeValues",
"=",
"{",
"'s'",
":",
"1",
",",
"'m'",
":",
"1",
"*",
"60",
",",
"'h'",
":",
"1",
"*",
"60",
"*",
"60",
",",
"'d'",
":",
"1",
"*",
"60",
"*",
"60",
"*",
"24",
",",
"'w'",
":",
"1",
"*",
"60",
"*",
"60",
"*",
"24",
"*",
"7",
",",
"}",
";",
"var",
"timePairs",
";",
"//expand to \"1 h 30 m 20 s\" and split",
"timeString",
"=",
"timeString",
".",
"replace",
"(",
"/",
"([smhdw])",
"/",
"g",
",",
"' $1 '",
")",
".",
"trim",
"(",
")",
";",
"timePairs",
"=",
"timeString",
".",
"split",
"(",
"' '",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"timePairs",
".",
"length",
";",
"i",
"+=",
"2",
")",
"{",
"totalSeconds",
"+=",
"parseInt",
"(",
"timePairs",
"[",
"i",
"]",
",",
"10",
")",
"*",
"timeValues",
"[",
"timePairs",
"[",
"i",
"+",
"1",
"]",
"||",
"'s'",
"]",
";",
"}",
"return",
"totalSeconds",
";",
"}"
] |
parses strings like 1h30m20s to seconds
|
[
"parses",
"strings",
"like",
"1h30m20s",
"to",
"seconds"
] |
4f819a536f57413f784f2a78ff826b605722e275
|
https://github.com/Zod-/jsVideoUrlParser/blob/4f819a536f57413f784f2a78ff826b605722e275/lib/util.js#L55-L75
|
14,774
|
esvit/ng-table
|
scripts/webpack/libParts.js
|
extractSass
|
function extractSass(files) {
// note: The way we're setting up webpack here seems a bit of a hack:
//
// Although the setup creates two bundles seperating the js and css as desired,
// it's also producing an extra styles.js file which we're throwing away/ignoring.
// The alternative, more supported way of things, is to leave the css inline
// within js and let the styles plugin add the css at runtime to the html page.
// At the moment keeping with the extracted css as:
// 1. more familar to angular 1 developers (?)
// 2. maintains backwards compatibility with the existing apps that expects
// the css to be delivered to the browser as a seperate file
const filename = env.prod ? `${libraryName}.min.css` : `${libraryName}.css`;
const extractor = new ExtractTextPlugin(filename);
let loader;
if (env.debug || env.prod) {
loader = 'css-loader?sourceMap!sass-loader?sourceMap';
} else {
loader = 'css-loader!sass-loader';
}
return {
entry: {
styles: files
},
module: {
rules: [
{
test: /\.scss$/,
loader: extractor.extract(loader),
include: files
}
]
},
plugins: [
extractor
]
};
}
|
javascript
|
function extractSass(files) {
// note: The way we're setting up webpack here seems a bit of a hack:
//
// Although the setup creates two bundles seperating the js and css as desired,
// it's also producing an extra styles.js file which we're throwing away/ignoring.
// The alternative, more supported way of things, is to leave the css inline
// within js and let the styles plugin add the css at runtime to the html page.
// At the moment keeping with the extracted css as:
// 1. more familar to angular 1 developers (?)
// 2. maintains backwards compatibility with the existing apps that expects
// the css to be delivered to the browser as a seperate file
const filename = env.prod ? `${libraryName}.min.css` : `${libraryName}.css`;
const extractor = new ExtractTextPlugin(filename);
let loader;
if (env.debug || env.prod) {
loader = 'css-loader?sourceMap!sass-loader?sourceMap';
} else {
loader = 'css-loader!sass-loader';
}
return {
entry: {
styles: files
},
module: {
rules: [
{
test: /\.scss$/,
loader: extractor.extract(loader),
include: files
}
]
},
plugins: [
extractor
]
};
}
|
[
"function",
"extractSass",
"(",
"files",
")",
"{",
"// note: The way we're setting up webpack here seems a bit of a hack:",
"//",
"// Although the setup creates two bundles seperating the js and css as desired,",
"// it's also producing an extra styles.js file which we're throwing away/ignoring.",
"// The alternative, more supported way of things, is to leave the css inline",
"// within js and let the styles plugin add the css at runtime to the html page.",
"// At the moment keeping with the extracted css as:",
"// 1. more familar to angular 1 developers (?)",
"// 2. maintains backwards compatibility with the existing apps that expects",
"// the css to be delivered to the browser as a seperate file",
"const",
"filename",
"=",
"env",
".",
"prod",
"?",
"`",
"${",
"libraryName",
"}",
"`",
":",
"`",
"${",
"libraryName",
"}",
"`",
";",
"const",
"extractor",
"=",
"new",
"ExtractTextPlugin",
"(",
"filename",
")",
";",
"let",
"loader",
";",
"if",
"(",
"env",
".",
"debug",
"||",
"env",
".",
"prod",
")",
"{",
"loader",
"=",
"'css-loader?sourceMap!sass-loader?sourceMap'",
";",
"}",
"else",
"{",
"loader",
"=",
"'css-loader!sass-loader'",
";",
"}",
"return",
"{",
"entry",
":",
"{",
"styles",
":",
"files",
"}",
",",
"module",
":",
"{",
"rules",
":",
"[",
"{",
"test",
":",
"/",
"\\.scss$",
"/",
",",
"loader",
":",
"extractor",
".",
"extract",
"(",
"loader",
")",
",",
"include",
":",
"files",
"}",
"]",
"}",
",",
"plugins",
":",
"[",
"extractor",
"]",
"}",
";",
"}"
] |
Extracts styles into a seperate bundle
|
[
"Extracts",
"styles",
"into",
"a",
"seperate",
"bundle"
] |
b6d5d0bfeef923c617081ffe80a0266d7fb4aa33
|
https://github.com/esvit/ng-table/blob/b6d5d0bfeef923c617081ffe80a0266d7fb4aa33/scripts/webpack/libParts.js#L65-L103
|
14,775
|
mapbox/tilelive
|
lib/stream-pyramid.js
|
nextShallow
|
function nextShallow(stream) {
if (!stream.cursor) return false;
var cursor = stream.cursor;
cursor.x++;
var bbox = stream.bboxes[cursor.z];
if (cursor.x > bbox.maxX) {
cursor.x = bbox.minX;
cursor.y++;
}
if (cursor.y > bbox.maxY) {
stream.cursor = false;
return false;
}
return true;
}
|
javascript
|
function nextShallow(stream) {
if (!stream.cursor) return false;
var cursor = stream.cursor;
cursor.x++;
var bbox = stream.bboxes[cursor.z];
if (cursor.x > bbox.maxX) {
cursor.x = bbox.minX;
cursor.y++;
}
if (cursor.y > bbox.maxY) {
stream.cursor = false;
return false;
}
return true;
}
|
[
"function",
"nextShallow",
"(",
"stream",
")",
"{",
"if",
"(",
"!",
"stream",
".",
"cursor",
")",
"return",
"false",
";",
"var",
"cursor",
"=",
"stream",
".",
"cursor",
";",
"cursor",
".",
"x",
"++",
";",
"var",
"bbox",
"=",
"stream",
".",
"bboxes",
"[",
"cursor",
".",
"z",
"]",
";",
"if",
"(",
"cursor",
".",
"x",
">",
"bbox",
".",
"maxX",
")",
"{",
"cursor",
".",
"x",
"=",
"bbox",
".",
"minX",
";",
"cursor",
".",
"y",
"++",
";",
"}",
"if",
"(",
"cursor",
".",
"y",
">",
"bbox",
".",
"maxY",
")",
"{",
"stream",
".",
"cursor",
"=",
"false",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Increment a tile cursor to the next position on the lowest zoom level.
|
[
"Increment",
"a",
"tile",
"cursor",
"to",
"the",
"next",
"position",
"on",
"the",
"lowest",
"zoom",
"level",
"."
] |
8a37d89dd6e9fb0f6938e1c6ccf62349556c9375
|
https://github.com/mapbox/tilelive/blob/8a37d89dd6e9fb0f6938e1c6ccf62349556c9375/lib/stream-pyramid.js#L172-L186
|
14,776
|
mapbox/tilelive
|
lib/stream-scanline.js
|
nextDeep
|
function nextDeep(stream) {
if (!stream.cursor) return false;
var cursor = stream.cursor;
cursor.x++;
var bbox = stream.bboxes[cursor.z];
if (cursor.x > bbox.maxX) {
cursor.x = bbox.minX;
cursor.y++;
}
if (cursor.y > bbox.maxY) {
cursor.z++;
if (cursor.z > stream.maxzoom) {
stream.cursor = false;
return false;
}
bbox = stream.bboxes[cursor.z];
cursor.x = bbox.minX;
cursor.y = bbox.minY;
}
return true;
}
|
javascript
|
function nextDeep(stream) {
if (!stream.cursor) return false;
var cursor = stream.cursor;
cursor.x++;
var bbox = stream.bboxes[cursor.z];
if (cursor.x > bbox.maxX) {
cursor.x = bbox.minX;
cursor.y++;
}
if (cursor.y > bbox.maxY) {
cursor.z++;
if (cursor.z > stream.maxzoom) {
stream.cursor = false;
return false;
}
bbox = stream.bboxes[cursor.z];
cursor.x = bbox.minX;
cursor.y = bbox.minY;
}
return true;
}
|
[
"function",
"nextDeep",
"(",
"stream",
")",
"{",
"if",
"(",
"!",
"stream",
".",
"cursor",
")",
"return",
"false",
";",
"var",
"cursor",
"=",
"stream",
".",
"cursor",
";",
"cursor",
".",
"x",
"++",
";",
"var",
"bbox",
"=",
"stream",
".",
"bboxes",
"[",
"cursor",
".",
"z",
"]",
";",
"if",
"(",
"cursor",
".",
"x",
">",
"bbox",
".",
"maxX",
")",
"{",
"cursor",
".",
"x",
"=",
"bbox",
".",
"minX",
";",
"cursor",
".",
"y",
"++",
";",
"}",
"if",
"(",
"cursor",
".",
"y",
">",
"bbox",
".",
"maxY",
")",
"{",
"cursor",
".",
"z",
"++",
";",
"if",
"(",
"cursor",
".",
"z",
">",
"stream",
".",
"maxzoom",
")",
"{",
"stream",
".",
"cursor",
"=",
"false",
";",
"return",
"false",
";",
"}",
"bbox",
"=",
"stream",
".",
"bboxes",
"[",
"cursor",
".",
"z",
"]",
";",
"cursor",
".",
"x",
"=",
"bbox",
".",
"minX",
";",
"cursor",
".",
"y",
"=",
"bbox",
".",
"minY",
";",
"}",
"return",
"true",
";",
"}"
] |
Increment a tile cursor to the next position, descending zoom levels until maxzoom is reached.
|
[
"Increment",
"a",
"tile",
"cursor",
"to",
"the",
"next",
"position",
"descending",
"zoom",
"levels",
"until",
"maxzoom",
"is",
"reached",
"."
] |
8a37d89dd6e9fb0f6938e1c6ccf62349556c9375
|
https://github.com/mapbox/tilelive/blob/8a37d89dd6e9fb0f6938e1c6ccf62349556c9375/lib/stream-scanline.js#L129-L149
|
14,777
|
mapbox/tilelive
|
lib/stream-util.js
|
multiread
|
function multiread(stream, get) {
if (stream._multiread === undefined) {
stream._multiread = stream._multiread || [];
stream._multireading = stream._multireading || 0;
stream._multireadmax = stream._multireadmax || concurrency;
}
if (stream._multiread.length) {
push();
} else {
stream.once('_push', push);
}
while ((stream._multiread.length + stream._multireading) < stream._multireadmax) {
stream._multireading++;
if (!get(done)) break;
}
function done(item) {
stream._multireading--;
if (item === null && !stream._multireading) {
stream.emit('_push');
} else if (item) {
stream._multiread.push(item);
stream.emit('_push');
}
}
function push() {
if (stream._multiread.length) {
stream.push(stream._multiread.shift());
} else {
stream.push(null);
}
}
}
|
javascript
|
function multiread(stream, get) {
if (stream._multiread === undefined) {
stream._multiread = stream._multiread || [];
stream._multireading = stream._multireading || 0;
stream._multireadmax = stream._multireadmax || concurrency;
}
if (stream._multiread.length) {
push();
} else {
stream.once('_push', push);
}
while ((stream._multiread.length + stream._multireading) < stream._multireadmax) {
stream._multireading++;
if (!get(done)) break;
}
function done(item) {
stream._multireading--;
if (item === null && !stream._multireading) {
stream.emit('_push');
} else if (item) {
stream._multiread.push(item);
stream.emit('_push');
}
}
function push() {
if (stream._multiread.length) {
stream.push(stream._multiread.shift());
} else {
stream.push(null);
}
}
}
|
[
"function",
"multiread",
"(",
"stream",
",",
"get",
")",
"{",
"if",
"(",
"stream",
".",
"_multiread",
"===",
"undefined",
")",
"{",
"stream",
".",
"_multiread",
"=",
"stream",
".",
"_multiread",
"||",
"[",
"]",
";",
"stream",
".",
"_multireading",
"=",
"stream",
".",
"_multireading",
"||",
"0",
";",
"stream",
".",
"_multireadmax",
"=",
"stream",
".",
"_multireadmax",
"||",
"concurrency",
";",
"}",
"if",
"(",
"stream",
".",
"_multiread",
".",
"length",
")",
"{",
"push",
"(",
")",
";",
"}",
"else",
"{",
"stream",
".",
"once",
"(",
"'_push'",
",",
"push",
")",
";",
"}",
"while",
"(",
"(",
"stream",
".",
"_multiread",
".",
"length",
"+",
"stream",
".",
"_multireading",
")",
"<",
"stream",
".",
"_multireadmax",
")",
"{",
"stream",
".",
"_multireading",
"++",
";",
"if",
"(",
"!",
"get",
"(",
"done",
")",
")",
"break",
";",
"}",
"function",
"done",
"(",
"item",
")",
"{",
"stream",
".",
"_multireading",
"--",
";",
"if",
"(",
"item",
"===",
"null",
"&&",
"!",
"stream",
".",
"_multireading",
")",
"{",
"stream",
".",
"emit",
"(",
"'_push'",
")",
";",
"}",
"else",
"if",
"(",
"item",
")",
"{",
"stream",
".",
"_multiread",
".",
"push",
"(",
"item",
")",
";",
"stream",
".",
"emit",
"(",
"'_push'",
")",
";",
"}",
"}",
"function",
"push",
"(",
")",
"{",
"if",
"(",
"stream",
".",
"_multiread",
".",
"length",
")",
"{",
"stream",
".",
"push",
"(",
"stream",
".",
"_multiread",
".",
"shift",
"(",
")",
")",
";",
"}",
"else",
"{",
"stream",
".",
"push",
"(",
"null",
")",
";",
"}",
"}",
"}"
] |
Helper utility for _read functions. Pass your stream object and a getter that can be called concurrently and it will concurrently call your getter behind the scenes and manage the endstate of the stream.
|
[
"Helper",
"utility",
"for",
"_read",
"functions",
".",
"Pass",
"your",
"stream",
"object",
"and",
"a",
"getter",
"that",
"can",
"be",
"called",
"concurrently",
"and",
"it",
"will",
"concurrently",
"call",
"your",
"getter",
"behind",
"the",
"scenes",
"and",
"manage",
"the",
"endstate",
"of",
"the",
"stream",
"."
] |
8a37d89dd6e9fb0f6938e1c6ccf62349556c9375
|
https://github.com/mapbox/tilelive/blob/8a37d89dd6e9fb0f6938e1c6ccf62349556c9375/lib/stream-util.js#L167-L200
|
14,778
|
sc-forks/solidity-coverage
|
lib/preprocessor.js
|
blockWrap
|
function blockWrap(contract, expression) {
return contract.slice(0, expression.start) + '{' + contract.slice(expression.start, expression.end) + '}' + contract.slice(expression.end);
}
|
javascript
|
function blockWrap(contract, expression) {
return contract.slice(0, expression.start) + '{' + contract.slice(expression.start, expression.end) + '}' + contract.slice(expression.end);
}
|
[
"function",
"blockWrap",
"(",
"contract",
",",
"expression",
")",
"{",
"return",
"contract",
".",
"slice",
"(",
"0",
",",
"expression",
".",
"start",
")",
"+",
"'{'",
"+",
"contract",
".",
"slice",
"(",
"expression",
".",
"start",
",",
"expression",
".",
"end",
")",
"+",
"'}'",
"+",
"contract",
".",
"slice",
"(",
"expression",
".",
"end",
")",
";",
"}"
] |
Splices enclosing brackets into `contract` around `expression`;
@param {String} contract solidity source
@param {Object} node AST node to bracket
@return {String} contract
|
[
"Splices",
"enclosing",
"brackets",
"into",
"contract",
"around",
"expression",
";"
] |
7e18028812849ed4f2e0e7e78558a7b18dfda0e8
|
https://github.com/sc-forks/solidity-coverage/blob/7e18028812849ed4f2e0e7e78558a7b18dfda0e8/lib/preprocessor.js#L11-L13
|
14,779
|
sc-forks/solidity-coverage
|
lib/preprocessor.js
|
getModifierWhitespace
|
function getModifierWhitespace(contract, modifier){
const source = contract.slice(modifier.start, modifier.end);
const whitespace = source.match(crRegex) || [];
return whitespace.join('');
}
|
javascript
|
function getModifierWhitespace(contract, modifier){
const source = contract.slice(modifier.start, modifier.end);
const whitespace = source.match(crRegex) || [];
return whitespace.join('');
}
|
[
"function",
"getModifierWhitespace",
"(",
"contract",
",",
"modifier",
")",
"{",
"const",
"source",
"=",
"contract",
".",
"slice",
"(",
"modifier",
".",
"start",
",",
"modifier",
".",
"end",
")",
";",
"const",
"whitespace",
"=",
"source",
".",
"match",
"(",
"crRegex",
")",
"||",
"[",
"]",
";",
"return",
"whitespace",
".",
"join",
"(",
"''",
")",
";",
"}"
] |
Captures carriage returns at modifiers we'll remove. These need to be re-injected into the
source to keep line report alignments accurate.
@param {String} contract solidity source
@param {Object} modifier AST node
@return {String} whitespace around the modifier
|
[
"Captures",
"carriage",
"returns",
"at",
"modifiers",
"we",
"ll",
"remove",
".",
"These",
"need",
"to",
"be",
"re",
"-",
"injected",
"into",
"the",
"source",
"to",
"keep",
"line",
"report",
"alignments",
"accurate",
"."
] |
7e18028812849ed4f2e0e7e78558a7b18dfda0e8
|
https://github.com/sc-forks/solidity-coverage/blob/7e18028812849ed4f2e0e7e78558a7b18dfda0e8/lib/preprocessor.js#L23-L27
|
14,780
|
sc-forks/solidity-coverage
|
lib/instrumenter.js
|
createOrAppendInjectionPoint
|
function createOrAppendInjectionPoint(contract, key, value) {
if (contract.injectionPoints[key]) {
contract.injectionPoints[key].push(value);
} else {
contract.injectionPoints[key] = [value];
}
}
|
javascript
|
function createOrAppendInjectionPoint(contract, key, value) {
if (contract.injectionPoints[key]) {
contract.injectionPoints[key].push(value);
} else {
contract.injectionPoints[key] = [value];
}
}
|
[
"function",
"createOrAppendInjectionPoint",
"(",
"contract",
",",
"key",
",",
"value",
")",
"{",
"if",
"(",
"contract",
".",
"injectionPoints",
"[",
"key",
"]",
")",
"{",
"contract",
".",
"injectionPoints",
"[",
"key",
"]",
".",
"push",
"(",
"value",
")",
";",
"}",
"else",
"{",
"contract",
".",
"injectionPoints",
"[",
"key",
"]",
"=",
"[",
"value",
"]",
";",
"}",
"}"
] |
These functions work out where in an expression we can inject our instrumenation events.
|
[
"These",
"functions",
"work",
"out",
"where",
"in",
"an",
"expression",
"we",
"can",
"inject",
"our",
"instrumenation",
"events",
"."
] |
7e18028812849ed4f2e0e7e78558a7b18dfda0e8
|
https://github.com/sc-forks/solidity-coverage/blob/7e18028812849ed4f2e0e7e78558a7b18dfda0e8/lib/instrumenter.js#L6-L12
|
14,781
|
sitespeedio/browsertime
|
lib/core/seleniumRunner.js
|
timeout
|
async function timeout(promise, ms, errorMessage) {
let timer = null;
return Promise.race([
new Promise((resolve, reject) => {
timer = setTimeout(reject, ms, new BrowserError(errorMessage));
return timer;
}),
promise.then(value => {
clearTimeout(timer);
return value;
})
]);
}
|
javascript
|
async function timeout(promise, ms, errorMessage) {
let timer = null;
return Promise.race([
new Promise((resolve, reject) => {
timer = setTimeout(reject, ms, new BrowserError(errorMessage));
return timer;
}),
promise.then(value => {
clearTimeout(timer);
return value;
})
]);
}
|
[
"async",
"function",
"timeout",
"(",
"promise",
",",
"ms",
",",
"errorMessage",
")",
"{",
"let",
"timer",
"=",
"null",
";",
"return",
"Promise",
".",
"race",
"(",
"[",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"timer",
"=",
"setTimeout",
"(",
"reject",
",",
"ms",
",",
"new",
"BrowserError",
"(",
"errorMessage",
")",
")",
";",
"return",
"timer",
";",
"}",
")",
",",
"promise",
".",
"then",
"(",
"value",
"=>",
"{",
"clearTimeout",
"(",
"timer",
")",
";",
"return",
"value",
";",
"}",
")",
"]",
")",
";",
"}"
] |
Timeout a promise after ms. Use promise.race to compete
about the timeout and the promise.
@param {promise} promise - The promise to wait for
@param {int} ms - how long in ms to wait for the promise to fininsh
@param {string} errorMessage - the error message in the Error if we timeouts
|
[
"Timeout",
"a",
"promise",
"after",
"ms",
".",
"Use",
"promise",
".",
"race",
"to",
"compete",
"about",
"the",
"timeout",
"and",
"the",
"promise",
"."
] |
97cefe2a081e2a14d95a19e3a22ab68467988c68
|
https://github.com/sitespeedio/browsertime/blob/97cefe2a081e2a14d95a19e3a22ab68467988c68/lib/core/seleniumRunner.js#L35-L48
|
14,782
|
sitespeedio/browsertime
|
browserscripts/timings/rumSpeedIndex.js
|
function(el, url) {
if (url) {
var rect = GetElementViewportRect(el);
if (rect) {
rects.push({'url': url,
'area': rect.area,
'rect': rect});
}
}
}
|
javascript
|
function(el, url) {
if (url) {
var rect = GetElementViewportRect(el);
if (rect) {
rects.push({'url': url,
'area': rect.area,
'rect': rect});
}
}
}
|
[
"function",
"(",
"el",
",",
"url",
")",
"{",
"if",
"(",
"url",
")",
"{",
"var",
"rect",
"=",
"GetElementViewportRect",
"(",
"el",
")",
";",
"if",
"(",
"rect",
")",
"{",
"rects",
".",
"push",
"(",
"{",
"'url'",
":",
"url",
",",
"'area'",
":",
"rect",
".",
"area",
",",
"'rect'",
":",
"rect",
"}",
")",
";",
"}",
"}",
"}"
] |
Check a given element to see if it is visible
|
[
"Check",
"a",
"given",
"element",
"to",
"see",
"if",
"it",
"is",
"visible"
] |
97cefe2a081e2a14d95a19e3a22ab68467988c68
|
https://github.com/sitespeedio/browsertime/blob/97cefe2a081e2a14d95a19e3a22ab68467988c68/browserscripts/timings/rumSpeedIndex.js#L78-L87
|
|
14,783
|
sitespeedio/browsertime
|
browserscripts/timings/rumSpeedIndex.js
|
function() {
var timings = {};
var requests = win.performance.getEntriesByType("resource");
for (var i = 0; i < requests.length; i++)
timings[requests[i].name] = requests[i].responseEnd;
for (var j = 0; j < rects.length; j++) {
if (!('tm' in rects[j]))
rects[j].tm = timings[rects[j].url] !== undefined ? timings[rects[j].url] : 0;
}
}
|
javascript
|
function() {
var timings = {};
var requests = win.performance.getEntriesByType("resource");
for (var i = 0; i < requests.length; i++)
timings[requests[i].name] = requests[i].responseEnd;
for (var j = 0; j < rects.length; j++) {
if (!('tm' in rects[j]))
rects[j].tm = timings[rects[j].url] !== undefined ? timings[rects[j].url] : 0;
}
}
|
[
"function",
"(",
")",
"{",
"var",
"timings",
"=",
"{",
"}",
";",
"var",
"requests",
"=",
"win",
".",
"performance",
".",
"getEntriesByType",
"(",
"\"resource\"",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"requests",
".",
"length",
";",
"i",
"++",
")",
"timings",
"[",
"requests",
"[",
"i",
"]",
".",
"name",
"]",
"=",
"requests",
"[",
"i",
"]",
".",
"responseEnd",
";",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"rects",
".",
"length",
";",
"j",
"++",
")",
"{",
"if",
"(",
"!",
"(",
"'tm'",
"in",
"rects",
"[",
"j",
"]",
")",
")",
"rects",
"[",
"j",
"]",
".",
"tm",
"=",
"timings",
"[",
"rects",
"[",
"j",
"]",
".",
"url",
"]",
"!==",
"undefined",
"?",
"timings",
"[",
"rects",
"[",
"j",
"]",
".",
"url",
"]",
":",
"0",
";",
"}",
"}"
] |
Get the time at which each external resource loaded
|
[
"Get",
"the",
"time",
"at",
"which",
"each",
"external",
"resource",
"loaded"
] |
97cefe2a081e2a14d95a19e3a22ab68467988c68
|
https://github.com/sitespeedio/browsertime/blob/97cefe2a081e2a14d95a19e3a22ab68467988c68/browserscripts/timings/rumSpeedIndex.js#L128-L137
|
|
14,784
|
sitespeedio/browsertime
|
browserscripts/timings/rumSpeedIndex.js
|
function() {
var paints = {'0':0};
var total = 0;
for (var i = 0; i < rects.length; i++) {
var tm = firstPaint;
if ('tm' in rects[i] && rects[i].tm > firstPaint)
tm = rects[i].tm;
if (paints[tm] === undefined)
paints[tm] = 0;
paints[tm] += rects[i].area;
total += rects[i].area;
}
// Add a paint area for the page background (count 10% of the pixels not
// covered by existing paint rects.
var pixels = Math.max(doc.documentElement.clientWidth, win.innerWidth || 0) *
Math.max(doc.documentElement.clientHeight, win.innerHeight || 0);
if (pixels > 0 ) {
pixels = Math.max(pixels - total, 0) * pageBackgroundWeight;
if (paints[firstPaint] === undefined)
paints[firstPaint] = 0;
paints[firstPaint] += pixels;
total += pixels;
}
// Calculate the visual progress
if (total) {
for (var time in paints) {
if (paints.hasOwnProperty(time)) {
progress.push({'tm': time, 'area': paints[time]});
}
}
progress.sort(function(a,b){return a.tm - b.tm;});
var accumulated = 0;
for (var j = 0; j < progress.length; j++) {
accumulated += progress[j].area;
progress[j].progress = accumulated / total;
}
}
}
|
javascript
|
function() {
var paints = {'0':0};
var total = 0;
for (var i = 0; i < rects.length; i++) {
var tm = firstPaint;
if ('tm' in rects[i] && rects[i].tm > firstPaint)
tm = rects[i].tm;
if (paints[tm] === undefined)
paints[tm] = 0;
paints[tm] += rects[i].area;
total += rects[i].area;
}
// Add a paint area for the page background (count 10% of the pixels not
// covered by existing paint rects.
var pixels = Math.max(doc.documentElement.clientWidth, win.innerWidth || 0) *
Math.max(doc.documentElement.clientHeight, win.innerHeight || 0);
if (pixels > 0 ) {
pixels = Math.max(pixels - total, 0) * pageBackgroundWeight;
if (paints[firstPaint] === undefined)
paints[firstPaint] = 0;
paints[firstPaint] += pixels;
total += pixels;
}
// Calculate the visual progress
if (total) {
for (var time in paints) {
if (paints.hasOwnProperty(time)) {
progress.push({'tm': time, 'area': paints[time]});
}
}
progress.sort(function(a,b){return a.tm - b.tm;});
var accumulated = 0;
for (var j = 0; j < progress.length; j++) {
accumulated += progress[j].area;
progress[j].progress = accumulated / total;
}
}
}
|
[
"function",
"(",
")",
"{",
"var",
"paints",
"=",
"{",
"'0'",
":",
"0",
"}",
";",
"var",
"total",
"=",
"0",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"rects",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"tm",
"=",
"firstPaint",
";",
"if",
"(",
"'tm'",
"in",
"rects",
"[",
"i",
"]",
"&&",
"rects",
"[",
"i",
"]",
".",
"tm",
">",
"firstPaint",
")",
"tm",
"=",
"rects",
"[",
"i",
"]",
".",
"tm",
";",
"if",
"(",
"paints",
"[",
"tm",
"]",
"===",
"undefined",
")",
"paints",
"[",
"tm",
"]",
"=",
"0",
";",
"paints",
"[",
"tm",
"]",
"+=",
"rects",
"[",
"i",
"]",
".",
"area",
";",
"total",
"+=",
"rects",
"[",
"i",
"]",
".",
"area",
";",
"}",
"// Add a paint area for the page background (count 10% of the pixels not",
"// covered by existing paint rects.",
"var",
"pixels",
"=",
"Math",
".",
"max",
"(",
"doc",
".",
"documentElement",
".",
"clientWidth",
",",
"win",
".",
"innerWidth",
"||",
"0",
")",
"*",
"Math",
".",
"max",
"(",
"doc",
".",
"documentElement",
".",
"clientHeight",
",",
"win",
".",
"innerHeight",
"||",
"0",
")",
";",
"if",
"(",
"pixels",
">",
"0",
")",
"{",
"pixels",
"=",
"Math",
".",
"max",
"(",
"pixels",
"-",
"total",
",",
"0",
")",
"*",
"pageBackgroundWeight",
";",
"if",
"(",
"paints",
"[",
"firstPaint",
"]",
"===",
"undefined",
")",
"paints",
"[",
"firstPaint",
"]",
"=",
"0",
";",
"paints",
"[",
"firstPaint",
"]",
"+=",
"pixels",
";",
"total",
"+=",
"pixels",
";",
"}",
"// Calculate the visual progress",
"if",
"(",
"total",
")",
"{",
"for",
"(",
"var",
"time",
"in",
"paints",
")",
"{",
"if",
"(",
"paints",
".",
"hasOwnProperty",
"(",
"time",
")",
")",
"{",
"progress",
".",
"push",
"(",
"{",
"'tm'",
":",
"time",
",",
"'area'",
":",
"paints",
"[",
"time",
"]",
"}",
")",
";",
"}",
"}",
"progress",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"a",
".",
"tm",
"-",
"b",
".",
"tm",
";",
"}",
")",
";",
"var",
"accumulated",
"=",
"0",
";",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"progress",
".",
"length",
";",
"j",
"++",
")",
"{",
"accumulated",
"+=",
"progress",
"[",
"j",
"]",
".",
"area",
";",
"progress",
"[",
"j",
"]",
".",
"progress",
"=",
"accumulated",
"/",
"total",
";",
"}",
"}",
"}"
] |
Sort and group all of the paint rects by time and use them to calculate the visual progress
|
[
"Sort",
"and",
"group",
"all",
"of",
"the",
"paint",
"rects",
"by",
"time",
"and",
"use",
"them",
"to",
"calculate",
"the",
"visual",
"progress"
] |
97cefe2a081e2a14d95a19e3a22ab68467988c68
|
https://github.com/sitespeedio/browsertime/blob/97cefe2a081e2a14d95a19e3a22ab68467988c68/browserscripts/timings/rumSpeedIndex.js#L188-L225
|
|
14,785
|
sitespeedio/browsertime
|
browserscripts/timings/rumSpeedIndex.js
|
function() {
if (progress.length) {
SpeedIndex = 0;
var lastTime = 0;
var lastProgress = 0;
for (var i = 0; i < progress.length; i++) {
var elapsed = progress[i].tm - lastTime;
if (elapsed > 0 && lastProgress < 1)
SpeedIndex += (1 - lastProgress) * elapsed;
lastTime = progress[i].tm;
lastProgress = progress[i].progress;
}
} else {
SpeedIndex = firstPaint;
}
}
|
javascript
|
function() {
if (progress.length) {
SpeedIndex = 0;
var lastTime = 0;
var lastProgress = 0;
for (var i = 0; i < progress.length; i++) {
var elapsed = progress[i].tm - lastTime;
if (elapsed > 0 && lastProgress < 1)
SpeedIndex += (1 - lastProgress) * elapsed;
lastTime = progress[i].tm;
lastProgress = progress[i].progress;
}
} else {
SpeedIndex = firstPaint;
}
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"progress",
".",
"length",
")",
"{",
"SpeedIndex",
"=",
"0",
";",
"var",
"lastTime",
"=",
"0",
";",
"var",
"lastProgress",
"=",
"0",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"progress",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"elapsed",
"=",
"progress",
"[",
"i",
"]",
".",
"tm",
"-",
"lastTime",
";",
"if",
"(",
"elapsed",
">",
"0",
"&&",
"lastProgress",
"<",
"1",
")",
"SpeedIndex",
"+=",
"(",
"1",
"-",
"lastProgress",
")",
"*",
"elapsed",
";",
"lastTime",
"=",
"progress",
"[",
"i",
"]",
".",
"tm",
";",
"lastProgress",
"=",
"progress",
"[",
"i",
"]",
".",
"progress",
";",
"}",
"}",
"else",
"{",
"SpeedIndex",
"=",
"firstPaint",
";",
"}",
"}"
] |
Given the visual progress information, Calculate the speed index.
|
[
"Given",
"the",
"visual",
"progress",
"information",
"Calculate",
"the",
"speed",
"index",
"."
] |
97cefe2a081e2a14d95a19e3a22ab68467988c68
|
https://github.com/sitespeedio/browsertime/blob/97cefe2a081e2a14d95a19e3a22ab68467988c68/browserscripts/timings/rumSpeedIndex.js#L228-L243
|
|
14,786
|
sitespeedio/browsertime
|
browserscripts/pageinfo/visualElements.js
|
toArray
|
function toArray(arrayLike) {
if (arrayLike === undefined || arrayLike === null) {
return [];
}
if (Array.isArray(arrayLike)) {
return arrayLike;
}
return [arrayLike];
}
|
javascript
|
function toArray(arrayLike) {
if (arrayLike === undefined || arrayLike === null) {
return [];
}
if (Array.isArray(arrayLike)) {
return arrayLike;
}
return [arrayLike];
}
|
[
"function",
"toArray",
"(",
"arrayLike",
")",
"{",
"if",
"(",
"arrayLike",
"===",
"undefined",
"||",
"arrayLike",
"===",
"null",
")",
"{",
"return",
"[",
"]",
";",
"}",
"if",
"(",
"Array",
".",
"isArray",
"(",
"arrayLike",
")",
")",
"{",
"return",
"arrayLike",
";",
"}",
"return",
"[",
"arrayLike",
"]",
";",
"}"
] |
When we feed options from the CLI it can be a String or an Array with Strings. Make it easy to treat everything the same.
|
[
"When",
"we",
"feed",
"options",
"from",
"the",
"CLI",
"it",
"can",
"be",
"a",
"String",
"or",
"an",
"Array",
"with",
"Strings",
".",
"Make",
"it",
"easy",
"to",
"treat",
"everything",
"the",
"same",
"."
] |
97cefe2a081e2a14d95a19e3a22ab68467988c68
|
https://github.com/sitespeedio/browsertime/blob/97cefe2a081e2a14d95a19e3a22ab68467988c68/browserscripts/pageinfo/visualElements.js#L14-L22
|
14,787
|
sitespeedio/browsertime
|
lib/support/browserScript.js
|
scriptsFromDirectory
|
async function scriptsFromDirectory(dirpath) {
const dir = (await readdir(dirpath))
.map(name => toFullPath(name, dirpath))
.filter(await filters.onlyFiles)
.filter(filters.onlyWithExtension('.js'));
const result = {};
for (const filepath of dir) {
const name = path.basename(filepath, '.js');
const script = await readFile(filepath, 'utf8');
result[name] = script;
}
return result;
}
|
javascript
|
async function scriptsFromDirectory(dirpath) {
const dir = (await readdir(dirpath))
.map(name => toFullPath(name, dirpath))
.filter(await filters.onlyFiles)
.filter(filters.onlyWithExtension('.js'));
const result = {};
for (const filepath of dir) {
const name = path.basename(filepath, '.js');
const script = await readFile(filepath, 'utf8');
result[name] = script;
}
return result;
}
|
[
"async",
"function",
"scriptsFromDirectory",
"(",
"dirpath",
")",
"{",
"const",
"dir",
"=",
"(",
"await",
"readdir",
"(",
"dirpath",
")",
")",
".",
"map",
"(",
"name",
"=>",
"toFullPath",
"(",
"name",
",",
"dirpath",
")",
")",
".",
"filter",
"(",
"await",
"filters",
".",
"onlyFiles",
")",
".",
"filter",
"(",
"filters",
".",
"onlyWithExtension",
"(",
"'.js'",
")",
")",
";",
"const",
"result",
"=",
"{",
"}",
";",
"for",
"(",
"const",
"filepath",
"of",
"dir",
")",
"{",
"const",
"name",
"=",
"path",
".",
"basename",
"(",
"filepath",
",",
"'.js'",
")",
";",
"const",
"script",
"=",
"await",
"readFile",
"(",
"filepath",
",",
"'utf8'",
")",
";",
"result",
"[",
"name",
"]",
"=",
"script",
";",
"}",
"return",
"result",
";",
"}"
] |
Read all JavaScript files in a specific dir. Will use the filename
without .js as the name of the script.
@param {*} dirpath
|
[
"Read",
"all",
"JavaScript",
"files",
"in",
"a",
"specific",
"dir",
".",
"Will",
"use",
"the",
"filename",
"without",
".",
"js",
"as",
"the",
"name",
"of",
"the",
"script",
"."
] |
97cefe2a081e2a14d95a19e3a22ab68467988c68
|
https://github.com/sitespeedio/browsertime/blob/97cefe2a081e2a14d95a19e3a22ab68467988c68/lib/support/browserScript.js#L21-L33
|
14,788
|
sitespeedio/browsertime
|
lib/support/browserScript.js
|
findAndParseScripts
|
async function findAndParseScripts(root, category) {
async function scriptsFromDirectory(dirpath) {
const dir = (await readdir(dirpath))
.map(name => toFullPath(name, dirpath))
.filter(await filters.onlyFiles)
.filter(filters.onlyWithExtension('.js'));
const result = {};
for (const filepath of dir) {
const name = path.basename(filepath, '.js');
const script = await readFile(filepath, 'utf8');
result[name] = script;
}
return result;
}
async function parseDirectory(dirPath) {
const categoryName = path.basename(dirPath);
return scriptsFromDirectory(dirPath).then(scripts => {
const categories = {};
categories[categoryName] = scripts;
return categories;
});
}
return stat(root).then(stats => {
if (stats.isFile()) {
return readFile(root, 'utf8').then(content => {
const name = path.basename(root, '.js');
let scripts = {};
scripts[name] = content;
let categories = {};
categories[category] = scripts;
return categories;
});
} else {
return parseDirectory(root);
}
});
}
|
javascript
|
async function findAndParseScripts(root, category) {
async function scriptsFromDirectory(dirpath) {
const dir = (await readdir(dirpath))
.map(name => toFullPath(name, dirpath))
.filter(await filters.onlyFiles)
.filter(filters.onlyWithExtension('.js'));
const result = {};
for (const filepath of dir) {
const name = path.basename(filepath, '.js');
const script = await readFile(filepath, 'utf8');
result[name] = script;
}
return result;
}
async function parseDirectory(dirPath) {
const categoryName = path.basename(dirPath);
return scriptsFromDirectory(dirPath).then(scripts => {
const categories = {};
categories[categoryName] = scripts;
return categories;
});
}
return stat(root).then(stats => {
if (stats.isFile()) {
return readFile(root, 'utf8').then(content => {
const name = path.basename(root, '.js');
let scripts = {};
scripts[name] = content;
let categories = {};
categories[category] = scripts;
return categories;
});
} else {
return parseDirectory(root);
}
});
}
|
[
"async",
"function",
"findAndParseScripts",
"(",
"root",
",",
"category",
")",
"{",
"async",
"function",
"scriptsFromDirectory",
"(",
"dirpath",
")",
"{",
"const",
"dir",
"=",
"(",
"await",
"readdir",
"(",
"dirpath",
")",
")",
".",
"map",
"(",
"name",
"=>",
"toFullPath",
"(",
"name",
",",
"dirpath",
")",
")",
".",
"filter",
"(",
"await",
"filters",
".",
"onlyFiles",
")",
".",
"filter",
"(",
"filters",
".",
"onlyWithExtension",
"(",
"'.js'",
")",
")",
";",
"const",
"result",
"=",
"{",
"}",
";",
"for",
"(",
"const",
"filepath",
"of",
"dir",
")",
"{",
"const",
"name",
"=",
"path",
".",
"basename",
"(",
"filepath",
",",
"'.js'",
")",
";",
"const",
"script",
"=",
"await",
"readFile",
"(",
"filepath",
",",
"'utf8'",
")",
";",
"result",
"[",
"name",
"]",
"=",
"script",
";",
"}",
"return",
"result",
";",
"}",
"async",
"function",
"parseDirectory",
"(",
"dirPath",
")",
"{",
"const",
"categoryName",
"=",
"path",
".",
"basename",
"(",
"dirPath",
")",
";",
"return",
"scriptsFromDirectory",
"(",
"dirPath",
")",
".",
"then",
"(",
"scripts",
"=>",
"{",
"const",
"categories",
"=",
"{",
"}",
";",
"categories",
"[",
"categoryName",
"]",
"=",
"scripts",
";",
"return",
"categories",
";",
"}",
")",
";",
"}",
"return",
"stat",
"(",
"root",
")",
".",
"then",
"(",
"stats",
"=>",
"{",
"if",
"(",
"stats",
".",
"isFile",
"(",
")",
")",
"{",
"return",
"readFile",
"(",
"root",
",",
"'utf8'",
")",
".",
"then",
"(",
"content",
"=>",
"{",
"const",
"name",
"=",
"path",
".",
"basename",
"(",
"root",
",",
"'.js'",
")",
";",
"let",
"scripts",
"=",
"{",
"}",
";",
"scripts",
"[",
"name",
"]",
"=",
"content",
";",
"let",
"categories",
"=",
"{",
"}",
";",
"categories",
"[",
"category",
"]",
"=",
"scripts",
";",
"return",
"categories",
";",
"}",
")",
";",
"}",
"else",
"{",
"return",
"parseDirectory",
"(",
"root",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Parse a file or directory, and return an object representing that groups scripts by category.
Single js files will be put into the category 'custom', for directories the category name will
be taken from the directory name.
The resulting value looks like this:
<pre>
{
'category': {
'script': <contents of script.js>
}
}
</pre>
@param {string} root a path to a js file, alternatively a directory containing js files.
@param {string} category a category to apply if a file is passed
@returns {Promise.<Object>}
|
[
"Parse",
"a",
"file",
"or",
"directory",
"and",
"return",
"an",
"object",
"representing",
"that",
"groups",
"scripts",
"by",
"category",
".",
"Single",
"js",
"files",
"will",
"be",
"put",
"into",
"the",
"category",
"custom",
"for",
"directories",
"the",
"category",
"name",
"will",
"be",
"taken",
"from",
"the",
"directory",
"name",
"."
] |
97cefe2a081e2a14d95a19e3a22ab68467988c68
|
https://github.com/sitespeedio/browsertime/blob/97cefe2a081e2a14d95a19e3a22ab68467988c68/lib/support/browserScript.js#L66-L108
|
14,789
|
nagix/chartjs-plugin-streaming
|
src/scales/scale.realtime.js
|
toTimestamp
|
function toTimestamp(scale, input) {
var adapter = scale._adapter || defaultAdapter;
var options = scale.options.time;
var parser = options.parser;
var format = parser || options.format;
var value = input;
if (typeof parser === 'function') {
value = parser(value);
}
// Only parse if its not a timestamp already
if (typeof value !== 'number' && !(value instanceof Number) || !isFinite(value)) {
value = typeof format === 'string'
? adapter.parse(value, format)
: adapter.parse(value);
}
if (value !== null) {
return +value;
}
// Labels are in an incompatible format and no `parser` has been provided.
// The user might still use the deprecated `format` option for parsing.
if (!parser && typeof format === 'function') {
value = format(input);
// `format` could return something else than a timestamp, if so, parse it
if (typeof value !== 'number' && !(value instanceof Number) || !isFinite(value)) {
value = adapter.parse(value);
}
}
return value;
}
|
javascript
|
function toTimestamp(scale, input) {
var adapter = scale._adapter || defaultAdapter;
var options = scale.options.time;
var parser = options.parser;
var format = parser || options.format;
var value = input;
if (typeof parser === 'function') {
value = parser(value);
}
// Only parse if its not a timestamp already
if (typeof value !== 'number' && !(value instanceof Number) || !isFinite(value)) {
value = typeof format === 'string'
? adapter.parse(value, format)
: adapter.parse(value);
}
if (value !== null) {
return +value;
}
// Labels are in an incompatible format and no `parser` has been provided.
// The user might still use the deprecated `format` option for parsing.
if (!parser && typeof format === 'function') {
value = format(input);
// `format` could return something else than a timestamp, if so, parse it
if (typeof value !== 'number' && !(value instanceof Number) || !isFinite(value)) {
value = adapter.parse(value);
}
}
return value;
}
|
[
"function",
"toTimestamp",
"(",
"scale",
",",
"input",
")",
"{",
"var",
"adapter",
"=",
"scale",
".",
"_adapter",
"||",
"defaultAdapter",
";",
"var",
"options",
"=",
"scale",
".",
"options",
".",
"time",
";",
"var",
"parser",
"=",
"options",
".",
"parser",
";",
"var",
"format",
"=",
"parser",
"||",
"options",
".",
"format",
";",
"var",
"value",
"=",
"input",
";",
"if",
"(",
"typeof",
"parser",
"===",
"'function'",
")",
"{",
"value",
"=",
"parser",
"(",
"value",
")",
";",
"}",
"// Only parse if its not a timestamp already",
"if",
"(",
"typeof",
"value",
"!==",
"'number'",
"&&",
"!",
"(",
"value",
"instanceof",
"Number",
")",
"||",
"!",
"isFinite",
"(",
"value",
")",
")",
"{",
"value",
"=",
"typeof",
"format",
"===",
"'string'",
"?",
"adapter",
".",
"parse",
"(",
"value",
",",
"format",
")",
":",
"adapter",
".",
"parse",
"(",
"value",
")",
";",
"}",
"if",
"(",
"value",
"!==",
"null",
")",
"{",
"return",
"+",
"value",
";",
"}",
"// Labels are in an incompatible format and no `parser` has been provided.",
"// The user might still use the deprecated `format` option for parsing.",
"if",
"(",
"!",
"parser",
"&&",
"typeof",
"format",
"===",
"'function'",
")",
"{",
"value",
"=",
"format",
"(",
"input",
")",
";",
"// `format` could return something else than a timestamp, if so, parse it",
"if",
"(",
"typeof",
"value",
"!==",
"'number'",
"&&",
"!",
"(",
"value",
"instanceof",
"Number",
")",
"||",
"!",
"isFinite",
"(",
"value",
")",
")",
"{",
"value",
"=",
"adapter",
".",
"parse",
"(",
"value",
")",
";",
"}",
"}",
"return",
"value",
";",
"}"
] |
Ported from Chart.js 2.8.0-rc.1 35273ee. Modified for Chart.js 2.7.x backward compatibility.
|
[
"Ported",
"from",
"Chart",
".",
"js",
"2",
".",
"8",
".",
"0",
"-",
"rc",
".",
"1",
"35273ee",
".",
"Modified",
"for",
"Chart",
".",
"js",
"2",
".",
"7",
".",
"x",
"backward",
"compatibility",
"."
] |
b53ec168f2d0729014651d694cc041a6a7d4ff26
|
https://github.com/nagix/chartjs-plugin-streaming/blob/b53ec168f2d0729014651d694cc041a6a7d4ff26/src/scales/scale.realtime.js#L34-L68
|
14,790
|
nagix/chartjs-plugin-streaming
|
src/plugins/plugin.streaming.js
|
update
|
function update(config) {
var me = this;
var preservation = config && config.preservation;
var tooltip, lastActive, tooltipLastActive, lastMouseEvent;
if (preservation) {
tooltip = me.tooltip;
lastActive = me.lastActive;
tooltipLastActive = tooltip._lastActive;
me._bufferedRender = true;
}
Chart.prototype.update.apply(me, arguments);
if (preservation) {
me._bufferedRender = false;
me._bufferedRequest = null;
me.lastActive = lastActive;
tooltip._lastActive = tooltipLastActive;
if (me.animating) {
// If the chart is animating, keep it until the duration is over
Chart.animationService.animations.forEach(function(animation) {
if (animation.chart === me) {
me.render({
duration: (animation.numSteps - animation.currentStep) * 16.66
});
}
});
} else {
// If the chart is not animating, make sure that all elements are at the final positions
me.data.datasets.forEach(function(dataset, datasetIndex) {
me.getDatasetMeta(datasetIndex).controller.transition(1);
});
}
if (tooltip._active) {
tooltip.update(true);
}
lastMouseEvent = me.streaming.lastMouseEvent;
if (lastMouseEvent) {
me.eventHandler(lastMouseEvent);
}
}
}
|
javascript
|
function update(config) {
var me = this;
var preservation = config && config.preservation;
var tooltip, lastActive, tooltipLastActive, lastMouseEvent;
if (preservation) {
tooltip = me.tooltip;
lastActive = me.lastActive;
tooltipLastActive = tooltip._lastActive;
me._bufferedRender = true;
}
Chart.prototype.update.apply(me, arguments);
if (preservation) {
me._bufferedRender = false;
me._bufferedRequest = null;
me.lastActive = lastActive;
tooltip._lastActive = tooltipLastActive;
if (me.animating) {
// If the chart is animating, keep it until the duration is over
Chart.animationService.animations.forEach(function(animation) {
if (animation.chart === me) {
me.render({
duration: (animation.numSteps - animation.currentStep) * 16.66
});
}
});
} else {
// If the chart is not animating, make sure that all elements are at the final positions
me.data.datasets.forEach(function(dataset, datasetIndex) {
me.getDatasetMeta(datasetIndex).controller.transition(1);
});
}
if (tooltip._active) {
tooltip.update(true);
}
lastMouseEvent = me.streaming.lastMouseEvent;
if (lastMouseEvent) {
me.eventHandler(lastMouseEvent);
}
}
}
|
[
"function",
"update",
"(",
"config",
")",
"{",
"var",
"me",
"=",
"this",
";",
"var",
"preservation",
"=",
"config",
"&&",
"config",
".",
"preservation",
";",
"var",
"tooltip",
",",
"lastActive",
",",
"tooltipLastActive",
",",
"lastMouseEvent",
";",
"if",
"(",
"preservation",
")",
"{",
"tooltip",
"=",
"me",
".",
"tooltip",
";",
"lastActive",
"=",
"me",
".",
"lastActive",
";",
"tooltipLastActive",
"=",
"tooltip",
".",
"_lastActive",
";",
"me",
".",
"_bufferedRender",
"=",
"true",
";",
"}",
"Chart",
".",
"prototype",
".",
"update",
".",
"apply",
"(",
"me",
",",
"arguments",
")",
";",
"if",
"(",
"preservation",
")",
"{",
"me",
".",
"_bufferedRender",
"=",
"false",
";",
"me",
".",
"_bufferedRequest",
"=",
"null",
";",
"me",
".",
"lastActive",
"=",
"lastActive",
";",
"tooltip",
".",
"_lastActive",
"=",
"tooltipLastActive",
";",
"if",
"(",
"me",
".",
"animating",
")",
"{",
"// If the chart is animating, keep it until the duration is over",
"Chart",
".",
"animationService",
".",
"animations",
".",
"forEach",
"(",
"function",
"(",
"animation",
")",
"{",
"if",
"(",
"animation",
".",
"chart",
"===",
"me",
")",
"{",
"me",
".",
"render",
"(",
"{",
"duration",
":",
"(",
"animation",
".",
"numSteps",
"-",
"animation",
".",
"currentStep",
")",
"*",
"16.66",
"}",
")",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"// If the chart is not animating, make sure that all elements are at the final positions",
"me",
".",
"data",
".",
"datasets",
".",
"forEach",
"(",
"function",
"(",
"dataset",
",",
"datasetIndex",
")",
"{",
"me",
".",
"getDatasetMeta",
"(",
"datasetIndex",
")",
".",
"controller",
".",
"transition",
"(",
"1",
")",
";",
"}",
")",
";",
"}",
"if",
"(",
"tooltip",
".",
"_active",
")",
"{",
"tooltip",
".",
"update",
"(",
"true",
")",
";",
"}",
"lastMouseEvent",
"=",
"me",
".",
"streaming",
".",
"lastMouseEvent",
";",
"if",
"(",
"lastMouseEvent",
")",
"{",
"me",
".",
"eventHandler",
"(",
"lastMouseEvent",
")",
";",
"}",
"}",
"}"
] |
Update the chart keeping the current animation but suppressing a new one
@param {object} config - animation options
|
[
"Update",
"the",
"chart",
"keeping",
"the",
"current",
"animation",
"but",
"suppressing",
"a",
"new",
"one"
] |
b53ec168f2d0729014651d694cc041a6a7d4ff26
|
https://github.com/nagix/chartjs-plugin-streaming/blob/b53ec168f2d0729014651d694cc041a6a7d4ff26/src/plugins/plugin.streaming.js#L24-L69
|
14,791
|
nagix/chartjs-plugin-streaming
|
src/plugins/plugin.streaming.js
|
drawChart
|
function drawChart(chart) {
var streaming = chart.streaming;
var frameRate = chart.options.plugins.streaming.frameRate;
var frameDuration = 1000 / (Math.max(frameRate, 0) || 30);
var next = streaming.lastDrawn + frameDuration || 0;
var now = Date.now();
var lastMouseEvent = streaming.lastMouseEvent;
if (next <= now) {
// Draw only when animation is inactive
if (!chart.animating && !chart.tooltip._start) {
chart.draw();
}
if (lastMouseEvent) {
chart.eventHandler(lastMouseEvent);
}
streaming.lastDrawn = (next + frameDuration > now) ? next : now;
}
}
|
javascript
|
function drawChart(chart) {
var streaming = chart.streaming;
var frameRate = chart.options.plugins.streaming.frameRate;
var frameDuration = 1000 / (Math.max(frameRate, 0) || 30);
var next = streaming.lastDrawn + frameDuration || 0;
var now = Date.now();
var lastMouseEvent = streaming.lastMouseEvent;
if (next <= now) {
// Draw only when animation is inactive
if (!chart.animating && !chart.tooltip._start) {
chart.draw();
}
if (lastMouseEvent) {
chart.eventHandler(lastMouseEvent);
}
streaming.lastDrawn = (next + frameDuration > now) ? next : now;
}
}
|
[
"function",
"drawChart",
"(",
"chart",
")",
"{",
"var",
"streaming",
"=",
"chart",
".",
"streaming",
";",
"var",
"frameRate",
"=",
"chart",
".",
"options",
".",
"plugins",
".",
"streaming",
".",
"frameRate",
";",
"var",
"frameDuration",
"=",
"1000",
"/",
"(",
"Math",
".",
"max",
"(",
"frameRate",
",",
"0",
")",
"||",
"30",
")",
";",
"var",
"next",
"=",
"streaming",
".",
"lastDrawn",
"+",
"frameDuration",
"||",
"0",
";",
"var",
"now",
"=",
"Date",
".",
"now",
"(",
")",
";",
"var",
"lastMouseEvent",
"=",
"streaming",
".",
"lastMouseEvent",
";",
"if",
"(",
"next",
"<=",
"now",
")",
"{",
"// Draw only when animation is inactive",
"if",
"(",
"!",
"chart",
".",
"animating",
"&&",
"!",
"chart",
".",
"tooltip",
".",
"_start",
")",
"{",
"chart",
".",
"draw",
"(",
")",
";",
"}",
"if",
"(",
"lastMouseEvent",
")",
"{",
"chart",
".",
"eventHandler",
"(",
"lastMouseEvent",
")",
";",
"}",
"streaming",
".",
"lastDrawn",
"=",
"(",
"next",
"+",
"frameDuration",
">",
"now",
")",
"?",
"next",
":",
"now",
";",
"}",
"}"
] |
Draw chart at frameRate
|
[
"Draw",
"chart",
"at",
"frameRate"
] |
b53ec168f2d0729014651d694cc041a6a7d4ff26
|
https://github.com/nagix/chartjs-plugin-streaming/blob/b53ec168f2d0729014651d694cc041a6a7d4ff26/src/plugins/plugin.streaming.js#L72-L90
|
14,792
|
DubFriend/jquery.repeater
|
jquery.repeater.js
|
function (minimumInterval, callback) {
var timeout = null;
return function () {
var that = this, args = arguments;
if(timeout === null) {
timeout = setTimeout(function () {
timeout = null;
}, minimumInterval);
callback.apply(that, args);
}
};
}
|
javascript
|
function (minimumInterval, callback) {
var timeout = null;
return function () {
var that = this, args = arguments;
if(timeout === null) {
timeout = setTimeout(function () {
timeout = null;
}, minimumInterval);
callback.apply(that, args);
}
};
}
|
[
"function",
"(",
"minimumInterval",
",",
"callback",
")",
"{",
"var",
"timeout",
"=",
"null",
";",
"return",
"function",
"(",
")",
"{",
"var",
"that",
"=",
"this",
",",
"args",
"=",
"arguments",
";",
"if",
"(",
"timeout",
"===",
"null",
")",
"{",
"timeout",
"=",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"timeout",
"=",
"null",
";",
"}",
",",
"minimumInterval",
")",
";",
"callback",
".",
"apply",
"(",
"that",
",",
"args",
")",
";",
"}",
"}",
";",
"}"
] |
execute callback immediately and at most one time on the minimumInterval, ignore block attempts
|
[
"execute",
"callback",
"immediately",
"and",
"at",
"most",
"one",
"time",
"on",
"the",
"minimumInterval",
"ignore",
"block",
"attempts"
] |
1c3ba62b6a6801f0555cd58ba23706a6b65a4c1e
|
https://github.com/DubFriend/jquery.repeater/blob/1c3ba62b6a6801f0555cd58ba23706a6b65a4c1e/jquery.repeater.js#L123-L134
|
|
14,793
|
biggora/caminte
|
lib/validatable.js
|
blank
|
function blank(v) {
if (typeof v === 'undefined') return true;
if (v instanceof Array && v.length === 0) return true;
if (v === null) return true;
if (typeof v === 'string' && v === '') return true;
return false;
}
|
javascript
|
function blank(v) {
if (typeof v === 'undefined') return true;
if (v instanceof Array && v.length === 0) return true;
if (v === null) return true;
if (typeof v === 'string' && v === '') return true;
return false;
}
|
[
"function",
"blank",
"(",
"v",
")",
"{",
"if",
"(",
"typeof",
"v",
"===",
"'undefined'",
")",
"return",
"true",
";",
"if",
"(",
"v",
"instanceof",
"Array",
"&&",
"v",
".",
"length",
"===",
"0",
")",
"return",
"true",
";",
"if",
"(",
"v",
"===",
"null",
")",
"return",
"true",
";",
"if",
"(",
"typeof",
"v",
"===",
"'string'",
"&&",
"v",
"===",
"''",
")",
"return",
"true",
";",
"return",
"false",
";",
"}"
] |
Return true when v is undefined, blank array, null or empty string
otherwise returns false
@param {Mix} v
@returns {Boolean} whether `v` blank or not
|
[
"Return",
"true",
"when",
"v",
"is",
"undefined",
"blank",
"array",
"null",
"or",
"empty",
"string",
"otherwise",
"returns",
"false"
] |
1d75b68052416d9819e2275479ef51b88e96d3e6
|
https://github.com/biggora/caminte/blob/1d75b68052416d9819e2275479ef51b88e96d3e6/lib/validatable.js#L546-L552
|
14,794
|
biggora/caminte
|
lib/schema.js
|
Schema
|
function Schema(name, settings) {
var schema = this;
name = name ? name.toLowerCase() : '';
switch (name) {
case 'sqlite':
name = 'sqlite3';
break;
case 'mysqldb':
case 'mariadb':
name = 'mysql';
break;
case 'mongo':
name = 'mongodb';
break;
case 'couchdb':
case 'couch':
name = 'nano';
break;
case 'rethinkdb':
case 'rethink':
name = 'rethinkdb';
break;
}
// just save everything we get
schema.name = name;
schema.settings = settings;
// Disconnected by default
schema.connected = false;
// create blank models pool
schema.models = {};
schema.definitions = {};
// define schema types
schema.Text = function Text() {
};
schema.JSON = schema.Json = function JSON() {
};
schema.Float = function Float() {
};
schema.Real = schema.Double = function Real() {
};
schema.Int = schema.Integer = function Integer() {
};
schema.UUID = schema.Uuid = function UUID() {
};
schema.TimeUUID = schema.TimeUuid = function TimeUUID() {
};
schema.CounterColumn = function CounterColumn() {
};
schema.Blob = schema.Bytes = function Blob() {
};
schema.Date = schema.Timestamp = Date;
schema.Boolean = schema.Tinyint = Boolean;
schema.Number = Number;
schema.String = schema.Varchar = String;
// and initialize schema using adapter
// this is only one initialization entry point of adapter
// this module should define `adapter` member of `this` (schema)
var adapter;
if (typeof name === 'object') {
adapter = name;
schema.name = adapter.name;
} else if (name.match(/^\//)) {
// try absolute path
adapter = require(name);
} else if (existsSync(__dirname + '/adapters/' + name + '.js')) {
// try built-in adapter
adapter = require('./adapters/' + name);
} else {
try {
adapter = require('caminte-' + name);
} catch (e) {
throw new Error('Adapter ' + name + ' is not defined, try\n npm install ' + name);
}
}
adapter.initialize(schema, function () {
// we have an adaper now?
if (!schema.adapter) {
throw new Error('Adapter is not defined correctly: it should create `adapter` member of schema');
}
schema.adapter.log = function (query, start) {
schema.log(query, start);
};
schema.adapter.logger = function (query) {
'use strict';
var t1 = Date.now();
var log = schema.log;
return function (q) {
log(q || query, t1);
};
};
var res = getState(schema);
if (util.isError(res)) {
schema.emit('error', res);
} else {
schema.connected = true;
schema.emit('connected');
}
}.bind(schema));
}
|
javascript
|
function Schema(name, settings) {
var schema = this;
name = name ? name.toLowerCase() : '';
switch (name) {
case 'sqlite':
name = 'sqlite3';
break;
case 'mysqldb':
case 'mariadb':
name = 'mysql';
break;
case 'mongo':
name = 'mongodb';
break;
case 'couchdb':
case 'couch':
name = 'nano';
break;
case 'rethinkdb':
case 'rethink':
name = 'rethinkdb';
break;
}
// just save everything we get
schema.name = name;
schema.settings = settings;
// Disconnected by default
schema.connected = false;
// create blank models pool
schema.models = {};
schema.definitions = {};
// define schema types
schema.Text = function Text() {
};
schema.JSON = schema.Json = function JSON() {
};
schema.Float = function Float() {
};
schema.Real = schema.Double = function Real() {
};
schema.Int = schema.Integer = function Integer() {
};
schema.UUID = schema.Uuid = function UUID() {
};
schema.TimeUUID = schema.TimeUuid = function TimeUUID() {
};
schema.CounterColumn = function CounterColumn() {
};
schema.Blob = schema.Bytes = function Blob() {
};
schema.Date = schema.Timestamp = Date;
schema.Boolean = schema.Tinyint = Boolean;
schema.Number = Number;
schema.String = schema.Varchar = String;
// and initialize schema using adapter
// this is only one initialization entry point of adapter
// this module should define `adapter` member of `this` (schema)
var adapter;
if (typeof name === 'object') {
adapter = name;
schema.name = adapter.name;
} else if (name.match(/^\//)) {
// try absolute path
adapter = require(name);
} else if (existsSync(__dirname + '/adapters/' + name + '.js')) {
// try built-in adapter
adapter = require('./adapters/' + name);
} else {
try {
adapter = require('caminte-' + name);
} catch (e) {
throw new Error('Adapter ' + name + ' is not defined, try\n npm install ' + name);
}
}
adapter.initialize(schema, function () {
// we have an adaper now?
if (!schema.adapter) {
throw new Error('Adapter is not defined correctly: it should create `adapter` member of schema');
}
schema.adapter.log = function (query, start) {
schema.log(query, start);
};
schema.adapter.logger = function (query) {
'use strict';
var t1 = Date.now();
var log = schema.log;
return function (q) {
log(q || query, t1);
};
};
var res = getState(schema);
if (util.isError(res)) {
schema.emit('error', res);
} else {
schema.connected = true;
schema.emit('connected');
}
}.bind(schema));
}
|
[
"function",
"Schema",
"(",
"name",
",",
"settings",
")",
"{",
"var",
"schema",
"=",
"this",
";",
"name",
"=",
"name",
"?",
"name",
".",
"toLowerCase",
"(",
")",
":",
"''",
";",
"switch",
"(",
"name",
")",
"{",
"case",
"'sqlite'",
":",
"name",
"=",
"'sqlite3'",
";",
"break",
";",
"case",
"'mysqldb'",
":",
"case",
"'mariadb'",
":",
"name",
"=",
"'mysql'",
";",
"break",
";",
"case",
"'mongo'",
":",
"name",
"=",
"'mongodb'",
";",
"break",
";",
"case",
"'couchdb'",
":",
"case",
"'couch'",
":",
"name",
"=",
"'nano'",
";",
"break",
";",
"case",
"'rethinkdb'",
":",
"case",
"'rethink'",
":",
"name",
"=",
"'rethinkdb'",
";",
"break",
";",
"}",
"// just save everything we get",
"schema",
".",
"name",
"=",
"name",
";",
"schema",
".",
"settings",
"=",
"settings",
";",
"// Disconnected by default",
"schema",
".",
"connected",
"=",
"false",
";",
"// create blank models pool",
"schema",
".",
"models",
"=",
"{",
"}",
";",
"schema",
".",
"definitions",
"=",
"{",
"}",
";",
"// define schema types",
"schema",
".",
"Text",
"=",
"function",
"Text",
"(",
")",
"{",
"}",
";",
"schema",
".",
"JSON",
"=",
"schema",
".",
"Json",
"=",
"function",
"JSON",
"(",
")",
"{",
"}",
";",
"schema",
".",
"Float",
"=",
"function",
"Float",
"(",
")",
"{",
"}",
";",
"schema",
".",
"Real",
"=",
"schema",
".",
"Double",
"=",
"function",
"Real",
"(",
")",
"{",
"}",
";",
"schema",
".",
"Int",
"=",
"schema",
".",
"Integer",
"=",
"function",
"Integer",
"(",
")",
"{",
"}",
";",
"schema",
".",
"UUID",
"=",
"schema",
".",
"Uuid",
"=",
"function",
"UUID",
"(",
")",
"{",
"}",
";",
"schema",
".",
"TimeUUID",
"=",
"schema",
".",
"TimeUuid",
"=",
"function",
"TimeUUID",
"(",
")",
"{",
"}",
";",
"schema",
".",
"CounterColumn",
"=",
"function",
"CounterColumn",
"(",
")",
"{",
"}",
";",
"schema",
".",
"Blob",
"=",
"schema",
".",
"Bytes",
"=",
"function",
"Blob",
"(",
")",
"{",
"}",
";",
"schema",
".",
"Date",
"=",
"schema",
".",
"Timestamp",
"=",
"Date",
";",
"schema",
".",
"Boolean",
"=",
"schema",
".",
"Tinyint",
"=",
"Boolean",
";",
"schema",
".",
"Number",
"=",
"Number",
";",
"schema",
".",
"String",
"=",
"schema",
".",
"Varchar",
"=",
"String",
";",
"// and initialize schema using adapter",
"// this is only one initialization entry point of adapter",
"// this module should define `adapter` member of `this` (schema)",
"var",
"adapter",
";",
"if",
"(",
"typeof",
"name",
"===",
"'object'",
")",
"{",
"adapter",
"=",
"name",
";",
"schema",
".",
"name",
"=",
"adapter",
".",
"name",
";",
"}",
"else",
"if",
"(",
"name",
".",
"match",
"(",
"/",
"^\\/",
"/",
")",
")",
"{",
"// try absolute path",
"adapter",
"=",
"require",
"(",
"name",
")",
";",
"}",
"else",
"if",
"(",
"existsSync",
"(",
"__dirname",
"+",
"'/adapters/'",
"+",
"name",
"+",
"'.js'",
")",
")",
"{",
"// try built-in adapter",
"adapter",
"=",
"require",
"(",
"'./adapters/'",
"+",
"name",
")",
";",
"}",
"else",
"{",
"try",
"{",
"adapter",
"=",
"require",
"(",
"'caminte-'",
"+",
"name",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Adapter '",
"+",
"name",
"+",
"' is not defined, try\\n npm install '",
"+",
"name",
")",
";",
"}",
"}",
"adapter",
".",
"initialize",
"(",
"schema",
",",
"function",
"(",
")",
"{",
"// we have an adaper now?",
"if",
"(",
"!",
"schema",
".",
"adapter",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Adapter is not defined correctly: it should create `adapter` member of schema'",
")",
";",
"}",
"schema",
".",
"adapter",
".",
"log",
"=",
"function",
"(",
"query",
",",
"start",
")",
"{",
"schema",
".",
"log",
"(",
"query",
",",
"start",
")",
";",
"}",
";",
"schema",
".",
"adapter",
".",
"logger",
"=",
"function",
"(",
"query",
")",
"{",
"'use strict'",
";",
"var",
"t1",
"=",
"Date",
".",
"now",
"(",
")",
";",
"var",
"log",
"=",
"schema",
".",
"log",
";",
"return",
"function",
"(",
"q",
")",
"{",
"log",
"(",
"q",
"||",
"query",
",",
"t1",
")",
";",
"}",
";",
"}",
";",
"var",
"res",
"=",
"getState",
"(",
"schema",
")",
";",
"if",
"(",
"util",
".",
"isError",
"(",
"res",
")",
")",
"{",
"schema",
".",
"emit",
"(",
"'error'",
",",
"res",
")",
";",
"}",
"else",
"{",
"schema",
".",
"connected",
"=",
"true",
";",
"schema",
".",
"emit",
"(",
"'connected'",
")",
";",
"}",
"}",
".",
"bind",
"(",
"schema",
")",
")",
";",
"}"
] |
Schema - adapter-specific classes factory.
All classes in single schema shares same adapter type and
one database connection
@param name - type of schema adapter (mysql, mongoose, sequelize, redis)
@param settings - any database-specific settings which we need to
establish connection (of course it depends on specific adapter)
- host
- port
- username
- password
- database
- debug {Boolean} = false
@example Schema creation, waiting for connection callback
```
var schema = new Schema('mysql', { database: 'myapp_test' });
schema.define(...);
schema.on('connected', function () {
// work with database
});
```
|
[
"Schema",
"-",
"adapter",
"-",
"specific",
"classes",
"factory",
"."
] |
1d75b68052416d9819e2275479ef51b88e96d3e6
|
https://github.com/biggora/caminte/blob/1d75b68052416d9819e2275479ef51b88e96d3e6/lib/schema.js#L50-L158
|
14,795
|
gruntjs/grunt-contrib-watch
|
tasks/watch.js
|
function(time) {
grunt.log.writeln(String(
'Completed in ' +
time.toFixed(3) +
's at ' +
(new Date()).toString()
).cyan + ' - ' + waiting);
}
|
javascript
|
function(time) {
grunt.log.writeln(String(
'Completed in ' +
time.toFixed(3) +
's at ' +
(new Date()).toString()
).cyan + ' - ' + waiting);
}
|
[
"function",
"(",
"time",
")",
"{",
"grunt",
".",
"log",
".",
"writeln",
"(",
"String",
"(",
"'Completed in '",
"+",
"time",
".",
"toFixed",
"(",
"3",
")",
"+",
"'s at '",
"+",
"(",
"new",
"Date",
"(",
")",
")",
".",
"toString",
"(",
")",
")",
".",
"cyan",
"+",
"' - '",
"+",
"waiting",
")",
";",
"}"
] |
Default date format logged
|
[
"Default",
"date",
"format",
"logged"
] |
3b7ddf4453787979a22b83949b86106534c78d26
|
https://github.com/gruntjs/grunt-contrib-watch/blob/3b7ddf4453787979a22b83949b86106534c78d26/tasks/watch.js#L23-L30
|
|
14,796
|
gruntjs/grunt-contrib-watch
|
tasks/lib/taskrun.js
|
TaskRun
|
function TaskRun(target) {
this.name = target.name || 0;
this.files = target.files || [];
this._getConfig = target._getConfig;
this.options = target.options;
this.startedAt = false;
this.spawned = null;
this.changedFiles = Object.create(null);
this.spawnTaskFailure = false;
this.livereloadOnError = true;
if (typeof this.options.livereloadOnError !== 'undefined') {
this.livereloadOnError = this.options.livereloadOnError;
}
}
|
javascript
|
function TaskRun(target) {
this.name = target.name || 0;
this.files = target.files || [];
this._getConfig = target._getConfig;
this.options = target.options;
this.startedAt = false;
this.spawned = null;
this.changedFiles = Object.create(null);
this.spawnTaskFailure = false;
this.livereloadOnError = true;
if (typeof this.options.livereloadOnError !== 'undefined') {
this.livereloadOnError = this.options.livereloadOnError;
}
}
|
[
"function",
"TaskRun",
"(",
"target",
")",
"{",
"this",
".",
"name",
"=",
"target",
".",
"name",
"||",
"0",
";",
"this",
".",
"files",
"=",
"target",
".",
"files",
"||",
"[",
"]",
";",
"this",
".",
"_getConfig",
"=",
"target",
".",
"_getConfig",
";",
"this",
".",
"options",
"=",
"target",
".",
"options",
";",
"this",
".",
"startedAt",
"=",
"false",
";",
"this",
".",
"spawned",
"=",
"null",
";",
"this",
".",
"changedFiles",
"=",
"Object",
".",
"create",
"(",
"null",
")",
";",
"this",
".",
"spawnTaskFailure",
"=",
"false",
";",
"this",
".",
"livereloadOnError",
"=",
"true",
";",
"if",
"(",
"typeof",
"this",
".",
"options",
".",
"livereloadOnError",
"!==",
"'undefined'",
")",
"{",
"this",
".",
"livereloadOnError",
"=",
"this",
".",
"options",
".",
"livereloadOnError",
";",
"}",
"}"
] |
Create a TaskRun on a target
|
[
"Create",
"a",
"TaskRun",
"on",
"a",
"target"
] |
3b7ddf4453787979a22b83949b86106534c78d26
|
https://github.com/gruntjs/grunt-contrib-watch/blob/3b7ddf4453787979a22b83949b86106534c78d26/tasks/lib/taskrun.js#L14-L27
|
14,797
|
bhushankumarl/amazon-mws
|
lib/AmazonMwsResource.js
|
AmazonMwsResource
|
function AmazonMwsResource(AmazonMws, urlData) {
this._AmazonMws = AmazonMws;
this._urlData = urlData || {};
this.basePath = utils.makeURLInterpolator(AmazonMws.getApiField('basePath'));
this.path = utils.makeURLInterpolator(this.path);
if (this.includeBasic) {
this.includeBasic.forEach(function (methodName) {
this[methodName] = AmazonMwsResource.BASIC_METHODS[methodName];
}, this);
}
this.initialize.apply(this, arguments);
}
|
javascript
|
function AmazonMwsResource(AmazonMws, urlData) {
this._AmazonMws = AmazonMws;
this._urlData = urlData || {};
this.basePath = utils.makeURLInterpolator(AmazonMws.getApiField('basePath'));
this.path = utils.makeURLInterpolator(this.path);
if (this.includeBasic) {
this.includeBasic.forEach(function (methodName) {
this[methodName] = AmazonMwsResource.BASIC_METHODS[methodName];
}, this);
}
this.initialize.apply(this, arguments);
}
|
[
"function",
"AmazonMwsResource",
"(",
"AmazonMws",
",",
"urlData",
")",
"{",
"this",
".",
"_AmazonMws",
"=",
"AmazonMws",
";",
"this",
".",
"_urlData",
"=",
"urlData",
"||",
"{",
"}",
";",
"this",
".",
"basePath",
"=",
"utils",
".",
"makeURLInterpolator",
"(",
"AmazonMws",
".",
"getApiField",
"(",
"'basePath'",
")",
")",
";",
"this",
".",
"path",
"=",
"utils",
".",
"makeURLInterpolator",
"(",
"this",
".",
"path",
")",
";",
"if",
"(",
"this",
".",
"includeBasic",
")",
"{",
"this",
".",
"includeBasic",
".",
"forEach",
"(",
"function",
"(",
"methodName",
")",
"{",
"this",
"[",
"methodName",
"]",
"=",
"AmazonMwsResource",
".",
"BASIC_METHODS",
"[",
"methodName",
"]",
";",
"}",
",",
"this",
")",
";",
"}",
"this",
".",
"initialize",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}"
] |
Encapsulates request logic for a AmazonMws Resource
|
[
"Encapsulates",
"request",
"logic",
"for",
"a",
"AmazonMws",
"Resource"
] |
e531635363a03a124c75bfac7aedde89b1193d07
|
https://github.com/bhushankumarl/amazon-mws/blob/e531635363a03a124c75bfac7aedde89b1193d07/lib/AmazonMwsResource.js#L32-L46
|
14,798
|
bhushankumarl/amazon-mws
|
lib/AmazonMwsMethod.js
|
amazonMwsMethod
|
function amazonMwsMethod(spec) {
var commandPath = typeof spec.path === 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function (data) {
return data;
};
return function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] === 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function (resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
return reject(new Error(
'AmazonMws: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to ' + requestMethod + ' ' + commandPath + ')'
));
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var err = new Error('AmazonMws: Unknown arguments (' + args + ').');
return reject(err);
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
}
var options = {headers: objectAssign(opts.headers, spec.headers)};
options.useBody = spec.useBody || false;
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}
|
javascript
|
function amazonMwsMethod(spec) {
var commandPath = typeof spec.path === 'function' ? spec.path
: utils.makeURLInterpolator(spec.path || '');
var requestMethod = (spec.method || 'GET').toUpperCase();
var urlParams = spec.urlParams || [];
var encode = spec.encode || function (data) {
return data;
};
return function () {
var self = this;
var args = [].slice.call(arguments);
var callback = typeof args[args.length - 1] === 'function' && args.pop();
var urlData = this.createUrlData();
return this.wrapTimeout(new Promise((function (resolve, reject) {
for (var i = 0, l = urlParams.length; i < l; ++i) {
// Note that we shift the args array after every iteration so this just
// grabs the "next" argument for use as a URL parameter.
var arg = args[0];
var param = urlParams[i];
var isOptional = OPTIONAL_REGEX.test(param);
param = param.replace(OPTIONAL_REGEX, '');
if (!arg) {
if (isOptional) {
urlData[param] = '';
continue;
}
return reject(new Error(
'AmazonMws: Argument "' + urlParams[i] + '" required, but got: ' + arg +
' (on API request to ' + requestMethod + ' ' + commandPath + ')'
));
}
urlData[param] = args.shift();
}
var data = encode(utils.getDataFromArgs(args));
var opts = utils.getOptionsFromArgs(args);
if (args.length) {
var err = new Error('AmazonMws: Unknown arguments (' + args + ').');
return reject(err);
}
var requestPath = this.createFullPath(commandPath, urlData);
function requestCallback(err, response) {
if (err) {
reject(err);
} else {
resolve(
spec.transformResponseData ?
spec.transformResponseData(response) :
response
);
}
}
var options = {headers: objectAssign(opts.headers, spec.headers)};
options.useBody = spec.useBody || false;
self._request(requestMethod, requestPath, data, opts.auth, options, requestCallback);
}).bind(this)), callback);
};
}
|
[
"function",
"amazonMwsMethod",
"(",
"spec",
")",
"{",
"var",
"commandPath",
"=",
"typeof",
"spec",
".",
"path",
"===",
"'function'",
"?",
"spec",
".",
"path",
":",
"utils",
".",
"makeURLInterpolator",
"(",
"spec",
".",
"path",
"||",
"''",
")",
";",
"var",
"requestMethod",
"=",
"(",
"spec",
".",
"method",
"||",
"'GET'",
")",
".",
"toUpperCase",
"(",
")",
";",
"var",
"urlParams",
"=",
"spec",
".",
"urlParams",
"||",
"[",
"]",
";",
"var",
"encode",
"=",
"spec",
".",
"encode",
"||",
"function",
"(",
"data",
")",
"{",
"return",
"data",
";",
"}",
";",
"return",
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"args",
"=",
"[",
"]",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
";",
"var",
"callback",
"=",
"typeof",
"args",
"[",
"args",
".",
"length",
"-",
"1",
"]",
"===",
"'function'",
"&&",
"args",
".",
"pop",
"(",
")",
";",
"var",
"urlData",
"=",
"this",
".",
"createUrlData",
"(",
")",
";",
"return",
"this",
".",
"wrapTimeout",
"(",
"new",
"Promise",
"(",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"urlParams",
".",
"length",
";",
"i",
"<",
"l",
";",
"++",
"i",
")",
"{",
"// Note that we shift the args array after every iteration so this just",
"// grabs the \"next\" argument for use as a URL parameter.",
"var",
"arg",
"=",
"args",
"[",
"0",
"]",
";",
"var",
"param",
"=",
"urlParams",
"[",
"i",
"]",
";",
"var",
"isOptional",
"=",
"OPTIONAL_REGEX",
".",
"test",
"(",
"param",
")",
";",
"param",
"=",
"param",
".",
"replace",
"(",
"OPTIONAL_REGEX",
",",
"''",
")",
";",
"if",
"(",
"!",
"arg",
")",
"{",
"if",
"(",
"isOptional",
")",
"{",
"urlData",
"[",
"param",
"]",
"=",
"''",
";",
"continue",
";",
"}",
"return",
"reject",
"(",
"new",
"Error",
"(",
"'AmazonMws: Argument \"'",
"+",
"urlParams",
"[",
"i",
"]",
"+",
"'\" required, but got: '",
"+",
"arg",
"+",
"' (on API request to '",
"+",
"requestMethod",
"+",
"' '",
"+",
"commandPath",
"+",
"')'",
")",
")",
";",
"}",
"urlData",
"[",
"param",
"]",
"=",
"args",
".",
"shift",
"(",
")",
";",
"}",
"var",
"data",
"=",
"encode",
"(",
"utils",
".",
"getDataFromArgs",
"(",
"args",
")",
")",
";",
"var",
"opts",
"=",
"utils",
".",
"getOptionsFromArgs",
"(",
"args",
")",
";",
"if",
"(",
"args",
".",
"length",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'AmazonMws: Unknown arguments ('",
"+",
"args",
"+",
"').'",
")",
";",
"return",
"reject",
"(",
"err",
")",
";",
"}",
"var",
"requestPath",
"=",
"this",
".",
"createFullPath",
"(",
"commandPath",
",",
"urlData",
")",
";",
"function",
"requestCallback",
"(",
"err",
",",
"response",
")",
"{",
"if",
"(",
"err",
")",
"{",
"reject",
"(",
"err",
")",
";",
"}",
"else",
"{",
"resolve",
"(",
"spec",
".",
"transformResponseData",
"?",
"spec",
".",
"transformResponseData",
"(",
"response",
")",
":",
"response",
")",
";",
"}",
"}",
"var",
"options",
"=",
"{",
"headers",
":",
"objectAssign",
"(",
"opts",
".",
"headers",
",",
"spec",
".",
"headers",
")",
"}",
";",
"options",
".",
"useBody",
"=",
"spec",
".",
"useBody",
"||",
"false",
";",
"self",
".",
"_request",
"(",
"requestMethod",
",",
"requestPath",
",",
"data",
",",
"opts",
".",
"auth",
",",
"options",
",",
"requestCallback",
")",
";",
"}",
")",
".",
"bind",
"(",
"this",
")",
")",
",",
"callback",
")",
";",
"}",
";",
"}"
] |
Create an API method from the declared spec.
@param [spec.method='GET'] Request Method (POST, GET, DELETE, PUT)
@param [spec.path=''] Path to be appended to the API BASE_PATH, joined with
the instance's path (e.g. 'charges' or 'customers')
@param [spec.required=[]] Array of required arguments in the order that they
must be passed by the consumer of the API. Subsequent optional arguments are
optionally passed through a hash (Object) as the penultimate argument
(preceding the also-optional callback argument
@param [spec.encode] Function for mutating input parameters to a method.
Usefully for applying transforms to data on a per-method basis.
|
[
"Create",
"an",
"API",
"method",
"from",
"the",
"declared",
"spec",
"."
] |
e531635363a03a124c75bfac7aedde89b1193d07
|
https://github.com/bhushankumarl/amazon-mws/blob/e531635363a03a124c75bfac7aedde89b1193d07/lib/AmazonMwsMethod.js#L22-L90
|
14,799
|
bhushankumarl/amazon-mws
|
lib/Error.js
|
_Error
|
function _Error() {
this.populate.apply(this, arguments);
var stack = (new Error(this.message)).stack;
debug('stack ', stack);
}
|
javascript
|
function _Error() {
this.populate.apply(this, arguments);
var stack = (new Error(this.message)).stack;
debug('stack ', stack);
}
|
[
"function",
"_Error",
"(",
")",
"{",
"this",
".",
"populate",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"var",
"stack",
"=",
"(",
"new",
"Error",
"(",
"this",
".",
"message",
")",
")",
".",
"stack",
";",
"debug",
"(",
"'stack '",
",",
"stack",
")",
";",
"}"
] |
Generic Error Class to wrap any errors returned by AmazonMws-node
|
[
"Generic",
"Error",
"Class",
"to",
"wrap",
"any",
"errors",
"returned",
"by",
"AmazonMws",
"-",
"node"
] |
e531635363a03a124c75bfac7aedde89b1193d07
|
https://github.com/bhushankumarl/amazon-mws/blob/e531635363a03a124c75bfac7aedde89b1193d07/lib/Error.js#L11-L15
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.