@credo-ts/drizzle-storage 0.6.0-pr-2324-20250708122805 → 0.6.0-pr-2324-20250709075226
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/cli/drizzle.config.ts +1 -1
- package/cli-build/drizzle.config.js +1 -1
- package/cli-build/drizzle.config.js.map +1 -1
- package/package.json +18 -17
- package/src/DrizzleDatabase.ts +29 -0
- package/src/DrizzleRecord.ts +73 -0
- package/src/DrizzleStorageModule.ts +112 -0
- package/src/DrizzleStorageModuleConfig.ts +48 -0
- package/src/action-menu/action-menu/DrizzleDidcommActionMenuRecordAdapter.ts +46 -0
- package/src/action-menu/action-menu/index.ts +10 -0
- package/src/action-menu/action-menu/postgres.ts +31 -0
- package/src/action-menu/action-menu/sqlite.ts +34 -0
- package/src/action-menu/bundle.ts +18 -0
- package/src/action-menu/postgres.ts +1 -0
- package/src/action-menu/sqlite.ts +1 -0
- package/src/adapter/BaseDrizzleRecordAdapter.ts +319 -0
- package/src/adapter/__tests__/queryToDrizzlePostgres.drizzle.e2e.test.ts +330 -0
- package/src/adapter/__tests__/queryToDrizzleSqlite.test.ts +324 -0
- package/src/adapter/index.ts +6 -0
- package/src/adapter/queryToDrizzlePostgres.ts +217 -0
- package/src/adapter/queryToDrizzleSqlite.ts +213 -0
- package/src/anoncreds/bundle.ts +34 -0
- package/src/anoncreds/credential/DrizzleAnonCredsCredentialRecordAdapter.ts +93 -0
- package/src/anoncreds/credential/index.ts +10 -0
- package/src/anoncreds/credential/postgres.ts +27 -0
- package/src/anoncreds/credential/sqlite.ts +27 -0
- package/src/anoncreds/credential-definition/DrizzleAnonCredsCredentialDefinitionRecordAdapter.ts +72 -0
- package/src/anoncreds/credential-definition/index.ts +10 -0
- package/src/anoncreds/credential-definition/postgres.ts +23 -0
- package/src/anoncreds/credential-definition/sqlite.ts +23 -0
- package/src/anoncreds/credential-definition-private/DrizzleAnonCredsCredentialDefinitionPrivateRecordAdapter.ts +48 -0
- package/src/anoncreds/credential-definition-private/index.ts +10 -0
- package/src/anoncreds/credential-definition-private/postgres.ts +14 -0
- package/src/anoncreds/credential-definition-private/sqlite.ts +14 -0
- package/src/anoncreds/key-correctness-proof/DrizzleAnonCredsKeyCorrectnessProofRecordAdapter.ts +46 -0
- package/src/anoncreds/key-correctness-proof/index.ts +10 -0
- package/src/anoncreds/key-correctness-proof/postgres.ts +13 -0
- package/src/anoncreds/key-correctness-proof/sqlite.ts +14 -0
- package/src/anoncreds/link-secret/DrizzleAnonCredsLinkSecretRecordAdapter.ts +45 -0
- package/src/anoncreds/link-secret/index.ts +10 -0
- package/src/anoncreds/link-secret/postgres.ts +18 -0
- package/src/anoncreds/link-secret/sqlite.ts +18 -0
- package/src/anoncreds/postgres.ts +8 -0
- package/src/anoncreds/revocation-registry-definition/DrizzleAnonCredsRevocationRegistryDefinitionRecordAdapter.ts +52 -0
- package/src/anoncreds/revocation-registry-definition/index.ts +10 -0
- package/src/anoncreds/revocation-registry-definition/postgres.ts +18 -0
- package/src/anoncreds/revocation-registry-definition/sqlite.ts +20 -0
- package/src/anoncreds/revocation-registry-definition-private/DrizzleAnonCredsRevocationRegistryDefinitionPrivateRecordAdapter.ts +53 -0
- package/src/anoncreds/revocation-registry-definition-private/index.ts +10 -0
- package/src/anoncreds/revocation-registry-definition-private/postgres.ts +22 -0
- package/src/anoncreds/revocation-registry-definition-private/sqlite.ts +18 -0
- package/src/anoncreds/schema/DrizzleAnonCredsSchemaRecordAdapter.ts +54 -0
- package/src/anoncreds/schema/__tests__/schema.drizzle.e2e.test.ts +70 -0
- package/src/anoncreds/schema/index.ts +10 -0
- package/src/anoncreds/schema/postgres.ts +22 -0
- package/src/anoncreds/schema/sqlite.ts +22 -0
- package/src/anoncreds/sqlite.ts +8 -0
- package/src/applyReactNativeMigrations.ts +24 -0
- package/src/combineSchemas.ts +44 -0
- package/src/core/bundle.ts +33 -0
- package/src/core/context/index.ts +8 -0
- package/src/core/context/postgres.ts +5 -0
- package/src/core/context/sqlite.ts +5 -0
- package/src/core/did/DrizzleDidRecordAdapter.ts +71 -0
- package/src/core/did/index.ts +10 -0
- package/src/core/did/postgres.ts +28 -0
- package/src/core/did/sqlite.ts +26 -0
- package/src/core/genericRecord/DrizzleGenericRecordAdapter.ts +36 -0
- package/src/core/genericRecord/index.ts +10 -0
- package/src/core/genericRecord/postgres.ts +12 -0
- package/src/core/genericRecord/sqlite.ts +12 -0
- package/src/core/mdoc/DrizzleMdocRecordAdapter.ts +44 -0
- package/src/core/mdoc/index.ts +10 -0
- package/src/core/mdoc/postgres.ts +15 -0
- package/src/core/mdoc/sqlite.ts +15 -0
- package/src/core/postgres.ts +8 -0
- package/src/core/sdJwtVc/DrizzleSdJwtVcRecordAdapter.ts +46 -0
- package/src/core/sdJwtVc/index.ts +10 -0
- package/src/core/sdJwtVc/postgres.ts +17 -0
- package/src/core/sdJwtVc/sqlite.ts +17 -0
- package/src/core/singleContextLruCache/DrizzleSingleContextLruCacheRecordAdapter.ts +43 -0
- package/src/core/singleContextLruCache/index.ts +10 -0
- package/src/core/singleContextLruCache/postgres.ts +12 -0
- package/src/core/singleContextLruCache/sqlite.ts +13 -0
- package/src/core/sqlite.ts +8 -0
- package/src/core/storageVersion/DrizzleStorageVersionRecordAdapter.ts +36 -0
- package/src/core/storageVersion/index.ts +10 -0
- package/src/core/storageVersion/postgres.ts +13 -0
- package/src/core/storageVersion/sqlite.ts +13 -0
- package/src/core/w3cCredential/DrizzleW3cCredentialRecordAdapter.ts +95 -0
- package/src/core/w3cCredential/index.ts +10 -0
- package/src/core/w3cCredential/postgres.ts +31 -0
- package/src/core/w3cCredential/sqlite.ts +29 -0
- package/src/didcomm/basic-message/DrizzleDidcommBasicMessageRecordAdapter.ts +54 -0
- package/src/didcomm/basic-message/index.ts +10 -0
- package/src/didcomm/basic-message/postgres.ts +30 -0
- package/src/didcomm/basic-message/sqlite.ts +29 -0
- package/src/didcomm/bundle.ts +34 -0
- package/src/didcomm/connection/DrizzleDidcommConnectionRecordAdapter.ts +70 -0
- package/src/didcomm/connection/index.ts +10 -0
- package/src/didcomm/connection/postgres.ts +55 -0
- package/src/didcomm/connection/sqlite.ts +39 -0
- package/src/didcomm/credential-exchange/DrizzleDidcommCredentialExchangeRecordAdapter.ts +64 -0
- package/src/didcomm/credential-exchange/__tests__/credentialExchange.drizzle.e2e.test.ts +104 -0
- package/src/didcomm/credential-exchange/index.ts +10 -0
- package/src/didcomm/credential-exchange/postgres.ts +45 -0
- package/src/didcomm/credential-exchange/sqlite.ts +39 -0
- package/src/didcomm/didcomm-message/DrizzleDidcommMessageRecordAdapter.ts +75 -0
- package/src/didcomm/didcomm-message/index.ts +10 -0
- package/src/didcomm/didcomm-message/postgres.ts +27 -0
- package/src/didcomm/didcomm-message/sqlite.ts +26 -0
- package/src/didcomm/mediation/DrizzleDidcommMediationRecordAdapter.ts +51 -0
- package/src/didcomm/mediation/index.ts +10 -0
- package/src/didcomm/mediation/postgres.ts +33 -0
- package/src/didcomm/mediation/sqlite.ts +31 -0
- package/src/didcomm/mediator-routing/DrizzleDidcommMediatorRoutingRecordAdapter.ts +49 -0
- package/src/didcomm/mediator-routing/index.ts +10 -0
- package/src/didcomm/mediator-routing/postgres.ts +14 -0
- package/src/didcomm/mediator-routing/sqlite.ts +17 -0
- package/src/didcomm/out-of-band/DrizzleDidcommOutOfBandRecordAdapter.ts +85 -0
- package/src/didcomm/out-of-band/__tests__/outOfBand.drizzle.e2e.test.ts +88 -0
- package/src/didcomm/out-of-band/index.ts +10 -0
- package/src/didcomm/out-of-band/postgres.ts +46 -0
- package/src/didcomm/out-of-band/sqlite.ts +46 -0
- package/src/didcomm/postgres.ts +8 -0
- package/src/didcomm/proof-exchange/DrizzleDidcommProofExchangeRecordAdapter.ts +51 -0
- package/src/didcomm/proof-exchange/index.ts +10 -0
- package/src/didcomm/proof-exchange/postgres.ts +33 -0
- package/src/didcomm/proof-exchange/sqlite.ts +29 -0
- package/src/didcomm/sqlite.ts +8 -0
- package/src/drpc/bundle.ts +18 -0
- package/src/drpc/drpc/DrizzleDidcommDrpcRecordAdapter.ts +44 -0
- package/src/drpc/drpc/index.ts +10 -0
- package/src/drpc/drpc/postgres.ts +31 -0
- package/src/drpc/drpc/sqlite.ts +29 -0
- package/src/drpc/postgres.ts +1 -0
- package/src/drpc/sqlite.ts +1 -0
- package/src/error/CredoDrizzleColumnDoesNotExistError.ts +21 -0
- package/src/error/CredoDrizzleStorageError.ts +7 -0
- package/src/error/index.ts +2 -0
- package/src/index.ts +29 -0
- package/src/openid4vc/bundle.ts +26 -0
- package/src/openid4vc/openid4vc-issuance-session/DrizzleOpenId4VcIssuanceSessionRecordAdapter.ts +90 -0
- package/src/openid4vc/openid4vc-issuance-session/index.ts +10 -0
- package/src/openid4vc/openid4vc-issuance-session/postgres.ts +54 -0
- package/src/openid4vc/openid4vc-issuance-session/sqlite.ts +54 -0
- package/src/openid4vc/openid4vc-issuer/DrizzleOpenid4vcIssuerRecordAdapter.ts +50 -0
- package/src/openid4vc/openid4vc-issuer/index.ts +10 -0
- package/src/openid4vc/openid4vc-issuer/postgres.ts +31 -0
- package/src/openid4vc/openid4vc-issuer/sqlite.ts +40 -0
- package/src/openid4vc/openid4vc-verification-session/DrizzleOpenId4VcVerificationSessionRecordAdapter.ts +62 -0
- package/src/openid4vc/openid4vc-verification-session/index.ts +10 -0
- package/src/openid4vc/openid4vc-verification-session/postgres.ts +46 -0
- package/src/openid4vc/openid4vc-verification-session/sqlite.ts +40 -0
- package/src/openid4vc/openid4vc-verifier/DrizzleOpenid4vcVerifierRecordAdapter.ts +43 -0
- package/src/openid4vc/openid4vc-verifier/index.ts +10 -0
- package/src/openid4vc/openid4vc-verifier/postgres.ts +14 -0
- package/src/openid4vc/openid4vc-verifier/sqlite.ts +19 -0
- package/src/openid4vc/postgres.ts +4 -0
- package/src/openid4vc/sqlite.ts +4 -0
- package/src/postgres/baseRecord.ts +44 -0
- package/src/postgres/index.ts +1 -0
- package/src/question-answer/bundle.ts +18 -0
- package/src/question-answer/postgres.ts +1 -0
- package/src/question-answer/question-answer/DrizzleDidcommQuestionAnswerRecordAdapter.ts +52 -0
- package/src/question-answer/question-answer/index.ts +10 -0
- package/src/question-answer/question-answer/postgres.ts +34 -0
- package/src/question-answer/question-answer/sqlite.ts +32 -0
- package/src/question-answer/sqlite.ts +1 -0
- package/src/sqlite/baseRecord.ts +38 -0
- package/src/sqlite/index.ts +1 -0
- package/src/storage/DrizzleStorageService.ts +87 -0
- package/src/storage/index.ts +1 -0
- package/src/tenants/bundle.ts +19 -0
- package/src/tenants/postgres.ts +2 -0
- package/src/tenants/sqlite.ts +2 -0
- package/src/tenants/tenant/DrizzleTenantRecordAdapter.ts +45 -0
- package/src/tenants/tenant/index.ts +10 -0
- package/src/tenants/tenant/postgres.ts +16 -0
- package/src/tenants/tenant/sqlite.ts +16 -0
- package/src/tenants/tenant-routing/DrizzleTenantRoutingRecordAdapter.ts +44 -0
- package/src/tenants/tenant-routing/index.ts +10 -0
- package/src/tenants/tenant-routing/postgres.ts +20 -0
- package/src/tenants/tenant-routing/sqlite.ts +20 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OpenId4VcIssuanceSessionAuthorization,
|
|
3
|
+
OpenId4VcIssuanceSessionDpop,
|
|
4
|
+
OpenId4VcIssuanceSessionPresentation,
|
|
5
|
+
OpenId4VcIssuanceSessionRecord,
|
|
6
|
+
OpenId4VcIssuanceSessionState,
|
|
7
|
+
OpenId4VcIssuanceSessionWalletAttestation,
|
|
8
|
+
OpenId4VciCredentialOfferPayload,
|
|
9
|
+
} from '@credo-ts/openid4vc'
|
|
10
|
+
import { sqliteTable, text } from 'drizzle-orm/sqlite-core'
|
|
11
|
+
import { getSqliteBaseRecordTable, sqliteBaseRecordIndexes } from '../../sqlite/baseRecord'
|
|
12
|
+
import { openid4vcIssuer } from '../sqlite'
|
|
13
|
+
|
|
14
|
+
export const openId4VcIssuanceSession = sqliteTable(
|
|
15
|
+
'OpenId4VcIssuanceSession',
|
|
16
|
+
{
|
|
17
|
+
...getSqliteBaseRecordTable(),
|
|
18
|
+
|
|
19
|
+
issuerId: text('issuer_id')
|
|
20
|
+
.notNull()
|
|
21
|
+
.references(() => openid4vcIssuer.issuerId, { onDelete: 'cascade' }),
|
|
22
|
+
|
|
23
|
+
state: text().$type<OpenId4VcIssuanceSessionState>().notNull(),
|
|
24
|
+
issuedCredentials: text('issued_credentials', { mode: 'json' }).$type<string[]>(),
|
|
25
|
+
|
|
26
|
+
// Pre-authorized flow
|
|
27
|
+
preAuthorizedCode: text('pre_authorized_code'),
|
|
28
|
+
userPin: text('user_pin'),
|
|
29
|
+
|
|
30
|
+
// Client and authentication
|
|
31
|
+
clientId: text('client_id'),
|
|
32
|
+
|
|
33
|
+
pkce: text({ mode: 'json' }).$type<NonNullable<OpenId4VcIssuanceSessionRecord['pkce']>>(),
|
|
34
|
+
walletAttestation: text('wallet_attestation', { mode: 'json' }).$type<OpenId4VcIssuanceSessionWalletAttestation>(),
|
|
35
|
+
dpop: text({ mode: 'json' }).$type<OpenId4VcIssuanceSessionDpop>(),
|
|
36
|
+
authorization: text({ mode: 'json' }).$type<
|
|
37
|
+
Omit<OpenId4VcIssuanceSessionAuthorization, 'codeExpiresAt'> & { codeExpiresAt?: string }
|
|
38
|
+
>(),
|
|
39
|
+
presentation: text({ mode: 'json' }).$type<OpenId4VcIssuanceSessionPresentation>(),
|
|
40
|
+
|
|
41
|
+
// Metadata and error handling
|
|
42
|
+
issuanceMetadata: text('issuance_metadata', { mode: 'json' }).$type<Record<string, unknown>>(),
|
|
43
|
+
|
|
44
|
+
// Credential offer
|
|
45
|
+
credentialOfferUri: text('credential_offer_uri'),
|
|
46
|
+
credentialOfferId: text('credential_offer_id'),
|
|
47
|
+
credentialOfferPayload: text('credential_offer_payload', { mode: 'json' })
|
|
48
|
+
.$type<OpenId4VciCredentialOfferPayload>()
|
|
49
|
+
.notNull(),
|
|
50
|
+
|
|
51
|
+
errorMessage: text('error_message'),
|
|
52
|
+
},
|
|
53
|
+
(table) => sqliteBaseRecordIndexes(table, 'openId4VcIssuanceSession')
|
|
54
|
+
)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { JsonTransformer, TagsBase } from '@credo-ts/core'
|
|
2
|
+
|
|
3
|
+
import { OpenId4VcIssuerRecord } from '@credo-ts/openid4vc'
|
|
4
|
+
import { DrizzleDatabase } from '../../DrizzleDatabase'
|
|
5
|
+
import {
|
|
6
|
+
BaseDrizzleRecordAdapter,
|
|
7
|
+
DrizzleAdapterRecordValues,
|
|
8
|
+
DrizzleAdapterValues,
|
|
9
|
+
} from '../../adapter/BaseDrizzleRecordAdapter'
|
|
10
|
+
import * as postgres from './postgres'
|
|
11
|
+
import * as sqlite from './sqlite'
|
|
12
|
+
|
|
13
|
+
type DrizzleOpenid4vcIssuerAdapterValues = DrizzleAdapterRecordValues<(typeof sqlite)['openid4vcIssuer']>
|
|
14
|
+
export class DrizzleOpenid4vcIssuerRecordAdapter extends BaseDrizzleRecordAdapter<
|
|
15
|
+
OpenId4VcIssuerRecord,
|
|
16
|
+
typeof postgres.openid4vcIssuer,
|
|
17
|
+
typeof postgres,
|
|
18
|
+
typeof sqlite.openid4vcIssuer,
|
|
19
|
+
typeof sqlite
|
|
20
|
+
> {
|
|
21
|
+
public constructor(database: DrizzleDatabase<typeof postgres, typeof sqlite>) {
|
|
22
|
+
super(database, { postgres: postgres.openid4vcIssuer, sqlite: sqlite.openid4vcIssuer }, 'OpenId4VcIssuerRecord')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public getValues(record: OpenId4VcIssuerRecord): DrizzleAdapterValues<(typeof sqlite)['openid4vcIssuer']> {
|
|
26
|
+
const { issuerId, ...customTags } = record.getTags()
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
issuerId,
|
|
30
|
+
accessTokenPublicJwk: record.accessTokenPublicJwk,
|
|
31
|
+
accessTokenPublicKeyFingerprint: record.accessTokenPublicKeyFingerprint,
|
|
32
|
+
credentialConfigurationsSupported: record.credentialConfigurationsSupported,
|
|
33
|
+
dpopSigningAlgValuesSupported: record.dpopSigningAlgValuesSupported,
|
|
34
|
+
display: record.display,
|
|
35
|
+
authorizationServerConfigs: record.authorizationServerConfigs,
|
|
36
|
+
batchCredentialIssuance: record.batchCredentialIssuance,
|
|
37
|
+
|
|
38
|
+
customTags,
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public toRecord(values: DrizzleOpenid4vcIssuerAdapterValues): OpenId4VcIssuerRecord {
|
|
43
|
+
const { customTags, ...remainingValues } = values
|
|
44
|
+
|
|
45
|
+
const record = JsonTransformer.fromJSON(remainingValues, OpenId4VcIssuerRecord)
|
|
46
|
+
if (customTags) record.setTags(customTags as TagsBase)
|
|
47
|
+
|
|
48
|
+
return record
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DrizzleRecord } from '../../DrizzleRecord'
|
|
2
|
+
import { DrizzleOpenid4vcIssuerRecordAdapter } from './DrizzleOpenid4vcIssuerRecordAdapter'
|
|
3
|
+
import * as postgres from './postgres'
|
|
4
|
+
import * as sqlite from './sqlite'
|
|
5
|
+
|
|
6
|
+
export const openid4vcIssuerDrizzleRecord = {
|
|
7
|
+
adapter: DrizzleOpenid4vcIssuerRecordAdapter,
|
|
8
|
+
postgres,
|
|
9
|
+
sqlite,
|
|
10
|
+
} satisfies DrizzleRecord
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Kms } from '@credo-ts/core'
|
|
2
|
+
import {
|
|
3
|
+
OpenId4VciAuthorizationServerConfig,
|
|
4
|
+
OpenId4VciBatchCredentialIssuanceOptions,
|
|
5
|
+
OpenId4VciCredentialConfigurationsSupportedWithFormats,
|
|
6
|
+
OpenId4VciCredentialIssuerMetadataDisplay,
|
|
7
|
+
} from '@credo-ts/openid4vc'
|
|
8
|
+
import { jsonb, pgTable, text } from 'drizzle-orm/pg-core'
|
|
9
|
+
import { getPostgresBaseRecordTable, postgresBaseRecordIndexes } from '../../postgres/baseRecord'
|
|
10
|
+
|
|
11
|
+
export const openid4vcIssuer = pgTable(
|
|
12
|
+
'Openid4vcIssuer',
|
|
13
|
+
{
|
|
14
|
+
...getPostgresBaseRecordTable(),
|
|
15
|
+
|
|
16
|
+
issuerId: text('issuer_id').unique().notNull(),
|
|
17
|
+
accessTokenPublicKeyFingerprint: jsonb('access_token_public_key_fingerprint'),
|
|
18
|
+
accessTokenPublicJwk: jsonb('access_token_public_jwk').$type<Kms.KmsJwkPublicAsymmetric>(),
|
|
19
|
+
|
|
20
|
+
credentialConfigurationsSupported: jsonb('credential_configurations_supported')
|
|
21
|
+
.$type<OpenId4VciCredentialConfigurationsSupportedWithFormats>()
|
|
22
|
+
.notNull(),
|
|
23
|
+
display: jsonb().$type<OpenId4VciCredentialIssuerMetadataDisplay[]>(),
|
|
24
|
+
authorizationServerConfigs: jsonb('authorization_server_configs').$type<OpenId4VciAuthorizationServerConfig[]>(),
|
|
25
|
+
dpopSigningAlgValuesSupported: jsonb('dpop_signing_alg_values_supported').$type<
|
|
26
|
+
[Kms.KnownJwaSignatureAlgorithm, ...Kms.KnownJwaSignatureAlgorithm[]]
|
|
27
|
+
>(),
|
|
28
|
+
batchCredentialIssuance: text('batch_credential_issuance').$type<OpenId4VciBatchCredentialIssuanceOptions>(),
|
|
29
|
+
},
|
|
30
|
+
(table) => postgresBaseRecordIndexes(table, 'openid4vcIssuer')
|
|
31
|
+
)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Kms } from '@credo-ts/core'
|
|
2
|
+
import {
|
|
3
|
+
OpenId4VciAuthorizationServerConfig,
|
|
4
|
+
OpenId4VciBatchCredentialIssuanceOptions,
|
|
5
|
+
OpenId4VciCredentialConfigurationsSupportedWithFormats,
|
|
6
|
+
OpenId4VciCredentialIssuerMetadataDisplay,
|
|
7
|
+
} from '@credo-ts/openid4vc'
|
|
8
|
+
import { sqliteTable, text } from 'drizzle-orm/sqlite-core'
|
|
9
|
+
import { getSqliteBaseRecordTable, sqliteBaseRecordIndexes } from '../../sqlite/baseRecord'
|
|
10
|
+
|
|
11
|
+
export const openid4vcIssuer = sqliteTable(
|
|
12
|
+
'Openid4vcIssuer',
|
|
13
|
+
{
|
|
14
|
+
...getSqliteBaseRecordTable(),
|
|
15
|
+
|
|
16
|
+
// NOTE: generally we don't have unique constraints on single fields,
|
|
17
|
+
// (always in combination with the context correlation id), but for issuer
|
|
18
|
+
// id, it will actually cause issues, since we use the issuerId in the public
|
|
19
|
+
// url and map that to the context correlation id.
|
|
20
|
+
issuerId: text('issuer_id').notNull().unique(),
|
|
21
|
+
|
|
22
|
+
accessTokenPublicKeyFingerprint: text('access_token_public_key_fingerprint', {
|
|
23
|
+
mode: 'json',
|
|
24
|
+
}),
|
|
25
|
+
accessTokenPublicJwk: text('access_token_public_jwk', { mode: 'json' }).$type<Kms.KmsJwkPublicAsymmetric>(),
|
|
26
|
+
|
|
27
|
+
credentialConfigurationsSupported: text('credential_configurations_supported', { mode: 'json' })
|
|
28
|
+
.$type<OpenId4VciCredentialConfigurationsSupportedWithFormats>()
|
|
29
|
+
.notNull(),
|
|
30
|
+
display: text({ mode: 'json' }).$type<OpenId4VciCredentialIssuerMetadataDisplay[]>(),
|
|
31
|
+
authorizationServerConfigs: text('authorization_server_configs', { mode: 'json' }).$type<
|
|
32
|
+
OpenId4VciAuthorizationServerConfig[]
|
|
33
|
+
>(),
|
|
34
|
+
dpopSigningAlgValuesSupported: text('dpop_signing_alg_values_supported', { mode: 'json' }).$type<
|
|
35
|
+
[Kms.KnownJwaSignatureAlgorithm, ...Kms.KnownJwaSignatureAlgorithm[]]
|
|
36
|
+
>(),
|
|
37
|
+
batchCredentialIssuance: text('batch_credential_issuance').$type<OpenId4VciBatchCredentialIssuanceOptions>(),
|
|
38
|
+
},
|
|
39
|
+
(table) => sqliteBaseRecordIndexes(table, 'openid4vcIssuer')
|
|
40
|
+
)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { JsonTransformer, TagsBase } from '@credo-ts/core'
|
|
2
|
+
|
|
3
|
+
import { OpenId4VcVerificationSessionRecord } from '@credo-ts/openid4vc'
|
|
4
|
+
import { DrizzleDatabase } from '../../DrizzleDatabase'
|
|
5
|
+
import {
|
|
6
|
+
BaseDrizzleRecordAdapter,
|
|
7
|
+
DrizzleAdapterRecordValues,
|
|
8
|
+
DrizzleAdapterValues,
|
|
9
|
+
} from '../../adapter/BaseDrizzleRecordAdapter'
|
|
10
|
+
import * as postgres from './postgres'
|
|
11
|
+
import * as sqlite from './sqlite'
|
|
12
|
+
|
|
13
|
+
type DrizzleOpenId4VcVerificationSessionAdapterValues = DrizzleAdapterRecordValues<
|
|
14
|
+
(typeof sqlite)['openId4VcVerificationSession']
|
|
15
|
+
>
|
|
16
|
+
export class DrizzleOpenId4VcVerificationSessionRecordAdapter extends BaseDrizzleRecordAdapter<
|
|
17
|
+
OpenId4VcVerificationSessionRecord,
|
|
18
|
+
typeof postgres.openId4VcVerificationSession,
|
|
19
|
+
typeof postgres,
|
|
20
|
+
typeof sqlite.openId4VcVerificationSession,
|
|
21
|
+
typeof sqlite
|
|
22
|
+
> {
|
|
23
|
+
public constructor(database: DrizzleDatabase<typeof postgres, typeof sqlite>) {
|
|
24
|
+
super(
|
|
25
|
+
database,
|
|
26
|
+
{ postgres: postgres.openId4VcVerificationSession, sqlite: sqlite.openId4VcVerificationSession },
|
|
27
|
+
'OpenId4VcVerificationSessionRecord'
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public getValues(
|
|
32
|
+
record: OpenId4VcVerificationSessionRecord
|
|
33
|
+
): DrizzleAdapterValues<(typeof sqlite)['openId4VcVerificationSession']> {
|
|
34
|
+
const { authorizationRequestId, authorizationRequestUri, nonce, payloadState, state, verifierId, ...customTags } =
|
|
35
|
+
record.getTags()
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
authorizationRequestJwt: record.authorizationRequestJwt,
|
|
39
|
+
authorizationRequestPayload: record.authorizationRequestPayload,
|
|
40
|
+
authorizationResponsePayload: record.authorizationResponsePayload,
|
|
41
|
+
errorMessage: record.errorMessage,
|
|
42
|
+
expiresAt: record.expiresAt,
|
|
43
|
+
presentationDuringIssuanceSession: record.presentationDuringIssuanceSession,
|
|
44
|
+
authorizationRequestId,
|
|
45
|
+
authorizationRequestUri,
|
|
46
|
+
nonce,
|
|
47
|
+
payloadState,
|
|
48
|
+
state,
|
|
49
|
+
verifierId,
|
|
50
|
+
customTags,
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public toRecord(values: DrizzleOpenId4VcVerificationSessionAdapterValues): OpenId4VcVerificationSessionRecord {
|
|
55
|
+
const { customTags, nonce, payloadState, ...remainingValues } = values
|
|
56
|
+
|
|
57
|
+
const record = JsonTransformer.fromJSON(remainingValues, OpenId4VcVerificationSessionRecord)
|
|
58
|
+
if (customTags) record.setTags(customTags as TagsBase)
|
|
59
|
+
|
|
60
|
+
return record
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DrizzleRecord } from '../../DrizzleRecord'
|
|
2
|
+
import { DrizzleOpenId4VcVerificationSessionRecordAdapter } from './DrizzleOpenId4VcVerificationSessionRecordAdapter'
|
|
3
|
+
import * as postgres from './postgres'
|
|
4
|
+
import * as sqlite from './sqlite'
|
|
5
|
+
|
|
6
|
+
export const openId4VcVerificationSessionDrizzleRecord = {
|
|
7
|
+
adapter: DrizzleOpenId4VcVerificationSessionRecordAdapter,
|
|
8
|
+
postgres,
|
|
9
|
+
sqlite,
|
|
10
|
+
} satisfies DrizzleRecord
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OpenId4VcVerificationSessionState,
|
|
3
|
+
OpenId4VpAuthorizationRequestPayload,
|
|
4
|
+
OpenId4VpAuthorizationResponsePayload,
|
|
5
|
+
} from '@credo-ts/openid4vc'
|
|
6
|
+
import { jsonb, pgEnum, pgTable, text, timestamp } from 'drizzle-orm/pg-core'
|
|
7
|
+
import { getPostgresBaseRecordTable, postgresBaseRecordIndexes } from '../../postgres/baseRecord'
|
|
8
|
+
import { openid4vcVerifier } from '../postgres'
|
|
9
|
+
|
|
10
|
+
export const openId4VcVerificationSessionStateEnum = pgEnum(
|
|
11
|
+
'OpenId4VcVerificationSessionState',
|
|
12
|
+
OpenId4VcVerificationSessionState
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
export const openId4VcVerificationSession = pgTable(
|
|
16
|
+
'OpenId4VcVerificationSession',
|
|
17
|
+
{
|
|
18
|
+
...getPostgresBaseRecordTable(),
|
|
19
|
+
|
|
20
|
+
verifierId: text('verifier_id')
|
|
21
|
+
.notNull()
|
|
22
|
+
.references(() => openid4vcVerifier.verifierId, { onDelete: 'cascade' }),
|
|
23
|
+
|
|
24
|
+
state: openId4VcVerificationSessionStateEnum().notNull(),
|
|
25
|
+
errorMessage: text('error_message'),
|
|
26
|
+
|
|
27
|
+
authorizationRequestJwt: text('authorization_request_jwt'),
|
|
28
|
+
authorizationRequestPayload: jsonb('authorization_request_payload').$type<OpenId4VpAuthorizationRequestPayload>(),
|
|
29
|
+
authorizationRequestUri: text('authorization_request_uri'),
|
|
30
|
+
authorizationRequestId: text('authorization_request_id'),
|
|
31
|
+
|
|
32
|
+
expiresAt: timestamp('expires_at', {
|
|
33
|
+
withTimezone: true,
|
|
34
|
+
precision: 3,
|
|
35
|
+
}),
|
|
36
|
+
authorizationResponsePayload: jsonb(
|
|
37
|
+
'authorization_response_payload'
|
|
38
|
+
).$type<OpenId4VpAuthorizationResponsePayload>(),
|
|
39
|
+
presentationDuringIssuanceSession: text('presentation_during_issuance_session'),
|
|
40
|
+
|
|
41
|
+
// These tags may be encoded in a JWT, so we need to duplicate them
|
|
42
|
+
nonce: text().notNull(),
|
|
43
|
+
payloadState: text('payload_state'),
|
|
44
|
+
},
|
|
45
|
+
(table) => postgresBaseRecordIndexes(table, 'openId4VcVerificationSession')
|
|
46
|
+
)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OpenId4VcVerificationSessionState,
|
|
3
|
+
OpenId4VpAuthorizationRequestPayload,
|
|
4
|
+
OpenId4VpAuthorizationResponsePayload,
|
|
5
|
+
} from '@credo-ts/openid4vc'
|
|
6
|
+
import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core'
|
|
7
|
+
import { getSqliteBaseRecordTable, sqliteBaseRecordIndexes } from '../../sqlite/baseRecord'
|
|
8
|
+
import { openid4vcVerifier } from '../sqlite'
|
|
9
|
+
|
|
10
|
+
export const openId4VcVerificationSession = sqliteTable(
|
|
11
|
+
'OpenId4VcVerificationSession',
|
|
12
|
+
{
|
|
13
|
+
...getSqliteBaseRecordTable(),
|
|
14
|
+
|
|
15
|
+
verifierId: text('verifier_id')
|
|
16
|
+
.notNull()
|
|
17
|
+
.references(() => openid4vcVerifier.verifierId, { onDelete: 'cascade' }),
|
|
18
|
+
|
|
19
|
+
state: text().$type<OpenId4VcVerificationSessionState>().notNull(),
|
|
20
|
+
errorMessage: text('error_message'),
|
|
21
|
+
|
|
22
|
+
authorizationRequestJwt: text('authorization_request_jwt'),
|
|
23
|
+
authorizationRequestPayload: text('authorization_request_payload', {
|
|
24
|
+
mode: 'json',
|
|
25
|
+
}).$type<OpenId4VpAuthorizationRequestPayload>(),
|
|
26
|
+
authorizationRequestUri: text('authorization_request_uri'),
|
|
27
|
+
authorizationRequestId: text('authorization_request_id'),
|
|
28
|
+
|
|
29
|
+
expiresAt: integer('expires_at', { mode: 'timestamp_ms' }),
|
|
30
|
+
authorizationResponsePayload: text('authorization_response_payload', {
|
|
31
|
+
mode: 'json',
|
|
32
|
+
}).$type<OpenId4VpAuthorizationResponsePayload>(),
|
|
33
|
+
presentationDuringIssuanceSession: text('presentation_during_issuance_session'),
|
|
34
|
+
|
|
35
|
+
// These tags may be encoded in a JWT, so we need to duplicate them
|
|
36
|
+
nonce: text().notNull(),
|
|
37
|
+
payloadState: text('payload_state'),
|
|
38
|
+
},
|
|
39
|
+
(table) => sqliteBaseRecordIndexes(table, 'openId4VcVerificationSession')
|
|
40
|
+
)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { JsonTransformer, TagsBase } from '@credo-ts/core'
|
|
2
|
+
|
|
3
|
+
import { OpenId4VcVerifierRecord } from '@credo-ts/openid4vc'
|
|
4
|
+
import { DrizzleDatabase } from '../../DrizzleDatabase'
|
|
5
|
+
import { BaseDrizzleRecordAdapter, DrizzleAdapterRecordValues } from '../../adapter/BaseDrizzleRecordAdapter'
|
|
6
|
+
import * as postgres from './postgres'
|
|
7
|
+
import * as sqlite from './sqlite'
|
|
8
|
+
|
|
9
|
+
type DrizzleOpenid4vcVerifierAdapterValues = DrizzleAdapterRecordValues<(typeof sqlite)['openid4vcVerifier']>
|
|
10
|
+
export class DrizzleOpenid4vcVerifierRecordAdapter extends BaseDrizzleRecordAdapter<
|
|
11
|
+
OpenId4VcVerifierRecord,
|
|
12
|
+
typeof postgres.openid4vcVerifier,
|
|
13
|
+
typeof postgres,
|
|
14
|
+
typeof sqlite.openid4vcVerifier,
|
|
15
|
+
typeof sqlite
|
|
16
|
+
> {
|
|
17
|
+
public constructor(database: DrizzleDatabase<typeof postgres, typeof sqlite>) {
|
|
18
|
+
super(
|
|
19
|
+
database,
|
|
20
|
+
{ postgres: postgres.openid4vcVerifier, sqlite: sqlite.openid4vcVerifier },
|
|
21
|
+
'OpenId4VcVerifierRecord'
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public getValues(record: OpenId4VcVerifierRecord) {
|
|
26
|
+
const { verifierId, ...customTags } = record.getTags()
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
verifierId,
|
|
30
|
+
clientMetadata: record.clientMetadata,
|
|
31
|
+
customTags,
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public toRecord(values: DrizzleOpenid4vcVerifierAdapterValues): OpenId4VcVerifierRecord {
|
|
36
|
+
const { customTags, ...remainingValues } = values
|
|
37
|
+
|
|
38
|
+
const record = JsonTransformer.fromJSON(remainingValues, OpenId4VcVerifierRecord)
|
|
39
|
+
if (customTags) record.setTags(customTags as TagsBase)
|
|
40
|
+
|
|
41
|
+
return record
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DrizzleRecord } from '../../DrizzleRecord'
|
|
2
|
+
import { DrizzleOpenid4vcVerifierRecordAdapter } from './DrizzleOpenid4vcVerifierRecordAdapter'
|
|
3
|
+
import * as postgres from './postgres'
|
|
4
|
+
import * as sqlite from './sqlite'
|
|
5
|
+
|
|
6
|
+
export const openid4vcVerifierDrizzleRecord = {
|
|
7
|
+
adapter: DrizzleOpenid4vcVerifierRecordAdapter,
|
|
8
|
+
postgres,
|
|
9
|
+
sqlite,
|
|
10
|
+
} satisfies DrizzleRecord
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsonb, pgTable, text } from 'drizzle-orm/pg-core'
|
|
2
|
+
import { getPostgresBaseRecordTable, postgresBaseRecordIndexes } from '../../postgres/baseRecord'
|
|
3
|
+
|
|
4
|
+
import { OpenId4VpVerifierClientMetadata } from '@credo-ts/openid4vc'
|
|
5
|
+
|
|
6
|
+
export const openid4vcVerifier = pgTable(
|
|
7
|
+
'Openid4vcVerifier',
|
|
8
|
+
{
|
|
9
|
+
...getPostgresBaseRecordTable(),
|
|
10
|
+
verifierId: text('verifier_id').unique().notNull(),
|
|
11
|
+
clientMetadata: jsonb('client_metadata').$type<OpenId4VpVerifierClientMetadata>(),
|
|
12
|
+
},
|
|
13
|
+
(table) => postgresBaseRecordIndexes(table, 'openid4vcVerifier')
|
|
14
|
+
)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { OpenId4VpVerifierClientMetadata } from '@credo-ts/openid4vc'
|
|
2
|
+
import { sqliteTable, text } from 'drizzle-orm/sqlite-core'
|
|
3
|
+
import { getSqliteBaseRecordTable, sqliteBaseRecordIndexes } from '../../sqlite/baseRecord'
|
|
4
|
+
|
|
5
|
+
export const openid4vcVerifier = sqliteTable(
|
|
6
|
+
'Openid4vcVerifier',
|
|
7
|
+
{
|
|
8
|
+
...getSqliteBaseRecordTable(),
|
|
9
|
+
|
|
10
|
+
// NOTE: generally we don't have unique constraints on single fields,
|
|
11
|
+
// (always in combination with the context correlation id), but for verifier
|
|
12
|
+
// id, it will actually cause issues, since we use the verifierId in the public
|
|
13
|
+
// url and map that to the context correlation id.
|
|
14
|
+
verifierId: text('verifier_id').unique().notNull(),
|
|
15
|
+
|
|
16
|
+
clientMetadata: text('client_metadata', { mode: 'json' }).$type<OpenId4VpVerifierClientMetadata>(),
|
|
17
|
+
},
|
|
18
|
+
(table) => sqliteBaseRecordIndexes(table, 'openid4vcVerifier')
|
|
19
|
+
)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ExtraConfigColumn, foreignKey, jsonb, primaryKey, text, timestamp } from 'drizzle-orm/pg-core'
|
|
2
|
+
import { context } from '../core/context/postgres'
|
|
3
|
+
|
|
4
|
+
export const getPostgresBaseRecordTable = () =>
|
|
5
|
+
({
|
|
6
|
+
contextCorrelationId: text('context_correlation_id').notNull(),
|
|
7
|
+
id: text().notNull(),
|
|
8
|
+
|
|
9
|
+
// createdAt is set in credo, to avoid having to query the
|
|
10
|
+
// value from the database after creation
|
|
11
|
+
createdAt: timestamp('created_at', {
|
|
12
|
+
withTimezone: true,
|
|
13
|
+
precision: 3,
|
|
14
|
+
}).notNull(),
|
|
15
|
+
|
|
16
|
+
// updatedAt is updated in credo, to avoid having to query the updated
|
|
17
|
+
// value from the database after an update
|
|
18
|
+
updatedAt: timestamp('updated_at', {
|
|
19
|
+
withTimezone: true,
|
|
20
|
+
precision: 3,
|
|
21
|
+
}).notNull(),
|
|
22
|
+
|
|
23
|
+
metadata: jsonb().$type<Record<string, Record<string, unknown> | undefined>>(),
|
|
24
|
+
customTags: jsonb('custom_tags').$type<Record<string, string | number | boolean | null | string[]>>(),
|
|
25
|
+
}) as const
|
|
26
|
+
|
|
27
|
+
// Define common base indexes that all tables should have
|
|
28
|
+
export const postgresBaseRecordIndexes = <
|
|
29
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
30
|
+
Table extends { contextCorrelationId: ExtraConfigColumn<any>; id: ExtraConfigColumn<any> },
|
|
31
|
+
>(
|
|
32
|
+
table: Table,
|
|
33
|
+
tableName: string
|
|
34
|
+
) => {
|
|
35
|
+
return [
|
|
36
|
+
// Composite primary key on each table with id + context correlation id
|
|
37
|
+
primaryKey({ columns: [table.contextCorrelationId, table.id], name: `${tableName}_pk` }),
|
|
38
|
+
foreignKey({
|
|
39
|
+
columns: [table.contextCorrelationId],
|
|
40
|
+
foreignColumns: [context.contextCorrelationId],
|
|
41
|
+
name: `${tableName}_fk_context`,
|
|
42
|
+
}).onDelete('cascade'),
|
|
43
|
+
]
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getPostgresBaseRecordTable, postgresBaseRecordIndexes } from './baseRecord'
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DrizzleRecordBundle } from '../DrizzleRecord'
|
|
2
|
+
import { didcommQuestionAnswerDrizzleRecord } from './question-answer'
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
name: 'question-answer',
|
|
6
|
+
records: [didcommQuestionAnswerDrizzleRecord],
|
|
7
|
+
|
|
8
|
+
migrations: {
|
|
9
|
+
postgres: {
|
|
10
|
+
schemaModule: '@credo-ts/drizzle-storage/question-answer/postgres',
|
|
11
|
+
migrationsPath: '../../migrations/question-answer/postgres',
|
|
12
|
+
},
|
|
13
|
+
sqlite: {
|
|
14
|
+
schemaModule: '@credo-ts/drizzle-storage/question-answer/sqlite',
|
|
15
|
+
migrationsPath: '../../migrations/question-answer/sqlite',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
} as const satisfies DrizzleRecordBundle
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './question-answer/postgres'
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { JsonTransformer, TagsBase } from '@credo-ts/core'
|
|
2
|
+
|
|
3
|
+
import { QuestionAnswerRecord } from '@credo-ts/question-answer'
|
|
4
|
+
import { DrizzleDatabase } from '../../DrizzleDatabase'
|
|
5
|
+
import { BaseDrizzleRecordAdapter, DrizzleAdapterRecordValues } from '../../adapter/BaseDrizzleRecordAdapter'
|
|
6
|
+
import * as postgres from './postgres'
|
|
7
|
+
import * as sqlite from './sqlite'
|
|
8
|
+
|
|
9
|
+
type DrizzleDidcommQuestionAnswerAdapterValues = DrizzleAdapterRecordValues<(typeof sqlite)['didcommQuestionAnswer']>
|
|
10
|
+
export class DrizzleDidcommQuestionAnswerRecordAdapter extends BaseDrizzleRecordAdapter<
|
|
11
|
+
QuestionAnswerRecord,
|
|
12
|
+
typeof postgres.didcommQuestionAnswer,
|
|
13
|
+
typeof postgres,
|
|
14
|
+
typeof sqlite.didcommQuestionAnswer,
|
|
15
|
+
typeof sqlite
|
|
16
|
+
> {
|
|
17
|
+
public constructor(database: DrizzleDatabase<typeof postgres, typeof sqlite>) {
|
|
18
|
+
super(
|
|
19
|
+
database,
|
|
20
|
+
{ postgres: postgres.didcommQuestionAnswer, sqlite: sqlite.didcommQuestionAnswer },
|
|
21
|
+
'QuestionAnswerRecord'
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public getValues(record: QuestionAnswerRecord) {
|
|
26
|
+
const { connectionId, role, state, threadId, ...customTags } = record.getTags()
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
state,
|
|
30
|
+
role,
|
|
31
|
+
connectionId,
|
|
32
|
+
threadId,
|
|
33
|
+
|
|
34
|
+
questionText: record.questionText,
|
|
35
|
+
questionDetail: record.questionDetail,
|
|
36
|
+
validResponses: record.validResponses,
|
|
37
|
+
signatureRequired: record.signatureRequired,
|
|
38
|
+
response: record.response,
|
|
39
|
+
|
|
40
|
+
customTags,
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public toRecord(values: DrizzleDidcommQuestionAnswerAdapterValues): QuestionAnswerRecord {
|
|
45
|
+
const { customTags, ...remainingValues } = values
|
|
46
|
+
|
|
47
|
+
const record = JsonTransformer.fromJSON(remainingValues, QuestionAnswerRecord)
|
|
48
|
+
if (customTags) record.setTags(customTags as TagsBase)
|
|
49
|
+
|
|
50
|
+
return record
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DrizzleRecord } from '../../DrizzleRecord'
|
|
2
|
+
import { DrizzleDidcommQuestionAnswerRecordAdapter } from './DrizzleDidcommQuestionAnswerRecordAdapter'
|
|
3
|
+
import * as postgres from './postgres'
|
|
4
|
+
import * as sqlite from './sqlite'
|
|
5
|
+
|
|
6
|
+
export const didcommQuestionAnswerDrizzleRecord = {
|
|
7
|
+
adapter: DrizzleDidcommQuestionAnswerRecordAdapter,
|
|
8
|
+
postgres,
|
|
9
|
+
sqlite,
|
|
10
|
+
} satisfies DrizzleRecord
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { QuestionAnswerRole, QuestionAnswerState, ValidResponse } from '@credo-ts/question-answer'
|
|
2
|
+
import { boolean, foreignKey, jsonb, pgEnum, pgTable, text, unique } from 'drizzle-orm/pg-core'
|
|
3
|
+
import { didcommConnection } from '../../didcomm/connection/postgres'
|
|
4
|
+
import { getPostgresBaseRecordTable, postgresBaseRecordIndexes } from '../../postgres/baseRecord'
|
|
5
|
+
|
|
6
|
+
export const didcommQuestionAnswerStateEnum = pgEnum('DidcommQuestionAnswerState', QuestionAnswerState)
|
|
7
|
+
export const didcommQuestionAnswerRoleEnum = pgEnum('DidcommQuestionAnswerRole', QuestionAnswerRole)
|
|
8
|
+
|
|
9
|
+
export const didcommQuestionAnswer = pgTable(
|
|
10
|
+
'DidcommQuestionAnswer',
|
|
11
|
+
{
|
|
12
|
+
...getPostgresBaseRecordTable(),
|
|
13
|
+
|
|
14
|
+
state: didcommQuestionAnswerStateEnum().notNull(),
|
|
15
|
+
role: didcommQuestionAnswerRoleEnum().notNull(),
|
|
16
|
+
|
|
17
|
+
connectionId: text('connection_id').notNull(),
|
|
18
|
+
threadId: text('thread_id').notNull(),
|
|
19
|
+
|
|
20
|
+
questionText: text('question_text').notNull(),
|
|
21
|
+
questionDetail: text('question_detail'),
|
|
22
|
+
validResponses: jsonb('valid_responses').notNull().$type<ValidResponse[]>(),
|
|
23
|
+
signatureRequired: boolean('signature_required').notNull(),
|
|
24
|
+
response: text(),
|
|
25
|
+
},
|
|
26
|
+
(table) => [
|
|
27
|
+
...postgresBaseRecordIndexes(table, 'didcommQuestionAnswer'),
|
|
28
|
+
unique().on(table.contextCorrelationId, table.threadId),
|
|
29
|
+
foreignKey({
|
|
30
|
+
columns: [table.connectionId, table.contextCorrelationId],
|
|
31
|
+
foreignColumns: [didcommConnection.id, didcommConnection.contextCorrelationId],
|
|
32
|
+
}).onDelete('cascade'),
|
|
33
|
+
]
|
|
34
|
+
)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { foreignKey, integer, sqliteTable, text, unique } from 'drizzle-orm/sqlite-core'
|
|
2
|
+
|
|
3
|
+
import { QuestionAnswerRole, QuestionAnswerState, ValidResponse } from '@credo-ts/question-answer'
|
|
4
|
+
import { didcommConnection } from '../../didcomm/connection/sqlite'
|
|
5
|
+
import { getSqliteBaseRecordTable, sqliteBaseRecordIndexes } from '../../sqlite/baseRecord'
|
|
6
|
+
|
|
7
|
+
export const didcommQuestionAnswer = sqliteTable(
|
|
8
|
+
'DidcommQuestionAnswer',
|
|
9
|
+
{
|
|
10
|
+
...getSqliteBaseRecordTable(),
|
|
11
|
+
|
|
12
|
+
state: text('state').$type<QuestionAnswerState>().notNull(),
|
|
13
|
+
role: text('role').$type<QuestionAnswerRole>().notNull(),
|
|
14
|
+
|
|
15
|
+
connectionId: text('connection_id').notNull(),
|
|
16
|
+
threadId: text('thread_id').notNull(),
|
|
17
|
+
|
|
18
|
+
questionText: text('question_text').notNull(),
|
|
19
|
+
questionDetail: text('question_detail'),
|
|
20
|
+
validResponses: text('valid_responses', { mode: 'json' }).notNull().$type<ValidResponse[]>(),
|
|
21
|
+
signatureRequired: integer('signature_required', { mode: 'boolean' }).notNull(),
|
|
22
|
+
response: text(),
|
|
23
|
+
},
|
|
24
|
+
(table) => [
|
|
25
|
+
...sqliteBaseRecordIndexes(table, 'didcommQuestionAnswer'),
|
|
26
|
+
unique().on(table.contextCorrelationId, table.threadId),
|
|
27
|
+
foreignKey({
|
|
28
|
+
columns: [table.connectionId, table.contextCorrelationId],
|
|
29
|
+
foreignColumns: [didcommConnection.id, didcommConnection.contextCorrelationId],
|
|
30
|
+
}).onDelete('cascade'),
|
|
31
|
+
]
|
|
32
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './question-answer/sqlite'
|