@sphereon/ssi-sdk.data-store 0.33.0 → 0.33.1-feature.vcdm2.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.
Files changed (210) hide show
  1. package/dist/contact/AbstractContactStore.js +1 -5
  2. package/dist/contact/AbstractContactStore.js.map +1 -1
  3. package/dist/contact/ContactStore.js +544 -545
  4. package/dist/contact/ContactStore.js.map +1 -1
  5. package/dist/digitalCredential/AbstractDigitalCredentialStore.js +1 -5
  6. package/dist/digitalCredential/AbstractDigitalCredentialStore.js.map +1 -1
  7. package/dist/digitalCredential/DigitalCredentialStore.js +131 -142
  8. package/dist/digitalCredential/DigitalCredentialStore.js.map +1 -1
  9. package/dist/entities/contact/BaseConfigEntity.js +13 -14
  10. package/dist/entities/contact/BaseConfigEntity.js.map +1 -1
  11. package/dist/entities/contact/BaseContactEntity.js +24 -22
  12. package/dist/entities/contact/BaseContactEntity.js.map +1 -1
  13. package/dist/entities/contact/ConnectionEntity.js +23 -20
  14. package/dist/entities/contact/ConnectionEntity.js.map +1 -1
  15. package/dist/entities/contact/ContactMetadataItemEntity.js +38 -44
  16. package/dist/entities/contact/ContactMetadataItemEntity.js.map +1 -1
  17. package/dist/entities/contact/CorrelationIdentifierEntity.js +34 -42
  18. package/dist/entities/contact/CorrelationIdentifierEntity.js.map +1 -1
  19. package/dist/entities/contact/DidAuthConfigEntity.js +16 -14
  20. package/dist/entities/contact/DidAuthConfigEntity.js.map +1 -1
  21. package/dist/entities/contact/ElectronicAddressEntity.js +42 -47
  22. package/dist/entities/contact/ElectronicAddressEntity.js.map +1 -1
  23. package/dist/entities/contact/IdentityEntity.js +56 -57
  24. package/dist/entities/contact/IdentityEntity.js.map +1 -1
  25. package/dist/entities/contact/IdentityMetadataItemEntity.js +38 -44
  26. package/dist/entities/contact/IdentityMetadataItemEntity.js.map +1 -1
  27. package/dist/entities/contact/NaturalPersonEntity.js +35 -43
  28. package/dist/entities/contact/NaturalPersonEntity.js.map +1 -1
  29. package/dist/entities/contact/OpenIdConfigEntity.js +24 -18
  30. package/dist/entities/contact/OpenIdConfigEntity.js.map +1 -1
  31. package/dist/entities/contact/OrganizationEntity.js +28 -38
  32. package/dist/entities/contact/OrganizationEntity.js.map +1 -1
  33. package/dist/entities/contact/PartyEntity.js +57 -59
  34. package/dist/entities/contact/PartyEntity.js.map +1 -1
  35. package/dist/entities/contact/PartyRelationshipEntity.js +37 -43
  36. package/dist/entities/contact/PartyRelationshipEntity.js.map +1 -1
  37. package/dist/entities/contact/PartyTypeEntity.js +44 -49
  38. package/dist/entities/contact/PartyTypeEntity.js.map +1 -1
  39. package/dist/entities/contact/PhysicalAddressEntity.js +61 -60
  40. package/dist/entities/contact/PhysicalAddressEntity.js.map +1 -1
  41. package/dist/entities/digitalCredential/DigitalCredentialEntity.js +63 -38
  42. package/dist/entities/digitalCredential/DigitalCredentialEntity.js.map +1 -1
  43. package/dist/entities/eventLogger/AuditEventEntity.js +60 -37
  44. package/dist/entities/eventLogger/AuditEventEntity.js.map +1 -1
  45. package/dist/entities/issuanceBranding/BackgroundAttributesEntity.js +25 -36
  46. package/dist/entities/issuanceBranding/BackgroundAttributesEntity.js.map +1 -1
  47. package/dist/entities/issuanceBranding/BaseLocaleBrandingEntity.js +48 -53
  48. package/dist/entities/issuanceBranding/BaseLocaleBrandingEntity.js.map +1 -1
  49. package/dist/entities/issuanceBranding/CredentialBrandingEntity.js +35 -43
  50. package/dist/entities/issuanceBranding/CredentialBrandingEntity.js.map +1 -1
  51. package/dist/entities/issuanceBranding/CredentialClaimsEntity.js +28 -38
  52. package/dist/entities/issuanceBranding/CredentialClaimsEntity.js.map +1 -1
  53. package/dist/entities/issuanceBranding/CredentialLocaleBrandingEntity.js +18 -18
  54. package/dist/entities/issuanceBranding/CredentialLocaleBrandingEntity.js.map +1 -1
  55. package/dist/entities/issuanceBranding/ImageAttributesEntity.js +34 -42
  56. package/dist/entities/issuanceBranding/ImageAttributesEntity.js.map +1 -1
  57. package/dist/entities/issuanceBranding/ImageDimensionsEntity.js +11 -11
  58. package/dist/entities/issuanceBranding/ImageDimensionsEntity.js.map +1 -1
  59. package/dist/entities/issuanceBranding/IssuerBrandingEntity.js +31 -40
  60. package/dist/entities/issuanceBranding/IssuerBrandingEntity.js.map +1 -1
  61. package/dist/entities/issuanceBranding/IssuerLocaleBrandingEntity.js +27 -24
  62. package/dist/entities/issuanceBranding/IssuerLocaleBrandingEntity.js.map +1 -1
  63. package/dist/entities/issuanceBranding/TextAttributesEntity.js +20 -32
  64. package/dist/entities/issuanceBranding/TextAttributesEntity.js.map +1 -1
  65. package/dist/entities/machineState/MachineStateInfoEntity.js +31 -21
  66. package/dist/entities/machineState/MachineStateInfoEntity.js.map +1 -1
  67. package/dist/entities/oid4vcState/Oid4vcStateEntity.js +24 -18
  68. package/dist/entities/oid4vcState/Oid4vcStateEntity.js.map +1 -1
  69. package/dist/entities/presentationDefinition/PresentationDefinitionItemEntity.js +34 -27
  70. package/dist/entities/presentationDefinition/PresentationDefinitionItemEntity.js.map +1 -1
  71. package/dist/entities/statusList/StatusList2021EntryEntity.js +26 -22
  72. package/dist/entities/statusList/StatusList2021EntryEntity.js.map +1 -1
  73. package/dist/entities/statusList/StatusListEntities.js +48 -39
  74. package/dist/entities/statusList/StatusListEntities.js.map +1 -1
  75. package/dist/entities/validators/index.js +6 -10
  76. package/dist/entities/validators/index.js.map +1 -1
  77. package/dist/eventLogger/AbstractEventLoggerStore.js +1 -5
  78. package/dist/eventLogger/AbstractEventLoggerStore.js.map +1 -1
  79. package/dist/eventLogger/EventLoggerStore.js +50 -65
  80. package/dist/eventLogger/EventLoggerStore.js.map +1 -1
  81. package/dist/index.js +96 -163
  82. package/dist/index.js.map +1 -1
  83. package/dist/issuanceBranding/AbstractIssuanceBrandingStore.js +1 -5
  84. package/dist/issuanceBranding/AbstractIssuanceBrandingStore.js.map +1 -1
  85. package/dist/issuanceBranding/IssuanceBrandingStore.js +331 -333
  86. package/dist/issuanceBranding/IssuanceBrandingStore.js.map +1 -1
  87. package/dist/machineState/IAbstractMachineStateStore.js +1 -5
  88. package/dist/machineState/IAbstractMachineStateStore.js.map +1 -1
  89. package/dist/machineState/MachineStateStore.js +102 -122
  90. package/dist/machineState/MachineStateStore.js.map +1 -1
  91. package/dist/migrations/generic/1-CreateContacts.js +50 -72
  92. package/dist/migrations/generic/1-CreateContacts.js.map +1 -1
  93. package/dist/migrations/generic/10-CreatePresentationDefinitions.js +50 -72
  94. package/dist/migrations/generic/10-CreatePresentationDefinitions.js.map +1 -1
  95. package/dist/migrations/generic/11-FixCredentialClaimsReferenceUuid.js +52 -74
  96. package/dist/migrations/generic/11-FixCredentialClaimsReferenceUuid.js.map +1 -1
  97. package/dist/migrations/generic/2-CreateIssuanceBranding.js +50 -72
  98. package/dist/migrations/generic/2-CreateIssuanceBranding.js.map +1 -1
  99. package/dist/migrations/generic/3-CreateContacts.js +50 -72
  100. package/dist/migrations/generic/3-CreateContacts.js.map +1 -1
  101. package/dist/migrations/generic/4-CreateStatusList.js +56 -78
  102. package/dist/migrations/generic/4-CreateStatusList.js.map +1 -1
  103. package/dist/migrations/generic/5-CreateAuditEvents.js +50 -72
  104. package/dist/migrations/generic/5-CreateAuditEvents.js.map +1 -1
  105. package/dist/migrations/generic/6-CreateDigitalCredential.js +50 -72
  106. package/dist/migrations/generic/6-CreateDigitalCredential.js.map +1 -1
  107. package/dist/migrations/generic/7-CreateMachineStateStore.js +50 -72
  108. package/dist/migrations/generic/7-CreateMachineStateStore.js.map +1 -1
  109. package/dist/migrations/generic/8-CreateContacts.js +50 -72
  110. package/dist/migrations/generic/8-CreateContacts.js.map +1 -1
  111. package/dist/migrations/generic/9-CreateContacts.js +50 -72
  112. package/dist/migrations/generic/9-CreateContacts.js.map +1 -1
  113. package/dist/migrations/generic/index.js +30 -33
  114. package/dist/migrations/generic/index.js.map +1 -1
  115. package/dist/migrations/index.js +1 -12
  116. package/dist/migrations/index.js.map +1 -1
  117. package/dist/migrations/internal-migrations-ormconfig.js +6 -8
  118. package/dist/migrations/internal-migrations-ormconfig.js.map +1 -1
  119. package/dist/migrations/postgres/1659463079428-CreateContacts.js +34 -53
  120. package/dist/migrations/postgres/1659463079428-CreateContacts.js.map +1 -1
  121. package/dist/migrations/postgres/1685628974232-CreateIssuanceBranding.js +50 -69
  122. package/dist/migrations/postgres/1685628974232-CreateIssuanceBranding.js.map +1 -1
  123. package/dist/migrations/postgres/1690925872592-CreateContacts.js +87 -106
  124. package/dist/migrations/postgres/1690925872592-CreateContacts.js.map +1 -1
  125. package/dist/migrations/postgres/1693866470001-CreateStatusList.js +16 -35
  126. package/dist/migrations/postgres/1693866470001-CreateStatusList.js.map +1 -1
  127. package/dist/migrations/postgres/1701634812183-CreateAuditEvents.js +22 -41
  128. package/dist/migrations/postgres/1701634812183-CreateAuditEvents.js.map +1 -1
  129. package/dist/migrations/postgres/1708525189001-CreateDigitalCredential.js +19 -38
  130. package/dist/migrations/postgres/1708525189001-CreateDigitalCredential.js.map +1 -1
  131. package/dist/migrations/postgres/1708797018115-CreateMachineStateStore.js +6 -25
  132. package/dist/migrations/postgres/1708797018115-CreateMachineStateStore.js.map +1 -1
  133. package/dist/migrations/postgres/1710438363001-CreateContacts.js +40 -59
  134. package/dist/migrations/postgres/1710438363001-CreateContacts.js.map +1 -1
  135. package/dist/migrations/postgres/1715761125001-CreateContacts.js +18 -37
  136. package/dist/migrations/postgres/1715761125001-CreateContacts.js.map +1 -1
  137. package/dist/migrations/postgres/1716475165345-CreatePresentationDefinitions.js +6 -25
  138. package/dist/migrations/postgres/1716475165345-CreatePresentationDefinitions.js.map +1 -1
  139. package/dist/migrations/postgres/1737110469001-UpdateStatusList.js +16 -35
  140. package/dist/migrations/postgres/1737110469001-UpdateStatusList.js.map +1 -1
  141. package/dist/migrations/postgres/1741895822987-FixCredentialClaimsReferencesUuid.js +8 -27
  142. package/dist/migrations/postgres/1741895822987-FixCredentialClaimsReferencesUuid.js.map +1 -1
  143. package/dist/migrations/sqlite/1659463069549-CreateContacts.js +56 -75
  144. package/dist/migrations/sqlite/1659463069549-CreateContacts.js.map +1 -1
  145. package/dist/migrations/sqlite/1685628973231-CreateIssuanceBranding.js +70 -89
  146. package/dist/migrations/sqlite/1685628973231-CreateIssuanceBranding.js.map +1 -1
  147. package/dist/migrations/sqlite/1690925872693-CreateContacts.js +120 -139
  148. package/dist/migrations/sqlite/1690925872693-CreateContacts.js.map +1 -1
  149. package/dist/migrations/sqlite/1693866470000-CreateStatusList.js +12 -31
  150. package/dist/migrations/sqlite/1693866470000-CreateStatusList.js.map +1 -1
  151. package/dist/migrations/sqlite/1701634819487-CreateAuditEvents.js +6 -25
  152. package/dist/migrations/sqlite/1701634819487-CreateAuditEvents.js.map +1 -1
  153. package/dist/migrations/sqlite/1708525189002-CreateDigitalCredential.js +7 -26
  154. package/dist/migrations/sqlite/1708525189002-CreateDigitalCredential.js.map +1 -1
  155. package/dist/migrations/sqlite/1708796002272-CreateMachineStateStore.js +6 -25
  156. package/dist/migrations/sqlite/1708796002272-CreateMachineStateStore.js.map +1 -1
  157. package/dist/migrations/sqlite/1710438363002-CreateContacts.js +43 -62
  158. package/dist/migrations/sqlite/1710438363002-CreateContacts.js.map +1 -1
  159. package/dist/migrations/sqlite/1715761125002-CreateContacts.js +18 -37
  160. package/dist/migrations/sqlite/1715761125002-CreateContacts.js.map +1 -1
  161. package/dist/migrations/sqlite/1716475165344-CreatePresentationDefinitions.js +6 -25
  162. package/dist/migrations/sqlite/1716475165344-CreatePresentationDefinitions.js.map +1 -1
  163. package/dist/migrations/sqlite/1737110469000-UpdateStatusList.js +20 -39
  164. package/dist/migrations/sqlite/1737110469000-UpdateStatusList.js.map +1 -1
  165. package/dist/migrations/sqlite/1741895822987-FixCredentialClaimsReferencesUuid.js +25 -44
  166. package/dist/migrations/sqlite/1741895822987-FixCredentialClaimsReferencesUuid.js.map +1 -1
  167. package/dist/presentationDefinition/AbstractPDStore.js +1 -5
  168. package/dist/presentationDefinition/AbstractPDStore.js.map +1 -1
  169. package/dist/presentationDefinition/PDStore.js +114 -123
  170. package/dist/presentationDefinition/PDStore.js.map +1 -1
  171. package/dist/statusList/IStatusListStore.js +1 -2
  172. package/dist/statusList/StatusListStore.js +196 -225
  173. package/dist/statusList/StatusListStore.js.map +1 -1
  174. package/dist/types/contact/IAbstractContactStore.js +1 -2
  175. package/dist/types/contact/contact.js +10 -13
  176. package/dist/types/contact/contact.js.map +1 -1
  177. package/dist/types/digitalCredential/IAbstractDigitalCredentialStore.js +1 -2
  178. package/dist/types/digitalCredential/digitalCredential.js +13 -16
  179. package/dist/types/digitalCredential/digitalCredential.js.map +1 -1
  180. package/dist/types/eventLogger/IAbstractEventLoggerStore.js +1 -2
  181. package/dist/types/eventLogger/eventLogger.js +1 -2
  182. package/dist/types/index.js +14 -30
  183. package/dist/types/index.js.map +1 -1
  184. package/dist/types/issuanceBranding/IAbstractIssuanceBrandingStore.js +1 -2
  185. package/dist/types/issuanceBranding/issuanceBranding.js +1 -2
  186. package/dist/types/machineState/IAbstractMachineStateStore.js +1 -2
  187. package/dist/types/presentationDefinition/IAbstractPDStore.js +1 -2
  188. package/dist/types/presentationDefinition/presentationDefinition.js +1 -2
  189. package/dist/types/statusList/IAbstractStatusListStore.js +1 -2
  190. package/dist/types/statusList/statusList.js +1 -2
  191. package/dist/types/validation/validation.js +1 -2
  192. package/dist/utils/FormattingUtils.js +3 -7
  193. package/dist/utils/FormattingUtils.js.map +1 -1
  194. package/dist/utils/SortingUtils.js +1 -5
  195. package/dist/utils/SortingUtils.js.map +1 -1
  196. package/dist/utils/ValidatorUtils.js +2 -6
  197. package/dist/utils/ValidatorUtils.js.map +1 -1
  198. package/dist/utils/contact/MappingUtils.js +124 -150
  199. package/dist/utils/contact/MappingUtils.js.map +1 -1
  200. package/dist/utils/digitalCredential/MappingUtils.js +50 -47
  201. package/dist/utils/digitalCredential/MappingUtils.js.map +1 -1
  202. package/dist/utils/eventLogger/MappingUtils.js +60 -22
  203. package/dist/utils/eventLogger/MappingUtils.js.map +1 -1
  204. package/dist/utils/issuanceBranding/MappingUtils.js +71 -77
  205. package/dist/utils/issuanceBranding/MappingUtils.js.map +1 -1
  206. package/dist/utils/presentationDefinition/MappingUtils.js +9 -15
  207. package/dist/utils/presentationDefinition/MappingUtils.js.map +1 -1
  208. package/dist/utils/statusList/MappingUtils.js +27 -22
  209. package/dist/utils/statusList/MappingUtils.js.map +1 -1
  210. package/package.json +5 -5
