diff --git a/packages/data-store/package.json b/packages/data-store/package.json index f96410110..fad29cbe1 100644 --- a/packages/data-store/package.json +++ b/packages/data-store/package.json @@ -13,6 +13,7 @@ "typeorm-postgres:migration:run": "pnpm run typeorm -- migration:run -c migration-postgres" }, "dependencies": { + "@sphereon/ssi-sdk.core": "workspace:*", "@sphereon/ssi-types": "workspace:*", "@veramo/core": "4.2.0", "class-validator": "^0.14.0", diff --git a/packages/data-store/src/index.ts b/packages/data-store/src/index.ts index 889b3b6ca..8c03dad94 100644 --- a/packages/data-store/src/index.ts +++ b/packages/data-store/src/index.ts @@ -29,7 +29,7 @@ export { AbstractContactStore } from './contact/AbstractContactStore' export { AbstractIssuanceBrandingStore } from './issuanceBranding/AbstractIssuanceBrandingStore' export { IssuanceBrandingStore } from './issuanceBranding/IssuanceBrandingStore' export { StatusListStore } from './statusList/StatusListStore' -export { DataStoreMigrations, enableUuidv4 } from './migrations' +export { DataStoreMigrations } from './migrations' export * from './types' export * from './utils/contact/MappingUtils' diff --git a/packages/data-store/src/migrations/index.ts b/packages/data-store/src/migrations/index.ts index cc3ccde60..daad5a1dc 100644 --- a/packages/data-store/src/migrations/index.ts +++ b/packages/data-store/src/migrations/index.ts @@ -1,2 +1 @@ export { DataStoreMigrations } from './generic' -export { enableUuidv4 } from './postgres/uuid' diff --git a/packages/data-store/src/migrations/postgres/1659463079428-CreateContacts.ts b/packages/data-store/src/migrations/postgres/1659463079428-CreateContacts.ts index 691e87642..712a8a264 100644 --- a/packages/data-store/src/migrations/postgres/1659463079428-CreateContacts.ts +++ b/packages/data-store/src/migrations/postgres/1659463079428-CreateContacts.ts @@ -1,11 +1,11 @@ import { MigrationInterface, QueryRunner } from 'typeorm' -import { enableUuidv4 } from './uuid' +import { enablePostgresUuidExtension } from '@sphereon/ssi-sdk.core' export class CreateContacts1659463079428 implements MigrationInterface { name = 'CreateContacts1659463079428' public async up(queryRunner: QueryRunner): Promise { - await enableUuidv4(queryRunner) + await enablePostgresUuidExtension(queryRunner) await queryRunner.query( `CREATE TABLE "BaseConfigEntity" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "client_id" character varying(255), "client_secret" character varying(255), "scopes" text, "issuer" character varying(255), "redirect_url" text, "dangerously_allow_insecure_http_requests" boolean, "client_auth_method" text, "identifier" character varying(255), "session_id" character varying(255), "type" character varying NOT NULL, "connectionId" uuid, CONSTRAINT "REL_BaseConfig_connectionId" UNIQUE ("connectionId"), CONSTRAINT "PK_BaseConfigEntity_id" PRIMARY KEY ("id"))` ) diff --git a/packages/data-store/src/migrations/postgres/1685628974232-CreateIssuanceBranding.ts b/packages/data-store/src/migrations/postgres/1685628974232-CreateIssuanceBranding.ts index 969615420..d1ad2922d 100644 --- a/packages/data-store/src/migrations/postgres/1685628974232-CreateIssuanceBranding.ts +++ b/packages/data-store/src/migrations/postgres/1685628974232-CreateIssuanceBranding.ts @@ -1,11 +1,11 @@ import { MigrationInterface, QueryRunner } from 'typeorm' -import { enableUuidv4 } from './uuid' +import { enablePostgresUuidExtension } from '@sphereon/ssi-sdk.core' export class CreateIssuanceBranding1685628974232 implements MigrationInterface { name = 'CreateIssuanceBranding1685628974232' public async up(queryRunner: QueryRunner): Promise { - await enableUuidv4(queryRunner) + await enablePostgresUuidExtension(queryRunner) await queryRunner.query( `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"))` ) diff --git a/packages/data-store/src/migrations/postgres/1690925872592-CreateContacts.ts b/packages/data-store/src/migrations/postgres/1690925872592-CreateContacts.ts index b928cb5cc..2550cdd1d 100644 --- a/packages/data-store/src/migrations/postgres/1690925872592-CreateContacts.ts +++ b/packages/data-store/src/migrations/postgres/1690925872592-CreateContacts.ts @@ -1,11 +1,11 @@ import { MigrationInterface, QueryRunner } from 'typeorm' -import { enableUuidv4 } from './uuid' +import { enablePostgresUuidExtension } from '@sphereon/ssi-sdk.core' export class CreateContacts1690925872592 implements MigrationInterface { name = 'CreateContacts1690925872592' public async up(queryRunner: QueryRunner): Promise { - await enableUuidv4(queryRunner) + await enablePostgresUuidExtension(queryRunner) await queryRunner.query(`ALTER TABLE "CorrelationIdentifier" DROP CONSTRAINT "FK_CorrelationIdentifier_identityId"`) await queryRunner.query(`ALTER TABLE "IdentityMetadata" DROP CONSTRAINT "FK_IdentityMetadata_identityId"`) await queryRunner.query(`ALTER TABLE "Identity" DROP CONSTRAINT "FK_Identity_contactId"`) diff --git a/packages/data-store/src/migrations/postgres/uuid.ts b/packages/data-store/src/migrations/postgres/uuid.ts deleted file mode 100644 index aabfaecce..000000000 --- a/packages/data-store/src/migrations/postgres/uuid.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { QueryRunner } from 'typeorm' - -export async function enableUuidv4(queryRunner: QueryRunner) { - try { - await queryRunner.query(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp";`) - } catch (error) { - console.log( - `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` - ) - throw error - } -} diff --git a/packages/data-store/tsconfig.json b/packages/data-store/tsconfig.json index 861e525c4..42efb4cff 100644 --- a/packages/data-store/tsconfig.json +++ b/packages/data-store/tsconfig.json @@ -10,6 +10,8 @@ }, "references": [ { + "path": "../ssi-sdk-core" + }, { "path": "../ssi-types" } ] diff --git a/packages/ssi-sdk-core/src/utils/database.ts b/packages/ssi-sdk-core/src/utils/database.ts index 2d4336c08..68e1db58d 100644 --- a/packages/ssi-sdk-core/src/utils/database.ts +++ b/packages/ssi-sdk-core/src/utils/database.ts @@ -1,3 +1,22 @@ export const flattenArray = (args: { items: Array> }): Array => args.items.flat() as Array export const flattenMigrations = (args: { migrations: Array> }): Array => args.migrations.flat() as Array + +type QueryRunnerType = { + query(query: string, parameters: any[] | undefined, useStructuredResult: true): Promise + query(query: string, parameters?: any[]): Promise +} + +/** + * It should accept the type QueryRunner from the typeorm + */ +export const enablePostgresUuidExtension = async (queryRunner: QueryRunnerType) => { + try { + await queryRunner.query(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp";`) + } catch (error) { + console.error( + `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` + ) + throw error + } +} diff --git a/packages/ssi-sdk-core/src/utils/index.ts b/packages/ssi-sdk-core/src/utils/index.ts index 16630ae8c..25af8c5c0 100644 --- a/packages/ssi-sdk-core/src/utils/index.ts +++ b/packages/ssi-sdk-core/src/utils/index.ts @@ -1,4 +1,4 @@ export * from './encoding' -export { flattenArray, flattenMigrations } from './database' +export { enablePostgresUuidExtension, flattenArray, flattenMigrations } from './database' export { getImageMediaType, getImageDimensions, downloadImage } from './image' export * from './vc' diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9c2526e90..7d54c6237 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -357,6 +357,9 @@ importers: packages/data-store: dependencies: + '@sphereon/ssi-sdk.core': + specifier: workspace:* + version: link:../ssi-sdk-core '@sphereon/ssi-types': specifier: workspace:* version: link:../ssi-types @@ -6309,7 +6312,7 @@ packages: '@octokit/request-error': 3.0.3 '@octokit/types': 9.3.2 is-plain-object: 5.0.0 - node-fetch: 2.6.7 + node-fetch: 2.7.0 universal-user-agent: 6.0.0 transitivePeerDependencies: - encoding