Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fable

Package Overview
Dependencies
Maintainers
3
Versions
154
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fable - npm Package Compare versions

Comparing version 3.0.14 to 3.0.17

source/Fable-Service-Template.js

26

debug/Harness.js
const libFable = require('../source/Fable.js');
class SimpleService extends libFable.ServiceProviderBase
{
constructor(pFable, pOptions, pServiceHash)
{
super(pFable, pOptions, pServiceHash);
this.serviceType = 'SimpleService';
}
doSomething()
{
this.fable.log.info(`SimpleService ${this.UUID}::${this.Hash} is doing something.`);
}
}
let testFable = new libFable({});
testFable.serviceManager.addServiceType('SimpleService');
testFable.serviceManager.addServiceType('SimpleService', SimpleService);
testFable.serviceManager.instantiateServiceProvider('SimpleService', {SomeOption: true}, 'SimpleService-123');
console.log(`Initialized Service ${testFable.serviceManager.services['SimpleService']['SimpleService-123'].serviceType} as UUID ${testFable.serviceManager.services['SimpleService']['SimpleService-123'].UUID} with hash ${testFable.serviceManager.services['SimpleService']['SimpleService-123'].Hash}`);
testFable.serviceManager.services['SimpleService']['SimpleService-123'].doSomething();
testFable.serviceManager.services['SimpleService']['SimpleService-123'].doSomething();
console.log(`Initialized Service ${testFable.serviceManager.services['SimpleService']['SimpleService-123'].serviceType} as UUID ${testFable.serviceManager.services['SimpleService']['SimpleService-123'].UUID} with hash ${testFable.serviceManager.services['SimpleService']['SimpleService-123'].Hash}`);
testFable.serviceManager.services['SimpleService']['SimpleService-123'].doSomething();

2

