@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,213 @@
|
|
|
1
|
+
import { BaseRecord, Query } from '@credo-ts/core'
|
|
2
|
+
import { SQL, SQLWrapper, and, eq, not, or, sql } from 'drizzle-orm'
|
|
3
|
+
import { sqliteTable } from 'drizzle-orm/sqlite-core'
|
|
4
|
+
import type { AnySQLiteColumn, SQLiteColumn } from 'drizzle-orm/sqlite-core'
|
|
5
|
+
import { CredoDrizzleStorageError } from '../error'
|
|
6
|
+
import { getSqliteBaseRecordTable } from '../sqlite'
|
|
7
|
+
import { DrizzleCustomTagKeyMapping } from './queryToDrizzlePostgres'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Checks if an array column (stored as JSON text in SQLite) contains all values from the given array
|
|
11
|
+
* This ensures that the provided values array is a subset of the stored array
|
|
12
|
+
*
|
|
13
|
+
* @param column The column storing the JSON array
|
|
14
|
+
* @param values Array of values that should be contained in the column
|
|
15
|
+
* @returns SQL condition that checks if all values are in the array
|
|
16
|
+
*/
|
|
17
|
+
function arrayContainsAll<T extends AnySQLiteColumn>(column: T, values: unknown[]): SQL<unknown> {
|
|
18
|
+
if (values.length === 0) {
|
|
19
|
+
return sql`1=1` // Empty array always matches
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return sql.join(
|
|
23
|
+
values.map((value) => sql`EXISTS (SELECT 1 FROM json_each(${column}) WHERE value = ${value})`),
|
|
24
|
+
sql` AND `
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Checks if a JSON array within a JSON object contains all values from a given array
|
|
30
|
+
*
|
|
31
|
+
* @param column The column storing the JSON object
|
|
32
|
+
* @param path Path to the JSON array property
|
|
33
|
+
* @param values Array of values to check for containment
|
|
34
|
+
* @returns SQL condition that checks if all values are contained in the array
|
|
35
|
+
*/
|
|
36
|
+
function jsonArrayContainsAll<T extends AnySQLiteColumn>(column: T, tag: string, values: unknown[]): SQL<unknown> {
|
|
37
|
+
if (values.length === 0) {
|
|
38
|
+
return sql`1=1` // Empty array always matches
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const jsonPath = `$."${tag}"`
|
|
42
|
+
return sql.join(
|
|
43
|
+
values.map(
|
|
44
|
+
(value) => sql`EXISTS (SELECT 1 FROM json_each(json_extract(${column}, ${jsonPath})) WHERE value = ${value})`
|
|
45
|
+
),
|
|
46
|
+
sql` AND `
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Converts a WQL object to Drizzle SQLite where conditions
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
54
|
+
export function queryToDrizzleSqlite<CredoRecord extends BaseRecord<any, any, any> = BaseRecord>(
|
|
55
|
+
query: Query<CredoRecord>,
|
|
56
|
+
table: ReturnType<typeof sqliteTable<string, ReturnType<typeof getSqliteBaseRecordTable>>>,
|
|
57
|
+
customTagKeyMapping?: DrizzleCustomTagKeyMapping
|
|
58
|
+
): SQL {
|
|
59
|
+
// Handle empty WQL
|
|
60
|
+
if (!query || Object.keys(query).length === 0) {
|
|
61
|
+
return sql`1=1`
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const conditions: Array<SQLWrapper> = []
|
|
65
|
+
|
|
66
|
+
// Process $or operator
|
|
67
|
+
if (query.$or && Array.isArray(query.$or) && query.$or.length > 0) {
|
|
68
|
+
const _$or = query.$or as Query<BaseRecord>[]
|
|
69
|
+
|
|
70
|
+
const orCondition = or(
|
|
71
|
+
..._$or
|
|
72
|
+
.map((orItem) => queryToDrizzleSqlite(orItem, table, customTagKeyMapping))
|
|
73
|
+
.filter((sql) => sql !== undefined)
|
|
74
|
+
)
|
|
75
|
+
if (orCondition) {
|
|
76
|
+
conditions.push(orCondition)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Process $and operator
|
|
81
|
+
if (query.$and && Array.isArray(query.$and) && query.$and.length > 0) {
|
|
82
|
+
const _$and = query.$and as Query<BaseRecord>[]
|
|
83
|
+
|
|
84
|
+
const andCondition = and(
|
|
85
|
+
..._$and
|
|
86
|
+
.map((andItem) => queryToDrizzleSqlite(andItem, table, customTagKeyMapping))
|
|
87
|
+
.filter((sql) => sql !== undefined)
|
|
88
|
+
)
|
|
89
|
+
if (andCondition) {
|
|
90
|
+
conditions.push(andCondition)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Process $not operator
|
|
95
|
+
if (query.$not) {
|
|
96
|
+
const notQuery = query.$not as Query<BaseRecord>
|
|
97
|
+
const notConditions: Array<SQLWrapper> = []
|
|
98
|
+
|
|
99
|
+
// Process $and within $not - all statements must be false
|
|
100
|
+
if (notQuery.$and && Array.isArray(notQuery.$and) && notQuery.$and.length > 0) {
|
|
101
|
+
const _$and = notQuery.$and as Query<BaseRecord>[]
|
|
102
|
+
|
|
103
|
+
// We need NOT(condition1 OR condition2 OR condition3)
|
|
104
|
+
// This is equivalent to NOT(condition1) AND NOT(condition2) AND NOT(condition3)
|
|
105
|
+
const andNotConditions = _$and
|
|
106
|
+
.map((andItem) => {
|
|
107
|
+
const condition = queryToDrizzleSqlite(andItem, table, customTagKeyMapping)
|
|
108
|
+
return condition ? not(condition) : undefined
|
|
109
|
+
})
|
|
110
|
+
.filter((condition) => condition !== undefined)
|
|
111
|
+
|
|
112
|
+
const andCondition = and(...andNotConditions)
|
|
113
|
+
if (andCondition) {
|
|
114
|
+
notConditions.push(andCondition)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Process $or within $not - at least one statement must be false
|
|
119
|
+
if (notQuery.$or && Array.isArray(notQuery.$or) && notQuery.$or.length > 0) {
|
|
120
|
+
const _$or = notQuery.$or as Query<BaseRecord>[]
|
|
121
|
+
|
|
122
|
+
// We need at least one false, so NOT(condition1 AND condition2 AND condition3)
|
|
123
|
+
const orCondition = and(
|
|
124
|
+
..._$or.map((orItem) => queryToDrizzleSqlite(orItem, table, customTagKeyMapping)).filter(Boolean)
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
if (orCondition) {
|
|
128
|
+
notConditions.push(not(orCondition))
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Process other fields in $not
|
|
133
|
+
for (const field in notQuery) {
|
|
134
|
+
if (field === '$not') {
|
|
135
|
+
throw new CredoDrizzleStorageError('Nested $not in $not is not supported')
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (field === '$or' || field === '$and') {
|
|
139
|
+
continue
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const condition = queryToDrizzleSqlite(
|
|
143
|
+
{ [field]: notQuery[field as keyof typeof notQuery] } as Query<BaseRecord>,
|
|
144
|
+
table,
|
|
145
|
+
customTagKeyMapping
|
|
146
|
+
)
|
|
147
|
+
if (condition) {
|
|
148
|
+
notConditions.push(not(condition))
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Combine all $not conditions with AND
|
|
153
|
+
const combinedNotCondition = notConditions.length === 1 ? notConditions[0] : and(...notConditions)
|
|
154
|
+
if (combinedNotCondition) {
|
|
155
|
+
conditions.push(combinedNotCondition)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Process regular field conditions
|
|
160
|
+
for (const field in query) {
|
|
161
|
+
// Skip special operators we've already handled
|
|
162
|
+
if (field === '$or' || field === '$and' || field === '$not') {
|
|
163
|
+
continue
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const value = query[field as keyof typeof query]
|
|
167
|
+
|
|
168
|
+
// Skip undefined values
|
|
169
|
+
if (value === undefined) continue
|
|
170
|
+
|
|
171
|
+
// Check if the field exists in the table
|
|
172
|
+
// In that case, query the column
|
|
173
|
+
if (field in table && table[field as keyof typeof table] instanceof Object) {
|
|
174
|
+
const column = table[field as keyof typeof table] as AnySQLiteColumn
|
|
175
|
+
if (Array.isArray(value)) {
|
|
176
|
+
conditions.push(arrayContainsAll(column, value))
|
|
177
|
+
} else {
|
|
178
|
+
conditions.push(eq(column, value))
|
|
179
|
+
}
|
|
180
|
+
} else {
|
|
181
|
+
// Check if field has a custom mapping
|
|
182
|
+
let targetField = field
|
|
183
|
+
let targetColumn: SQLiteColumn = table.customTags
|
|
184
|
+
|
|
185
|
+
if (customTagKeyMapping && field in customTagKeyMapping) {
|
|
186
|
+
const mapping = customTagKeyMapping[field]
|
|
187
|
+
const [columnName, fieldName] = mapping
|
|
188
|
+
|
|
189
|
+
if (columnName in table && table[columnName as keyof typeof table] instanceof Object) {
|
|
190
|
+
// Check if the mapped column exists in the table
|
|
191
|
+
targetColumn = table[columnName as keyof typeof table] as AnySQLiteColumn
|
|
192
|
+
targetField = fieldName
|
|
193
|
+
} else {
|
|
194
|
+
throw new CredoDrizzleStorageError(
|
|
195
|
+
`Query defined custom mapping from key '${field}' to column ${columnName}, but the column does not exist in the table.`
|
|
196
|
+
)
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Handle custom tag or mapped field
|
|
201
|
+
if (Array.isArray(value)) {
|
|
202
|
+
conditions.push(jsonArrayContainsAll(targetColumn, targetField, value))
|
|
203
|
+
} else {
|
|
204
|
+
const jsonPath = `$."${targetField}"`
|
|
205
|
+
// For scalar values, we need to extract and compare in SQLite syntax
|
|
206
|
+
conditions.push(eq(sql`json_extract(${targetColumn}, ${jsonPath})`, value))
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Combine all conditions with AND
|
|
212
|
+
return conditions.length === 1 ? conditions[0].getSQL() : (and(...conditions) ?? sql`1=1`)
|
|
213
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { DrizzleRecordBundle } from '../DrizzleRecord'
|
|
2
|
+
import { anonCredsCredentialDrizzleRecord } from './credential'
|
|
3
|
+
import { anonCredsCredentialDefinitionDrizzleRecord } from './credential-definition'
|
|
4
|
+
import { anonCredsCredentialDefinitionPrivateDrizzleRecord } from './credential-definition-private'
|
|
5
|
+
import { anonCredsKeyCorrectnessProofDrizzleRecord } from './key-correctness-proof'
|
|
6
|
+
import { anonCredsLinkSecretDrizzleRecord } from './link-secret'
|
|
7
|
+
import { anonCredsRevocationRegistryDefinitionDrizzleRecord } from './revocation-registry-definition'
|
|
8
|
+
import { anonCredsRevocationRegistryDefinitionPrivateDrizzleRecord } from './revocation-registry-definition-private'
|
|
9
|
+
import { anonCredsSchemaDrizzleRecord } from './schema'
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
name: 'anoncreds',
|
|
13
|
+
records: [
|
|
14
|
+
anonCredsCredentialDrizzleRecord,
|
|
15
|
+
anonCredsCredentialDefinitionDrizzleRecord,
|
|
16
|
+
anonCredsCredentialDefinitionPrivateDrizzleRecord,
|
|
17
|
+
anonCredsKeyCorrectnessProofDrizzleRecord,
|
|
18
|
+
anonCredsLinkSecretDrizzleRecord,
|
|
19
|
+
anonCredsRevocationRegistryDefinitionDrizzleRecord,
|
|
20
|
+
anonCredsRevocationRegistryDefinitionPrivateDrizzleRecord,
|
|
21
|
+
anonCredsSchemaDrizzleRecord,
|
|
22
|
+
],
|
|
23
|
+
|
|
24
|
+
migrations: {
|
|
25
|
+
postgres: {
|
|
26
|
+
schemaModule: '@credo-ts/drizzle-storage/anoncreds/postgres',
|
|
27
|
+
migrationsPath: '../../migrations/anoncreds/postgres',
|
|
28
|
+
},
|
|
29
|
+
sqlite: {
|
|
30
|
+
schemaModule: '@credo-ts/drizzle-storage/anoncreds/sqlite',
|
|
31
|
+
migrationsPath: '../../migrations/anoncreds/sqlite',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
} as const satisfies DrizzleRecordBundle
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { JsonTransformer, TagsBase } from '@credo-ts/core'
|
|
2
|
+
|
|
3
|
+
import { BaseDrizzleRecordAdapter, DrizzleAdapterRecordValues } from '../../adapter/BaseDrizzleRecordAdapter'
|
|
4
|
+
|
|
5
|
+
import { AnonCredsCredentialRecord } from '@credo-ts/anoncreds'
|
|
6
|
+
import { DrizzleDatabase } from '../../DrizzleDatabase'
|
|
7
|
+
import * as postgres from './postgres'
|
|
8
|
+
import * as sqlite from './sqlite'
|
|
9
|
+
|
|
10
|
+
type DrizzleAnonCredsCredentialAdapterValues = DrizzleAdapterRecordValues<(typeof sqlite)['anonCredsCredential']>
|
|
11
|
+
export class DrizzleAnonCredsCredentialRecordAdapter extends BaseDrizzleRecordAdapter<
|
|
12
|
+
AnonCredsCredentialRecord,
|
|
13
|
+
typeof postgres.anonCredsCredential,
|
|
14
|
+
typeof postgres,
|
|
15
|
+
typeof sqlite.anonCredsCredential,
|
|
16
|
+
typeof sqlite
|
|
17
|
+
> {
|
|
18
|
+
public constructor(database: DrizzleDatabase<typeof postgres, typeof sqlite>) {
|
|
19
|
+
super(
|
|
20
|
+
database,
|
|
21
|
+
{ postgres: postgres.anonCredsCredential, sqlite: sqlite.anonCredsCredential },
|
|
22
|
+
'AnonCredsCredentialRecord'
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public getValues(record: AnonCredsCredentialRecord) {
|
|
27
|
+
const {
|
|
28
|
+
credentialId,
|
|
29
|
+
linkSecretId,
|
|
30
|
+
credentialDefinitionId,
|
|
31
|
+
credentialRevocationId,
|
|
32
|
+
revocationRegistryId,
|
|
33
|
+
schemaId,
|
|
34
|
+
methodName,
|
|
35
|
+
schemaName,
|
|
36
|
+
schemaVersion,
|
|
37
|
+
schemaIssuerId,
|
|
38
|
+
issuerId,
|
|
39
|
+
...customTags
|
|
40
|
+
} = record.getTags()
|
|
41
|
+
|
|
42
|
+
const { schema_id, cred_def_id, rev_reg_id, ...credentialRest } = record.credential
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
credentialId,
|
|
46
|
+
credentialRevocationId,
|
|
47
|
+
linkSecretId,
|
|
48
|
+
methodName,
|
|
49
|
+
|
|
50
|
+
credential: credentialRest,
|
|
51
|
+
credentialDefinitionId,
|
|
52
|
+
revocationRegistryId,
|
|
53
|
+
schemaId,
|
|
54
|
+
|
|
55
|
+
schemaName,
|
|
56
|
+
schemaVersion,
|
|
57
|
+
schemaIssuerId,
|
|
58
|
+
issuerId,
|
|
59
|
+
|
|
60
|
+
customTags,
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public toRecord(values: DrizzleAnonCredsCredentialAdapterValues): AnonCredsCredentialRecord {
|
|
65
|
+
const {
|
|
66
|
+
customTags,
|
|
67
|
+
schemaId,
|
|
68
|
+
revocationRegistryId,
|
|
69
|
+
credentialDefinitionId,
|
|
70
|
+
schemaName,
|
|
71
|
+
schemaVersion,
|
|
72
|
+
schemaIssuerId,
|
|
73
|
+
issuerId,
|
|
74
|
+
...remainingValues
|
|
75
|
+
} = values
|
|
76
|
+
|
|
77
|
+
const record = JsonTransformer.fromJSON(
|
|
78
|
+
{
|
|
79
|
+
...remainingValues,
|
|
80
|
+
credential: {
|
|
81
|
+
...remainingValues.credential,
|
|
82
|
+
schema_id: schemaId,
|
|
83
|
+
cred_def_id: credentialDefinitionId,
|
|
84
|
+
rev_reg_id: revocationRegistryId,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
AnonCredsCredentialRecord
|
|
88
|
+
)
|
|
89
|
+
record.setTags({ ...customTags, schemaName, schemaVersion, schemaIssuerId, issuerId } as TagsBase)
|
|
90
|
+
|
|
91
|
+
return record
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DrizzleRecord } from '../../DrizzleRecord'
|
|
2
|
+
import { DrizzleAnonCredsCredentialRecordAdapter } from './DrizzleAnonCredsCredentialRecordAdapter'
|
|
3
|
+
import * as postgres from './postgres'
|
|
4
|
+
import * as sqlite from './sqlite'
|
|
5
|
+
|
|
6
|
+
export const anonCredsCredentialDrizzleRecord = {
|
|
7
|
+
adapter: DrizzleAnonCredsCredentialRecordAdapter,
|
|
8
|
+
postgres,
|
|
9
|
+
sqlite,
|
|
10
|
+
} satisfies DrizzleRecord
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AnonCredsCredential } 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 anonCredsCredential = pgTable(
|
|
6
|
+
'AnonCredsCredential',
|
|
7
|
+
{
|
|
8
|
+
...getPostgresBaseRecordTable(),
|
|
9
|
+
|
|
10
|
+
credentialId: text('credential_id').notNull().unique(),
|
|
11
|
+
credentialRevocationId: text('credential_revocation_id'),
|
|
12
|
+
linkSecretId: text('link_secret_id').notNull(),
|
|
13
|
+
credential: jsonb('credential')
|
|
14
|
+
.$type<Omit<AnonCredsCredential, 'schema_id' | 'cred_def_id' | 'rev_reg_id'>>()
|
|
15
|
+
.notNull(),
|
|
16
|
+
methodName: text('method_name').notNull(),
|
|
17
|
+
|
|
18
|
+
credentialDefinitionId: text('credential_definition_id').notNull(),
|
|
19
|
+
revocationRegistryId: text('revocation_registry_id'),
|
|
20
|
+
schemaId: text('schema_id').notNull(),
|
|
21
|
+
schemaName: text('schema_name').notNull(),
|
|
22
|
+
schemaVersion: text('schema_version').notNull(),
|
|
23
|
+
schemaIssuerId: text('schema_issuer_id').notNull(),
|
|
24
|
+
issuerId: text('issuer_id').notNull(),
|
|
25
|
+
},
|
|
26
|
+
(table) => postgresBaseRecordIndexes(table, 'anonCredsCredential')
|
|
27
|
+
)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AnonCredsCredential } from '@credo-ts/anoncreds'
|
|
2
|
+
import { sqliteTable, text } from 'drizzle-orm/sqlite-core'
|
|
3
|
+
import { getSqliteBaseRecordTable, sqliteBaseRecordIndexes } from '../../sqlite/baseRecord'
|
|
4
|
+
|
|
5
|
+
export const anonCredsCredential = sqliteTable(
|
|
6
|
+
'AnonCredsCredential',
|
|
7
|
+
{
|
|
8
|
+
...getSqliteBaseRecordTable(),
|
|
9
|
+
|
|
10
|
+
credentialId: text('credential_id').notNull(),
|
|
11
|
+
credentialRevocationId: text('credential_revocation_id'),
|
|
12
|
+
linkSecretId: text('link_secret_id').notNull(),
|
|
13
|
+
credential: text('credential', { mode: 'json' })
|
|
14
|
+
.$type<Omit<AnonCredsCredential, 'schema_id' | 'cred_def_id' | 'rev_reg_id'>>()
|
|
15
|
+
.notNull(),
|
|
16
|
+
methodName: text('method_name').notNull(),
|
|
17
|
+
|
|
18
|
+
credentialDefinitionId: text('credential_definition_id').notNull(),
|
|
19
|
+
revocationRegistryId: text('revocation_registry_id'),
|
|
20
|
+
schemaId: text('schema_id').notNull(),
|
|
21
|
+
schemaName: text('schema_name').notNull(),
|
|
22
|
+
schemaVersion: text('schema_version').notNull(),
|
|
23
|
+
schemaIssuerId: text('schema_issuer_id').notNull(),
|
|
24
|
+
issuerId: text('issuer_id').notNull(),
|
|
25
|
+
},
|
|
26
|
+
(table) => sqliteBaseRecordIndexes(table, 'anonCredsCredential')
|
|
27
|
+
)
|
package/src/anoncreds/credential-definition/DrizzleAnonCredsCredentialDefinitionRecordAdapter.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { JsonTransformer, TagsBase } from '@credo-ts/core'
|
|
2
|
+
|
|
3
|
+
import { BaseDrizzleRecordAdapter, DrizzleAdapterRecordValues } from '../../adapter/BaseDrizzleRecordAdapter'
|
|
4
|
+
|
|
5
|
+
import { AnonCredsCredentialDefinitionRecord } from '@credo-ts/anoncreds'
|
|
6
|
+
import { DrizzleDatabase } from '../../DrizzleDatabase'
|
|
7
|
+
import * as postgres from './postgres'
|
|
8
|
+
import * as sqlite from './sqlite'
|
|
9
|
+
|
|
10
|
+
type DrizzleAnonCredsCredentialDefinitionAdapterValues = DrizzleAdapterRecordValues<
|
|
11
|
+
(typeof sqlite)['anonCredsCredentialDefinition']
|
|
12
|
+
>
|
|
13
|
+
export class DrizzleAnonCredsCredentialDefinitionRecordAdapter extends BaseDrizzleRecordAdapter<
|
|
14
|
+
AnonCredsCredentialDefinitionRecord,
|
|
15
|
+
typeof postgres.anonCredsCredentialDefinition,
|
|
16
|
+
typeof postgres,
|
|
17
|
+
typeof sqlite.anonCredsCredentialDefinition,
|
|
18
|
+
typeof sqlite
|
|
19
|
+
> {
|
|
20
|
+
public constructor(database: DrizzleDatabase<typeof postgres, typeof sqlite>) {
|
|
21
|
+
super(
|
|
22
|
+
database,
|
|
23
|
+
{ postgres: postgres.anonCredsCredentialDefinition, sqlite: sqlite.anonCredsCredentialDefinition },
|
|
24
|
+
'AnonCredsCredentialDefinitionRecord'
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public getValues(record: AnonCredsCredentialDefinitionRecord) {
|
|
29
|
+
const {
|
|
30
|
+
schemaId: schemaIdTag,
|
|
31
|
+
credentialDefinitionId,
|
|
32
|
+
issuerId: issuerIdTag,
|
|
33
|
+
tag: tagTag,
|
|
34
|
+
methodName,
|
|
35
|
+
unqualifiedCredentialDefinitionId,
|
|
36
|
+
...customTags
|
|
37
|
+
} = record.getTags()
|
|
38
|
+
|
|
39
|
+
const { issuerId, schemaId, tag, ...credentialDefinitionRest } = record.credentialDefinition
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
credentialDefinitionId,
|
|
43
|
+
methodName,
|
|
44
|
+
unqualifiedCredentialDefinitionId,
|
|
45
|
+
|
|
46
|
+
schemaId,
|
|
47
|
+
issuerId,
|
|
48
|
+
tag,
|
|
49
|
+
credentialDefinition: credentialDefinitionRest,
|
|
50
|
+
|
|
51
|
+
customTags,
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public toRecord(values: DrizzleAnonCredsCredentialDefinitionAdapterValues): AnonCredsCredentialDefinitionRecord {
|
|
56
|
+
const { customTags, unqualifiedCredentialDefinitionId, issuerId, schemaId, tag, ...remainingValues } = values
|
|
57
|
+
|
|
58
|
+
const record = JsonTransformer.fromJSON(
|
|
59
|
+
{
|
|
60
|
+
...remainingValues,
|
|
61
|
+
credentialDefinition: { ...remainingValues.credentialDefinition, issuerId, schemaId, tag },
|
|
62
|
+
},
|
|
63
|
+
AnonCredsCredentialDefinitionRecord
|
|
64
|
+
)
|
|
65
|
+
record.setTags({
|
|
66
|
+
...customTags,
|
|
67
|
+
unqualifiedCredentialDefinitionId: unqualifiedCredentialDefinitionId ?? undefined,
|
|
68
|
+
} as TagsBase)
|
|
69
|
+
|
|
70
|
+
return record
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DrizzleRecord } from '../../DrizzleRecord'
|
|
2
|
+
import { DrizzleAnonCredsCredentialDefinitionRecordAdapter } from './DrizzleAnonCredsCredentialDefinitionRecordAdapter'
|
|
3
|
+
import * as postgres from './postgres'
|
|
4
|
+
import * as sqlite from './sqlite'
|
|
5
|
+
|
|
6
|
+
export const anonCredsCredentialDefinitionDrizzleRecord = {
|
|
7
|
+
adapter: DrizzleAnonCredsCredentialDefinitionRecordAdapter,
|
|
8
|
+
postgres,
|
|
9
|
+
sqlite,
|
|
10
|
+
} satisfies DrizzleRecord
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AnonCredsCredentialDefinition } 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 anonCredsCredentialDefinition = pgTable(
|
|
6
|
+
'AnonCredsCredentialDefinition',
|
|
7
|
+
{
|
|
8
|
+
...getPostgresBaseRecordTable(),
|
|
9
|
+
|
|
10
|
+
credentialDefinitionId: text('credential_definition_id').notNull().unique(),
|
|
11
|
+
credentialDefinition: jsonb('credential_definition')
|
|
12
|
+
.$type<Omit<AnonCredsCredentialDefinition, 'issuerId' | 'schemaId' | 'tag'>>()
|
|
13
|
+
.notNull(),
|
|
14
|
+
methodName: text('method_name').notNull(),
|
|
15
|
+
|
|
16
|
+
// These are extracted from the credential definition JSON object, to allow for easy querying based on tags
|
|
17
|
+
schemaId: text('schema_id').notNull(),
|
|
18
|
+
issuerId: text('issuer_id').notNull(),
|
|
19
|
+
tag: text('tag').notNull(),
|
|
20
|
+
unqualifiedCredentialDefinitionId: text('unqualified_credential_definition_id'),
|
|
21
|
+
},
|
|
22
|
+
(table) => postgresBaseRecordIndexes(table, 'anonCredsCredentialDefinition')
|
|
23
|
+
)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AnonCredsCredentialDefinition } from '@credo-ts/anoncreds'
|
|
2
|
+
import { sqliteTable, text } from 'drizzle-orm/sqlite-core'
|
|
3
|
+
import { getSqliteBaseRecordTable, sqliteBaseRecordIndexes } from '../../sqlite/baseRecord'
|
|
4
|
+
|
|
5
|
+
export const anonCredsCredentialDefinition = sqliteTable(
|
|
6
|
+
'AnonCredsCredentialDefinition',
|
|
7
|
+
{
|
|
8
|
+
...getSqliteBaseRecordTable(),
|
|
9
|
+
|
|
10
|
+
credentialDefinitionId: text('credential_definition_id').notNull().unique(),
|
|
11
|
+
credentialDefinition: text('credential_definition', { mode: 'json' })
|
|
12
|
+
.$type<Omit<AnonCredsCredentialDefinition, 'issuerId' | 'schemaId' | 'tag'>>()
|
|
13
|
+
.notNull(),
|
|
14
|
+
methodName: text('method_name').notNull(),
|
|
15
|
+
|
|
16
|
+
// These are extracted from the credential definition JSON object, to allow for easy querying based on tags
|
|
17
|
+
schemaId: text('schema_id').notNull(),
|
|
18
|
+
issuerId: text('issuer_id').notNull(),
|
|
19
|
+
tag: text('tag').notNull(),
|
|
20
|
+
unqualifiedCredentialDefinitionId: text('unqualified_credential_definition_id'),
|
|
21
|
+
},
|
|
22
|
+
(table) => sqliteBaseRecordIndexes(table, 'anonCredsCredentialDefinition')
|
|
23
|
+
)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { JsonTransformer, TagsBase } from '@credo-ts/core'
|
|
2
|
+
|
|
3
|
+
import { BaseDrizzleRecordAdapter, DrizzleAdapterRecordValues } from '../../adapter/BaseDrizzleRecordAdapter'
|
|
4
|
+
|
|
5
|
+
import { AnonCredsCredentialDefinitionPrivateRecord } from '@credo-ts/anoncreds'
|
|
6
|
+
import { DrizzleDatabase } from '../../DrizzleDatabase'
|
|
7
|
+
import * as postgres from './postgres'
|
|
8
|
+
import * as sqlite from './sqlite'
|
|
9
|
+
|
|
10
|
+
type DrizzleAnonCredsCredentialDefinitionPrivateAdapterValues = DrizzleAdapterRecordValues<
|
|
11
|
+
(typeof sqlite)['anonCredsCredentialDefinitionPrivate']
|
|
12
|
+
>
|
|
13
|
+
export class DrizzleAnonCredsCredentialDefinitionPrivateRecordAdapter extends BaseDrizzleRecordAdapter<
|
|
14
|
+
AnonCredsCredentialDefinitionPrivateRecord,
|
|
15
|
+
typeof postgres.anonCredsCredentialDefinitionPrivate,
|
|
16
|
+
typeof postgres,
|
|
17
|
+
typeof sqlite.anonCredsCredentialDefinitionPrivate,
|
|
18
|
+
typeof sqlite
|
|
19
|
+
> {
|
|
20
|
+
public constructor(database: DrizzleDatabase<typeof postgres, typeof sqlite>) {
|
|
21
|
+
super(
|
|
22
|
+
database,
|
|
23
|
+
{ postgres: postgres.anonCredsCredentialDefinitionPrivate, sqlite: sqlite.anonCredsCredentialDefinitionPrivate },
|
|
24
|
+
'AnonCredsCredentialDefinitionPrivateRecord'
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public getValues(record: AnonCredsCredentialDefinitionPrivateRecord) {
|
|
29
|
+
const { credentialDefinitionId, ...customTags } = record.getTags()
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
credentialDefinitionId,
|
|
33
|
+
value: record.value,
|
|
34
|
+
customTags,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public toRecord(
|
|
39
|
+
values: DrizzleAnonCredsCredentialDefinitionPrivateAdapterValues
|
|
40
|
+
): AnonCredsCredentialDefinitionPrivateRecord {
|
|
41
|
+
const { customTags, credentialDefinitionId, ...remainingValues } = values
|
|
42
|
+
|
|
43
|
+
const record = JsonTransformer.fromJSON(remainingValues, AnonCredsCredentialDefinitionPrivateRecord)
|
|
44
|
+
record.setTags({ ...customTags, credentialDefinitionId } as TagsBase)
|
|
45
|
+
|
|
46
|
+
return record
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DrizzleRecord } from '../../DrizzleRecord'
|
|
2
|
+
import { DrizzleAnonCredsCredentialDefinitionPrivateRecordAdapter } from './DrizzleAnonCredsCredentialDefinitionPrivateRecordAdapter'
|
|
3
|
+
import * as postgres from './postgres'
|
|
4
|
+
import * as sqlite from './sqlite'
|
|
5
|
+
|
|
6
|
+
export const anonCredsCredentialDefinitionPrivateDrizzleRecord = {
|
|
7
|
+
adapter: DrizzleAnonCredsCredentialDefinitionPrivateRecordAdapter,
|
|
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
|
+
export const anonCredsCredentialDefinitionPrivate = pgTable(
|
|
5
|
+
'AnonCredsCredentialDefinitionPrivate',
|
|
6
|
+
{
|
|
7
|
+
...getPostgresBaseRecordTable(),
|
|
8
|
+
|
|
9
|
+
credentialDefinitionId: text('credential_definition_id').notNull().unique(),
|
|
10
|
+
|
|
11
|
+
value: jsonb('value').$type<Record<string, unknown>>().notNull(),
|
|
12
|
+
},
|
|
13
|
+
(table) => postgresBaseRecordIndexes(table, 'anonCredsCredentialDefinitionPrivate')
|
|
14
|
+
)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { sqliteTable, text } from 'drizzle-orm/sqlite-core'
|
|
2
|
+
import { getSqliteBaseRecordTable, sqliteBaseRecordIndexes } from '../../sqlite/baseRecord'
|
|
3
|
+
|
|
4
|
+
export const anonCredsCredentialDefinitionPrivate = sqliteTable(
|
|
5
|
+
'AnonCredsCredentialDefinitionPrivate',
|
|
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, 'anonCredsCredentialDefinitionPrivate')
|
|
14
|
+
)
|
package/src/anoncreds/key-correctness-proof/DrizzleAnonCredsKeyCorrectnessProofRecordAdapter.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { JsonTransformer, TagsBase } from '@credo-ts/core'
|
|
2
|
+
|
|
3
|
+
import { BaseDrizzleRecordAdapter, DrizzleAdapterRecordValues } from '../../adapter/BaseDrizzleRecordAdapter'
|
|
4
|
+
|
|
5
|
+
import { AnonCredsKeyCorrectnessProofRecord } from '@credo-ts/anoncreds'
|
|
6
|
+
import { DrizzleDatabase } from '../../DrizzleDatabase'
|
|
7
|
+
import * as postgres from './postgres'
|
|
8
|
+
import * as sqlite from './sqlite'
|
|
9
|
+
|
|
10
|
+
type DrizzleAnonCredsKeyCorrectnessProofAdapterValues = DrizzleAdapterRecordValues<
|
|
11
|
+
(typeof sqlite)['anonCredsKeyCorrectnessProof']
|
|
12
|
+
>
|
|
13
|
+
export class DrizzleAnonCredsKeyCorrectnessProofRecordAdapter extends BaseDrizzleRecordAdapter<
|
|
14
|
+
AnonCredsKeyCorrectnessProofRecord,
|
|
15
|
+
typeof postgres.anonCredsKeyCorrectnessProof,
|
|
16
|
+
typeof postgres,
|
|
17
|
+
typeof sqlite.anonCredsKeyCorrectnessProof,
|
|
18
|
+
typeof sqlite
|
|
19
|
+
> {
|
|
20
|
+
public constructor(database: DrizzleDatabase<typeof postgres, typeof sqlite>) {
|
|
21
|
+
super(
|
|
22
|
+
database,
|
|
23
|
+
{ postgres: postgres.anonCredsKeyCorrectnessProof, sqlite: sqlite.anonCredsKeyCorrectnessProof },
|
|
24
|
+
'AnonCredsKeyCorrectnessProofRecord'
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public getValues(record: AnonCredsKeyCorrectnessProofRecord) {
|
|
29
|
+
const { credentialDefinitionId, ...customTags } = record.getTags()
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
credentialDefinitionId,
|
|
33
|
+
value: record.value,
|
|
34
|
+
customTags,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public toRecord(values: DrizzleAnonCredsKeyCorrectnessProofAdapterValues): AnonCredsKeyCorrectnessProofRecord {
|
|
39
|
+
const { customTags, credentialDefinitionId, ...remainingValues } = values
|
|
40
|
+
|
|
41
|
+
const record = JsonTransformer.fromJSON(remainingValues, AnonCredsKeyCorrectnessProofRecord)
|
|
42
|
+
record.setTags({ ...customTags, credentialDefinitionId } as TagsBase)
|
|
43
|
+
|
|
44
|
+
return record
|
|
45
|
+
}
|
|
46
|
+
}
|