@yielded/auth-persistence-drizzle 0.1.0-beta.0 → 0.1.0-beta.12

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 (291) hide show
  1. package/README.md +6 -1
  2. package/dist/D1.d.mts +155 -40
  3. package/dist/D1.mjs +10 -6
  4. package/dist/D1.mjs.map +1 -1
  5. package/dist/Libsql.d.mts +251 -129
  6. package/dist/Libsql.mjs +20 -21
  7. package/dist/Libsql.mjs.map +1 -1
  8. package/dist/Mysql2.d.mts +208 -56
  9. package/dist/Mysql2.mjs +13 -8
  10. package/dist/Mysql2.mjs.map +1 -1
  11. package/dist/Pglite.d.mts +209 -57
  12. package/dist/Pglite.mjs +13 -9
  13. package/dist/Pglite.mjs.map +1 -1
  14. package/dist/Postgres.d.mts +207 -55
  15. package/dist/Postgres.mjs +13 -9
  16. package/dist/Postgres.mjs.map +1 -1
  17. package/dist/SqliteBun.d.mts +249 -126
  18. package/dist/SqliteBun.mjs +20 -18
  19. package/dist/SqliteBun.mjs.map +1 -1
  20. package/dist/SqliteDo.d.mts +248 -158
  21. package/dist/SqliteDo.mjs +26 -44
  22. package/dist/SqliteDo.mjs.map +1 -1
  23. package/dist/SqliteNode.d.mts +247 -124
  24. package/dist/SqliteNode.mjs +20 -18
  25. package/dist/SqliteNode.mjs.map +1 -1
  26. package/dist/SqliteWasm.d.mts +251 -128
  27. package/dist/SqliteWasm.mjs +20 -18
  28. package/dist/SqliteWasm.mjs.map +1 -1
  29. package/dist/drizzle/D1BatchStatements.d.mts +1 -1
  30. package/dist/drizzle/D1BatchStatements.mjs.map +1 -1
  31. package/dist/drizzle/d1-database.d.mts +11 -0
  32. package/dist/drizzle/d1-database.mjs +8 -0
  33. package/dist/drizzle/d1-database.mjs.map +1 -0
  34. package/dist/drizzle/d1-emails.d.mts +8 -7
  35. package/dist/drizzle/d1-emails.mjs +7 -4
  36. package/dist/drizzle/d1-emails.mjs.map +1 -1
  37. package/dist/drizzle/d1-generated-statement.mjs.map +1 -1
  38. package/dist/drizzle/d1-identity.mjs +12 -9
  39. package/dist/drizzle/d1-identity.mjs.map +1 -1
  40. package/dist/drizzle/d1-oauth.d.mts +41 -10
  41. package/dist/drizzle/d1-oauth.mjs +8 -5
  42. package/dist/drizzle/d1-oauth.mjs.map +1 -1
  43. package/dist/drizzle/d1-passkey.d.mts +3 -14
  44. package/dist/drizzle/d1-passkey.mjs +2 -1
  45. package/dist/drizzle/d1-passkey.mjs.map +1 -1
  46. package/dist/drizzle/d1-password-prepared.d.mts +4 -3
  47. package/dist/drizzle/d1-password-prepared.mjs +3 -1
  48. package/dist/drizzle/d1-password-prepared.mjs.map +1 -1
  49. package/dist/drizzle/d1-passwords.d.mts +7 -6
  50. package/dist/drizzle/d1-passwords.mjs +5 -2
  51. package/dist/drizzle/d1-passwords.mjs.map +1 -1
  52. package/dist/drizzle/d1-phone.d.mts +3 -4
  53. package/dist/drizzle/d1-phone.mjs +2 -1
  54. package/dist/drizzle/d1-phone.mjs.map +1 -1
  55. package/dist/drizzle/d1-planning.d.mts +1 -1
  56. package/dist/drizzle/d1-proofs.d.mts +5 -4
  57. package/dist/drizzle/d1-proofs.mjs +3 -1
  58. package/dist/drizzle/d1-proofs.mjs.map +1 -1
  59. package/dist/drizzle/d1-sessions.d.mts +14 -13
  60. package/dist/drizzle/d1-sessions.mjs +15 -9
  61. package/dist/drizzle/d1-sessions.mjs.map +1 -1
  62. package/dist/drizzle/d1-totp.d.mts +3 -4
  63. package/dist/drizzle/d1-totp.mjs +2 -1
  64. package/dist/drizzle/d1-totp.mjs.map +1 -1
  65. package/dist/drizzle/email-registration.d.mts +1 -1
  66. package/dist/drizzle/email-registration.mjs +2 -1
  67. package/dist/drizzle/email-registration.mjs.map +1 -1
  68. package/dist/drizzle/email-target.d.mts +8 -7
  69. package/dist/drizzle/email-target.mjs +10 -10
  70. package/dist/drizzle/email-target.mjs.map +1 -1
  71. package/dist/drizzle/model.d.mts +2 -126
  72. package/dist/drizzle/model.mjs +2 -21
  73. package/dist/drizzle/model.mjs.map +1 -1
  74. package/dist/drizzle/mysql-database.d.mts +8 -0
  75. package/dist/drizzle/mysql-database.mjs +8 -0
  76. package/dist/drizzle/mysql-database.mjs.map +1 -0
  77. package/dist/drizzle/mysql-emails.d.mts +8 -7
  78. package/dist/drizzle/mysql-emails.mjs +12 -8
  79. package/dist/drizzle/mysql-emails.mjs.map +1 -1
  80. package/dist/drizzle/mysql-identity.mjs +12 -9
  81. package/dist/drizzle/mysql-identity.mjs.map +1 -1
  82. package/dist/drizzle/mysql-password-prepared.d.mts +4 -3
  83. package/dist/drizzle/mysql-password-prepared.mjs +6 -2
  84. package/dist/drizzle/mysql-password-prepared.mjs.map +1 -1
  85. package/dist/drizzle/mysql-passwords.d.mts +7 -5
  86. package/dist/drizzle/mysql-passwords.mjs +11 -7
  87. package/dist/drizzle/mysql-passwords.mjs.map +1 -1
  88. package/dist/drizzle/mysql-proofs.d.mts +4 -3
  89. package/dist/drizzle/mysql-proofs.mjs +8 -4
  90. package/dist/drizzle/mysql-proofs.mjs.map +1 -1
  91. package/dist/drizzle/mysql-sessions.d.mts +12 -11
  92. package/dist/drizzle/mysql-sessions.mjs +16 -12
  93. package/dist/drizzle/mysql-sessions.mjs.map +1 -1
  94. package/dist/drizzle/native-database.mjs +10 -0
  95. package/dist/drizzle/native-database.mjs.map +1 -0
  96. package/dist/drizzle/oauth-accounts.mjs +1 -1
  97. package/dist/drizzle/oauth-connected-access.mjs +14 -12
  98. package/dist/drizzle/oauth-connected-access.mjs.map +1 -1
  99. package/dist/drizzle/oauth-connected-custody.mjs +2 -2
  100. package/dist/drizzle/oauth-connected-drivers.mjs +11 -6
  101. package/dist/drizzle/oauth-connected-drivers.mjs.map +1 -1
  102. package/dist/drizzle/oauth-connected-flow.mjs +2 -2
  103. package/dist/drizzle/oauth-connected-input.mjs +14 -1
  104. package/dist/drizzle/oauth-connected-input.mjs.map +1 -1
  105. package/dist/drizzle/oauth-connected-maintenance.mjs +1 -1
  106. package/dist/drizzle/oauth-connected-management.mjs +2 -2
  107. package/dist/drizzle/oauth-connected-model.d.mts +17 -3
  108. package/dist/drizzle/oauth-connected-model.mjs.map +1 -1
  109. package/dist/drizzle/oauth-connected-settlement.mjs +51 -41
  110. package/dist/drizzle/oauth-connected-settlement.mjs.map +1 -1
  111. package/dist/drizzle/oauth-connected-sign-in.mjs +263 -0
  112. package/dist/drizzle/oauth-connected-sign-in.mjs.map +1 -0
  113. package/dist/drizzle/oauth-connected-state.d.mts +110 -2
  114. package/dist/drizzle/oauth-connected-state.mjs +9 -4
  115. package/dist/drizzle/oauth-connected-state.mjs.map +1 -1
  116. package/dist/drizzle/oauth-connected-target.d.mts +142 -15
  117. package/dist/drizzle/oauth-connected-target.mjs +9 -6
  118. package/dist/drizzle/oauth-connected-target.mjs.map +1 -1
  119. package/dist/drizzle/oauth-drivers.mjs +9 -7
  120. package/dist/drizzle/oauth-drivers.mjs.map +1 -1
  121. package/dist/drizzle/oauth-flow.d.mts +1 -1
  122. package/dist/drizzle/oauth-flow.mjs +1 -1
  123. package/dist/drizzle/oauth-input.mjs +1 -1
  124. package/dist/drizzle/oauth-model.d.mts +1 -1
  125. package/dist/drizzle/oauth-owner.d.mts +1 -1
  126. package/dist/drizzle/oauth-registration.d.mts +2 -2
  127. package/dist/drizzle/oauth-registration.mjs +1 -1
  128. package/dist/drizzle/oauth-state.mjs +5 -4
  129. package/dist/drizzle/oauth-state.mjs.map +1 -1
  130. package/dist/drizzle/oauth-target.d.mts +14 -13
  131. package/dist/drizzle/oauth-target.mjs +14 -13
  132. package/dist/drizzle/oauth-target.mjs.map +1 -1
  133. package/dist/drizzle/passkey-drivers.mjs +8 -6
  134. package/dist/drizzle/passkey-drivers.mjs.map +1 -1
  135. package/dist/drizzle/passkey-write-drivers.mjs +5 -3
  136. package/dist/drizzle/passkey-write-drivers.mjs.map +1 -1
  137. package/dist/drizzle/passkey-write-target.d.mts +1 -1
  138. package/dist/drizzle/password-prepared-sql.mjs +2 -1
  139. package/dist/drizzle/password-prepared-sql.mjs.map +1 -1
  140. package/dist/drizzle/password-prepared-state.mjs +1 -1
  141. package/dist/drizzle/password-prepared-target.d.mts +4 -3
  142. package/dist/drizzle/password-prepared-target.mjs +4 -3
  143. package/dist/drizzle/password-prepared-target.mjs.map +1 -1
  144. package/dist/drizzle/password-registration.mjs +2 -1
  145. package/dist/drizzle/password-registration.mjs.map +1 -1
  146. package/dist/drizzle/password-target.d.mts +6 -5
  147. package/dist/drizzle/password-target.mjs +8 -8
  148. package/dist/drizzle/password-target.mjs.map +1 -1
  149. package/dist/drizzle/pg-database.d.mts +9 -0
  150. package/dist/drizzle/pg-database.mjs +8 -0
  151. package/dist/drizzle/pg-database.mjs.map +1 -0
  152. package/dist/drizzle/pg-emails.d.mts +8 -7
  153. package/dist/drizzle/pg-emails.mjs +12 -8
  154. package/dist/drizzle/pg-emails.mjs.map +1 -1
  155. package/dist/drizzle/pg-identity.mjs +92 -0
  156. package/dist/drizzle/pg-identity.mjs.map +1 -0
  157. package/dist/drizzle/pg-password-prepared.d.mts +4 -3
  158. package/dist/drizzle/pg-password-prepared.mjs +6 -2
  159. package/dist/drizzle/pg-password-prepared.mjs.map +1 -1
  160. package/dist/drizzle/pg-passwords.d.mts +7 -5
  161. package/dist/drizzle/pg-passwords.mjs +11 -7
  162. package/dist/drizzle/pg-passwords.mjs.map +1 -1
  163. package/dist/drizzle/pg-proofs.d.mts +4 -3
  164. package/dist/drizzle/pg-proofs.mjs +8 -4
  165. package/dist/drizzle/pg-proofs.mjs.map +1 -1
  166. package/dist/drizzle/pg-sessions.d.mts +12 -11
  167. package/dist/drizzle/pg-sessions.mjs +16 -12
  168. package/dist/drizzle/pg-sessions.mjs.map +1 -1
  169. package/dist/drizzle/phone-model.d.mts +1 -1
  170. package/dist/drizzle/phone-target.d.mts +5 -4
  171. package/dist/drizzle/phone-target.mjs +12 -11
  172. package/dist/drizzle/phone-target.mjs.map +1 -1
  173. package/dist/drizzle/proof-target.d.mts +4 -3
  174. package/dist/drizzle/proof-target.mjs +5 -5
  175. package/dist/drizzle/proof-target.mjs.map +1 -1
  176. package/dist/drizzle/session-sql.d.mts +1 -0
  177. package/dist/drizzle/session-target.d.mts +11 -9
  178. package/dist/drizzle/session-target.mjs +11 -11
  179. package/dist/drizzle/session-target.mjs.map +1 -1
  180. package/dist/drizzle/sqlite-emails.mjs +9 -5
  181. package/dist/drizzle/sqlite-emails.mjs.map +1 -1
  182. package/dist/drizzle/sqlite-identity.mjs +14 -11
  183. package/dist/drizzle/sqlite-identity.mjs.map +1 -1
  184. package/dist/drizzle/sqlite-password-prepared.mjs +7 -3
  185. package/dist/drizzle/sqlite-password-prepared.mjs.map +1 -1
  186. package/dist/drizzle/sqlite-passwords.mjs +10 -6
  187. package/dist/drizzle/sqlite-passwords.mjs.map +1 -1
  188. package/dist/drizzle/sqlite-proofs.mjs +7 -3
  189. package/dist/drizzle/sqlite-proofs.mjs.map +1 -1
  190. package/dist/drizzle/sqlite-sessions.mjs +16 -12
  191. package/dist/drizzle/sqlite-sessions.mjs.map +1 -1
  192. package/dist/drizzle/standalone-guard.d.mts +2 -0
  193. package/dist/drizzle/standalone-guard.mjs +8 -4
  194. package/dist/drizzle/standalone-guard.mjs.map +1 -1
  195. package/dist/drizzle/totp-model.d.mts +1 -1
  196. package/dist/drizzle/totp-target.d.mts +5 -4
  197. package/dist/drizzle/totp-target.mjs +31 -28
  198. package/dist/drizzle/totp-target.mjs.map +1 -1
  199. package/dist/drizzle/transaction-mysql.mjs +1 -1
  200. package/dist/drizzle/transaction-mysql.mjs.map +1 -1
  201. package/dist/index.d.mts +2 -4
  202. package/dist/index.mjs +2 -4
  203. package/dist/internal/drizzle-postgres.mjs.map +1 -1
  204. package/dist/internal/drizzle-sqlite.mjs.map +1 -1
  205. package/package.json +1 -1
  206. package/src/D1.ts +37 -26
  207. package/src/Libsql.ts +45 -61
  208. package/src/Mysql2.ts +39 -35
  209. package/src/Pglite.ts +48 -30
  210. package/src/Postgres.ts +48 -30
  211. package/src/SqliteBun.ts +59 -68
  212. package/src/SqliteDo.ts +61 -274
  213. package/src/SqliteNode.ts +56 -66
  214. package/src/SqliteWasm.ts +56 -66
  215. package/src/drizzle/D1BatchStatements.ts +1 -1
  216. package/src/drizzle/d1-database.ts +10 -0
  217. package/src/drizzle/d1-emails.ts +86 -88
  218. package/src/drizzle/d1-generated-statement.ts +1 -1
  219. package/src/drizzle/d1-identity.ts +17 -20
  220. package/src/drizzle/d1-oauth.ts +19 -8
  221. package/src/drizzle/d1-passkey.ts +5 -1
  222. package/src/drizzle/d1-password-prepared.ts +40 -42
  223. package/src/drizzle/d1-passwords.ts +76 -80
  224. package/src/drizzle/d1-phone.ts +5 -1
  225. package/src/drizzle/d1-proofs.ts +31 -34
  226. package/src/drizzle/d1-sessions.ts +53 -40
  227. package/src/drizzle/d1-totp.ts +5 -1
  228. package/src/drizzle/email-registration.ts +6 -2
  229. package/src/drizzle/email-target.ts +18 -20
  230. package/src/drizzle/model.ts +1 -208
  231. package/src/drizzle/mysql-database.ts +8 -0
  232. package/src/drizzle/mysql-emails.ts +29 -17
  233. package/src/drizzle/mysql-identity.ts +18 -21
  234. package/src/drizzle/mysql-password-prepared.ts +11 -9
  235. package/src/drizzle/mysql-passwords.ts +22 -10
  236. package/src/drizzle/mysql-proofs.ts +17 -6
  237. package/src/drizzle/mysql-sessions.ts +41 -18
  238. package/src/drizzle/native-database.ts +22 -0
  239. package/src/drizzle/oauth-connected-access.ts +8 -1
  240. package/src/drizzle/oauth-connected-drivers.ts +21 -6
  241. package/src/drizzle/oauth-connected-input.ts +13 -0
  242. package/src/drizzle/oauth-connected-model.ts +17 -0
  243. package/src/drizzle/oauth-connected-settlement.ts +65 -42
  244. package/src/drizzle/oauth-connected-sign-in.ts +438 -0
  245. package/src/drizzle/oauth-connected-state.ts +19 -7
  246. package/src/drizzle/oauth-connected-target.ts +26 -18
  247. package/src/drizzle/oauth-drivers.ts +26 -10
  248. package/src/drizzle/oauth-state.ts +5 -4
  249. package/src/drizzle/oauth-target.ts +31 -43
  250. package/src/drizzle/passkey-drivers.ts +21 -13
  251. package/src/drizzle/passkey-write-drivers.ts +11 -6
  252. package/src/drizzle/password-prepared-sql.ts +2 -4
  253. package/src/drizzle/password-prepared-target.ts +10 -7
  254. package/src/drizzle/password-registration.ts +7 -8
  255. package/src/drizzle/password-target.ts +20 -19
  256. package/src/drizzle/pg-database.ts +10 -0
  257. package/src/drizzle/pg-emails.ts +29 -17
  258. package/src/drizzle/pg-identity.ts +297 -0
  259. package/src/drizzle/pg-password-prepared.ts +11 -9
  260. package/src/drizzle/pg-passwords.ts +22 -10
  261. package/src/drizzle/pg-proofs.ts +17 -6
  262. package/src/drizzle/pg-sessions.ts +41 -18
  263. package/src/drizzle/phone-target.ts +23 -18
  264. package/src/drizzle/proof-target.ts +10 -13
  265. package/src/drizzle/session-target.ts +33 -51
  266. package/src/drizzle/sqlite-emails.ts +31 -14
  267. package/src/drizzle/sqlite-identity.ts +22 -42
  268. package/src/drizzle/sqlite-password-prepared.ts +24 -10
  269. package/src/drizzle/sqlite-passwords.ts +30 -16
  270. package/src/drizzle/sqlite-proofs.ts +29 -6
  271. package/src/drizzle/sqlite-sessions.ts +50 -24
  272. package/src/drizzle/standalone-guard.ts +19 -7
  273. package/src/drizzle/totp-target.ts +62 -61
  274. package/src/drizzle/transaction-mysql.ts +1 -1
  275. package/src/index.ts +0 -24
  276. package/src/internal/drizzle-postgres.ts +1 -1
  277. package/src/internal/drizzle-sqlite.ts +1 -1
  278. package/dist/drizzle/d1-identity.d.mts +0 -30
  279. package/dist/drizzle/mysql-identity.d.mts +0 -21
  280. package/dist/drizzle/mysql.d.mts +0 -69
  281. package/dist/drizzle/mysql.mjs +0 -218
  282. package/dist/drizzle/mysql.mjs.map +0 -1
  283. package/dist/drizzle/pg.d.mts +0 -80
  284. package/dist/drizzle/pg.mjs +0 -289
  285. package/dist/drizzle/pg.mjs.map +0 -1
  286. package/dist/drizzle/sqlite.d.mts +0 -77
  287. package/dist/drizzle/sqlite.mjs +0 -217
  288. package/dist/drizzle/sqlite.mjs.map +0 -1
  289. package/src/drizzle/mysql.ts +0 -687
  290. package/src/drizzle/pg.ts +0 -984
  291. package/src/drizzle/sqlite.ts +0 -705