package.json
{
"name": "fable",
"version": "3.0.14",
"version": "3.0.17",
"description": "An entity behavior management and API bundling library.",

@@ -5,0 +5,0 @@ "main": "source/Fable.js",

@@ -34,2 +34,4 @@ const _OperationStatePrototype = JSON.stringify(

this.name = pOperationName;
this.state = JSON.parse(_OperationStatePrototype);

@@ -36,0 +38,0 @@

@@ -35,3 +35,3 @@ /**

if (typeof(pServiceClass) == 'object' && pServiceClass.prototype instanceof libFableServiceBase)
if ((typeof(pServiceClass) == 'function') && (pServiceClass.prototype instanceof libFableServiceBase))
{

@@ -51,3 +51,3 @@ // Add the class to the list of classes

// Instantiate the service
let tmpService = new this.serviceClasses[pServiceType](this.fable, pOptions, pCustomServiceHash);
let tmpService = this.instantiateServiceProviderWithoutRegistration(pServiceType, pOptions, pCustomServiceHash);

@@ -66,2 +66,10 @@ // Add the service to the service map

// Create a service provider but don't register it to live forever in fable.services
instantiateServiceProviderWithoutRegistration(pServiceType, pOptions, pCustomServiceHash)
{
// Instantiate the service
let tmpService = new this.serviceClasses[pServiceType](this.fable, pOptions, pCustomServiceHash);
return tmpService;
}
setDefaultServiceInstantiation(pServiceType, pServiceHash)

@@ -77,12 +85,2 @@ {

}
getServiceByHash(pServiceHash)
{
if (this.services.hasOwnProperty(pServiceHash))
{
return this.services[pServiceHash];
}
return false;
}
}

@@ -92,2 +90,2 @@

module.exports.FableServiceBase = libFableServiceBase;
module.exports.ServiceProviderBase = libFableServiceBase;

@@ -13,3 +13,3 @@ /**

this.options = pOptions;
this.options = (typeof(pOptions) === 'object') ? pOptions : {};

@@ -16,0 +16,0 @@ this.serviceType = 'Unknown';

@@ -1,5 +0,4 @@

const libFableUtilityTemplate = require('./Fable-Utility-Template.js');
// TODO: These are still pretty big -- consider the smaller polyfills
const libAsyncWaterfall = require('async.waterfall');
const libAsyncEachLimit = require('async.eachLimit');
const libAsyncEachLimit = require('async.eachlimit');

@@ -12,2 +11,4 @@ class FableUtility

this.templates = {};
// These two functions are used extensively throughout

@@ -30,3 +31,3 @@ this.waterfall = libAsyncWaterfall;

{
let tmpTemplate = new libFableUtilityTemplate(this.fable, pTemplateText);
let tmpTemplate = this.fable.serviceManager.instantiateServiceProviderWithoutRegistration('Template');

@@ -36,2 +37,12 @@ return tmpTemplate.buildTemplateFunction(pTemplateText, pData);

// Build a template function from a template hash, and, register it with the service provider
buildHashedTemplate(pTemplateHash, pTemplateText, pData)
{
let tmpTemplate = this.fable.serviceManager.instantiateServiceProvider('Template', {}, pTemplateHash);
this.templates[pTemplateHash] = tmpTemplate.buildTemplateFunction(pTemplateText, pData);
return this.templates[pTemplateHash];
}
// This is a safe, modern version of chunk from underscore

@@ -38,0 +49,0 @@ // Algorithm pulled from a mix of these two polyfills:

@@ -13,2 +13,4 @@ /**

const libFableServiceTemplate = require('./Fable-Service-Template.js');
const libFableOperation = require('./Fable-Operation.js');

@@ -43,2 +45,7 @@

this.serviceManager = new libFableServiceManager(this);
this.serviceManager.addServiceType('Template', libFableServiceTemplate);
this.services = this.serviceManager.services;
this.defaultServices = this.serviceManager.defaultServices;
}

@@ -86,3 +93,3 @@

{
return this.pOperations[pOperationHash];
return this.Operations[pOperationHash];
}

@@ -89,0 +96,0 @@ }

@@ -33,4 +33,6 @@ /**

Expect(tmpOperation).to.be.an('object');
Expect(testFable.getOperation('INTEGRATION-123')).to.equal(tmpOperation);
Expect(testFable.getOperation('BADHASH')).to.be.false;
Expect(testFable.Operations.hasOwnProperty('INTEGRATION-123')).to.equal(true);
tmpOperation.log.info('Test 123');
tmpOperation.log.info(`Operation GUID ${tmpOperation.GUID} ---- Test 123`);
Expect(tmpOperation.state.Log.length).to.equal(1);

@@ -42,2 +44,20 @@ Expect(tmpOperation.state.Log[0]).to.contain('Test 123');

(
'Create an Operation and try to create another with the hash',
function()
{
let testFable = new libFable();
let tmpOperation = testFable.createOperation('Big Complex Integration Operation', 'INTEGRATION-123');
Expect(tmpOperation).to.be.an('object');
Expect(tmpOperation.name).to.equal('Big Complex Integration Operation');
let tmpCollisionOperation = testFable.createOperation('Another Big Complex Integration Operation with Colliding Name', 'INTEGRATION-123');
Expect(tmpCollisionOperation).to.be.an('object');
Expect(tmpCollisionOperation.name).to.equal('Another Big Complex Integration Operation with Colliding Name');
Expect(testFable.getOperation('INTEGRATION-123')).to.equal(tmpOperation);
}
);
test
(
'Create a basic Integration Operation without a Hash',

@@ -59,6 +79,7 @@ function()

tmpOperation.log.error('This was an error!');
tmpOperation.log.error('And this was an error with some sort of data!', {TestData:'Ignition Complete'});
tmpOperation.log.fatal('It was fatal.');
Expect(tmpOperation.state.Log.length).to.equal(7);
Expect(tmpOperation.state.Log.length).to.equal(9);
Expect(tmpOperation.state.Log[3]).to.equal('{"TestData":"Ignition Complete"}')
Expect(tmpOperation.state.Errors.length).to.equal(2);
Expect(tmpOperation.state.Errors.length).to.equal(4);
}

@@ -65,0 +86,0 @@ );

@@ -14,2 +14,37 @@ /**

class SimpleService extends libFable.ServiceProviderBase
{
constructor(pFable, pOptions, pServiceHash)
{
super(pFable, pOptions, pServiceHash);
this.serviceType = 'SimpleService';
}
doSomething()
{
this.fable.log.info(`SimpleService ${this.UUID}::${this.Hash} is doing something.`);
}
}
class MockDatabaseService extends libFable.ServiceProviderBase
{
constructor(pFable, pOptions, pServiceHash)
{
super(pFable, pOptions, pServiceHash);
this.serviceType = 'MockDatabaseService';
}
connect()
{
this.fable.log.info(`MockDatabaseService ${this.UUID}::${this.Hash} is connecting to a database.`);
}
commit(pRecord)
{
this.fable.log.info(`MockDatabaseService ${this.UUID}::${this.Hash} is committing a record ${pRecord}.`);
}
}
suite

@@ -52,3 +87,3 @@ (

testFable = new libFable();
testFable.serviceManager.addServiceType('SimpleService');
testFable.serviceManager.addServiceType('SimpleService', SimpleService);
testFable.serviceManager.instantiateServiceProvider('SimpleService', {SomeOption: true}, 'SimpleService-123');

@@ -59,5 +94,107 @@

Expect(testFable.serviceManager.defaultServices['SimpleService']).to.be.an('object');
testFable.serviceManager.defaultServices.SimpleService.doSomething();
Expect(testFable.serviceManager.defaultServices['SimpleService'].Hash).to.equal('SimpleService-123');
}
);
test
(
'Use the Default Service with a different hash',
function()
{
let testFable = new libFable({});
testFable.serviceManager.addServiceType('SimpleService', SimpleService);
testFable.serviceManager.instantiateServiceProvider('SimpleService', {SomeOption: true}, 'SimpleService-13');
testFable.serviceManager.services['SimpleService']['SimpleService-13'].doSomething();
Expect(testFable.serviceManager.services['SimpleService']['SimpleService-13']).to.be.an('object');
}
);
test
(
'Instantiate a service without registering it to Fable',
function()
{
let testFable = new libFable({});
testFable.serviceManager.addServiceType('SimpleService', SimpleService);
let tmpService = testFable.serviceManager.instantiateServiceProviderWithoutRegistration('SimpleService', {SomeOption: true}, 'SimpleService-99');
Expect(testFable.services.SimpleService['SimpleService-99']).to.be.an('undefined');
Expect(tmpService).to.be.an('object');
}
);
test
(
'Change the default service provider',
function()
{
let testFable = new libFable({});
testFable.serviceManager.addServiceType('SimpleService', SimpleService);
testFable.serviceManager.addServiceType('DatabaseService', MockDatabaseService);
testFable.serviceManager.instantiateServiceProvider('SimpleService', {SomeOption: true});
testFable.serviceManager.defaultServices.SimpleService.doSomething();
testFable.serviceManager.instantiateServiceProvider('DatabaseService', {ConnectionString: 'mongodb://localhost:27017/test'}, 'PrimaryConnection');
Expect(testFable.serviceManager.defaultServices.DatabaseService.Hash).to.equal('PrimaryConnection');
testFable.serviceManager.instantiateServiceProvider('DatabaseService', {ConnectionString: 'mongodb://localhost:27017/test'}, 'SecondaryConnection');
Expect(testFable.serviceManager.defaultServices.DatabaseService.Hash).to.equal('PrimaryConnection');
testFable.serviceManager.defaultServices.DatabaseService.connect();
testFable.serviceManager.defaultServices.DatabaseService.commit('Test Record');
testFable.serviceManager.setDefaultServiceInstantiation('DatabaseService', 'SecondaryConnection');
testFable.serviceManager.defaultServices.DatabaseService.connect();
testFable.serviceManager.defaultServices.DatabaseService.commit('Another Test Record');
Expect(testFable.serviceManager.defaultServices.DatabaseService.Hash).to.equal('SecondaryConnection');
}
);
test
(
'Attempt to change the default service provider to a nonexistant provider',
function()
{
let testFable = new libFable({});
testFable.serviceManager.addServiceType('SimpleService', SimpleService);
testFable.serviceManager.addServiceType('DatabaseService', MockDatabaseService);
testFable.serviceManager.instantiateServiceProvider('SimpleService', {SomeOption: true});
testFable.serviceManager.defaultServices.SimpleService.doSomething();
testFable.serviceManager.instantiateServiceProvider('DatabaseService', {ConnectionString: 'mongodb://localhost:27017/test'}, 'PrimaryConnection');
Expect(testFable.serviceManager.defaultServices.DatabaseService.Hash).to.equal('PrimaryConnection');
testFable.serviceManager.instantiateServiceProvider('DatabaseService', {ConnectionString: 'mongodb://localhost:27017/test'}, 'SecondaryConnection');
Expect(testFable.serviceManager.defaultServices.DatabaseService.Hash).to.equal('PrimaryConnection');
testFable.serviceManager.defaultServices.DatabaseService.connect();
testFable.serviceManager.defaultServices.DatabaseService.commit('Test Record');
Expect(testFable.serviceManager.setDefaultServiceInstantiation('DatabaseService', 'TertiaryConnection')).to.be.false;
testFable.serviceManager.defaultServices.DatabaseService.connect();
testFable.serviceManager.defaultServices.DatabaseService.commit('Another Test Record');
Expect(testFable.serviceManager.defaultServices.DatabaseService.Hash).to.equal('PrimaryConnection');
}
);
}

@@ -64,0 +201,0 @@ );

@@ -61,5 +61,5 @@ /**

testFable = new libFable();
let tmpTemplate = testFable.Utility.template('There are <%= Count %> things....');
let tmpTemplate = testFable.Utility.template('There // %> are \\ */ /* <%= Count %> things....');
Expect(tmpTemplate).to.be.a('function');
Expect(tmpTemplate({Count:1000})).to.equal('There are 1000 things....');
Expect(tmpTemplate({Count:1000})).to.equal('There // %> are \\ */ /* 1000 things....');
}

@@ -69,2 +69,45 @@ );

(
'Processed Template like Underscore Work With Variables and no scope leakage',
function()
{
testFable = new libFable();
let tmpTemplate = testFable.Utility.template('There are so many of these things (<%= Count %> to be exact)....');
Expect(tmpTemplate).to.be.a('function');
Expect(tmpTemplate({Count:1000})).to.equal('There are so many of these things (1000 to be exact)....');
let tmpOtherTemplate = testFable.Utility.template('Things count: <%= Count %>');
Expect(tmpOtherTemplate).to.be.a('function');
Expect(tmpOtherTemplate({Count:600})).to.equal('Things count: 600');
Expect(tmpTemplate({Count:256})).to.equal('There are so many of these things (256 to be exact)....');
}
);
test
(
'Processed Template like Underscore Work With Variables and no scope leakage',
function()
{
testFable = new libFable();
testFable.Utility.buildHashedTemplate('HeadLine', '<h1><%= TitleText %> Page</h1>');
testFable.Utility.buildHashedTemplate('Slogan', '<p>Some people, like <%= Name %>, have all the fun.</p>');
// Access the low level service render function
Expect(testFable.services.Template.HeadLine.renderFunction({TitleText:'Test'})).to.equal('<h1>Test Page</h1>');
Expect(testFable.services.Template.Slogan.renderFunction({Name:'Jim'})).to.equal('<p>Some people, like Jim, have all the fun.</p>');
// Use the high level simpler one
Expect(testFable.Utility.templates.HeadLine({TitleText:'A New'})).to.equal('<h1>A New Page</h1>');
Expect(testFable.Utility.templates.Slogan({Name:'Bob'})).to.equal('<p>Some people, like Bob, have all the fun.</p>');
}
);
test
(
'Processed Template with default scope',
function()
{
testFable = new libFable();
let tmpTemplate = testFable.Utility.template('There are <%= Count %> things....', {Count:1000});
Expect(tmpTemplate).to.equal('There are 1000 things....');
}
);
test
(
'merging objects should work like old underscore did with 1 paramter',

@@ -71,0 +114,0 @@ function()

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc