@riffdb/better-auth 0.0.0-stage → 0.2.1

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 (226) hide show
  1. package/DESIGN.md +273 -0
  2. package/LICENSE-APACHE +201 -0
  3. package/LICENSE-MIT +27 -0
  4. package/README.md +323 -2
  5. package/dist/adapter.d.ts +34 -0
  6. package/dist/adapter.d.ts.map +1 -0
  7. package/dist/adapter.js +1600 -0
  8. package/dist/adapter.js.map +1 -0
  9. package/dist/generated/client.d.ts +2166 -0
  10. package/dist/generated/client.d.ts.map +1 -0
  11. package/dist/generated/client.js +2454 -0
  12. package/dist/generated/client.js.map +1 -0
  13. package/dist/index.d.ts +7 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +7 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/plugin-dispatch.d.ts +37 -0
  18. package/dist/plugin-dispatch.d.ts.map +1 -0
  19. package/dist/plugin-dispatch.js +293 -0
  20. package/dist/plugin-dispatch.js.map +1 -0
  21. package/dist/profile-contract.d.ts +63 -0
  22. package/dist/profile-contract.d.ts.map +1 -0
  23. package/dist/profile-contract.js +543 -0
  24. package/dist/profile-contract.js.map +1 -0
  25. package/dist/profile-plan.d.ts +69 -0
  26. package/dist/profile-plan.d.ts.map +1 -0
  27. package/dist/profile-plan.js +180 -0
  28. package/dist/profile-plan.js.map +1 -0
  29. package/dist/profile.d.ts +48 -0
  30. package/dist/profile.d.ts.map +1 -0
  31. package/dist/profile.js +132 -0
  32. package/dist/profile.js.map +1 -0
  33. package/dist/profiles/custom-fields/profile.d.ts +3 -0
  34. package/dist/profiles/custom-fields/profile.d.ts.map +1 -0
  35. package/dist/profiles/custom-fields/profile.js +475 -0
  36. package/dist/profiles/custom-fields/profile.js.map +1 -0
  37. package/dist/profiles/custom-fields/src/generated/client.d.ts +2710 -0
  38. package/dist/profiles/custom-fields/src/generated/client.d.ts.map +1 -0
  39. package/dist/profiles/custom-fields/src/generated/client.js +2663 -0
  40. package/dist/profiles/custom-fields/src/generated/client.js.map +1 -0
  41. package/dist/profiles/runtime/profile.d.ts +3 -0
  42. package/dist/profiles/runtime/profile.d.ts.map +1 -0
  43. package/dist/profiles/runtime/profile.js +1065 -0
  44. package/dist/profiles/runtime/profile.js.map +1 -0
  45. package/dist/profiles/runtime/src/generated/client.d.ts +4274 -0
  46. package/dist/profiles/runtime/src/generated/client.d.ts.map +1 -0
  47. package/dist/profiles/runtime/src/generated/client.js +4607 -0
  48. package/dist/profiles/runtime/src/generated/client.js.map +1 -0
  49. package/dist/runtime-materialize.d.ts +10 -0
  50. package/dist/runtime-materialize.d.ts.map +1 -0
  51. package/dist/runtime-materialize.js +344 -0
  52. package/dist/runtime-materialize.js.map +1 -0
  53. package/dist/runtime-profile.d.ts +34 -0
  54. package/dist/runtime-profile.d.ts.map +1 -0
  55. package/dist/runtime-profile.js +203 -0
  56. package/dist/runtime-profile.js.map +1 -0
  57. package/dist/testing.d.ts +11 -0
  58. package/dist/testing.d.ts.map +1 -0
  59. package/dist/testing.js +12 -0
  60. package/dist/testing.js.map +1 -0
  61. package/generated/go/client.go +2250 -0
  62. package/generated/mcp/tools.json +13922 -0
  63. package/generated/python/client.py +4454 -0
  64. package/generated/riffdb.application.exact.json +1 -0
  65. package/generated/riffdb.contract.bundle +0 -0
  66. package/generated/rust/client.rs +6524 -0
  67. package/package.json +83 -4
  68. package/profiles/custom-fields/generated/go/client.go +2578 -0
  69. package/profiles/custom-fields/generated/mcp/tools.json +15998 -0
  70. package/profiles/custom-fields/generated/python/client.py +5141 -0
  71. package/profiles/custom-fields/generated/riffdb.application.exact.json +1 -0
  72. package/profiles/custom-fields/generated/riffdb.contract.bundle +0 -0
  73. package/profiles/custom-fields/generated/rust/client.rs +7980 -0
  74. package/profiles/custom-fields/profile.ts +474 -0
  75. package/profiles/custom-fields/riffdb/contract.riff +568 -0
  76. package/profiles/custom-fields/riffdb/queries/admin_users_all_email_asc.riffq +24 -0
  77. package/profiles/custom-fields/riffdb/queries/admin_users_contains_asc.riffq +24 -0
  78. package/profiles/custom-fields/riffdb/queries/admin_users_contains_desc.riffq +24 -0
  79. package/profiles/custom-fields/riffdb/queries/admin_users_email_contains_created_desc.riffq +24 -0
  80. package/profiles/custom-fields/riffdb/queries/admin_users_email_contains_image_asc.riffq +24 -0
  81. package/profiles/custom-fields/riffdb/queries/admin_users_ends_with_asc.riffq +24 -0
  82. package/profiles/custom-fields/riffdb/queries/admin_users_ends_with_desc.riffq +24 -0
  83. package/profiles/custom-fields/riffdb/queries/admin_users_starts_with_asc.riffq +24 -0
  84. package/profiles/custom-fields/riffdb/queries/admin_users_starts_with_desc.riffq +24 -0
  85. package/profiles/custom-fields/riffdb/queries/find_account_by_id.riffq +24 -0
  86. package/profiles/custom-fields/riffdb/queries/find_account_by_provider.riffq +26 -0
  87. package/profiles/custom-fields/riffdb/queries/find_accounts_by_user_id.riffq +25 -0
  88. package/profiles/custom-fields/riffdb/queries/find_accounts_by_user_provider.riffq +27 -0
  89. package/profiles/custom-fields/riffdb/queries/find_active_sessions_by_user_id.riffq +23 -0
  90. package/profiles/custom-fields/riffdb/queries/find_credential_account.riffq +25 -0
  91. package/profiles/custom-fields/riffdb/queries/find_expired_verification_ids.riffq +17 -0
  92. package/profiles/custom-fields/riffdb/queries/find_latest_verification.riffq +20 -0
  93. package/profiles/custom-fields/riffdb/queries/find_session_by_id.riffq +20 -0
  94. package/profiles/custom-fields/riffdb/queries/find_session_by_token.riffq +20 -0
  95. package/profiles/custom-fields/riffdb/queries/find_sessions_by_token_set.riffq +20 -0
  96. package/profiles/custom-fields/riffdb/queries/find_sessions_by_user_id.riffq +21 -0
  97. package/profiles/custom-fields/riffdb/queries/find_user_by_email.riffq +16 -0
  98. package/profiles/custom-fields/riffdb/queries/find_user_by_id.riffq +15 -0
  99. package/profiles/custom-fields/riffdb/queries/find_verification_by_id.riffq +19 -0
  100. package/profiles/custom-fields/riffdb/queries/find_verifications_by_identifier.riffq +21 -0
  101. package/profiles/custom-fields/riffdb/queries/profile_account_with_user_by_provider.riffq +31 -0
  102. package/profiles/custom-fields/riffdb/queries/profile_session_with_user_by_id.riffq +14 -0
  103. package/profiles/custom-fields/riffdb/queries/profile_session_with_user_by_token.riffq +14 -0
  104. package/profiles/custom-fields/riffdb/queries/profile_sessions_with_users_by_token_set.riffq +25 -0
  105. package/profiles/custom-fields/riffdb/queries/profile_user_with_accounts_by_email.riffq +19 -0
  106. package/profiles/custom-fields/riffdb/queries/profile_user_with_accounts_by_id.riffq +19 -0
  107. package/profiles/custom-fields/riffdb.application.json +217 -0
  108. package/profiles/custom-fields/riffdb.application.lock.json +1 -0
  109. package/profiles/custom-fields/riffdb.toml +3 -0
  110. package/profiles/custom-fields/src/generated/client.ts +3096 -0
  111. package/profiles/organization-security/materialization.json +51 -0
  112. package/profiles/organization-security/riffdb/contract.riff +778 -0
  113. package/profiles/organization-security/riffdb/queries/find_account_by_id.riffq +18 -0
  114. package/profiles/organization-security/riffdb/queries/find_invitation_by_email.riffq +17 -0
  115. package/profiles/organization-security/riffdb/queries/find_invitation_by_id.riffq +18 -0
  116. package/profiles/organization-security/riffdb/queries/find_invitation_by_organization_id.riffq +17 -0
  117. package/profiles/organization-security/riffdb/queries/find_member_by_id.riffq +18 -0
  118. package/profiles/organization-security/riffdb/queries/find_member_by_user_id.riffq +17 -0
  119. package/profiles/organization-security/riffdb/queries/find_organization_by_id.riffq +16 -0
  120. package/profiles/organization-security/riffdb/queries/find_organization_by_slug.riffq +16 -0
  121. package/profiles/organization-security/riffdb/queries/find_session_by_id.riffq +18 -0
  122. package/profiles/organization-security/riffdb/queries/find_session_by_token.riffq +16 -0
  123. package/profiles/organization-security/riffdb/queries/find_team_by_id.riffq +18 -0
  124. package/profiles/organization-security/riffdb/queries/find_team_member_by_id.riffq +18 -0
  125. package/profiles/organization-security/riffdb/queries/find_team_member_by_membership_key.riffq +16 -0
  126. package/profiles/organization-security/riffdb/queries/find_team_member_by_team_id.riffq +17 -0
  127. package/profiles/organization-security/riffdb/queries/find_two_factor_by_id.riffq +18 -0
  128. package/profiles/organization-security/riffdb/queries/find_two_factor_by_secret.riffq +17 -0
  129. package/profiles/organization-security/riffdb/queries/find_user_by_email.riffq +16 -0
  130. package/profiles/organization-security/riffdb/queries/find_user_by_id.riffq +16 -0
  131. package/profiles/organization-security/riffdb/queries/find_verification_by_id.riffq +16 -0
  132. package/profiles/organization-security/riffdb/queries/find_verification_by_identifier.riffq +17 -0
  133. package/profiles/organization-security/riffdb.application.json +172 -0
  134. package/profiles/organization-security/riffdb.toml +7 -0
  135. package/profiles/organization-security.profile.json +980 -0
  136. package/profiles/runtime/generated/go/client.go +4511 -0
  137. package/profiles/runtime/generated/mcp/tools.json +30004 -0
  138. package/profiles/runtime/generated/python/client.py +9337 -0
  139. package/profiles/runtime/generated/riffdb.application.exact.json +1 -0
  140. package/profiles/runtime/generated/riffdb.contract.bundle +0 -0
  141. package/profiles/runtime/generated/rust/client.rs +13297 -0
  142. package/profiles/runtime/profile.ts +1064 -0
  143. package/profiles/runtime/riffdb/contract.riff +1053 -0
  144. package/profiles/runtime/riffdb/queries/admin_users_all_email_asc.riffq +24 -0
  145. package/profiles/runtime/riffdb/queries/admin_users_contains_asc.riffq +24 -0
  146. package/profiles/runtime/riffdb/queries/admin_users_contains_desc.riffq +24 -0
  147. package/profiles/runtime/riffdb/queries/admin_users_email_contains_created_desc.riffq +24 -0
  148. package/profiles/runtime/riffdb/queries/admin_users_email_contains_image_asc.riffq +24 -0
  149. package/profiles/runtime/riffdb/queries/admin_users_ends_with_asc.riffq +24 -0
  150. package/profiles/runtime/riffdb/queries/admin_users_ends_with_desc.riffq +24 -0
  151. package/profiles/runtime/riffdb/queries/admin_users_starts_with_asc.riffq +24 -0
  152. package/profiles/runtime/riffdb/queries/admin_users_starts_with_desc.riffq +24 -0
  153. package/profiles/runtime/riffdb/queries/find_account_by_id.riffq +24 -0
  154. package/profiles/runtime/riffdb/queries/find_account_by_provider.riffq +26 -0
  155. package/profiles/runtime/riffdb/queries/find_accounts_by_user_id.riffq +25 -0
  156. package/profiles/runtime/riffdb/queries/find_accounts_by_user_provider.riffq +27 -0
  157. package/profiles/runtime/riffdb/queries/find_active_sessions_by_user_id.riffq +23 -0
  158. package/profiles/runtime/riffdb/queries/find_credential_account.riffq +25 -0
  159. package/profiles/runtime/riffdb/queries/find_expired_verification_ids.riffq +17 -0
  160. package/profiles/runtime/riffdb/queries/find_latest_verification.riffq +20 -0
  161. package/profiles/runtime/riffdb/queries/find_session_by_id.riffq +20 -0
  162. package/profiles/runtime/riffdb/queries/find_session_by_token.riffq +20 -0
  163. package/profiles/runtime/riffdb/queries/find_sessions_by_token_set.riffq +20 -0
  164. package/profiles/runtime/riffdb/queries/find_sessions_by_user_id.riffq +21 -0
  165. package/profiles/runtime/riffdb/queries/find_user_by_email.riffq +16 -0
  166. package/profiles/runtime/riffdb/queries/find_user_by_id.riffq +15 -0
  167. package/profiles/runtime/riffdb/queries/find_verification_by_id.riffq +19 -0
  168. package/profiles/runtime/riffdb/queries/find_verifications_by_identifier.riffq +21 -0
  169. package/profiles/runtime/riffdb/queries/profile_account_with_user_by_provider.riffq +31 -0
  170. package/profiles/runtime/riffdb/queries/profile_invitation_by_email.riffq +17 -0
  171. package/profiles/runtime/riffdb/queries/profile_invitation_by_id.riffq +17 -0
  172. package/profiles/runtime/riffdb/queries/profile_invitation_by_organization_email_status.riffq +19 -0
  173. package/profiles/runtime/riffdb/queries/profile_invitation_by_organization_id.riffq +17 -0
  174. package/profiles/runtime/riffdb/queries/profile_invitation_by_organization_status.riffq +18 -0
  175. package/profiles/runtime/riffdb/queries/profile_member_by_id.riffq +27 -0
  176. package/profiles/runtime/riffdb/queries/profile_member_by_organization.riffq +20 -0
  177. package/profiles/runtime/riffdb/queries/profile_member_by_organization_created_at_asc.riffq +20 -0
  178. package/profiles/runtime/riffdb/queries/profile_member_by_organization_created_at_desc.riffq +20 -0
  179. package/profiles/runtime/riffdb/queries/profile_member_by_organization_role_asc.riffq +20 -0
  180. package/profiles/runtime/riffdb/queries/profile_member_by_organization_role_desc.riffq +20 -0
  181. package/profiles/runtime/riffdb/queries/profile_member_by_organization_user.riffq +28 -0
  182. package/profiles/runtime/riffdb/queries/profile_member_by_user.riffq +27 -0
  183. package/profiles/runtime/riffdb/queries/profile_organization_by_id.riffq +27 -0
  184. package/profiles/runtime/riffdb/queries/profile_organization_by_slug.riffq +27 -0
  185. package/profiles/runtime/riffdb/queries/profile_session_with_user_by_id.riffq +14 -0
  186. package/profiles/runtime/riffdb/queries/profile_session_with_user_by_token.riffq +14 -0
  187. package/profiles/runtime/riffdb/queries/profile_sessions_with_users_by_token_set.riffq +25 -0
  188. package/profiles/runtime/riffdb/queries/profile_two_factor_by_id.riffq +17 -0
  189. package/profiles/runtime/riffdb/queries/profile_two_factor_by_user.riffq +17 -0
  190. package/profiles/runtime/riffdb/queries/profile_user_with_accounts_by_email.riffq +19 -0
  191. package/profiles/runtime/riffdb/queries/profile_user_with_accounts_by_id.riffq +19 -0
  192. package/profiles/runtime/riffdb/queries/profile_users_by_id_set.riffq +8 -0
  193. package/profiles/runtime/riffdb.application.json +324 -0
  194. package/profiles/runtime/riffdb.application.lock.json +1 -0
  195. package/profiles/runtime/riffdb.toml +3 -0
  196. package/profiles/runtime/src/generated/client.ts +5186 -0
  197. package/riffdb/contract.riff +547 -0
  198. package/riffdb/queries/admin_users_all_email_asc.riffq +24 -0
  199. package/riffdb/queries/admin_users_contains_asc.riffq +24 -0
  200. package/riffdb/queries/admin_users_contains_desc.riffq +24 -0
  201. package/riffdb/queries/admin_users_email_contains_created_desc.riffq +24 -0
  202. package/riffdb/queries/admin_users_email_contains_image_asc.riffq +24 -0
  203. package/riffdb/queries/admin_users_ends_with_asc.riffq +24 -0
  204. package/riffdb/queries/admin_users_ends_with_desc.riffq +24 -0
  205. package/riffdb/queries/admin_users_starts_with_asc.riffq +24 -0
  206. package/riffdb/queries/admin_users_starts_with_desc.riffq +24 -0
  207. package/riffdb/queries/find_account_by_id.riffq +24 -0
  208. package/riffdb/queries/find_account_by_provider.riffq +26 -0
  209. package/riffdb/queries/find_accounts_by_user_id.riffq +25 -0
  210. package/riffdb/queries/find_accounts_by_user_provider.riffq +27 -0
  211. package/riffdb/queries/find_active_sessions_by_user_id.riffq +23 -0
  212. package/riffdb/queries/find_credential_account.riffq +25 -0
  213. package/riffdb/queries/find_expired_verification_ids.riffq +17 -0
  214. package/riffdb/queries/find_latest_verification.riffq +20 -0
  215. package/riffdb/queries/find_session_by_id.riffq +20 -0
  216. package/riffdb/queries/find_session_by_token.riffq +20 -0
  217. package/riffdb/queries/find_sessions_by_token_set.riffq +20 -0
  218. package/riffdb/queries/find_sessions_by_user_id.riffq +21 -0
  219. package/riffdb/queries/find_user_by_email.riffq +16 -0
  220. package/riffdb/queries/find_user_by_id.riffq +15 -0
  221. package/riffdb/queries/find_verification_by_id.riffq +19 -0
  222. package/riffdb/queries/find_verifications_by_identifier.riffq +21 -0
  223. package/riffdb.application.json +187 -0
  224. package/riffdb.application.lock.json +1 -0
  225. package/scripts/real-riffdb-runner.mjs +333 -0
  226. package/src/generated/client.ts +2746 -0
