@sphereon/ssi-sdk.data-store 0.15.2-next.6 → 0.15.2-next.77
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/contact/AbstractContactStore.d.ts +21 -11
- package/dist/contact/AbstractContactStore.d.ts.map +1 -1
- package/dist/contact/AbstractContactStore.js.map +1 -1
- package/dist/contact/ContactStore.d.ts +25 -21
- package/dist/contact/ContactStore.d.ts.map +1 -1
- package/dist/contact/ContactStore.js +216 -136
- package/dist/contact/ContactStore.js.map +1 -1
- package/dist/entities/contact/BaseConfigEntity.d.ts +2 -0
- package/dist/entities/contact/BaseConfigEntity.d.ts.map +1 -1
- package/dist/entities/contact/BaseConfigEntity.js +10 -2
- package/dist/entities/contact/BaseConfigEntity.js.map +1 -1
- package/dist/entities/contact/BaseContactEntity.d.ts +10 -0
- package/dist/entities/contact/BaseContactEntity.d.ts.map +1 -0
- package/dist/entities/contact/BaseContactEntity.js +54 -0
- package/dist/entities/contact/BaseContactEntity.js.map +1 -0
- package/dist/entities/contact/ConnectionEntity.d.ts +1 -2
- package/dist/entities/contact/ConnectionEntity.d.ts.map +1 -1
- package/dist/entities/contact/ConnectionEntity.js +2 -21
- package/dist/entities/contact/ConnectionEntity.js.map +1 -1
- package/dist/entities/contact/CorrelationIdentifierEntity.d.ts +2 -3
- package/dist/entities/contact/CorrelationIdentifierEntity.d.ts.map +1 -1
- package/dist/entities/contact/CorrelationIdentifierEntity.js +8 -11
- package/dist/entities/contact/CorrelationIdentifierEntity.js.map +1 -1
- package/dist/entities/contact/DidAuthConfigEntity.d.ts +0 -4
- package/dist/entities/contact/DidAuthConfigEntity.d.ts.map +1 -1
- package/dist/entities/contact/DidAuthConfigEntity.js +1 -17
- package/dist/entities/contact/DidAuthConfigEntity.js.map +1 -1
- package/dist/entities/contact/ElectronicAddressEntity.d.ts +14 -0
- package/dist/entities/contact/ElectronicAddressEntity.d.ts.map +1 -0
- package/dist/entities/contact/ElectronicAddressEntity.js +92 -0
- package/dist/entities/contact/ElectronicAddressEntity.js.map +1 -0
- package/dist/entities/contact/IdentityEntity.d.ts +5 -6
- package/dist/entities/contact/IdentityEntity.d.ts.map +1 -1
- package/dist/entities/contact/IdentityEntity.js +15 -20
- package/dist/entities/contact/IdentityEntity.js.map +1 -1
- package/dist/entities/contact/IdentityMetadataItemEntity.d.ts +1 -3
- package/dist/entities/contact/IdentityMetadataItemEntity.d.ts.map +1 -1
- package/dist/entities/contact/IdentityMetadataItemEntity.js +7 -10
- package/dist/entities/contact/IdentityMetadataItemEntity.js.map +1 -1
- package/dist/entities/contact/NaturalPersonEntity.d.ts +9 -0
- package/dist/entities/contact/NaturalPersonEntity.d.ts.map +1 -0
- package/dist/entities/contact/NaturalPersonEntity.js +72 -0
- package/dist/entities/contact/NaturalPersonEntity.js.map +1 -0
- package/dist/entities/contact/OpenIdConfigEntity.d.ts +0 -4
- package/dist/entities/contact/OpenIdConfigEntity.d.ts.map +1 -1
- package/dist/entities/contact/OpenIdConfigEntity.js +1 -22
- package/dist/entities/contact/OpenIdConfigEntity.js.map +1 -1
- package/dist/entities/contact/OrganizationEntity.d.ts +9 -0
- package/dist/entities/contact/OrganizationEntity.d.ts.map +1 -0
- package/dist/entities/contact/OrganizationEntity.js +67 -0
- package/dist/entities/contact/OrganizationEntity.js.map +1 -0
- package/dist/entities/contact/PartyEntity.d.ts +21 -0
- package/dist/entities/contact/PartyEntity.d.ts.map +1 -0
- package/dist/entities/contact/PartyEntity.js +155 -0
- package/dist/entities/contact/PartyEntity.js.map +1 -0
- package/dist/entities/contact/PartyRelationshipEntity.d.ts +13 -0
- package/dist/entities/contact/PartyRelationshipEntity.d.ts.map +1 -0
- package/dist/entities/contact/PartyRelationshipEntity.js +95 -0
- package/dist/entities/contact/PartyRelationshipEntity.js.map +1 -0
- package/dist/entities/contact/PartyTypeEntity.d.ts +15 -0
- package/dist/entities/contact/PartyTypeEntity.d.ts.map +1 -0
- package/dist/entities/contact/{ContactEntity.js → PartyTypeEntity.js} +35 -36
- package/dist/entities/contact/PartyTypeEntity.js.map +1 -0
- package/dist/entities/statusList2021/StatusList2021Entity.d.ts +19 -0
- package/dist/entities/statusList2021/StatusList2021Entity.d.ts.map +1 -0
- package/dist/entities/statusList2021/StatusList2021Entity.js +115 -0
- package/dist/entities/statusList2021/StatusList2021Entity.js.map +1 -0
- package/dist/entities/statusList2021/StatusList2021EntryEntity.d.ts +11 -0
- package/dist/entities/statusList2021/StatusList2021EntryEntity.d.ts.map +1 -0
- package/dist/entities/statusList2021/StatusList2021EntryEntity.js +51 -0
- package/dist/entities/statusList2021/StatusList2021EntryEntity.js.map +1 -0
- package/dist/index.d.ts +20 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -11
- package/dist/index.js.map +1 -1
- package/dist/migrations/generic/1-CreateContacts.d.ts.map +1 -1
- package/dist/migrations/generic/1-CreateContacts.js +36 -32
- package/dist/migrations/generic/1-CreateContacts.js.map +1 -1
- package/dist/migrations/generic/2-CreateContacts.d.ts +7 -0
- package/dist/migrations/generic/2-CreateContacts.d.ts.map +1 -0
- package/dist/migrations/generic/2-CreateContacts.js +76 -0
- package/dist/migrations/generic/2-CreateContacts.js.map +1 -0
- package/dist/migrations/generic/{1-CreateIssuanceBranding.d.ts → 2-CreateIssuanceBranding.d.ts} +1 -1
- package/dist/migrations/generic/2-CreateIssuanceBranding.d.ts.map +1 -0
- package/dist/migrations/generic/2-CreateIssuanceBranding.js +76 -0
- package/dist/migrations/generic/2-CreateIssuanceBranding.js.map +1 -0
- package/dist/migrations/generic/3-CreateStatusList.d.ts +7 -0
- package/dist/migrations/generic/3-CreateStatusList.d.ts.map +1 -0
- package/dist/migrations/generic/{1-CreateIssuanceBranding.js → 3-CreateStatusList.js} +11 -11
- package/dist/migrations/generic/3-CreateStatusList.js.map +1 -0
- package/dist/migrations/generic/index.d.ts +5 -0
- package/dist/migrations/generic/index.d.ts.map +1 -1
- package/dist/migrations/generic/index.js +10 -3
- package/dist/migrations/generic/index.js.map +1 -1
- package/dist/migrations/internal-migrations-ormconfig.d.ts +2 -1
- package/dist/migrations/internal-migrations-ormconfig.d.ts.map +1 -1
- package/dist/migrations/internal-migrations-ormconfig.js +0 -2
- package/dist/migrations/internal-migrations-ormconfig.js.map +1 -1
- package/dist/migrations/postgres/1659463079428-CreateContacts.d.ts.map +1 -1
- package/dist/migrations/postgres/1659463079428-CreateContacts.js +4 -2
- package/dist/migrations/postgres/1659463079428-CreateContacts.js.map +1 -1
- package/dist/migrations/postgres/1685628974232-CreateIssuanceBranding.d.ts.map +1 -1
- package/dist/migrations/postgres/1685628974232-CreateIssuanceBranding.js +2 -0
- package/dist/migrations/postgres/1685628974232-CreateIssuanceBranding.js.map +1 -1
- package/dist/migrations/postgres/1690925872592-CreateContacts.d.ts +7 -0
- package/dist/migrations/postgres/1690925872592-CreateContacts.d.ts.map +1 -0
- package/dist/migrations/postgres/1690925872592-CreateContacts.js +69 -0
- package/dist/migrations/postgres/1690925872592-CreateContacts.js.map +1 -0
- package/dist/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.d.ts +7 -0
- package/dist/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.d.ts.map +1 -0
- package/dist/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.js +32 -0
- package/dist/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.js.map +1 -0
- package/dist/migrations/postgres/uuid.d.ts +3 -0
- package/dist/migrations/postgres/uuid.d.ts.map +1 -0
- package/dist/migrations/postgres/uuid.js +25 -0
- package/dist/migrations/postgres/uuid.js.map +1 -0
- package/dist/migrations/sqlite/1690925872693-CreateContacts.d.ts +7 -0
- package/dist/migrations/sqlite/1690925872693-CreateContacts.d.ts.map +1 -0
- package/dist/migrations/sqlite/1690925872693-CreateContacts.js +108 -0
- package/dist/migrations/sqlite/1690925872693-CreateContacts.js.map +1 -0
- package/dist/migrations/sqlite/1693866470000-CreateStatusList.d.ts +7 -0
- package/dist/migrations/sqlite/1693866470000-CreateStatusList.d.ts.map +1 -0
- package/dist/migrations/sqlite/1693866470000-CreateStatusList.js +32 -0
- package/dist/migrations/sqlite/1693866470000-CreateStatusList.js.map +1 -0
- package/dist/statusList/IStatusListStore.d.ts +20 -0
- package/dist/statusList/IStatusListStore.d.ts.map +1 -0
- package/dist/statusList/IStatusListStore.js +3 -0
- package/dist/statusList/IStatusListStore.js.map +1 -0
- package/dist/statusList/StatusListStore.d.ts +36 -0
- package/dist/statusList/StatusListStore.d.ts.map +1 -0
- package/dist/statusList/StatusListStore.js +213 -0
- package/dist/statusList/StatusListStore.js.map +1 -0
- package/dist/types/contact/IAbstractContactStore.d.ts +70 -36
- package/dist/types/contact/IAbstractContactStore.d.ts.map +1 -1
- package/dist/types/contact/contact.d.ts +139 -56
- package/dist/types/contact/contact.d.ts.map +1 -1
- package/dist/types/contact/contact.js +6 -1
- package/dist/types/contact/contact.js.map +1 -1
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/statusList/IAbstractStatusListStore.d.ts +38 -0
- package/dist/types/statusList/IAbstractStatusListStore.d.ts.map +1 -0
- package/dist/types/statusList/IAbstractStatusListStore.js +3 -0
- package/dist/types/statusList/IAbstractStatusListStore.js.map +1 -0
- package/dist/types/statusList/statusList.d.ts +25 -0
- package/dist/types/statusList/statusList.d.ts.map +1 -0
- package/dist/types/statusList/statusList.js +3 -0
- package/dist/types/statusList/statusList.js.map +1 -0
- package/dist/types/validation/validation.d.ts +4 -0
- package/dist/types/validation/validation.d.ts.map +1 -0
- package/dist/types/validation/validation.js +3 -0
- package/dist/types/validation/validation.js.map +1 -0
- package/dist/utils/ValidatorUtils.d.ts +4 -0
- package/dist/utils/ValidatorUtils.d.ts.map +1 -0
- package/dist/utils/ValidatorUtils.js +13 -0
- package/dist/utils/ValidatorUtils.js.map +1 -0
- package/dist/utils/contact/MappingUtils.d.ts +47 -0
- package/dist/utils/contact/MappingUtils.d.ts.map +1 -0
- package/dist/utils/contact/MappingUtils.js +291 -0
- package/dist/utils/contact/MappingUtils.js.map +1 -0
- package/package.json +5 -4
- package/src/__tests__/contact.entities.test.ts +1457 -195
- package/src/__tests__/contact.store.test.ts +1302 -266
- package/src/contact/AbstractContactStore.ts +44 -22
- package/src/contact/ContactStore.ts +328 -204
- package/src/entities/contact/BaseConfigEntity.ts +10 -2
- package/src/entities/contact/BaseContactEntity.ts +30 -0
- package/src/entities/contact/ConnectionEntity.ts +4 -23
- package/src/entities/contact/CorrelationIdentifierEntity.ts +9 -13
- package/src/entities/contact/DidAuthConfigEntity.ts +1 -18
- package/src/entities/contact/ElectronicAddressEntity.ts +60 -0
- package/src/entities/contact/IdentityEntity.ts +18 -25
- package/src/entities/contact/IdentityMetadataItemEntity.ts +8 -12
- package/src/entities/contact/NaturalPersonEntity.ts +38 -0
- package/src/entities/contact/OpenIdConfigEntity.ts +1 -23
- package/src/entities/contact/OrganizationEntity.ts +34 -0
- package/src/entities/contact/PartyEntity.ts +118 -0
- package/src/entities/contact/PartyRelationshipEntity.ts +61 -0
- package/src/entities/contact/PartyTypeEntity.ts +59 -0
- package/src/entities/statusList2021/StatusList2021Entity.ts +95 -0
- package/src/entities/statusList2021/StatusList2021EntryEntity.ts +29 -0
- package/src/index.ts +36 -17
- package/src/migrations/generic/1-CreateContacts.ts +46 -36
- package/src/migrations/generic/2-CreateContacts.ts +64 -0
- package/src/migrations/generic/2-CreateIssuanceBranding.ts +62 -0
- package/src/migrations/generic/{1-CreateIssuanceBranding.ts → 3-CreateStatusList.ts} +9 -9
- package/src/migrations/generic/index.ts +11 -2
- package/src/migrations/internal-migrations-ormconfig.ts +2 -4
- package/src/migrations/postgres/1659463079428-CreateContacts.ts +4 -2
- package/src/migrations/postgres/1685628974232-CreateIssuanceBranding.ts +2 -0
- package/src/migrations/postgres/1690925872592-CreateContacts.ts +94 -0
- package/src/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.ts +24 -0
- package/src/migrations/postgres/uuid.ts +12 -0
- package/src/migrations/sqlite/1690925872693-CreateContacts.ts +163 -0
- package/src/migrations/sqlite/1693866470000-CreateStatusList.ts +24 -0
- package/src/statusList/IStatusListStore.ts +44 -0
- package/src/statusList/StatusListStore.ts +237 -0
- package/src/types/contact/IAbstractContactStore.ts +84 -27
- package/src/types/contact/contact.ts +144 -50
- package/src/types/index.ts +4 -0
- package/src/types/statusList/IAbstractStatusListStore.ts +47 -0
- package/src/types/statusList/statusList.ts +39 -0
- package/src/types/validation/validation.ts +3 -0
- package/src/utils/ValidatorUtils.ts +10 -0
- package/src/utils/contact/MappingUtils.ts +344 -0
- package/dist/entities/contact/ContactEntity.d.ts +0 -16
- package/dist/entities/contact/ContactEntity.d.ts.map +0 -1
- package/dist/entities/contact/ContactEntity.js.map +0 -1
- package/dist/migrations/generic/1-CreateIssuanceBranding.d.ts.map +0 -1
- package/dist/migrations/generic/1-CreateIssuanceBranding.js.map +0 -1
- package/src/entities/contact/ContactEntity.ts +0 -74
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { MigrationInterface, QueryRunner } from 'typeorm'
|
|
2
|
+
import { enableUuidv4 } from './uuid'
|
|
2
3
|
|
|
3
4
|
export class CreateIssuanceBranding1685628974232 implements MigrationInterface {
|
|
4
5
|
name = 'CreateIssuanceBranding1685628974232'
|
|
5
6
|
|
|
6
7
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
8
|
+
await enableUuidv4(queryRunner)
|
|
7
9
|
await queryRunner.query(
|
|
8
10
|
`CREATE TABLE "ImageDimensions" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "width" integer NOT NULL, "height" integer NOT NULL, CONSTRAINT "PK_ImageDimensions_id" PRIMARY KEY ("id"))`
|
|
9
11
|
)
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { MigrationInterface, QueryRunner } from 'typeorm'
|
|
2
|
+
import { enableUuidv4 } from './uuid'
|
|
3
|
+
|
|
4
|
+
export class CreateContacts1690925872592 implements MigrationInterface {
|
|
5
|
+
name = 'CreateContacts1690925872592'
|
|
6
|
+
|
|
7
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
8
|
+
await enableUuidv4(queryRunner)
|
|
9
|
+
await queryRunner.query(`ALTER TABLE "CorrelationIdentifier" DROP CONSTRAINT "FK_CorrelationIdentifier_identityId"`)
|
|
10
|
+
await queryRunner.query(`ALTER TABLE "IdentityMetadata" DROP CONSTRAINT "FK_IdentityMetadata_identityId"`)
|
|
11
|
+
await queryRunner.query(`ALTER TABLE "Identity" DROP CONSTRAINT "FK_Identity_contactId"`)
|
|
12
|
+
await queryRunner.query(`ALTER TABLE "Connection" DROP CONSTRAINT "FK_Connection_identityId"`)
|
|
13
|
+
await queryRunner.query(`ALTER TABLE "CorrelationIdentifier" RENAME COLUMN "identityId" TO "identity_id"`)
|
|
14
|
+
await queryRunner.query(`ALTER TABLE "Connection" RENAME COLUMN "identityId" TO "identity_id"`)
|
|
15
|
+
await queryRunner.query(`CREATE TYPE "public"."PartyType_type_enum" AS ENUM('naturalPerson', 'organization')`)
|
|
16
|
+
await queryRunner.query(
|
|
17
|
+
`CREATE TABLE "PartyType" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "type" "public"."PartyType_type_enum" NOT NULL, "name" character varying(255) NOT NULL, "description" character varying(255), "tenant_id" character varying(255) NOT NULL, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "UQ_PartyType_name" UNIQUE ("name"), CONSTRAINT "PK_PartyType_id" PRIMARY KEY ("id"))`
|
|
18
|
+
)
|
|
19
|
+
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_PartyType_type_tenant_id" ON "PartyType" ("type", "tenant_id")`)
|
|
20
|
+
await queryRunner.query(
|
|
21
|
+
`CREATE TABLE "BaseContact" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), "legal_name" character varying(255), "display_name" character varying(255), "first_name" character varying(255), "middle_name" character varying(255), "last_name" character varying(255), "type" character varying NOT NULL, "party_id" uuid, CONSTRAINT "UQ_BaseContact_legal_name" UNIQUE ("legal_name"), CONSTRAINT "REL_BaseContact_party_id" UNIQUE ("party_id"), CONSTRAINT "PK_BaseContact_id" PRIMARY KEY ("id"))`
|
|
22
|
+
)
|
|
23
|
+
await queryRunner.query(`CREATE INDEX "IDX_BaseContact_type" ON "BaseContact" ("type")`)
|
|
24
|
+
await queryRunner.query(
|
|
25
|
+
`CREATE TABLE "PartyRelationship" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "left_id" uuid NOT NULL, "right_id" uuid NOT NULL, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_PartyRelationship_id" PRIMARY KEY ("id"))`
|
|
26
|
+
)
|
|
27
|
+
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_PartyRelationship_left_right" ON "PartyRelationship" ("left_id", "right_id")`)
|
|
28
|
+
await queryRunner.query(
|
|
29
|
+
`CREATE TABLE "ElectronicAddress" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "type" character varying(255) NOT NULL, "electronic_address" character varying(255) NOT NULL, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), "partyId" uuid, CONSTRAINT "PK_ElectronicAddress_id" PRIMARY KEY ("id"))`
|
|
30
|
+
)
|
|
31
|
+
await queryRunner.query(
|
|
32
|
+
`CREATE TABLE "Party" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "uri" character varying(255) NOT NULL, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), "party_type_id" uuid NOT NULL, CONSTRAINT "PK_Party_id" PRIMARY KEY ("id"))`
|
|
33
|
+
)
|
|
34
|
+
await queryRunner.query(
|
|
35
|
+
`CREATE TABLE "BaseConfig" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "identifier" character varying(255), "redirect_url" character varying(255), "session_id" character varying(255), "client_id" character varying(255), "client_secret" character varying(255), "scopes" text, "issuer" character varying(255), "dangerously_allow_insecure_http_requests" boolean, "client_auth_method" text, "type" character varying NOT NULL, "connection_id" uuid, CONSTRAINT "REL_BaseConfig_connection_id" UNIQUE ("connection_id"), CONSTRAINT "PK_BaseConfig_id" PRIMARY KEY ("id"))`
|
|
36
|
+
)
|
|
37
|
+
await queryRunner.query(`CREATE INDEX "IDX_BaseConfig_type" ON "BaseConfig" ("type")`)
|
|
38
|
+
await queryRunner.query(`ALTER TABLE "Identity" RENAME COLUMN "contactId" TO "partyId"`)
|
|
39
|
+
await queryRunner.query(`ALTER TABLE "Identity" ALTER COLUMN "roles" SET NOT NULL`)
|
|
40
|
+
await queryRunner.query(
|
|
41
|
+
`ALTER TABLE "CorrelationIdentifier" ADD CONSTRAINT "FK_CorrelationIdentifier_identity_id" FOREIGN KEY ("identity_id") REFERENCES "Identity"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
|
|
42
|
+
)
|
|
43
|
+
await queryRunner.query(
|
|
44
|
+
`ALTER TABLE "IdentityMetadata" ADD CONSTRAINT "FK_IdentityMetadata_identityId" FOREIGN KEY ("identityId") REFERENCES "Identity"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
|
|
45
|
+
)
|
|
46
|
+
await queryRunner.query(
|
|
47
|
+
`ALTER TABLE "BaseContact" ADD CONSTRAINT "FK_BaseContact_party_id" FOREIGN KEY ("party_id") REFERENCES "Party"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
|
|
48
|
+
)
|
|
49
|
+
await queryRunner.query(
|
|
50
|
+
`ALTER TABLE "PartyRelationship" ADD CONSTRAINT "FK_PartyRelationship_left_id" FOREIGN KEY ("left_id") REFERENCES "Party"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
|
|
51
|
+
)
|
|
52
|
+
await queryRunner.query(
|
|
53
|
+
`ALTER TABLE "PartyRelationship" ADD CONSTRAINT "FK_PartyRelationship_right_id" FOREIGN KEY ("right_id") REFERENCES "Party"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
|
|
54
|
+
)
|
|
55
|
+
await queryRunner.query(
|
|
56
|
+
`ALTER TABLE "ElectronicAddress" ADD CONSTRAINT "FK_ElectronicAddress_partyId" FOREIGN KEY ("partyId") REFERENCES "Party"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
|
|
57
|
+
)
|
|
58
|
+
await queryRunner.query(
|
|
59
|
+
`ALTER TABLE "Party" ADD CONSTRAINT "FK_Party_party_type_id" FOREIGN KEY ("party_type_id") REFERENCES "PartyType"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
|
|
60
|
+
)
|
|
61
|
+
await queryRunner.query(
|
|
62
|
+
`ALTER TABLE "Identity" ADD CONSTRAINT "FK_Identity_partyId" FOREIGN KEY ("partyId") REFERENCES "Party"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
|
|
63
|
+
)
|
|
64
|
+
await queryRunner.query(
|
|
65
|
+
`ALTER TABLE "Connection" ADD CONSTRAINT "FK_Connection_identity_id" FOREIGN KEY ("identity_id") REFERENCES "Identity"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
|
|
66
|
+
)
|
|
67
|
+
await queryRunner.query(
|
|
68
|
+
`ALTER TABLE "BaseConfig" ADD CONSTRAINT "FK_BaseConfig_connection_id" FOREIGN KEY ("connection_id") REFERENCES "Connection"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
// migrate existing data
|
|
72
|
+
await queryRunner.query(`ALTER TABLE "CorrelationIdentifier" RENAME CONSTRAINT "UQ_Correlation_id" TO "UQ_CorrelationIdentifier_correlation_id"`)
|
|
73
|
+
await queryRunner.query(`ALTER TABLE "Identity" RENAME CONSTRAINT "UQ_Identity_Alias" TO "UQ_Identity_alias"`)
|
|
74
|
+
await queryRunner.query(
|
|
75
|
+
`INSERT INTO "BaseConfig"("id", "identifier", "redirect_url", "session_id", "client_id", "client_secret", "scopes", "issuer", "dangerously_allow_insecure_http_requests", "client_auth_method", "type", "connection_id") SELECT "id", "identifier", "redirect_url", "session_id", "client_id", "client_secret", "scopes", "issuer", "dangerously_allow_insecure_http_requests", "client_auth_method", "type", "connectionId" FROM "BaseConfigEntity"`
|
|
76
|
+
)
|
|
77
|
+
await queryRunner.query(`DROP TABLE "BaseConfigEntity"`)
|
|
78
|
+
await queryRunner.query(
|
|
79
|
+
`INSERT INTO "PartyType"(id, type, name, description, tenant_id, created_at, last_updated_at) VALUES ('3875c12e-fdaa-4ef6-a340-c936e054b627', 'organization', 'Sphereon_default_type', 'sphereon_default_organization', '95e09cfc-c974-4174-86aa-7bf1d5251fb4', now(), now())`
|
|
80
|
+
)
|
|
81
|
+
await queryRunner.query(
|
|
82
|
+
`INSERT INTO "Party"(id, uri, created_at, last_updated_at, party_type_id) SELECT id, uri, created_at, last_updated_at, '3875c12e-fdaa-4ef6-a340-c936e054b627' FROM "Contact"`
|
|
83
|
+
)
|
|
84
|
+
await queryRunner.query(
|
|
85
|
+
`INSERT INTO "BaseContact"(id, legal_name, display_name, party_id, created_at, last_updated_at, type) SELECT id, name, alias, id, created_at, last_updated_at, 'Organization' FROM "Contact"`
|
|
86
|
+
)
|
|
87
|
+
await queryRunner.query(`DROP TABLE "Contact"`)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
91
|
+
// TODO DPP-27 implement downgrade
|
|
92
|
+
return Promise.reject(Error(`Downgrade is not yet implemented for ${this.name}`))
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { MigrationInterface, QueryRunner } from 'typeorm'
|
|
2
|
+
|
|
3
|
+
export class CreateStatusList1693866470001 implements MigrationInterface {
|
|
4
|
+
name = 'CreateStatusList1693866470001'
|
|
5
|
+
|
|
6
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
7
|
+
await queryRunner.query(
|
|
8
|
+
`CREATE TABLE "StatusListEntry" ("statusListId" character varying NOT NULL, "statusListIndex" integer NOT NULL, "credentialId" character varying, "credentialHash" character varying(128), "correlationId" character varying(255), "value" character varying(50), CONSTRAINT "PK_68704d2d13857360c6b44a3d1d0" PRIMARY KEY ("statusListId", "statusListIndex"))`
|
|
9
|
+
)
|
|
10
|
+
await queryRunner.query(`CREATE TYPE "public"."StatusList_type_enum" AS ENUM('StatusList2021')`)
|
|
11
|
+
await queryRunner.query(
|
|
12
|
+
`CREATE TYPE "public"."StatusList_drivertype_enum" AS ENUM('agent_typeorm', 'agent_kv_store', 'github', 'agent_filesystem')`
|
|
13
|
+
)
|
|
14
|
+
await queryRunner.query(`CREATE TYPE "public"."StatusList_credentialidmode_enum" AS ENUM('ISSUANCE', 'PERSISTENCE', 'NEVER')`)
|
|
15
|
+
await queryRunner.query(
|
|
16
|
+
`CREATE TABLE "StatusList" ("id" character varying NOT NULL, "correlationId" character varying NOT NULL, "length" integer NOT NULL, "issuer" text NOT NULL, "type" "public"."StatusList_type_enum" NOT NULL DEFAULT 'StatusList2021', "driverType" "public"."StatusList_drivertype_enum" NOT NULL DEFAULT 'agent_typeorm', "credentialIdMode" "public"."StatusList_credentialidmode_enum" NOT NULL DEFAULT 'ISSUANCE', "proofFormat" character varying NOT NULL DEFAULT 'lds', "indexingDirection" character varying NOT NULL DEFAULT 'rightToLeft', "statusPurpose" character varying NOT NULL DEFAULT 'revocation', "statusListCredential" text, CONSTRAINT "UQ_correlationId" UNIQUE ("correlationId"), CONSTRAINT "PK_StatusList_Id" PRIMARY KEY ("id"))`
|
|
17
|
+
)
|
|
18
|
+
await queryRunner.query(
|
|
19
|
+
`ALTER TABLE "StatusListEntry" ADD CONSTRAINT "FK_statusListEntry_statusListId" FOREIGN KEY ("statusListId") REFERENCES "StatusList"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public async down(queryRunner: QueryRunner): Promise<void> {}
|
|
24
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { QueryRunner } from 'typeorm'
|
|
2
|
+
|
|
3
|
+
export async function enableUuidv4(queryRunner: QueryRunner) {
|
|
4
|
+
try {
|
|
5
|
+
await queryRunner.query(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp";`)
|
|
6
|
+
} catch (error) {
|
|
7
|
+
console.log(
|
|
8
|
+
`Please enable the uuid-ossp.control extension in your postgresql installation. It enables generating V4 UUID and can be found in the postgresql-contrib package`
|
|
9
|
+
)
|
|
10
|
+
throw error
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { MigrationInterface, QueryRunner } from 'typeorm'
|
|
2
|
+
|
|
3
|
+
export class CreateContacts1690925872693 implements MigrationInterface {
|
|
4
|
+
name = 'CreateContacts1690925872693'
|
|
5
|
+
|
|
6
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
7
|
+
await queryRunner.query(
|
|
8
|
+
`CREATE TABLE "temporary_CorrelationIdentifier" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('did','url') ) NOT NULL, "correlation_id" text NOT NULL, "identityId" varchar, CONSTRAINT "REL_CorrelationIdentifier_identityId" UNIQUE ("identityId"), CONSTRAINT "UQ_CorrelationIdentifier_correlation_id" UNIQUE ("correlation_id"))`
|
|
9
|
+
)
|
|
10
|
+
await queryRunner.query(
|
|
11
|
+
`INSERT INTO "temporary_CorrelationIdentifier"("id", "type", "correlation_id", "identityId") SELECT "id", "type", "correlation_id", "identityId" FROM "CorrelationIdentifier"`
|
|
12
|
+
)
|
|
13
|
+
await queryRunner.query(`DROP TABLE "CorrelationIdentifier"`)
|
|
14
|
+
await queryRunner.query(`ALTER TABLE "temporary_CorrelationIdentifier" RENAME TO "CorrelationIdentifier"`)
|
|
15
|
+
await queryRunner.query(
|
|
16
|
+
`CREATE TABLE "temporary_Identity" ("id" varchar PRIMARY KEY NOT NULL, "alias" varchar(255) NOT NULL, "roles" text NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "contactId" varchar, CONSTRAINT "UQ_Identity_alias" UNIQUE ("alias"))`
|
|
17
|
+
)
|
|
18
|
+
await queryRunner.query(
|
|
19
|
+
`INSERT INTO "temporary_Identity"("id", "alias", "roles", "created_at", "last_updated_at", "contactId") SELECT "id", "alias", "roles", "created_at", "last_updated_at", "contactId" FROM "Identity"`
|
|
20
|
+
)
|
|
21
|
+
await queryRunner.query(`DROP TABLE "Identity"`)
|
|
22
|
+
await queryRunner.query(`ALTER TABLE "temporary_Identity" RENAME TO "Identity"`)
|
|
23
|
+
await queryRunner.query(
|
|
24
|
+
`CREATE TABLE "temporary_Connection" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('OIDC','SIOPv2','SIOPv2+OpenID4VP') ) NOT NULL, "identityId" varchar, CONSTRAINT "REL_Connection_identityId" UNIQUE ("identityId"))`
|
|
25
|
+
)
|
|
26
|
+
await queryRunner.query(`INSERT INTO "temporary_Connection"("id", "type", "identityId") SELECT "id", "type", "identityId" FROM "Connection"`)
|
|
27
|
+
await queryRunner.query(`DROP TABLE "Connection"`)
|
|
28
|
+
await queryRunner.query(`ALTER TABLE "temporary_Connection" RENAME TO "Connection"`)
|
|
29
|
+
await queryRunner.query(
|
|
30
|
+
`CREATE TABLE "temporary_CorrelationIdentifier" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('did','url') ) NOT NULL, "correlation_id" text NOT NULL, "identity_id" varchar, CONSTRAINT "REL_CorrelationIdentifier_identityId" UNIQUE ("identity_id"), CONSTRAINT "UQ_CorrelationIdentifier_correlation_id" UNIQUE ("correlation_id"))`
|
|
31
|
+
)
|
|
32
|
+
await queryRunner.query(
|
|
33
|
+
`INSERT INTO "temporary_CorrelationIdentifier"("id", "type", "correlation_id", "identity_id") SELECT "id", "type", "correlation_id", "identityId" FROM "CorrelationIdentifier"`
|
|
34
|
+
)
|
|
35
|
+
await queryRunner.query(`DROP TABLE "CorrelationIdentifier"`)
|
|
36
|
+
await queryRunner.query(`ALTER TABLE "temporary_CorrelationIdentifier" RENAME TO "CorrelationIdentifier"`)
|
|
37
|
+
await queryRunner.query(
|
|
38
|
+
`CREATE TABLE "temporary_Identity" ("id" varchar PRIMARY KEY NOT NULL, "alias" varchar(255) NOT NULL, "roles" text NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "partyId" varchar, CONSTRAINT "UQ_Identity_alias" UNIQUE ("alias"))`
|
|
39
|
+
)
|
|
40
|
+
await queryRunner.query(
|
|
41
|
+
`INSERT INTO "temporary_Identity"("id", "alias", "roles", "created_at", "last_updated_at", "partyId") SELECT "id", "alias", "roles", "created_at", "last_updated_at", "contactId" FROM "Identity"`
|
|
42
|
+
)
|
|
43
|
+
await queryRunner.query(`DROP TABLE "Identity"`)
|
|
44
|
+
await queryRunner.query(`ALTER TABLE "temporary_Identity" RENAME TO "Identity"`)
|
|
45
|
+
await queryRunner.query(
|
|
46
|
+
`CREATE TABLE "temporary_Connection" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('OIDC','SIOPv2','SIOPv2+OpenID4VP') ) NOT NULL, "identity_id" varchar, CONSTRAINT "REL_Connection_identityId" UNIQUE ("identity_id"))`
|
|
47
|
+
)
|
|
48
|
+
await queryRunner.query(`INSERT INTO "temporary_Connection"("id", "type", "identity_id") SELECT "id", "type", "identityId" FROM "Connection"`)
|
|
49
|
+
await queryRunner.query(`DROP TABLE "Connection"`)
|
|
50
|
+
await queryRunner.query(`ALTER TABLE "temporary_Connection" RENAME TO "Connection"`)
|
|
51
|
+
await queryRunner.query(
|
|
52
|
+
`CREATE TABLE "PartyType" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('naturalPerson','organization') ) NOT NULL, "name" varchar(255) NOT NULL, "description" varchar(255), "tenant_id" varchar(255) NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "UQ_PartyType_name" UNIQUE ("name"))`
|
|
53
|
+
)
|
|
54
|
+
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_PartyType_type_tenant_id" ON "PartyType" ("type", "tenant_id")`)
|
|
55
|
+
await queryRunner.query(
|
|
56
|
+
`CREATE TABLE "BaseContact" ("id" varchar PRIMARY KEY NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "legal_name" varchar(255), "display_name" varchar(255), "first_name" varchar(255), "middle_name" varchar(255), "last_name" varchar(255), "type" varchar NOT NULL, "party_id" varchar, CONSTRAINT "UQ_BaseContact_legal_name" UNIQUE ("legal_name"), CONSTRAINT "REL_BaseContact_party_id" UNIQUE ("party_id"))`
|
|
57
|
+
)
|
|
58
|
+
await queryRunner.query(`CREATE INDEX "IDX_BaseContact_type" ON "BaseContact" ("type")`)
|
|
59
|
+
await queryRunner.query(
|
|
60
|
+
`CREATE TABLE "PartyRelationship" ("id" varchar PRIMARY KEY NOT NULL, "left_id" varchar NOT NULL, "right_id" varchar NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')))`
|
|
61
|
+
)
|
|
62
|
+
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_PartyRelationship_left_right" ON "PartyRelationship" ("left_id", "right_id")`)
|
|
63
|
+
await queryRunner.query(
|
|
64
|
+
`CREATE TABLE "ElectronicAddress" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar(255) NOT NULL, "electronic_address" varchar(255) NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "partyId" varchar)`
|
|
65
|
+
)
|
|
66
|
+
await queryRunner.query(
|
|
67
|
+
`CREATE TABLE "Party" ("id" varchar PRIMARY KEY NOT NULL, "uri" varchar(255) NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "party_type_id" varchar NOT NULL)`
|
|
68
|
+
)
|
|
69
|
+
await queryRunner.query(
|
|
70
|
+
`CREATE TABLE "BaseConfig" ("id" varchar PRIMARY KEY NOT NULL, "identifier" varchar(255), "redirect_url" varchar(255), "session_id" varchar(255), "client_id" varchar(255), "client_secret" varchar(255), "scopes" text, "issuer" varchar(255), "dangerously_allow_insecure_http_requests" boolean, "client_auth_method" text, "type" varchar NOT NULL, "connection_id" varchar, CONSTRAINT "REL_BaseConfig_connection_id" UNIQUE ("connection_id"))`
|
|
71
|
+
)
|
|
72
|
+
await queryRunner.query(`CREATE INDEX "IDX_BaseConfig_type" ON "BaseConfig" ("type")`)
|
|
73
|
+
await queryRunner.query(
|
|
74
|
+
`CREATE TABLE "temporary_CorrelationIdentifier" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('did','url') ) NOT NULL, "correlation_id" text NOT NULL, "identity_id" varchar, CONSTRAINT "REL_CorrelationIdentifier_identity_id" UNIQUE ("identity_id"), CONSTRAINT "UQ_CorrelationIdentifier_correlation_id" UNIQUE ("correlation_id"), CONSTRAINT "FK_CorrelationIdentifier_identity_id" FOREIGN KEY ("identity_id") REFERENCES "Identity" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`
|
|
75
|
+
)
|
|
76
|
+
await queryRunner.query(
|
|
77
|
+
`INSERT INTO "temporary_CorrelationIdentifier"("id", "type", "correlation_id", "identity_id") SELECT "id", "type", "correlation_id", "identity_id" FROM "CorrelationIdentifier"`
|
|
78
|
+
)
|
|
79
|
+
await queryRunner.query(`DROP TABLE "CorrelationIdentifier"`)
|
|
80
|
+
await queryRunner.query(`ALTER TABLE "temporary_CorrelationIdentifier" RENAME TO "CorrelationIdentifier"`)
|
|
81
|
+
await queryRunner.query(`DROP INDEX "IDX_BaseContact_type"`)
|
|
82
|
+
await queryRunner.query(
|
|
83
|
+
`CREATE TABLE "temporary_BaseContact" ("id" varchar PRIMARY KEY NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "legal_name" varchar(255), "display_name" varchar(255), "first_name" varchar(255), "middle_name" varchar(255), "last_name" varchar(255), "type" varchar NOT NULL, "party_id" varchar, CONSTRAINT "UQ_BaseContact_legal_name" UNIQUE ("legal_name"), CONSTRAINT "REL_BaseContact_party_id" UNIQUE ("party_id"), CONSTRAINT "FK_BaseContact_party_id" FOREIGN KEY ("party_id") REFERENCES "Party" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`
|
|
84
|
+
)
|
|
85
|
+
await queryRunner.query(
|
|
86
|
+
`INSERT INTO "temporary_BaseContact"("id", "created_at", "last_updated_at", "legal_name", "display_name", "first_name", "middle_name", "last_name", "type", "party_id") SELECT "id", "created_at", "last_updated_at", "legal_name", "display_name", "first_name", "middle_name", "last_name", "type", "party_id" FROM "BaseContact"`
|
|
87
|
+
)
|
|
88
|
+
await queryRunner.query(`DROP TABLE "BaseContact"`)
|
|
89
|
+
await queryRunner.query(`ALTER TABLE "temporary_BaseContact" RENAME TO "BaseContact"`)
|
|
90
|
+
await queryRunner.query(`CREATE INDEX "IDX_BaseContact_type" ON "BaseContact" ("type")`)
|
|
91
|
+
await queryRunner.query(`DROP INDEX "IDX_PartyRelationship_left_right"`)
|
|
92
|
+
await queryRunner.query(
|
|
93
|
+
`CREATE TABLE "temporary_PartyRelationship" ("id" varchar PRIMARY KEY NOT NULL, "left_id" varchar NOT NULL, "right_id" varchar NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "FK_PartyRelationship_left_id" FOREIGN KEY ("left_id") REFERENCES "Party" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_PartyRelationship_right_id" FOREIGN KEY ("right_id") REFERENCES "Party" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`
|
|
94
|
+
)
|
|
95
|
+
await queryRunner.query(
|
|
96
|
+
`INSERT INTO "temporary_PartyRelationship"("id", "left_id", "right_id", "created_at", "last_updated_at") SELECT "id", "left_id", "right_id", "created_at", "last_updated_at" FROM "PartyRelationship"`
|
|
97
|
+
)
|
|
98
|
+
await queryRunner.query(`DROP TABLE "PartyRelationship"`)
|
|
99
|
+
await queryRunner.query(`ALTER TABLE "temporary_PartyRelationship" RENAME TO "PartyRelationship"`)
|
|
100
|
+
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_PartyRelationship_left_right" ON "PartyRelationship" ("left_id", "right_id")`)
|
|
101
|
+
await queryRunner.query(
|
|
102
|
+
`CREATE TABLE "temporary_ElectronicAddress" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar(255) NOT NULL, "electronic_address" varchar(255) NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "partyId" varchar, CONSTRAINT "FK_ElectronicAddress_partyId" FOREIGN KEY ("partyId") REFERENCES "Party" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`
|
|
103
|
+
)
|
|
104
|
+
await queryRunner.query(
|
|
105
|
+
`INSERT INTO "temporary_ElectronicAddress"("id", "type", "electronic_address", "created_at", "last_updated_at", "partyId") SELECT "id", "type", "electronic_address", "created_at", "last_updated_at", "partyId" FROM "ElectronicAddress"`
|
|
106
|
+
)
|
|
107
|
+
await queryRunner.query(`DROP TABLE "ElectronicAddress"`)
|
|
108
|
+
await queryRunner.query(`ALTER TABLE "temporary_ElectronicAddress" RENAME TO "ElectronicAddress"`)
|
|
109
|
+
await queryRunner.query(
|
|
110
|
+
`CREATE TABLE "temporary_Party" ("id" varchar PRIMARY KEY NOT NULL, "uri" varchar(255) NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "party_type_id" varchar NOT NULL, CONSTRAINT "FK_Party_party_type_id" FOREIGN KEY ("party_type_id") REFERENCES "PartyType" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION)`
|
|
111
|
+
)
|
|
112
|
+
await queryRunner.query(
|
|
113
|
+
`INSERT INTO "temporary_Party"("id", "uri", "created_at", "last_updated_at", "party_type_id") SELECT "id", "uri", "created_at", "last_updated_at", "party_type_id" FROM "Party"`
|
|
114
|
+
)
|
|
115
|
+
await queryRunner.query(`DROP TABLE "Party"`)
|
|
116
|
+
await queryRunner.query(`ALTER TABLE "temporary_Party" RENAME TO "Party"`)
|
|
117
|
+
await queryRunner.query(
|
|
118
|
+
`CREATE TABLE "temporary_Identity" ("id" varchar PRIMARY KEY NOT NULL, "alias" varchar(255) NOT NULL, "roles" text NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "partyId" varchar, CONSTRAINT "UQ_Identity_alias" UNIQUE ("alias"), CONSTRAINT "FK_Identity_partyId" FOREIGN KEY ("partyId") REFERENCES "Party" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`
|
|
119
|
+
)
|
|
120
|
+
await queryRunner.query(
|
|
121
|
+
`INSERT INTO "temporary_Identity"("id", "alias", "roles", "created_at", "last_updated_at", "partyId") SELECT "id", "alias", "roles", "created_at", "last_updated_at", "partyId" FROM "Identity"`
|
|
122
|
+
)
|
|
123
|
+
await queryRunner.query(`DROP TABLE "Identity"`)
|
|
124
|
+
await queryRunner.query(`ALTER TABLE "temporary_Identity" RENAME TO "Identity"`)
|
|
125
|
+
await queryRunner.query(
|
|
126
|
+
`CREATE TABLE "temporary_Connection" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('OIDC','SIOPv2','SIOPv2+OpenID4VP') ) NOT NULL, "identity_id" varchar, CONSTRAINT "REL_Connection_identity_id" UNIQUE ("identity_id"), CONSTRAINT "FK_Connection_identity_id" FOREIGN KEY ("identity_id") REFERENCES "Identity" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`
|
|
127
|
+
)
|
|
128
|
+
await queryRunner.query(`INSERT INTO "temporary_Connection"("id", "type", "identity_id") SELECT "id", "type", "identity_id" FROM "Connection"`)
|
|
129
|
+
await queryRunner.query(`DROP TABLE "Connection"`)
|
|
130
|
+
await queryRunner.query(`ALTER TABLE "temporary_Connection" RENAME TO "Connection"`)
|
|
131
|
+
await queryRunner.query(`DROP INDEX "IDX_BaseConfig_type"`)
|
|
132
|
+
await queryRunner.query(
|
|
133
|
+
`CREATE TABLE "temporary_BaseConfig" ("id" varchar PRIMARY KEY NOT NULL, "identifier" varchar(255), "redirect_url" varchar(255), "session_id" varchar(255), "client_id" varchar(255), "client_secret" varchar(255), "scopes" text, "issuer" varchar(255), "dangerously_allow_insecure_http_requests" boolean, "client_auth_method" text, "type" varchar NOT NULL, "connection_id" varchar, CONSTRAINT "REL_BaseConfig_connection_id" UNIQUE ("connection_id"), CONSTRAINT "FK_BaseConfig_connection_id" FOREIGN KEY ("connection_id") REFERENCES "Connection" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`
|
|
134
|
+
)
|
|
135
|
+
await queryRunner.query(
|
|
136
|
+
`INSERT INTO "temporary_BaseConfig"("id", "identifier", "redirect_url", "session_id", "client_id", "client_secret", "scopes", "issuer", "dangerously_allow_insecure_http_requests", "client_auth_method", "type", "connection_id") SELECT "id", "identifier", "redirect_url", "session_id", "client_id", "client_secret", "scopes", "issuer", "dangerously_allow_insecure_http_requests", "client_auth_method", "type", "connection_id" FROM "BaseConfig"`
|
|
137
|
+
)
|
|
138
|
+
await queryRunner.query(`DROP TABLE "BaseConfig"`)
|
|
139
|
+
await queryRunner.query(`ALTER TABLE "temporary_BaseConfig" RENAME TO "BaseConfig"`)
|
|
140
|
+
await queryRunner.query(`CREATE INDEX "IDX_BaseConfig_type" ON "BaseConfig" ("type")`)
|
|
141
|
+
|
|
142
|
+
// migrate existing data
|
|
143
|
+
await queryRunner.query(
|
|
144
|
+
`INSERT INTO "BaseConfig"("id", "identifier", "redirect_url", "session_id", "client_id", "client_secret", "scopes", "issuer", "dangerously_allow_insecure_http_requests", "client_auth_method", "type", "connection_id") SELECT "id", "identifier", "redirect_url", "session_id", "client_id", "client_secret", "scopes", "issuer", "dangerously_allow_insecure_http_requests", "client_auth_method", "type", "connection_id" FROM "BaseConfigEntity"`
|
|
145
|
+
)
|
|
146
|
+
await queryRunner.query(`DROP TABLE "BaseConfigEntity"`)
|
|
147
|
+
await queryRunner.query(
|
|
148
|
+
`INSERT INTO "PartyType"(id, type, name, description, tenant_id, created_at, last_updated_at) VALUES ('3875c12e-fdaa-4ef6-a340-c936e054b627', 'organization', 'Sphereon_default_type', 'sphereon_default_organization', '95e09cfc-c974-4174-86aa-7bf1d5251fb4', datetime('now'), datetime('now'))`
|
|
149
|
+
)
|
|
150
|
+
await queryRunner.query(
|
|
151
|
+
`INSERT INTO "Party"(id, uri, created_at, last_updated_at, party_type_id) SELECT id, uri, created_at, last_updated_at, '3875c12e-fdaa-4ef6-a340-c936e054b627' FROM "Contact"`
|
|
152
|
+
)
|
|
153
|
+
await queryRunner.query(
|
|
154
|
+
`INSERT INTO "BaseContact"(id, legal_name, display_name, party_id, created_at, last_updated_at, type) SELECT id, name, alias, id, created_at, last_updated_at, 'Organization' FROM "Contact"`
|
|
155
|
+
)
|
|
156
|
+
await queryRunner.query(`DROP TABLE "Contact"`)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
160
|
+
// TODO DPP-27 implement downgrade
|
|
161
|
+
return Promise.reject(Error(`Downgrade is not yet implemented for ${this.name}`))
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { MigrationInterface, QueryRunner } from 'typeorm'
|
|
2
|
+
|
|
3
|
+
export class CreateStatusList1693866470002 implements MigrationInterface {
|
|
4
|
+
name = 'CreateStatusList1693866470002'
|
|
5
|
+
|
|
6
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
7
|
+
await queryRunner.query(
|
|
8
|
+
`CREATE TABLE "StatusListEntry" ("statusListId" varchar NOT NULL, "statusListIndex" integer NOT NULL, "credentialId" varchar, "credentialHash" varchar(128), "correlationId" varchar(255), "value" varchar(50), PRIMARY KEY ("statusListId", "statusListIndex"))`
|
|
9
|
+
)
|
|
10
|
+
await queryRunner.query(
|
|
11
|
+
`CREATE TABLE "StatusList" ("id" varchar PRIMARY KEY NOT NULL, "correlationId" varchar NOT NULL, "length" integer NOT NULL, "issuer" text NOT NULL, "type" varchar CHECK( "type" IN ('StatusList2021') ) NOT NULL DEFAULT ('StatusList2021'), "driverType" varchar CHECK( "driverType" IN ('agent_typeorm','agent_kv_store','github','agent_filesystem') ) NOT NULL DEFAULT ('agent_typeorm'), "credentialIdMode" varchar CHECK( "credentialIdMode" IN ('ISSUANCE','PERSISTENCE','NEVER') ) NOT NULL DEFAULT ('ISSUANCE'), "proofFormat" varchar CHECK( "proofFormat" IN ('lds','jwt') ) NOT NULL DEFAULT ('lds'), "indexingDirection" varchar CHECK( "indexingDirection" IN ('rightToLeft') ) NOT NULL DEFAULT ('rightToLeft'), "statusPurpose" varchar NOT NULL DEFAULT ('revocation'), "statusListCredential" text, CONSTRAINT "UQ_correlationId" UNIQUE ("correlationId"))`
|
|
12
|
+
)
|
|
13
|
+
await queryRunner.query(
|
|
14
|
+
`CREATE TABLE "temporary_StatusListEntry" ("statusListId" varchar NOT NULL, "statusListIndex" integer NOT NULL, "credentialId" varchar, "credentialHash" varchar(128), "correlationId" varchar(255), "value" varchar(50), CONSTRAINT "FK_statusListEntry_statusListId" FOREIGN KEY ("statusListId") REFERENCES "StatusList" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION, PRIMARY KEY ("statusListId", "statusListIndex"))`
|
|
15
|
+
)
|
|
16
|
+
await queryRunner.query(
|
|
17
|
+
`INSERT INTO "temporary_StatusListEntry"("statusListId", "statusListIndex", "credentialId", "credentialHash", "correlationId", "value") SELECT "statusListId", "statusListIndex", "credentialId", "credentialHash", "correlationId", "value" FROM "StatusListEntry"`
|
|
18
|
+
)
|
|
19
|
+
await queryRunner.query(`DROP TABLE "StatusListEntry"`)
|
|
20
|
+
await queryRunner.query(`ALTER TABLE "temporary_StatusListEntry" RENAME TO "StatusListEntry"`)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public async down(queryRunner: QueryRunner): Promise<void> {}
|
|
24
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { StatusListEntryEntity } from '../entities/statusList2021/StatusList2021EntryEntity'
|
|
2
|
+
import {
|
|
3
|
+
IAddStatusListArgs,
|
|
4
|
+
IAddStatusListEntryArgs,
|
|
5
|
+
IGetStatusListArgs,
|
|
6
|
+
IGetStatusListEntriesArgs,
|
|
7
|
+
IGetStatusListEntryByCredentialIdArgs,
|
|
8
|
+
IGetStatusListEntryByIndexArgs,
|
|
9
|
+
IGetStatusListsArgs,
|
|
10
|
+
IRemoveStatusListArgs,
|
|
11
|
+
IStatusListEntryAvailableArgs,
|
|
12
|
+
IUpdateStatusListIndexArgs,
|
|
13
|
+
} from '../types/statusList/IAbstractStatusListStore'
|
|
14
|
+
import { IStatusListEntity, IStatusListEntryEntity } from '../types/statusList/statusList'
|
|
15
|
+
|
|
16
|
+
export interface IStatusListStore {
|
|
17
|
+
getStatusList(args: IGetStatusListArgs): Promise<IStatusListEntity>
|
|
18
|
+
|
|
19
|
+
getStatusLists(args: IGetStatusListsArgs): Promise<Array<IStatusListEntity>>
|
|
20
|
+
|
|
21
|
+
removeStatusList(args: IRemoveStatusListArgs): Promise<void>
|
|
22
|
+
|
|
23
|
+
addStatusList(args: IAddStatusListArgs): Promise<IStatusListEntity>
|
|
24
|
+
|
|
25
|
+
updateStatusList(args: IUpdateStatusListIndexArgs): Promise<IStatusListEntity>
|
|
26
|
+
|
|
27
|
+
availableStatusListEntries(args: IStatusListEntryAvailableArgs): Promise<number[]>
|
|
28
|
+
|
|
29
|
+
addStatusListEntry(args: IAddStatusListEntryArgs): Promise<IStatusListEntryEntity>
|
|
30
|
+
|
|
31
|
+
updateStatusListEntry(args: IAddStatusListEntryArgs): Promise<IStatusListEntryEntity>
|
|
32
|
+
|
|
33
|
+
getStatusListEntryByIndex(args: IGetStatusListEntryByIndexArgs): Promise<StatusListEntryEntity | undefined>
|
|
34
|
+
|
|
35
|
+
getStatusListEntryByCredentialId(args: IGetStatusListEntryByCredentialIdArgs): Promise<StatusListEntryEntity | undefined>
|
|
36
|
+
|
|
37
|
+
removeStatusListEntryByIndex(args: IGetStatusListEntryByIndexArgs): Promise<boolean>
|
|
38
|
+
|
|
39
|
+
removeStatusListEntryByCredentialId(args: IGetStatusListEntryByCredentialIdArgs): Promise<boolean>
|
|
40
|
+
|
|
41
|
+
getStatusListEntries(args: IGetStatusListEntriesArgs): Promise<IStatusListEntryEntity[]>
|
|
42
|
+
|
|
43
|
+
getStatusList(args: IGetStatusListArgs): Promise<IStatusListEntity>
|
|
44
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { OrPromise } from '@sphereon/ssi-types'
|
|
2
|
+
import Debug from 'debug'
|
|
3
|
+
import { DataSource, In, Repository } from 'typeorm'
|
|
4
|
+
import { StatusListEntity } from '../entities/statusList2021/StatusList2021Entity'
|
|
5
|
+
import { StatusListEntryEntity } from '../entities/statusList2021/StatusList2021EntryEntity'
|
|
6
|
+
import {
|
|
7
|
+
IAddStatusListArgs,
|
|
8
|
+
IAddStatusListEntryArgs,
|
|
9
|
+
IGetStatusListArgs,
|
|
10
|
+
IGetStatusListEntriesArgs,
|
|
11
|
+
IGetStatusListEntryByCredentialIdArgs,
|
|
12
|
+
IGetStatusListEntryByIndexArgs,
|
|
13
|
+
IGetStatusListsArgs,
|
|
14
|
+
IRemoveStatusListArgs,
|
|
15
|
+
IStatusListEntryAvailableArgs,
|
|
16
|
+
IUpdateStatusListIndexArgs,
|
|
17
|
+
IStatusListEntity,
|
|
18
|
+
IStatusListEntryEntity,
|
|
19
|
+
} from '../types'
|
|
20
|
+
import { IStatusListStore } from './IStatusListStore'
|
|
21
|
+
|
|
22
|
+
const debug = Debug('sphereon:ssi-sdk:data-store:status-list')
|
|
23
|
+
|
|
24
|
+
export class StatusListStore implements IStatusListStore {
|
|
25
|
+
private readonly _dbConnection: OrPromise<DataSource>
|
|
26
|
+
|
|
27
|
+
constructor(dbConnection: OrPromise<DataSource>) {
|
|
28
|
+
this._dbConnection = dbConnection
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Get's the available status list indices from the provided indices. Meaning it will filter out any index that is already known.
|
|
33
|
+
*
|
|
34
|
+
* The idea is that the caller provides a set of random status list indices. We can relatively easy check against the DB in an optimized way.
|
|
35
|
+
* If the status list is large it is probably best ot also provide at least a good number of indices. So something like 10 or 20 values.
|
|
36
|
+
* Callers are also expected to call this function multiple times if it does not yield results
|
|
37
|
+
*
|
|
38
|
+
* @param args
|
|
39
|
+
*/
|
|
40
|
+
async availableStatusListEntries(args: IStatusListEntryAvailableArgs): Promise<number[]> {
|
|
41
|
+
const statusListIndex = Array.isArray(args.statusListIndex) ? args.statusListIndex : [args.statusListIndex]
|
|
42
|
+
const statusList = await this.getStatusList({ ...args, id: args.statusListId })
|
|
43
|
+
const repo = await this.getStatusListEntryRepo()
|
|
44
|
+
const results = (
|
|
45
|
+
await repo.find({
|
|
46
|
+
where: {
|
|
47
|
+
statusList,
|
|
48
|
+
statusListIndex: In(statusListIndex),
|
|
49
|
+
},
|
|
50
|
+
})
|
|
51
|
+
).map((index) => index.statusListIndex)
|
|
52
|
+
return statusListIndex.filter((index) => !results.includes(index))
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async addStatusListEntry(args: IAddStatusListEntryArgs): Promise<IStatusListEntryEntity> {
|
|
56
|
+
return (await this.getStatusListEntryRepo()).save(args)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async updateStatusListEntry(args: IAddStatusListEntryArgs): Promise<IStatusListEntryEntity> {
|
|
60
|
+
const statusListId = typeof args.statusList === 'string' ? args.statusList : args.statusList.id
|
|
61
|
+
const result = await this.getStatusListEntryByIndex({ ...args, statusListId, errorOnNotFound: false })
|
|
62
|
+
const updatedEntry: Partial<IStatusListEntryEntity> = {
|
|
63
|
+
value: args.value,
|
|
64
|
+
correlationId: args.correlationId,
|
|
65
|
+
credentialHash: args.credentialHash,
|
|
66
|
+
credentialId: args.credentialId,
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const updateResult = await (
|
|
70
|
+
await this.getStatusListEntryRepo()
|
|
71
|
+
).upsert(
|
|
72
|
+
{ ...(result ?? { statusList: args.statusList, statusListIndex: args.statusListIndex }), ...updatedEntry },
|
|
73
|
+
{ conflictPaths: ['statusList', 'statusListIndex'] }
|
|
74
|
+
)
|
|
75
|
+
console.log(updateResult)
|
|
76
|
+
return (await this.getStatusListEntryByIndex({ ...args, statusListId, errorOnNotFound: true })) as IStatusListEntryEntity
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async getStatusListEntryByIndex(args: IGetStatusListEntryByIndexArgs): Promise<StatusListEntryEntity | undefined> {
|
|
80
|
+
if (!args.statusListId && !args.correlationId) {
|
|
81
|
+
throw Error(`Cannot get statusList entry if not either a statusList id or correlationId is provided`)
|
|
82
|
+
}
|
|
83
|
+
const result = await (
|
|
84
|
+
await this.getStatusListEntryRepo()
|
|
85
|
+
).findOne({
|
|
86
|
+
where: {
|
|
87
|
+
...(args.statusListId && { statusList: args.statusListId }),
|
|
88
|
+
...(args.correlationId && { correlationId: args.correlationId }),
|
|
89
|
+
statusListIndex: args.statusListIndex,
|
|
90
|
+
},
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
if (!result && args.errorOnNotFound) {
|
|
94
|
+
throw Error(`Could not find status list index ${args.statusListIndex} for status list id ${args.statusListId}`)
|
|
95
|
+
}
|
|
96
|
+
return result ?? undefined
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async removeStatusListEntryByIndex(args: IGetStatusListEntryByIndexArgs): Promise<boolean> {
|
|
100
|
+
let error = false
|
|
101
|
+
try {
|
|
102
|
+
await this.getStatusListEntryByIndex(args) // only used to check it exists
|
|
103
|
+
} catch (error) {
|
|
104
|
+
error = true
|
|
105
|
+
}
|
|
106
|
+
if (error) {
|
|
107
|
+
console.log(`Could not delete statusList ${args.statusListId} entry by index ${args.statusListIndex}`)
|
|
108
|
+
} else {
|
|
109
|
+
const result = await (
|
|
110
|
+
await this.getStatusListEntryRepo()
|
|
111
|
+
).delete({
|
|
112
|
+
...(args.statusListId && { statusList: args.statusListId }),
|
|
113
|
+
...(args.correlationId && { correlationId: args.correlationId }),
|
|
114
|
+
statusListIndex: args.statusListIndex,
|
|
115
|
+
})
|
|
116
|
+
error = !result.affected || result.affected !== 1
|
|
117
|
+
}
|
|
118
|
+
return !error
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async getStatusListEntryByCredentialId(args: IGetStatusListEntryByCredentialIdArgs): Promise<StatusListEntryEntity | undefined> {
|
|
122
|
+
const credentialId = args.credentialId
|
|
123
|
+
if (!credentialId) {
|
|
124
|
+
throw Error('Can only get a credential by credentialId when a credentialId is supplied')
|
|
125
|
+
}
|
|
126
|
+
const statusList = await this.getStatusList({ id: args.statusListId, correlationId: args.statusListCorrelationId })
|
|
127
|
+
const where = {
|
|
128
|
+
statusList: statusList.id,
|
|
129
|
+
...(args.entryCorrelationId && { correlationId: args.entryCorrelationId }),
|
|
130
|
+
credentialId,
|
|
131
|
+
}
|
|
132
|
+
console.log(`Entries: ${JSON.stringify(await (await this.getStatusListEntryRepo()).find(), null, 2)}`)
|
|
133
|
+
const result = await (await this.getStatusListEntryRepo()).findOne({ where })
|
|
134
|
+
|
|
135
|
+
if (!result && args.errorOnNotFound) {
|
|
136
|
+
throw Error(`Could not find status list credential id ${credentialId} for status list id ${statusList.id}`)
|
|
137
|
+
}
|
|
138
|
+
return result ?? undefined
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async removeStatusListEntryByCredentialId(args: IGetStatusListEntryByCredentialIdArgs): Promise<boolean> {
|
|
142
|
+
let error = false
|
|
143
|
+
try {
|
|
144
|
+
await this.getStatusListEntryByCredentialId(args) // only used to check it exists
|
|
145
|
+
} catch (error) {
|
|
146
|
+
error = true
|
|
147
|
+
}
|
|
148
|
+
if (!error) {
|
|
149
|
+
const result = await (
|
|
150
|
+
await this.getStatusListEntryRepo()
|
|
151
|
+
).delete({
|
|
152
|
+
...(args.statusListId && { statusList: args.statusListId }),
|
|
153
|
+
...(args.entryCorrelationId && { correlationId: args.entryCorrelationId }),
|
|
154
|
+
credentialId: args.credentialId,
|
|
155
|
+
})
|
|
156
|
+
error = !result.affected || result.affected !== 1
|
|
157
|
+
}
|
|
158
|
+
return !error
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async getStatusListEntries(args: IGetStatusListEntriesArgs): Promise<StatusListEntryEntity[]> {
|
|
162
|
+
return (await this.getStatusListEntryRepo()).find({ where: { ...args?.filter, statusList: args.statusListId } })
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async getStatusList(args: IGetStatusListArgs): Promise<IStatusListEntity> {
|
|
166
|
+
if (!args.id && !args.correlationId) {
|
|
167
|
+
throw Error(`At least and 'id' or 'correlationId' needs to be provided to lookup a status list`)
|
|
168
|
+
}
|
|
169
|
+
const where = []
|
|
170
|
+
if (args.id) {
|
|
171
|
+
where.push({ id: args.id })
|
|
172
|
+
}
|
|
173
|
+
if (args.correlationId) {
|
|
174
|
+
where.push({ correlationId: args.correlationId })
|
|
175
|
+
}
|
|
176
|
+
const result = await (await this.getStatusListRepo()).findOne({ where })
|
|
177
|
+
if (!result) {
|
|
178
|
+
throw Error(`No status list found for id ${args.id}`)
|
|
179
|
+
}
|
|
180
|
+
return result
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async getStatusLists(args: IGetStatusListsArgs): Promise<Array<IStatusListEntity>> {
|
|
184
|
+
const result = await (
|
|
185
|
+
await this.getStatusListRepo()
|
|
186
|
+
).find({
|
|
187
|
+
where: args.filter,
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
if (!result) {
|
|
191
|
+
return []
|
|
192
|
+
}
|
|
193
|
+
return result
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async addStatusList(args: IAddStatusListArgs): Promise<IStatusListEntity> {
|
|
197
|
+
const { id, correlationId } = args
|
|
198
|
+
|
|
199
|
+
const result = await (
|
|
200
|
+
await this.getStatusListRepo()
|
|
201
|
+
).findOne({
|
|
202
|
+
where: [{ id }, { correlationId }],
|
|
203
|
+
})
|
|
204
|
+
if (result) {
|
|
205
|
+
throw Error(`Status list for id ${id}, correlationId ${correlationId} already exists`)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
debug('Adding status list ', id)
|
|
209
|
+
const createdResult = await (await this.getStatusListRepo()).save(args)
|
|
210
|
+
|
|
211
|
+
return createdResult
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async updateStatusList(args: IUpdateStatusListIndexArgs): Promise<IStatusListEntity> {
|
|
215
|
+
const result = await this.getStatusList(args)
|
|
216
|
+
debug('Updating status list', result)
|
|
217
|
+
const updatedResult = await (await this.getStatusListRepo()).save(args, { transaction: true })
|
|
218
|
+
return updatedResult
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
async removeStatusList(args: IRemoveStatusListArgs): Promise<void> {
|
|
222
|
+
const result = await this.getStatusList(args)
|
|
223
|
+
await (await this.getStatusListRepo()).delete(result)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
private async getDS(): Promise<DataSource> {
|
|
227
|
+
return await this._dbConnection
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
async getStatusListRepo(): Promise<Repository<StatusListEntity>> {
|
|
231
|
+
return (await this.getDS()).getRepository(StatusListEntity)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
async getStatusListEntryRepo(): Promise<Repository<StatusListEntryEntity>> {
|
|
235
|
+
return (await this.getDS()).getRepository(StatusListEntryEntity)
|
|
236
|
+
}
|
|
237
|
+
}
|