@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.
Files changed (184) hide show
  1. package/cli/drizzle.config.ts +1 -1
  2. package/cli-build/drizzle.config.js +1 -1
  3. package/cli-build/drizzle.config.js.map +1 -1
  4. package/package.json +18 -17
  5. package/src/DrizzleDatabase.ts +29 -0
  6. package/src/DrizzleRecord.ts +73 -0
  7. package/src/DrizzleStorageModule.ts +112 -0
  8. package/src/DrizzleStorageModuleConfig.ts +48 -0
  9. package/src/action-menu/action-menu/DrizzleDidcommActionMenuRecordAdapter.ts +46 -0
  10. package/src/action-menu/action-menu/index.ts +10 -0
  11. package/src/action-menu/action-menu/postgres.ts +31 -0
  12. package/src/action-menu/action-menu/sqlite.ts +34 -0
  13. package/src/action-menu/bundle.ts +18 -0
  14. package/src/action-menu/postgres.ts +1 -0
  15. package/src/action-menu/sqlite.ts +1 -0
  16. package/src/adapter/BaseDrizzleRecordAdapter.ts +319 -0
  17. package/src/adapter/__tests__/queryToDrizzlePostgres.drizzle.e2e.test.ts +330 -0
  18. package/src/adapter/__tests__/queryToDrizzleSqlite.test.ts +324 -0
  19. package/src/adapter/index.ts +6 -0
  20. package/src/adapter/queryToDrizzlePostgres.ts +217 -0
  21. package/src/adapter/queryToDrizzleSqlite.ts +213 -0
  22. package/src/anoncreds/bundle.ts +34 -0
  23. package/src/anoncreds/credential/DrizzleAnonCredsCredentialRecordAdapter.ts +93 -0
  24. package/src/anoncreds/credential/index.ts +10 -0
  25. package/src/anoncreds/credential/postgres.ts +27 -0
  26. package/src/anoncreds/credential/sqlite.ts +27 -0
  27. package/src/anoncreds/credential-definition/DrizzleAnonCredsCredentialDefinitionRecordAdapter.ts +72 -0
  28. package/src/anoncreds/credential-definition/index.ts +10 -0
  29. package/src/anoncreds/credential-definition/postgres.ts +23 -0
  30. package/src/anoncreds/credential-definition/sqlite.ts +23 -0
  31. package/src/anoncreds/credential-definition-private/DrizzleAnonCredsCredentialDefinitionPrivateRecordAdapter.ts +48 -0
  32. package/src/anoncreds/credential-definition-private/index.ts +10 -0
  33. package/src/anoncreds/credential-definition-private/postgres.ts +14 -0
  34. package/src/anoncreds/credential-definition-private/sqlite.ts +14 -0
  35. package/src/anoncreds/key-correctness-proof/DrizzleAnonCredsKeyCorrectnessProofRecordAdapter.ts +46 -0
  36. package/src/anoncreds/key-correctness-proof/index.ts +10 -0
  37. package/src/anoncreds/key-correctness-proof/postgres.ts +13 -0
  38. package/src/anoncreds/key-correctness-proof/sqlite.ts +14 -0
  39. package/src/anoncreds/link-secret/DrizzleAnonCredsLinkSecretRecordAdapter.ts +45 -0
  40. package/src/anoncreds/link-secret/index.ts +10 -0
  41. package/src/anoncreds/link-secret/postgres.ts +18 -0
  42. package/src/anoncreds/link-secret/sqlite.ts +18 -0
  43. package/src/anoncreds/postgres.ts +8 -0
  44. package/src/anoncreds/revocation-registry-definition/DrizzleAnonCredsRevocationRegistryDefinitionRecordAdapter.ts +52 -0
  45. package/src/anoncreds/revocation-registry-definition/index.ts +10 -0
  46. package/src/anoncreds/revocation-registry-definition/postgres.ts +18 -0
  47. package/src/anoncreds/revocation-registry-definition/sqlite.ts +20 -0
  48. package/src/anoncreds/revocation-registry-definition-private/DrizzleAnonCredsRevocationRegistryDefinitionPrivateRecordAdapter.ts +53 -0
  49. package/src/anoncreds/revocation-registry-definition-private/index.ts +10 -0
  50. package/src/anoncreds/revocation-registry-definition-private/postgres.ts +22 -0
  51. package/src/anoncreds/revocation-registry-definition-private/sqlite.ts +18 -0
  52. package/src/anoncreds/schema/DrizzleAnonCredsSchemaRecordAdapter.ts +54 -0
  53. package/src/anoncreds/schema/__tests__/schema.drizzle.e2e.test.ts +70 -0
  54. package/src/anoncreds/schema/index.ts +10 -0
  55. package/src/anoncreds/schema/postgres.ts +22 -0
  56. package/src/anoncreds/schema/sqlite.ts +22 -0
  57. package/src/anoncreds/sqlite.ts +8 -0
  58. package/src/applyReactNativeMigrations.ts +24 -0
  59. package/src/combineSchemas.ts +44 -0
  60. package/src/core/bundle.ts +33 -0
  61. package/src/core/context/index.ts +8 -0
  62. package/src/core/context/postgres.ts +5 -0
  63. package/src/core/context/sqlite.ts +5 -0
  64. package/src/core/did/DrizzleDidRecordAdapter.ts +71 -0
  65. package/src/core/did/index.ts +10 -0
  66. package/src/core/did/postgres.ts +28 -0
  67. package/src/core/did/sqlite.ts +26 -0
  68. package/src/core/genericRecord/DrizzleGenericRecordAdapter.ts +36 -0
  69. package/src/core/genericRecord/index.ts +10 -0
  70. package/src/core/genericRecord/postgres.ts +12 -0
  71. package/src/core/genericRecord/sqlite.ts +12 -0
  72. package/src/core/mdoc/DrizzleMdocRecordAdapter.ts +44 -0
  73. package/src/core/mdoc/index.ts +10 -0
  74. package/src/core/mdoc/postgres.ts +15 -0
  75. package/src/core/mdoc/sqlite.ts +15 -0
  76. package/src/core/postgres.ts +8 -0
  77. package/src/core/sdJwtVc/DrizzleSdJwtVcRecordAdapter.ts +46 -0
  78. package/src/core/sdJwtVc/index.ts +10 -0
  79. package/src/core/sdJwtVc/postgres.ts +17 -0
  80. package/src/core/sdJwtVc/sqlite.ts +17 -0
  81. package/src/core/singleContextLruCache/DrizzleSingleContextLruCacheRecordAdapter.ts +43 -0
  82. package/src/core/singleContextLruCache/index.ts +10 -0
  83. package/src/core/singleContextLruCache/postgres.ts +12 -0
  84. package/src/core/singleContextLruCache/sqlite.ts +13 -0
  85. package/src/core/sqlite.ts +8 -0
  86. package/src/core/storageVersion/DrizzleStorageVersionRecordAdapter.ts +36 -0
  87. package/src/core/storageVersion/index.ts +10 -0
  88. package/src/core/storageVersion/postgres.ts +13 -0
  89. package/src/core/storageVersion/sqlite.ts +13 -0
  90. package/src/core/w3cCredential/DrizzleW3cCredentialRecordAdapter.ts +95 -0
  91. package/src/core/w3cCredential/index.ts +10 -0
  92. package/src/core/w3cCredential/postgres.ts +31 -0
  93. package/src/core/w3cCredential/sqlite.ts +29 -0
  94. package/src/didcomm/basic-message/DrizzleDidcommBasicMessageRecordAdapter.ts +54 -0
  95. package/src/didcomm/basic-message/index.ts +10 -0
  96. package/src/didcomm/basic-message/postgres.ts +30 -0
  97. package/src/didcomm/basic-message/sqlite.ts +29 -0
  98. package/src/didcomm/bundle.ts +34 -0
  99. package/src/didcomm/connection/DrizzleDidcommConnectionRecordAdapter.ts +70 -0
  100. package/src/didcomm/connection/index.ts +10 -0
  101. package/src/didcomm/connection/postgres.ts +55 -0
  102. package/src/didcomm/connection/sqlite.ts +39 -0
  103. package/src/didcomm/credential-exchange/DrizzleDidcommCredentialExchangeRecordAdapter.ts +64 -0
  104. package/src/didcomm/credential-exchange/__tests__/credentialExchange.drizzle.e2e.test.ts +104 -0
  105. package/src/didcomm/credential-exchange/index.ts +10 -0
  106. package/src/didcomm/credential-exchange/postgres.ts +45 -0
  107. package/src/didcomm/credential-exchange/sqlite.ts +39 -0
  108. package/src/didcomm/didcomm-message/DrizzleDidcommMessageRecordAdapter.ts +75 -0
  109. package/src/didcomm/didcomm-message/index.ts +10 -0
  110. package/src/didcomm/didcomm-message/postgres.ts +27 -0
  111. package/src/didcomm/didcomm-message/sqlite.ts +26 -0
  112. package/src/didcomm/mediation/DrizzleDidcommMediationRecordAdapter.ts +51 -0
  113. package/src/didcomm/mediation/index.ts +10 -0
  114. package/src/didcomm/mediation/postgres.ts +33 -0
  115. package/src/didcomm/mediation/sqlite.ts +31 -0
  116. package/src/didcomm/mediator-routing/DrizzleDidcommMediatorRoutingRecordAdapter.ts +49 -0
  117. package/src/didcomm/mediator-routing/index.ts +10 -0
  118. package/src/didcomm/mediator-routing/postgres.ts +14 -0
  119. package/src/didcomm/mediator-routing/sqlite.ts +17 -0
  120. package/src/didcomm/out-of-band/DrizzleDidcommOutOfBandRecordAdapter.ts +85 -0
  121. package/src/didcomm/out-of-band/__tests__/outOfBand.drizzle.e2e.test.ts +88 -0
  122. package/src/didcomm/out-of-band/index.ts +10 -0
  123. package/src/didcomm/out-of-band/postgres.ts +46 -0
  124. package/src/didcomm/out-of-band/sqlite.ts +46 -0
  125. package/src/didcomm/postgres.ts +8 -0
  126. package/src/didcomm/proof-exchange/DrizzleDidcommProofExchangeRecordAdapter.ts +51 -0
  127. package/src/didcomm/proof-exchange/index.ts +10 -0
  128. package/src/didcomm/proof-exchange/postgres.ts +33 -0
  129. package/src/didcomm/proof-exchange/sqlite.ts +29 -0
  130. package/src/didcomm/sqlite.ts +8 -0
  131. package/src/drpc/bundle.ts +18 -0
  132. package/src/drpc/drpc/DrizzleDidcommDrpcRecordAdapter.ts +44 -0
  133. package/src/drpc/drpc/index.ts +10 -0
  134. package/src/drpc/drpc/postgres.ts +31 -0
  135. package/src/drpc/drpc/sqlite.ts +29 -0
  136. package/src/drpc/postgres.ts +1 -0
  137. package/src/drpc/sqlite.ts +1 -0
  138. package/src/error/CredoDrizzleColumnDoesNotExistError.ts +21 -0
  139. package/src/error/CredoDrizzleStorageError.ts +7 -0
  140. package/src/error/index.ts +2 -0
  141. package/src/index.ts +29 -0
  142. package/src/openid4vc/bundle.ts +26 -0
  143. package/src/openid4vc/openid4vc-issuance-session/DrizzleOpenId4VcIssuanceSessionRecordAdapter.ts +90 -0
  144. package/src/openid4vc/openid4vc-issuance-session/index.ts +10 -0
  145. package/src/openid4vc/openid4vc-issuance-session/postgres.ts +54 -0
  146. package/src/openid4vc/openid4vc-issuance-session/sqlite.ts +54 -0
  147. package/src/openid4vc/openid4vc-issuer/DrizzleOpenid4vcIssuerRecordAdapter.ts +50 -0
  148. package/src/openid4vc/openid4vc-issuer/index.ts +10 -0
  149. package/src/openid4vc/openid4vc-issuer/postgres.ts +31 -0
  150. package/src/openid4vc/openid4vc-issuer/sqlite.ts +40 -0
  151. package/src/openid4vc/openid4vc-verification-session/DrizzleOpenId4VcVerificationSessionRecordAdapter.ts +62 -0
  152. package/src/openid4vc/openid4vc-verification-session/index.ts +10 -0
  153. package/src/openid4vc/openid4vc-verification-session/postgres.ts +46 -0
  154. package/src/openid4vc/openid4vc-verification-session/sqlite.ts +40 -0
  155. package/src/openid4vc/openid4vc-verifier/DrizzleOpenid4vcVerifierRecordAdapter.ts +43 -0
  156. package/src/openid4vc/openid4vc-verifier/index.ts +10 -0
  157. package/src/openid4vc/openid4vc-verifier/postgres.ts +14 -0
  158. package/src/openid4vc/openid4vc-verifier/sqlite.ts +19 -0
  159. package/src/openid4vc/postgres.ts +4 -0
  160. package/src/openid4vc/sqlite.ts +4 -0
  161. package/src/postgres/baseRecord.ts +44 -0
  162. package/src/postgres/index.ts +1 -0
  163. package/src/question-answer/bundle.ts +18 -0
  164. package/src/question-answer/postgres.ts +1 -0
  165. package/src/question-answer/question-answer/DrizzleDidcommQuestionAnswerRecordAdapter.ts +52 -0
  166. package/src/question-answer/question-answer/index.ts +10 -0
  167. package/src/question-answer/question-answer/postgres.ts +34 -0
  168. package/src/question-answer/question-answer/sqlite.ts +32 -0
  169. package/src/question-answer/sqlite.ts +1 -0
  170. package/src/sqlite/baseRecord.ts +38 -0
  171. package/src/sqlite/index.ts +1 -0
  172. package/src/storage/DrizzleStorageService.ts +87 -0
  173. package/src/storage/index.ts +1 -0
  174. package/src/tenants/bundle.ts +19 -0
  175. package/src/tenants/postgres.ts +2 -0
  176. package/src/tenants/sqlite.ts +2 -0
  177. package/src/tenants/tenant/DrizzleTenantRecordAdapter.ts +45 -0
  178. package/src/tenants/tenant/index.ts +10 -0
  179. package/src/tenants/tenant/postgres.ts +16 -0
  180. package/src/tenants/tenant/sqlite.ts +16 -0
  181. package/src/tenants/tenant-routing/DrizzleTenantRoutingRecordAdapter.ts +44 -0
  182. package/src/tenants/tenant-routing/index.ts +10 -0
  183. package/src/tenants/tenant-routing/postgres.ts +20 -0
  184. package/src/tenants/tenant-routing/sqlite.ts +20 -0