package/DESIGN.md ADDED
@@ -0,0 +1,273 @@
1
+ # Design boundary
2
+
3
+ ## Package responsibility
4
+
5
+ `@riffdb/better-auth` owns Better Auth schema interpretation, profile
6
+ generation, adapter method mapping, and Better Auth conformance tests. RiffDB
7
+ owns database semantics, compiled operations, authorization, durability,
8
+ idempotency, and the Rust-backed TypeScript transport.
9
+
10
+ ## Better Auth 1.7.18 method inventory
11
+
12
+ The adapter project must cover the current `createAdapterFactory` interface:
13
+
14
+ - `create`
15
+ - `update`
16
+ - `updateMany`
17
+ - `delete`
18
+ - `deleteMany`
19
+ - `consumeOne`
20
+ - `findOne`
21
+ - `findMany`
22
+ - `count`
23
+ - `incrementOne`
24
+
25
+ The Better Auth API presents these as generic model/where/update requests.
26
+ The RiffDB adapter must instead recognize a finite reviewed call shape and
27
+ dispatch to one generated named command or query. An unmatched combination
28
+ is an unsupported-profile error, never a dynamic RiffQL expression or generic
29
+ storage callback.
30
+
31
+ The core profile implements exact user `count` and bounded user windows for a
32
+ finite set of UUID and email predicates. Numeric offset, exact total, text
33
+ matching, independent order, and nullable order are declared in the compiled
34
+ query. The result page and total therefore share one provider epoch; the
35
+ adapter neither drains pages nor recounts client-side.
36
+
37
+ `consumeOne` maps to one atomic delete-and-return compiled command. In a
38
+ recognized Better Auth verification transaction, the adapter records a bounded
39
+ candidate and its internal revision, then commits `ConsumeVerificationSnapshot`.
40
+ The database validates that revision while deleting; a losing delete racer
41
+ returns `null`, and a changed snapshot fails explicitly. Remaining identifier-
42
+ scoped rows use the separate bounded cleanup command.
43
+
44
+ Better Auth 1.7.18 wraps password reset in a larger transaction. For the
45
+ supported existing-credential graph, `ResetCredentialPassword` consumes the
46
+ recorded verification row and revision-guards the credential password write
47
+ in one compiled command. A stale or missing account leaves the token and
48
+ password unchanged. Basic password changes use the native
49
+ `UpdateCredentialPassword` command with its current credential selector.
50
+ Additional verification rows, credential-account creation,
51
+ and session-revoking reset graphs are unsupported. Signup and OAuth creation
52
+ also remain single-command graphs; unknown callback shapes fail closed.
53
+
54
+ Mutable core records carry internal monotonically increasing revisions. The
55
+ adapter reads that compiler-owned revision, sends it to an exact update
56
+ command, and retries a bounded stale outcome. This preserves partial-update
57
+ semantics without allowing a client-side read/modify/write race to overwrite
58
+ an unrelated concurrent change. Revisions are not exposed as Better Auth
59
+ model fields.
60
+
61
+ Password-only account updates use the same revision protocol. The adapter
62
+ queries the bounded `(organization_id, user_id, provider_id)` index, submits
63
+ every observed revision to `UpdateAccountPasswords`, and retries a stale whole
64
+ command. An OAuth refresh therefore cannot restore a password from an older
65
+ account snapshot.
66
+
67
+ ## Upstream patterns adopted
68
+
69
+ The adapter follows Better Auth's documented `createAdapterFactory` boundary
70
+ and lets that factory own its standard model/field mapping and value
71
+ transformations. It uses the current `@better-auth/test-utils/adapter`
72
+ conformance harness rather than reproducing the upstream tests.
73
+
74
+ Community adapters are useful compatibility references, especially the
75
+ non-relational Convex, Firestore, InstantDB, and DynamoDB implementations. The
76
+ patterns worth retaining are:
77
+
78
+ - declare storage capabilities explicitly in the adapter factory;
79
+ - keep transport/storage mechanics behind a small typed seam;
80
+ - derive and validate schema metadata before serving requests;
81
+ - exercise the adapter through Better Auth's own conformance suite; and
82
+ - treat pagination, uniqueness, and atomic consumption as database semantics,
83
+ not incidental adapter conveniences.
84
+
85
+ RiffDB intentionally does not copy their generic CRUD dispatch, unbounded
86
+ page-draining, sequential multi-row mutation, or callback-transaction
87
+ patterns. Its seam consists of generated named operations for a compiled
88
+ profile, with explicit bounds and idempotency identity.
89
+
90
+ ## Profile planning boundary
91
+
92
+ Better Auth's `createSchema` hook is exposed through a generation-only adapter.
93
+ It captures Better Auth's resolved tables after plugins, additional fields,
94
+ and storage-name overrides have been applied. The deterministic plan records
95
+ only bounded declarative metadata and never connects to RiffDB.
96
+
97
+ A plan is not a runtime database schema. Materializing it requires a reviewed
98
+ RiffDB contract, finite named queries and commands for the call shapes used by
99
+ that Better Auth configuration, generated bindings, and equivalent conformance
100
+ tests. This separation makes the profile customizable without turning schema
101
+ generation into a generic database or weakening the application-facing safety
102
+ boundary. The generation adapter rejects every runtime method.
103
+
104
+ ## Planning materialization
105
+
106
+ `materializeRiffDBBetterAuthProfile` turns a reviewed plan into the first two
107
+ of those artifacts: one contract and one named query per accepted call shape,
108
+ plus the application source binding them. It emits source for review and
109
+ compilation, never a deployment, and it never connects to RiffDB.
110
+
111
+ Rows partition on `tenant_id`. The column is deliberately not `organization_id`
112
+ because the organization plugin contributes a model of that name, whose
113
+ synthesized key column would collide. Each model's key column is likewise
114
+ resolved against the rest of its entity: Better Auth's `account` carries the
115
+ provider's own `accountId`, so that entity keys on `account_row_id`.
116
+
117
+ Aggregate assignment follows the reference graph. A model with no references is
118
+ a root; a model that references a root becomes that root's child, choosing the
119
+ first such reference in sorted field order so the assignment is deterministic;
120
+ anything else is its own root, because a RiffDB aggregate is one level deep and
121
+ a child cannot own children. A child's key is prefixed by its root's key, which
122
+ is what makes the aggregate provable.
123
+
124
+ Deletion follows from that shape. A root cascades to its children, naming each
125
+ relationship and the reverse index that serves it. SPEC DEL-004 bounds the
126
+ whole discovered graph at `root_count_maximum * (1 + sum(maxima)) <= 256`, so a
127
+ wide aggregate lowers its per-relationship maximum and its bulk-delete root
128
+ count rather than failing to compile: `user` owns five children and admits one
129
+ root per command, `organization` owns two and admits three.
130
+
131
+ The generator does not pretend to enforce what RiffDB cannot prove. A cascade
132
+ may not cross an aggregate (DEL-003) and must cover every inbound relationship
133
+ exactly once (DEL-002), so a join model that reaches two roots can declare only
134
+ the edge that owns it. Every other edge becomes an indexed `uuid` field and is
135
+ listed in the materialization report as an unenforced reference. For the
136
+ representative organization and two-factor plan those are
137
+ `invitation.organizationId`, `member.userId`, and `teamMember.teamId`; the
138
+ adapter, not the contract, is responsible for their integrity. A reviewer who
139
+ needs one of them enforced changes the aggregate assignment by hand.
140
+
141
+ `profiles/organization-security/` is the materialized fixture for the
142
+ representative plan, regenerated by `npm run profiles:materialize` and verified
143
+ byte-for-byte by `npm run profiles:check`. It ships its own `riffdb.toml`, so
144
+ the claim made about it is checkable directly: `riffdb application check` in
145
+ that directory compiles the contract and all twenty queries.
146
+
147
+ References:
148
+
149
+ - <https://better-auth.com/docs/guides/create-a-db-adapter>
150
+ - <https://better-auth.com/docs/adapters/community-adapters>
151
+ - <https://github.com/get-convex/better-auth>
152
+ - <https://github.com/yultyyev/better-auth-firestore>
153
+ - <https://github.com/datar-platform/better-auth-dynamodb>
154
+
155
+ ## Executable runtime profiles
156
+
157
+ `materializeRiffDBBetterAuthRuntimeProfile` extends the reviewed core sources
158
+ with a finite operation catalogue and emits `profile.ts`. After source review,
159
+ `riffdb application lock --write` generates its named client and exact immutable
160
+ identity. The adapter accepts that bound module, compares its schema plan with
161
+ the resolved Better Auth schema, and instantiates the generated client. It never
162
+ accepts a JSON schema as executable storage or a caller-supplied CRUD callback.
163
+
164
+ The runtime generator currently accepts scalar custom user fields and the
165
+ reviewed default organization and two-factor schemas. Baseline fields,
166
+ references, requiredness, and secret classification cannot be overridden.
167
+ Organization teams, dynamic access control, and mutation hooks are rejected.
168
+ Additional plugins and call shapes need a reviewed compiler implementation.
169
+ `nextCookies` is a reviewed integration plugin and adds no storage schema; its
170
+ ID is excluded from storage plans while runtime validation checks its version.
171
+
172
+ The sample applications live in `profiles/custom-fields/` and `profiles/runtime/`.
173
+ They have separate locks and generated clients. Source freshness, compilation,
174
+ package contents, and official real-service authentication conformance are
175
+ checked for all advertised profiles. The custom-field profile runs the official
176
+ additional-fields test against a contract already carrying that field.
177
+
178
+ Runtime profiles place all entities under one tenant aggregate. This intentionally
179
+ serializes same-tenant commands and lets member and invitation rows retain both
180
+ user and organization references. Compiled reads hydrate related rows through
181
+ bounded dependent batches in the same snapshot; the adapter only associates
182
+ those returned identities. It enables native joins for these profiles and
183
+ rejects unmatched joins before querying, rather than invoking factory fallback
184
+ join queries.
185
+
186
+ The current compiler refuses a command binding two entities carrying cascade
187
+ policies, even when they are read parents. Therefore the organization profile
188
+ omits user deletion and rejects `user.deleteUser.enabled`; organization deletion
189
+ cascades both memberships and invitations atomically. This is a limitation of
190
+ this layout and compiler surface, not permission to remove either reference.
191
+ The core and custom-field profiles retain their compiled user cascade.
192
+
193
+ Organization capacity is authoritative: member and invitation creation mutate
194
+ the organization's internal counters with a guard below 100, and individual
195
+ deletions release capacity atomically. The organization delete graph has at most
196
+ 201 rows. Membership creation plus session activation during invitation
197
+ acceptance is another single compiled graph. Invitation status guards admit
198
+ one racer; upstream Better Auth owns its higher-level acceptance and compensation
199
+ flow around that graph.
200
+
201
+ Native 2FA commands increment failure counters, set locks under a threshold
202
+ guard, reset expired locks, and replace backup codes under an exact old-value
203
+ guard. An internal millisecond field tracks the optional lock timestamp in the
204
+ same commands, so the expiry comparison stays a native scalar predicate. Every
205
+ secret result leaf has an explicit `reveals` declaration. No counter or backup-
206
+ code path invokes Better Auth's generic mutation fallback.
207
+
208
+ Profile changes require explicit data migration review. The shared tenant
209
+ aggregate and plugin fields cannot reinterpret an installed core profile.
210
+ Internal revisions, capacity counters, required fields, reference targets, and
211
+ secret authority must be initialized and verified before adopting a new lock.
212
+ No automatic migration or mixed-profile runtime is supplied.
213
+
214
+ The broader planning materializer still supports schema exploration for teams.
215
+ Better Auth 1.7's optional unique `teamMember.membershipKey` needs an explicit
216
+ `requireUniqueValues` review: RiffDB cannot enforce a nullable unique field.
217
+ The planning fixture requires a non-null key on every row and reports that
218
+ stronger storage requirement. It cannot accept legacy null-key rows and is not
219
+ an advertised runtime profile.
220
+
221
+ ## Default core profile exclusions
222
+
223
+ - renamed models or fields;
224
+ - additional user/session fields;
225
+ - plugin models or plugin-added fields;
226
+ - numeric, serial, mixed, or database-generated identifiers;
227
+ - arbitrary joins, predicates, offsets beyond the compiled bound, or sort
228
+ combinations outside the named user-window queries;
229
+ - Better Auth database hooks that imply additional database mutations; and
230
+ - secondary storage implemented by RiffDB.
231
+
232
+ These exclusions describe the default core profile; the executable profiles
233
+ above provide reviewed extensions. Each addition needs an explicit bounded contract and semantic tests.
234
+
235
+ ## Closed RiffDB blockers
236
+
237
+ The loopback conformance run deploys the exact contract and role and connects
238
+ through `riffdb-driverd`. The initial empty `FindUserByEmail` result carries the
239
+ valid application head `0`; `@riffdb/client@0.2.1` preserves it
240
+ as `0n`. The adapter does not issue an unrelated warmup write, so the first
241
+ application-visible mutation remains the compiled signup graph.
242
+
243
+ RiffDB now supports bounded cascade deletion across the `Account` and `Session`
244
+ inbound relationships, so user deletion retains stored referential integrity
245
+ and executes as one compiled command.
246
+
247
+ Named RiffQL queries now support exact compiler-declared secret output leaves.
248
+ The application role derives dedicated secret-field visibility from each
249
+ selected immutable query, which closes the former `RDB-AUTH-0214` failure
250
+ without using read-only commands or broadening the role manually.
251
+
252
+ Unary compiled deletes can now return the exact transaction-revalidated
253
+ preimage, including explicitly authorized secret leaves. Verification
254
+ consumption therefore has one durable delete/result boundary rather than a
255
+ query followed by a delete.
256
+
257
+ RiffQL now supports finite exact text predicates, numeric offsets, exact totals,
258
+ independent ordering, and explicit null placement. The generated TypeScript
259
+ client also emits only reachable compact decoders, so it compiles under strict
260
+ consumer `noUnusedLocals` settings without generated-source suppressions.
261
+
262
+
263
+ ## Secrets and authority
264
+
265
+ Session tokens, verification values, passwords, OAuth access/refresh tokens,
266
+ and ID tokens require deliberate secret classification in the generated
267
+ RiffDB contract. Every named RiffQL result leaf that returns one carries an
268
+ exact `reveals` annotation. That declaration participates in immutable query
269
+ and role identity, while the generated Better Auth server role receives only
270
+ the corresponding secret-field visibility. These queries are typed SDK reads
271
+ and are omitted from MCP tool generation. End-user identity and session
272
+ semantics remain Better Auth's responsibility; the adapter must not turn them
273
+ into RiffDB capability administration.
package/LICENSE-APACHE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/LICENSE-MIT ADDED
@@ -0,0 +1,27 @@
1
+ MIT License
2
+
3
+ Copyright © 2026 Kevin O'Shea and O'Shea & Sons, LLC.
4
+
5
+ Permission is hereby granted, free of charge, to any
6
+ person obtaining a copy of this software and associated
7
+ documentation files (the "Software"), to deal in the
8
+ Software without restriction, including without
9
+ limitation the rights to use, copy, modify, merge,
10
+ publish, distribute, sublicense, and/or sell copies of
11
+ the Software, and to permit persons to whom the Software
12
+ is furnished to do so, subject to the following
13
+ conditions:
14
+
15
+ The above copyright notice and this permission notice
16
+ shall be included in all copies or substantial portions
17
+ of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
20
+ ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
21
+ TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
22
+ PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
23
+ SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
26
+ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27
+ DEALINGS IN THE SOFTWARE.