@opensanctions/followthemoney 3.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/model.js ADDED
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Model = void 0;
4
+ const schema_1 = require("./schema");
5
+ const entity_1 = require("./entity");
6
+ const type_1 = require("./type");
7
+ const uuid_1 = require("uuid");
8
+ class Model {
9
+ constructor(config) {
10
+ this.schemata = {};
11
+ this.types = {};
12
+ this.types = {};
13
+ Object.entries(config.types).forEach(([typeName, typeData]) => {
14
+ this.types[typeName] = new type_1.PropertyType(typeName, typeData);
15
+ });
16
+ this.schemata = {};
17
+ Object.entries(config.schemata).forEach(([schemaName, schema]) => {
18
+ this.schemata[schemaName] = new schema_1.Schema(this, schemaName, schema);
19
+ });
20
+ }
21
+ getSchema(schemaName) {
22
+ if (schemaName === null || schemaName === undefined) {
23
+ throw new Error('Invalid schema.');
24
+ }
25
+ if (schemaName instanceof schema_1.Schema) {
26
+ return schemaName;
27
+ }
28
+ const schema = this.schemata[schemaName];
29
+ if (schema === undefined) {
30
+ throw new Error('No such schema: ' + schemaName);
31
+ }
32
+ return schema;
33
+ }
34
+ /**
35
+ * Get a list of all schemata.
36
+ */
37
+ getSchemata() {
38
+ return Object.keys(this.schemata)
39
+ .map((name) => this.schemata[name])
40
+ .filter(schema_1.Schema.isSchema);
41
+ }
42
+ /**
43
+ * Get a list of all unique properties.
44
+ */
45
+ getProperties() {
46
+ const qnames = new Map();
47
+ this.getSchemata().forEach((schema) => {
48
+ schema.getProperties().forEach((prop) => {
49
+ qnames.set(prop.qname, prop);
50
+ });
51
+ });
52
+ return Array.from(qnames.values());
53
+ }
54
+ /**
55
+ * Get a particular property type.
56
+ *
57
+ * @param type name of the type
58
+ */
59
+ getType(type) {
60
+ if (type instanceof type_1.PropertyType) {
61
+ return type;
62
+ }
63
+ return this.types[type];
64
+ }
65
+ /**
66
+ * Convert a raw JSON object to an entity proxy.
67
+ *
68
+ * @param raw entity source data
69
+ */
70
+ getEntity(raw) {
71
+ if (raw instanceof entity_1.Entity) {
72
+ return raw;
73
+ }
74
+ else {
75
+ return new entity_1.Entity(this, raw);
76
+ }
77
+ }
78
+ /**
79
+ * Make a new object with the given schema, and generate a random ID for
80
+ * it.
81
+ *
82
+ * @param schema Schema name or object
83
+ */
84
+ createEntity(schema, namespace) {
85
+ const rawId = (0, uuid_1.v4)();
86
+ const id = namespace ? namespace.sign(rawId) : rawId;
87
+ return this.getEntity({
88
+ id,
89
+ schema: schema,
90
+ properties: {}
91
+ });
92
+ }
93
+ }
94
+ exports.Model = Model;
95
+ //# sourceMappingURL=model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":";;;AAAA,qCAA+C;AAC/C,qCAA+C;AAE/C,iCAAyD;AAEzD,+BAAoC;AAQpC,MAAa,KAAK;IAIhB,YAAY,MAAmB;QAHf,aAAQ,GAAwC,EAAE,CAAA;QAClD,UAAK,GAAkC,EAAE,CAAA;QAGvD,IAAI,CAAC,KAAK,GAAG,EAAE,CAAA;QACf,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAClC,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,EAAE;YACvB,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,IAAI,mBAAY,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;QAC7D,CAAC,CACF,CAAA;QAED,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAA;QAClB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CACrC,CAAC,CAAC,UAAU,EAAE,MAAM,CAAC,EAAE,EAAE;YACvB,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,IAAI,eAAM,CAAC,IAAI,EAA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AAY,mBAAY,EAAE,CAAC;YACjC,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACzB,CAAC;IAED;;;;OAIG;IACH,SAAS,CAAC,GAA0B;QAClC,IAAI,GAAG,YAAY,eAAM,EAAE,CAAC;YAC1B,OAAO,GAAG,CAAA;QACZ,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,eAAM,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;QAC9B,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,YAAY,CAAC,MAAuB,EAAE,SAAqB;QACzD,MAAM,KAAK,GAAG,IAAA,SAAM,GAAE,CAAC;QACvB,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QACrD,OAAO,IAAI,CAAC,SAAS,CAAC;YACpB,EAAE;YACF,MAAM,EAAE,MAAM;YACd,UAAU,EAAE,EAAE;SACf,CAAC,CAAA;IACJ,CAAC;CACF;AAhGD,sBAgGC"}
@@ -0,0 +1,8 @@
1
+ export declare class Namespace {
2
+ private separator;
3
+ private namespaceKey;
4
+ constructor(namespaceKey: string);
5
+ parse(id: string): string[];
6
+ signature(id: string): string;
7
+ sign(id: string): string;
8
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Namespace = void 0;
7
+ const crypto_1 = __importDefault(require("crypto"));
8
+ class Namespace {
9
+ constructor(namespaceKey) {
10
+ this.separator = '.';
11
+ this.namespaceKey = namespaceKey;
12
+ }
13
+ parse(id) {
14
+ return id.split(this.separator);
15
+ }
16
+ signature(id) {
17
+ return crypto_1.default.createHmac('sha1', this.namespaceKey)
18
+ .update(id)
19
+ .digest('hex');
20
+ }
21
+ sign(id) {
22
+ const entityId = this.parse(id)[0];
23
+ if (!entityId) {
24
+ return id;
25
+ }
26
+ if (!this.namespaceKey.length) {
27
+ return entityId;
28
+ }
29
+ const digest = this.signature(entityId);
30
+ return [entityId, digest].join(this.separator);
31
+ }
32
+ }
33
+ exports.Namespace = Namespace;
34
+ //# sourceMappingURL=namespace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"namespace.js","sourceRoot":"","sources":["../src/namespace.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAE5B,MAAa,SAAS;IAIpB,YAAY,YAAoB;QAHxB,cAAS,GAAG,GAAG,CAAA;QAIrB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,EAAU;QACd,OAAO,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAClC,CAAC;IAED,SAAS,CAAC,EAAU;QAClB,OAAO,gBAAM,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC;aAChD,MAAM,CAAC,EAAE,CAAC;aACV,MAAM,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC;IAED,IAAI,CAAC,EAAU;QACb,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACnC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;YAC9B,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QAExC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACjD,CAAC;CACF;AA9BD,8BA8BC"}
@@ -0,0 +1,44 @@
1
+ import { Schema } from './schema';
2
+ import { PropertyType } from './type';
3
+ export interface IPropertyDatum {
4
+ name: string;
5
+ qname: string;
6
+ label: string;
7
+ type: string;
8
+ description?: string;
9
+ maxLength?: number;
10
+ format?: string;
11
+ stub?: boolean;
12
+ hidden?: boolean;
13
+ matchable?: boolean;
14
+ deprecated?: boolean;
15
+ range?: string | null;
16
+ reverse?: string;
17
+ }
18
+ /**
19
+ * Definition of a property, with relevant metadata for type,
20
+ * labels and other useful criteria.
21
+ */
22
+ export declare class Property {
23
+ readonly schema: Schema;
24
+ readonly name: string;
25
+ readonly qname: string;
26
+ readonly label: string;
27
+ readonly type: PropertyType;
28
+ readonly hidden: boolean;
29
+ readonly matchable: boolean;
30
+ readonly deprecated: boolean;
31
+ readonly description: string | null;
32
+ readonly format: string | null;
33
+ readonly stub: boolean;
34
+ readonly maxLength: number;
35
+ readonly hasReverse: boolean;
36
+ readonly hasRange: boolean;
37
+ private readonly range;
38
+ private readonly reverse;
39
+ constructor(schema: Schema, property: IPropertyDatum);
40
+ getRange(): Schema;
41
+ getReverse(): Property;
42
+ static isProperty: (item: Property | undefined) => item is Property;
43
+ toString(): string;
44
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Property = void 0;
4
+ /**
5
+ * Definition of a property, with relevant metadata for type,
6
+ * labels and other useful criteria.
7
+ */
8
+ class Property {
9
+ constructor(schema, property) {
10
+ this.schema = schema;
11
+ this.name = property.name;
12
+ this.qname = property.qname;
13
+ this.label = property.label || property.name;
14
+ this.hidden = !!property.hidden;
15
+ this.description = property.description || null;
16
+ this.format = property.format || null;
17
+ this.stub = !!property.stub;
18
+ this.maxLength = property.maxLength || 0;
19
+ this.matchable = !!property.matchable;
20
+ this.deprecated = !!property.deprecated;
21
+ this.range = property.range || null;
22
+ this.reverse = property.reverse || null;
23
+ this.type = schema.model.getType(property.type);
24
+ this.hasRange = this.range !== null;
25
+ this.hasReverse = this.range !== null && this.reverse !== null;
26
+ }
27
+ getRange() {
28
+ return this.schema.model.getSchema(this.range);
29
+ }
30
+ getReverse() {
31
+ if (this.range === null || this.reverse === null) {
32
+ throw new Error("This property has no reverse");
33
+ }
34
+ return this.getRange().getProperty(this.reverse);
35
+ }
36
+ toString() {
37
+ return this.qname;
38
+ }
39
+ }
40
+ exports.Property = Property;
41
+ Property.isProperty = (item) => {
42
+ return !!item;
43
+ };
44
+ //# sourceMappingURL=property.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"property.js","sourceRoot":"","sources":["../src/property.ts"],"names":[],"mappings":";;;AAmBA;;;GAGG;AACH,MAAa,QAAQ;IAkBnB,YAAY,MAAc,EAAE,QAAwB;QAClD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAA;QACzB,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAA;QAC3B,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,IAAI,QAAQ,CAAC,IAAI,CAAA;QAC5C,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAA;QAC/B,IAAI,CAAC,WAAW,GAAG,QAAQ,CAAC,WAAW,IAAI,IAAI,CAAA;QAC/C,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,IAAI,IAAI,CAAA;QACrC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAA;QAC3B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,SAAS,IAAI,CAAC,CAAA;QACxC,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAA;QACrC,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAA;QACvC,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,IAAI,IAAI,CAAA;QACnC,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,OAAO,IAAI,IAAI,CAAA;QACvC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;QAC/C,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK,KAAK,IAAI,CAAA;QACnC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,KAAK,KAAK,IAAI,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,CAAA;IAChE,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAChD,CAAC;IAED,UAAU;QACR,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;YACjD,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;QACjD,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAClD,CAAC;IAMD,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;;AAtDH,4BAuDC;AAPQ,mBAAU,GAAG,CAAC,IAA0B,EAAoB,EAAE;IACnE,OAAO,CAAC,CAAC,IAAI,CAAA;AACf,CAAC,CAAA"}
@@ -0,0 +1,83 @@
1
+ import { IPropertyDatum, Property } from './property';
2
+ import { Model } from './model';
3
+ interface IEdgeSpecification {
4
+ source: string;
5
+ target: string;
6
+ directed: boolean;
7
+ label?: string;
8
+ caption: string[];
9
+ required?: string[];
10
+ }
11
+ interface ITemporalExtentSpecification {
12
+ start: string[];
13
+ end: string[];
14
+ }
15
+ export type SchemaSpec = string | null | undefined | Schema;
16
+ export interface ISchemaDatum {
17
+ label: string;
18
+ plural: string;
19
+ schemata: string[];
20
+ extends: string[];
21
+ abstract?: boolean;
22
+ hidden?: boolean;
23
+ matchable?: boolean;
24
+ generated?: boolean;
25
+ deprecated?: boolean;
26
+ description?: string;
27
+ edge?: IEdgeSpecification;
28
+ temporalExtent?: ITemporalExtentSpecification;
29
+ featured?: string[];
30
+ caption?: string[];
31
+ required?: string[];
32
+ properties: {
33
+ [x: string]: IPropertyDatum;
34
+ };
35
+ }
36
+ export declare class Schema {
37
+ static readonly THING = "Thing";
38
+ static readonly DOCUMENT = "Document";
39
+ readonly model: Model;
40
+ readonly name: string;
41
+ readonly label: string;
42
+ readonly plural: string;
43
+ readonly abstract: boolean;
44
+ readonly hidden: boolean;
45
+ readonly matchable: boolean;
46
+ readonly generated: boolean;
47
+ readonly deprecated: boolean;
48
+ readonly description: string | null;
49
+ readonly featured: string[];
50
+ readonly schemata: string[];
51
+ readonly extends: string[];
52
+ readonly caption: string[];
53
+ readonly required: string[];
54
+ readonly edge?: IEdgeSpecification;
55
+ readonly isEdge: boolean;
56
+ readonly temporalStart: string[];
57
+ readonly temporalEnd: string[];
58
+ private properties;
59
+ constructor(model: Model, schemaName: string, config: ISchemaDatum);
60
+ isThing(): boolean;
61
+ isDocument(): boolean;
62
+ getExtends(): Array<Schema>;
63
+ getParents(): Array<Schema>;
64
+ getChildren(): Array<Schema>;
65
+ getProperties(qualified?: boolean): Map<string, Property>;
66
+ getEditableProperties(): Array<Property>;
67
+ getFeaturedProperties(): Array<Property>;
68
+ getTemporalStartProperties(): Array<Property>;
69
+ getTemporalEndProperties(): Array<Property>;
70
+ hasProperty(prop: string | Property): boolean;
71
+ /**
72
+ * Get the value of a property. If it's not defined, return an
73
+ * empty array. If it's not a valid property, raise an error.
74
+ *
75
+ * @param prop name or Property
76
+ */
77
+ getProperty(prop: string | Property): Property;
78
+ isA(schema: SchemaSpec): boolean;
79
+ isAny(schemata: Array<SchemaSpec>): boolean;
80
+ static isSchema: (item: Schema | undefined) => item is Schema;
81
+ toString(): string;
82
+ }
83
+ export {};
package/dist/schema.js ADDED
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Schema = void 0;
4
+ const property_1 = require("./property");
5
+ class Schema {
6
+ constructor(model, schemaName, config) {
7
+ var _a, _b;
8
+ this.properties = new Map();
9
+ this.model = model;
10
+ this.name = schemaName;
11
+ this.label = config.label || this.name;
12
+ this.plural = config.plural || this.label;
13
+ this.schemata = config.schemata;
14
+ this.extends = config.extends;
15
+ this.featured = config.featured || [];
16
+ this.caption = config.caption || [];
17
+ this.required = config.required || [];
18
+ this.abstract = !!config.abstract;
19
+ this.hidden = !!config.hidden;
20
+ this.matchable = !!config.matchable;
21
+ this.generated = !!config.generated;
22
+ this.deprecated = !!config.deprecated;
23
+ this.description = config.description || null;
24
+ this.isEdge = !!config.edge;
25
+ this.edge = config.edge;
26
+ this.temporalStart = ((_a = config.temporalExtent) === null || _a === void 0 ? void 0 : _a.start) || [];
27
+ this.temporalEnd = ((_b = config.temporalExtent) === null || _b === void 0 ? void 0 : _b.end) || [];
28
+ Object.entries(config.properties).forEach(([propertyName, property]) => {
29
+ this.properties.set(propertyName, new property_1.Property(this, property));
30
+ });
31
+ }
32
+ isThing() {
33
+ return this.isA(Schema.THING);
34
+ }
35
+ isDocument() {
36
+ return this.isA(Schema.DOCUMENT);
37
+ }
38
+ getExtends() {
39
+ return this.extends.map(name => this.model.getSchema(name));
40
+ }
41
+ getParents() {
42
+ const parents = new Map();
43
+ for (const ext of this.getExtends()) {
44
+ parents.set(ext.name, ext);
45
+ for (const parent of ext.getParents()) {
46
+ parents.set(parent.name, parent);
47
+ }
48
+ }
49
+ return Array.from(parents.values());
50
+ }
51
+ getChildren() {
52
+ const children = new Array();
53
+ for (const schema of this.model.getSchemata()) {
54
+ const parents = schema.getParents().map(s => s.name);
55
+ if (parents.indexOf(this.name) !== -1) {
56
+ children.push(schema);
57
+ }
58
+ }
59
+ return children;
60
+ }
61
+ getProperties(qualified = false) {
62
+ const properties = new Map();
63
+ this.getExtends().forEach((schema) => {
64
+ schema.getProperties(qualified).forEach((prop, name) => {
65
+ properties.set(name, prop);
66
+ });
67
+ });
68
+ this.properties.forEach((prop, name) => {
69
+ properties.set(qualified ? prop.qname : name, prop);
70
+ });
71
+ return properties;
72
+ }
73
+ getEditableProperties() {
74
+ return Array.from(this.getProperties().values())
75
+ .filter(prop => !prop.hidden && !prop.stub);
76
+ }
77
+ getFeaturedProperties() {
78
+ return this.featured.map(name => this.getProperty(name));
79
+ }
80
+ getTemporalStartProperties() {
81
+ const properties = new Set(this.temporalStart);
82
+ for (const ext of this.getExtends()) {
83
+ for (const property of ext.getTemporalStartProperties()) {
84
+ properties.add(property.name);
85
+ }
86
+ }
87
+ return Array.from(properties).map((name) => this.getProperty(name));
88
+ }
89
+ getTemporalEndProperties() {
90
+ const properties = new Set(this.temporalEnd);
91
+ for (const ext of this.getExtends()) {
92
+ for (const property of ext.getTemporalEndProperties()) {
93
+ properties.add(property.name);
94
+ }
95
+ }
96
+ return Array.from(properties).map((name) => this.getProperty(name));
97
+ }
98
+ hasProperty(prop) {
99
+ if (prop instanceof property_1.Property) {
100
+ return this.getProperties(true).has(prop.qname);
101
+ }
102
+ return this.getProperties().has(prop);
103
+ }
104
+ /**
105
+ * Get the value of a property. If it's not defined, return an
106
+ * empty array. If it's not a valid property, raise an error.
107
+ *
108
+ * @param prop name or Property
109
+ */
110
+ getProperty(prop) {
111
+ if (prop instanceof property_1.Property) {
112
+ return prop;
113
+ }
114
+ if (this.hasProperty(prop)) {
115
+ return this.getProperties().get(prop);
116
+ }
117
+ else {
118
+ throw new Error('Property does not exist: ' + prop);
119
+ }
120
+ }
121
+ isA(schema) {
122
+ try {
123
+ schema = this.model.getSchema(schema);
124
+ return !!~this.schemata.indexOf(schema.name);
125
+ }
126
+ catch (_a) {
127
+ return false;
128
+ }
129
+ }
130
+ isAny(schemata) {
131
+ for (const schema of schemata) {
132
+ if (this.isA(schema)) {
133
+ return true;
134
+ }
135
+ }
136
+ return false;
137
+ }
138
+ toString() {
139
+ return this.name;
140
+ }
141
+ }
142
+ exports.Schema = Schema;
143
+ Schema.THING = 'Thing';
144
+ Schema.DOCUMENT = 'Document';
145
+ Schema.isSchema = (item) => {
146
+ return !!item;
147
+ };
148
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":";;;AAAA,yCAAqD;AAwCrD,MAAa,MAAM;IAyBjB,YAAY,KAAY,EAAE,UAAkB,EAAE,MAAoB;;QAF1D,eAAU,GAA0B,IAAI,GAAG,EAAE,CAAA;QAGnD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,IAAI,GAAG,UAAU,CAAA;QACtB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC;QAC1C,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAA;QAC/B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAA;QAC7B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAA;QACrC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,EAAE,CAAA;QACnC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAA;QACrC,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAA;QACjC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,MAAM,CAAA;QAC7B,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC,SAAS,CAAA;QACnC,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC,SAAS,CAAA;QACnC,IAAI,CAAC,UAAU,GAAG,CAA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O,KAAK,CAAC;IACf,CAAC;IAMD,QAAQ;QACN,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;;AArLH,wBAsLC;AArLiB,YAAK,GAAG,OAAO,AAAV,CAAU;AACf,eAAQ,GAAG,UAAU,AAAb,CAAa;AA6K9B,eAAQ,GAAG,CAAC,IAAwB,EAAkB,EAAE;IAC7D,OAAO,CAAC,CAAC,IAAI,CAAA;AACf,CAAC,AAFc,CAEd"}
package/dist/type.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ export interface IPropertyTypeDatum {
2
+ group?: string;
3
+ label?: string;
4
+ description?: string;
5
+ maxLength?: number;
6
+ plural?: string | null;
7
+ matchable?: boolean;
8
+ pivot?: boolean;
9
+ values?: {
10
+ [name: string]: string;
11
+ };
12
+ }
13
+ /**
14
+ * A property type, such as a string, email address, phone number,
15
+ * URL or a related entity.
16
+ */
17
+ export declare class PropertyType {
18
+ static ENTITY: string;
19
+ name: string;
20
+ group: string | null;
21
+ grouped: boolean;
22
+ label: string;
23
+ plural: string;
24
+ description: string | null;
25
+ maxLength: number;
26
+ matchable: boolean;
27
+ pivot: boolean;
28
+ values: Map<string, string>;
29
+ isEntity: boolean;
30
+ constructor(name: string, data: IPropertyTypeDatum);
31
+ getLabel(value: string | undefined | null): string;
32
+ toString(): string;
33
+ }
package/dist/type.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PropertyType = void 0;
4
+ /**
5
+ * A property type, such as a string, email address, phone number,
6
+ * URL or a related entity.
7
+ */
8
+ class PropertyType {
9
+ constructor(name, data) {
10
+ this.name = name;
11
+ this.label = data.label || name;
12
+ this.description = data.description || null;
13
+ this.maxLength = data.maxLength || 0;
14
+ this.plural = data.plural || this.label;
15
+ this.group = data.group || null;
16
+ this.grouped = data.group !== undefined;
17
+ this.matchable = !!data.matchable;
18
+ this.pivot = !!data.pivot;
19
+ this.isEntity = name === PropertyType.ENTITY;
20
+ this.values = new Map();
21
+ if (data.values) {
22
+ Object.entries(data.values).forEach(([value, label]) => {
23
+ this.values.set(value, label);
24
+ });
25
+ }
26
+ }
27
+ getLabel(value) {
28
+ if (!value) {
29
+ return '';
30
+ }
31
+ return this.values.get(value) || value;
32
+ }
33
+ toString() {
34
+ return this.name;
35
+ }
36
+ }
37
+ exports.PropertyType = PropertyType;
38
+ PropertyType.ENTITY = 'entity';
39
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":";;;AAYA;;;GAGG;AACH,MAAa,YAAY;IAevB,YAAY,IAAY,EAAE,IAAwB;QAChD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAA;QAC/B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,IAAI,IAAI,CAAA;QAC3C,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,CAAC,CAAA;QACpC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAA;QACvC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAA;QAC/B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,KAAK,SAAS,CAAA;QACvC,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,CAAA;QACjC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAA;QACzB,IAAI,CAAC,QAAQ,GAAG,IAAI,KAAK,YAAY,CAAC,MAAM,CAAA;QAC5C,IAAI,CAAC,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAA;QAEvC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE;gBACrD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;YAC/B,CAAC,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,QAAQ,CAAC,KAAgC;QACrC,IAAI,CAAC,KAAK,EAAE,CAAC;YACT,OAAO,EAAE,CAAA;QACb,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,CAAA;IAC1C,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;;AA5CH,oCA6CC;AA5CQ,mBAAM,GAAG,QAAQ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,97 @@
1
+ {
2
+ "name": "@opensanctions/followthemoney",
3
+ "version": "3.8.4",
4
+ "description": "JavaScript version of the followthemoney data model",
5
+ "keywords": [],
6
+ "main": "dist/followthemoney.umd.js",
7
+ "module": "dist/followthemoney.es5.js",
8
+ "typings": "dist/followthemoney.d.ts",
9
+ "sideEffects": false,
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "author": "OCCRP Data <data@occrp.org>",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/opensanctions/followthemoney"
17
+ },
18
+ "license": "MIT",
19
+ "engines": {
20
+ "node": ">=8.0.0"
21
+ },
22
+ "scripts": {
23
+ "lint": "eslint src",
24
+ "prebuild": "rimraf dist && npm run build:icons",
25
+ "build:icons": "node scripts/buildIcons.js",
26
+ "build": "tsc --module commonjs && rollup -c rollup.config.mjs",
27
+ "start": "npm run build:icons && rollup -c rollup.config.mjs -w",
28
+ "test": "jest --coverage",
29
+ "test:watch": "jest --coverage --watch",
30
+ "test:prod": "npm run lint && npm run test -- --no-cache"
31
+ },
32
+ "jest": {
33
+ "transform": {
34
+ ".(ts|tsx)": "ts-jest"
35
+ },
36
+ "testEnvironment": "node",
37
+ "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
38
+ "moduleFileExtensions": [
39
+ "ts",
40
+ "tsx",
41
+ "js"
42
+ ],
43
+ "coveragePathIgnorePatterns": [
44
+ "/node_modules/",
45
+ "/test/"
46
+ ],
47
+ "coverageThreshold": {
48
+ "global": {
49
+ "branches": 0,
50
+ "functions": 0,
51
+ "lines": 0,
52
+ "statements": 0
53
+ }
54
+ },
55
+ "collectCoverageFrom": [
56
+ "src/**/*.{js,ts}"
57
+ ]
58
+ },
59
+ "prettier": {
60
+ "semi": false,
61
+ "singleQuote": true
62
+ },
63
+ "devDependencies": {
64
+ "@eslint/js": "^9.17.0",
65
+ "@rollup/plugin-commonjs": "~28.0.2",
66
+ "@rollup/plugin-json": "~6.1.0",
67
+ "@rollup/plugin-node-resolve": "~16.0.0",
68
+ "@rollup/plugin-typescript": "^12.1.2",
69
+ "@types/eslint__js": "^8.42.3",
70
+ "@types/jest": "^30.0.0",
71
+ "@types/node": "^24.0.4",
72
+ "@types/uuid": "^10.0.0",
73
+ "@typescript-eslint/eslint-plugin": "^8.19.1",
74
+ "@typescript-eslint/parser": "^8.19.1",
75
+ "colors": "~1.4.0",
76
+ "cross-env": "~7.0.3",
77
+ "eslint": "^9.17.0",
78
+ "jest": "^30.0.3",
79
+ "jest-config": "~30.0.3",
80
+ "lint-staged": "^16.1.2",
81
+ "prettier": "^3.4.2",
82
+ "prompt": "^1.3.0",
83
+ "replace-in-file": "~8.3.0",
84
+ "rimraf": "~6.0.1",
85
+ "rollup": "^4.30.1",
86
+ "shelljs": "^0.10.0",
87
+ "svgo": "~4.0.0",
88
+ "ts-jest": "^29.2.5",
89
+ "ts-node": "~10.9.2",
90
+ "tslib": "^2.8.1",
91
+ "typescript": "^5.7.2",
92
+ "typescript-eslint": "^8.19.1"
93
+ },
94
+ "dependencies": {
95
+ "uuid": "~11.1.0"
96
+ }
97
+ }