@@ -48,7 +48,7 @@ if (drizzleDialect === 'sqlite') {
48
48
  dbCredentials: { url: drizzleDatabaseUrl },
49
49
  }
50
50
  : {
51
- driver: 'pglite',
51
+ driver: 'node-postgres',
52
52
  }),
53
53
  })
54
54
  }
@@ -46,7 +46,7 @@ else {
46
46
  dbCredentials: { url: drizzleDatabaseUrl },
47
47
  }
48
48
  : {
49
- driver: 'pglite',
49
+ driver: 'node-postgres',
50
50
  }),
51
51
  });
52
52
  }
@@ -1 +1 @@
1
- {"version":3,"file":"drizzle.config.js","sourceRoot":"","sources":["../cli/drizzle.config.ts"],"names":[],"mappings":";;AAAA,6CAAkD;AAElD,MAAM,kBAAkB,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAA;AAE3D,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAA;AAClD,IAAI,CAAC,cAAc,IAAI,CAAC,cAAc,KAAK,QAAQ,IAAI,cAAc,KAAK,UAAU,CAAC,EAAE,CAAC;IACtF,MAAM,IAAI,KAAK,CAAC,gFAAgF,CAAC,CAAA;AACnG,CAAC;AAED,MAAM,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAA;AACzD,MAAM,uBAAuB,GAAG,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAA;AACrE,MAAM,sBAAsB,GAAG,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAA;AAEnE,IAAI,aAAqB,CAAA;AAEzB,IAAI,cAAc,KAAK,QAAQ,EAAE,CAAC;IAChC,aAAa,GAAG,IAAA,0BAAY,EAAC;QAC3B,OAAO,EAAE,cAAc;QACvB,gFAAgF;QAChF,gEAAgE;QAChE,MAAM,EAAE,iBAAiB;QACzB,GAAG,EAAE,uBAAuB;QAC5B,UAAU,EAAE,sBAAsB;YAChC,CAAC,CAAC;gBACE,KAAK,EAAE,sBAAsB;aAC9B;YACH,CAAC,CAAC,SAAS;QACb,GAAG,CAAC,kBAAkB;YACpB,CAAC,CAAC;gBACE,aAAa,EAAE,EAAE,GAAG,EAAE,kBAAkB,EAAE;aAC3C;YACH,CAAC,CAAC;gBACE,MAAM,EAAE,MAAM;aACf,CAAC;KACP,CAAC,CAAA;AACJ,CAAC;KAAM,CAAC;IACN,aAAa,GAAG,IAAA,0BAAY,EAAC;QAC3B,OAAO,EAAE,YAAY;QACrB,MAAM,EAAE,iBAAiB;QACzB,GAAG,EAAE,uBAAuB;QAC5B,UAAU,EAAE,sBAAsB;YAChC,CAAC,CAAC;gBACE,KAAK,EAAE,sBAAsB;aAC9B;YACH,CAAC,CAAC,SAAS;QACb,GAAG,CAAC,kBAAkB;YACpB,CAAC,CAAC;gBACE,aAAa,EAAE,EAAE,GAAG,EAAE,kBAAkB,EAAE;aAC3C;YACH,CAAC,CAAC;gBACE,MAAM,EAAE,QAAQ;aACjB,CAAC;KACP,CAAC,CAAA;AACJ,CAAC;AAED,kBAAe,aAAa,CAAA"}
1
+ {"version":3,"file":"drizzle.config.js","sourceRoot":"","sources":["../cli/drizzle.config.ts"],"names":[],"mappings":";;AAAA,6CAAkD;AAElD,MAAM,kBAAkB,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAA;AAE3D,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAA;AAClD,IAAI,CAAC,cAAc,IAAI,CAAC,cAAc,KAAK,QAAQ,IAAI,cAAc,KAAK,UAAU,CAAC,EAAE,CAAC;IACtF,MAAM,IAAI,KAAK,CAAC,gFAAgF,CAAC,CAAA;AACnG,CAAC;AAED,MAAM,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAA;AACzD,MAAM,uBAAuB,GAAG,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAA;AACrE,MAAM,sBAAsB,GAAG,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAA;AAEnE,IAAI,aAAqB,CAAA;AAEzB,IAAI,cAAc,KAAK,QAAQ,EAAE,CAAC;IAChC,aAAa,GAAG,IAAA,0BAAY,EAAC;QAC3B,OAAO,EAAE,cAAc;QACvB,gFAAgF;QAChF,gEAAgE;QAChE,MAAM,EAAE,iBAAiB;QACzB,GAAG,EAAE,uBAAuB;QAC5B,UAAU,EAAE,sBAAsB;YAChC,CAAC,CAAC;gBACE,KAAK,EAAE,sBAAsB;aAC9B;YACH,CAAC,CAAC,SAAS;QACb,GAAG,CAAC,kBAAkB;YACpB,CAAC,CAAC;gBACE,aAAa,EAAE,EAAE,GAAG,EAAE,kBAAkB,EAAE;aAC3C;YACH,CAAC,CAAC;gBACE,MAAM,EAAE,MAAM;aACf,CAAC;KACP,CAAC,CAAA;AACJ,CAAC;KAAM,CAAC;IACN,aAAa,GAAG,IAAA,0BAAY,EAAC;QAC3B,OAAO,EAAE,YAAY;QACrB,MAAM,EAAE,iBAAiB;QACzB,GAAG,EAAE,uBAAuB;QAC5B,UAAU,EAAE,sBAAsB;YAChC,CAAC,CAAC;gBACE,KAAK,EAAE,sBAAsB;aAC9B;YACH,CAAC,CAAC,SAAS;QACb,GAAG,CAAC,kBAAkB;YACpB,CAAC,CAAC;gBACE,aAAa,EAAE,EAAE,GAAG,EAAE,kBAAkB,EAAE;aAC3C;YACH,CAAC,CAAC;gBACE,MAAM,EAAE,eAAe;aACxB,CAAC;KACP,CAAC,CAAA;AACJ,CAAC;AAED,kBAAe,aAAa,CAAA"}
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@credo-ts/drizzle-storage",
3
- "version": "0.6.0-pr-2324-20250708122805",
3
+ "version": "0.6.0-pr-2324-20250709075226",
4
4
  "files": [
5
5
  "build",
6
6
  "cli-build",
7
7
  "migrations",
8
8
  "tsconfig.json",
9
9
  "types",
10
- "cli/drizzle.config.ts"
10
+ "cli/drizzle.config.ts",
11
+ "src"
11
12
  ],
