@credo-ts/drizzle-storage 0.6.0-pr-2324-20250708122332 → 0.6.0-pr-2324-20250708123651
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-build/utils.js +4 -1
- package/cli-build/utils.js.map +1 -1
- package/package.json +15 -14
- 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.test.ts +328 -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.test.ts +66 -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.test.ts +97 -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.test.ts +84 -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,38 @@
|
|
|
1
|
+
import { SQLiteColumn, foreignKey, integer, primaryKey, text } from 'drizzle-orm/sqlite-core'
|
|
2
|
+
import { context } from '../core/context/sqlite'
|
|
3
|
+
|
|
4
|
+
export const getSqliteBaseRecordTable = () =>
|
|
5
|
+
({
|
|
6
|
+
contextCorrelationId: text('context_correlation_id').notNull(),
|
|
7
|
+
|
|
8
|
+
id: text().notNull(),
|
|
9
|
+
|
|
10
|
+
// createdAt is set in credo, to avoid having to query the
|
|
11
|
+
// value from the database after creation
|
|
12
|
+
createdAt: integer('created_at', { mode: 'timestamp_ms' }).notNull(),
|
|
13
|
+
|
|
14
|
+
// updatedAt is updated in credo, to avoid having to query the updated
|
|
15
|
+
// value from the database after an update
|
|
16
|
+
updatedAt: integer('updated_at', { mode: 'timestamp_ms' }).notNull(),
|
|
17
|
+
|
|
18
|
+
metadata: text({ mode: 'json' }).$type<Record<string, Record<string, unknown> | undefined>>(),
|
|
19
|
+
customTags: text('custom_tags', { mode: 'json' }).$type<
|
|
20
|
+
Record<string, string | number | undefined | boolean | null | string[]>
|
|
21
|
+
>(),
|
|
22
|
+
}) as const
|
|
23
|
+
|
|
24
|
+
// Define common base indexes that all tables should have
|
|
25
|
+
export const sqliteBaseRecordIndexes = <
|
|
26
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
27
|
+
Table extends { contextCorrelationId: SQLiteColumn<any>; id: SQLiteColumn<any> },
|
|
28
|
+
>(
|
|
29
|
+
table: Table,
|
|
30
|
+
tableName: string
|
|
31
|
+
) => [
|
|
32
|
+
primaryKey({ columns: [table.contextCorrelationId, table.id], name: `${tableName}_pk` }),
|
|
33
|
+
foreignKey({
|
|
34
|
+
columns: [table.contextCorrelationId],
|
|
35
|
+
foreignColumns: [context.contextCorrelationId],
|
|
36
|
+
name: `${tableName}_fk_context`,
|
|
37
|
+
}).onDelete('cascade'),
|
|
38
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getSqliteBaseRecordTable, sqliteBaseRecordIndexes } from './baseRecord'
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AgentContext,
|
|
3
|
+
BaseRecord,
|
|
4
|
+
BaseRecordConstructor,
|
|
5
|
+
Query,
|
|
6
|
+
QueryOptions,
|
|
7
|
+
StorageService,
|
|
8
|
+
} from '@credo-ts/core'
|
|
9
|
+
import { injectable } from '@credo-ts/core'
|
|
10
|
+
import { DrizzleStorageModuleConfig } from '../DrizzleStorageModuleConfig'
|
|
11
|
+
import { BaseDrizzleRecordAdapter } from '../adapter/BaseDrizzleRecordAdapter'
|
|
12
|
+
import { CredoDrizzleStorageError } from '../error/CredoDrizzleStorageError'
|
|
13
|
+
|
|
14
|
+
@injectable()
|
|
15
|
+
export class DrizzleStorageService<T extends BaseRecord> implements StorageService<T> {
|
|
16
|
+
public constructor(public config: DrizzleStorageModuleConfig) {}
|
|
17
|
+
|
|
18
|
+
private getAdapterForRecordType(recordType: string) {
|
|
19
|
+
const adapter = this.config.adapters.find((adapter) => adapter.recordType === recordType)
|
|
20
|
+
if (!adapter) {
|
|
21
|
+
throw new CredoDrizzleStorageError(
|
|
22
|
+
`Could not find a registered drizzle adapter for record type '${recordType}'. Make sure to register the record type in the DrizzleStorageModule.`
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
27
|
+
return adapter as BaseDrizzleRecordAdapter<T, any, any, any, any>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public async save(agentContext: AgentContext, record: T): Promise<void> {
|
|
31
|
+
record.createdAt = record.createdAt ?? new Date()
|
|
32
|
+
record.updatedAt = record.createdAt
|
|
33
|
+
|
|
34
|
+
const adapter = this.getAdapterForRecordType(record.type)
|
|
35
|
+
|
|
36
|
+
// TOOD: duplicate
|
|
37
|
+
await adapter.insert(agentContext, record)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public async update(agentContext: AgentContext, record: T): Promise<void> {
|
|
41
|
+
record.updatedAt = new Date()
|
|
42
|
+
|
|
43
|
+
const adapter = this.getAdapterForRecordType(record.type)
|
|
44
|
+
await adapter.update(agentContext, record)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public async delete(agentContext: AgentContext, record: T): Promise<void> {
|
|
48
|
+
const adapter = this.getAdapterForRecordType(record.type)
|
|
49
|
+
await adapter.delete(agentContext, record.id)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public async deleteById(
|
|
53
|
+
agentContext: AgentContext,
|
|
54
|
+
recordClass: BaseRecordConstructor<T>,
|
|
55
|
+
id: string
|
|
56
|
+
): Promise<void> {
|
|
57
|
+
const adapter = this.getAdapterForRecordType(recordClass.type)
|
|
58
|
+
|
|
59
|
+
await adapter.delete(agentContext, id)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public async getById(agentContext: AgentContext, recordClass: BaseRecordConstructor<T>, id: string): Promise<T> {
|
|
63
|
+
const adapter = this.getAdapterForRecordType(recordClass.type)
|
|
64
|
+
|
|
65
|
+
const record = await adapter.getById(agentContext, id)
|
|
66
|
+
return record
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public async getAll(agentContext: AgentContext, recordClass: BaseRecordConstructor<T>): Promise<T[]> {
|
|
70
|
+
const adapter = this.getAdapterForRecordType(recordClass.type)
|
|
71
|
+
|
|
72
|
+
const records = await adapter.query(agentContext)
|
|
73
|
+
return records
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public async findByQuery(
|
|
77
|
+
agentContext: AgentContext,
|
|
78
|
+
recordClass: BaseRecordConstructor<T>,
|
|
79
|
+
query: Query<T>,
|
|
80
|
+
queryOptions?: QueryOptions
|
|
81
|
+
): Promise<T[]> {
|
|
82
|
+
const adapter = this.getAdapterForRecordType(recordClass.type)
|
|
83
|
+
|
|
84
|
+
const records = await adapter.query(agentContext, query, queryOptions)
|
|
85
|
+
return records
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './DrizzleStorageService'
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DrizzleRecordBundle } from '../DrizzleRecord'
|
|
2
|
+
import { tenantDrizzleRecord } from './tenant'
|
|
3
|
+
import { tenantRoutingDrizzleRecord } from './tenant-routing'
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
name: 'tenants',
|
|
7
|
+
records: [tenantDrizzleRecord, tenantRoutingDrizzleRecord],
|
|
8
|
+
|
|
9
|
+
migrations: {
|
|
10
|
+
postgres: {
|
|
11
|
+
schemaModule: '@credo-ts/drizzle-storage/tenants/postgres',
|
|
12
|
+
migrationsPath: '../../migrations/tenants/postgres',
|
|
13
|
+
},
|
|
14
|
+
sqlite: {
|
|
15
|
+
schemaModule: '@credo-ts/drizzle-storage/tenants/sqlite',
|
|
16
|
+
migrationsPath: '../../migrations/tenants/sqlite',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
} as const satisfies DrizzleRecordBundle
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { JsonTransformer, TagsBase } from '@credo-ts/core'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
BaseDrizzleRecordAdapter,
|
|
5
|
+
DrizzleAdapterRecordValues,
|
|
6
|
+
DrizzleAdapterValues,
|
|
7
|
+
} from '../../adapter/BaseDrizzleRecordAdapter'
|
|
8
|
+
|
|
9
|
+
import { TenantRecord } from '@credo-ts/tenants'
|
|
10
|
+
import { DrizzleDatabase } from '../../DrizzleDatabase'
|
|
11
|
+
import * as postgres from './postgres'
|
|
12
|
+
import * as sqlite from './sqlite'
|
|
13
|
+
|
|
14
|
+
type DrizzleTenantAdapterValues = DrizzleAdapterRecordValues<(typeof sqlite)['tenant']>
|
|
15
|
+
export class DrizzleTenantRecordAdapter extends BaseDrizzleRecordAdapter<
|
|
16
|
+
TenantRecord,
|
|
17
|
+
typeof postgres.tenant,
|
|
18
|
+
typeof postgres,
|
|
19
|
+
typeof sqlite.tenant,
|
|
20
|
+
typeof sqlite
|
|
21
|
+
> {
|
|
22
|
+
public constructor(database: DrizzleDatabase<typeof postgres, typeof sqlite>) {
|
|
23
|
+
super(database, { postgres: postgres.tenant, sqlite: sqlite.tenant }, 'TenantRecord')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public getValues(record: TenantRecord): DrizzleAdapterValues<(typeof sqlite)['tenant']> {
|
|
27
|
+
const { label, storageVersion, ...customTags } = record.getTags()
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
label,
|
|
31
|
+
storageVersion,
|
|
32
|
+
config: record.config,
|
|
33
|
+
customTags,
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public toRecord(values: DrizzleTenantAdapterValues): TenantRecord {
|
|
38
|
+
const { customTags, ...remainingValues } = values
|
|
39
|
+
|
|
40
|
+
const record = JsonTransformer.fromJSON(remainingValues, TenantRecord)
|
|
41
|
+
if (customTags) record.setTags(customTags as TagsBase)
|
|
42
|
+
|
|
43
|
+
return record
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DrizzleRecord } from '../../DrizzleRecord'
|
|
2
|
+
import { DrizzleTenantRecordAdapter } from './DrizzleTenantRecordAdapter'
|
|
3
|
+
import * as postgres from './postgres'
|
|
4
|
+
import * as sqlite from './sqlite'
|
|
5
|
+
|
|
6
|
+
export const tenantDrizzleRecord = {
|
|
7
|
+
adapter: DrizzleTenantRecordAdapter,
|
|
8
|
+
postgres,
|
|
9
|
+
sqlite,
|
|
10
|
+
} satisfies DrizzleRecord
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { VersionString } from '@credo-ts/core'
|
|
2
|
+
import { TenantRecord } from '@credo-ts/tenants'
|
|
3
|
+
import { jsonb, pgTable, text } from 'drizzle-orm/pg-core'
|
|
4
|
+
import { getPostgresBaseRecordTable, postgresBaseRecordIndexes } from '../../postgres/baseRecord'
|
|
5
|
+
|
|
6
|
+
export const tenant = pgTable(
|
|
7
|
+
'Tenant',
|
|
8
|
+
{
|
|
9
|
+
...getPostgresBaseRecordTable(),
|
|
10
|
+
|
|
11
|
+
storageVersion: text('storage_version').$type<VersionString>(),
|
|
12
|
+
config: jsonb().$type<TenantRecord['config']>().notNull(),
|
|
13
|
+
label: text().notNull(),
|
|
14
|
+
},
|
|
15
|
+
(table) => postgresBaseRecordIndexes(table, 'tenant')
|
|
16
|
+
)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { VersionString } from '@credo-ts/core'
|
|
2
|
+
import { TenantRecord } from '@credo-ts/tenants'
|
|
3
|
+
import { sqliteTable, text } from 'drizzle-orm/sqlite-core'
|
|
4
|
+
import { getSqliteBaseRecordTable, sqliteBaseRecordIndexes } from '../../sqlite/baseRecord'
|
|
5
|
+
|
|
6
|
+
export const tenant = sqliteTable(
|
|
7
|
+
'Tenant',
|
|
8
|
+
{
|
|
9
|
+
...getSqliteBaseRecordTable(),
|
|
10
|
+
|
|
11
|
+
storageVersion: text('storage_version').$type<VersionString>(),
|
|
12
|
+
config: text({ mode: 'json' }).$type<TenantRecord['config']>().notNull(),
|
|
13
|
+
label: text().notNull(),
|
|
14
|
+
},
|
|
15
|
+
(table) => sqliteBaseRecordIndexes(table, 'tenant')
|
|
16
|
+
)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { JsonTransformer, TagsBase } from '@credo-ts/core'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
BaseDrizzleRecordAdapter,
|
|
5
|
+
DrizzleAdapterRecordValues,
|
|
6
|
+
DrizzleAdapterValues,
|
|
7
|
+
} from '../../adapter/BaseDrizzleRecordAdapter'
|
|
8
|
+
|
|
9
|
+
import { TenantRoutingRecord } from '@credo-ts/tenants'
|
|
10
|
+
import { DrizzleDatabase } from '../../DrizzleDatabase'
|
|
11
|
+
import * as postgres from './postgres'
|
|
12
|
+
import * as sqlite from './sqlite'
|
|
13
|
+
|
|
14
|
+
type DrizzleTenantRoutingAdapterValues = DrizzleAdapterRecordValues<(typeof sqlite)['tenantRouting']>
|
|
15
|
+
export class DrizzleTenantRoutingRecordAdapter extends BaseDrizzleRecordAdapter<
|
|
16
|
+
TenantRoutingRecord,
|
|
17
|
+
typeof postgres.tenantRouting,
|
|
18
|
+
typeof postgres,
|
|
19
|
+
typeof sqlite.tenantRouting,
|
|
20
|
+
typeof sqlite
|
|
21
|
+
> {
|
|
22
|
+
public constructor(database: DrizzleDatabase<typeof postgres, typeof sqlite>) {
|
|
23
|
+
super(database, { postgres: postgres.tenantRouting, sqlite: sqlite.tenantRouting }, 'TenantRoutingRecord')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public getValues(record: TenantRoutingRecord): DrizzleAdapterValues<(typeof sqlite)['tenantRouting']> {
|
|
27
|
+
const { recipientKeyFingerprint, tenantId, ...customTags } = record.getTags()
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
recipientKeyFingerprint,
|
|
31
|
+
tenantId,
|
|
32
|
+
customTags,
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public toRecord(values: DrizzleTenantRoutingAdapterValues): TenantRoutingRecord {
|
|
37
|
+
const { customTags, ...remainingValues } = values
|
|
38
|
+
|
|
39
|
+
const record = JsonTransformer.fromJSON(remainingValues, TenantRoutingRecord)
|
|
40
|
+
if (customTags) record.setTags(customTags as TagsBase)
|
|
41
|
+
|
|
42
|
+
return record
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DrizzleRecord } from '../../DrizzleRecord'
|
|
2
|
+
import { DrizzleTenantRoutingRecordAdapter } from './DrizzleTenantRoutingRecordAdapter'
|
|
3
|
+
import * as postgres from './postgres'
|
|
4
|
+
import * as sqlite from './sqlite'
|
|
5
|
+
|
|
6
|
+
export const tenantRoutingDrizzleRecord = {
|
|
7
|
+
adapter: DrizzleTenantRoutingRecordAdapter,
|
|
8
|
+
postgres,
|
|
9
|
+
sqlite,
|
|
10
|
+
} satisfies DrizzleRecord
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { foreignKey, pgTable, text } from 'drizzle-orm/pg-core'
|
|
2
|
+
import { getPostgresBaseRecordTable, postgresBaseRecordIndexes } from '../../postgres/baseRecord'
|
|
3
|
+
import { tenant } from '../postgres'
|
|
4
|
+
|
|
5
|
+
export const tenantRouting = pgTable(
|
|
6
|
+
'TenantRouting',
|
|
7
|
+
{
|
|
8
|
+
...getPostgresBaseRecordTable(),
|
|
9
|
+
|
|
10
|
+
tenantId: text('tenant_id').notNull(),
|
|
11
|
+
recipientKeyFingerprint: text('recipient_key_fingerprint').notNull(),
|
|
12
|
+
},
|
|
13
|
+
(table) => [
|
|
14
|
+
...postgresBaseRecordIndexes(table, 'tenantRouting'),
|
|
15
|
+
foreignKey({
|
|
16
|
+
columns: [table.tenantId, table.contextCorrelationId],
|
|
17
|
+
foreignColumns: [tenant.id, tenant.contextCorrelationId],
|
|
18
|
+
}).onDelete('cascade'),
|
|
19
|
+
]
|
|
20
|
+
)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { foreignKey, sqliteTable, text } from 'drizzle-orm/sqlite-core'
|
|
2
|
+
import { getSqliteBaseRecordTable, sqliteBaseRecordIndexes } from '../../sqlite/baseRecord'
|
|
3
|
+
import { tenant } from '../sqlite'
|
|
4
|
+
|
|
5
|
+
export const tenantRouting = sqliteTable(
|
|
6
|
+
'TenantRouting',
|
|
7
|
+
{
|
|
8
|
+
...getSqliteBaseRecordTable(),
|
|
9
|
+
|
|
10
|
+
tenantId: text('tenant_id').notNull(),
|
|
11
|
+
recipientKeyFingerprint: text('recipient_key_fingerprint').notNull(),
|
|
12
|
+
},
|
|
13
|
+
(table) => [
|
|
14
|
+
...sqliteBaseRecordIndexes(table, 'tenantRouting'),
|
|
15
|
+
foreignKey({
|
|
16
|
+
columns: [table.tenantId, table.contextCorrelationId],
|
|
17
|
+
foreignColumns: [tenant.id, tenant.contextCorrelationId],
|
|
18
|
+
}).onDelete('cascade'),
|
|
19
|
+
]
|
|
20
|
+
)
|