@@ -1,573 +1,572 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.ContactStore = void 0;
16
- const typeorm_1 = require("typeorm");
17
- const debug_1 = __importDefault(require("debug"));
18
- const AbstractContactStore_1 = require("./AbstractContactStore");
19
- const PartyEntity_1 = require("../entities/contact/PartyEntity");
20
- const IdentityEntity_1 = require("../entities/contact/IdentityEntity");
21
- const IdentityMetadataItemEntity_1 = require("../entities/contact/IdentityMetadataItemEntity");
22
- const CorrelationIdentifierEntity_1 = require("../entities/contact/CorrelationIdentifierEntity");
23
- const ConnectionEntity_1 = require("../entities/contact/ConnectionEntity");
24
- const BaseConfigEntity_1 = require("../entities/contact/BaseConfigEntity");
25
- const PartyRelationshipEntity_1 = require("../entities/contact/PartyRelationshipEntity");
26
- const PartyTypeEntity_1 = require("../entities/contact/PartyTypeEntity");
27
- const BaseContactEntity_1 = require("../entities/contact/BaseContactEntity");
28
- const ElectronicAddressEntity_1 = require("../entities/contact/ElectronicAddressEntity");
29
- const PhysicalAddressEntity_1 = require("../entities/contact/PhysicalAddressEntity");
30
- const MappingUtils_1 = require("../utils/contact/MappingUtils");
31
- const types_1 = require("../types");
32
- const debug = (0, debug_1.default)('sphereon:ssi-sdk:contact-store');
33
- class ContactStore extends AbstractContactStore_1.AbstractContactStore {
1
+ import { In } from 'typeorm';
2
+ import Debug from 'debug';
3
+ import { AbstractContactStore } from './AbstractContactStore';
4
+ import { PartyEntity } from '../entities/contact/PartyEntity';
5
+ import { IdentityEntity } from '../entities/contact/IdentityEntity';
6
+ import { IdentityMetadataItemEntity } from '../entities/contact/IdentityMetadataItemEntity';
7
+ import { CorrelationIdentifierEntity } from '../entities/contact/CorrelationIdentifierEntity';
8
+ import { ConnectionEntity } from '../entities/contact/ConnectionEntity';
9
+ import { BaseConfigEntity } from '../entities/contact/BaseConfigEntity';
10
+ import { PartyRelationshipEntity } from '../entities/contact/PartyRelationshipEntity';
11
+ import { PartyTypeEntity } from '../entities/contact/PartyTypeEntity';
12
+ import { BaseContactEntity } from '../entities/contact/BaseContactEntity';
13
+ import { ElectronicAddressEntity } from '../entities/contact/ElectronicAddressEntity';
14
+ import { PhysicalAddressEntity } from '../entities/contact/PhysicalAddressEntity';
15
+ import { electronicAddressEntityFrom, electronicAddressFrom, identityEntityFrom, identityFrom, isDidAuthConfig, isNaturalPerson, isOpenIdConfig, isOrganization, partyEntityFrom, partyFrom, partyRelationshipEntityFrom, partyRelationshipFrom, partyTypeEntityFrom, partyTypeFrom, physicalAddressEntityFrom, physicalAddressFrom, } from '../utils/contact/MappingUtils';
16
+ import { ConnectionType, CorrelationIdentifierType, PartyTypeType, } from '../types';
17
+ const debug = Debug('sphereon:ssi-sdk:contact-store');
18
+ export class ContactStore extends AbstractContactStore {
19
+ dbConnection;
34
20
  constructor(dbConnection) {
35
21
  super();
36
- this.getParty = (args) => __awaiter(this, void 0, void 0, function* () {
37
- const { partyId } = args;
38
- const result = yield (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity).findOne({
39
- where: { id: partyId },
40
- });
41
- if (!result) {
42
- return Promise.reject(Error(`No party found for id: ${partyId}`));
43
- }
44
- return (0, MappingUtils_1.partyFrom)(result);
45
- });
46
- this.getParties = (args) => __awaiter(this, void 0, void 0, function* () {
47
- debug('getParties()', args);
48
- const { filter } = args !== null && args !== void 0 ? args : {};
49
- const partyRepository = (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity);
50
- const filterConditions = this.buildFilters(filter);
51
- const initialResult = yield partyRepository.find({ select: ['id'], where: filterConditions });
52
- // Fetch the complete entities based on the initial result IDs
53
- const result = yield partyRepository.find({ where: { id: (0, typeorm_1.In)(initialResult.map((party) => party.id)) } });
54
- debug(`getParties() resulted in ${result.length} parties`);
55
- return result.map(MappingUtils_1.partyFrom);
56
- });
57
- this.addParty = (args) => __awaiter(this, void 0, void 0, function* () {
58
- const { identities, contact, partyType } = args;
59
- const partyRepository = (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity);
60
- if (!this.hasCorrectPartyType(partyType.type, contact)) {
61
- return Promise.reject(Error(`Party type ${partyType.type}, does not match for provided contact`));
62
- }
63
- for (const identity of identities !== null && identities !== void 0 ? identities : []) {
64
- if (identity.identifier.type === types_1.CorrelationIdentifierType.URL) {
65
- if (!identity.connection) {
66
- return Promise.reject(Error(`Identity with correlation type ${types_1.CorrelationIdentifierType.URL} should contain a connection`));
67
- }
68
- if (!this.hasCorrectConnectionConfig(identity.connection.type, identity.connection.config)) {
69
- return Promise.reject(Error(`Connection type ${identity.connection.type}, does not match for provided config`));
70
- }
71
- }
72
- }
73
- const partyEntity = (0, MappingUtils_1.partyEntityFrom)(args);
74
- debug('Adding party', args);
75
- const createdResult = yield partyRepository.save(partyEntity);
76
- return (0, MappingUtils_1.partyFrom)(createdResult);
77
- });
78
- this.updateParty = (args) => __awaiter(this, void 0, void 0, function* () {
79
- const { party } = args;
80
- const partyRepository = (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity);
81
- const result = yield partyRepository.findOne({
82
- where: { id: party.id },
83
- });
84
- if (!result) {
85
- return Promise.reject(Error(`No party found for id: ${party.id}`));
86
- }
87
- const updatedParty = Object.assign(Object.assign({}, party), { identities: result.identities, type: result.partyType, relationships: result.relationships, electronicAddresses: result.electronicAddresses });
88
- debug('Updating party', party);
89
- const updatedResult = yield partyRepository.save(updatedParty, { transaction: true });
90
- return (0, MappingUtils_1.partyFrom)(updatedResult);
91
- });
92
- this.removeParty = (args) => __awaiter(this, void 0, void 0, function* () {
93
- const { partyId } = args;
94
- const partyRepository = (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity);
95
- debug('Removing party', partyId);
96
- partyRepository
97
- .findOneById(partyId)
98
- .then((party) => __awaiter(this, void 0, void 0, function* () {
99
- if (!party) {
100
- yield Promise.reject(Error(`Unable to find the party with id to remove: ${partyId}`));
101
- }
102
- else {
103
- yield this.deleteIdentities(party.identities);
104
- yield this.deleteElectronicAddresses(party.electronicAddresses);
105
- yield this.deletePhysicalAddresses(party.physicalAddresses);
106
- yield partyRepository
107
- .delete({ id: partyId })
108
- .catch((error) => Promise.reject(Error(`Unable to remove party with id: ${partyId}. ${error}`)));
109
- const partyContactRepository = (yield this.dbConnection).getRepository(BaseContactEntity_1.BaseContactEntity);
110
- yield partyContactRepository
111
- .delete({ id: party.contact.id })
112
- .catch((error) => Promise.reject(Error(`Unable to remove party contact with id: ${party.contact.id}. ${error}`)));
113
- }
114
- }))
115
- .catch((error) => Promise.reject(Error(`Unable to remove party with id: ${partyId}. ${error}`)));
116
- });
117
- this.getIdentity = (args) => __awaiter(this, void 0, void 0, function* () {
118
- const { identityId } = args;
119
- const result = yield (yield this.dbConnection).getRepository(IdentityEntity_1.IdentityEntity).findOne({
120
- where: { id: identityId },
121
- });
122
- if (!result) {
123
- return Promise.reject(Error(`No identity found for id: ${identityId}`));
124
- }
125
- return (0, MappingUtils_1.identityFrom)(result);
126
- });
127
- this.getIdentities = (args) => __awaiter(this, void 0, void 0, function* () {
128
- const { filter } = args !== null && args !== void 0 ? args : {};
129
- const identityRepository = (yield this.dbConnection).getRepository(IdentityEntity_1.IdentityEntity);
130
- const filterConditions = this.buildFilters(filter);
131
- const initialResult = yield identityRepository.find({ select: ['id'], where: filterConditions });
132
- const result = yield identityRepository.find({ where: { id: (0, typeorm_1.In)(initialResult.map((identity) => identity.id)) } });
133
- return result.map(MappingUtils_1.identityFrom);
134
- });
135
- this.addIdentity = (args) => __awaiter(this, void 0, void 0, function* () {
136
- const { identity, partyId } = args;
137
- const party = yield (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity).findOne({
138
- where: { id: partyId },
139
- });
140
- if (!party) {
141
- return Promise.reject(Error(`No party found for id: ${partyId}`));
142
- }
143
- if (identity.identifier.type === types_1.CorrelationIdentifierType.URL) {
144
- if (!identity.connection) {
145
- return Promise.reject(Error(`Identity with correlation type ${types_1.CorrelationIdentifierType.URL} should contain a connection`));
146
- }
147
- if (!this.hasCorrectConnectionConfig(identity.connection.type, identity.connection.config)) {
148
- return Promise.reject(Error(`Connection type ${identity.connection.type}, does not match for provided config`));
149
- }
150
- }
151
- const identityEntity = (0, MappingUtils_1.identityEntityFrom)(identity);
152
- identityEntity.party = party;
153
- debug('Adding identity', identity);
154
- const result = yield (yield this.dbConnection).getRepository(IdentityEntity_1.IdentityEntity).save(identityEntity, {
155
- transaction: true,
156
- });
157
- return (0, MappingUtils_1.identityFrom)(result);
158
- });
159
- this.updateIdentity = (args) => __awaiter(this, void 0, void 0, function* () {
160
- const { identity } = args;
161
- const identityRepository = (yield this.dbConnection).getRepository(IdentityEntity_1.IdentityEntity);
162
- const result = yield identityRepository.findOne({
163
- where: { id: identity.id },
164
- });
165
- if (!result) {
166
- return Promise.reject(Error(`No identity found for id: ${identity.id}`));
167
- }
168
- if (identity.identifier.type === types_1.CorrelationIdentifierType.URL) {
22
+ this.dbConnection = dbConnection;
23
+ }
24
+ getParty = async (args) => {
25
+ const { partyId } = args;
26
+ const result = await (await this.dbConnection).getRepository(PartyEntity).findOne({
27
+ where: { id: partyId },
28
+ });
29
+ if (!result) {
30
+ return Promise.reject(Error(`No party found for id: ${partyId}`));
31
+ }
32
+ return partyFrom(result);
33
+ };
34
+ getParties = async (args) => {
35
+ debug('getParties()', args);
36
+ const { filter } = args ?? {};
37
+ const partyRepository = (await this.dbConnection).getRepository(PartyEntity);
38
+ const filterConditions = this.buildFilters(filter);
39
+ const initialResult = await partyRepository.find({ select: ['id'], where: filterConditions });
40
+ // Fetch the complete entities based on the initial result IDs
41
+ const result = await partyRepository.find({ where: { id: In(initialResult.map((party) => party.id)) } });
42
+ debug(`getParties() resulted in ${result.length} parties`);
43
+ return result.map(partyFrom);
44
+ };
45
+ addParty = async (args) => {
46
+ const { identities, contact, partyType } = args;
47
+ const partyRepository = (await this.dbConnection).getRepository(PartyEntity);
48
+ if (!this.hasCorrectPartyType(partyType.type, contact)) {
49
+ return Promise.reject(Error(`Party type ${partyType.type}, does not match for provided contact`));
50
+ }
51
+ for (const identity of identities ?? []) {
52
+ if (identity.identifier.type === CorrelationIdentifierType.URL) {
169
53
  if (!identity.connection) {
170
- return Promise.reject(Error(`Identity with correlation type ${types_1.CorrelationIdentifierType.URL} should contain a connection`));
54
+ return Promise.reject(Error(`Identity with correlation type ${CorrelationIdentifierType.URL} should contain a connection`));
171
55
  }
172
56
  if (!this.hasCorrectConnectionConfig(identity.connection.type, identity.connection.config)) {
173
57
  return Promise.reject(Error(`Connection type ${identity.connection.type}, does not match for provided config`));
174
58
  }
175
59
  }
176
- debug('Updating identity', identity);
177
- const updatedResult = yield identityRepository.save(identity, { transaction: true });
178
- return (0, MappingUtils_1.identityFrom)(updatedResult);
179
- });
180
- this.removeIdentity = (args) => __awaiter(this, void 0, void 0, function* () {
181
- const { identityId } = args;
182
- const identity = yield (yield this.dbConnection).getRepository(IdentityEntity_1.IdentityEntity).findOne({
183
- where: { id: identityId },
184
- });
185
- if (!identity) {
186
- return Promise.reject(Error(`No identity found for id: ${identityId}`));
187
- }
188
- debug('Removing identity', identityId);
189
- yield this.deleteIdentities([identity]);
190
- });
191
- this.addRelationship = (args) => __awaiter(this, void 0, void 0, function* () {
192
- const { leftId, rightId } = args;
193
- return this.assertRelationshipSides(leftId, rightId).then(() => __awaiter(this, void 0, void 0, function* () {
194
- const relationship = (0, MappingUtils_1.partyRelationshipEntityFrom)({
195
- leftId,
196
- rightId,
197
- });
198
- debug('Adding party relationship', relationship);
199
- const createdResult = yield (yield this.dbConnection).getRepository(PartyRelationshipEntity_1.PartyRelationshipEntity).save(relationship);
200
- return (0, MappingUtils_1.partyRelationshipFrom)(createdResult);
201
- }));
202
- });
203
- this.getRelationship = (args) => __awaiter(this, void 0, void 0, function* () {
204
- const { relationshipId } = args;
205
- const result = yield (yield this.dbConnection).getRepository(PartyRelationshipEntity_1.PartyRelationshipEntity).findOne({
206
- where: { id: relationshipId },
207
- });
208
- if (!result) {
209
- return Promise.reject(Error(`No relationship found for id: ${relationshipId}`));
210
- }
211
- return (0, MappingUtils_1.partyRelationshipFrom)(result);
212
- });
213
- this.getRelationships = (args) => __awaiter(this, void 0, void 0, function* () {
214
- const { filter } = args !== null && args !== void 0 ? args : {};
215
- const partyRelationshipRepository = (yield this.dbConnection).getRepository(PartyRelationshipEntity_1.PartyRelationshipEntity);
216
- const initialResult = yield partyRelationshipRepository.find(Object.assign({}, (filter && { where: filter })));
217
- const result = yield partyRelationshipRepository.find({
218
- where: {
219
- id: (0, typeorm_1.In)(initialResult.map((partyRelationship) => partyRelationship.id)),
220
- },
221
- });
222
- return result.map((partyRelationship) => (0, MappingUtils_1.partyRelationshipFrom)(partyRelationship));
223
- });
224
- this.updateRelationship = (args) => __awaiter(this, void 0, void 0, function* () {
225
- const { relationship } = args;
226
- const partyRelationshipRepository = (yield this.dbConnection).getRepository(PartyRelationshipEntity_1.PartyRelationshipEntity);
227
- const result = yield partyRelationshipRepository.findOne({
228
- where: { id: relationship.id },
229
- });
230
- if (!result) {
231
- return Promise.reject(Error(`No party relationship found for id: ${relationship.id}`));
232
- }
233
- return this.assertRelationshipSides(relationship.leftId, relationship.rightId).then(() => __awaiter(this, void 0, void 0, function* () {
234
- debug('Updating party relationship', relationship);
235
- const updatedResult = yield partyRelationshipRepository.save(relationship, { transaction: true });
236
- return (0, MappingUtils_1.partyRelationshipFrom)(updatedResult);
237
- }));
238
- });
239
- this.removeRelationship = (args) => __awaiter(this, void 0, void 0, function* () {
240
- const { relationshipId } = args;
241
- const partyRelationshipRepository = (yield this.dbConnection).getRepository(PartyRelationshipEntity_1.PartyRelationshipEntity);
242
- const relationship = yield partyRelationshipRepository.findOne({
243
- where: { id: relationshipId },
244
- });
245
- if (!relationship) {
246
- return Promise.reject(Error(`No relationship found for id: ${relationshipId}`));
247
- }
248
- debug('Removing relationship', relationshipId);
249
- yield partyRelationshipRepository.delete(relationshipId);
250
- });
251
- this.addPartyType = (args) => __awaiter(this, void 0, void 0, function* () {
252
- const partyEntity = (0, MappingUtils_1.partyTypeEntityFrom)(args);
253
- debug('Adding party type', args);
254
- const createdResult = yield (yield this.dbConnection).getRepository(PartyTypeEntity_1.PartyTypeEntity).save(partyEntity);
255
- return (0, MappingUtils_1.partyTypeFrom)(createdResult);
256
- });
257
- this.getPartyType = (args) => __awaiter(this, void 0, void 0, function* () {
258
- const { partyTypeId } = args;
259
- const result = yield (yield this.dbConnection).getRepository(PartyTypeEntity_1.PartyTypeEntity).findOne({
260
- where: { id: partyTypeId },
261
- });
262
- if (!result) {
263
- return Promise.reject(Error(`No party type found for id: ${partyTypeId}`));
264
- }
265
- return (0, MappingUtils_1.partyTypeFrom)(result);
266
- });
267
- this.getPartyTypes = (args) => __awaiter(this, void 0, void 0, function* () {
268
- const { filter } = args !== null && args !== void 0 ? args : {};
269
- const partyTypeRepository = (yield this.dbConnection).getRepository(PartyTypeEntity_1.PartyTypeEntity);
270
- const initialResult = yield partyTypeRepository.find(Object.assign({}, (filter && { where: filter })));
271
- const result = yield partyTypeRepository.find({
272
- where: {
273
- id: (0, typeorm_1.In)(initialResult.map((partyType) => partyType.id)),
274
- },
275
- });
276
- return result.map((partyType) => (0, MappingUtils_1.partyTypeFrom)(partyType));
277
- });
278
- this.updatePartyType = (args) => __awaiter(this, void 0, void 0, function* () {
279
- const { partyType } = args;
280
- const partyTypeRepository = (yield this.dbConnection).getRepository(PartyTypeEntity_1.PartyTypeEntity);
281
- const result = yield partyTypeRepository.findOne({
282
- where: { id: partyType.id },
283
- });
284
- if (!result) {
285
- return Promise.reject(Error(`No party type found for id: ${partyType.id}`));
286
- }
287
- debug('Updating party type', partyType);
288
- const updatedResult = yield partyTypeRepository.save(partyType, { transaction: true });
289
- return (0, MappingUtils_1.partyTypeFrom)(updatedResult);
290
- });
291
- this.removePartyType = (args) => __awaiter(this, void 0, void 0, function* () {
292
- const { partyTypeId } = args;
293
- const parties = yield (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity).find({
294
- where: {
295
- partyType: {
296
- id: partyTypeId,
297
- },
298
- },
299
- });
300
- if (parties.length > 0) {
301
- return Promise.reject(Error(`Unable to remove party type with id: ${partyTypeId}. Party type is in use`));
302
- }
303
- const partyTypeRepository = (yield this.dbConnection).getRepository(PartyTypeEntity_1.PartyTypeEntity);
304
- const partyType = yield partyTypeRepository.findOne({
305
- where: { id: partyTypeId },
306
- });
307
- if (!partyType) {
308
- return Promise.reject(Error(`No party type found for id: ${partyTypeId}`));
309
- }
310
- debug('Removing party type', partyTypeId);
311
- yield partyTypeRepository.delete(partyTypeId);
312
- });
313
- this.getElectronicAddress = (args) => __awaiter(this, void 0, void 0, function* () {
314
- const { electronicAddressId } = args;
315
- const result = yield (yield this.dbConnection).getRepository(ElectronicAddressEntity_1.ElectronicAddressEntity).findOne({
316
- where: { id: electronicAddressId },
317
- });
318
- if (!result) {
319
- return Promise.reject(Error(`No electronic address found for id: ${electronicAddressId}`));
320
- }
321
- return (0, MappingUtils_1.electronicAddressFrom)(result);
322
- });
323
- this.getElectronicAddresses = (args) => __awaiter(this, void 0, void 0, function* () {
324
- const { filter } = args !== null && args !== void 0 ? args : {};
325
- const electronicAddressRepository = (yield this.dbConnection).getRepository(ElectronicAddressEntity_1.ElectronicAddressEntity);
326
- const initialResult = yield electronicAddressRepository.find(Object.assign({}, (filter && { where: filter })));
327
- const result = yield electronicAddressRepository.find({
328
- where: {
329
- id: (0, typeorm_1.In)(initialResult.map((electronicAddress) => electronicAddress.id)),
330
- },
331
- });
332
- return result.map((electronicAddress) => (0, MappingUtils_1.electronicAddressFrom)(electronicAddress));
333
- });
334
- this.addElectronicAddress = (args) => __awaiter(this, void 0, void 0, function* () {
335
- const { electronicAddress, partyId } = args;
336
- const party = yield (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity).findOne({
337
- where: { id: partyId },
338
- });
60
+ }
61
+ const partyEntity = partyEntityFrom(args);
62
+ debug('Adding party', args);
63
+ const createdResult = await partyRepository.save(partyEntity);
64
+ return partyFrom(createdResult);
65
+ };
66
+ updateParty = async (args) => {
67
+ const { party } = args;
68
+ const partyRepository = (await this.dbConnection).getRepository(PartyEntity);
69
+ const result = await partyRepository.findOne({
70
+ where: { id: party.id },
71
+ });
72
+ if (!result) {
73
+ return Promise.reject(Error(`No party found for id: ${party.id}`));
74
+ }
75
+ const updatedParty = {
76
+ ...party,
77
+ identities: result.identities,
78
+ type: result.partyType,
79
+ relationships: result.relationships,
80
+ electronicAddresses: result.electronicAddresses,
81
+ };
82
+ debug('Updating party', party);
83
+ const updatedResult = await partyRepository.save(updatedParty, { transaction: true });
84
+ return partyFrom(updatedResult);
85
+ };
86
+ removeParty = async (args) => {
87
+ const { partyId } = args;
88
+ const partyRepository = (await this.dbConnection).getRepository(PartyEntity);
89
+ debug('Removing party', partyId);
90
+ partyRepository
91
+ .findOneById(partyId)
92
+ .then(async (party) => {
339
93
  if (!party) {
340
- return Promise.reject(Error(`No party found for id: ${partyId}`));
94
+ await Promise.reject(Error(`Unable to find the party with id to remove: ${partyId}`));
341
95
  }
342
- const electronicAddressEntity = (0, MappingUtils_1.electronicAddressEntityFrom)(electronicAddress);
343
- electronicAddressEntity.party = party;
344
- debug('Adding electronic address', electronicAddress);
345
- const result = yield (yield this.dbConnection).getRepository(ElectronicAddressEntity_1.ElectronicAddressEntity).save(electronicAddressEntity, {
346
- transaction: true,
347
- });
348
- return (0, MappingUtils_1.electronicAddressFrom)(result);
349
- });
350
- this.updateElectronicAddress = (args) => __awaiter(this, void 0, void 0, function* () {
351
- const { electronicAddress } = args;
352
- const electronicAddressRepository = (yield this.dbConnection).getRepository(ElectronicAddressEntity_1.ElectronicAddressEntity);
353
- const result = yield electronicAddressRepository.findOne({
354
- where: { id: electronicAddress.id },
355
- });
356
- if (!result) {
357
- return Promise.reject(Error(`No electronic address found for id: ${electronicAddress.id}`));
96
+ else {
97
+ await this.deleteIdentities(party.identities);
98
+ await this.deleteElectronicAddresses(party.electronicAddresses);
99
+ await this.deletePhysicalAddresses(party.physicalAddresses);
100
+ await partyRepository
101
+ .delete({ id: partyId })
102
+ .catch((error) => Promise.reject(Error(`Unable to remove party with id: ${partyId}. ${error}`)));
103
+ const partyContactRepository = (await this.dbConnection).getRepository(BaseContactEntity);
104
+ await partyContactRepository
105
+ .delete({ id: party.contact.id })
106
+ .catch((error) => Promise.reject(Error(`Unable to remove party contact with id: ${party.contact.id}. ${error}`)));
358
107
  }
359
- debug('Updating electronic address', electronicAddress);
360
- const updatedResult = yield electronicAddressRepository.save(electronicAddress, { transaction: true });
361
- return (0, MappingUtils_1.electronicAddressFrom)(updatedResult);
362
- });
363
- this.removeElectronicAddress = (args) => __awaiter(this, void 0, void 0, function* () {
364
- const { electronicAddressId } = args;
365
- const electronicAddressRepository = (yield this.dbConnection).getRepository(ElectronicAddressEntity_1.ElectronicAddressEntity);
366
- const electronicAddress = yield electronicAddressRepository.findOne({
367
- where: { id: electronicAddressId },
368
- });
369
- if (!electronicAddress) {
370
- return Promise.reject(Error(`No electronic address found for id: ${electronicAddressId}`));
108
+ })
109
+ .catch((error) => Promise.reject(Error(`Unable to remove party with id: ${partyId}. ${error}`)));
110
+ };
111
+ getIdentity = async (args) => {
112
+ const { identityId } = args;
113
+ const result = await (await this.dbConnection).getRepository(IdentityEntity).findOne({
114
+ where: { id: identityId },
115
+ });
116
+ if (!result) {
117
+ return Promise.reject(Error(`No identity found for id: ${identityId}`));
118
+ }
119
+ return identityFrom(result);
120
+ };
121
+ getIdentities = async (args) => {
122
+ const { filter } = args ?? {};
123
+ const identityRepository = (await this.dbConnection).getRepository(IdentityEntity);
124
+ const filterConditions = this.buildFilters(filter);
125
+ const initialResult = await identityRepository.find({ select: ['id'], where: filterConditions });
126
+ const result = await identityRepository.find({ where: { id: In(initialResult.map((identity) => identity.id)) } });
127
+ return result.map(identityFrom);
128
+ };
129
+ addIdentity = async (args) => {
130
+ const { identity, partyId } = args;
131
+ const party = await (await this.dbConnection).getRepository(PartyEntity).findOne({
132
+ where: { id: partyId },
133
+ });
134
+ if (!party) {
135
+ return Promise.reject(Error(`No party found for id: ${partyId}`));
136
+ }
137
+ if (identity.identifier.type === CorrelationIdentifierType.URL) {
138
+ if (!identity.connection) {
139
+ return Promise.reject(Error(`Identity with correlation type ${CorrelationIdentifierType.URL} should contain a connection`));
371
140
  }
372
- debug('Removing electronic address', electronicAddressId);
373
- yield electronicAddressRepository.delete(electronicAddressId);
374
- });
375
- this.getPhysicalAddress = (args) => __awaiter(this, void 0, void 0, function* () {
376
- const { physicalAddressId } = args;
377
- const result = yield (yield this.dbConnection).getRepository(PhysicalAddressEntity_1.PhysicalAddressEntity).findOne({
378
- where: { id: physicalAddressId },
379
- });
380
- if (!result) {
381
- return Promise.reject(Error(`No physical address found for id: ${physicalAddressId}`));
141
+ if (!this.hasCorrectConnectionConfig(identity.connection.type, identity.connection.config)) {
142
+ return Promise.reject(Error(`Connection type ${identity.connection.type}, does not match for provided config`));
382
143
  }
383
- return (0, MappingUtils_1.physicalAddressFrom)(result);
384
- });
385
- this.getPhysicalAddresses = (args) => __awaiter(this, void 0, void 0, function* () {
386
- const { filter } = args !== null && args !== void 0 ? args : {};
387
- const physicalAddressRepository = (yield this.dbConnection).getRepository(PhysicalAddressEntity_1.PhysicalAddressEntity);
388
- const initialResult = yield physicalAddressRepository.find(Object.assign({}, (filter && { where: filter })));
389
- const result = yield physicalAddressRepository.find({
390
- where: {
391
- id: (0, typeorm_1.In)(initialResult.map((physicalAddress) => physicalAddress.id)),
392
- },
393
- });
394
- return result.map((physicalAddress) => (0, MappingUtils_1.physicalAddressFrom)(physicalAddress));
395
- });
396
- this.addPhysicalAddress = (args) => __awaiter(this, void 0, void 0, function* () {
397
- const { physicalAddress, partyId } = args;
398
- const party = yield (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity).findOne({
399
- where: { id: partyId },
400
- });
401
- if (!party) {
402
- return Promise.reject(Error(`No party found for id: ${partyId}`));
144
+ }
145
+ const identityEntity = identityEntityFrom(identity);
146
+ identityEntity.party = party;
147
+ debug('Adding identity', identity);
148
+ const result = await (await this.dbConnection).getRepository(IdentityEntity).save(identityEntity, {
149
+ transaction: true,
150
+ });
151
+ return identityFrom(result);
152
+ };
153
+ updateIdentity = async (args) => {
154
+ const { identity } = args;
155
+ const identityRepository = (await this.dbConnection).getRepository(IdentityEntity);
156
+ const result = await identityRepository.findOne({
157
+ where: { id: identity.id },
158
+ });
159
+ if (!result) {
160
+ return Promise.reject(Error(`No identity found for id: ${identity.id}`));
161
+ }
162
+ if (identity.identifier.type === CorrelationIdentifierType.URL) {
163
+ if (!identity.connection) {
164
+ return Promise.reject(Error(`Identity with correlation type ${CorrelationIdentifierType.URL} should contain a connection`));
403
165
  }
404
- const physicalAddressEntity = (0, MappingUtils_1.physicalAddressEntityFrom)(physicalAddress);
405
- physicalAddressEntity.party = party;
406
- debug('Adding physical address', physicalAddress);
407
- const result = yield (yield this.dbConnection).getRepository(PhysicalAddressEntity_1.PhysicalAddressEntity).save(physicalAddressEntity, {
408
- transaction: true,
409
- });
410
- return (0, MappingUtils_1.physicalAddressFrom)(result);
411
- });
412
- this.updatePhysicalAddress = (args) => __awaiter(this, void 0, void 0, function* () {
413
- const { physicalAddress } = args;
414
- const physicalAddressRepository = (yield this.dbConnection).getRepository(PhysicalAddressEntity_1.PhysicalAddressEntity);
415
- const result = yield physicalAddressRepository.findOne({
416
- where: { id: physicalAddress.id },
417
- });
418
- if (!result) {
419
- return Promise.reject(Error(`No physical address found for id: ${physicalAddress.id}`));
166
+ if (!this.hasCorrectConnectionConfig(identity.connection.type, identity.connection.config)) {
167
+ return Promise.reject(Error(`Connection type ${identity.connection.type}, does not match for provided config`));
420
168
  }
421
- debug('Updating physical address', physicalAddress);
422
- const updatedResult = yield physicalAddressRepository.save(physicalAddress, { transaction: true });
423
- return (0, MappingUtils_1.physicalAddressFrom)(updatedResult);
424
- });
425
- this.removePhysicalAddress = (args) => __awaiter(this, void 0, void 0, function* () {
426
- const { physicalAddressId } = args;
427
- const physicalAddressRepository = (yield this.dbConnection).getRepository(PhysicalAddressEntity_1.PhysicalAddressEntity);
428
- const physicalAddress = yield physicalAddressRepository.findOne({
429
- where: { id: physicalAddressId },
169
+ }
170
+ debug('Updating identity', identity);
171
+ const updatedResult = await identityRepository.save(identity, { transaction: true });
172
+ return identityFrom(updatedResult);
173
+ };
174
+ removeIdentity = async (args) => {
175
+ const { identityId } = args;
176
+ const identity = await (await this.dbConnection).getRepository(IdentityEntity).findOne({
177
+ where: { id: identityId },
178
+ });
179
+ if (!identity) {
180
+ return Promise.reject(Error(`No identity found for id: ${identityId}`));
181
+ }
182
+ debug('Removing identity', identityId);
183
+ await this.deleteIdentities([identity]);
184
+ };
185
+ addRelationship = async (args) => {
186
+ const { leftId, rightId } = args;
187
+ return this.assertRelationshipSides(leftId, rightId).then(async () => {
188
+ const relationship = partyRelationshipEntityFrom({
189
+ leftId,
190
+ rightId,
430
191
  });
431
- if (!physicalAddress) {
432
- return Promise.reject(Error(`No physical address found for id: ${physicalAddressId}`));
192
+ debug('Adding party relationship', relationship);
193
+ const createdResult = await (await this.dbConnection).getRepository(PartyRelationshipEntity).save(relationship);
194
+ return partyRelationshipFrom(createdResult);
195
+ });
196
+ };
197
+ getRelationship = async (args) => {
198
+ const { relationshipId } = args;
199
+ const result = await (await this.dbConnection).getRepository(PartyRelationshipEntity).findOne({
200
+ where: { id: relationshipId },
201
+ });
202
+ if (!result) {
203
+ return Promise.reject(Error(`No relationship found for id: ${relationshipId}`));
204
+ }
205
+ return partyRelationshipFrom(result);
206
+ };
207
+ getRelationships = async (args) => {
208
+ const { filter } = args ?? {};
209
+ const partyRelationshipRepository = (await this.dbConnection).getRepository(PartyRelationshipEntity);
210
+ const initialResult = await partyRelationshipRepository.find({
211
+ ...(filter && { where: filter }),
212
+ });
213
+ const result = await partyRelationshipRepository.find({
214
+ where: {
215
+ id: In(initialResult.map((partyRelationship) => partyRelationship.id)),
216
+ },
217
+ });
218
+ return result.map((partyRelationship) => partyRelationshipFrom(partyRelationship));
219
+ };
220
+ updateRelationship = async (args) => {
221
+ const { relationship } = args;
222
+ const partyRelationshipRepository = (await this.dbConnection).getRepository(PartyRelationshipEntity);
223
+ const result = await partyRelationshipRepository.findOne({
224
+ where: { id: relationship.id },
225
+ });
226
+ if (!result) {
227
+ return Promise.reject(Error(`No party relationship found for id: ${relationship.id}`));
228
+ }
229
+ return this.assertRelationshipSides(relationship.leftId, relationship.rightId).then(async () => {
230
+ debug('Updating party relationship', relationship);
231
+ const updatedResult = await partyRelationshipRepository.save(relationship, { transaction: true });
232
+ return partyRelationshipFrom(updatedResult);
233
+ });
234
+ };
235
+ removeRelationship = async (args) => {
236
+ const { relationshipId } = args;
237
+ const partyRelationshipRepository = (await this.dbConnection).getRepository(PartyRelationshipEntity);
238
+ const relationship = await partyRelationshipRepository.findOne({
239
+ where: { id: relationshipId },
240
+ });
241
+ if (!relationship) {
242
+ return Promise.reject(Error(`No relationship found for id: ${relationshipId}`));
243
+ }
244
+ debug('Removing relationship', relationshipId);
245
+ await partyRelationshipRepository.delete(relationshipId);
246
+ };
247
+ addPartyType = async (args) => {
248
+ const partyEntity = partyTypeEntityFrom(args);
249
+ debug('Adding party type', args);
250
+ const createdResult = await (await this.dbConnection).getRepository(PartyTypeEntity).save(partyEntity);
251
+ return partyTypeFrom(createdResult);
252
+ };
253
+ getPartyType = async (args) => {
254
+ const { partyTypeId } = args;
255
+ const result = await (await this.dbConnection).getRepository(PartyTypeEntity).findOne({
256
+ where: { id: partyTypeId },
257
+ });
258
+ if (!result) {
259
+ return Promise.reject(Error(`No party type found for id: ${partyTypeId}`));
260
+ }
261
+ return partyTypeFrom(result);
262
+ };
263
+ getPartyTypes = async (args) => {
264
+ const { filter } = args ?? {};
265
+ const partyTypeRepository = (await this.dbConnection).getRepository(PartyTypeEntity);
266
+ const initialResult = await partyTypeRepository.find({
267
+ ...(filter && { where: filter }),
268
+ });
269
+ const result = await partyTypeRepository.find({
270
+ where: {
271
+ id: In(initialResult.map((partyType) => partyType.id)),
272
+ },
273
+ });
274
+ return result.map((partyType) => partyTypeFrom(partyType));
275
+ };
276
+ updatePartyType = async (args) => {
277
+ const { partyType } = args;
278
+ const partyTypeRepository = (await this.dbConnection).getRepository(PartyTypeEntity);
279
+ const result = await partyTypeRepository.findOne({
280
+ where: { id: partyType.id },
281
+ });
282
+ if (!result) {
283
+ return Promise.reject(Error(`No party type found for id: ${partyType.id}`));
284
+ }
285
+ debug('Updating party type', partyType);
286
+ const updatedResult = await partyTypeRepository.save(partyType, { transaction: true });
287
+ return partyTypeFrom(updatedResult);
288
+ };
289
+ removePartyType = async (args) => {
290
+ const { partyTypeId } = args;
291
+ const parties = await (await this.dbConnection).getRepository(PartyEntity).find({
292
+ where: {
293
+ partyType: {
294
+ id: partyTypeId,
295
+ },
296
+ },
297
+ });
298
+ if (parties.length > 0) {
299
+ return Promise.reject(Error(`Unable to remove party type with id: ${partyTypeId}. Party type is in use`));
300
+ }
301
+ const partyTypeRepository = (await this.dbConnection).getRepository(PartyTypeEntity);
302
+ const partyType = await partyTypeRepository.findOne({
303
+ where: { id: partyTypeId },
304
+ });
305
+ if (!partyType) {
306
+ return Promise.reject(Error(`No party type found for id: ${partyTypeId}`));
307
+ }
308
+ debug('Removing party type', partyTypeId);
309
+ await partyTypeRepository.delete(partyTypeId);
310
+ };
311
+ getElectronicAddress = async (args) => {
312
+ const { electronicAddressId } = args;
313
+ const result = await (await this.dbConnection).getRepository(ElectronicAddressEntity).findOne({
314
+ where: { id: electronicAddressId },
315
+ });
316
+ if (!result) {
317
+ return Promise.reject(Error(`No electronic address found for id: ${electronicAddressId}`));
318
+ }
319
+ return electronicAddressFrom(result);
320
+ };
321
+ getElectronicAddresses = async (args) => {
322
+ const { filter } = args ?? {};
323
+ const electronicAddressRepository = (await this.dbConnection).getRepository(ElectronicAddressEntity);
324
+ const initialResult = await electronicAddressRepository.find({
325
+ ...(filter && { where: filter }),
326
+ });
327
+ const result = await electronicAddressRepository.find({
328
+ where: {
329
+ id: In(initialResult.map((electronicAddress) => electronicAddress.id)),
330
+ },
331
+ });
332
+ return result.map((electronicAddress) => electronicAddressFrom(electronicAddress));
333
+ };
334
+ addElectronicAddress = async (args) => {
335
+ const { electronicAddress, partyId } = args;
336
+ const party = await (await this.dbConnection).getRepository(PartyEntity).findOne({
337
+ where: { id: partyId },
338
+ });
339
+ if (!party) {
340
+ return Promise.reject(Error(`No party found for id: ${partyId}`));
341
+ }
342
+ const electronicAddressEntity = electronicAddressEntityFrom(electronicAddress);
343
+ electronicAddressEntity.party = party;
344
+ debug('Adding electronic address', electronicAddress);
345
+ const result = await (await this.dbConnection).getRepository(ElectronicAddressEntity).save(electronicAddressEntity, {
346
+ transaction: true,
347
+ });
348
+ return electronicAddressFrom(result);
349
+ };
350
+ updateElectronicAddress = async (args) => {
351
+ const { electronicAddress } = args;
352
+ const electronicAddressRepository = (await this.dbConnection).getRepository(ElectronicAddressEntity);
353
+ const result = await electronicAddressRepository.findOne({
354
+ where: { id: electronicAddress.id },
355
+ });
356
+ if (!result) {
357
+ return Promise.reject(Error(`No electronic address found for id: ${electronicAddress.id}`));
358
+ }
359
+ debug('Updating electronic address', electronicAddress);
360
+ const updatedResult = await electronicAddressRepository.save(electronicAddress, { transaction: true });
361
+ return electronicAddressFrom(updatedResult);
362
+ };
363
+ removeElectronicAddress = async (args) => {
364
+ const { electronicAddressId } = args;
365
+ const electronicAddressRepository = (await this.dbConnection).getRepository(ElectronicAddressEntity);
366
+ const electronicAddress = await electronicAddressRepository.findOne({
367
+ where: { id: electronicAddressId },
368
+ });
369
+ if (!electronicAddress) {
370
+ return Promise.reject(Error(`No electronic address found for id: ${electronicAddressId}`));
371
+ }
372
+ debug('Removing electronic address', electronicAddressId);
373
+ await electronicAddressRepository.delete(electronicAddressId);
374
+ };
375
+ getPhysicalAddress = async (args) => {
376
+ const { physicalAddressId } = args;
377
+ const result = await (await this.dbConnection).getRepository(PhysicalAddressEntity).findOne({
378
+ where: { id: physicalAddressId },
379
+ });
380
+ if (!result) {
381
+ return Promise.reject(Error(`No physical address found for id: ${physicalAddressId}`));
382
+ }
383
+ return physicalAddressFrom(result);
384
+ };
385
+ getPhysicalAddresses = async (args) => {
386
+ const { filter } = args ?? {};
387
+ const physicalAddressRepository = (await this.dbConnection).getRepository(PhysicalAddressEntity);
388
+ const initialResult = await physicalAddressRepository.find({
389
+ ...(filter && { where: filter }),
390
+ });
391
+ const result = await physicalAddressRepository.find({
392
+ where: {
393
+ id: In(initialResult.map((physicalAddress) => physicalAddress.id)),
394
+ },
395
+ });
396
+ return result.map((physicalAddress) => physicalAddressFrom(physicalAddress));
397
+ };
398
+ addPhysicalAddress = async (args) => {
399
+ const { physicalAddress, partyId } = args;
400
+ const party = await (await this.dbConnection).getRepository(PartyEntity).findOne({
401
+ where: { id: partyId },
402
+ });
403
+ if (!party) {
404
+ return Promise.reject(Error(`No party found for id: ${partyId}`));
405
+ }
406
+ const physicalAddressEntity = physicalAddressEntityFrom(physicalAddress);
407
+ physicalAddressEntity.party = party;
408
+ debug('Adding physical address', physicalAddress);
409
+ const result = await (await this.dbConnection).getRepository(PhysicalAddressEntity).save(physicalAddressEntity, {
410
+ transaction: true,
411
+ });
412
+ return physicalAddressFrom(result);
413
+ };
414
+ updatePhysicalAddress = async (args) => {
415
+ const { physicalAddress } = args;
416
+ const physicalAddressRepository = (await this.dbConnection).getRepository(PhysicalAddressEntity);
417
+ const result = await physicalAddressRepository.findOne({
418
+ where: { id: physicalAddress.id },
419
+ });
420
+ if (!result) {
421
+ return Promise.reject(Error(`No physical address found for id: ${physicalAddress.id}`));
422
+ }
423
+ debug('Updating physical address', physicalAddress);
424
+ const updatedResult = await physicalAddressRepository.save(physicalAddress, { transaction: true });
425
+ return physicalAddressFrom(updatedResult);
426
+ };
427
+ removePhysicalAddress = async (args) => {
428
+ const { physicalAddressId } = args;
429
+ const physicalAddressRepository = (await this.dbConnection).getRepository(PhysicalAddressEntity);
430
+ const physicalAddress = await physicalAddressRepository.findOne({
431
+ where: { id: physicalAddressId },
432
+ });
433
+ if (!physicalAddress) {
434
+ return Promise.reject(Error(`No physical address found for id: ${physicalAddressId}`));
435
+ }
436
+ debug('Removing physical address', physicalAddressId);
437
+ await physicalAddressRepository.delete(physicalAddressId);
438
+ };
439
+ hasCorrectConnectionConfig = (type, config) => {
440
+ switch (type) {
441
+ case ConnectionType.OPENID_CONNECT:
442
+ return isOpenIdConfig(config);
443
+ case ConnectionType.SIOPv2:
444
+ return isDidAuthConfig(config);
445
+ default:
446
+ throw new Error('Connection type not supported');
447
+ }
448
+ };
449
+ hasCorrectPartyType = (type, contact) => {
450
+ switch (type) {
451
+ case PartyTypeType.NATURAL_PERSON:
452
+ return isNaturalPerson(contact);
453
+ case PartyTypeType.ORGANIZATION:
454
+ return isOrganization(contact);
455
+ default:
456
+ throw new Error('Party type not supported');
457
+ }
458
+ };
459
+ deleteIdentities = async (identities) => {
460
+ debug('Removing identities', identities);
461
+ const connection = await this.dbConnection;
462
+ const correlationIdentifierRepository = connection.getRepository(CorrelationIdentifierEntity);
463
+ const baseConfigRepository = connection.getRepository(BaseConfigEntity);
464
+ const connectionRepository = connection.getRepository(ConnectionEntity);
465
+ const identityMetadataItemRepository = connection.getRepository(IdentityMetadataItemEntity);
466
+ const identityRepository = connection.getRepository(IdentityEntity);
467
+ identities.map(async (identity) => {
468
+ await correlationIdentifierRepository
469
+ .delete(identity.identifier.id)
470
+ .catch((error) => Promise.reject(Error(`Unable to remove identity.identifier with id ${identity.identifier.id}. ${error}`)));
471
+ if (identity.connection) {
472
+ await baseConfigRepository.delete(identity.connection.config.id);
473
+ await connectionRepository
474
+ .delete(identity.connection.id)
475
+ .catch((error) => Promise.reject(Error(`Unable to remove identity.connection with id ${identity.connection?.id}. ${error}`)));
433
476
  }
434
- debug('Removing physical address', physicalAddressId);
435
- yield physicalAddressRepository.delete(physicalAddressId);
436
- });
437
- this.hasCorrectConnectionConfig = (type, config) => {
438
- switch (type) {
439
- case types_1.ConnectionType.OPENID_CONNECT:
440
- return (0, MappingUtils_1.isOpenIdConfig)(config);
441
- case types_1.ConnectionType.SIOPv2:
442
- return (0, MappingUtils_1.isDidAuthConfig)(config);
443
- default:
444
- throw new Error('Connection type not supported');
477
+ if (identity.metadata) {
478
+ identity.metadata.map(async (metadataItem) => {
479
+ await identityMetadataItemRepository
480
+ .delete(metadataItem.id)
481
+ .catch((error) => Promise.reject(Error(`Unable to remove identity.metadataItem with id ${metadataItem.id}. ${error}`)));
482
+ });
445
483
  }
446
- };
447
- this.hasCorrectPartyType = (type, contact) => {
448
- switch (type) {
449
- case types_1.PartyTypeType.NATURAL_PERSON:
450
- return (0, MappingUtils_1.isNaturalPerson)(contact);
451
- case types_1.PartyTypeType.ORGANIZATION:
452
- return (0, MappingUtils_1.isOrganization)(contact);
453
- default:
454
- throw new Error('Party type not supported');
484
+ await identityRepository
485
+ .delete(identity.id)
486
+ .catch((error) => Promise.reject(Error(`Unable to remove identity with id ${identity.id}. ${error}`)));
487
+ });
488
+ };
489
+ deleteElectronicAddresses = async (electronicAddresses) => {
490
+ debug('Removing electronic addresses', electronicAddresses);
491
+ const electronicAddressRepository = (await this.dbConnection).getRepository(ElectronicAddressEntity);
492
+ electronicAddresses.map(async (electronicAddress) => {
493
+ await electronicAddressRepository
494
+ .delete(electronicAddress.id)
495
+ .catch((error) => Promise.reject(Error(`Unable to remove electronic address with id ${electronicAddress.id}. ${error}`)));
496
+ });
497
+ };
498
+ deletePhysicalAddresses = async (physicalAddresses) => {
499
+ debug('Removing physical addresses', physicalAddresses);
500
+ const physicalAddressRepository = (await this.dbConnection).getRepository(PhysicalAddressEntity);
501
+ physicalAddresses.map(async (physicalAddress) => {
502
+ await physicalAddressRepository
503
+ .delete(physicalAddress.id)
504
+ .catch((error) => Promise.reject(Error(`Unable to remove physical address with id ${physicalAddress.id}. ${error}`)));
505
+ });
506
+ };
507
+ assertRelationshipSides = async (leftId, rightId) => {
508
+ const partyRepository = (await this.dbConnection).getRepository(PartyEntity);
509
+ const leftParty = await partyRepository.findOne({
510
+ where: { id: leftId },
511
+ });
512
+ if (!leftParty) {
513
+ return Promise.reject(Error(`No party found for left side of the relationship, party id: ${leftId}`));
514
+ }
515
+ const rightParty = await partyRepository.findOne({
516
+ where: { id: rightId },
517
+ });
518
+ if (!rightParty) {
519
+ return Promise.reject(Error(`No party found for right side of the relationship, party id: ${rightId}`));
520
+ }
521
+ };
522
+ buildFilters = (filter) => {
523
+ if (!filter)
524
+ return {};
525
+ return filter.map((condition) => this.processCondition(condition));
526
+ };
527
+ processCondition = (condition) => {
528
+ const conditionObject = {};
529
+ Object.keys(condition).forEach((key) => {
530
+ const value = condition[key];
531
+ if (key === 'metadata' && value) {
532
+ conditionObject[key] = this.buildMetadataCondition(value);
455
533
  }
456
- };
457
- this.deleteIdentities = (identities) => __awaiter(this, void 0, void 0, function* () {
458
- debug('Removing identities', identities);
459
- const connection = yield this.dbConnection;
460
- const correlationIdentifierRepository = connection.getRepository(CorrelationIdentifierEntity_1.CorrelationIdentifierEntity);
461
- const baseConfigRepository = connection.getRepository(BaseConfigEntity_1.BaseConfigEntity);
462
- const connectionRepository = connection.getRepository(ConnectionEntity_1.ConnectionEntity);
463
- const identityMetadataItemRepository = connection.getRepository(IdentityMetadataItemEntity_1.IdentityMetadataItemEntity);
464
- const identityRepository = connection.getRepository(IdentityEntity_1.IdentityEntity);
465
- identities.map((identity) => __awaiter(this, void 0, void 0, function* () {
466
- yield correlationIdentifierRepository
467
- .delete(identity.identifier.id)
468
- .catch((error) => Promise.reject(Error(`Unable to remove identity.identifier with id ${identity.identifier.id}. ${error}`)));
469
- if (identity.connection) {
470
- yield baseConfigRepository.delete(identity.connection.config.id);
471
- yield connectionRepository
472
- .delete(identity.connection.id)
473
- .catch((error) => { var _a; return Promise.reject(Error(`Unable to remove identity.connection with id ${(_a = identity.connection) === null || _a === void 0 ? void 0 : _a.id}. ${error}`)); });
474
- }
475
- if (identity.metadata) {
476
- identity.metadata.map((metadataItem) => __awaiter(this, void 0, void 0, function* () {
477
- yield identityMetadataItemRepository
478
- .delete(metadataItem.id)
479
- .catch((error) => Promise.reject(Error(`Unable to remove identity.metadataItem with id ${metadataItem.id}. ${error}`)));
480
- }));
481
- }
482
- yield identityRepository
483
- .delete(identity.id)
484
- .catch((error) => Promise.reject(Error(`Unable to remove identity with id ${identity.id}. ${error}`)));
485
- }));
486
- });
487
- this.deleteElectronicAddresses = (electronicAddresses) => __awaiter(this, void 0, void 0, function* () {
488
- debug('Removing electronic addresses', electronicAddresses);
489
- const electronicAddressRepository = (yield this.dbConnection).getRepository(ElectronicAddressEntity_1.ElectronicAddressEntity);
490
- electronicAddresses.map((electronicAddress) => __awaiter(this, void 0, void 0, function* () {
491
- yield electronicAddressRepository
492
- .delete(electronicAddress.id)
493
- .catch((error) => Promise.reject(Error(`Unable to remove electronic address with id ${electronicAddress.id}. ${error}`)));
494
- }));
495
- });
496
- this.deletePhysicalAddresses = (physicalAddresses) => __awaiter(this, void 0, void 0, function* () {
497
- debug('Removing physical addresses', physicalAddresses);
498
- const physicalAddressRepository = (yield this.dbConnection).getRepository(PhysicalAddressEntity_1.PhysicalAddressEntity);
499
- physicalAddresses.map((physicalAddress) => __awaiter(this, void 0, void 0, function* () {
500
- yield physicalAddressRepository
501
- .delete(physicalAddress.id)
502
- .catch((error) => Promise.reject(Error(`Unable to remove physical address with id ${physicalAddress.id}. ${error}`)));
503
- }));
504
- });
505
- this.assertRelationshipSides = (leftId, rightId) => __awaiter(this, void 0, void 0, function* () {
506
- const partyRepository = (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity);
507
- const leftParty = yield partyRepository.findOne({
508
- where: { id: leftId },
509
- });
510
- if (!leftParty) {
511
- return Promise.reject(Error(`No party found for left side of the relationship, party id: ${leftId}`));
534
+ else if (typeof value === 'object' && value !== null) {
535
+ conditionObject[key] = this.processCondition(value);
512
536
  }
513
- const rightParty = yield partyRepository.findOne({
514
- where: { id: rightId },
515
- });
516
- if (!rightParty) {
517
- return Promise.reject(Error(`No party found for right side of the relationship, party id: ${rightId}`));
537
+ else {
538
+ conditionObject[key] = value;
518
539
  }
519
540
  });
520
- this.buildFilters = (filter) => {
521
- if (!filter)
522
- return {};
523
- return filter.map((condition) => this.processCondition(condition));
541
+ return conditionObject;
542
+ };
543
+ buildMetadataCondition = (metadata) => {
544
+ const metadataCondition = {
545
+ label: metadata.label,
524
546
  };
525
- this.processCondition = (condition) => {
526
- const conditionObject = {};
527
- Object.keys(condition).forEach((key) => {
528
- const value = condition[key];
529
- if (key === 'metadata' && value) {
530
- conditionObject[key] = this.buildMetadataCondition(value);
531
- }
532
- else if (typeof value === 'object' && value !== null) {
533
- conditionObject[key] = this.processCondition(value);
547
+ switch (typeof metadata.value) {
548
+ case 'string':
549
+ metadataCondition.stringValue = metadata.value;
550
+ break;
551
+ case 'number':
552
+ metadataCondition.numberValue = metadata.value;
553
+ break;
554
+ case 'boolean':
555
+ metadataCondition.boolValue = metadata.value;
556
+ break;
557
+ case 'object':
558
+ if (metadata.value instanceof Date) {
559
+ metadataCondition.dateValue = metadata.value;
534
560
  }
535
561
  else {
536
- conditionObject[key] = value;
562
+ // For now, we only support / implement not-primitive type Date in the entity
563
+ throw new Error(`Unsupported object type: ${Object.prototype.toString.call(metadata.value).slice(8, -1)} for value ${metadata.value}`); // slice to extract type from string [object String]
537
564
  }
538
- });
539
- return conditionObject;
540
- };
541
- this.buildMetadataCondition = (metadata) => {
542
- const metadataCondition = {
543
- label: metadata.label,
544
- };
545
- switch (typeof metadata.value) {
546
- case 'string':
547
- metadataCondition.stringValue = metadata.value;
548
- break;
549
- case 'number':
550
- metadataCondition.numberValue = metadata.value;
551
- break;
552
- case 'boolean':
553
- metadataCondition.boolValue = metadata.value;
554
- break;
555
- case 'object':
556
- if (metadata.value instanceof Date) {
557
- metadataCondition.dateValue = metadata.value;
558
- }
559
- else {
560
- // For now, we only support / implement not-primitive type Date in the entity
561
- throw new Error(`Unsupported object type: ${Object.prototype.toString.call(metadata.value).slice(8, -1)} for value ${metadata.value}`); // slice to extract type from string [object String]
562
- }
563
- break;
564
- default:
565
- throw new Error(`Unsupported value type: ${typeof metadata.value}`);
566
- }
567
- return metadataCondition;
568
- };
569
- this.dbConnection = dbConnection;
570
- }
565
+ break;
566
+ default:
567
+ throw new Error(`Unsupported value type: ${typeof metadata.value}`);
568
+ }
569
+ return metadataCondition;
570
+ };
571
571
  }
572
- exports.ContactStore = ContactStore;
573
572
  //# sourceMappingURL=ContactStore.js.map