12
13
  "license": "Apache-2.0",
13
14
  "description": "Credo storage service implementation based on Drizzle ORM, supporting PostgreSQL and SQLite",
@@ -21,12 +22,12 @@
21
22
  "default": "./build/index.js"
22
23
  },
23
24
  "./*/sqlite": {
24
- "types": "./build/*/sqlite.d.ts",
25
- "default": "./build/*/sqlite.ts"
25
+ "default": "./build/*/sqlite.js",
26
+ "types": "./build/*/sqlite.d.ts"
26
27
  },
27
28
  "./*/postgres": {
28
- "types": "./build/*/postgres.d.ts",
29
- "default": "./build/*/postgres.ts"
29
+ "default": "./build/*/postgres.js",
30
+ "types": "./build/*/postgres.d.ts"
30
31
  },
31
32
  "./*": {
32
33
  "default": "./build/*/bundle.js",
@@ -51,24 +52,24 @@
51
52
  "ts-node": "^10.9.2",
52
53
  "tsyringe": "^4.8.0",
53
54
  "zod": "^3.24.2",
54
- "@credo-ts/action-menu": "0.6.0-pr-2324-20250708122805",
55
- "@credo-ts/anoncreds": "0.6.0-pr-2324-20250708122805",
56
- "@credo-ts/core": "0.6.0-pr-2324-20250708122805",
57
- "@credo-ts/didcomm": "0.6.0-pr-2324-20250708122805",
58
- "@credo-ts/drpc": "0.6.0-pr-2324-20250708122805",
59
- "@credo-ts/openid4vc": "0.6.0-pr-2324-20250708122805",
60
- "@credo-ts/question-answer": "0.6.0-pr-2324-20250708122805",
61
- "@credo-ts/tenants": "0.6.0-pr-2324-20250708122805"
55
+ "@credo-ts/action-menu": "0.6.0-pr-2324-20250709075226",
56
+ "@credo-ts/anoncreds": "0.6.0-pr-2324-20250709075226",
57
+ "@credo-ts/core": "0.6.0-pr-2324-20250709075226",
58
+ "@credo-ts/didcomm": "0.6.0-pr-2324-20250709075226",
59
+ "@credo-ts/drpc": "0.6.0-pr-2324-20250709075226",
60
+ "@credo-ts/openid4vc": "0.6.0-pr-2324-20250709075226",
61
+ "@credo-ts/question-answer": "0.6.0-pr-2324-20250709075226",
62
+ "@credo-ts/tenants": "0.6.0-pr-2324-20250709075226"
62
63
  },
