@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,10 @@
|
|
|
1
|
+
import { DrizzleRecord } from '../../DrizzleRecord'
|
|
2
|
+
import { DrizzleAnonCredsKeyCorrectnessProofRecordAdapter } from './DrizzleAnonCredsKeyCorrectnessProofRecordAdapter'
|
|
3
|
+
import * as postgres from './postgres'
|
|
4
|
+
import * as sqlite from './sqlite'
|
|
5
|
+
|
|
6
|
+
export const anonCredsKeyCorrectnessProofDrizzleRecord = {
|
|
7
|
+
adapter: DrizzleAnonCredsKeyCorrectnessProofRecordAdapter,
|
|
8
|
+
postgres,
|
|
9
|
+
sqlite,
|
|
10
|
+
} satisfies DrizzleRecord
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsonb, pgTable, text } from 'drizzle-orm/pg-core'
|
|
2
|
+
import { getPostgresBaseRecordTable, postgresBaseRecordIndexes } from '../../postgres/baseRecord'
|
|
3
|
+
|
|
4
|
+
export const anonCredsKeyCorrectnessProof = pgTable(
|
|
5
|
+
'AnonCredsKeyCorrectnessProof',
|
|
6
|
+
{
|
|
7
|
+
...getPostgresBaseRecordTable(),
|
|
8
|
+
|
|
9
|
+
credentialDefinitionId: text('credential_definition_id').notNull().unique(),
|
|
10
|
+
value: jsonb('value').$type<Record<string, unknown>>().notNull(),
|
|
11
|
+
},
|
|
12
|
+
(table) => postgresBaseRecordIndexes(table, 'anonCredsKeyCorrectnessProof')
|
|
13
|
+
)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { sqliteTable, text } from 'drizzle-orm/sqlite-core'
|
|
2
|
+
import { getSqliteBaseRecordTable, sqliteBaseRecordIndexes } from '../../sqlite/baseRecord'
|
|
3
|
+
|
|
4
|
+
export const anonCredsKeyCorrectnessProof = sqliteTable(
|
|
5
|
+
'AnonCredsKeyCorrectnessProof',
|
|
6
|
+
{
|
|
7
|
+
...getSqliteBaseRecordTable(),
|
|
8
|
+
|
|
9
|
+
credentialDefinitionId: text('credential_definition_id').notNull().unique(),
|
|
10
|
+
|
|
11
|
+
value: text('value', { mode: 'json' }).$type<Record<string, unknown>>().notNull(),
|
|
12
|
+
},
|
|
13
|
+
(table) => sqliteBaseRecordIndexes(table, 'anonCredsKeyCorrectnessProof')
|
|
14
|
+
)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { JsonTransformer, TagsBase } from '@credo-ts/core'
|
|
2
|
+
|
|
3
|
+
import { BaseDrizzleRecordAdapter, DrizzleAdapterRecordValues } from '../../adapter/BaseDrizzleRecordAdapter'
|
|
4
|
+
|
|
5
|
+
import { AnonCredsLinkSecretRecord } from '@credo-ts/anoncreds'
|
|
6
|
+
import { DrizzleDatabase } from '../../DrizzleDatabase'
|
|
7
|
+
import * as postgres from './postgres'
|
|
8
|
+
import * as sqlite from './sqlite'
|
|
9
|
+
|
|
10
|
+
type DrizzleAnonCredsLinkSecretAdapterValues = DrizzleAdapterRecordValues<(typeof sqlite)['anonCredsLinkSecret']>
|
|
11
|
+
export class DrizzleAnonCredsLinkSecretRecordAdapter extends BaseDrizzleRecordAdapter<
|
|
12
|
+
AnonCredsLinkSecretRecord,
|
|
13
|
+
typeof postgres.anonCredsLinkSecret,
|
|
14
|
+
typeof postgres,
|
|
15
|
+
typeof sqlite.anonCredsLinkSecret,
|
|
16
|
+
typeof sqlite
|
|
17
|
+
> {
|
|
18
|
+
public constructor(database: DrizzleDatabase<typeof postgres, typeof sqlite>) {
|
|
19
|
+
super(
|
|
20
|
+
database,
|
|
21
|
+
{ postgres: postgres.anonCredsLinkSecret, sqlite: sqlite.anonCredsLinkSecret },
|
|
22
|
+
'AnonCredsLinkSecretRecord'
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public getValues(record: AnonCredsLinkSecretRecord) {
|
|
27
|
+
const { linkSecretId, isDefault, ...customTags } = record.getTags()
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
linkSecretId,
|
|
31
|
+
isDefault,
|
|
32
|
+
value: record.value,
|
|
33
|
+
customTags,
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public toRecord(values: DrizzleAnonCredsLinkSecretAdapterValues): AnonCredsLinkSecretRecord {
|
|
38
|
+
const { customTags, isDefault, ...remainingValues } = values
|
|
39
|
+
|
|
40
|
+
const record = JsonTransformer.fromJSON(remainingValues, AnonCredsLinkSecretRecord)
|
|
41
|
+
record.setTags({ ...customTags, isDefault: isDefault ?? undefined } as TagsBase)
|
|
42
|
+
|
|
43
|
+
return record
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DrizzleRecord } from '../../DrizzleRecord'
|
|
2
|
+
import { DrizzleAnonCredsLinkSecretRecordAdapter } from './DrizzleAnonCredsLinkSecretRecordAdapter'
|
|
3
|
+
import * as postgres from './postgres'
|
|
4
|
+
import * as sqlite from './sqlite'
|
|
5
|
+
|
|
6
|
+
export const anonCredsLinkSecretDrizzleRecord = {
|
|
7
|
+
adapter: DrizzleAnonCredsLinkSecretRecordAdapter,
|
|
8
|
+
postgres,
|
|
9
|
+
sqlite,
|
|
10
|
+
} satisfies DrizzleRecord
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { boolean, pgTable, text, uniqueIndex } from 'drizzle-orm/pg-core'
|
|
2
|
+
import { getPostgresBaseRecordTable, postgresBaseRecordIndexes } from '../../postgres/baseRecord'
|
|
3
|
+
|
|
4
|
+
export const anonCredsLinkSecret = pgTable(
|
|
5
|
+
'AnonCredsLinkSecret',
|
|
6
|
+
{
|
|
7
|
+
...getPostgresBaseRecordTable(),
|
|
8
|
+
|
|
9
|
+
linkSecretId: text('link_secret_id').notNull(),
|
|
10
|
+
isDefault: boolean('is_default').notNull().default(false),
|
|
11
|
+
|
|
12
|
+
value: text('value'),
|
|
13
|
+
},
|
|
14
|
+
(table) => [
|
|
15
|
+
...postgresBaseRecordIndexes(table, 'anonCredsLinkSecret'),
|
|
16
|
+
uniqueIndex('link_secret_id_context_correlation_id_unique').on(table.linkSecretId, table.contextCorrelationId),
|
|
17
|
+
]
|
|
18
|
+
)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { integer, sqliteTable, text, uniqueIndex } from 'drizzle-orm/sqlite-core'
|
|
2
|
+
import { getSqliteBaseRecordTable, sqliteBaseRecordIndexes } from '../../sqlite/baseRecord'
|
|
3
|
+
|
|
4
|
+
export const anonCredsLinkSecret = sqliteTable(
|
|
5
|
+
'AnonCredsLinkSecret',
|
|
6
|
+
{
|
|
7
|
+
...getSqliteBaseRecordTable(),
|
|
8
|
+
|
|
9
|
+
linkSecretId: text('link_secret_id').notNull(),
|
|
10
|
+
isDefault: integer('is_default', { mode: 'boolean' }).notNull().default(false),
|
|
11
|
+
|
|
12
|
+
value: text('value'),
|
|
13
|
+
},
|
|
14
|
+
(table) => [
|
|
15
|
+
...sqliteBaseRecordIndexes(table, 'anonCredsLinkSecret'),
|
|
16
|
+
uniqueIndex('link_secret_id_context_correlation_id_unique').on(table.linkSecretId, table.contextCorrelationId),
|
|
17
|
+
]
|
|
18
|
+
)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './credential/postgres'
|
|
2
|
+
export * from './credential-definition/postgres'
|
|
3
|
+
export * from './credential-definition-private/postgres'
|
|
4
|
+
export * from './key-correctness-proof/postgres'
|
|
5
|
+
export * from './link-secret/postgres'
|
|
6
|
+
export * from './revocation-registry-definition/postgres'
|
|
7
|
+
export * from './revocation-registry-definition-private/postgres'
|
|
8
|
+
export * from './schema/postgres'
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { JsonTransformer, TagsBase } from '@credo-ts/core'
|
|
2
|
+
|
|
3
|
+
import { BaseDrizzleRecordAdapter, DrizzleAdapterRecordValues } from '../../adapter/BaseDrizzleRecordAdapter'
|
|
4
|
+
|
|
5
|
+
import { AnonCredsRevocationRegistryDefinitionRecord } from '@credo-ts/anoncreds'
|
|
6
|
+
import { DrizzleDatabase } from '../../DrizzleDatabase'
|
|
7
|
+
import * as postgres from './postgres'
|
|
8
|
+
import * as sqlite from './sqlite'
|
|
9
|
+
|
|
10
|
+
type DrizzleAnonCredsRevocationRegistryDefinitionAdapterValues = DrizzleAdapterRecordValues<
|
|
11
|
+
(typeof sqlite)['anonCredsRevocationRegistryDefinition']
|
|
12
|
+
>
|
|
13
|
+
export class DrizzleAnonCredsRevocationRegistryDefinitionRecordAdapter extends BaseDrizzleRecordAdapter<
|
|
14
|
+
AnonCredsRevocationRegistryDefinitionRecord,
|
|
15
|
+
typeof postgres.anonCredsRevocationRegistryDefinition,
|
|
16
|
+
typeof postgres,
|
|
17
|
+
typeof sqlite.anonCredsRevocationRegistryDefinition,
|
|
18
|
+
typeof sqlite
|
|
19
|
+
> {
|
|
20
|
+
public constructor(database: DrizzleDatabase<typeof postgres, typeof sqlite>) {
|
|
21
|
+
super(
|
|
22
|
+
database,
|
|
23
|
+
{
|
|
24
|
+
postgres: postgres.anonCredsRevocationRegistryDefinition,
|
|
25
|
+
sqlite: sqlite.anonCredsRevocationRegistryDefinition,
|
|
26
|
+
},
|
|
27
|
+
'AnonCredsRevocationRegistryDefinitionRecord'
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public getValues(record: AnonCredsRevocationRegistryDefinitionRecord) {
|
|
32
|
+
const { revocationRegistryDefinitionId, credentialDefinitionId, ...customTags } = record.getTags()
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
revocationRegistryDefinitionId,
|
|
36
|
+
credentialDefinitionId,
|
|
37
|
+
revocationRegistryDefinition: record.revocationRegistryDefinition,
|
|
38
|
+
customTags,
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public toRecord(
|
|
43
|
+
values: DrizzleAnonCredsRevocationRegistryDefinitionAdapterValues
|
|
44
|
+
): AnonCredsRevocationRegistryDefinitionRecord {
|
|
45
|
+
const { customTags, credentialDefinitionId, ...remainingValues } = values
|
|
46
|
+
|
|
47
|
+
const record = JsonTransformer.fromJSON(remainingValues, AnonCredsRevocationRegistryDefinitionRecord)
|
|
48
|
+
record.setTags({ ...customTags, credentialDefinitionId } as TagsBase)
|
|
49
|
+
|
|
50
|
+
return record
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DrizzleRecord } from '../../DrizzleRecord'
|
|
2
|
+
import { DrizzleAnonCredsRevocationRegistryDefinitionRecordAdapter } from './DrizzleAnonCredsRevocationRegistryDefinitionRecordAdapter'
|
|
3
|
+
import * as postgres from './postgres'
|
|
4
|
+
import * as sqlite from './sqlite'
|
|
5
|
+
|
|
6
|
+
export const anonCredsRevocationRegistryDefinitionDrizzleRecord: DrizzleRecord = {
|
|
7
|
+
adapter: DrizzleAnonCredsRevocationRegistryDefinitionRecordAdapter,
|
|
8
|
+
postgres,
|
|
9
|
+
sqlite,
|
|
10
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AnonCredsRevocationRegistryDefinition } from '@credo-ts/anoncreds'
|
|
2
|
+
import { jsonb, pgTable, text } from 'drizzle-orm/pg-core'
|
|
3
|
+
import { getPostgresBaseRecordTable, postgresBaseRecordIndexes } from '../../postgres/baseRecord'
|
|
4
|
+
|
|
5
|
+
export const anonCredsRevocationRegistryDefinition = pgTable(
|
|
6
|
+
'AnonCredsRevocationRegistryDefinition',
|
|
7
|
+
{
|
|
8
|
+
...getPostgresBaseRecordTable(),
|
|
9
|
+
|
|
10
|
+
revocationRegistryDefinitionId: text('revocation_registry_definition_id').notNull().unique(),
|
|
11
|
+
credentialDefinitionId: text('credential_definition_id').notNull(),
|
|
12
|
+
|
|
13
|
+
revocationRegistryDefinition: jsonb('revocation_registry_definition')
|
|
14
|
+
.$type<AnonCredsRevocationRegistryDefinition>()
|
|
15
|
+
.notNull(),
|
|
16
|
+
},
|
|
17
|
+
(table) => postgresBaseRecordIndexes(table, 'anonCredsRevocationRegistryDefinition')
|
|
18
|
+
)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AnonCredsRevocationRegistryDefinition } from '@credo-ts/anoncreds'
|
|
2
|
+
import { sqliteTable, text } from 'drizzle-orm/sqlite-core'
|
|
3
|
+
import { getSqliteBaseRecordTable, sqliteBaseRecordIndexes } from '../../sqlite/baseRecord'
|
|
4
|
+
|
|
5
|
+
export const anonCredsRevocationRegistryDefinition = sqliteTable(
|
|
6
|
+
'AnonCredsRevocationRegistryDefinition',
|
|
7
|
+
{
|
|
8
|
+
...getSqliteBaseRecordTable(),
|
|
9
|
+
|
|
10
|
+
revocationRegistryDefinitionId: text('revocation_registry_definition_id').notNull().unique(),
|
|
11
|
+
revocationRegistryDefinition: text('revocation_registry_definition', { mode: 'json' })
|
|
12
|
+
.$type<AnonCredsRevocationRegistryDefinition>()
|
|
13
|
+
.notNull(),
|
|
14
|
+
|
|
15
|
+
// This is duplicated from the revocation registry definition. Might want to
|
|
16
|
+
// dedupe by omitting that key from the json
|
|
17
|
+
credentialDefinitionId: text('credential_definition_id').notNull(),
|
|
18
|
+
},
|
|
19
|
+
(table) => sqliteBaseRecordIndexes(table, 'anonCredsRevocationRegistryDefinition')
|
|
20
|
+
)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { JsonTransformer, TagsBase } from '@credo-ts/core'
|
|
2
|
+
|
|
3
|
+
import { BaseDrizzleRecordAdapter, DrizzleAdapterRecordValues } from '../../adapter/BaseDrizzleRecordAdapter'
|
|
4
|
+
|
|
5
|
+
import { AnonCredsRevocationRegistryDefinitionPrivateRecord } from '@credo-ts/anoncreds'
|
|
6
|
+
import { DrizzleDatabase } from '../../DrizzleDatabase'
|
|
7
|
+
import * as postgres from './postgres'
|
|
8
|
+
import * as sqlite from './sqlite'
|
|
9
|
+
|
|
10
|
+
type DrizzleAnonCredsRevocationRegistryDefinitionPrivateAdapterValues = DrizzleAdapterRecordValues<
|
|
11
|
+
(typeof sqlite)['anonCredsRevocationRegistryDefinitionPrivate']
|
|
12
|
+
>
|
|
13
|
+
export class DrizzleAnonCredsRevocationRegistryDefinitionPrivateRecordAdapter extends BaseDrizzleRecordAdapter<
|
|
14
|
+
AnonCredsRevocationRegistryDefinitionPrivateRecord,
|
|
15
|
+
typeof postgres.anonCredsRevocationRegistryDefinitionPrivate,
|
|
16
|
+
typeof postgres,
|
|
17
|
+
typeof sqlite.anonCredsRevocationRegistryDefinitionPrivate,
|
|
18
|
+
typeof sqlite
|
|
19
|
+
> {
|
|
20
|
+
public constructor(database: DrizzleDatabase<typeof postgres, typeof sqlite>) {
|
|
21
|
+
super(
|
|
22
|
+
database,
|
|
23
|
+
{
|
|
24
|
+
postgres: postgres.anonCredsRevocationRegistryDefinitionPrivate,
|
|
25
|
+
sqlite: sqlite.anonCredsRevocationRegistryDefinitionPrivate,
|
|
26
|
+
},
|
|
27
|
+
'AnonCredsRevocationRegistryDefinitionPrivateRecord'
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public getValues(record: AnonCredsRevocationRegistryDefinitionPrivateRecord) {
|
|
32
|
+
const { revocationRegistryDefinitionId, credentialDefinitionId, state, ...customTags } = record.getTags()
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
revocationRegistryDefinitionId,
|
|
36
|
+
credentialDefinitionId,
|
|
37
|
+
state,
|
|
38
|
+
value: record.value,
|
|
39
|
+
customTags,
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public toRecord(
|
|
44
|
+
values: DrizzleAnonCredsRevocationRegistryDefinitionPrivateAdapterValues
|
|
45
|
+
): AnonCredsRevocationRegistryDefinitionPrivateRecord {
|
|
46
|
+
const { customTags, ...remainingValues } = values
|
|
47
|
+
|
|
48
|
+
const record = JsonTransformer.fromJSON(remainingValues, AnonCredsRevocationRegistryDefinitionPrivateRecord)
|
|
49
|
+
if (customTags) record.setTags(customTags as TagsBase)
|
|
50
|
+
|
|
51
|
+
return record
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DrizzleRecord } from '../../DrizzleRecord'
|
|
2
|
+
import { DrizzleAnonCredsRevocationRegistryDefinitionPrivateRecordAdapter } from './DrizzleAnonCredsRevocationRegistryDefinitionPrivateRecordAdapter'
|
|
3
|
+
import * as postgres from './postgres'
|
|
4
|
+
import * as sqlite from './sqlite'
|
|
5
|
+
|
|
6
|
+
export const anonCredsRevocationRegistryDefinitionPrivateDrizzleRecord: DrizzleRecord = {
|
|
7
|
+
adapter: DrizzleAnonCredsRevocationRegistryDefinitionPrivateRecordAdapter,
|
|
8
|
+
postgres,
|
|
9
|
+
sqlite,
|
|
10
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AnonCredsRevocationRegistryState } from '@credo-ts/anoncreds'
|
|
2
|
+
import { jsonb, pgEnum, pgTable, text } from 'drizzle-orm/pg-core'
|
|
3
|
+
import { getPostgresBaseRecordTable, postgresBaseRecordIndexes } from '../../postgres/baseRecord'
|
|
4
|
+
|
|
5
|
+
export const anonCredsRevocationRegistryStateEnum = pgEnum(
|
|
6
|
+
'AnonCredsRevocationRegistryState',
|
|
7
|
+
AnonCredsRevocationRegistryState
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
export const anonCredsRevocationRegistryDefinitionPrivate = pgTable(
|
|
11
|
+
'AnonCredsRevocationRegistryDefinitionPrivate',
|
|
12
|
+
{
|
|
13
|
+
...getPostgresBaseRecordTable(),
|
|
14
|
+
state: anonCredsRevocationRegistryStateEnum('state').notNull(),
|
|
15
|
+
|
|
16
|
+
revocationRegistryDefinitionId: text('revocation_registry_definition_id').notNull().unique(),
|
|
17
|
+
credentialDefinitionId: text('credential_definition_id').notNull(),
|
|
18
|
+
|
|
19
|
+
value: jsonb('value').$type<Record<string, unknown>>().notNull(),
|
|
20
|
+
},
|
|
21
|
+
(table) => postgresBaseRecordIndexes(table, 'anonCredsRevocationRegistryDefinitionPrivate')
|
|
22
|
+
)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AnonCredsRevocationRegistryState } from '@credo-ts/anoncreds'
|
|
2
|
+
import { sqliteTable, text } from 'drizzle-orm/sqlite-core'
|
|
3
|
+
import { getSqliteBaseRecordTable, sqliteBaseRecordIndexes } from '../../sqlite/baseRecord'
|
|
4
|
+
|
|
5
|
+
export const anonCredsRevocationRegistryDefinitionPrivate = sqliteTable(
|
|
6
|
+
'AnonCredsRevocationRegistryDefinitionPrivate',
|
|
7
|
+
{
|
|
8
|
+
...getSqliteBaseRecordTable(),
|
|
9
|
+
|
|
10
|
+
state: text('state').$type<AnonCredsRevocationRegistryState>().notNull(),
|
|
11
|
+
|
|
12
|
+
revocationRegistryDefinitionId: text('revocation_registry_definition_id').notNull().unique(),
|
|
13
|
+
credentialDefinitionId: text('credential_definition_id').notNull(),
|
|
14
|
+
|
|
15
|
+
value: text('value', { mode: 'json' }).$type<Record<string, unknown>>().notNull(),
|
|
16
|
+
},
|
|
17
|
+
(table) => sqliteBaseRecordIndexes(table, 'anonCredsRevocationRegistryDefinitionPrivate')
|
|
18
|
+
)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { JsonTransformer } from '@credo-ts/core'
|
|
2
|
+
|
|
3
|
+
import { BaseDrizzleRecordAdapter, DrizzleAdapterRecordValues } from '../../adapter/BaseDrizzleRecordAdapter'
|
|
4
|
+
|
|
5
|
+
import { AnonCredsSchemaRecord } from '@credo-ts/anoncreds'
|
|
6
|
+
import { DrizzleDatabase } from '../../DrizzleDatabase'
|
|
7
|
+
import * as postgres from './postgres'
|
|
8
|
+
import * as sqlite from './sqlite'
|
|
9
|
+
|
|
10
|
+
type DrizzleAnonCredsSchemaAdapterValues = DrizzleAdapterRecordValues<(typeof sqlite)['anonCredsSchema']>
|
|
11
|
+
export class DrizzleAnonCredsSchemaRecordAdapter extends BaseDrizzleRecordAdapter<
|
|
12
|
+
AnonCredsSchemaRecord,
|
|
13
|
+
typeof postgres.anonCredsSchema,
|
|
14
|
+
typeof postgres,
|
|
15
|
+
typeof sqlite.anonCredsSchema,
|
|
16
|
+
typeof sqlite
|
|
17
|
+
> {
|
|
18
|
+
public constructor(database: DrizzleDatabase<typeof postgres, typeof sqlite>) {
|
|
19
|
+
super(database, { postgres: postgres.anonCredsSchema, sqlite: sqlite.anonCredsSchema }, 'AnonCredsSchemaRecord')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public getValues(record: AnonCredsSchemaRecord) {
|
|
23
|
+
const { schemaId, issuerId, schemaName, schemaVersion, methodName, unqualifiedSchemaId, ...customTags } =
|
|
24
|
+
record.getTags()
|
|
25
|
+
|
|
26
|
+
const { issuerId: _, name: __, version: ___, ...restSchema } = record.schema
|
|
27
|
+
return {
|
|
28
|
+
schemaId,
|
|
29
|
+
schema: restSchema,
|
|
30
|
+
issuerId,
|
|
31
|
+
schemaName,
|
|
32
|
+
schemaVersion,
|
|
33
|
+
methodName,
|
|
34
|
+
unqualifiedSchemaId,
|
|
35
|
+
customTags,
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public toRecord(values: DrizzleAnonCredsSchemaAdapterValues): AnonCredsSchemaRecord {
|
|
40
|
+
const { customTags, unqualifiedSchemaId, issuerId, schemaName, schemaVersion, ...remainingValues } = values
|
|
41
|
+
|
|
42
|
+
const record = JsonTransformer.fromJSON(
|
|
43
|
+
{ ...remainingValues, schema: { ...remainingValues.schema, issuerId, name: schemaName, version: schemaVersion } },
|
|
44
|
+
AnonCredsSchemaRecord
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
record.setTags({
|
|
48
|
+
...customTags,
|
|
49
|
+
unqualifiedSchemaId: unqualifiedSchemaId ?? undefined,
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
return record
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { AnonCredsSchemaRecord, AnonCredsSchemaRepository } from '@credo-ts/anoncreds'
|
|
2
|
+
import { JsonTransformer } from '@credo-ts/core'
|
|
3
|
+
|
|
4
|
+
import { DrizzleRecordTest, setupDrizzleRecordTest } from '../../../../tests/testDatabase'
|
|
5
|
+
import { anonCredsSchemaDrizzleRecord } from '../index'
|
|
6
|
+
|
|
7
|
+
describe.each(['postgres', 'sqlite'] as const)('AnonCredsSchemaRecord with %s', (type) => {
|
|
8
|
+
let recordTest: DrizzleRecordTest
|
|
9
|
+
|
|
10
|
+
beforeAll(async () => {
|
|
11
|
+
recordTest = await setupDrizzleRecordTest(type, anonCredsSchemaDrizzleRecord)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
afterAll(async () => {
|
|
15
|
+
await recordTest.teardown()
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('create, retrieve, update, query and delete schema record', async () => {
|
|
19
|
+
const schema = JsonTransformer.fromJSON(
|
|
20
|
+
{
|
|
21
|
+
id: '6e7fcaf3-ebb9-45ed-9261-7b893f732bc1',
|
|
22
|
+
schemaId: 'did:web:123/schemas/1',
|
|
23
|
+
schema: {
|
|
24
|
+
name: 'TestSchema',
|
|
25
|
+
version: '1.0.0',
|
|
26
|
+
issuerId: 'did:web:123',
|
|
27
|
+
attrNames: ['test'],
|
|
28
|
+
},
|
|
29
|
+
methodName: 'web',
|
|
30
|
+
createdAt: new Date(),
|
|
31
|
+
_tags: {},
|
|
32
|
+
},
|
|
33
|
+
AnonCredsSchemaRecord
|
|
34
|
+
)
|
|
35
|
+
const anoncredsSchemaRepository = recordTest.agent.context.resolve(AnonCredsSchemaRepository)
|
|
36
|
+
|
|
37
|
+
await anoncredsSchemaRepository.save(recordTest.agent.context, schema)
|
|
38
|
+
|
|
39
|
+
const schema2 = await anoncredsSchemaRepository.findById(recordTest.agent.context, schema.id)
|
|
40
|
+
expect(schema).toEqual(schema2)
|
|
41
|
+
|
|
42
|
+
schema.setTags({
|
|
43
|
+
myCustomTag: 'hello',
|
|
44
|
+
isMorning: false,
|
|
45
|
+
})
|
|
46
|
+
await anoncredsSchemaRepository.update(recordTest.agent.context, schema)
|
|
47
|
+
|
|
48
|
+
const [schema3] = await anoncredsSchemaRepository.findByQuery(recordTest.agent.context, {
|
|
49
|
+
// TODO: we should allow null values in the query
|
|
50
|
+
// unqualifiedSchemaId: null,
|
|
51
|
+
isMorning: false,
|
|
52
|
+
schemaName: 'TestSchema',
|
|
53
|
+
schemaVersion: '1.0.0',
|
|
54
|
+
issuerId: 'did:web:123',
|
|
55
|
+
methodName: 'web',
|
|
56
|
+
schemaId: 'did:web:123/schemas/1',
|
|
57
|
+
})
|
|
58
|
+
expect(schema3).toEqual(schema)
|
|
59
|
+
|
|
60
|
+
expect(
|
|
61
|
+
await anoncredsSchemaRepository.findByQuery(recordTest.agent.context, {
|
|
62
|
+
myCustomTag: 'not-hello',
|
|
63
|
+
})
|
|
64
|
+
).toHaveLength(0)
|
|
65
|
+
|
|
66
|
+
await anoncredsSchemaRepository.deleteById(recordTest.agent.context, schema.id)
|
|
67
|
+
|
|
68
|
+
expect(await anoncredsSchemaRepository.findByQuery(recordTest.agent.context, {})).toHaveLength(0)
|
|
69
|
+
})
|
|
70
|
+
})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DrizzleRecord } from '../../DrizzleRecord'
|
|
2
|
+
import { DrizzleAnonCredsSchemaRecordAdapter } from './DrizzleAnonCredsSchemaRecordAdapter'
|
|
3
|
+
import * as postgres from './postgres'
|
|
4
|
+
import * as sqlite from './sqlite'
|
|
5
|
+
|
|
6
|
+
export const anonCredsSchemaDrizzleRecord: DrizzleRecord = {
|
|
7
|
+
adapter: DrizzleAnonCredsSchemaRecordAdapter,
|
|
8
|
+
postgres,
|
|
9
|
+
sqlite,
|
|
10
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AnonCredsSchema } from '@credo-ts/anoncreds'
|
|
2
|
+
import { jsonb, pgTable, text } from 'drizzle-orm/pg-core'
|
|
3
|
+
import { getPostgresBaseRecordTable, postgresBaseRecordIndexes } from '../../postgres/baseRecord'
|
|
4
|
+
|
|
5
|
+
export const anonCredsSchema = pgTable(
|
|
6
|
+
'AnonCredsSchema',
|
|
7
|
+
{
|
|
8
|
+
...getPostgresBaseRecordTable(),
|
|
9
|
+
|
|
10
|
+
schemaId: text('schema_id').notNull().unique(),
|
|
11
|
+
schema: jsonb('schema').$type<Omit<AnonCredsSchema, 'issuerId' | 'name' | 'version'>>().notNull(),
|
|
12
|
+
|
|
13
|
+
// These are extracted from the schema JSON object, to allow for easy querying based on tags
|
|
14
|
+
issuerId: text('issuer_id').notNull(),
|
|
15
|
+
schemaName: text('schema_name').notNull(),
|
|
16
|
+
schemaVersion: text('schema_version').notNull(),
|
|
17
|
+
|
|
18
|
+
methodName: text('method_name').notNull(),
|
|
19
|
+
unqualifiedSchemaId: text('unqualified_schema_id'),
|
|
20
|
+
},
|
|
21
|
+
(table) => postgresBaseRecordIndexes(table, 'anonCredsSchema')
|
|
22
|
+
)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AnonCredsSchema } from '@credo-ts/anoncreds'
|
|
2
|
+
import { sqliteTable, text } from 'drizzle-orm/sqlite-core'
|
|
3
|
+
import { getSqliteBaseRecordTable, sqliteBaseRecordIndexes } from '../../sqlite/baseRecord'
|
|
4
|
+
|
|
5
|
+
export const anonCredsSchema = sqliteTable(
|
|
6
|
+
'AnonCredsSchema',
|
|
7
|
+
{
|
|
8
|
+
...getSqliteBaseRecordTable(),
|
|
9
|
+
|
|
10
|
+
schemaId: text('schema_id').notNull().unique(),
|
|
11
|
+
schema: text({ mode: 'json' }).$type<Omit<AnonCredsSchema, 'issuerId' | 'name' | 'version'>>().notNull(),
|
|
12
|
+
|
|
13
|
+
// These are extracted from the schema JSON object, to allow for easy querying based on tags
|
|
14
|
+
issuerId: text('issuer_id').notNull(),
|
|
15
|
+
schemaName: text('schema_name').notNull(),
|
|
16
|
+
schemaVersion: text('schema_version').notNull(),
|
|
17
|
+
|
|
18
|
+
methodName: text('method_name').notNull(),
|
|
19
|
+
unqualifiedSchemaId: text('unqualified_schema_id'),
|
|
20
|
+
},
|
|
21
|
+
(table) => sqliteBaseRecordIndexes(table, 'anonCredsSchema')
|
|
22
|
+
)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './credential/sqlite'
|
|
2
|
+
export * from './credential-definition/sqlite'
|
|
3
|
+
export * from './credential-definition-private/sqlite'
|
|
4
|
+
export * from './key-correctness-proof/sqlite'
|
|
5
|
+
export * from './link-secret/sqlite'
|
|
6
|
+
export * from './revocation-registry-definition/sqlite'
|
|
7
|
+
export * from './revocation-registry-definition-private/sqlite'
|
|
8
|
+
export * from './schema/sqlite'
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AnyDrizzleDatabase } from './DrizzleStorageModuleConfig'
|
|
2
|
+
|
|
3
|
+
export interface ReactNativeDrizzleMigration {
|
|
4
|
+
journal: {
|
|
5
|
+
entries: { idx: number; when: number; tag: string; breakpoints: boolean }[]
|
|
6
|
+
}
|
|
7
|
+
migrations: Record<string, string>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface ReactNativeDrizzleMigrationsOptions<Database extends AnyDrizzleDatabase = AnyDrizzleDatabase> {
|
|
11
|
+
db: Database
|
|
12
|
+
migrations: ReactNativeDrizzleMigration[]
|
|
13
|
+
migrate: (db: Database, migration: ReactNativeDrizzleMigration) => Promise<void>
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function applyReactNativeMigrations<Database extends AnyDrizzleDatabase = AnyDrizzleDatabase>({
|
|
17
|
+
migrate,
|
|
18
|
+
migrations,
|
|
19
|
+
db,
|
|
20
|
+
}: ReactNativeDrizzleMigrationsOptions<Database>) {
|
|
21
|
+
for (const migration of migrations) {
|
|
22
|
+
await migrate(db, migration)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { UnionToIntersection } from '@credo-ts/core'
|
|
2
|
+
import { DrizzleRecord } from './DrizzleRecord'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Extracts and combines schema types from an array of DrizzleRecord objects for a specific database type
|
|
6
|
+
*/
|
|
7
|
+
export type GetSchemaFromDrizzleRecords<
|
|
8
|
+
Schemas extends readonly DrizzleRecord[],
|
|
9
|
+
DatabaseType extends 'postgres' | 'sqlite',
|
|
10
|
+
> = UnionToIntersection<
|
|
11
|
+
{
|
|
12
|
+
[K in keyof Schemas]: Schemas[K][DatabaseType]
|
|
13
|
+
}[number]
|
|
14
|
+
>
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Combines multiple Drizzle schema objects into a single unified schema
|
|
18
|
+
* @param schemas - Array of schema objects to combine
|
|
19
|
+
* @returns A single merged schema object
|
|
20
|
+
*/
|
|
21
|
+
export function getSchemaFromDrizzleRecords<
|
|
22
|
+
DrizzleRecords extends Array<DrizzleRecord> | ReadonlyArray<DrizzleRecord>,
|
|
23
|
+
DatabaseType extends 'postgres' | 'sqlite',
|
|
24
|
+
>(
|
|
25
|
+
drizzleRecords: DrizzleRecords,
|
|
26
|
+
databaseType: DatabaseType
|
|
27
|
+
): GetSchemaFromDrizzleRecords<DrizzleRecords, DatabaseType> {
|
|
28
|
+
// Create a new empty object to hold our combined schema
|
|
29
|
+
const combinedSchema = {} as GetSchemaFromDrizzleRecords<DrizzleRecords, DatabaseType>
|
|
30
|
+
|
|
31
|
+
// Iterate through each schema and merge its properties into the combined schema
|
|
32
|
+
for (const drizzleRecord of drizzleRecords) {
|
|
33
|
+
const schema = drizzleRecord[databaseType]
|
|
34
|
+
|
|
35
|
+
for (const key in schema) {
|
|
36
|
+
if (Object.prototype.hasOwnProperty.call(schema, key)) {
|
|
37
|
+
// Merge each property from the current schema into our combined schema
|
|
38
|
+
Object.assign(combinedSchema as object, { [key]: schema[key] })
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return combinedSchema
|
|
44
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { DrizzleRecordBundle } from '../DrizzleRecord'
|
|
2
|
+
import { contextDrizzleRecord } from './context'
|
|
3
|
+
import { didDrizzleRecord } from './did'
|
|
4
|
+
import { genericRecordDrizzleRecord } from './genericRecord'
|
|
5
|
+
import { mdocDrizzleRecord } from './mdoc'
|
|
6
|
+
import { sdJwtVcDrizzleRecord } from './sdJwtVc'
|
|
7
|
+
import { singleContextLruCacheDrizzleRecord } from './singleContextLruCache'
|
|
8
|
+
import { storageVersionDrizzleRecord } from './storageVersion'
|
|
9
|
+
import { w3cCredentialDrizzleRecord } from './w3cCredential'
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
name: 'core',
|
|
13
|
+
records: [
|
|
14
|
+
contextDrizzleRecord,
|
|
15
|
+
sdJwtVcDrizzleRecord,
|
|
16
|
+
mdocDrizzleRecord,
|
|
17
|
+
storageVersionDrizzleRecord,
|
|
18
|
+
genericRecordDrizzleRecord,
|
|
19
|
+
didDrizzleRecord,
|
|
20
|
+
w3cCredentialDrizzleRecord,
|
|
21
|
+
singleContextLruCacheDrizzleRecord,
|
|
22
|
+
],
|
|
23
|
+
migrations: {
|
|
24
|
+
postgres: {
|
|
25
|
+
schemaModule: '@credo-ts/drizzle-storage/core/postgres',
|
|
26
|
+
migrationsPath: '../../migrations/core/postgres',
|
|
27
|
+
},
|
|
28
|
+
sqlite: {
|
|
29
|
+
schemaModule: '@credo-ts/drizzle-storage/core/sqlite',
|
|
30
|
+
migrationsPath: '../../migrations/core/sqlite',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
} as const satisfies DrizzleRecordBundle
|