@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.
@@ -0,0 +1,93 @@
1
+ import { Schema } from './schema';
2
+ import { Model } from './model';
3
+ import { Property } from './property';
4
+ import { PropertyType } from './type';
5
+ export type Value = string | Entity;
6
+ export type Values = Array<Value>;
7
+ export type EntityProperties = {
8
+ [prop: string]: Array<Value | IEntityDatum>;
9
+ };
10
+ export interface IEntityDatum {
11
+ schema: Schema | string;
12
+ properties?: EntityProperties;
13
+ id: string;
14
+ }
15
+ /**
16
+ * An entity proxy which provides simplified access to the
17
+ * properties and schema associated with an entity.
18
+ */
19
+ export declare class Entity {
20
+ id: string;
21
+ properties: Map<Property, Values>;
22
+ readonly schema: Schema;
23
+ constructor(model: Model, data: IEntityDatum);
24
+ setProperty(prop: string | Property, value: Value | IEntityDatum | undefined | null): Values;
25
+ hasProperty(prop: string | Property): boolean;
26
+ getProperty(prop: string | Property): Values;
27
+ /**
28
+ * The first value of a property only.
29
+ *
30
+ * @param prop A property name or object
31
+ */
32
+ getFirst(prop: string | Property): Value | null;
33
+ /**
34
+ * List all properties for which this entity has values set. This
35
+ * does not include unset properties.
36
+ */
37
+ getProperties(): Array<Property>;
38
+ /**
39
+ * Copy the properties from a given entity that match the local
40
+ * schema to this entity.
41
+ */
42
+ copyProperties(entity: Entity): void;
43
+ /**
44
+ * Get the designated label for the given entity.
45
+ */
46
+ getCaption(): string;
47
+ /**
48
+ * Set the designated label as the first caption prop for the given entity.
49
+ */
50
+ setCaption(value: string): void;
51
+ /**
52
+ * Get the designated label for the given entity.
53
+ */
54
+ getEdgeCaption(): string;
55
+ /**
56
+ * Get a date that can be used to represent the start of the entity in a timeline.
57
+ * If there are multiple possible dates, the earliest date is returned.
58
+ */
59
+ getTemporalStart(): {
60
+ property: Property;
61
+ value: string;
62
+ } | null;
63
+ /**
64
+ * Get a date that can be used to represent the end of the entity in a timeline.
65
+ * If there are multiple possible dates, the earliest date is returned.
66
+ */
67
+ getTemporalEnd(): {
68
+ property: Property;
69
+ value: string;
70
+ } | null;
71
+ /**
72
+ * Get all the values of a particular type, irrespective of
73
+ * which property it is associated with.
74
+ */
75
+ getTypeValues(type: string | PropertyType, matchableOnly?: boolean): Values;
76
+ /**
77
+ * Serialise the entity to a plain JSON object, suitable for feeding to the
78
+ * JSON.stringify() call.
79
+ */
80
+ toJSON(): IEntityDatum;
81
+ /**
82
+ * Make a copy of the entity with no shared object identity.
83
+ */
84
+ clone(): Entity;
85
+ /**
86
+ * Shortcut helper function.
87
+ *
88
+ * @param model active FollowTheMoney model
89
+ * @param data the raw blob, which must match IEntityDatum
90
+ */
91
+ static fromJSON(model: Model, data: any): Entity;
92
+ static isEntity(value: Value): boolean;
93
+ }
package/dist/entity.js ADDED
@@ -0,0 +1,213 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Entity = void 0;
4
+ /**
5
+ * An entity proxy which provides simplified access to the
6
+ * properties and schema associated with an entity.
7
+ */
8
+ class Entity {
9
+ constructor(model, data) {
10
+ this.properties = new Map();
11
+ this.schema = model.getSchema(data.schema);
12
+ this.id = data.id;
13
+ if (data.properties) {
14
+ Object.entries(data.properties).forEach(([prop, values]) => {
15
+ values.forEach((value) => {
16
+ this.setProperty(prop, value);
17
+ });
18
+ });
19
+ }
20
+ }
21
+ setProperty(prop, value) {
22
+ const property = this.schema.getProperty(prop);
23
+ const values = this.properties.get(property) || [];
24
+ if (value === undefined || value === null) {
25
+ return values;
26
+ }
27
+ if (typeof (value) === 'string' && value.trim().length === 0) {
28
+ return values;
29
+ }
30
+ if (typeof (value) !== 'string') {
31
+ value = this.schema.model.getEntity(value);
32
+ }
33
+ values.push(value);
34
+ this.properties.set(property, values);
35
+ return values;
36
+ }
37
+ hasProperty(prop) {
38
+ try {
39
+ const property = this.schema.getProperty(prop);
40
+ return this.properties.has(property);
41
+ }
42
+ catch (_a) {
43
+ return false;
44
+ }
45
+ }
46
+ getProperty(prop) {
47
+ try {
48
+ const property = this.schema.getProperty(prop);
49
+ if (!this.properties.has(property)) {
50
+ return [];
51
+ }
52
+ return this.properties.get(property);
53
+ }
54
+ catch (_a) {
55
+ return [];
56
+ }
57
+ }
58
+ /**
59
+ * The first value of a property only.
60
+ *
61
+ * @param prop A property name or object
62
+ */
63
+ getFirst(prop) {
64
+ for (const value of this.getProperty(prop)) {
65
+ return value;
66
+ }
67
+ return null;
68
+ }
69
+ /**
70
+ * List all properties for which this entity has values set. This
71
+ * does not include unset properties.
72
+ */
73
+ getProperties() {
74
+ return Array.from(this.properties.keys());
75
+ }
76
+ /**
77
+ * Copy the properties from a given entity that match the local
78
+ * schema to this entity.
79
+ */
80
+ copyProperties(entity) {
81
+ entity.getProperties().forEach((prop) => {
82
+ if (this.schema.hasProperty(prop)) {
83
+ const localProp = this.schema.getProperty(prop.name);
84
+ if (localProp.qname === prop.qname) {
85
+ entity.getProperty(prop).forEach((value) => {
86
+ this.setProperty(localProp, value);
87
+ });
88
+ }
89
+ }
90
+ });
91
+ }
92
+ /**
93
+ * Get the designated label for the given entity.
94
+ */
95
+ getCaption() {
96
+ for (const property of this.schema.caption) {
97
+ for (const value of this.getProperty(property)) {
98
+ return value;
99
+ }
100
+ }
101
+ return this.schema.label;
102
+ }
103
+ /**
104
+ * Set the designated label as the first caption prop for the given entity.
105
+ */
106
+ setCaption(value) {
107
+ const captionProperties = this.schema.caption;
108
+ if (captionProperties && captionProperties.length > 0) {
109
+ this.setProperty(captionProperties[0], value);
110
+ }
111
+ }
112
+ /**
113
+ * Get the designated label for the given entity.
114
+ */
115
+ getEdgeCaption() {
116
+ const captions = this.schema.edge ? this.schema.edge.caption : [];
117
+ for (const property of captions) {
118
+ for (const value of this.getProperty(property)) {
119
+ return value;
120
+ }
121
+ }
122
+ return this.schema.label;
123
+ }
124
+ /**
125
+ * Get a date that can be used to represent the start of the entity in a timeline.
126
+ * If there are multiple possible dates, the earliest date is returned.
127
+ */
128
+ getTemporalStart() {
129
+ const values = [];
130
+ const properties = this.schema.getTemporalStartProperties();
131
+ for (const property of properties) {
132
+ for (const value of this.getProperty(property)) {
133
+ if (typeof value === 'string') {
134
+ values.push({ property, value });
135
+ }
136
+ }
137
+ }
138
+ const sortedValues = values.sort((a, b) => a.value < b.value ? -1 : 1);
139
+ return sortedValues[0] || null;
140
+ }
141
+ /**
142
+ * Get a date that can be used to represent the end of the entity in a timeline.
143
+ * If there are multiple possible dates, the earliest date is returned.
144
+ */
145
+ getTemporalEnd() {
146
+ const values = [];
147
+ const properties = this.schema.getTemporalEndProperties();
148
+ for (const property of properties) {
149
+ for (const value of this.getProperty(property)) {
150
+ if (typeof value === 'string') {
151
+ values.push({ property, value });
152
+ }
153
+ }
154
+ }
155
+ const sortedValues = values.sort((a, b) => b.value < a.value ? -1 : 1);
156
+ return sortedValues[0] || null;
157
+ }
158
+ /**
159
+ * Get all the values of a particular type, irrespective of
160
+ * which property it is associated with.
161
+ */
162
+ getTypeValues(type, matchableOnly = false) {
163
+ const propType = this.schema.model.getType(type);
164
+ const values = new Array();
165
+ for (const property of this.getProperties()) {
166
+ if (!matchableOnly || property.matchable) {
167
+ if (property.type.toString() === propType.toString()) {
168
+ for (const value of this.getProperty(property)) {
169
+ if (values.indexOf(value) === -1) {
170
+ values.push(value);
171
+ }
172
+ }
173
+ }
174
+ }
175
+ }
176
+ return values;
177
+ }
178
+ /**
179
+ * Serialise the entity to a plain JSON object, suitable for feeding to the
180
+ * JSON.stringify() call.
181
+ */
182
+ toJSON() {
183
+ const properties = {};
184
+ this.properties.forEach((values, prop) => {
185
+ properties[prop.name] = values.map((value) => Entity.isEntity(value) ? value.toJSON() : value);
186
+ });
187
+ return {
188
+ id: this.id,
189
+ schema: this.schema.name,
190
+ properties: properties
191
+ };
192
+ }
193
+ /**
194
+ * Make a copy of the entity with no shared object identity.
195
+ */
196
+ clone() {
197
+ return Entity.fromJSON(this.schema.model, this.toJSON());
198
+ }
199
+ /**
200
+ * Shortcut helper function.
201
+ *
202
+ * @param model active FollowTheMoney model
203
+ * @param data the raw blob, which must match IEntityDatum
204
+ */
205
+ static fromJSON(model, data) {
206
+ return model.getEntity(data);
207
+ }
208
+ static isEntity(value) {
209
+ return typeof (value) !== 'string';
210
+ }
211
+ }
212
+ exports.Entity = Entity;
213
+ //# sourceMappingURL=entity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity.js","sourceRoot":"","sources":["../src/entity.ts"],"names":[],"mappings":";;;AAeA;;;GAGG;AACH,MAAa,MAAM;IAKjB,YAAY,KAAY,EAAE,IAAkB;QAHrC,eAAU,GAA0B,IAAI,GAAG,EAAE,CAAA;QAIlD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAC1C,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAA;QAEjB,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE;gBACzD,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;oBACvB,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;gBAC/B,CAAC,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,WAAW,CAAC,IAAuB,EAAE,KAA8C;QACjF,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;QAC9C,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAA;QAClD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YAC1C,OAAO,MAAM,CAAA;QACf,CAAC;Q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C,IAAI,CAAC,KAAK,CAAC,CAAA;wBACpB,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;IAED;;;OAGG;IACH,MAAM;QACJ,MAAM,UAAU,GAAqB,EAAE,CAAA;QACvC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;YACvC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAC3C,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAE,KAAgB,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,KAAK,CAC5D,CAAA;QACH,CAAC,CAAC,CAAA;QACF,OAAO;YACL,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI;YACxB,UAAU,EAAE,UAAU;SACvB,CAAA;IACH,CAAC;IAED;;OAEG;IACH,KAAK;QACH,OAAO,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAA;IAC1D,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,CAAC,KAAY,EAAE,IAAS;QACrC,OAAO,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IAC9B,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,KAAY;QAC1B,OAAO,OAAO,CAAC,KAAK,CAAC,KAAK,QAAQ,CAAA;IACpC,CAAC;CACF;AAzOD,wBAyOC"}
@@ -0,0 +1,9 @@
1
+ export * from './entity';
2
+ export * from './model';
3
+ export * from './namespace';
4
+ export * from './property';
5
+ export * from './schema';
6
+ export * from './type';
7
+ export * from './icons';
8
+ import { IModelDatum } from './model';
9
+ export declare const defaultModel: IModelDatum;