63
64
  "peerDependencies": {
64
65
  "drizzle-orm": "^0.44.2"
65
66
  },
66
67
  "devDependencies": {
67
- "@electric-sql/pglite": "^0.3.1",
68
68
  "@libsql/client": "^0.15.6",
69
+ "@types/pg": "^8.15.4",
69
70
  "@types/yargs": "^17.0.33",
70
- "pg": "^8.16.3",
71
71
  "drizzle-orm": "^0.44.2",
72
+ "pg": "^8.16.3",
72
73
  "rimraf": "^4.4.0",
73
74
  "typescript": "~5.5.2"
74
75
  },
@@ -83,6 +84,6 @@
83
84
  "cli:dev:migrate:sqlite": "pnpm cli:dev migrate --dialect sqlite --database-url \"file:local.db\"",
84
85
  "cli:dev:studio:postgres": "pnpm cli:dev studio --dialect postgres --database-url \"postgresql://postgres:postgres@localhost:5432/postgres\"",
85
86
  "cli:dev:studio:sqlite": "pnpm cli:dev studio --dialect sqlite --database-url \"file:local.db\"",
86
- "test": "NODE_OPTIONS=--experimental-vm-modules jest"
87
+ "test": "jest"
87
88
  }
88
89
  }
@@ -0,0 +1,29 @@
1
+ import { PgDatabase } from 'drizzle-orm/pg-core'
2
+ import { BaseSQLiteDatabase } from 'drizzle-orm/sqlite-core'
3
+
4
+ export type DrizzleSqliteDatabase<Schema extends Record<string, unknown> = Record<string, unknown>> =
5
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
6
+ BaseSQLiteDatabase<'sync' | 'async', any, Schema>
7
+
8
+ export type DrizzlePostgresDatabase<Schema extends Record<string, unknown> = Record<string, unknown>> = PgDatabase<
9
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
10
+ any,
11
+ Schema
12
+ >
13
+
14
+ export type DrizzleDatabase<
15
+ PostgresSchema extends Record<string, unknown> = Record<string, unknown>,
16
+ SqliteSchema extends Record<string, unknown> = Record<string, unknown>,
17
+ > = DrizzlePostgresDatabase<PostgresSchema> | DrizzleSqliteDatabase<SqliteSchema>
18
+
19
+ export function isDrizzlePostgresDatabase(database: DrizzleDatabase): database is DrizzlePostgresDatabase {
20
+ return database instanceof PgDatabase
21
+ }
22
+
23
+ export function isDrizzleSqliteDatabase(database: DrizzleDatabase): database is DrizzleSqliteDatabase {
24
+ return database instanceof BaseSQLiteDatabase
25
+ }
26
+
27
+ export function getDrizzleDatabaseType(database: DrizzleDatabase): 'sqlite' | 'postgres' {
28
+ return isDrizzlePostgresDatabase(database) ? 'postgres' : 'sqlite'
29
+ }
@@ -0,0 +1,73 @@
1
+ import { AnyDrizzleAdapter } from './adapter/BaseDrizzleRecordAdapter'
2
+
3
+ export interface DrizzleRecordBundle {
4
+ /**
5
+ * The name of the drizzle record bundle. Ideally it should be simple but unique.
6
+ *
7
+ * E.g. `core` or `anoncreds` for internal modules. For custom modules we recommend
8
+ * prefixing a scope. E.g. `my-org-custom-protocol`
9
+ */
10
+ name: string
11
+
12
+ /**
13
+ * The drizzle records part of this bundle. This should stay consistent, as migrations are
14
+ * managed per drizzle record bundle. Removing migrations or records can result in data loss
15
+ * or locked databases.
16
+ */
17
+ records: DrizzleRecord[]
18
+
19
+ /**
20
+ * Information related to generationg and applying migrations
21
+ */
22
+ migrations: {
23
+ sqlite: {
24
+ /**
25
+ * A resolvable module that contains the drizzle SQLite schema definition for the complete bundle.
26
+ *
27
+ * NOTE: this MUST resolve to the TypeScript schema file, it cannot point to the built files. This
28
+ * file will only be resolved during generation of migrations, and thus it's not needed to publish
29
+ * the source files in your NPM package, as long as the module resolves during migration generation.
30
+ */
31
+ schemaModule: string
32
+
33
+ /**
34
+ * The migrations path where the migrations should be generated and retrieved. Note that the contents
35
+ * of this directory must be published with your NPM package so it can be used to apply migrations.
36
+ *
37
+ * The path should be relative to the resolved `schemaModule`. Note that if you use `publishConfig` to
38
+ * have different exports during development, this should still resolve to the generated migration files
39
+ * in the generated packages, so it's recommended to place your migrations outside of the src folder
40
+ */
41
+ migrationsPath: string
42
+ }
43
+ postgres: {
44
+ /**
45
+ * A resolvable module that contains the drizzle SQLite schema definition for the complete bundle.
46
+ *
47
+ * NOTE: this MUST resolve to the TypeScript schema file, it cannot point to the built files. This
48
+ * file will only be resolved during generation of migrations, and thus it's not needed to publish
49
+ * the source files in your NPM package, as long as the module resolves during migration generation.
50
+ */
51
+ schemaModule: string
52
+
53
+ /**
54
+ * The migrations path where the migrations should be generated and retrieved. Note that the contents
55
+ * of this directory must be published with your NPM package so it can be used to apply migrations.
56
+ *
57
+ * The path should be relative to the resolved `schemaModule`. Note that if you use `publishConfig` to
58
+ * have different exports during development, this should still resolve to the generated migration files
59
+ * in the generated packages, so it's recommended to place your migrations outside of the src folder
60
+ */
61
+ migrationsPath: string
62
+ }
63
+ }
64
+ }
65
+
66
+ export interface DrizzleRecord {
67
+ postgres: Record<string, unknown>
68
+ sqlite: Record<string, unknown>
69
+ adapter?: new (
70
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
71
+ database: any
72
+ ) => AnyDrizzleAdapter
73
+ }
@@ -0,0 +1,112 @@
1
+ import type { AgentContext, DependencyManager, Module } from '@credo-ts/core'
2
+ import type { DrizzleStorageModuleConfigOptions } from './DrizzleStorageModuleConfig'
3
+
4
+ import { CredoError, InjectionSymbols, StorageUpdateService } from '@credo-ts/core'
5
+
6
+ import { eq } from 'drizzle-orm'
7
+ import { isDrizzlePostgresDatabase, isDrizzleSqliteDatabase } from './DrizzleDatabase'
8
+ import { DrizzleStorageModuleConfig } from './DrizzleStorageModuleConfig'
9
+ import { context as postgresContext } from './core/postgres'
10
+ import { context as sqliteContext } from './core/sqlite'
11
+ import { CredoDrizzleStorageError } from './error'
12
+ import { DrizzleStorageService } from './storage'
13
+
14
+ export class DrizzleStorageModule implements Module {
15
+ public readonly config: DrizzleStorageModuleConfig
16
+
17
+ public constructor(config: DrizzleStorageModuleConfigOptions) {
18
+ this.config = new DrizzleStorageModuleConfig(config)
19
+ }
20
+
21
+ public register(dependencyManager: DependencyManager) {
22
+ dependencyManager.registerInstance(DrizzleStorageModuleConfig, this.config)
23
+
24
+ if (dependencyManager.isRegistered(InjectionSymbols.StorageService)) {
25
+ throw new CredoError(
26
+ 'Unable to register DrizzleStorageService. There is an instance of StorageService already registered'
27
+ )
28
+ }
29
+ dependencyManager.registerSingleton(InjectionSymbols.StorageService, DrizzleStorageService)
30
+ }
31
+
32
+ public async onInitializeContext(agentContext: AgentContext): Promise<void> {
33
+ // For the root agent context we don't call provision, we should probably change that
34
+ // but this is because agent.initialize doesn't differantiate between create and open
35
+ // So we need to check basically when we start the agent if this is a new agent
36
+ // and if so, set the framework storage version. This is a bit inefficient, as we will
37
+ // again fetch the record after the module has been initialized, but probably something
38
+ // we can improve with caching.
39
+ if (agentContext.isRootAgentContext) {
40
+ const storageUpdateService = agentContext.resolve(StorageUpdateService)
41
+
42
+ // Previously if we didn't have a storage version record yet it meant we assumed you
43
+ // were on 0.1 before the record was added, but since this module is introduced in 0.6
44
+ // we can be sure that's not the case.
45
+ if (!(await storageUpdateService.hasStorageVersionRecord(agentContext))) {
46
+ await this.createNewContextInDatabase(agentContext)
47
+ }
48
+ }
49
+ }
50
+
51
+ public async onProvisionContext(agentContext: AgentContext): Promise<void> {
52
+ // This method is never called for root agent context
53
+ // but to be sure if that changesin the future
54
+ if (agentContext.isRootAgentContext) return
55
+
56
+ await this.createNewContextInDatabase(agentContext)
57
+ }
58
+
59
+ public async onDeleteContext(agentContext: AgentContext): Promise<void> {
60
+ // If it's the root agent context, we want to delete all the tenants as well
61
+ if (agentContext.isRootAgentContext) {
62
+ // Do we want to allow this? It can be quite impactfull
63
+ await this.deleteContextQuery()
64
+ } else {
65
+ await this.deleteContextQuery().where(eq(sqliteContext.contextCorrelationId, agentContext.contextCorrelationId))
66
+ }
67
+ }
68
+
69
+ private deleteContextQuery() {
70
+ // TODO: we could probably add some extra abstraction here.
71
+ if (isDrizzlePostgresDatabase(this.config.database)) {
72
+ return this.config.database.delete(postgresContext)
73
+ }
74
+
75
+ if (isDrizzleSqliteDatabase(this.config.database)) {
76
+ return this.config.database.delete(sqliteContext)
77
+ }
78
+
79
+ throw new CredoDrizzleStorageError(
80
+ 'Unable to delete context. Database must be instance of postgres or sqlite database.'
81
+ )
82
+ }
83
+
84
+ private async createNewContextInDatabase(agentContext: AgentContext) {
85
+ // For new contexts, we need to set the storage version
86
+ const storageUpdateService = agentContext.resolve(StorageUpdateService)
87
+
88
+ if (isDrizzlePostgresDatabase(this.config.database)) {
89
+ // Create a new context record. This is mostly used to allow deleting a context and
90
+ // cascade delete all other records.
91
+ await this.config.database
92
+ .insert(postgresContext)
93
+ .values({
94
+ contextCorrelationId: agentContext.contextCorrelationId,
95
+ })
96
+ .onConflictDoNothing()
97
+ } else if (isDrizzleSqliteDatabase(this.config.database)) {
98
+ await this.config.database
99
+ .insert(sqliteContext)
100
+ .values({
101
+ contextCorrelationId: agentContext.contextCorrelationId,
102
+ })
103
+ .onConflictDoNothing()
104
+ } else {
105
+ throw new CredoDrizzleStorageError(
106
+ 'Unable to provision context. Database must be instance of postgres or sqlite database.'
107
+ )
108
+ }
109
+
110
+ await storageUpdateService.setCurrentStorageVersion(agentContext, StorageUpdateService.frameworkStorageVersion)
111
+ }
112
+ }
@@ -0,0 +1,48 @@
1
+ import { DrizzleDatabase, getDrizzleDatabaseType } from './DrizzleDatabase'
2
+ import { DrizzleRecord, DrizzleRecordBundle } from './DrizzleRecord'
3
+ import { AnyDrizzleAdapter } from './adapter/BaseDrizzleRecordAdapter'
4
+ import { getSchemaFromDrizzleRecords } from './combineSchemas'
5
+ import coreDrizzleBundle from './core/bundle'
6
+
7
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
8
+ export type AnyDrizzleDatabase = DrizzleDatabase<any, any>
9
+
10
+ export interface DrizzleStorageModuleConfigOptions<Database extends AnyDrizzleDatabase = AnyDrizzleDatabase> {
11
+ /**
12
+ * The drizzle database to use. To not depend on specific drivers and support different
13
+ * environments you need to configure the database yourself.
14
+ *
15
+ * See https://orm.drizzle.team/docs/get-started for available drivers.
16
+ * All SQLite and Postgres database are supported.
17
+ */
18
+ database: Database
19
+
20
+ /**
21
+ * The drizzle bundles to register. Each drizzle bundles consists of records, which need to contain both an
22
+ * sqlite and postgres definition, as well as an adapter.
23
+ */
24
+ bundles: DrizzleRecordBundle[]
25
+ }
26
+
27
+ /**
28
+ * @public
29
+ */
30
+ export class DrizzleStorageModuleConfig {
31
+ public readonly database: AnyDrizzleDatabase
32
+ public readonly adapters: AnyDrizzleAdapter[]
33
+ public readonly schemas: Record<string, unknown>
34
+
35
+ public constructor(options: DrizzleStorageModuleConfigOptions) {
36
+ this.database = options.database
37
+
38
+ // core MUST always be registered
39
+ const allRecords: DrizzleRecord[] = Array.from(
40
+ new Set([...coreDrizzleBundle.records, ...options.bundles.flatMap((bundle) => bundle.records)])
41
+ )
42
+ this.adapters = allRecords
43
+ .map((record) => (record.adapter ? new record.adapter(this.database) : undefined))
44
+ .filter((adapter) => adapter !== undefined)
45
+
46
+ this.schemas = getSchemaFromDrizzleRecords(allRecords, getDrizzleDatabaseType(options.database))
47
+ }
48
+ }
@@ -0,0 +1,46 @@
1
+ import { JsonTransformer, TagsBase } from '@credo-ts/core'
2
+
3
+ import { BaseDrizzleRecordAdapter, DrizzleAdapterRecordValues } from '../../adapter/BaseDrizzleRecordAdapter'
4
+
5
+ import { ActionMenuOptions, ActionMenuRecord, ActionMenuSelectionOptions } from '@credo-ts/action-menu'
6
+ import { DrizzleDatabase } from '../../DrizzleDatabase'
7
+ import * as postgres from './postgres'
8
+ import * as sqlite from './sqlite'
9
+
10
+ type DrizzleDidcommActionMenuAdapterValues = DrizzleAdapterRecordValues<(typeof sqlite)['didcommActionMenu']>
11
+ export class DrizzleDidcommActionMenuRecordAdapter extends BaseDrizzleRecordAdapter<
12
+ ActionMenuRecord,
13
+ typeof postgres.didcommActionMenu,
14
+ typeof postgres,
15
+ typeof sqlite.didcommActionMenu,
16
+ typeof sqlite
17
+ > {
18
+ public constructor(database: DrizzleDatabase<typeof postgres, typeof sqlite>) {
19
+ super(database, { postgres: postgres.didcommActionMenu, sqlite: sqlite.didcommActionMenu }, 'ActionMenuRecord')
20
+ }
21
+
22
+ public getValues(record: ActionMenuRecord) {
23
+ const { role, connectionId, threadId, ...customTags } = record.getTags()
24
+
25
+ return {
26
+ role,
27
+ threadId,
28
+ connectionId,
29
+ state: record.state,
30
+ menu: record.menu ? (JsonTransformer.toJSON(record.menu) as ActionMenuOptions) : null,
31
+ performedAction: record.performedAction
32
+ ? (JsonTransformer.toJSON(record.performedAction) as ActionMenuSelectionOptions)
33
+ : null,
34
+ customTags,
35
+ }
36
+ }
37
+
38
+ public toRecord(values: DrizzleDidcommActionMenuAdapterValues): ActionMenuRecord {
39
+ const { customTags, ...remainingValues } = values
40
+
41
+ const record = JsonTransformer.fromJSON(remainingValues, ActionMenuRecord)
42
+ if (customTags) record.setTags(customTags as TagsBase)
43
+
44
+ return record
45
+ }
46
+ }
@@ -0,0 +1,10 @@
1
+ import { DrizzleRecord } from '../../DrizzleRecord'
2
+ import { DrizzleDidcommActionMenuRecordAdapter } from './DrizzleDidcommActionMenuRecordAdapter'
3
+ import * as postgres from './postgres'
4
+ import * as sqlite from './sqlite'
5
+
6
+ export const didcommActionMenuDrizzleRecord = {
7
+ adapter: DrizzleDidcommActionMenuRecordAdapter,
8
+ postgres,
9
+ sqlite,
10
+ } satisfies DrizzleRecord
@@ -0,0 +1,31 @@
1
+ import { ActionMenuOptions, ActionMenuRole, ActionMenuSelectionOptions, ActionMenuState } from '@credo-ts/action-menu'
2
+ import { foreignKey, jsonb, pgEnum, pgTable, text, unique } from 'drizzle-orm/pg-core'
3
+ import { didcommConnection } from '../../didcomm/connection/postgres'
4
+ import { getPostgresBaseRecordTable, postgresBaseRecordIndexes } from '../../postgres/baseRecord'
5
+
6
+ export const didcommActionMenuStateEnum = pgEnum('DidcommActionMenuState', ActionMenuState)
7
+ export const didcommActionMenuRoleEnum = pgEnum('DidcommActionMenuRole', ActionMenuRole)
8
+
9
+ export const didcommActionMenu = pgTable(
10
+ 'DidcommActionMenu',
11
+ {
12
+ ...getPostgresBaseRecordTable(),
13
+
14
+ state: didcommActionMenuStateEnum().notNull(),
15
+ role: didcommActionMenuRoleEnum().notNull(),
16
+
17
+ connectionId: text('connection_id').notNull(),
18
+ threadId: text('thread_id').notNull(),
19
+
20
+ menu: jsonb('menu').$type<ActionMenuOptions>(),
21
+ performedAction: jsonb('performed_action').$type<ActionMenuSelectionOptions>(),
22
+ },
23
+ (table) => [
24
+ ...postgresBaseRecordIndexes(table, 'didcommActionMenu'),
25
+ unique().on(table.contextCorrelationId, table.threadId),
26
+ foreignKey({
27
+ columns: [table.connectionId, table.contextCorrelationId],
28
+ foreignColumns: [didcommConnection.id, didcommConnection.contextCorrelationId],
29
+ }).onDelete('cascade'),
30
+ ]
31
+ )
@@ -0,0 +1,34 @@
1
+ import { foreignKey, sqliteTable, text, unique } from 'drizzle-orm/sqlite-core'
2
+
3
+ import type {
4
+ ActionMenuOptions,
5
+ ActionMenuRole,
6
+ ActionMenuSelectionOptions,
7
+ ActionMenuState,
8
+ } from '@credo-ts/action-menu'
9
+ import { didcommConnection } from '../../didcomm/connection/sqlite'
10
+ import { getSqliteBaseRecordTable, sqliteBaseRecordIndexes } from '../../sqlite/baseRecord'
11
+
12
+ export const didcommActionMenu = sqliteTable(
13
+ 'DidcommActionMenu',
14
+ {
15
+ ...getSqliteBaseRecordTable(),
16
+
17
+ state: text('state').$type<ActionMenuState>().notNull(),
18
+ role: text('role').$type<ActionMenuRole>().notNull(),
19
+
20
+ connectionId: text('connection_id').notNull(),
21
+ threadId: text('thread_id').notNull(),
22
+
23
+ menu: text('menu', { mode: 'json' }).$type<ActionMenuOptions>(),
24
+ performedAction: text('performed_action', { mode: 'json' }).$type<ActionMenuSelectionOptions>(),
25
+ },
26
+ (table) => [
27
+ ...sqliteBaseRecordIndexes(table, 'didcommActionMenu'),
28
+ unique().on(table.contextCorrelationId, table.threadId),
29
+ foreignKey({
30
+ columns: [table.connectionId, table.contextCorrelationId],
31
+ foreignColumns: [didcommConnection.id, didcommConnection.contextCorrelationId],
32
+ }).onDelete('cascade'),
33
+ ]
34
+ )
@@ -0,0 +1,18 @@
1
+ import { DrizzleRecordBundle } from '../DrizzleRecord'
2
+ import { didcommActionMenuDrizzleRecord } from './action-menu'
3
+
4
+ export default {
5
+ name: 'action-menu',
6
+ records: [didcommActionMenuDrizzleRecord],
7
+
8
+ migrations: {
9
+ postgres: {
10
+ schemaModule: '@credo-ts/drizzle-storage/action-menu/postgres',
11
+ migrationsPath: '../../migrations/action-menu/postgres',
12
+ },
13
+ sqlite: {
14
+ schemaModule: '@credo-ts/drizzle-storage/action-menu/sqlite',
15
+ migrationsPath: '../../migrations/action-menu/sqlite',
16
+ },
17
+ },
18
+ } as const satisfies DrizzleRecordBundle
@@ -0,0 +1 @@
1
+ export * from './action-menu/postgres'
@@ -0,0 +1 @@
1
+ export * from './action-menu/sqlite'