New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@alephdata/followthemoney

Package Overview
Dependencies
Maintainers
2
Versions
216
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@alephdata/followthemoney - npm Package Compare versions

Comparing version 1.1.0 to 1.11.1

40

dist/entity.d.ts
import { Schema } from './schema';
import { Model } from './model';
import { PropertyValue } from './propertyValue';
interface IEntityDatum {
schema: string;
import { Property } from './property';
export declare type Value = string | Entity;
export declare type Values = Array<Value>;
export interface IEntityDatum {
schema: Schema | string;
properties: {
[propName: string]: string[];
[prop: string]: Array<Value | IEntityDatum>;
};
id: string;
}
export { IEntityDatum };
/**
* An entity proxy which provides simplified access to the
* properties and schema associated with an entity.
*/
export declare class Entity {
static generate(schemaName: string, model: Model, rawEntity?: IEntityDatum): Entity;
id: string;
properties: Map<string, PropertyValue>;
schema: Schema;
constructor(schema: Schema, behaviour?: IEntityDatum);
getEdge(): {
source: PropertyValue;
target: PropertyValue;
};
setProperty(name: string, value: any): PropertyValue;
getProperty(name: string): PropertyValue;
getProperties(): Array<PropertyValue>;
is(schemaName: string): boolean;
properties: Map<Property, Values>;
readonly schema: Schema;
readonly raw: any;
constructor(model: Model, data: IEntityDatum);
setProperty(prop: string | Property, value: Value | IEntityDatum): Values;
hasProperty(prop: string | Property): boolean;
getProperty(prop: string | Property): Values;
/**
* List all properties for which this entity has values set. This
* does not include unset properties.
*/
getProperties(): Array<Property>;
toString(): string;
}

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

export * from './index';
export * from './entity';
export * from './model';
export * from './property';
export * from './schema';

@@ -1,86 +0,49 @@

var PropertyValue = /** @class */ (function () {
function PropertyValue(name, values, property) {
this.name = name;
this.values = values;
this.property = property;
}
PropertyValue.prototype.toString = function (separator) {
if (separator === void 0) { separator = ' '; }
return this.values.join(separator);
};
PropertyValue.prototype.isEmpty = function () {
return !this.values.length;
};
return PropertyValue;
}());
/**
* An entity proxy which provides simplified access to the
* properties and schema associated with an entity.
*/
var Entity = /** @class */ (function () {
function Entity(schema, behaviour) {
function Entity(model, data) {
var _this = this;
this.properties = new Map();
if (schema) {
this.schema = schema;
}
else {
throw new Error('`schema` name is require');
}
if (behaviour) {
if (behaviour.id) {
this.id = behaviour.id;
}
else {
this.id = '' + Math.random() * 1000;
}
if (behaviour.properties) {
Object.entries(behaviour.properties).forEach(function (val) {
_this.setProperty(val[0], val[1]);
});
}
}
else {
this.id = '' + Math.random() * 1000;
}
this.schema = model.getSchema(data.schema);
this.id = data.id;
this.raw = data;
Object.entries(data.properties).forEach(function (_a) {
var prop = _a[0], values = _a[1];
values.forEach(function (value) {
_this.setProperty(prop, value);
});
});
}
Entity.generate = function (schemaName, model, rawEntity) {
var schema = model.getSchema(schemaName);
if (!schema) {
throw console.error(new Error('Schema is not found'));
Entity.prototype.setProperty = function (prop, value) {
var property = this.schema.getProperty(prop);
if (typeof (value) !== 'string') {
value = this.schema.model.getEntity(value);
}
return new Entity(schema, rawEntity);
var values = this.properties.get(property) || [];
values.push(value);
this.properties.set(property, values);
return values;
};
Entity.prototype.getEdge = function () {
if (this.schema.isEdge) {
return {
source: this.getProperty(this.schema.edge.source),
target: this.getProperty(this.schema.edge.target)
};
}
throw new Error("The schema '" + this.schema.name + "' cannot be an edge");
Entity.prototype.hasProperty = function (prop) {
var property = this.schema.getProperty(prop);
return this.properties.has(property);
};
Entity.prototype.setProperty = function (name, value) {
if (this.schema.hasProperty(name)) {
var propertyValue = new PropertyValue(name, value, this.schema.getProperty(name));
this.properties.set(name, propertyValue);
return propertyValue;
Entity.prototype.getProperty = function (prop) {
var property = this.schema.getProperty(prop);
if (!this.properties.has(property)) {
return [];
}
else {
throw console.error(new Error('This schema does not implement this property'));
}
return this.properties.get(property);
};
Entity.prototype.getProperty = function (name) {
if (this.properties.has(name)) {
return this.properties.get(name);
}
else if (this.schema.hasProperty(name)) {
return this.setProperty(name, []);
}
else {
throw new Error("The schema '" + this.schema.name + "' does not have property " + name);
}
};
/**
* List all properties for which this entity has values set. This
* does not include unset properties.
*/
Entity.prototype.getProperties = function () {
return Array.from(this.properties.values());
return Array.from(this.properties.keys());
};
Entity.prototype.is = function (schemaName) {
return this.schema.isA(schemaName);
Entity.prototype.toString = function () {
return this.schema.name + this.id;
};

@@ -90,2 +53,6 @@ return Entity;

/**
* Definition of a property, with relevant metadata for type,
* labels and other useful criteria.
*/
var Property = /** @class */ (function () {

@@ -97,8 +64,7 @@ function Property(schema, property) {

this.label = property.label;
this.caption = property.caption;
this.hidden = property.hidden;
this.description = property.description;
this.stub = property.stub;
this.uri = property.uri;
this.required = property.required;
this.caption = !!property.caption;
this.hidden = !!property.hidden;
this.description = property.description || null;
this.stub = !!property.stub;
this.required = !!property.required;
this.range = property.range || null;

@@ -118,2 +84,5 @@ this.reverse = property.reverse || null;

};
Property.prototype.toString = function () {
return this.qname;
};
return Property;

@@ -123,17 +92,17 @@ }());

var Schema = /** @class */ (function () {
function Schema(model, config) {
function Schema(model, schemaName, config) {
var _this = this;
this.properties = new Map();
this.name = config.name;
this.model = model;
this.name = schemaName;
this.label = config.label || this.name;
this.plural = config.plural || this.label;
this.featured = config.featured;
this.schemata = config.schemata;
this.extends = config.extends;
this.abstract = config.abstract;
this.matchable = config.matchable;
this.description = config.description;
this.featured = config.featured || new Array();
this.abstract = !!config.abstract;
this.matchable = !!config.matchable;
this.description = config.description || null;
this.isEdge = !!config.edge;
this.edge = config.edge;
this.isEdge = !!config.edge.source && !!config.edge.target;
Object.entries(config.properties).forEach(function (_a) {

@@ -145,22 +114,48 @@ var propertyName = _a[0], property = _a[1];

Schema.prototype.isThing = function () {
return this.isA('Thing');
return this.isA(Schema.THING);
};
Schema.prototype.isDocument = function () {
return this.isA('Document');
return this.isA(Schema.DOCUMENT);
};
Schema.prototype.getFeaturedProperties = function () {
Schema.prototype.getExtends = function () {
var _this = this;
return this.featured.map(function (featuredPropertyName) {
return _this.properties.get(featuredPropertyName);
return this.extends.map(function (name) { return _this.model.getSchema(name); });
};
Schema.prototype.getProperties = function () {
var properties = new Map();
this.getExtends().forEach(function (schema) {
schema.getProperties().forEach(function (prop, name) {
properties.set(name, prop);
});
});
this.properties.forEach(function (prop, name) {
properties.set(name, prop);
});
return properties;
};
Schema.prototype.hasProperty = function (name) {
return this.properties.has(name);
Schema.prototype.getFeaturedProperties = function () {
var _this = this;
return this.featured.map(function (name) { return _this.getProperty(name); });
};
Schema.prototype.getProperty = function (name) {
if (this.hasProperty(name)) {
return this.properties.get(name);
Schema.prototype.hasProperty = function (prop) {
if (prop instanceof Property) {
return this.getProperties().has(prop.name);
}
return this.getProperties().has(prop);
};
/**
* Get the value of a property. If it's not defined, return an
* empty array. If it's not a valid property, raise an error.
*
* @param prop name or Property
*/
Schema.prototype.getProperty = function (prop) {
if (prop instanceof Property) {
return prop;
}
if (this.hasProperty(prop)) {
return this.getProperties().get(prop);
}
else {
throw new Error('there is no such a property set');
throw new Error('Property does not exist: ' + prop);
}

@@ -171,14 +166,26 @@ };

};
Schema.prototype.toString = function () {
return this.name;
};
Schema.THING = 'Thing';
Schema.DOCUMENT = 'Document';
return Schema;
}());
/**
* A property type, such as a string, email address, phone number,
* URL or a related entity.
*/
var PropertyType = /** @class */ (function () {
function PropertyType(data) {
this.name = data.name;
this.group = data.group;
this.grouped = data.group !== null;
this.label = data.label;
this.plural = data.plural;
this.matchable = data.matchable;
function PropertyType(name, data) {
this.name = name;
this.label = data.label || name;
this.plural = data.plural || this.label;
this.group = data.group || null;
this.grouped = data.group !== undefined;
this.matchable = !!data.matchable;
}
PropertyType.prototype.toString = function () {
return this.name;
};
PropertyType.ENTITY = 'entity';

@@ -188,2 +195,3 @@ return PropertyType;

var uuid = require('uuid/v4');
var Model = /** @class */ (function () {

@@ -194,7 +202,6 @@ function Model(config) {

this.types = {};
this.properties = {};
this.types = {};
Object.entries(config.types).forEach(function (_a) {
var typeName = _a[0], typeData = _a[1];
_this.types[typeName] = new PropertyType(typeData);
_this.types[typeName] = new PropertyType(typeName, typeData);
});

@@ -204,3 +211,3 @@ this.schemata = {};

var schemaName = _a[0], schema = _a[1];
_this.schemata[schemaName] = new Schema(_this, schema);
_this.schemata[schemaName] = new Schema(_this, schemaName, schema);
});

@@ -212,2 +219,5 @@ }

}
if (schemaName instanceof Schema) {
return schemaName;
}
var schema = this.schemata[schemaName];

@@ -222,12 +232,32 @@ if (schema === undefined) {

};
Model.prototype.createEntity = function (rawEntity) {
if (rawEntity.schema) {
return Entity.generate(rawEntity.schema, this, rawEntity);
/**
* Convert a raw JSON object to an entity proxy.
*
* @param raw entity source data
*/
Model.prototype.getEntity = function (raw) {
if (raw instanceof Entity) {
return raw;
}
throw new Error('no schema description found');
else {
return new Entity(this, raw);
}
};
/**
* Make a new object with the given schema, and generate a random ID for
* it.
*
* @param schema Schema name or object
*/
Model.prototype.createEntity = function (schema) {
return this.getEntity({
id: uuid(),
schema: schema,
properties: {}
});
};
return Model;
}());
export { Entity, Model, Property, PropertyValue, Schema };
export { Entity, Model, Property, Schema };
//# sourceMappingURL=followthemoney.es5.js.map

@@ -7,87 +7,50 @@ (function (global, factory) {

var PropertyValue = /** @class */ (function () {
function PropertyValue(name, values, property) {
this.name = name;
this.values = values;
this.property = property;
}
PropertyValue.prototype.toString = function (separator) {
if (separator === void 0) { separator = ' '; }
return this.values.join(separator);
};
PropertyValue.prototype.isEmpty = function () {
return !this.values.length;
};
return PropertyValue;
}());
/**
* An entity proxy which provides simplified access to the
* properties and schema associated with an entity.
*/
var Entity = /** @class */ (function () {
function Entity(schema, behaviour) {
function Entity(model, data) {
var _this = this;
this.properties = new Map();
if (schema) {
this.schema = schema;
}
else {
throw new Error('`schema` name is require');
}
if (behaviour) {
if (behaviour.id) {
this.id = behaviour.id;
}
else {
this.id = '' + Math.random() * 1000;
}
if (behaviour.properties) {
Object.entries(behaviour.properties).forEach(function (val) {
_this.setProperty(val[0], val[1]);
});
}
}
else {
this.id = '' + Math.random() * 1000;
}
this.schema = model.getSchema(data.schema);
this.id = data.id;
this.raw = data;
Object.entries(data.properties).forEach(function (_a) {
var prop = _a[0], values = _a[1];
values.forEach(function (value) {
_this.setProperty(prop, value);
});
});
}
Entity.generate = function (schemaName, model, rawEntity) {
var schema = model.getSchema(schemaName);
if (!schema) {
throw console.error(new Error('Schema is not found'));
Entity.prototype.setProperty = function (prop, value) {
var property = this.schema.getProperty(prop);
if (typeof (value) !== 'string') {
value = this.schema.model.getEntity(value);
}
return new Entity(schema, rawEntity);
var values = this.properties.get(property) || [];
values.push(value);
this.properties.set(property, values);
return values;
};
Entity.prototype.getEdge = function () {
if (this.schema.isEdge) {
return {
source: this.getProperty(this.schema.edge.source),
target: this.getProperty(this.schema.edge.target)
};
}
throw new Error("The schema '" + this.schema.name + "' cannot be an edge");
Entity.prototype.hasProperty = function (prop) {
var property = this.schema.getProperty(prop);
return this.properties.has(property);
};
Entity.prototype.setProperty = function (name, value) {
if (this.schema.hasProperty(name)) {
var propertyValue = new PropertyValue(name, value, this.schema.getProperty(name));
this.properties.set(name, propertyValue);
return propertyValue;
Entity.prototype.getProperty = function (prop) {
var property = this.schema.getProperty(prop);
if (!this.properties.has(property)) {
return [];
}
else {
throw console.error(new Error('This schema does not implement this property'));
}
return this.properties.get(property);
};
Entity.prototype.getProperty = function (name) {
if (this.properties.has(name)) {
return this.properties.get(name);
}
else if (this.schema.hasProperty(name)) {
return this.setProperty(name, []);
}
else {
throw new Error("The schema '" + this.schema.name + "' does not have property " + name);
}
};
/**
* List all properties for which this entity has values set. This
* does not include unset properties.
*/
Entity.prototype.getProperties = function () {
return Array.from(this.properties.values());
return Array.from(this.properties.keys());
};
Entity.prototype.is = function (schemaName) {
return this.schema.isA(schemaName);
Entity.prototype.toString = function () {
return this.schema.name + this.id;
};

@@ -97,2 +60,6 @@ return Entity;

/**
* Definition of a property, with relevant metadata for type,
* labels and other useful criteria.
*/
var Property = /** @class */ (function () {

@@ -104,8 +71,7 @@ function Property(schema, property) {

this.label = property.label;
this.caption = property.caption;
this.hidden = property.hidden;
this.description = property.description;
this.stub = property.stub;
this.uri = property.uri;
this.required = property.required;
this.caption = !!property.caption;
this.hidden = !!property.hidden;
this.description = property.description || null;
this.stub = !!property.stub;
this.required = !!property.required;
this.range = property.range || null;

@@ -125,2 +91,5 @@ this.reverse = property.reverse || null;

};
Property.prototype.toString = function () {
return this.qname;
};
return Property;

@@ -130,17 +99,17 @@ }());

var Schema = /** @class */ (function () {
function Schema(model, config) {
function Schema(model, schemaName, config) {
var _this = this;
this.properties = new Map();
this.name = config.name;
this.model = model;
this.name = schemaName;
this.label = config.label || this.name;
this.plural = config.plural || this.label;
this.featured = config.featured;
this.schemata = config.schemata;
this.extends = config.extends;
this.abstract = config.abstract;
this.matchable = config.matchable;
this.description = config.description;
this.featured = config.featured || new Array();
this.abstract = !!config.abstract;
this.matchable = !!config.matchable;
this.description = config.description || null;
this.isEdge = !!config.edge;
this.edge = config.edge;
this.isEdge = !!config.edge.source && !!config.edge.target;
Object.entries(config.properties).forEach(function (_a) {

@@ -152,22 +121,48 @@ var propertyName = _a[0], property = _a[1];

Schema.prototype.isThing = function () {
return this.isA('Thing');
return this.isA(Schema.THING);
};
Schema.prototype.isDocument = function () {
return this.isA('Document');
return this.isA(Schema.DOCUMENT);
};
Schema.prototype.getFeaturedProperties = function () {
Schema.prototype.getExtends = function () {
var _this = this;
return this.featured.map(function (featuredPropertyName) {
return _this.properties.get(featuredPropertyName);
return this.extends.map(function (name) { return _this.model.getSchema(name); });
};
Schema.prototype.getProperties = function () {
var properties = new Map();
this.getExtends().forEach(function (schema) {
schema.getProperties().forEach(function (prop, name) {
properties.set(name, prop);
});
});
this.properties.forEach(function (prop, name) {
properties.set(name, prop);
});
return properties;
};
Schema.prototype.hasProperty = function (name) {
return this.properties.has(name);
Schema.prototype.getFeaturedProperties = function () {
var _this = this;
return this.featured.map(function (name) { return _this.getProperty(name); });
};
Schema.prototype.getProperty = function (name) {
if (this.hasProperty(name)) {
return this.properties.get(name);
Schema.prototype.hasProperty = function (prop) {
if (prop instanceof Property) {
return this.getProperties().has(prop.name);
}
return this.getProperties().has(prop);
};
/**
* Get the value of a property. If it's not defined, return an
* empty array. If it's not a valid property, raise an error.
*
* @param prop name or Property
*/
Schema.prototype.getProperty = function (prop) {
if (prop instanceof Property) {
return prop;
}
if (this.hasProperty(prop)) {
return this.getProperties().get(prop);
}
else {
throw new Error('there is no such a property set');
throw new Error('Property does not exist: ' + prop);
}

@@ -178,14 +173,26 @@ };

};
Schema.prototype.toString = function () {
return this.name;
};
Schema.THING = 'Thing';
Schema.DOCUMENT = 'Document';
return Schema;
}());
/**
* A property type, such as a string, email address, phone number,
* URL or a related entity.
*/
var PropertyType = /** @class */ (function () {
function PropertyType(data) {
this.name = data.name;
this.group = data.group;
this.grouped = data.group !== null;
this.label = data.label;
this.plural = data.plural;
this.matchable = data.matchable;
function PropertyType(name, data) {
this.name = name;
this.label = data.label || name;
this.plural = data.plural || this.label;
this.group = data.group || null;
this.grouped = data.group !== undefined;
this.matchable = !!data.matchable;
}
PropertyType.prototype.toString = function () {
return this.name;
};
PropertyType.ENTITY = 'entity';

@@ -195,2 +202,3 @@ return PropertyType;

var uuid = require('uuid/v4');
var Model = /** @class */ (function () {

@@ -201,7 +209,6 @@ function Model(config) {

this.types = {};
this.properties = {};
this.types = {};
Object.entries(config.types).forEach(function (_a) {
var typeName = _a[0], typeData = _a[1];
_this.types[typeName] = new PropertyType(typeData);
_this.types[typeName] = new PropertyType(typeName, typeData);
});

@@ -211,3 +218,3 @@ this.schemata = {};

var schemaName = _a[0], schema = _a[1];
_this.schemata[schemaName] = new Schema(_this, schema);
_this.schemata[schemaName] = new Schema(_this, schemaName, schema);
});

@@ -219,2 +226,5 @@ }

}
if (schemaName instanceof Schema) {
return schemaName;
}
var schema = this.schemata[schemaName];

@@ -229,8 +239,28 @@ if (schema === undefined) {

};
Model.prototype.createEntity = function (rawEntity) {
if (rawEntity.schema) {
return Entity.generate(rawEntity.schema, this, rawEntity);
/**
* Convert a raw JSON object to an entity proxy.
*
* @param raw entity source data
*/
Model.prototype.getEntity = function (raw) {
if (raw instanceof Entity) {
return raw;
}
throw new Error('no schema description found');
else {
return new Entity(this, raw);
}
};
/**
* Make a new object with the given schema, and generate a random ID for
* it.
*
* @param schema Schema name or object
*/
Model.prototype.createEntity = function (schema) {
return this.getEntity({
id: uuid(),
schema: schema,
properties: {}
});
};
return Model;

@@ -242,3 +272,2 @@ }());

exports.Property = Property;
exports.PropertyValue = PropertyValue;
exports.Schema = Schema;

@@ -245,0 +274,0 @@

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

export * from './entity';
export * from './model';
export * from './property';
export * from './propertyValue';
export * from './schema';
export * from './followthemoney';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var propertyValue_1 = require("./propertyValue");
/**
* An entity proxy which provides simplified access to the
* properties and schema associated with an entity.
*/
var Entity = /** @class */ (function () {
function Entity(schema, behaviour) {
function Entity(model, data) {
var _this = this;
this.properties = new Map();
if (schema) {
this.schema = schema;
}
else {
throw new Error('`schema` name is require');
}
if (behaviour) {
if (behaviour.id) {
this.id = behaviour.id;
}
else {
this.id = '' + Math.random() * 1000;
}
if (behaviour.properties) {
Object.entries(behaviour.properties).forEach(function (val) {
_this.setProperty(val[0], val[1]);
});
}
}
else {
this.id = '' + Math.random() * 1000;
}
this.schema = model.getSchema(data.schema);
this.id = data.id;
this.raw = data;
Object.entries(data.properties).forEach(function (_a) {
var prop = _a[0], values = _a[1];
values.forEach(function (value) {
_this.setProperty(prop, value);
});
});
}
Entity.generate = function (schemaName, model, rawEntity) {
var schema = model.getSchema(schemaName);
if (!schema) {
throw console.error(new Error('Schema is not found'));
Entity.prototype.setProperty = function (prop, value) {
var property = this.schema.getProperty(prop);
if (typeof (value) !== 'string') {
value = this.schema.model.getEntity(value);
}
return new Entity(schema, rawEntity);
var values = this.properties.get(property) || [];
values.push(value);
this.properties.set(property, values);
return values;
};
Entity.prototype.getEdge = function () {
if (this.schema.isEdge) {
return {
source: this.getProperty(this.schema.edge.source),
target: this.getProperty(this.schema.edge.target)
};
}
throw new Error("The schema '" + this.schema.name + "' cannot be an edge");
Entity.prototype.hasProperty = function (prop) {
var property = this.schema.getProperty(prop);
return this.properties.has(property);
};
Entity.prototype.setProperty = function (name, value) {
if (this.schema.hasProperty(name)) {
var propertyValue = new propertyValue_1.PropertyValue(name, value, this.schema.getProperty(name));
this.properties.set(name, propertyValue);
return propertyValue;
Entity.prototype.getProperty = function (prop) {
var property = this.schema.getProperty(prop);
if (!this.properties.has(property)) {
return [];
}
else {
throw console.error(new Error('This schema does not implement this property'));
}
return this.properties.get(property);
};
Entity.prototype.getProperty = function (name) {
if (this.properties.has(name)) {
return this.properties.get(name);
}
else if (this.schema.hasProperty(name)) {
return this.setProperty(name, []);
}
else {
throw new Error("The schema '" + this.schema.name + "' does not have property " + name);
}
};
/**
* List all properties for which this entity has values set. This
* does not include unset properties.
*/
Entity.prototype.getProperties = function () {
return Array.from(this.properties.values());
return Array.from(this.properties.keys());
};
Entity.prototype.is = function (schemaName) {
return this.schema.isA(schemaName);
Entity.prototype.toString = function () {
return this.schema.name + this.id;
};

@@ -74,0 +52,0 @@ return Entity;

@@ -6,3 +6,6 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./index"));
__export(require("./entity"));
__export(require("./model"));
__export(require("./property"));
__export(require("./schema"));
//# sourceMappingURL=followthemoney.js.map

@@ -6,7 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./entity"));
__export(require("./model"));
__export(require("./property"));
__export(require("./propertyValue"));
__export(require("./schema"));
__export(require("./followthemoney"));
//# sourceMappingURL=index.js.map

@@ -6,2 +6,3 @@ "use strict";

var type_1 = require("./type");
var uuid = require('uuid/v4');
var Model = /** @class */ (function () {

@@ -12,7 +13,6 @@ function Model(config) {

this.types = {};
this.properties = {};
this.types = {};
Object.entries(config.types).forEach(function (_a) {
var typeName = _a[0], typeData = _a[1];
_this.types[typeName] = new type_1.PropertyType(typeData);
_this.types[typeName] = new type_1.PropertyType(typeName, typeData);
});

@@ -22,3 +22,3 @@ this.schemata = {};

var schemaName = _a[0], schema = _a[1];
_this.schemata[schemaName] = new schema_1.Schema(_this, schema);
_this.schemata[schemaName] = new schema_1.Schema(_this, schemaName, schema);
});

@@ -30,2 +30,5 @@ }

}
if (schemaName instanceof schema_1.Schema) {
return schemaName;
}
var schema = this.schemata[schemaName];

@@ -40,8 +43,28 @@ if (schema === undefined) {

};
Model.prototype.createEntity = function (rawEntity) {
if (rawEntity.schema) {
return entity_1.Entity.generate(rawEntity.schema, this, rawEntity);
/**
* Convert a raw JSON object to an entity proxy.
*
* @param raw entity source data
*/
Model.prototype.getEntity = function (raw) {
if (raw instanceof entity_1.Entity) {
return raw;
}
throw new Error('no schema description found');
else {
return new entity_1.Entity(this, raw);
}
};
/**
* Make a new object with the given schema, and generate a random ID for
* it.
*
* @param schema Schema name or object
*/
Model.prototype.createEntity = function (schema) {
return this.getEntity({
id: uuid(),
schema: schema,
properties: {}
});
};
return Model;

@@ -48,0 +71,0 @@ }());

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Definition of a property, with relevant metadata for type,
* labels and other useful criteria.
*/
var Property = /** @class */ (function () {

@@ -9,8 +13,7 @@ function Property(schema, property) {

this.label = property.label;
this.caption = property.caption;
this.hidden = property.hidden;
this.description = property.description;
this.stub = property.stub;
this.uri = property.uri;
this.required = property.required;
this.caption = !!property.caption;
this.hidden = !!property.hidden;
this.description = property.description || null;
this.stub = !!property.stub;
this.required = !!property.required;
this.range = property.range || null;

@@ -30,2 +33,5 @@ this.reverse = property.reverse || null;

};
Property.prototype.toString = function () {
return this.qname;
};
return Property;

@@ -32,0 +38,0 @@ }());

@@ -5,17 +5,17 @@ "use strict";

var Schema = /** @class */ (function () {
function Schema(model, config) {
function Schema(model, schemaName, config) {
var _this = this;
this.properties = new Map();
this.name = config.name;
this.model = model;
this.name = schemaName;
this.label = config.label || this.name;
this.plural = config.plural || this.label;
this.featured = config.featured;
this.schemata = config.schemata;
this.extends = config.extends;
this.abstract = config.abstract;
this.matchable = config.matchable;
this.description = config.description;
this.featured = config.featured || new Array();
this.abstract = !!config.abstract;
this.matchable = !!config.matchable;
this.description = config.description || null;
this.isEdge = !!config.edge;
this.edge = config.edge;
this.isEdge = !!config.edge.source && !!config.edge.target;
Object.entries(config.properties).forEach(function (_a) {

@@ -27,22 +27,48 @@ var propertyName = _a[0], property = _a[1];

Schema.prototype.isThing = function () {
return this.isA('Thing');
return this.isA(Schema.THING);
};
Schema.prototype.isDocument = function () {
return this.isA('Document');
return this.isA(Schema.DOCUMENT);
};
Schema.prototype.getFeaturedProperties = function () {
Schema.prototype.getExtends = function () {
var _this = this;
return this.featured.map(function (featuredPropertyName) {
return _this.properties.get(featuredPropertyName);
return this.extends.map(function (name) { return _this.model.getSchema(name); });
};
Schema.prototype.getProperties = function () {
var properties = new Map();
this.getExtends().forEach(function (schema) {
schema.getProperties().forEach(function (prop, name) {
properties.set(name, prop);
});
});
this.properties.forEach(function (prop, name) {
properties.set(name, prop);
});
return properties;
};
Schema.prototype.hasProperty = function (name) {
return this.properties.has(name);
Schema.prototype.getFeaturedProperties = function () {
var _this = this;
return this.featured.map(function (name) { return _this.getProperty(name); });
};
Schema.prototype.getProperty = function (name) {
if (this.hasProperty(name)) {
return this.properties.get(name);
Schema.prototype.hasProperty = function (prop) {
if (prop instanceof property_1.Property) {
return this.getProperties().has(prop.name);
}
return this.getProperties().has(prop);
};
/**
* Get the value of a property. If it's not defined, return an
* empty array. If it's not a valid property, raise an error.
*
* @param prop name or Property
*/
Schema.prototype.getProperty = function (prop) {
if (prop instanceof property_1.Property) {
return prop;
}
if (this.hasProperty(prop)) {
return this.getProperties().get(prop);
}
else {
throw new Error('there is no such a property set');
throw new Error('Property does not exist: ' + prop);
}

@@ -53,2 +79,7 @@ };

};
Schema.prototype.toString = function () {
return this.name;
};
Schema.THING = 'Thing';
Schema.DOCUMENT = 'Document';
return Schema;

@@ -55,0 +86,0 @@ }());

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* A property type, such as a string, email address, phone number,
* URL or a related entity.
*/
var PropertyType = /** @class */ (function () {
function PropertyType(data) {
this.name = data.name;
this.group = data.group;
this.grouped = data.group !== null;
this.label = data.label;
this.plural = data.plural;
this.matchable = data.matchable;
function PropertyType(name, data) {
this.name = name;
this.label = data.label || name;
this.plural = data.plural || this.label;
this.group = data.group || null;
this.grouped = data.group !== undefined;
this.matchable = !!data.matchable;
}
PropertyType.prototype.toString = function () {
return this.name;
};
PropertyType.ENTITY = 'entity';

@@ -13,0 +20,0 @@ return PropertyType;

@@ -5,4 +5,8 @@ import { Schema, ISchemaDatum } from './schema';

export interface IModelDatum {
schemata: Array<ISchemaDatum>;
types: Array<IPropertyTypeDatum>;
schemata: {
[name: string]: ISchemaDatum;
};
types: {
[name: string]: IPropertyTypeDatum;
};
}

@@ -16,7 +20,18 @@ export declare class Model {

};
private readonly properties;
constructor(config: IModelDatum);
getSchema(schemaName: string | null | undefined): Schema;
getSchema(schemaName: string | null | undefined | Schema): Schema;
getType(typeName: string): PropertyType;
createEntity(rawEntity: IEntityDatum): Entity;
/**
* Convert a raw JSON object to an entity proxy.
*
* @param raw entity source data
*/
getEntity(raw: IEntityDatum | Entity): Entity;
/**
* Make a new object with the given schema, and generate a random ID for
* it.
*
* @param schema Schema name or object
*/
createEntity(schema: string | Schema): Entity;
}

@@ -7,12 +7,15 @@ import { Schema } from './schema';

label: string;
description: string | null;
caption: boolean;
stub: boolean;
uri: string;
type: string;
hidden: boolean;
required: boolean;
description?: string;
stub?: boolean;
caption?: boolean;
hidden?: boolean;
required?: boolean;
range?: string | null;
reverse?: string;
}
/**
* Definition of a property, with relevant metadata for type,
* labels and other useful criteria.
*/
export declare class Property {

@@ -30,3 +33,2 @@ readonly schema: Schema;

readonly hasReverse: boolean;
readonly uri: string;
private readonly range;

@@ -37,2 +39,3 @@ private readonly reverse;

getReverse(): Property;
toString(): string;
}

@@ -8,13 +8,12 @@ import { IPropertyDatum, Property } from './property';

export interface ISchemaDatum {
name: string;
label: string;
required: boolean;
plural: string;
schemata: string[];
extends: string[];
abstract: boolean;
matchable: boolean;
description: string | null;
edge: IEdgeSpecification;
featured: string[];
required?: boolean;
abstract?: boolean;
matchable?: boolean;
description?: string;
edge?: IEdgeSpecification;
featured?: string[];
properties: {

@@ -25,3 +24,4 @@ [x: string]: IPropertyDatum;

export declare class Schema {
properties: Map<string, Property>;
static readonly THING = "Thing";
static readonly DOCUMENT = "Document";
readonly model: Model;

@@ -37,12 +37,22 @@ readonly name: string;

readonly extends: string[];
readonly edge: IEdgeSpecification;
readonly edge?: IEdgeSpecification;
readonly isEdge: boolean;
constructor(model: Model, config: ISchemaDatum);
private properties;
constructor(model: Model, schemaName: string, config: ISchemaDatum);
isThing(): boolean;
isDocument(): boolean;
getFeaturedProperties(): (Property | undefined)[];
hasProperty(name: string): boolean;
getProperty(name: string): Property;
getExtends(): Array<Schema>;
getProperties(): Map<string, Property>;
getFeaturedProperties(): Property[];
hasProperty(prop: string | Property): boolean;
/**
* Get the value of a property. If it's not defined, return an
* empty array. If it's not a valid property, raise an error.
*
* @param prop name or Property
*/
getProperty(prop: string | Property): Property;
isA(schemaName: string): boolean;
toString(): string;
}
export {};
export interface IPropertyTypeDatum {
name: string;
group: string | null;
label: string;
plural: string;
matchable: boolean;
group?: string;
label?: string;
plural?: string | null;
matchable?: boolean;
}
/**
* A property type, such as a string, email address, phone number,
* URL or a related entity.
*/
export declare class PropertyType {

@@ -16,3 +19,4 @@ static ENTITY: string;

matchable: boolean;
constructor(data: IPropertyTypeDatum);
constructor(name: string, data: IPropertyTypeDatum);
toString(): string;
}
import { Schema } from './schema';
import { Model } from './model';
import { PropertyValue } from './propertyValue';
interface IEntityDatum {
schema: string;
import { Property } from './property';
export declare type Value = string | Entity;
export declare type Values = Array<Value>;
export interface IEntityDatum {
schema: Schema | string;
properties: {
[propName: string]: string[];
[prop: string]: Array<Value | IEntityDatum>;
};
id: string;
}
export { IEntityDatum };
/**
* An entity proxy which provides simplified access to the
* properties and schema associated with an entity.
*/
export declare class Entity {
static generate(schemaName: string, model: Model, rawEntity?: IEntityDatum): Entity;
id: string;
properties: Map<string, PropertyValue>;
schema: Schema;
constructor(schema: Schema, behaviour?: IEntityDatum);
getEdge(): {
source: PropertyValue;
target: PropertyValue;
};
setProperty(name: string, value: any): PropertyValue;
getProperty(name: string): PropertyValue;
getProperties(): Array<PropertyValue>;
is(schemaName: string): boolean;
properties: Map<Property, Values>;
readonly schema: Schema;
readonly raw: any;
constructor(model: Model, data: IEntityDatum);
setProperty(prop: string | Property, value: Value | IEntityDatum): Values;
hasProperty(prop: string | Property): boolean;
getProperty(prop: string | Property): Values;
/**
* List all properties for which this entity has values set. This
* does not include unset properties.
*/
getProperties(): Array<Property>;
toString(): string;
}

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

export * from './index';
export * from './entity';
export * from './model';
export * from './property';
export * from './schema';

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

export * from './entity';
export * from './model';
export * from './property';
export * from './propertyValue';
export * from './schema';
export * from './followthemoney';

@@ -5,4 +5,8 @@ import { Schema, ISchemaDatum } from './schema';

export interface IModelDatum {
schemata: Array<ISchemaDatum>;
types: Array<IPropertyTypeDatum>;
schemata: {
[name: string]: ISchemaDatum;
};
types: {
[name: string]: IPropertyTypeDatum;
};
}

@@ -16,7 +20,18 @@ export declare class Model {

};
private readonly properties;
constructor(config: IModelDatum);
getSchema(schemaName: string | null | undefined): Schema;
getSchema(schemaName: string | null | undefined | Schema): Schema;
getType(typeName: string): PropertyType;
createEntity(rawEntity: IEntityDatum): Entity;
/**
* Convert a raw JSON object to an entity proxy.
*
* @param raw entity source data
*/
getEntity(raw: IEntityDatum | Entity): Entity;
/**
* Make a new object with the given schema, and generate a random ID for
* it.
*
* @param schema Schema name or object
*/
createEntity(schema: string | Schema): Entity;
}

@@ -7,12 +7,15 @@ import { Schema } from './schema';

label: string;
description: string | null;
caption: boolean;
stub: boolean;
uri: string;
type: string;
hidden: boolean;
required: boolean;
description?: string;
stub?: boolean;
caption?: boolean;
hidden?: boolean;
required?: boolean;
range?: string | null;
reverse?: string;
}
/**
* Definition of a property, with relevant metadata for type,
* labels and other useful criteria.
*/
export declare class Property {

@@ -30,3 +33,2 @@ readonly schema: Schema;

readonly hasReverse: boolean;
readonly uri: string;
private readonly range;

@@ -37,2 +39,3 @@ private readonly reverse;

getReverse(): Property;
toString(): string;
}

@@ -8,13 +8,12 @@ import { IPropertyDatum, Property } from './property';

export interface ISchemaDatum {
name: string;
label: string;
required: boolean;
plural: string;
schemata: string[];
extends: string[];
abstract: boolean;
matchable: boolean;
description: string | null;
edge: IEdgeSpecification;
featured: string[];
required?: boolean;
abstract?: boolean;
matchable?: boolean;
description?: string;
edge?: IEdgeSpecification;
featured?: string[];
properties: {

@@ -25,3 +24,4 @@ [x: string]: IPropertyDatum;

export declare class Schema {
properties: Map<string, Property>;
static readonly THING = "Thing";
static readonly DOCUMENT = "Document";
readonly model: Model;

@@ -37,12 +37,22 @@ readonly name: string;

readonly extends: string[];
readonly edge: IEdgeSpecification;
readonly edge?: IEdgeSpecification;
readonly isEdge: boolean;
constructor(model: Model, config: ISchemaDatum);
private properties;
constructor(model: Model, schemaName: string, config: ISchemaDatum);
isThing(): boolean;
isDocument(): boolean;
getFeaturedProperties(): (Property | undefined)[];
hasProperty(name: string): boolean;
getProperty(name: string): Property;
getExtends(): Array<Schema>;
getProperties(): Map<string, Property>;
getFeaturedProperties(): Property[];
hasProperty(prop: string | Property): boolean;
/**
* Get the value of a property. If it's not defined, return an
* empty array. If it's not a valid property, raise an error.
*
* @param prop name or Property
*/
getProperty(prop: string | Property): Property;
isA(schemaName: string): boolean;
toString(): string;
}
export {};
export interface IPropertyTypeDatum {
name: string;
group: string | null;
label: string;
plural: string;
matchable: boolean;
group?: string;
label?: string;
plural?: string | null;
matchable?: boolean;
}
/**
* A property type, such as a string, email address, phone number,
* URL or a related entity.
*/
export declare class PropertyType {

@@ -16,3 +19,4 @@ static ENTITY: string;

matchable: boolean;
constructor(data: IPropertyTypeDatum);
constructor(name: string, data: IPropertyTypeDatum);
toString(): string;
}
{
"name": "@alephdata/followthemoney",
"version": "1.1.0",
"version": "1.11.1",
"description": "JavaScript version of the followthemoney data model",

@@ -22,3 +22,3 @@ "keywords": [],

"scripts": {
"lint": "tslint --project tsconfig.json -t codeFrame 'src/**/*.ts' 'test/**/*.ts'",
"lint": "tslint --project tsconfig.json -t codeFrame 'src/**/*.ts' 'test/**/*.ts'",
"prebuild": "rimraf dist",

@@ -30,19 +30,4 @@ "build": "tsc --module commonjs && rollup -c rollup.config.ts",

"test:watch": "jest --coverage --watch",
"test:prod": "npm run lint && npm run test -- --no-cache",
"deploy-docs": "ts-node tools/gh-pages-publish",
"report-coverage": "cat ./coverage/lcov.info | coveralls",
"commit": "git-cz",
"semantic-release": "semantic-release"
"test:prod": "npm run lint && npm run test -- --no-cache"
},
"lint-staged": {
"{src,test}/**/*.ts": [
"prettier --write",
"git add"
]
},
"config": {
"commitizen": {
"path": "node_modules/cz-conventional-changelog"
}
},
"jest": {

@@ -79,34 +64,8 @@ "transform": {

},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"release": {
"branches": [
"+([1-9])?(.{+([1-9]),x}).x",
"master",
"next",
"next-major",
{
"name": "beta",
"prerelease": true
},
{
"name": "alpha",
"prerelease": true
}
]
},
"devDependencies": {
"@commitlint/cli": "^7.1.2",
"@commitlint/config-conventional": "^7.1.2",
"@types/jest": "^24.0.11",
"@types/node": "^11.12.0",
"colors": "^1.3.2",
"commitizen": "^3.0.0",
"coveralls": "^3.0.2",
"cross-env": "^5.2.0",
"cz-conventional-changelog": "^2.1.0",
"husky": "^1.3.1",
"jest": "^24.5.0",

@@ -126,3 +85,2 @@ "jest-config": "^24.0.0",

"rollup-plugin-typescript2": "^0.20.1",
"semantic-release": "beta",
"shelljs": "^0.8.3",

@@ -137,3 +95,6 @@ "ts-jest": "^24.0.0",

},
"dependencies": {}
"dependencies": {
"@types/uuid": "^3.4.4",
"uuid": "^3.3.2"
}
}
# followthemoney.js
Implementation of [Follow the money](https://github.com/alephdata/followthemoney) data model in javascript.
Should be moved to separated package at some point.
Implementation of [Follow the money](https://github.com/alephdata/followthemoney)
data model in TypeScript/JavaScript.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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