diff --git a/examples/gen-js/js/analytics/generated/index.js b/examples/gen-js/js/analytics/generated/index.js index 75308d27..fbb0d0d7 100644 --- a/examples/gen-js/js/analytics/generated/index.js +++ b/examples/gen-js/js/analytics/generated/index.js @@ -1,12 +1,3 @@ -const genOptions = (context = {}) => ({ - context: { - ...context, - typewriter: { - name: "gen-js", - version: "5.1.8" - } - } -}); export default class Analytics { /** * Instantiate a wrapper around an analytics library instance @@ -18,7 +9,16 @@ export default class Analytics { } this.analytics = analytics || { track: () => null }; } - feedViewed(props = {}, context) { + addTypewriterContext(context = {}) { + return { + ...context, + typewriter: { + name: "gen-js", + version: "5.1.8" + } + }; + } + feedViewed(props = {}, options = {}, callback) { var validate = function( data, dataPath, @@ -99,9 +99,17 @@ export default class Analytics { if (!validate({ properties: props })) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - this.analytics.track("Feed Viewed", props, genOptions(context)); + this.analytics.track( + "Feed Viewed", + props, + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback + ); } - photoViewed(props = {}, context) { + photoViewed(props = {}, options = {}, callback) { var validate = function( data, dataPath, @@ -182,9 +190,17 @@ export default class Analytics { if (!validate({ properties: props })) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - this.analytics.track("Photo Viewed", props, genOptions(context)); + this.analytics.track( + "Photo Viewed", + props, + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback + ); } - profileViewed(props = {}, context) { + profileViewed(props = {}, options = {}, callback) { var validate = function( data, dataPath, @@ -265,6 +281,14 @@ export default class Analytics { if (!validate({ properties: props })) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - this.analytics.track("Profile Viewed", props, genOptions(context)); + this.analytics.track( + "Profile Viewed", + props, + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback + ); } } diff --git a/examples/gen-js/node/analytics/generated/index.js b/examples/gen-js/node/analytics/generated/index.js index a75bcfa4..a7230f9c 100644 --- a/examples/gen-js/node/analytics/generated/index.js +++ b/examples/gen-js/node/analytics/generated/index.js @@ -1,13 +1,5 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -const genOptions = (context = {}) => ({ - context: Object.assign({}, context, { - typewriter: { - name: "gen-js", - version: "5.1.8" - } - }) -}); class Analytics { /** * Instantiate a wrapper around an analytics library instance @@ -19,6 +11,14 @@ class Analytics { } this.analytics = analytics || { track: () => null }; } + addTypewriterContext(context = {}) { + return Object.assign({}, context, { + typewriter: { + name: "gen-js", + version: "5.1.8" + } + }); + } orderCompleted(message = {}, callback) { var validate = function( data, @@ -565,7 +565,8 @@ class Analytics { if (!validate(message)) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - message = Object.assign({}, message, genOptions(message.context), { + message = Object.assign({}, message, { + context: this.addTypewriterContext(message.context), event: "Order Completed" }); this.analytics.track(message, callback); diff --git a/examples/gen-js/ts/analytics/generated/index.js b/examples/gen-js/ts/analytics/generated/index.js index 75308d27..fbb0d0d7 100644 --- a/examples/gen-js/ts/analytics/generated/index.js +++ b/examples/gen-js/ts/analytics/generated/index.js @@ -1,12 +1,3 @@ -const genOptions = (context = {}) => ({ - context: { - ...context, - typewriter: { - name: "gen-js", - version: "5.1.8" - } - } -}); export default class Analytics { /** * Instantiate a wrapper around an analytics library instance @@ -18,7 +9,16 @@ export default class Analytics { } this.analytics = analytics || { track: () => null }; } - feedViewed(props = {}, context) { + addTypewriterContext(context = {}) { + return { + ...context, + typewriter: { + name: "gen-js", + version: "5.1.8" + } + }; + } + feedViewed(props = {}, options = {}, callback) { var validate = function( data, dataPath, @@ -99,9 +99,17 @@ export default class Analytics { if (!validate({ properties: props })) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - this.analytics.track("Feed Viewed", props, genOptions(context)); + this.analytics.track( + "Feed Viewed", + props, + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback + ); } - photoViewed(props = {}, context) { + photoViewed(props = {}, options = {}, callback) { var validate = function( data, dataPath, @@ -182,9 +190,17 @@ export default class Analytics { if (!validate({ properties: props })) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - this.analytics.track("Photo Viewed", props, genOptions(context)); + this.analytics.track( + "Photo Viewed", + props, + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback + ); } - profileViewed(props = {}, context) { + profileViewed(props = {}, options = {}, callback) { var validate = function( data, dataPath, @@ -265,6 +281,14 @@ export default class Analytics { if (!validate({ properties: props })) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - this.analytics.track("Profile Viewed", props, genOptions(context)); + this.analytics.track( + "Profile Viewed", + props, + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback + ); } } diff --git a/package.json b/package.json index 7ebd136e..4bbd141b 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "generate-examples:js": "cd ./examples/gen-js/js && yarn run typewriter", "generate-examples:ts": "cd ./examples/gen-js/ts && yarn run typewriter", "generate-examples:node": "cd ./examples/gen-js/node && yarn run typewriter", - "generate-examples": "run-p generate-examples:*" + "generate-examples": "yarn run build && run-p generate-examples:*" }, "dependencies": { "@nucleartide/dx": "^1.0.0", diff --git a/src/commands/gen-js/library.ts b/src/commands/gen-js/library.ts index 7b6176d2..d0d7e87c 100644 --- a/src/commands/gen-js/library.ts +++ b/src/commands/gen-js/library.ts @@ -29,16 +29,6 @@ export function genJS( throw new Error('An instance of ${clientName} must be provided') }` const fileHeader = ` - const genOptions = (context = {}) => ({ - context: { - ...context, - typewriter: { - name: "${command}", - version: "${version}" - } - } - }) - export default class Analytics { /** * Instantiate a wrapper around an analytics library instance @@ -48,6 +38,16 @@ export function genJS( ${runtimeValidation ? analyticsValidation : ''} this.analytics = analytics || { track: () => null } } + + addTypewriterContext(context = {}) { + return { + ...context, + typewriter: { + name: "${command}", + version: "${version}" + } + } + } ` const trackCalls = @@ -61,15 +61,18 @@ export function genJS( let trackCall = '' let validateCall = '' if (client === Client.js) { - parameters = 'props = {}, context' - trackCall = `this.analytics.track('${name}', props, genOptions(context))` + parameters = 'props = {}, options = {}, callback' + trackCall = `this.analytics.track('${name}', props, { + ...options, + context: this.addTypewriterContext(options.context) + }, callback)` validateCall = 'validate({ properties: props })' } else if (client === Client.node) { parameters = 'message = {}, callback' trackCall = ` message = { ...message, - ...genOptions(message.context), + context: this.addTypewriterContext(message.context), event: '${name}' } this.analytics.track(message, callback)` diff --git a/tests/commands/gen-js/__snapshots__/index.amd.js b/tests/commands/gen-js/__snapshots__/index.amd.js index 99e7510f..6f0948ef 100644 --- a/tests/commands/gen-js/__snapshots__/index.amd.js +++ b/tests/commands/gen-js/__snapshots__/index.amd.js @@ -1,15 +1,6 @@ define(["require", "exports"], function(require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); - const genOptions = (context = {}) => ({ - context: { - ...context, - typewriter: { - name: "gen-js", - version: "5.1.8" - } - } - }); class Analytics { /** * Instantiate a wrapper around an analytics library instance @@ -21,7 +12,16 @@ define(["require", "exports"], function(require, exports) { } this.analytics = analytics || { track: () => null }; } - terribleEventName3(props = {}, context) { + addTypewriterContext(context = {}) { + return { + ...context, + typewriter: { + name: "gen-js", + version: "5.1.8" + } + }; + } + terribleEventName3(props = {}, options = {}, callback) { var validate = function( data, dataPath, @@ -76,10 +76,14 @@ define(["require", "exports"], function(require, exports) { this.analytics.track( "42_--terrible==event++name~!3", props, - genOptions(context) + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback ); } - emptyEvent(props = {}, context) { + emptyEvent(props = {}, options = {}, callback) { var validate = function( data, dataPath, @@ -140,9 +144,17 @@ define(["require", "exports"], function(require, exports) { if (!validate({ properties: props })) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - this.analytics.track("Empty Event", props, genOptions(context)); + this.analytics.track( + "Empty Event", + props, + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback + ); } - exampleEvent(props = {}, context) { + exampleEvent(props = {}, options = {}, callback) { var pattern0 = new RegExp("FOO|BAR"); var validate = function( data, @@ -1018,9 +1030,17 @@ define(["require", "exports"], function(require, exports) { if (!validate({ properties: props })) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - this.analytics.track("Example Event", props, genOptions(context)); + this.analytics.track( + "Example Event", + props, + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback + ); } - draft04Event(props = {}, context) { + draft04Event(props = {}, options = {}, callback) { var validate = function( data, dataPath, @@ -1081,9 +1101,17 @@ define(["require", "exports"], function(require, exports) { if (!validate({ properties: props })) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - this.analytics.track("Draft-04 Event", props, genOptions(context)); + this.analytics.track( + "Draft-04 Event", + props, + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback + ); } - draft06Event(props = {}, context) { + draft06Event(props = {}, options = {}, callback) { var validate = function( data, dataPath, @@ -1144,7 +1172,15 @@ define(["require", "exports"], function(require, exports) { if (!validate({ properties: props })) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - this.analytics.track("Draft-06 Event", props, genOptions(context)); + this.analytics.track( + "Draft-06 Event", + props, + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback + ); } } exports.default = Analytics; diff --git a/tests/commands/gen-js/__snapshots__/index.es5.js b/tests/commands/gen-js/__snapshots__/index.es5.js index 9638a2fd..08468445 100644 --- a/tests/commands/gen-js/__snapshots__/index.es5.js +++ b/tests/commands/gen-js/__snapshots__/index.es5.js @@ -15,19 +15,6 @@ var __assign = return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); -var genOptions = function(context) { - if (context === void 0) { - context = {}; - } - return { - context: __assign({}, context, { - typewriter: { - name: "gen-js", - version: "5.1.8" - } - }) - }; -}; var Analytics = /** @class */ (function() { /** * Instantiate a wrapper around an analytics library instance @@ -43,10 +30,24 @@ var Analytics = /** @class */ (function() { } }; } - Analytics.prototype.terribleEventName3 = function(props, context) { + Analytics.prototype.addTypewriterContext = function(context) { + if (context === void 0) { + context = {}; + } + return __assign({}, context, { + typewriter: { + name: "gen-js", + version: "5.1.8" + } + }); + }; + Analytics.prototype.terribleEventName3 = function(props, options, callback) { if (props === void 0) { props = {}; } + if (options === void 0) { + options = {}; + } var validate = function( data, dataPath, @@ -101,13 +102,19 @@ var Analytics = /** @class */ (function() { this.analytics.track( "42_--terrible==event++name~!3", props, - genOptions(context) + __assign({}, options, { + context: this.addTypewriterContext(options.context) + }), + callback ); }; - Analytics.prototype.emptyEvent = function(props, context) { + Analytics.prototype.emptyEvent = function(props, options, callback) { if (props === void 0) { props = {}; } + if (options === void 0) { + options = {}; + } var validate = function( data, dataPath, @@ -168,12 +175,22 @@ var Analytics = /** @class */ (function() { if (!validate({ properties: props })) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - this.analytics.track("Empty Event", props, genOptions(context)); + this.analytics.track( + "Empty Event", + props, + __assign({}, options, { + context: this.addTypewriterContext(options.context) + }), + callback + ); }; - Analytics.prototype.exampleEvent = function(props, context) { + Analytics.prototype.exampleEvent = function(props, options, callback) { if (props === void 0) { props = {}; } + if (options === void 0) { + options = {}; + } var pattern0 = new RegExp("FOO|BAR"); var validate = function( data, @@ -1010,12 +1027,22 @@ var Analytics = /** @class */ (function() { if (!validate({ properties: props })) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - this.analytics.track("Example Event", props, genOptions(context)); + this.analytics.track( + "Example Event", + props, + __assign({}, options, { + context: this.addTypewriterContext(options.context) + }), + callback + ); }; - Analytics.prototype.draft04Event = function(props, context) { + Analytics.prototype.draft04Event = function(props, options, callback) { if (props === void 0) { props = {}; } + if (options === void 0) { + options = {}; + } var validate = function( data, dataPath, @@ -1076,12 +1103,22 @@ var Analytics = /** @class */ (function() { if (!validate({ properties: props })) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - this.analytics.track("Draft-04 Event", props, genOptions(context)); + this.analytics.track( + "Draft-04 Event", + props, + __assign({}, options, { + context: this.addTypewriterContext(options.context) + }), + callback + ); }; - Analytics.prototype.draft06Event = function(props, context) { + Analytics.prototype.draft06Event = function(props, options, callback) { if (props === void 0) { props = {}; } + if (options === void 0) { + options = {}; + } var validate = function( data, dataPath, @@ -1142,7 +1179,14 @@ var Analytics = /** @class */ (function() { if (!validate({ properties: props })) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - this.analytics.track("Draft-06 Event", props, genOptions(context)); + this.analytics.track( + "Draft-06 Event", + props, + __assign({}, options, { + context: this.addTypewriterContext(options.context) + }), + callback + ); }; return Analytics; })(); diff --git a/tests/commands/gen-js/__snapshots__/index.es5.node.js b/tests/commands/gen-js/__snapshots__/index.es5.node.js index c5f29f5a..bc9652be 100644 --- a/tests/commands/gen-js/__snapshots__/index.es5.node.js +++ b/tests/commands/gen-js/__snapshots__/index.es5.node.js @@ -15,19 +15,6 @@ var __assign = return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); -var genOptions = function(context) { - if (context === void 0) { - context = {}; - } - return { - context: __assign({}, context, { - typewriter: { - name: "gen-js", - version: "5.1.8" - } - }) - }; -}; var Analytics = /** @class */ (function() { /** * Instantiate a wrapper around an analytics library instance @@ -43,6 +30,17 @@ var Analytics = /** @class */ (function() { } }; } + Analytics.prototype.addTypewriterContext = function(context) { + if (context === void 0) { + context = {}; + } + return __assign({}, context, { + typewriter: { + name: "gen-js", + version: "5.1.8" + } + }); + }; Analytics.prototype.terribleEventName3 = function(message, callback) { if (message === void 0) { message = {}; @@ -98,7 +96,8 @@ var Analytics = /** @class */ (function() { if (!validate(message)) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - message = __assign({}, message, genOptions(message.context), { + message = __assign({}, message, { + context: this.addTypewriterContext(message.context), event: "42_--terrible==event++name~!3" }); this.analytics.track(message, callback); @@ -167,7 +166,8 @@ var Analytics = /** @class */ (function() { if (!validate(message)) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - message = __assign({}, message, genOptions(message.context), { + message = __assign({}, message, { + context: this.addTypewriterContext(message.context), event: "Empty Event" }); this.analytics.track(message, callback); @@ -1012,7 +1012,8 @@ var Analytics = /** @class */ (function() { if (!validate(message)) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - message = __assign({}, message, genOptions(message.context), { + message = __assign({}, message, { + context: this.addTypewriterContext(message.context), event: "Example Event" }); this.analytics.track(message, callback); @@ -1081,7 +1082,8 @@ var Analytics = /** @class */ (function() { if (!validate(message)) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - message = __assign({}, message, genOptions(message.context), { + message = __assign({}, message, { + context: this.addTypewriterContext(message.context), event: "Draft-04 Event" }); this.analytics.track(message, callback); @@ -1150,7 +1152,8 @@ var Analytics = /** @class */ (function() { if (!validate(message)) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - message = __assign({}, message, genOptions(message.context), { + message = __assign({}, message, { + context: this.addTypewriterContext(message.context), event: "Draft-06 Event" }); this.analytics.track(message, callback); diff --git a/tests/commands/gen-js/__snapshots__/index.js b/tests/commands/gen-js/__snapshots__/index.js index bb41bdab..adebb7bc 100644 --- a/tests/commands/gen-js/__snapshots__/index.js +++ b/tests/commands/gen-js/__snapshots__/index.js @@ -1,12 +1,3 @@ -const genOptions = (context = {}) => ({ - context: { - ...context, - typewriter: { - name: "gen-js", - version: "5.1.8" - } - } -}); export default class Analytics { /** * Instantiate a wrapper around an analytics library instance @@ -18,7 +9,16 @@ export default class Analytics { } this.analytics = analytics || { track: () => null }; } - terribleEventName3(props = {}, context) { + addTypewriterContext(context = {}) { + return { + ...context, + typewriter: { + name: "gen-js", + version: "5.1.8" + } + }; + } + terribleEventName3(props = {}, options = {}, callback) { var validate = function( data, dataPath, @@ -73,10 +73,14 @@ export default class Analytics { this.analytics.track( "42_--terrible==event++name~!3", props, - genOptions(context) + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback ); } - emptyEvent(props = {}, context) { + emptyEvent(props = {}, options = {}, callback) { var validate = function( data, dataPath, @@ -137,9 +141,17 @@ export default class Analytics { if (!validate({ properties: props })) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - this.analytics.track("Empty Event", props, genOptions(context)); + this.analytics.track( + "Empty Event", + props, + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback + ); } - exampleEvent(props = {}, context) { + exampleEvent(props = {}, options = {}, callback) { var pattern0 = new RegExp("FOO|BAR"); var validate = function( data, @@ -976,9 +988,17 @@ export default class Analytics { if (!validate({ properties: props })) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - this.analytics.track("Example Event", props, genOptions(context)); + this.analytics.track( + "Example Event", + props, + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback + ); } - draft04Event(props = {}, context) { + draft04Event(props = {}, options = {}, callback) { var validate = function( data, dataPath, @@ -1039,9 +1059,17 @@ export default class Analytics { if (!validate({ properties: props })) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - this.analytics.track("Draft-04 Event", props, genOptions(context)); + this.analytics.track( + "Draft-04 Event", + props, + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback + ); } - draft06Event(props = {}, context) { + draft06Event(props = {}, options = {}, callback) { var validate = function( data, dataPath, @@ -1102,6 +1130,14 @@ export default class Analytics { if (!validate({ properties: props })) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - this.analytics.track("Draft-06 Event", props, genOptions(context)); + this.analytics.track( + "Draft-06 Event", + props, + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback + ); } } diff --git a/tests/commands/gen-js/__snapshots__/index.node.js b/tests/commands/gen-js/__snapshots__/index.node.js index d69a1592..e77e1f7b 100644 --- a/tests/commands/gen-js/__snapshots__/index.node.js +++ b/tests/commands/gen-js/__snapshots__/index.node.js @@ -1,13 +1,5 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -const genOptions = (context = {}) => ({ - context: Object.assign({}, context, { - typewriter: { - name: "gen-js", - version: "5.1.8" - } - }) -}); class Analytics { /** * Instantiate a wrapper around an analytics library instance @@ -19,6 +11,14 @@ class Analytics { } this.analytics = analytics || { track: () => null }; } + addTypewriterContext(context = {}) { + return Object.assign({}, context, { + typewriter: { + name: "gen-js", + version: "5.1.8" + } + }); + } terribleEventName3(message = {}, callback) { var validate = function( data, @@ -71,7 +71,8 @@ class Analytics { if (!validate(message)) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - message = Object.assign({}, message, genOptions(message.context), { + message = Object.assign({}, message, { + context: this.addTypewriterContext(message.context), event: "42_--terrible==event++name~!3" }); this.analytics.track(message, callback); @@ -137,7 +138,8 @@ class Analytics { if (!validate(message)) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - message = Object.assign({}, message, genOptions(message.context), { + message = Object.assign({}, message, { + context: this.addTypewriterContext(message.context), event: "Empty Event" }); this.analytics.track(message, callback); @@ -979,7 +981,8 @@ class Analytics { if (!validate(message)) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - message = Object.assign({}, message, genOptions(message.context), { + message = Object.assign({}, message, { + context: this.addTypewriterContext(message.context), event: "Example Event" }); this.analytics.track(message, callback); @@ -1045,7 +1048,8 @@ class Analytics { if (!validate(message)) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - message = Object.assign({}, message, genOptions(message.context), { + message = Object.assign({}, message, { + context: this.addTypewriterContext(message.context), event: "Draft-04 Event" }); this.analytics.track(message, callback); @@ -1111,7 +1115,8 @@ class Analytics { if (!validate(message)) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - message = Object.assign({}, message, genOptions(message.context), { + message = Object.assign({}, message, { + context: this.addTypewriterContext(message.context), event: "Draft-06 Event" }); this.analytics.track(message, callback); diff --git a/tests/commands/gen-js/__snapshots__/index.prod.js b/tests/commands/gen-js/__snapshots__/index.prod.js index 1d4223c0..73c6f506 100644 --- a/tests/commands/gen-js/__snapshots__/index.prod.js +++ b/tests/commands/gen-js/__snapshots__/index.prod.js @@ -1,12 +1,3 @@ -const genOptions = (context = {}) => ({ - context: { - ...context, - typewriter: { - name: "gen-js", - version: "5.1.8" - } - } -}); export default class Analytics { /** * Instantiate a wrapper around an analytics library instance @@ -15,23 +6,68 @@ export default class Analytics { constructor(analytics) { this.analytics = analytics || { track: () => null }; } - terribleEventName3(props = {}, context) { + addTypewriterContext(context = {}) { + return { + ...context, + typewriter: { + name: "gen-js", + version: "5.1.8" + } + }; + } + terribleEventName3(props = {}, options = {}, callback) { this.analytics.track( "42_--terrible==event++name~!3", props, - genOptions(context) + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback ); } - emptyEvent(props = {}, context) { - this.analytics.track("Empty Event", props, genOptions(context)); + emptyEvent(props = {}, options = {}, callback) { + this.analytics.track( + "Empty Event", + props, + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback + ); } - exampleEvent(props = {}, context) { - this.analytics.track("Example Event", props, genOptions(context)); + exampleEvent(props = {}, options = {}, callback) { + this.analytics.track( + "Example Event", + props, + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback + ); } - draft04Event(props = {}, context) { - this.analytics.track("Draft-04 Event", props, genOptions(context)); + draft04Event(props = {}, options = {}, callback) { + this.analytics.track( + "Draft-04 Event", + props, + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback + ); } - draft06Event(props = {}, context) { - this.analytics.track("Draft-06 Event", props, genOptions(context)); + draft06Event(props = {}, options = {}, callback) { + this.analytics.track( + "Draft-06 Event", + props, + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback + ); } } diff --git a/tests/commands/gen-js/__snapshots__/index.prod.node.js b/tests/commands/gen-js/__snapshots__/index.prod.node.js index cdde5563..37ad1f2b 100644 --- a/tests/commands/gen-js/__snapshots__/index.prod.node.js +++ b/tests/commands/gen-js/__snapshots__/index.prod.node.js @@ -1,13 +1,5 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -const genOptions = (context = {}) => ({ - context: Object.assign({}, context, { - typewriter: { - name: "gen-js", - version: "5.1.8" - } - }) -}); class Analytics { /** * Instantiate a wrapper around an analytics library instance @@ -16,32 +8,45 @@ class Analytics { constructor(analytics) { this.analytics = analytics || { track: () => null }; } + addTypewriterContext(context = {}) { + return Object.assign({}, context, { + typewriter: { + name: "gen-js", + version: "5.1.8" + } + }); + } terribleEventName3(message = {}, callback) { - message = Object.assign({}, message, genOptions(message.context), { + message = Object.assign({}, message, { + context: this.addTypewriterContext(message.context), event: "42_--terrible==event++name~!3" }); this.analytics.track(message, callback); } emptyEvent(message = {}, callback) { - message = Object.assign({}, message, genOptions(message.context), { + message = Object.assign({}, message, { + context: this.addTypewriterContext(message.context), event: "Empty Event" }); this.analytics.track(message, callback); } exampleEvent(message = {}, callback) { - message = Object.assign({}, message, genOptions(message.context), { + message = Object.assign({}, message, { + context: this.addTypewriterContext(message.context), event: "Example Event" }); this.analytics.track(message, callback); } draft04Event(message = {}, callback) { - message = Object.assign({}, message, genOptions(message.context), { + message = Object.assign({}, message, { + context: this.addTypewriterContext(message.context), event: "Draft-04 Event" }); this.analytics.track(message, callback); } draft06Event(message = {}, callback) { - message = Object.assign({}, message, genOptions(message.context), { + message = Object.assign({}, message, { + context: this.addTypewriterContext(message.context), event: "Draft-06 Event" }); this.analytics.track(message, callback); diff --git a/tests/commands/gen-js/__snapshots__/index.system.js b/tests/commands/gen-js/__snapshots__/index.system.js index daaa4f53..de1f4539 100644 --- a/tests/commands/gen-js/__snapshots__/index.system.js +++ b/tests/commands/gen-js/__snapshots__/index.system.js @@ -1,19 +1,10 @@ System.register([], function(exports_1, context_1) { "use strict"; - var genOptions, Analytics; + var Analytics; var __moduleName = context_1 && context_1.id; return { setters: [], execute: function() { - genOptions = (context = {}) => ({ - context: { - ...context, - typewriter: { - name: "gen-js", - version: "5.1.8" - } - } - }); Analytics = class Analytics { /** * Instantiate a wrapper around an analytics library instance @@ -25,7 +16,16 @@ System.register([], function(exports_1, context_1) { } this.analytics = analytics || { track: () => null }; } - terribleEventName3(props = {}, context) { + addTypewriterContext(context = {}) { + return { + ...context, + typewriter: { + name: "gen-js", + version: "5.1.8" + } + }; + } + terribleEventName3(props = {}, options = {}, callback) { var validate = function( data, dataPath, @@ -84,10 +84,14 @@ System.register([], function(exports_1, context_1) { this.analytics.track( "42_--terrible==event++name~!3", props, - genOptions(context) + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback ); } - emptyEvent(props = {}, context) { + emptyEvent(props = {}, options = {}, callback) { var validate = function( data, dataPath, @@ -152,9 +156,17 @@ System.register([], function(exports_1, context_1) { if (!validate({ properties: props })) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - this.analytics.track("Empty Event", props, genOptions(context)); + this.analytics.track( + "Empty Event", + props, + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback + ); } - exampleEvent(props = {}, context) { + exampleEvent(props = {}, options = {}, callback) { var pattern0 = new RegExp("FOO|BAR"); var validate = function( data, @@ -1059,9 +1071,17 @@ System.register([], function(exports_1, context_1) { if (!validate({ properties: props })) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - this.analytics.track("Example Event", props, genOptions(context)); + this.analytics.track( + "Example Event", + props, + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback + ); } - draft04Event(props = {}, context) { + draft04Event(props = {}, options = {}, callback) { var validate = function( data, dataPath, @@ -1126,9 +1146,17 @@ System.register([], function(exports_1, context_1) { if (!validate({ properties: props })) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - this.analytics.track("Draft-04 Event", props, genOptions(context)); + this.analytics.track( + "Draft-04 Event", + props, + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback + ); } - draft06Event(props = {}, context) { + draft06Event(props = {}, options = {}, callback) { var validate = function( data, dataPath, @@ -1193,7 +1221,15 @@ System.register([], function(exports_1, context_1) { if (!validate({ properties: props })) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - this.analytics.track("Draft-06 Event", props, genOptions(context)); + this.analytics.track( + "Draft-06 Event", + props, + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback + ); } }; exports_1("default", Analytics); diff --git a/tests/commands/gen-js/__snapshots__/index.umd.js b/tests/commands/gen-js/__snapshots__/index.umd.js index 9d19c264..5c653246 100644 --- a/tests/commands/gen-js/__snapshots__/index.umd.js +++ b/tests/commands/gen-js/__snapshots__/index.umd.js @@ -8,15 +8,6 @@ })(function(require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); - const genOptions = (context = {}) => ({ - context: { - ...context, - typewriter: { - name: "gen-js", - version: "5.1.8" - } - } - }); class Analytics { /** * Instantiate a wrapper around an analytics library instance @@ -28,7 +19,16 @@ } this.analytics = analytics || { track: () => null }; } - terribleEventName3(props = {}, context) { + addTypewriterContext(context = {}) { + return { + ...context, + typewriter: { + name: "gen-js", + version: "5.1.8" + } + }; + } + terribleEventName3(props = {}, options = {}, callback) { var validate = function( data, dataPath, @@ -83,10 +83,14 @@ this.analytics.track( "42_--terrible==event++name~!3", props, - genOptions(context) + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback ); } - emptyEvent(props = {}, context) { + emptyEvent(props = {}, options = {}, callback) { var validate = function( data, dataPath, @@ -147,9 +151,17 @@ if (!validate({ properties: props })) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - this.analytics.track("Empty Event", props, genOptions(context)); + this.analytics.track( + "Empty Event", + props, + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback + ); } - exampleEvent(props = {}, context) { + exampleEvent(props = {}, options = {}, callback) { var pattern0 = new RegExp("FOO|BAR"); var validate = function( data, @@ -1025,9 +1037,17 @@ if (!validate({ properties: props })) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - this.analytics.track("Example Event", props, genOptions(context)); + this.analytics.track( + "Example Event", + props, + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback + ); } - draft04Event(props = {}, context) { + draft04Event(props = {}, options = {}, callback) { var validate = function( data, dataPath, @@ -1088,9 +1108,17 @@ if (!validate({ properties: props })) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - this.analytics.track("Draft-04 Event", props, genOptions(context)); + this.analytics.track( + "Draft-04 Event", + props, + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback + ); } - draft06Event(props = {}, context) { + draft06Event(props = {}, options = {}, callback) { var validate = function( data, dataPath, @@ -1151,7 +1179,15 @@ if (!validate({ properties: props })) { throw new Error(JSON.stringify(validate.errors, null, 2)); } - this.analytics.track("Draft-06 Event", props, genOptions(context)); + this.analytics.track( + "Draft-06 Event", + props, + { + ...options, + context: this.addTypewriterContext(options.context) + }, + callback + ); } } exports.default = Analytics;