@twin.org/auditable-item-graph-service 0.10.1-next.2 → 0.10.1-next.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/es/auditableItemGraphService.js +25 -24
- package/dist/es/auditableItemGraphService.js.map +1 -1
- package/dist/es/entities/auditableItemGraphVertexIndex.js +14 -2
- package/dist/es/entities/auditableItemGraphVertexIndex.js.map +1 -1
- package/dist/es/index.js +1 -0
- package/dist/es/index.js.map +1 -1
- package/dist/es/utils/auditableItemGraphVertexIndexHelper.js +56 -0
- package/dist/es/utils/auditableItemGraphVertexIndexHelper.js.map +1 -0
- package/dist/types/entities/auditableItemGraphVertexIndex.d.ts +8 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/utils/auditableItemGraphVertexIndexHelper.d.ts +24 -0
- package/docs/changelog.md +28 -0
- package/docs/reference/classes/AuditableItemGraphVertexIndex.md +12 -0
- package/docs/reference/classes/AuditableItemGraphVertexIndexHelper.md +83 -0
- package/docs/reference/index.md +1 -0
- package/package.json +3 -2
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { HealthCategory, HealthStatus } from "@twin.org/api-models";
|
|
4
4
|
import { AuditableItemGraphAuditMode, AuditableItemGraphContexts, AuditableItemGraphDataTypes, AuditableItemGraphMetricIds, AuditableItemGraphMetrics, AuditableItemGraphTopics, AuditableItemGraphTypes, VerifyDepth } from "@twin.org/auditable-item-graph-models";
|
|
5
5
|
import { ContextIdHelper, ContextIdKeys, ContextIdStore } from "@twin.org/context";
|
|
6
|
-
import { ArrayHelper, BaseError, Coerce, ComponentFactory,
|
|
6
|
+
import { ArrayHelper, BaseError, Coerce, ComponentFactory, GeneralError, Guards, Is, JsonHelper, Mutex, NotFoundError, ObjectHelper, RandomHelper, StringHelper, Urn, Validation } from "@twin.org/core";
|
|
7
7
|
import { DataTypeHelper } from "@twin.org/data-core";
|
|
8
8
|
import { JsonLdDataTypes, JsonLdHelper, JsonLdProcessor } from "@twin.org/data-json-ld";
|
|
9
9
|
import { ComparisonOperator, LogicalOperator, SortDirection } from "@twin.org/entity";
|
|
@@ -11,6 +11,7 @@ import { EntityStorageConnectorFactory } from "@twin.org/entity-storage-models";
|
|
|
11
11
|
import { ImmutableProofContexts, ImmutableProofFailure, ImmutableProofTypes } from "@twin.org/immutable-proof-models";
|
|
12
12
|
import { SchemaOrgContexts, SchemaOrgDataTypes, SchemaOrgTypes } from "@twin.org/standards-schema-org";
|
|
13
13
|
import { MetricHelper } from "@twin.org/telemetry-models";
|
|
14
|
+
import { AuditableItemGraphVertexIndexHelper } from "./utils/auditableItemGraphVertexIndexHelper.js";
|
|
14
15
|
/**
|
|
15
16
|
* Class for performing auditable item graph operations.
|
|
16
17
|
*/
|
|
@@ -1624,7 +1625,7 @@ export class AuditableItemGraphService {
|
|
|
1624
1625
|
property: "vertexId",
|
|
1625
1626
|
comparison: ComparisonOperator.Equals,
|
|
1626
1627
|
value: vertex.id
|
|
1627
|
-
}, ["id", "type", "value", "dateCreated", "dateModified"]);
|
|
1628
|
+
}, ["id", "type", "value", "valueHash", "dateCreated", "dateModified"]);
|
|
1628
1629
|
// Collapse by row id first. A paged read can return the same row on more than one page,
|
|
1629
1630
|
// and without this a retained row could be queued for removal by its own duplicate.
|
|
1630
1631
|
const existingById = new Map();
|
|
@@ -1643,16 +1644,13 @@ export class AuditableItemGraphService {
|
|
|
1643
1644
|
const requiredEntry = required.get(key);
|
|
1644
1645
|
if (!Is.empty(requiredEntry) && !retainedKeys.has(key)) {
|
|
1645
1646
|
retainedKeys.add(key);
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
dateCreated: vertex.dateCreated,
|
|
1654
|
-
dateModified: indexDateModified
|
|
1655
|
-
});
|
|
1647
|
+
const requiredIndexEntry = AuditableItemGraphVertexIndexHelper.createIndexEntry(vertex.id, requiredEntry.type, requiredEntry.value, vertex.dateCreated, indexDateModified);
|
|
1648
|
+
if (entry.dateCreated !== requiredIndexEntry.dateCreated ||
|
|
1649
|
+
entry.dateModified !== requiredIndexEntry.dateModified ||
|
|
1650
|
+
entry.valueHash !== requiredIndexEntry.valueHash) {
|
|
1651
|
+
// Keep the row id so the copied dates and hash are corrected in place rather than
|
|
1652
|
+
// duplicated.
|
|
1653
|
+
writeEntries.push({ ...requiredIndexEntry, id });
|
|
1656
1654
|
}
|
|
1657
1655
|
}
|
|
1658
1656
|
else {
|
|
@@ -1661,14 +1659,7 @@ export class AuditableItemGraphService {
|
|
|
1661
1659
|
}
|
|
1662
1660
|
for (const [key, entry] of required) {
|
|
1663
1661
|
if (!retainedKeys.has(key)) {
|
|
1664
|
-
writeEntries.push(
|
|
1665
|
-
id: Converter.bytesToHex(RandomHelper.generate(16)),
|
|
1666
|
-
vertexId: vertex.id,
|
|
1667
|
-
type: entry.type,
|
|
1668
|
-
value: entry.value,
|
|
1669
|
-
dateCreated: vertex.dateCreated,
|
|
1670
|
-
dateModified: indexDateModified
|
|
1671
|
-
});
|
|
1662
|
+
writeEntries.push(AuditableItemGraphVertexIndexHelper.createIndexEntry(vertex.id, entry.type, entry.value, vertex.dateCreated, indexDateModified));
|
|
1672
1663
|
}
|
|
1673
1664
|
}
|
|
1674
1665
|
if (removeIds.length > 0) {
|
|
@@ -1709,7 +1700,8 @@ export class AuditableItemGraphService {
|
|
|
1709
1700
|
};
|
|
1710
1701
|
}
|
|
1711
1702
|
/**
|
|
1712
|
-
* Build the condition matching one index type and value.
|
|
1703
|
+
* Build the condition matching one index type and value. Exact matches are looked up by the
|
|
1704
|
+
* value hash, a partial match can only be answered by the value itself.
|
|
1713
1705
|
* @param type The index type to match.
|
|
1714
1706
|
* @param comparison The comparison to apply to the value.
|
|
1715
1707
|
* @param value The index value or values to match, already lower cased.
|
|
@@ -1717,11 +1709,20 @@ export class AuditableItemGraphService {
|
|
|
1717
1709
|
* @internal
|
|
1718
1710
|
*/
|
|
1719
1711
|
indexTypeValueCondition(type, comparison, value) {
|
|
1712
|
+
const valueCondition = comparison === ComparisonOperator.Includes
|
|
1713
|
+
? { property: "value", comparison, value }
|
|
1714
|
+
: {
|
|
1715
|
+
property: "valueHash",
|
|
1716
|
+
comparison,
|
|
1717
|
+
value: Is.array(value)
|
|
1718
|
+
? value.map(v => AuditableItemGraphVertexIndexHelper.hashValue(v))
|
|
1719
|
+
: AuditableItemGraphVertexIndexHelper.hashValue(value)
|
|
1720
|
+
};
|
|
1720
1721
|
return {
|
|
1721
1722
|
logicalOperator: LogicalOperator.And,
|
|
1722
1723
|
conditions: [
|
|
1723
1724
|
{ property: "type", comparison: ComparisonOperator.Equals, value: type },
|
|
1724
|
-
|
|
1725
|
+
valueCondition
|
|
1725
1726
|
]
|
|
1726
1727
|
};
|
|
1727
1728
|
}
|
|
@@ -1813,9 +1814,9 @@ export class AuditableItemGraphService {
|
|
|
1813
1814
|
value: AuditableItemGraphService._INDEX_TYPE_ALIAS
|
|
1814
1815
|
},
|
|
1815
1816
|
{
|
|
1816
|
-
property: "
|
|
1817
|
+
property: "valueHash",
|
|
1817
1818
|
comparison: ComparisonOperator.Equals,
|
|
1818
|
-
value:
|
|
1819
|
+
value: AuditableItemGraphVertexIndexHelper.hashValue(aliasId)
|
|
1819
1820
|
},
|
|
1820
1821
|
{
|
|
1821
1822
|
property: "vertexId",
|