@@ -2,10 +2,10 @@ import { OAuthConnectedAuthorityMapping, OAuthConnectedClientRegistrationTable,
2
2
  import { Row } from "./transaction-owner.mjs";
3
3
  import { CurrentOAuthTransaction } from "./oauth-owner.mjs";
4
4
  import { currentSubject } from "./oauth-flow.mjs";
5
- import * as M from "@yielded/auth/OAuth";
6
- import { OAuthAccountRevision } from "@yielded/auth/OAuth";
7
5
  import { SQL, Table } from "drizzle-orm";
8
6
  import { DateTime, Effect, Schema } from "effect";
7
+ import * as M from "@yielded/auth/OAuth";
8
+ import { OAuthAccountRevision } from "@yielded/auth/OAuth";
9
9
  declare namespace oauth_connected_state_d_exports {
10
10
  export { Authority, ClientAnchor, Current, Mapping, Revocations, ScopeAnchor, action, admissionStorage, claimStorage, client, clientKey, cohort, cohortKey, cohortWork, commandStorage, configuration, contextStorage, countCondition, current, disconnectStorage, disconnectedStorage, flowStorage, grantStorage, heldScope, initialGeneration, jobStorage, jobTable, lockClientById, nativeCopy, nativeOrder, nextOrder, orderNumber, policy, prelockClients, readGrant, readScope, refreshStorage, retainedUntil, rowCount, scope, scopeKey, sealedStorage, summaryStorage, tokenContextStorage, touchScope, unknownWork, useAuthority };
11
11
  }
@@ -29,6 +29,21 @@ export declare const contextStorage: {
29
29
  readonly generation: number;
30
30
  readonly flowId: string & import("effect/Brand").Brand<"effect-auth/RequestBindingFlowId">;
31
31
  readonly commandId: string & import("effect/Brand").Brand<"effect-auth/OAuthCommandId">;
32
+ readonly access?: {
33
+ readonly key: string & import("effect/Brand").Brand<"effect-auth/OAuthPermissionProfileKey">;
34
+ readonly generation: number;
35
+ readonly issuance: "active" | "retired";
36
+ readonly provider: string & import("effect/Brand").Brand<"effect-auth/OAuthProviderKey">;
37
+ readonly clientRegistrationId: string;
38
+ readonly scopes: readonly string[];
39
+ readonly resources: readonly string[];
40
+ readonly retention: "access-and-refresh" | "access-only";
41
+ readonly maximumAccessLifetimeMillis: number;
42
+ readonly maximumRefreshLifetimeMillis?: number | undefined;
43
+ readonly refreshAheadMillis: number;
44
+ readonly refresh: "confidential" | "rotating" | "unsupported";
45
+ readonly revocation: "cohort" | "unsupported";
46
+ } | undefined;
32
47
  readonly returnTarget: string & import("effect/Brand").Brand<"effect-auth/OAuthReturnTarget">;
33
48
  readonly stateDigest: string & import("effect/Brand").Brand<"effect-auth/TokenDigest">;
34
49
  readonly requestBindingVerifier: string & import("effect/Brand").Brand<"effect-auth/TokenDigest">;
@@ -110,6 +125,21 @@ export declare const contextStorage: {
110
125
  readonly generation: number;
111
126
  readonly flowId: string & import("effect/Brand").Brand<"effect-auth/RequestBindingFlowId">;
112
127
  readonly commandId: string & import("effect/Brand").Brand<"effect-auth/OAuthCommandId">;
128
+ readonly access?: {
129
+ readonly key: string & import("effect/Brand").Brand<"effect-auth/OAuthPermissionProfileKey">;
130
+ readonly generation: number;
131
+ readonly issuance: "active" | "retired";
132
+ readonly provider: string & import("effect/Brand").Brand<"effect-auth/OAuthProviderKey">;
133
+ readonly clientRegistrationId: string;
134
+ readonly scopes: readonly string[];
135
+ readonly resources: readonly string[];
136
+ readonly retention: "access-and-refresh" | "access-only";
137
+ readonly maximumAccessLifetimeMillis: number;
138
+ readonly maximumRefreshLifetimeMillis?: number | undefined;
139
+ readonly refreshAheadMillis: number;
140
+ readonly refresh: "confidential" | "rotating" | "unsupported";
141
+ readonly revocation: "cohort" | "unsupported";
142
+ } | undefined;
113
143
  readonly returnTarget: string & import("effect/Brand").Brand<"effect-auth/OAuthReturnTarget">;
114
144
  readonly stateDigest: string & import("effect/Brand").Brand<"effect-auth/TokenDigest">;
115
145
  readonly requestBindingVerifier: string & import("effect/Brand").Brand<"effect-auth/TokenDigest">;
@@ -194,6 +224,21 @@ export declare const flowStorage: {
194
224
  readonly generation: number;
195
225
  readonly flowId: string & import("effect/Brand").Brand<"effect-auth/RequestBindingFlowId">;
196
226
  readonly commandId: string & import("effect/Brand").Brand<"effect-auth/OAuthCommandId">;
227
+ readonly access?: {
228
+ readonly key: string & import("effect/Brand").Brand<"effect-auth/OAuthPermissionProfileKey">;
229
+ readonly generation: number;
230
+ readonly issuance: "active" | "retired";
231
+ readonly provider: string & import("effect/Brand").Brand<"effect-auth/OAuthProviderKey">;
232
+ readonly clientRegistrationId: string;
233
+ readonly scopes: readonly string[];
234
+ readonly resources: readonly string[];
235
+ readonly retention: "access-and-refresh" | "access-only";
236
+ readonly maximumAccessLifetimeMillis: number;
237
+ readonly maximumRefreshLifetimeMillis?: number | undefined;
238
+ readonly refreshAheadMillis: number;
239
+ readonly refresh: "confidential" | "rotating" | "unsupported";
240
+ readonly revocation: "cohort" | "unsupported";
241
+ } | undefined;
197
242
  readonly returnTarget: string & import("effect/Brand").Brand<"effect-auth/OAuthReturnTarget">;
198
243
  readonly stateDigest: string & import("effect/Brand").Brand<"effect-auth/TokenDigest">;
199
244
  readonly requestBindingVerifier: string & import("effect/Brand").Brand<"effect-auth/TokenDigest">;
@@ -284,6 +329,21 @@ export declare const flowStorage: {
284
329
  readonly generation: number;
285
330
  readonly flowId: string & import("effect/Brand").Brand<"effect-auth/RequestBindingFlowId">;
286
331
  readonly commandId: string & import("effect/Brand").Brand<"effect-auth/OAuthCommandId">;
332
+ readonly access?: {
333
+ readonly key: string & import("effect/Brand").Brand<"effect-auth/OAuthPermissionProfileKey">;
334
+ readonly generation: number;
335
+ readonly issuance: "active" | "retired";
336
+ readonly provider: string & import("effect/Brand").Brand<"effect-auth/OAuthProviderKey">;
337
+ readonly clientRegistrationId: string;
338
+ readonly scopes: readonly string[];
339
+ readonly resources: readonly string[];
340
+ readonly retention: "access-and-refresh" | "access-only";
341
+ readonly maximumAccessLifetimeMillis: number;
342
+ readonly maximumRefreshLifetimeMillis?: number | undefined;
343
+ readonly refreshAheadMillis: number;
344
+ readonly refresh: "confidential" | "rotating" | "unsupported";
345
+ readonly revocation: "cohort" | "unsupported";
346
+ } | undefined;
287
347
  readonly returnTarget: string & import("effect/Brand").Brand<"effect-auth/OAuthReturnTarget">;
288
348
  readonly stateDigest: string & import("effect/Brand").Brand<"effect-auth/TokenDigest">;
289
349
  readonly requestBindingVerifier: string & import("effect/Brand").Brand<"effect-auth/TokenDigest">;
@@ -377,6 +437,21 @@ export declare const claimStorage: {
377
437
  readonly generation: number;
378
438
  readonly flowId: string & import("effect/Brand").Brand<"effect-auth/RequestBindingFlowId">;
379
439
  readonly commandId: string & import("effect/Brand").Brand<"effect-auth/OAuthCommandId">;
440
+ readonly access?: {
441
+ readonly key: string & import("effect/Brand").Brand<"effect-auth/OAuthPermissionProfileKey">;
442
+ readonly generation: number;
443
+ readonly issuance: "active" | "retired";
444
+ readonly provider: string & import("effect/Brand").Brand<"effect-auth/OAuthProviderKey">;
445
+ readonly clientRegistrationId: string;
446
+ readonly scopes: readonly string[];
447
+ readonly resources: readonly string[];
448
+ readonly retention: "access-and-refresh" | "access-only";
449
+ readonly maximumAccessLifetimeMillis: number;
450
+ readonly maximumRefreshLifetimeMillis?: number | undefined;
451
+ readonly refreshAheadMillis: number;
452
+ readonly refresh: "confidential" | "rotating" | "unsupported";
453
+ readonly revocation: "cohort" | "unsupported";
454
+ } | undefined;
380
455
  readonly returnTarget: string & import("effect/Brand").Brand<"effect-auth/OAuthReturnTarget">;
381
456
  readonly stateDigest: string & import("effect/Brand").Brand<"effect-auth/TokenDigest">;
382
457
  readonly requestBindingVerifier: string & import("effect/Brand").Brand<"effect-auth/TokenDigest">;
@@ -473,6 +548,21 @@ export declare const claimStorage: {
473
548
  readonly generation: number;
474
549
  readonly flowId: string & import("effect/Brand").Brand<"effect-auth/RequestBindingFlowId">;
475
550
  readonly commandId: string & import("effect/Brand").Brand<"effect-auth/OAuthCommandId">;
551
+ readonly access?: {
552
+ readonly key: string & import("effect/Brand").Brand<"effect-auth/OAuthPermissionProfileKey">;
553
+ readonly generation: number;
554
+ readonly issuance: "active" | "retired";
555
+ readonly provider: string & import("effect/Brand").Brand<"effect-auth/OAuthProviderKey">;
556
+ readonly clientRegistrationId: string;
557
+ readonly scopes: readonly string[];
558
+ readonly resources: readonly string[];
559
+ readonly retention: "access-and-refresh" | "access-only";
560
+ readonly maximumAccessLifetimeMillis: number;
561
+ readonly maximumRefreshLifetimeMillis?: number | undefined;
562
+ readonly refreshAheadMillis: number;
563
+ readonly refresh: "confidential" | "rotating" | "unsupported";
564
+ readonly revocation: "cohort" | "unsupported";
565
+ } | undefined;
476
566
  readonly returnTarget: string & import("effect/Brand").Brand<"effect-auth/OAuthReturnTarget">;
477
567
  readonly stateDigest: string & import("effect/Brand").Brand<"effect-auth/TokenDigest">;
478
568
  readonly requestBindingVerifier: string & import("effect/Brand").Brand<"effect-auth/TokenDigest">;
@@ -559,6 +649,7 @@ export declare const claimStorage: {
559
649
  export declare const tokenContextStorage: {
560
650
  encode: (value: {
561
651
  readonly namespace: "effect-auth/oauth-connected-token-context/v1";
652
+ readonly exchangeOrder: string;
562
653
  readonly moduleId: string & import("effect/Brand").Brand<"effect-auth/OAuthModuleId">;
563
654
  readonly subjectId: string & import("effect/Brand").Brand<"effect-auth/SubjectId">;
564
655
  readonly identity: {
@@ -617,6 +708,7 @@ export declare const tokenContextStorage: {
617
708
  }) => string;
618
709
  decode: (value: string) => {
619
710
  readonly namespace: "effect-auth/oauth-connected-token-context/v1";
711
+ readonly exchangeOrder: string;
620
712
  readonly moduleId: string & import("effect/Brand").Brand<"effect-auth/OAuthModuleId">;
621
713
  readonly subjectId: string & import("effect/Brand").Brand<"effect-auth/SubjectId">;
622
714
  readonly identity: {
@@ -692,6 +784,7 @@ export declare const grantStorage: {
692
784
  encode: (value: {
693
785
  readonly context: {
694
786
  readonly namespace: "effect-auth/oauth-connected-token-context/v1";
787
+ readonly exchangeOrder: string;
695
788
  readonly moduleId: string & import("effect/Brand").Brand<"effect-auth/OAuthModuleId">;
696
789
  readonly subjectId: string & import("effect/Brand").Brand<"effect-auth/SubjectId">;
697
790
  readonly identity: {
@@ -758,6 +851,7 @@ export declare const grantStorage: {
758
851
  decode: (value: string) => {
759
852
  readonly context: {
760
853
  readonly namespace: "effect-auth/oauth-connected-token-context/v1";
854
+ readonly exchangeOrder: string;
761
855
  readonly moduleId: string & import("effect/Brand").Brand<"effect-auth/OAuthModuleId">;
762
856
  readonly subjectId: string & import("effect/Brand").Brand<"effect-auth/SubjectId">;
763
857
  readonly identity: {
@@ -827,6 +921,7 @@ export declare const admissionStorage: {
827
921
  readonly grant: {
828
922
  readonly context: {
829
923
  readonly namespace: "effect-auth/oauth-connected-token-context/v1";
924
+ readonly exchangeOrder: string;
830
925
  readonly moduleId: string & import("effect/Brand").Brand<"effect-auth/OAuthModuleId">;
831
926
  readonly subjectId: string & import("effect/Brand").Brand<"effect-auth/SubjectId">;
832
927
  readonly identity: {
@@ -911,6 +1006,7 @@ export declare const admissionStorage: {
911
1006
  readonly grant: {
912
1007
  readonly context: {
913
1008
  readonly namespace: "effect-auth/oauth-connected-token-context/v1";
1009
+ readonly exchangeOrder: string;
914
1010
  readonly moduleId: string & import("effect/Brand").Brand<"effect-auth/OAuthModuleId">;
915
1011
  readonly subjectId: string & import("effect/Brand").Brand<"effect-auth/SubjectId">;
916
1012
  readonly identity: {
@@ -996,6 +1092,7 @@ export declare const commandStorage: {
996
1092
  encode: (value: {
997
1093
  readonly context: {
998
1094
  readonly namespace: "effect-auth/oauth-connected-token-context/v1";
1095
+ readonly exchangeOrder: string;
999
1096
  readonly moduleId: string & import("effect/Brand").Brand<"effect-auth/OAuthModuleId">;
1000
1097
  readonly subjectId: string & import("effect/Brand").Brand<"effect-auth/SubjectId">;
1001
1098
  readonly identity: {
@@ -1058,6 +1155,7 @@ export declare const commandStorage: {
1058
1155
  decode: (value: string) => {
1059
1156
  readonly context: {
1060
1157
  readonly namespace: "effect-auth/oauth-connected-token-context/v1";
1158
+ readonly exchangeOrder: string;
1061
1159
  readonly moduleId: string & import("effect/Brand").Brand<"effect-auth/OAuthModuleId">;
1062
1160
  readonly subjectId: string & import("effect/Brand").Brand<"effect-auth/SubjectId">;
1063
1161
  readonly identity: {
@@ -1122,6 +1220,7 @@ export declare const disconnectStorage: {
1122
1220
  encode: (value: {
1123
1221
  readonly context: {
1124
1222
  readonly namespace: "effect-auth/oauth-connected-token-context/v1";
1223
+ readonly exchangeOrder: string;
1125
1224
  readonly moduleId: string & import("effect/Brand").Brand<"effect-auth/OAuthModuleId">;
1126
1225
  readonly subjectId: string & import("effect/Brand").Brand<"effect-auth/SubjectId">;
1127
1226
  readonly identity: {
@@ -1188,6 +1287,7 @@ export declare const disconnectStorage: {
1188
1287
  decode: (value: string) => {
1189
1288
  readonly context: {
1190
1289
  readonly namespace: "effect-auth/oauth-connected-token-context/v1";
1290
+ readonly exchangeOrder: string;
1191
1291
  readonly moduleId: string & import("effect/Brand").Brand<"effect-auth/OAuthModuleId">;
1192
1292
  readonly subjectId: string & import("effect/Brand").Brand<"effect-auth/SubjectId">;
1193
1293
  readonly identity: {
@@ -1257,6 +1357,7 @@ export declare const refreshStorage: {
1257
1357
  readonly grant: {
1258
1358
  readonly context: {
1259
1359
  readonly namespace: "effect-auth/oauth-connected-token-context/v1";
1360
+ readonly exchangeOrder: string;
1260
1361
  readonly moduleId: string & import("effect/Brand").Brand<"effect-auth/OAuthModuleId">;
1261
1362
  readonly subjectId: string & import("effect/Brand").Brand<"effect-auth/SubjectId">;
1262
1363
  readonly identity: {
@@ -1320,6 +1421,7 @@ export declare const refreshStorage: {
1320
1421
  readonly ciphertext: import("effect/Redacted").Redacted<string>;
1321
1422
  };
1322
1423
  };
1424
+ readonly order: string;
1323
1425
  readonly claimId: string & import("effect/Brand").Brand<"effect-auth/OAuthClaimId">;
1324
1426
  readonly claimedAtMillis: number;
1325
1427
  readonly claimExpiresAtMillis: number;
@@ -1329,6 +1431,7 @@ export declare const refreshStorage: {
1329
1431
  readonly grant: {
1330
1432
  readonly context: {
1331
1433
  readonly namespace: "effect-auth/oauth-connected-token-context/v1";
1434
+ readonly exchangeOrder: string;
1332
1435
  readonly moduleId: string & import("effect/Brand").Brand<"effect-auth/OAuthModuleId">;
1333
1436
  readonly subjectId: string & import("effect/Brand").Brand<"effect-auth/SubjectId">;
1334
1437
  readonly identity: {
@@ -1392,6 +1495,7 @@ export declare const refreshStorage: {
1392
1495
  readonly ciphertext: import("effect/Redacted").Redacted<string>;
1393
1496
  };
1394
1497
  };
1498
+ readonly order: string;
1395
1499
  readonly claimId: string & import("effect/Brand").Brand<"effect-auth/OAuthClaimId">;
1396
1500
  readonly claimedAtMillis: number;
1397
1501
  readonly claimExpiresAtMillis: number;
@@ -1405,6 +1509,7 @@ export declare const jobStorage: {
1405
1509
  readonly jobId: string & import("effect/Brand").Brand<"effect-auth/OAuthClaimId">;
1406
1510
  readonly token: {
1407
1511
  readonly namespace: "effect-auth/oauth-connected-token-context/v1";
1512
+ readonly exchangeOrder: string;
1408
1513
  readonly moduleId: string & import("effect/Brand").Brand<"effect-auth/OAuthModuleId">;
1409
1514
  readonly subjectId: string & import("effect/Brand").Brand<"effect-auth/SubjectId">;
1410
1515
  readonly identity: {
@@ -1475,6 +1580,7 @@ export declare const jobStorage: {
1475
1580
  readonly jobId: string & import("effect/Brand").Brand<"effect-auth/OAuthClaimId">;
1476
1581
  readonly token: {
1477
1582
  readonly namespace: "effect-auth/oauth-connected-token-context/v1";
1583
+ readonly exchangeOrder: string;
1478
1584
  readonly moduleId: string & import("effect/Brand").Brand<"effect-auth/OAuthModuleId">;
1479
1585
  readonly subjectId: string & import("effect/Brand").Brand<"effect-auth/SubjectId">;
1480
1586
  readonly identity: {
@@ -1726,6 +1832,7 @@ export declare const useAuthority: (mapping: Mapping, authorization: {
1726
1832
  readonly profileKey?: (string & import("effect/Brand").Brand<"effect-auth/OAuthPermissionProfileKey">) | undefined;
1727
1833
  }, kind: "metadata" | "use", grant?: {
1728
1834
  readonly namespace: "effect-auth/oauth-connected-token-context/v1";
1835
+ readonly exchangeOrder: string;
1729
1836
  readonly moduleId: string & import("effect/Brand").Brand<"effect-auth/OAuthModuleId">;
1730
1837
  readonly subjectId: string & import("effect/Brand").Brand<"effect-auth/SubjectId">;
1731
1838
  readonly identity: {
@@ -1883,6 +1990,7 @@ export declare const readGrant: (mapping: Authority, moduleId: string, grantId:
1883
1990
  row: Row;
1884
1991
  context: {
1885
1992
  readonly namespace: "effect-auth/oauth-connected-token-context/v1";
1993
+ readonly exchangeOrder: string;
1886
1994
  readonly moduleId: string & import("effect/Brand").Brand<"effect-auth/OAuthModuleId">;
1887
1995
  readonly subjectId: string & import("effect/Brand").Brand<"effect-auth/SubjectId">;
1888
1996
  readonly identity: {
@@ -2,11 +2,11 @@ import { digest, invariant, oauthIdentityKey, sameRevision, satisfies, storage,
2
2
  import { both } from "./transaction-owner.mjs";
3
3
  import { CurrentOAuthTransaction, col, copiedRow, equal } from "./oauth-owner.mjs";
4
4
  import { currentSubject } from "./oauth-flow.mjs";
5
- import * as M from "@yielded/auth/OAuth";
6
- import { snapshotOAuthSync } from "@yielded/auth/OAuth";
7
5
  import { and, eq, isNull, sql } from "drizzle-orm";
8
6
  import { DateTime, Effect, Schema } from "effect";
9
7
  import { AuthenticationRequirement } from "@yielded/auth/Sessions";
8
+ import * as M from "@yielded/auth/OAuth";
9
+ import { snapshotOAuthSync } from "@yielded/auth/OAuth";
10
10
  //#region src/drizzle/oauth-connected-state.ts
11
11
  const contextStorage = storage(M.OAuthConnectedTransactionContext);
12
12
  const flowStorage = storage(M.OAuthConnectedPendingFlow);
@@ -75,8 +75,13 @@ const policyData = (input) => Object.freeze({
75
75
  ...input,
76
76
  subjectId: nativeCopy(input.subjectId),
77
77
  revision: snapshotOAuthSync(M.OAuthConnectedUseAuthorization.fields.revision, input.revision),
78
- authorization: input.kind === "action" ? snapshotOAuthSync(M.OAuthConnectedActionAuthorization, input.authorization) : snapshotOAuthSync(M.OAuthConnectedUseAuthorization, input.authorization),
79
- ...input.kind === "action" ? { configuration: snapshotOAuthSync(M.OAuthConnectedConfiguration, input.configuration) } : {},
78
+ ...input.kind === "sign-in" ? {
79
+ credential: snapshotOAuthSync(M.OAuthCredentialSnapshot, input.credential),
80
+ configuration: snapshotOAuthSync(M.OAuthConnectedConfiguration, input.configuration)
81
+ } : {
82
+ authorization: input.kind === "action" ? snapshotOAuthSync(M.OAuthConnectedActionAuthorization, input.authorization) : snapshotOAuthSync(M.OAuthConnectedUseAuthorization, input.authorization),
83
+ ...input.kind === "action" ? { configuration: snapshotOAuthSync(M.OAuthConnectedConfiguration, input.configuration) } : {}
84
+ },
80
85
  ...input.grant === void 0 ? {} : { grant: snapshotOAuthSync(M.OAuthConnectedTokenContext, input.grant) }
81
86
  });
82
87
  const jobTable = (mapping) => {
@@ -1 +1 @@
1
- {"version":3,"file":"oauth-connected-state.mjs","names":[],"sources":["../../src/drizzle/oauth-connected-state.ts"],"sourcesContent":["import { type OAuthAccountRevision, snapshotOAuthSync } from \"@yielded/auth/OAuth\";\nimport * as M from \"@yielded/auth/OAuth\";\nimport { AuthenticationRequirement } from \"@yielded/auth/Sessions\";\n/* oxlint-disable no-explicit-any -- private table erasure retains declared callback error/requirements channels. */\nimport { and, eq, isNull, sql, type SQL, type Table } from \"drizzle-orm\";\nimport type { EffectDrizzleQueryError } from \"drizzle-orm/effect-core\";\nimport { DateTime, Effect, Schema } from \"effect\";\n\nimport type {\n OAuthConnectedAuthorityMapping,\n OAuthConnectedClientRegistrationTable,\n OAuthConnectedCohortTable,\n OAuthConnectedMapping,\n OAuthConnectedPolicyInput,\n OAuthConnectedRevocationMapping,\n} from \"./oauth-connected-model\";\nimport { currentSubject } from \"./oauth-flow\";\nimport {\n both,\n col,\n copiedRow,\n equal,\n CurrentOAuthTransaction,\n type OAuthOwner,\n type Row,\n} from \"./oauth-owner\";\nimport {\n digest,\n invariant,\n oauthIdentityKey,\n sameRevision,\n satisfies,\n storage,\n unavailable,\n} from \"./oauth-state\";\n\nexport type Authority = OAuthConnectedAuthorityMapping<any, any, any, any, any, any, any> & {\n readonly client: Partial<Pick<OAuthConnectedClientRegistrationTable<any>, \"encodeInsert\">>;\n readonly cohort: Partial<Pick<OAuthConnectedCohortTable<any>, \"encodeInsert\">>;\n};\n\nexport type Mapping = OAuthConnectedMapping<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n>;\n\nexport type Revocations = OAuthConnectedRevocationMapping<any, any, any, any, any, any, any, any>;\nexport type Current = NonNullable<Effect.Success<ReturnType<typeof currentSubject>>>;\nexport const contextStorage = storage(M.OAuthConnectedTransactionContext);\nexport const flowStorage = storage(M.OAuthConnectedPendingFlow);\nexport const claimStorage = storage(M.OAuthConnectedClaim);\nexport const tokenContextStorage = storage(M.OAuthConnectedTokenContext);\nexport const sealedStorage = storage(M.OAuthConnectedSealedTokens);\nexport const grantStorage = storage(M.OAuthConnectedStoredGrant);\n\nexport const admissionStorage = storage(\n Schema.Struct({\n grant: M.OAuthConnectedStoredGrant,\n authorization: M.OAuthConnectedUseAuthorization,\n }),\n);\n\nexport const commandStorage = storage(\n Schema.Struct({\n context: M.OAuthConnectedTokenContext,\n originalDigest: Schema.String.check(Schema.isPattern(/^[A-Za-z0-9_-]{43}$/)),\n revocationJobId: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(256))),\n }),\n);\n\nexport const disconnectStorage = storage(M.OAuthConnectedDisconnectGrant);\nexport const refreshStorage = storage(M.OAuthConnectedRefreshClaim);\nexport const jobStorage = storage(M.OAuthConnectedRevocationJob);\nexport const summaryStorage = storage(M.OAuthConnectedSummary);\nexport const disconnectedStorage = storage(M.OAuthConnectedDisconnected);\nconst strings = storage(Schema.Array(Schema.String));\n\nconst safeInteger = Schema.Int.check(\n Schema.isBetween({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER }),\n);\n\nconst orderParser = Schema.decodeSync(safeInteger);\nconst canonicalOrder = Schema.String.check(Schema.isPattern(/^(0|[1-9][0-9]{0,15})$/));\nconst orderTextParser = Schema.decodeSync(canonicalOrder);\n\nexport const orderNumber = (value: string) => {\n const number = orderParser(Number(orderTextParser(value)));\n\n invariant(String(number) === value);\n\n return number;\n};\n\nexport const nativeOrder = (mapping: Authority, value: unknown) =>\n orderParser(mapping.order.decode(value));\n\nconst encoder = new TextEncoder();\nconst decoder = new TextDecoder(\"utf-8\", { fatal: true });\n\nconst key = (domain: string, fields: ReadonlyArray<string>) => {\n for (const value of fields) invariant(decoder.decode(encoder.encode(value)) === value);\n\n return \"v1:\" + digest(strings.encode([domain, ...fields]));\n};\n\nexport const clientKey = (configuration: M.OAuthConnectedConfiguration) =>\n key(\"effect-auth/oauth-connected-client/v1\", [\n configuration.provider,\n configuration.issuer,\n configuration.profile.clientRegistrationId,\n ]);\n\nexport const cohortKey = (client: string, identity: string) =>\n key(\"effect-auth/oauth-connected-cohort/v1\", [client, identity]);\n\nexport const initialGeneration = (cohort: string) =>\n M.OAuthConnectedTarget.fields.cohortGeneration.make(\"initial:\" + digest(cohort));\n\nexport const configuration = (flow: M.OAuthConnectedPendingFlow): M.OAuthConnectedConfiguration =>\n snapshotOAuthSync(M.OAuthConnectedConfiguration, flow.context);\n\nexport const retainedUntil = (mapping: Authority, now: number) => {\n invariant(\n Number.isSafeInteger(mapping.retentionMillis) &&\n mapping.retentionMillis >= 120000 &&\n mapping.retentionMillis <= 2592000000,\n );\n\n return orderParser(now + mapping.retentionMillis);\n};\n\nexport const rowCount = Effect.fn(\"oauthConnected.rowCount\")(function* (table: Table, where: SQL) {\n const owner = yield* CurrentOAuthTransaction;\n\n const rows = yield* (\n owner.database\n .select({ value: sql<number>`count(*)`.mapWith(Number) })\n .from(table)\n .where(where) as Effect.Effect<ReadonlyArray<{ value: number }>, EffectDrizzleQueryError>\n ).pipe(Effect.mapError(unavailable));\n\n invariant(rows.length === 1);\n\n return orderParser(rows[0]!.value);\n});\n\nexport const countCondition = (table: Table, where: SQL, count: number) =>\n sql`(select count(*) from ${table} where ${where}) = ${count}`;\n\nexport const current = Effect.fn(\"oauthConnected.current\")(function* (\n mapping: Mapping,\n subject: OAuthAccountRevision[\"subjectId\"],\n) {\n const native = yield* mapping.subjectId.toNative(subject);\n\n return yield* currentSubject(mapping, native);\n});\n\nexport const nativeCopy = <N>(value: N): N => copiedRow({ value }).value as N;\n\nconst policyData = (input: OAuthConnectedPolicyInput<any>): OAuthConnectedPolicyInput<any> =>\n Object.freeze({\n ...input,\n subjectId: nativeCopy(input.subjectId),\n revision: snapshotOAuthSync(M.OAuthConnectedUseAuthorization.fields.revision, input.revision),\n authorization:\n input.kind === \"action\"\n ? snapshotOAuthSync(M.OAuthConnectedActionAuthorization, input.authorization)\n : snapshotOAuthSync(M.OAuthConnectedUseAuthorization, input.authorization),\n ...(input.kind === \"action\"\n ? { configuration: snapshotOAuthSync(M.OAuthConnectedConfiguration, input.configuration) }\n : {}),\n ...(input.grant === undefined\n ? {}\n : { grant: snapshotOAuthSync(M.OAuthConnectedTokenContext, input.grant) }),\n }) as OAuthConnectedPolicyInput<any>;\n\nexport const jobTable = (mapping: Authority) => {\n const direct = (mapping as Partial<Revocations>).job;\n const configured = (mapping as Partial<Mapping>).revocation;\n\n return direct ?? (configured?.mode === \"cohort\" ? configured.job : undefined);\n};\n\nexport const policy = Effect.fn(\"oauthConnected.policy\")(function* (\n mapping: Mapping,\n input: OAuthConnectedPolicyInput<any>,\n) {\n const owner = yield* CurrentOAuthTransaction;\n\n invariant((mapping.policy.guards?.length ?? 0) <= 32);\n for (const guard of mapping.policy.guards ?? []) {\n const read = yield* owner.read(guard.table, guard.condition(policyData(input)), {\n orderBy: col(guard.table, guard.orderBy),\n });\n\n invariant(read.rows.length > 0);\n }\n const condition = mapping.policy.condition(policyData(input));\n const accepted = yield* owner.check(condition);\n\n if (accepted) owner.postconditions.push(condition);\n\n return accepted;\n});\n\nexport const action = Effect.fn(\"oauthConnected.action\")(function* (\n mapping: Mapping,\n found: Current,\n authorization: M.OAuthConnectedActionAuthorization,\n operation: \"issue\" | \"claim\" | \"settle\" | \"disconnect\",\n expected: {\n readonly moduleId: string;\n readonly flowId: string;\n readonly commandId: string;\n readonly revision: OAuthAccountRevision;\n readonly intent: string;\n readonly maximumAgeMillis: number;\n readonly configuration: M.OAuthConnectedConfiguration;\n readonly grant?: M.OAuthConnectedTokenContext;\n },\n) {\n const owner = yield* CurrentOAuthTransaction;\n\n const challenge = authorization.challenge,\n evidence = authorization.evidence;\n\n const name =\n operation === \"issue\"\n ? \"connected-begin\"\n : operation === \"disconnect\"\n ? \"connected-disconnect\"\n : \"connected-complete\";\n\n const intentDigest = digest(expected.intent);\n\n const binding = digest(\n strings.encode([\n \"effect-auth/oauth-connected-action/v1\",\n expected.moduleId,\n name,\n expected.flowId,\n expected.commandId,\n intentDigest,\n ]),\n );\n\n if (\n challenge.moduleId !== expected.moduleId ||\n challenge.action !== name ||\n challenge.flowId !== expected.flowId ||\n challenge.commandId !== expected.commandId ||\n challenge.intentDigest !== intentDigest ||\n challenge.bindingDigest !== binding ||\n evidence.flowId !== expected.flowId ||\n evidence.bindingDigest !== binding ||\n !sameRevision(challenge.revision, expected.revision) ||\n !sameRevision(evidence.revision, expected.revision) ||\n !sameRevision(found.revision, expected.revision)\n )\n return false;\n const now = yield* owner.now(mapping.clock);\n\n const requirement = snapshotOAuthSync(\n AuthenticationRequirement,\n mapping.subject.decodeActionRequirement(copiedRow(found.row), name),\n );\n\n const revisions = new Map(\n found.revision.credentials.map((item) => [item.credentialId, item.revision]),\n );\n\n if (\n evidence.proofs.some(\n (proof) =>\n !revisions.has(proof.credentialId) || DateTime.toEpochMillis(proof.verifiedAt) > now,\n )\n )\n return false;\n for (const required of [authorization.requirement, requirement]) {\n const age = Math.min(expected.maximumAgeMillis, required.maximumAgeMillis);\n\n const fresh = evidence.proofs.filter(\n (proof) => now - DateTime.toEpochMillis(proof.verifiedAt) < age,\n );\n\n if (!satisfies(fresh, required)) return false;\n owner.postconditions.push(\n sql`${mapping.clock.engineNowMillis} >= ${now} and ${both(...fresh.map((proof) => sql`${mapping.clock.engineNowMillis} < ${DateTime.toEpochMillis(proof.verifiedAt) + age}`))}`,\n );\n }\n\n return yield* policy(mapping, {\n subjectId: found.nativeId,\n revision: found.revision,\n kind: \"action\",\n operation,\n authorization,\n configuration: expected.configuration,\n ...(expected.grant === undefined ? {} : { grant: expected.grant }),\n });\n});\n\nexport const useAuthority = Effect.fn(\"oauthConnected.useAuthority\")(function* (\n mapping: Mapping,\n authorization: M.OAuthConnectedUseAuthorization,\n kind: \"metadata\" | \"use\",\n grant?: M.OAuthConnectedTokenContext,\n) {\n const owner = yield* CurrentOAuthTransaction;\n const found = yield* current(mapping, authorization.revision.subjectId);\n const now = yield* owner.now(mapping.clock);\n\n if (\n found === undefined ||\n authorization.purpose !== kind ||\n !sameRevision(found.revision, authorization.revision) ||\n now >= authorization.expiresAtMillis ||\n (grant !== undefined &&\n (grant.moduleId !== authorization.moduleId ||\n grant.subjectId !== authorization.revision.subjectId ||\n (authorization.grantId !== undefined && authorization.grantId !== grant.grantId) ||\n (authorization.profileKey !== undefined &&\n authorization.profileKey !== grant.configuration.profile.key)))\n )\n return undefined;\n if (\n !(yield* policy(mapping, {\n subjectId: found.nativeId,\n revision: found.revision,\n kind,\n authorization,\n ...(grant === undefined ? {} : { grant }),\n }))\n )\n return undefined;\n owner.postconditions.push(\n sql`${mapping.clock.engineNowMillis} >= ${now} and ${mapping.clock.engineNowMillis} < ${authorization.expiresAtMillis}`,\n );\n\n return found;\n});\n\nexport const scopeKey = (provider: string, issuer: string) =>\n \"scope:\" + key(\"effect-auth/oauth-connected-provider-issuer/v1\", [provider, issuer]);\n\nexport interface ScopeAnchor {\n readonly id: string;\n row: Row;\n}\n\nexport interface ClientAnchor {\n readonly id: string;\n row: Row;\n counter: number;\n readonly scope: ScopeAnchor;\n}\n\nconst scopeCache = new WeakMap<OAuthOwner, Map<Table, Map<string, ScopeAnchor>>>();\nconst clientCache = new WeakMap<OAuthOwner, Map<Table, Map<string, ClientAnchor>>>();\n\nconst anchors = Effect.fn(\"oauthConnected.anchors\")(function* <A>(\n cache: WeakMap<OAuthOwner, Map<Table, Map<string, A>>>,\n table: Table,\n) {\n const owner = yield* CurrentOAuthTransaction;\n let tables = cache.get(owner);\n\n if (tables === undefined) {\n tables = new Map();\n cache.set(owner, tables);\n }\n let rows = tables.get(table);\n\n if (rows === undefined) {\n rows = new Map();\n tables.set(table, rows);\n }\n\n return rows;\n});\n\n/** Empty registration ID is impossible in the public profile label schema. The\n * distinct 52-byte key domain shares the physical table, never a client counter. */\nexport const scope = Effect.fn(\"oauthConnected.scope\")(function* (\n mapping: Authority,\n config: M.OAuthConnectedConfiguration,\n create: boolean,\n) {\n const owner = yield* CurrentOAuthTransaction;\n\n const c = mapping.client,\n id = scopeKey(config.provider, config.issuer),\n cache = yield* anchors(scopeCache, c.table);\n\n const existing = cache.get(id);\n\n if (existing !== undefined) return existing;\n const read = yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), { limit: 1 });\n\n if (read.rows.length === 0) {\n const related = [\n mapping.flow,\n mapping.grant,\n mapping.cohort,\n ...(jobTable(mapping) === undefined ? [] : [jobTable(mapping)!]),\n ];\n\n invariant(\n yield* owner.check(\n both(\n sql`not exists(select 1 from ${c.table} where ${owner.exact(c.table, { [c.provider]: config.provider, [c.issuer]: config.issuer })})`,\n ...related.map(\n (v) =>\n sql`not exists(select 1 from ${v.table} where not exists(select 1 from ${c.table} where ${col(c.table, c.clientKey)} = ${col(v.table, v.clientKey)}))`,\n ),\n ),\n ),\n );\n if (!create) return undefined;\n invariant(c.encodeInsert !== undefined);\n\n const inserted = yield* owner.insert(\n c.table,\n {\n ...c.encodeInsert(snapshotOAuthSync(M.OAuthConnectedConfiguration, config)),\n [c.clientKey]: id,\n [c.provider]: config.provider,\n [c.issuer]: config.issuer,\n [c.clientRegistrationId]: \"\",\n [c.counter]: mapping.order.encode(0),\n [c.version]: owner.marker,\n },\n { [c.clientKey]: id },\n true,\n );\n\n read.rows = inserted.rows;\n }\n const row = read.rows[0]!;\n\n invariant(\n row[c.provider] === config.provider &&\n row[c.issuer] === config.issuer &&\n row[c.clientRegistrationId] === \"\" &&\n nativeOrder(mapping, row[c.counter]) === 0,\n );\n const found = { id, row };\n\n cache.set(id, found);\n\n return found;\n});\n\nexport const touchScope = Effect.fn(\"oauthConnected.touchScope\")(function* (\n mapping: Authority,\n found: ScopeAnchor,\n) {\n const owner = yield* CurrentOAuthTransaction;\n const c = mapping.client;\n\n yield* owner.update(\n c.table,\n { [c.clientKey]: found.id, [c.version]: found.row[c.version] },\n { [c.version]: owner.marker },\n );\n found.row = { ...found.row, [c.version]: owner.marker };\n});\n\nexport const readScope = Effect.fn(\"oauthConnected.readScope\")(function* (\n mapping: Authority,\n provider: string,\n issuer: string,\n) {\n const owner = yield* CurrentOAuthTransaction;\n\n const c = mapping.client,\n id = scopeKey(provider, issuer),\n cache = yield* anchors(scopeCache, c.table),\n cached = cache.get(id);\n\n if (cached !== undefined) return cached;\n\n const read = yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), { limit: 1 }),\n row = read.rows[0];\n\n invariant(\n row !== undefined &&\n row[c.provider] === provider &&\n row[c.issuer] === issuer &&\n row[c.clientRegistrationId] === \"\" &&\n nativeOrder(mapping, row[c.counter]) === 0,\n );\n const found = { id, row };\n\n cache.set(id, found);\n\n return found;\n});\n\nexport const lockClientById = Effect.fn(\"oauthConnected.lockClientById\")(function* (\n mapping: Authority,\n id: string,\n) {\n const owner = yield* CurrentOAuthTransaction;\n\n const c = mapping.client,\n cache = yield* anchors(clientCache, c.table),\n cached = cache.get(id);\n\n if (cached !== undefined) return cached;\n\n const discovery = yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), {\n limit: 1,\n observe: false,\n lock: false,\n }),\n initial = discovery.rows[0];\n\n invariant(initial !== undefined);\n const scope = yield* readScope(mapping, initial[c.provider], initial[c.issuer]);\n\n const read = yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), { limit: 1 }),\n row = read.rows[0];\n\n invariant(\n row !== undefined &&\n row[c.clientRegistrationId] !== \"\" &&\n id ===\n key(\"effect-auth/oauth-connected-client/v1\", [\n row[c.provider],\n row[c.issuer],\n row[c.clientRegistrationId],\n ]) &&\n scope.id === scopeKey(row[c.provider], row[c.issuer]),\n );\n const found = { id, row, counter: nativeOrder(mapping, row[c.counter]), scope };\n\n cache.set(id, found);\n\n return found;\n});\n\nexport const heldScope = (mapping: Authority, provider: string, issuer: string) =>\n Effect.map(anchors(scopeCache, mapping.client.table), (cache) =>\n cache.get(scopeKey(provider, issuer)),\n );\n\n/** Cleanup obtains every scope then every client before entering any tuple. */\nexport const prelockClients = Effect.fn(\"oauthConnected.prelockClients\")(function* (\n mapping: Authority,\n ids: ReadonlyArray<string>,\n releaseScopes: ReadonlyArray<{ readonly provider: string; readonly issuer: string }> = [],\n) {\n const owner = yield* CurrentOAuthTransaction;\n\n const unique = [...new Set(ids)].sort(),\n c = mapping.client;\n\n invariant(unique.length <= 4000);\n const scopes = new Map<string, { provider: string; issuer: string; required: boolean }>();\n\n for (const value of releaseScopes)\n scopes.set(scopeKey(value.provider, value.issuer), { ...value, required: false });\n for (const id of unique) {\n const read = yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), {\n limit: 1,\n lock: false,\n observe: false,\n }),\n row = read.rows[0];\n\n invariant(row !== undefined);\n scopes.set(scopeKey(row[c.provider], row[c.issuer]), {\n provider: row[c.provider],\n issuer: row[c.issuer],\n required: true,\n });\n }\n for (const [id, { provider, issuer, required }] of [...scopes].sort(([a], [b]) =>\n a < b ? -1 : a > b ? 1 : 0,\n )) {\n if (required) yield* readScope(mapping, provider, issuer);\n else {\n const read = yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), { limit: 1 }),\n row = read.rows[0];\n\n if (row !== undefined) {\n invariant(\n row[c.provider] === provider &&\n row[c.issuer] === issuer &&\n row[c.clientRegistrationId] === \"\" &&\n nativeOrder(mapping, row[c.counter]) === 0,\n );\n (yield* anchors(scopeCache, c.table)).set(id, { id, row });\n }\n }\n }\n for (const id of unique) yield* lockClientById(mapping, id);\n});\n\nexport const client = Effect.fn(\"oauthConnected.client\")(function* (\n mapping: Authority,\n config: M.OAuthConnectedConfiguration,\n create: boolean,\n) {\n const owner = yield* CurrentOAuthTransaction;\n\n const c = mapping.client,\n id = clientKey(config),\n where = { [c.clientKey]: id };\n\n const heldScope = yield* scope(mapping, config, create);\n\n if (heldScope === undefined) return undefined;\n\n const cache = yield* anchors(clientCache, c.table),\n cached = cache.get(id);\n\n if (cached !== undefined) return cached;\n let read = yield* owner.read(c.table, equal(c.table, where), { limit: 1 });\n\n if (read.rows.length === 0) {\n const related = [\n mapping.flow,\n mapping.grant,\n mapping.cohort,\n ...(jobTable(mapping) === undefined ? [] : [jobTable(mapping)!]),\n ];\n\n invariant(\n yield* owner.check(\n both(\n ...related.map(\n (v) =>\n sql`not exists(select 1 from ${v.table} where ${eq(col(v.table, v.clientKey), id)})`,\n ),\n ),\n ),\n );\n }\n if (read.rows.length === 0 && create) {\n const inserted = yield* owner.insert(\n c.table,\n {\n ...(invariant(c.encodeInsert !== undefined),\n c.encodeInsert(snapshotOAuthSync(M.OAuthConnectedConfiguration, config))),\n ...where,\n [c.provider]: config.provider,\n [c.issuer]: config.issuer,\n [c.clientRegistrationId]: config.profile.clientRegistrationId,\n [c.counter]: mapping.order.encode(0),\n [c.version]: owner.marker,\n },\n where,\n true,\n );\n\n read.rows = inserted.rows;\n }\n const row = read.rows[0];\n\n if (row === undefined) return undefined;\n invariant(\n row[c.provider] === config.provider &&\n row[c.issuer] === config.issuer &&\n row[c.clientRegistrationId] === config.profile.clientRegistrationId,\n );\n const found = { id, row, counter: nativeOrder(mapping, row[c.counter]), scope: heldScope };\n\n cache.set(id, found);\n\n return found;\n});\n\nexport const nextOrder = Effect.fn(\"oauthConnected.nextOrder\")(function* (\n mapping: Authority,\n found: NonNullable<Effect.Success<ReturnType<typeof client>>>,\n) {\n const owner = yield* CurrentOAuthTransaction;\n\n const next = orderParser(found.counter + 1),\n c = mapping.client;\n\n yield* owner.update(\n c.table,\n { [c.clientKey]: found.id, [c.counter]: mapping.order.encode(found.counter) },\n { [c.counter]: mapping.order.encode(next), [c.version]: owner.marker },\n );\n found.counter = next;\n\n return next;\n});\n\nexport const cohort = Effect.fn(\"oauthConnected.cohort\")(function* (\n mapping: Authority,\n clientId: string,\n identityId: string,\n create: boolean,\n) {\n const owner = yield* CurrentOAuthTransaction;\n\n const c = mapping.cohort,\n id = cohortKey(clientId, identityId),\n where = { [c.cohortKey]: id };\n\n let read = yield* owner.read(c.table, equal(c.table, where), { limit: 1 });\n\n if (read.rows.length === 0) {\n const related = [\n mapping.flow,\n mapping.grant,\n ...(jobTable(mapping) === undefined ? [] : [jobTable(mapping)!]),\n ];\n\n invariant(\n yield* owner.check(\n both(\n ...related.map(\n (v) =>\n sql`not exists(select 1 from ${v.table} where ${eq(col(v.table, v.cohortKey), id)})`,\n ),\n ),\n ),\n );\n }\n if (read.rows.length === 0 && create) {\n const inserted = yield* owner.insert(\n c.table,\n {\n ...(invariant(c.encodeInsert !== undefined),\n c.encodeInsert({ clientKey: clientId, identityKey: identityId })),\n ...where,\n [c.clientKey]: clientId,\n [c.identityKey]: identityId,\n [c.generation]: initialGeneration(id),\n [c.cutoff]: mapping.order.encode(0),\n [c.state]: \"Open\",\n [c.version]: owner.marker,\n },\n where,\n true,\n );\n\n read.rows = inserted.rows;\n }\n const row = read.rows[0];\n\n if (row === undefined)\n return { id, row: undefined, generation: initialGeneration(id), cutoff: 0, blocked: false };\n invariant(\n row[c.clientKey] === clientId &&\n row[c.identityKey] === identityId &&\n [\"Open\", \"Blocked\"].includes(row[c.state]),\n );\n\n const generation = snapshotOAuthSync(\n M.OAuthConnectedTarget.fields.cohortGeneration,\n row[c.generation],\n );\n\n return {\n id,\n row,\n generation,\n cutoff: nativeOrder(mapping, row[c.cutoff]),\n blocked: row[c.state] === \"Blocked\",\n };\n});\n\nexport const readGrant = Effect.fn(\"oauthConnected.readGrant\")(function* (\n mapping: Authority,\n moduleId: string,\n grantId: string,\n lock = true,\n) {\n const owner = yield* CurrentOAuthTransaction;\n const g = mapping.grant;\n\n const read = yield* owner.read(\n g.table,\n equal(g.table, { [g.moduleId]: moduleId, [g.grantId]: grantId }),\n { limit: 1, lock, admissionOnly: lock, observe: false },\n );\n\n const row = read.rows[0];\n\n if (row === undefined) return undefined;\n if (lock) owner.observations.push(read);\n const context = tokenContextStorage.decode(row[g.context]);\n const native = yield* mapping.subjectId.toNative(context.subjectId);\n\n invariant(\n context.moduleId === moduleId &&\n context.grantId === grantId &&\n mapping.subjectId.equals(native, row[g.subjectId]) &&\n row[g.identityKey] === oauthIdentityKey(context.identity) &&\n row[g.clientKey] === clientKey(context.configuration) &&\n row[g.cohortKey] === cohortKey(row[g.clientKey], row[g.identityKey]) &&\n row[g.profileKey] === context.configuration.profile.key &&\n row[g.grantVersion] === context.grantVersion &&\n row[g.tokenVersion] === context.tokenVersion &&\n row[g.cohortGeneration] === context.cohortGeneration,\n );\n\n return {\n row,\n context,\n native,\n sealed: row[g.sealed] === null ? undefined : sealedStorage.decode(row[g.sealed]),\n };\n});\n\nexport const unknownWork = (mapping: Authority, clientId: string | SQL, cutoff?: number) => {\n const f = mapping.flow;\n\n return both(\n eq(col(f.table, f.clientKey), clientId),\n eq(col(f.table, f.work), \"Unresolved\"),\n isNull(col(f.table, f.cohortKey)),\n cutoff === undefined\n ? undefined\n : sql`${col(f.table, f.claimOrder)} <= ${mapping.order.encode(cutoff)}`,\n );\n};\n\nexport const cohortWork = (mapping: Authority, id: string | SQL) => {\n const f = mapping.flow,\n g = mapping.grant;\n\n return both(\n sql`not exists(select 1 from ${f.table} where ${and(eq(col(f.table, f.cohortKey), id), eq(col(f.table, f.work), \"Unresolved\"))})`,\n sql`not exists(select 1 from ${g.table} where ${and(eq(col(g.table, g.cohortKey), id), eq(col(g.table, g.ref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EAAE,EACxI;AACF"}
1
+ {"version":3,"file":"oauth-connected-state.mjs","names":[],"sources":["../../src/drizzle/oauth-connected-state.ts"],"sourcesContent":["import { type OAuthAccountRevision, snapshotOAuthSync } from \"@yielded/auth/OAuth\";\nimport * as M from \"@yielded/auth/OAuth\";\nimport { AuthenticationRequirement } from \"@yielded/auth/Sessions\";\n/* oxlint-disable no-explicit-any -- private table erasure retains declared callback error/requirements channels. */\nimport { and, eq, isNull, sql, type SQL, type Table } from \"drizzle-orm\";\nimport type { EffectDrizzleQueryError } from \"drizzle-orm/effect-core\";\nimport { DateTime, Effect, Schema } from \"effect\";\n\nimport type {\n OAuthConnectedAuthorityMapping,\n OAuthConnectedClientRegistrationTable,\n OAuthConnectedCohortTable,\n OAuthConnectedMapping,\n OAuthConnectedPolicyInput,\n OAuthConnectedRevocationMapping,\n} from \"./oauth-connected-model\";\nimport { currentSubject } from \"./oauth-flow\";\nimport {\n both,\n col,\n copiedRow,\n equal,\n CurrentOAuthTransaction,\n type OAuthOwner,\n type Row,\n} from \"./oauth-owner\";\nimport {\n digest,\n invariant,\n oauthIdentityKey,\n sameRevision,\n satisfies,\n storage,\n unavailable,\n} from \"./oauth-state\";\n\nexport type Authority = OAuthConnectedAuthorityMapping<any, any, any, any, any, any, any> & {\n readonly client: Partial<Pick<OAuthConnectedClientRegistrationTable<any>, \"encodeInsert\">>;\n readonly cohort: Partial<Pick<OAuthConnectedCohortTable<any>, \"encodeInsert\">>;\n};\n\nexport type Mapping = OAuthConnectedMapping<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n>;\n\nexport type Revocations = OAuthConnectedRevocationMapping<any, any, any, any, any, any, any, any>;\nexport type Current = NonNullable<Effect.Success<ReturnType<typeof currentSubject>>>;\nexport const contextStorage = storage(M.OAuthConnectedTransactionContext);\nexport const flowStorage = storage(M.OAuthConnectedPendingFlow);\nexport const claimStorage = storage(M.OAuthConnectedClaim);\nexport const tokenContextStorage = storage(M.OAuthConnectedTokenContext);\nexport const sealedStorage = storage(M.OAuthConnectedSealedTokens);\nexport const grantStorage = storage(M.OAuthConnectedStoredGrant);\n\nexport const admissionStorage = storage(\n Schema.Struct({\n grant: M.OAuthConnectedStoredGrant,\n authorization: M.OAuthConnectedUseAuthorization,\n }),\n);\n\nexport const commandStorage = storage(\n Schema.Struct({\n context: M.OAuthConnectedTokenContext,\n originalDigest: Schema.String.check(Schema.isPattern(/^[A-Za-z0-9_-]{43}$/)),\n revocationJobId: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(256))),\n }),\n);\n\nexport const disconnectStorage = storage(M.OAuthConnectedDisconnectGrant);\nexport const refreshStorage = storage(M.OAuthConnectedRefreshClaim);\nexport const jobStorage = storage(M.OAuthConnectedRevocationJob);\nexport const summaryStorage = storage(M.OAuthConnectedSummary);\nexport const disconnectedStorage = storage(M.OAuthConnectedDisconnected);\nconst strings = storage(Schema.Array(Schema.String));\n\nconst safeInteger = Schema.Int.check(\n Schema.isBetween({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER }),\n);\n\nconst orderParser = Schema.decodeSync(safeInteger);\nconst canonicalOrder = Schema.String.check(Schema.isPattern(/^(0|[1-9][0-9]{0,15})$/));\nconst orderTextParser = Schema.decodeSync(canonicalOrder);\n\nexport const orderNumber = (value: string) => {\n const number = orderParser(Number(orderTextParser(value)));\n\n invariant(String(number) === value);\n\n return number;\n};\n\nexport const nativeOrder = (mapping: Authority, value: unknown) =>\n orderParser(mapping.order.decode(value));\n\nconst encoder = new TextEncoder();\nconst decoder = new TextDecoder(\"utf-8\", { fatal: true });\n\nconst key = (domain: string, fields: ReadonlyArray<string>) => {\n for (const value of fields) invariant(decoder.decode(encoder.encode(value)) === value);\n\n return \"v1:\" + digest(strings.encode([domain, ...fields]));\n};\n\nexport const clientKey = (configuration: M.OAuthConnectedConfiguration) =>\n key(\"effect-auth/oauth-connected-client/v1\", [\n configuration.provider,\n configuration.issuer,\n configuration.profile.clientRegistrationId,\n ]);\n\nexport const cohortKey = (client: string, identity: string) =>\n key(\"effect-auth/oauth-connected-cohort/v1\", [client, identity]);\n\nexport const initialGeneration = (cohort: string) =>\n M.OAuthConnectedTarget.fields.cohortGeneration.make(\"initial:\" + digest(cohort));\n\nexport const configuration = (flow: M.OAuthConnectedPendingFlow): M.OAuthConnectedConfiguration =>\n snapshotOAuthSync(M.OAuthConnectedConfiguration, flow.context);\n\nexport const retainedUntil = (mapping: Authority, now: number) => {\n invariant(\n Number.isSafeInteger(mapping.retentionMillis) &&\n mapping.retentionMillis >= 120000 &&\n mapping.retentionMillis <= 2592000000,\n );\n\n return orderParser(now + mapping.retentionMillis);\n};\n\nexport const rowCount = Effect.fn(\"oauthConnected.rowCount\")(function* (table: Table, where: SQL) {\n const owner = yield* CurrentOAuthTransaction;\n\n const rows = yield* (\n owner.database\n .select({ value: sql<number>`count(*)`.mapWith(Number) })\n .from(table)\n .where(where) as Effect.Effect<ReadonlyArray<{ value: number }>, EffectDrizzleQueryError>\n ).pipe(Effect.mapError(unavailable));\n\n invariant(rows.length === 1);\n\n return orderParser(rows[0]!.value);\n});\n\nexport const countCondition = (table: Table, where: SQL, count: number) =>\n sql`(select count(*) from ${table} where ${where}) = ${count}`;\n\nexport const current = Effect.fn(\"oauthConnected.current\")(function* (\n mapping: Mapping,\n subject: OAuthAccountRevision[\"subjectId\"],\n) {\n const native = yield* mapping.subjectId.toNative(subject);\n\n return yield* currentSubject(mapping, native);\n});\n\nexport const nativeCopy = <N>(value: N): N => copiedRow({ value }).value as N;\n\nconst policyData = (input: OAuthConnectedPolicyInput<any>): OAuthConnectedPolicyInput<any> =>\n Object.freeze({\n ...input,\n subjectId: nativeCopy(input.subjectId),\n revision: snapshotOAuthSync(M.OAuthConnectedUseAuthorization.fields.revision, input.revision),\n ...(input.kind === \"sign-in\"\n ? {\n credential: snapshotOAuthSync(M.OAuthCredentialSnapshot, input.credential),\n configuration: snapshotOAuthSync(M.OAuthConnectedConfiguration, input.configuration),\n }\n : {\n authorization:\n input.kind === \"action\"\n ? snapshotOAuthSync(M.OAuthConnectedActionAuthorization, input.authorization)\n : snapshotOAuthSync(M.OAuthConnectedUseAuthorization, input.authorization),\n ...(input.kind === \"action\"\n ? {\n configuration: snapshotOAuthSync(\n M.OAuthConnectedConfiguration,\n input.configuration,\n ),\n }\n : {}),\n }),\n ...(input.grant === undefined\n ? {}\n : { grant: snapshotOAuthSync(M.OAuthConnectedTokenContext, input.grant) }),\n }) as OAuthConnectedPolicyInput<any>;\n\nexport const jobTable = (mapping: Authority) => {\n const direct = (mapping as Partial<Revocations>).job;\n const configured = (mapping as Partial<Mapping>).revocation;\n\n return direct ?? (configured?.mode === \"cohort\" ? configured.job : undefined);\n};\n\nexport const policy = Effect.fn(\"oauthConnected.policy\")(function* (\n mapping: Mapping,\n input: OAuthConnectedPolicyInput<any>,\n) {\n const owner = yield* CurrentOAuthTransaction;\n\n invariant((mapping.policy.guards?.length ?? 0) <= 32);\n for (const guard of mapping.policy.guards ?? []) {\n const read = yield* owner.read(guard.table, guard.condition(policyData(input)), {\n orderBy: col(guard.table, guard.orderBy),\n });\n\n invariant(read.rows.length > 0);\n }\n const condition = mapping.policy.condition(policyData(input));\n const accepted = yield* owner.check(condition);\n\n if (accepted) owner.postconditions.push(condition);\n\n return accepted;\n});\n\nexport const action = Effect.fn(\"oauthConnected.action\")(function* (\n mapping: Mapping,\n found: Current,\n authorization: M.OAuthConnectedActionAuthorization,\n operation: \"issue\" | \"claim\" | \"settle\" | \"disconnect\",\n expected: {\n readonly moduleId: string;\n readonly flowId: string;\n readonly commandId: string;\n readonly revision: OAuthAccountRevision;\n readonly intent: string;\n readonly maximumAgeMillis: number;\n readonly configuration: M.OAuthConnectedConfiguration;\n readonly grant?: M.OAuthConnectedTokenContext;\n },\n) {\n const owner = yield* CurrentOAuthTransaction;\n\n const challenge = authorization.challenge,\n evidence = authorization.evidence;\n\n const name =\n operation === \"issue\"\n ? \"connected-begin\"\n : operation === \"disconnect\"\n ? \"connected-disconnect\"\n : \"connected-complete\";\n\n const intentDigest = digest(expected.intent);\n\n const binding = digest(\n strings.encode([\n \"effect-auth/oauth-connected-action/v1\",\n expected.moduleId,\n name,\n expected.flowId,\n expected.commandId,\n intentDigest,\n ]),\n );\n\n if (\n challenge.moduleId !== expected.moduleId ||\n challenge.action !== name ||\n challenge.flowId !== expected.flowId ||\n challenge.commandId !== expected.commandId ||\n challenge.intentDigest !== intentDigest ||\n challenge.bindingDigest !== binding ||\n evidence.flowId !== expected.flowId ||\n evidence.bindingDigest !== binding ||\n !sameRevision(challenge.revision, expected.revision) ||\n !sameRevision(evidence.revision, expected.revision) ||\n !sameRevision(found.revision, expected.revision)\n )\n return false;\n const now = yield* owner.now(mapping.clock);\n\n const requirement = snapshotOAuthSync(\n AuthenticationRequirement,\n mapping.subject.decodeActionRequirement(copiedRow(found.row), name),\n );\n\n const revisions = new Map(\n found.revision.credentials.map((item) => [item.credentialId, item.revision]),\n );\n\n if (\n evidence.proofs.some(\n (proof) =>\n !revisions.has(proof.credentialId) || DateTime.toEpochMillis(proof.verifiedAt) > now,\n )\n )\n return false;\n for (const required of [authorization.requirement, requirement]) {\n const age = Math.min(expected.maximumAgeMillis, required.maximumAgeMillis);\n\n const fresh = evidence.proofs.filter(\n (proof) => now - DateTime.toEpochMillis(proof.verifiedAt) < age,\n );\n\n if (!satisfies(fresh, required)) return false;\n owner.postconditions.push(\n sql`${mapping.clock.engineNowMillis} >= ${now} and ${both(...fresh.map((proof) => sql`${mapping.clock.engineNowMillis} < ${DateTime.toEpochMillis(proof.verifiedAt) + age}`))}`,\n );\n }\n\n return yield* policy(mapping, {\n subjectId: found.nativeId,\n revision: found.revision,\n kind: \"action\",\n operation,\n authorization,\n configuration: expected.configuration,\n ...(expected.grant === undefined ? {} : { grant: expected.grant }),\n });\n});\n\nexport const useAuthority = Effect.fn(\"oauthConnected.useAuthority\")(function* (\n mapping: Mapping,\n authorization: M.OAuthConnectedUseAuthorization,\n kind: \"metadata\" | \"use\",\n grant?: M.OAuthConnectedTokenContext,\n) {\n const owner = yield* CurrentOAuthTransaction;\n const found = yield* current(mapping, authorization.revision.subjectId);\n const now = yield* owner.now(mapping.clock);\n\n if (\n found === undefined ||\n authorization.purpose !== kind ||\n !sameRevision(found.revision, authorization.revision) ||\n now >= authorization.expiresAtMillis ||\n (grant !== undefined &&\n (grant.moduleId !== authorization.moduleId ||\n grant.subjectId !== authorization.revision.subjectId ||\n (authorization.grantId !== undefined && authorization.grantId !== grant.grantId) ||\n (authorization.profileKey !== undefined &&\n authorization.profileKey !== grant.configuration.profile.key)))\n )\n return undefined;\n if (\n !(yield* policy(mapping, {\n subjectId: found.nativeId,\n revision: found.revision,\n kind,\n authorization,\n ...(grant === undefined ? {} : { grant }),\n }))\n )\n return undefined;\n owner.postconditions.push(\n sql`${mapping.clock.engineNowMillis} >= ${now} and ${mapping.clock.engineNowMillis} < ${authorization.expiresAtMillis}`,\n );\n\n return found;\n});\n\nexport const scopeKey = (provider: string, issuer: string) =>\n \"scope:\" + key(\"effect-auth/oauth-connected-provider-issuer/v1\", [provider, issuer]);\n\nexport interface ScopeAnchor {\n readonly id: string;\n row: Row;\n}\n\nexport interface ClientAnchor {\n readonly id: string;\n row: Row;\n counter: number;\n readonly scope: ScopeAnchor;\n}\n\nconst scopeCache = new WeakMap<OAuthOwner, Map<Table, Map<string, ScopeAnchor>>>();\nconst clientCache = new WeakMap<OAuthOwner, Map<Table, Map<string, ClientAnchor>>>();\n\nconst anchors = Effect.fn(\"oauthConnected.anchors\")(function* <A>(\n cache: WeakMap<OAuthOwner, Map<Table, Map<string, A>>>,\n table: Table,\n) {\n const owner = yield* CurrentOAuthTransaction;\n let tables = cache.get(owner);\n\n if (tables === undefined) {\n tables = new Map();\n cache.set(owner, tables);\n }\n let rows = tables.get(table);\n\n if (rows === undefined) {\n rows = new Map();\n tables.set(table, rows);\n }\n\n return rows;\n});\n\n/** Empty registration ID is impossible in the public profile label schema. The\n * distinct 52-byte key domain shares the physical table, never a client counter. */\nexport const scope = Effect.fn(\"oauthConnected.scope\")(function* (\n mapping: Authority,\n config: M.OAuthConnectedConfiguration,\n create: boolean,\n) {\n const owner = yield* CurrentOAuthTransaction;\n\n const c = mapping.client,\n id = scopeKey(config.provider, config.issuer),\n cache = yield* anchors(scopeCache, c.table);\n\n const existing = cache.get(id);\n\n if (existing !== undefined) return existing;\n const read = yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), { limit: 1 });\n\n if (read.rows.length === 0) {\n const related = [\n mapping.flow,\n mapping.grant,\n mapping.cohort,\n ...(jobTable(mapping) === undefined ? [] : [jobTable(mapping)!]),\n ];\n\n invariant(\n yield* owner.check(\n both(\n sql`not exists(select 1 from ${c.table} where ${owner.exact(c.table, { [c.provider]: config.provider, [c.issuer]: config.issuer })})`,\n ...related.map(\n (v) =>\n sql`not exists(select 1 from ${v.table} where not exists(select 1 from ${c.table} where ${col(c.table, c.clientKey)} = ${col(v.table, v.clientKey)}))`,\n ),\n ),\n ),\n );\n if (!create) return undefined;\n invariant(c.encodeInsert !== undefined);\n\n const inserted = yield* owner.insert(\n c.table,\n {\n ...c.encodeInsert(snapshotOAuthSync(M.OAuthConnectedConfiguration, config)),\n [c.clientKey]: id,\n [c.provider]: config.provider,\n [c.issuer]: config.issuer,\n [c.clientRegistrationId]: \"\",\n [c.counter]: mapping.order.encode(0),\n [c.version]: owner.marker,\n },\n { [c.clientKey]: id },\n true,\n );\n\n read.rows = inserted.rows;\n }\n const row = read.rows[0]!;\n\n invariant(\n row[c.provider] === config.provider &&\n row[c.issuer] === config.issuer &&\n row[c.clientRegistrationId] === \"\" &&\n nativeOrder(mapping, row[c.counter]) === 0,\n );\n const found = { id, row };\n\n cache.set(id, found);\n\n return found;\n});\n\nexport const touchScope = Effect.fn(\"oauthConnected.touchScope\")(function* (\n mapping: Authority,\n found: ScopeAnchor,\n) {\n const owner = yield* CurrentOAuthTransaction;\n const c = mapping.client;\n\n yield* owner.update(\n c.table,\n { [c.clientKey]: found.id, [c.version]: found.row[c.version] },\n { [c.version]: owner.marker },\n );\n found.row = { ...found.row, [c.version]: owner.marker };\n});\n\nexport const readScope = Effect.fn(\"oauthConnected.readScope\")(function* (\n mapping: Authority,\n provider: string,\n issuer: string,\n) {\n const owner = yield* CurrentOAuthTransaction;\n\n const c = mapping.client,\n id = scopeKey(provider, issuer),\n cache = yield* anchors(scopeCache, c.table),\n cached = cache.get(id);\n\n if (cached !== undefined) return cached;\n\n const read = yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), { limit: 1 }),\n row = read.rows[0];\n\n invariant(\n row !== undefined &&\n row[c.provider] === provider &&\n row[c.issuer] === issuer &&\n row[c.clientRegistrationId] === \"\" &&\n nativeOrder(mapping, row[c.counter]) === 0,\n );\n const found = { id, row };\n\n cache.set(id, found);\n\n return found;\n});\n\nexport const lockClientById = Effect.fn(\"oauthConnected.lockClientById\")(function* (\n mapping: Authority,\n id: string,\n) {\n const owner = yield* CurrentOAuthTransaction;\n\n const c = mapping.client,\n cache = yield* anchors(clientCache, c.table),\n cached = cache.get(id);\n\n if (cached !== undefined) return cached;\n\n const discovery = yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), {\n limit: 1,\n observe: false,\n lock: false,\n }),\n initial = discovery.rows[0];\n\n invariant(initial !== undefined);\n const scope = yield* readScope(mapping, initial[c.provider], initial[c.issuer]);\n\n const read = yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), { limit: 1 }),\n row = read.rows[0];\n\n invariant(\n row !== undefined &&\n row[c.clientRegistrationId] !== \"\" &&\n id ===\n key(\"effect-auth/oauth-connected-client/v1\", [\n row[c.provider],\n row[c.issuer],\n row[c.clientRegistrationId],\n ]) &&\n scope.id === scopeKey(row[c.provider], row[c.issuer]),\n );\n const found = { id, row, counter: nativeOrder(mapping, row[c.counter]), scope };\n\n cache.set(id, found);\n\n return found;\n});\n\nexport const heldScope = (mapping: Authority, provider: string, issuer: string) =>\n Effect.map(anchors(scopeCache, mapping.client.table), (cache) =>\n cache.get(scopeKey(provider, issuer)),\n );\n\n/** Cleanup obtains every scope then every client before entering any tuple. */\nexport const prelockClients = Effect.fn(\"oauthConnected.prelockClients\")(function* (\n mapping: Authority,\n ids: ReadonlyArray<string>,\n releaseScopes: ReadonlyArray<{ readonly provider: string; readonly issuer: string }> = [],\n) {\n const owner = yield* CurrentOAuthTransaction;\n\n const unique = [...new Set(ids)].sort(),\n c = mapping.client;\n\n invariant(unique.length <= 4000);\n const scopes = new Map<string, { provider: string; issuer: string; required: boolean }>();\n\n for (const value of releaseScopes)\n scopes.set(scopeKey(value.provider, value.issuer), { ...value, required: false });\n for (const id of unique) {\n const read = yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), {\n limit: 1,\n lock: false,\n observe: false,\n }),\n row = read.rows[0];\n\n invariant(row !== undefined);\n scopes.set(scopeKey(row[c.provider], row[c.issuer]), {\n provider: row[c.provider],\n issuer: row[c.issuer],\n required: true,\n });\n }\n for (const [id, { provider, issuer, required }] of [...scopes].sort(([a], [b]) =>\n a < b ? -1 : a > b ? 1 : 0,\n )) {\n if (required) yield* readScope(mapping, provider, issuer);\n else {\n const read = yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), { limit: 1 }),\n row = read.rows[0];\n\n if (row !== undefined) {\n invariant(\n row[c.provider] === provider &&\n row[c.issuer] === issuer &&\n row[c.clientRegistrationId] === \"\" &&\n nativeOrder(mapping, row[c.counter]) === 0,\n );\n (yield* anchors(scopeCache, c.table)).set(id, { id, row });\n }\n }\n }\n for (const id of unique) yield* lockClientById(mapping, id);\n});\n\nexport const client = Effect.fn(\"oauthConnected.client\")(function* (\n mapping: Authority,\n config: M.OAuthConnectedConfiguration,\n create: boolean,\n) {\n const owner = yield* CurrentOAuthTransaction;\n\n const c = mapping.client,\n id = clientKey(config),\n where = { [c.clientKey]: id };\n\n const heldScope = yield* scope(mapping, config, create);\n\n if (heldScope === undefined) return undefined;\n\n const cache = yield* anchors(clientCache, c.table),\n cached = cache.get(id);\n\n if (cached !== undefined) return cached;\n let read = yield* owner.read(c.table, equal(c.table, where), { limit: 1 });\n\n if (read.rows.length === 0) {\n const related = [\n mapping.flow,\n mapping.grant,\n mapping.cohort,\n ...(jobTable(mapping) === undefined ? [] : [jobTable(mapping)!]),\n ];\n\n invariant(\n yield* owner.check(\n both(\n ...related.map(\n (v) =>\n sql`not exists(select 1 from ${v.table} where ${eq(col(v.table, v.clientKey), id)})`,\n ),\n ),\n ),\n );\n }\n if (read.rows.length === 0 && create) {\n const inserted = yield* owner.insert(\n c.table,\n {\n ...(invariant(c.encodeInsert !== undefined),\n c.encodeInsert(snapshotOAuthSync(M.OAuthConnectedConfiguration, config))),\n ...where,\n [c.provider]: config.provider,\n [c.issuer]: config.issuer,\n [c.clientRegistrationId]: config.profile.clientRegistrationId,\n [c.counter]: mapping.order.encode(0),\n [c.version]: owner.marker,\n },\n where,\n true,\n );\n\n read.rows = inserted.rows;\n }\n const row = read.rows[0];\n\n if (row === undefined) return undefined;\n invariant(\n row[c.provider] === config.provider &&\n row[c.issuer] === config.issuer &&\n row[c.clientRegistrationId] === config.profile.clientRegistrationId,\n );\n const found = { id, row, counter: nativeOrder(mapping, row[c.counter]), scope: heldScope };\n\n cache.set(id, found);\n\n return found;\n});\n\nexport const nextOrder = Effect.fn(\"oauthConnected.nextOrder\")(function* (\n mapping: Authority,\n found: NonNullable<Effect.Success<ReturnType<typeof client>>>,\n) {\n const owner = yield* CurrentOAuthTransaction;\n\n const next = orderParser(found.counter + 1),\n c = mapping.client;\n\n yield* owner.update(\n c.table,\n { [c.clientKey]: found.id, [c.counter]: mapping.order.encode(found.counter) },\n { [c.counter]: mapping.order.encode(next), [c.version]: owner.marker },\n );\n found.counter = next;\n\n return next;\n});\n\nexport const cohort = Effect.fn(\"oauthConnected.cohort\")(function* (\n mapping: Authority,\n clientId: string,\n identityId: string,\n create: boolean,\n) {\n const owner = yield* CurrentOAuthTransaction;\n\n const c = mapping.cohort,\n id = cohortKey(clientId, identityId),\n where = { [c.cohortKey]: id };\n\n let read = yield* owner.read(c.table, equal(c.table, where), { limit: 1 });\n\n if (read.rows.length === 0) {\n const related = [\n mapping.flow,\n mapping.grant,\n ...(jobTable(mapping) === undefined ? [] : [jobTable(mapping)!]),\n ];\n\n invariant(\n yield* owner.check(\n both(\n ...related.map(\n (v) =>\n sql`not exists(select 1 from ${v.table} where ${eq(col(v.table, v.cohortKey), id)})`,\n ),\n ),\n ),\n );\n }\n if (read.rows.length === 0 && create) {\n const inserted = yield* owner.insert(\n c.table,\n {\n ...(invariant(c.encodeInsert !== undefined),\n c.encodeInsert({ clientKey: clientId, identityKey: identityId })),\n ...where,\n [c.clientKey]: clientId,\n [c.identityKey]: identityId,\n [c.generation]: initialGeneration(id),\n [c.cutoff]: mapping.order.encode(0),\n [c.state]: \"Open\",\n [c.version]: owner.marker,\n },\n where,\n true,\n );\n\n read.rows = inserted.rows;\n }\n const row = read.rows[0];\n\n if (row === undefined)\n return { id, row: undefined, generation: initialGeneration(id), cutoff: 0, blocked: false };\n invariant(\n row[c.clientKey] === clientId &&\n row[c.identityKey] === identityId &&\n [\"Open\", \"Blocked\"].includes(row[c.state]),\n );\n\n const generation = snapshotOAuthSync(\n M.OAuthConnectedTarget.fields.cohortGeneration,\n row[c.generation],\n );\n\n return {\n id,\n row,\n generation,\n cutoff: nativeOrder(mapping, row[c.cutoff]),\n blocked: row[c.state] === \"Blocked\",\n };\n});\n\nexport const readGrant = Effect.fn(\"oauthConnected.readGrant\")(function* (\n mapping: Authority,\n moduleId: string,\n grantId: string,\n lock = true,\n) {\n const owner = yield* CurrentOAuthTransaction;\n const g = mapping.grant;\n\n const read = yield* owner.read(\n g.table,\n equal(g.table, { [g.moduleId]: moduleId, [g.grantId]: grantId }),\n { limit: 1, lock, admissionOnly: lock, observe: false },\n );\n\n const row = read.rows[0];\n\n if (row === undefined) return undefined;\n if (lock) owner.observations.push(read);\n const context = tokenContextStorage.decode(row[g.context]);\n const native = yield* mapping.subjectId.toNative(context.subjectId);\n\n invariant(\n context.moduleId === moduleId &&\n context.grantId === grantId &&\n mapping.subjectId.equals(native, row[g.subjectId]) &&\n row[g.identityKey] === oauthIdentityKey(context.identity) &&\n row[g.clientKey] === clientKey(context.configuration) &&\n row[g.cohortKey] === cohortKey(row[g.clientKey], row[g.identityKey]) &&\n row[g.profileKey] === context.configuration.profile.key &&\n row[g.grantVersion] === context.grantVersion &&\n row[g.tokenVersion] === context.tokenVersion &&\n row[g.cohortGeneration] === context.cohortGeneration,\n );\n\n return {\n row,\n context,\n native,\n sealed: row[g.sealed] === null ? undefined : sealedStorage.decode(row[g.sealed]),\n };\n});\n\nexport const unknownWork = (mapping: Authority, clientId: string | SQL, cutoff?: number) => {\n const f = mapping.flow;\n\n return both(\n eq(col(f.table, f.clientKey), clientId),\n eq(col(f.table, f.work), \"Unresolved\"),\n isNull(col(f.table, f.cohortKey)),\n cutoff === undefined\n ? undefined\n : sql`${col(f.table, f.claimOrder)} <= ${mapping.order.encode(cutoff)}`,\n );\n};\n\nexport const cohortWork = (mapping: Authority, id: string | SQL) => {\n const f = mapping.flow,\n g = mapping.grant;\n\n return both(\n sql`not exists(select 1 from ${f.table} where ${and(eq(col(f.table, f.cohortKey), id), eq(col(f.table, f.work), \"Unresolved\"))})`,\n sql`not exists(select 1 from ${g.table} where ${and(eq(col(g.table, g.cohortKey), id), eq(col(g.table, g.refreshWork), \"Unresolved\"))})`,\n );\n};\n"],"mappings":";;;;;;;;;;AA0DA,MAAa,iBAAiB,QAAQ,EAAE,gCAAgC;AACxE,MAAa,cAAc,QAAQ,EAAE,yBAAyB;AAC9D,MAAa,eAAe,QAAQ,EAAE,mBAAmB;AACzD,MAAa,sBAAsB,QAAQ,EAAE,0BAA0B;AACvE,MAAa,gBAAgB,QAAQ,EAAE,0BAA0B;AACjE,MAAa,eAAe,QAAQ,EAAE,yBAAyB;AAE/D,MAAa,mBAAmB,QAC9B,OAAO,OAAO;CACZ,OAAO,EAAE;CACT,eAAe,EA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