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

@financial-times/biz-ops-schema

Package Overview
Dependencies
Maintainers
14
Versions
151
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@financial-times/biz-ops-schema - npm Package Compare versions

Comparing version 2.0.0-beta.5 to 2.0.0-beta.6

lib/biz-ops-error.js

48

data-accessors/index.js

@@ -7,17 +7,49 @@ const type = require('./type');

/**
Probably the most functional magic in this comopnent
- accessor = a function that reads data from the rawSchemaData (which is an instance of the RawData class),
enriches it and returns the enriched schema object for use by the application
- cacheKeyGenerator = a function which has the same signature as accessor and returns a string, which is
used to retrieve results from the in memory cache for calls to accessor that match previous ones
What make things more complex is that accessor needs access to rawData (and sometimes other things too),
but we don't want the end user to have to manually pass this around. This is why `.bind(null, rawSchemaData)`
is used to populate the first parameter of accessor.
e.g. an accessor which to the end user looks like `getEnums(options)` is actually a pair of functions
- accessor(rawSchemaData, options)
- cacheKeyGenerator(options)
accessor.bind(null, rawSchemaData) returns a function with the signature boundAccessor(options)
rawSchemaData.cache.addCacheToFunction returns a function with the signature boundAndCacheEnabledAccessor(options)
This is what's finally exposed to the end user
TODO - consider moving away from using bind towards functions that return functions
* */
const createCachedAccessor = (
{ accessor, cacheKeyGenerator },
rawData,
rawSchemaData,
...moreBoundArgs
) =>
rawData.cache.cacheify(
accessor.bind(null, rawData, ...moreBoundArgs),
rawSchemaData.cache.addCacheToFunction(
accessor.bind(null, rawSchemaData, ...moreBoundArgs),
cacheKeyGenerator,
);
module.exports = rawData => {
const getStringValidator = createCachedAccessor(stringValidator, rawData);
const getType = createCachedAccessor(type, rawData, getStringValidator);
const getEnums = createCachedAccessor(enums, rawData);
const getTypes = createCachedAccessor(types, rawData, getType);
module.exports = rawSchemaData => {
const getStringValidator = createCachedAccessor(
stringValidator,
rawSchemaData,
);
const getType = createCachedAccessor(
type,
rawSchemaData,
getStringValidator,
);
const getEnums = createCachedAccessor(enums, rawSchemaData);
const getTypes = createCachedAccessor(types, rawSchemaData, getType);

@@ -24,0 +56,0 @@ return {

3

data-accessors/type.js
const clone = require('clone');
const primitiveTypesMap = require('../lib/primitive-types-map');
const metaProperties = require('../lib/constants');
const BizOpsError = require('../lib/biz-ops-error');

@@ -63,3 +64,3 @@ const BIZ_OPS = 'biz-ops';

if (!typeDefinition) {
throw new Error(`Invalid type ${typeName}`);
throw new BizOpsError(`Invalid type \`${typeName}\``);
}

@@ -66,0 +67,0 @@

@@ -13,3 +13,3 @@ const deepFreeze = require('deep-freeze');

cacheify(func, keyFunc) {
addCacheToFunction(func, keyFunc) {
return (...args) => {

@@ -16,0 +16,0 @@ const key = keyFunc(...args);

@@ -11,2 +11,4 @@ const primitiveTypes = require('./primitive-types-map');

const rawData = new RawData(opts);
// generally only use in tests
if (opts.rawData) {

@@ -21,2 +23,3 @@ rawData.setRawData(opts.rawData);

on: rawData.on.bind(rawData),
configure: rawData.configure.bind(rawData),
startPolling: rawData.startPolling.bind(rawData),

@@ -23,0 +26,0 @@ stopPolling: rawData.stopPolling.bind(rawData),

@@ -23,2 +23,4 @@ const EventEmitter = require('events');

});
} else {
this.rawData = {};
}

@@ -119,2 +121,5 @@ }

}
if (this.firstFetch) {
return this.firstFetch;
}
this.logger.info({

@@ -124,3 +129,4 @@ event: 'STARTING_SCHEMA_POLLER',

this.timer = setInterval(() => this.fetch(), this.ttl).unref();
return this.fetch();
this.firstFetch = this.fetch();
return this.firstFetch;
}

@@ -130,2 +136,3 @@

clearInterval(this.timer);
delete this.firstFetch;
}

@@ -132,0 +139,0 @@ }

@@ -6,13 +6,5 @@ const propertyNameRegex = /^[a-z][a-zA-Z\d]+$/;

class BizOpsError {
constructor(message) {
this.message = message;
}
}
const BizOpsError = require('./biz-ops-error');
const validateTypeName = getType => type => {
if (!getType(type)) {
throw new BizOpsError(`Invalid type \`${type}\``);
}
};
const validateTypeName = getType => type => getType(type);

@@ -19,0 +11,0 @@ const throwInvalidValueError = (

{
"name": "@financial-times/biz-ops-schema",
"version": "2.0.0-beta.5",
"version": "2.0.0-beta.6",
"description": "Schema for biz-ops data store and api. It provides two things: - yaml files which define which types, properties and relationships are allowed - a nodejs library for extracting subsets of this information",

@@ -5,0 +5,0 @@ "main": "index.js",

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