@yielded/auth-persistence-drizzle 0.1.0-beta.24 → 0.1.0-beta.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/D1.d.mts +495 -1151
- package/dist/D1.mjs +41 -19
- package/dist/D1.mjs.map +1 -1
- package/dist/Libsql.d.mts +385 -1996
- package/dist/Libsql.mjs +43 -47
- package/dist/Libsql.mjs.map +1 -1
- package/dist/Mysql2.d.mts +397 -1743
- package/dist/Mysql2.mjs +35 -41
- package/dist/Mysql2.mjs.map +1 -1
- package/dist/Pglite.d.mts +397 -1743
- package/dist/Pglite.mjs +42 -31
- package/dist/Pglite.mjs.map +1 -1
- package/dist/Postgres.d.mts +397 -1743
- package/dist/Postgres.mjs +42 -31
- package/dist/Postgres.mjs.map +1 -1
- package/dist/SqliteBun.d.mts +385 -1992
- package/dist/SqliteBun.mjs +43 -43
- package/dist/SqliteBun.mjs.map +1 -1
- package/dist/SqliteDo.d.mts +385 -1991
- package/dist/SqliteDo.mjs +42 -41
- package/dist/SqliteDo.mjs.map +1 -1
- package/dist/SqliteNode.d.mts +385 -1992
- package/dist/SqliteNode.mjs +43 -43
- package/dist/SqliteNode.mjs.map +1 -1
- package/dist/SqliteWasm.d.mts +385 -1992
- package/dist/SqliteWasm.mjs +43 -43
- package/dist/SqliteWasm.mjs.map +1 -1
- package/dist/drizzle/d1-identity.mjs +2 -2
- package/dist/drizzle/d1-identity.mjs.map +1 -1
- package/dist/drizzle/driver-types.d.mts +15 -0
- package/dist/drizzle/email-drivers.mjs +32 -0
- package/dist/drizzle/email-drivers.mjs.map +1 -0
- package/dist/drizzle/email-model.d.mts +9 -13
- package/dist/drizzle/email-target.d.mts +10 -11
- package/dist/drizzle/email-target.mjs +33 -70
- package/dist/drizzle/email-target.mjs.map +1 -1
- package/dist/drizzle/model.d.mts +1 -10
- package/dist/drizzle/model.mjs +1 -2
- package/dist/drizzle/model.mjs.map +1 -1
- package/dist/drizzle/mysql-identity.mjs +3 -6
- package/dist/drizzle/mysql-identity.mjs.map +1 -1
- package/dist/drizzle/native-clock.d.mts +9 -0
- package/dist/drizzle/native-clock.mjs +18 -0
- package/dist/drizzle/native-clock.mjs.map +1 -0
- package/dist/drizzle/native-database.d.mts +46 -0
- package/dist/drizzle/native-database.mjs +6 -5
- package/dist/drizzle/native-database.mjs.map +1 -1
- package/dist/drizzle/native-sql-table.mjs +13 -5
- package/dist/drizzle/native-sql-table.mjs.map +1 -1
- package/dist/drizzle/native-target.d.mts +6 -0
- package/dist/drizzle/native-target.mjs +44 -0
- package/dist/drizzle/native-target.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-drivers.mjs +4 -56
- package/dist/drizzle/oauth-connected-drivers.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-model.d.mts +5 -22
- package/dist/drizzle/oauth-connected-model.mjs +1 -7
- package/dist/drizzle/oauth-connected-reference.d.mts +5 -7
- package/dist/drizzle/oauth-connected-reference.mjs +11 -3
- package/dist/drizzle/oauth-connected-reference.mjs.map +1 -1
- package/dist/drizzle/oauth-drivers.mjs +1 -2
- package/dist/drizzle/oauth-drivers.mjs.map +1 -1
- package/dist/drizzle/oauth-model.d.mts +11 -37
- package/dist/drizzle/oauth-model.mjs +3 -4
- package/dist/drizzle/oauth-model.mjs.map +1 -1
- package/dist/drizzle/oauth-proxy.d.mts +1 -1
- package/dist/drizzle/oauth-proxy.mjs +1 -1
- package/dist/drizzle/oauth-target.d.mts +9 -6
- package/dist/drizzle/oauth-target.mjs +47 -15
- package/dist/drizzle/oauth-target.mjs.map +1 -1
- package/dist/drizzle/passkey/target.d.mts +14 -0
- package/dist/drizzle/passkey/target.mjs +52 -0
- package/dist/drizzle/passkey/target.mjs.map +1 -0
- package/dist/drizzle/passkey/write-target.d.mts +11 -0
- package/dist/drizzle/passkey/write-target.mjs +28 -0
- package/dist/drizzle/passkey/write-target.mjs.map +1 -0
- package/dist/drizzle/passkey-drivers.mjs +2 -4
- package/dist/drizzle/passkey-drivers.mjs.map +1 -1
- package/dist/drizzle/passkey-model.d.mts +5 -26
- package/dist/drizzle/passkey-model.mjs +2 -8
- package/dist/drizzle/passkey-registration-ceremony-model.d.mts +3 -6
- package/dist/drizzle/passkey-write-drivers.mjs +2 -3
- package/dist/drizzle/passkey-write-drivers.mjs.map +1 -1
- package/dist/drizzle/passkey-write-model.d.mts +7 -9
- package/dist/drizzle/passkey-write-model.mjs +1 -3
- package/dist/drizzle/passkey-write-model.mjs.map +1 -1
- package/dist/drizzle/password-drivers.mjs +31 -0
- package/dist/drizzle/password-drivers.mjs.map +1 -0
- package/dist/drizzle/password-model.d.mts +7 -10
- package/dist/drizzle/password-target.d.mts +7 -8
- package/dist/drizzle/password-target.mjs +23 -68
- package/dist/drizzle/password-target.mjs.map +1 -1
- package/dist/drizzle/pg-identity.mjs +3 -6
- package/dist/drizzle/pg-identity.mjs.map +1 -1
- package/dist/drizzle/phone-drivers.mjs +24 -0
- package/dist/drizzle/phone-drivers.mjs.map +1 -0
- package/dist/drizzle/phone-model.d.mts +13 -104
- package/dist/drizzle/phone-model.mjs +5 -33
- package/dist/drizzle/phone-model.mjs.map +1 -1
- package/dist/drizzle/phone-target.mjs +22 -171
- package/dist/drizzle/phone-target.mjs.map +1 -1
- package/dist/drizzle/proof-drivers.mjs +24 -0
- package/dist/drizzle/proof-drivers.mjs.map +1 -0
- package/dist/drizzle/proof-model.d.mts +7 -15
- package/dist/drizzle/proof-target.d.mts +5 -5
- package/dist/drizzle/proof-target.mjs +14 -28
- package/dist/drizzle/proof-target.mjs.map +1 -1
- package/dist/drizzle/session-drivers.mjs +97 -0
- package/dist/drizzle/session-drivers.mjs.map +1 -0
- package/dist/drizzle/session-model.d.mts +11 -22
- package/dist/drizzle/sqlite-do-database.d.mts +3 -3
- package/dist/drizzle/sqlite-do-database.mjs +6 -1
- package/dist/drizzle/sqlite-do-database.mjs.map +1 -1
- package/dist/drizzle/sqlite-identity.mjs +3 -5
- package/dist/drizzle/sqlite-identity.mjs.map +1 -1
- package/dist/drizzle/step-up-model.d.mts +2 -5
- package/dist/drizzle/storage-validation.mjs +2 -1
- package/dist/drizzle/storage-validation.mjs.map +1 -1
- package/dist/drizzle/totp-model.d.mts +7 -74
- package/dist/drizzle/totp-model.mjs +1 -5
- package/dist/drizzle/totp-model.mjs.map +1 -1
- package/dist/drizzle/totp-target.mjs +39 -75
- package/dist/drizzle/totp-target.mjs.map +1 -1
- package/dist/drizzle/transaction-handle.mjs +13 -0
- package/dist/drizzle/transaction-handle.mjs.map +1 -0
- package/dist/drizzle/transaction-mysql.mjs +43 -12
- package/dist/drizzle/transaction-mysql.mjs.map +1 -1
- package/dist/index.d.mts +17 -22
- package/dist/index.mjs +10 -16
- package/dist/internal/drizzle-postgres.mjs +4 -6
- package/dist/internal/drizzle-postgres.mjs.map +1 -1
- package/dist/internal/drizzle-sqlite.mjs +4 -6
- package/dist/internal/drizzle-sqlite.mjs.map +1 -1
- package/package.json +1 -1
- package/src/D1.ts +77 -74
- package/src/Libsql.ts +65 -105
- package/src/Mysql2.ts +52 -87
- package/src/Pglite.ts +74 -81
- package/src/Postgres.ts +74 -81
- package/src/SqliteBun.ts +65 -113
- package/src/SqliteDo.ts +58 -106
- package/src/SqliteNode.ts +65 -113
- package/src/SqliteWasm.ts +65 -113
- package/src/drizzle/d1-identity.ts +2 -2
- package/src/drizzle/driver-types.ts +26 -0
- package/src/drizzle/email-drivers.ts +320 -0
- package/src/drizzle/email-model.ts +24 -78
- package/src/drizzle/email-target.ts +118 -211
- package/src/drizzle/model.ts +0 -2
- package/src/drizzle/mysql-identity.ts +4 -24
- package/src/drizzle/native-clock.ts +21 -0
- package/src/drizzle/native-database.ts +59 -18
- package/src/drizzle/native-sql-table.ts +104 -87
- package/src/drizzle/native-target.ts +120 -0
- package/src/drizzle/oauth-connected-drivers.ts +24 -233
- package/src/drizzle/oauth-connected-model.ts +3 -93
- package/src/drizzle/oauth-connected-reference.ts +16 -25
- package/src/drizzle/oauth-drivers.ts +58 -99
- package/src/drizzle/oauth-model.ts +27 -132
- package/src/drizzle/oauth-target.ts +250 -33
- package/src/drizzle/passkey/target.ts +205 -0
- package/src/drizzle/passkey/write-target.ts +91 -0
- package/src/drizzle/passkey-drivers.ts +35 -133
- package/src/drizzle/passkey-model.ts +3 -81
- package/src/drizzle/passkey-registration-ceremony-model.ts +5 -25
- package/src/drizzle/passkey-write-drivers.ts +32 -102
- package/src/drizzle/passkey-write-model.ts +10 -44
- package/src/drizzle/password-drivers.ts +286 -0
- package/src/drizzle/password-model.ts +10 -44
- package/src/drizzle/password-target.ts +85 -239
- package/src/drizzle/pg-identity.ts +4 -19
- package/src/drizzle/phone-drivers.ts +142 -0
- package/src/drizzle/phone-model.ts +22 -162
- package/src/drizzle/phone-target.ts +51 -493
- package/src/drizzle/proof-drivers.ts +123 -0
- package/src/drizzle/proof-model.ts +12 -123
- package/src/drizzle/proof-target.ts +38 -102
- package/src/drizzle/session-drivers.ts +696 -0
- package/src/drizzle/session-model.ts +54 -118
- package/src/drizzle/sqlite-do-database.ts +8 -0
- package/src/drizzle/sqlite-identity.ts +4 -22
- package/src/drizzle/step-up-model.ts +13 -37
- package/src/drizzle/storage-validation.ts +2 -1
- package/src/drizzle/totp-model.ts +20 -77
- package/src/drizzle/totp-target.ts +121 -261
- package/src/drizzle/transaction-handle.ts +41 -0
- package/src/drizzle/transaction-mysql.ts +90 -25
- package/src/index.ts +7 -122
- package/src/internal/drizzle-postgres.ts +4 -7
- package/src/internal/drizzle-sqlite.ts +4 -7
- package/dist/drizzle/crypto.mjs +0 -11
- package/dist/drizzle/crypto.mjs.map +0 -1
- package/dist/drizzle/d1-emails.d.mts +0 -62
- package/dist/drizzle/d1-emails.mjs +0 -626
- package/dist/drizzle/d1-emails.mjs.map +0 -1
- package/dist/drizzle/d1-generated-statement.mjs +0 -79
- package/dist/drizzle/d1-generated-statement.mjs.map +0 -1
- package/dist/drizzle/d1-oauth.d.mts +0 -331
- package/dist/drizzle/d1-oauth.mjs +0 -79
- package/dist/drizzle/d1-oauth.mjs.map +0 -1
- package/dist/drizzle/d1-passkey.d.mts +0 -37
- package/dist/drizzle/d1-passkey.mjs +0 -98
- package/dist/drizzle/d1-passkey.mjs.map +0 -1
- package/dist/drizzle/d1-password-prepared.d.mts +0 -25
- package/dist/drizzle/d1-password-prepared.mjs +0 -473
- package/dist/drizzle/d1-password-prepared.mjs.map +0 -1
- package/dist/drizzle/d1-passwords.d.mts +0 -70
- package/dist/drizzle/d1-passwords.mjs +0 -808
- package/dist/drizzle/d1-passwords.mjs.map +0 -1
- package/dist/drizzle/d1-phone.d.mts +0 -23
- package/dist/drizzle/d1-phone.mjs +0 -33
- package/dist/drizzle/d1-phone.mjs.map +0 -1
- package/dist/drizzle/d1-planning.d.mts +0 -11
- package/dist/drizzle/d1-planning.mjs +0 -43
- package/dist/drizzle/d1-planning.mjs.map +0 -1
- package/dist/drizzle/d1-proofs.d.mts +0 -80
- package/dist/drizzle/d1-proofs.mjs +0 -842
- package/dist/drizzle/d1-proofs.mjs.map +0 -1
- package/dist/drizzle/d1-sessions.d.mts +0 -68
- package/dist/drizzle/d1-sessions.mjs +0 -987
- package/dist/drizzle/d1-sessions.mjs.map +0 -1
- package/dist/drizzle/d1-totp.d.mts +0 -23
- package/dist/drizzle/d1-totp.mjs +0 -30
- package/dist/drizzle/d1-totp.mjs.map +0 -1
- package/dist/drizzle/email-registration.d.mts +0 -33
- package/dist/drizzle/email-registration.mjs +0 -281
- package/dist/drizzle/email-registration.mjs.map +0 -1
- package/dist/drizzle/email-sql.d.mts +0 -1
- package/dist/drizzle/email-sql.mjs +0 -9
- package/dist/drizzle/email-sql.mjs.map +0 -1
- package/dist/drizzle/mysql-emails.d.mts +0 -71
- package/dist/drizzle/mysql-emails.mjs +0 -43
- package/dist/drizzle/mysql-emails.mjs.map +0 -1
- package/dist/drizzle/mysql-password-prepared.d.mts +0 -30
- package/dist/drizzle/mysql-password-prepared.mjs +0 -21
- package/dist/drizzle/mysql-password-prepared.mjs.map +0 -1
- package/dist/drizzle/mysql-passwords.d.mts +0 -71
- package/dist/drizzle/mysql-passwords.mjs +0 -43
- package/dist/drizzle/mysql-passwords.mjs.map +0 -1
- package/dist/drizzle/mysql-proofs.d.mts +0 -75
- package/dist/drizzle/mysql-proofs.mjs +0 -28
- package/dist/drizzle/mysql-proofs.mjs.map +0 -1
- package/dist/drizzle/mysql-sessions.d.mts +0 -92
- package/dist/drizzle/mysql-sessions.mjs +0 -58
- package/dist/drizzle/mysql-sessions.mjs.map +0 -1
- package/dist/drizzle/oauth-connected-model.mjs.map +0 -1
- package/dist/drizzle/oauth-connected-target.d.mts +0 -6
- package/dist/drizzle/oauth-connected-target.mjs +0 -12
- package/dist/drizzle/oauth-connected-target.mjs.map +0 -1
- package/dist/drizzle/oauth-kernel.mjs +0 -11
- package/dist/drizzle/oauth-kernel.mjs.map +0 -1
- package/dist/drizzle/oauth-mysql.mjs +0 -8
- package/dist/drizzle/oauth-mysql.mjs.map +0 -1
- package/dist/drizzle/passkey-kernel.mjs +0 -8
- package/dist/drizzle/passkey-kernel.mjs.map +0 -1
- package/dist/drizzle/passkey-model.mjs.map +0 -1
- package/dist/drizzle/passkey-registration-ceremony-model.mjs +0 -2
- package/dist/drizzle/passkey-state.mjs +0 -7
- package/dist/drizzle/passkey-state.mjs.map +0 -1
- package/dist/drizzle/passkey-target.d.mts +0 -2
- package/dist/drizzle/passkey-target.mjs +0 -7
- package/dist/drizzle/passkey-target.mjs.map +0 -1
- package/dist/drizzle/passkey-write-target.d.mts +0 -5
- package/dist/drizzle/passkey-write-target.mjs +0 -7
- package/dist/drizzle/passkey-write-target.mjs.map +0 -1
- package/dist/drizzle/password-prepared-model.d.mts +0 -92
- package/dist/drizzle/password-prepared-model.mjs +0 -11
- package/dist/drizzle/password-prepared-model.mjs.map +0 -1
- package/dist/drizzle/password-prepared-sql.mjs +0 -395
- package/dist/drizzle/password-prepared-sql.mjs.map +0 -1
- package/dist/drizzle/password-prepared-state.mjs +0 -104
- package/dist/drizzle/password-prepared-state.mjs.map +0 -1
- package/dist/drizzle/password-prepared-target.d.mts +0 -13
- package/dist/drizzle/password-prepared-target.mjs +0 -62
- package/dist/drizzle/password-prepared-target.mjs.map +0 -1
- package/dist/drizzle/password-registration.d.mts +0 -7
- package/dist/drizzle/password-registration.mjs +0 -137
- package/dist/drizzle/password-registration.mjs.map +0 -1
- package/dist/drizzle/password-sql.d.mts +0 -1
- package/dist/drizzle/password-sql.mjs +0 -10
- package/dist/drizzle/password-sql.mjs.map +0 -1
- package/dist/drizzle/pg-emails.d.mts +0 -72
- package/dist/drizzle/pg-emails.mjs +0 -43
- package/dist/drizzle/pg-emails.mjs.map +0 -1
- package/dist/drizzle/pg-password-prepared.d.mts +0 -31
- package/dist/drizzle/pg-password-prepared.mjs +0 -21
- package/dist/drizzle/pg-password-prepared.mjs.map +0 -1
- package/dist/drizzle/pg-passwords.d.mts +0 -72
- package/dist/drizzle/pg-passwords.mjs +0 -43
- package/dist/drizzle/pg-passwords.mjs.map +0 -1
- package/dist/drizzle/pg-proofs.d.mts +0 -76
- package/dist/drizzle/pg-proofs.mjs +0 -27
- package/dist/drizzle/pg-proofs.mjs.map +0 -1
- package/dist/drizzle/pg-sessions.d.mts +0 -93
- package/dist/drizzle/pg-sessions.mjs +0 -58
- package/dist/drizzle/pg-sessions.mjs.map +0 -1
- package/dist/drizzle/phone-state.mjs +0 -14
- package/dist/drizzle/phone-state.mjs.map +0 -1
- package/dist/drizzle/phone-target.d.mts +0 -15
- package/dist/drizzle/proof-sql.d.mts +0 -1
- package/dist/drizzle/proof-sql.mjs +0 -8
- package/dist/drizzle/proof-sql.mjs.map +0 -1
- package/dist/drizzle/query-operations.mjs +0 -31
- package/dist/drizzle/query-operations.mjs.map +0 -1
- package/dist/drizzle/session-sql.d.mts +0 -1
- package/dist/drizzle/session-sql.mjs +0 -9
- package/dist/drizzle/session-sql.mjs.map +0 -1
- package/dist/drizzle/session-target.d.mts +0 -30
- package/dist/drizzle/session-target.mjs +0 -49
- package/dist/drizzle/session-target.mjs.map +0 -1
- package/dist/drizzle/sqlite-emails.mjs +0 -50
- package/dist/drizzle/sqlite-emails.mjs.map +0 -1
- package/dist/drizzle/sqlite-password-prepared.mjs +0 -26
- package/dist/drizzle/sqlite-password-prepared.mjs.map +0 -1
- package/dist/drizzle/sqlite-passwords.mjs +0 -54
- package/dist/drizzle/sqlite-passwords.mjs.map +0 -1
- package/dist/drizzle/sqlite-proofs.mjs +0 -34
- package/dist/drizzle/sqlite-proofs.mjs.map +0 -1
- package/dist/drizzle/sqlite-sessions.mjs +0 -79
- package/dist/drizzle/sqlite-sessions.mjs.map +0 -1
- package/dist/drizzle/standalone-guard.d.mts +0 -2
- package/dist/drizzle/standalone-guard.mjs +0 -21
- package/dist/drizzle/standalone-guard.mjs.map +0 -1
- package/dist/drizzle/totp-state.d.mts +0 -37
- package/dist/drizzle/totp-state.mjs +0 -287
- package/dist/drizzle/totp-state.mjs.map +0 -1
- package/dist/drizzle/totp-target.d.mts +0 -15
- package/dist/drizzle/transaction-execution.d.mts +0 -2
- package/dist/drizzle/transaction-execution.mjs +0 -11
- package/dist/drizzle/transaction-execution.mjs.map +0 -1
- package/dist/drizzle/transaction-owner.d.mts +0 -1
- package/dist/drizzle/transaction-owner.mjs +0 -8
- package/dist/drizzle/transaction-owner.mjs.map +0 -1
- package/src/drizzle/crypto.ts +0 -14
- package/src/drizzle/d1-emails.ts +0 -1945
- package/src/drizzle/d1-generated-statement.ts +0 -129
- package/src/drizzle/d1-oauth.ts +0 -360
- package/src/drizzle/d1-passkey.ts +0 -383
- package/src/drizzle/d1-password-prepared.ts +0 -1265
- package/src/drizzle/d1-passwords.ts +0 -2060
- package/src/drizzle/d1-phone.ts +0 -103
- package/src/drizzle/d1-planning.ts +0 -104
- package/src/drizzle/d1-proofs.ts +0 -2354
- package/src/drizzle/d1-sessions.ts +0 -2940
- package/src/drizzle/d1-totp.ts +0 -88
- package/src/drizzle/email-registration.ts +0 -850
- package/src/drizzle/email-sql.ts +0 -25
- package/src/drizzle/mysql-emails.ts +0 -343
- package/src/drizzle/mysql-password-prepared.ts +0 -198
- package/src/drizzle/mysql-passwords.ts +0 -343
- package/src/drizzle/mysql-proofs.ts +0 -196
- package/src/drizzle/mysql-sessions.ts +0 -780
- package/src/drizzle/oauth-connected-target.ts +0 -21
- package/src/drizzle/oauth-kernel.ts +0 -10
- package/src/drizzle/oauth-mysql.ts +0 -10
- package/src/drizzle/passkey-kernel.ts +0 -4
- package/src/drizzle/passkey-state.ts +0 -3
- package/src/drizzle/passkey-target.ts +0 -23
- package/src/drizzle/passkey-write-target.ts +0 -9
- package/src/drizzle/password-prepared-model.ts +0 -241
- package/src/drizzle/password-prepared-sql.ts +0 -1201
- package/src/drizzle/password-prepared-state.ts +0 -231
- package/src/drizzle/password-prepared-target.ts +0 -169
- package/src/drizzle/password-registration.ts +0 -369
- package/src/drizzle/password-sql.ts +0 -16
- package/src/drizzle/pg-emails.ts +0 -343
- package/src/drizzle/pg-password-prepared.ts +0 -199
- package/src/drizzle/pg-passwords.ts +0 -342
- package/src/drizzle/pg-proofs.ts +0 -206
- package/src/drizzle/pg-sessions.ts +0 -789
- package/src/drizzle/phone-state.ts +0 -21
- package/src/drizzle/proof-sql.ts +0 -10
- package/src/drizzle/query-operations.ts +0 -49
- package/src/drizzle/session-sql.ts +0 -15
- package/src/drizzle/session-target.ts +0 -337
- package/src/drizzle/sqlite-emails.ts +0 -393
- package/src/drizzle/sqlite-password-prepared.ts +0 -230
- package/src/drizzle/sqlite-passwords.ts +0 -497
- package/src/drizzle/sqlite-proofs.ts +0 -229
- package/src/drizzle/sqlite-sessions.ts +0 -1013
- package/src/drizzle/totp-state.ts +0 -525
- package/src/drizzle/transaction-execution.ts +0 -13
- package/src/drizzle/transaction-owner.ts +0 -11
|
@@ -1,808 +0,0 @@
|
|
|
1
|
-
import { requiredPasswordConstraints, requiredPasswordRegistrationConstraints } from "./password-model.mjs";
|
|
2
|
-
import { PersistenceMappingError as PersistenceMappingError$1, column, isMappedConstraintConflict, updateValues } from "./model.mjs";
|
|
3
|
-
import { balancedD1And } from "./d1-generated-statement.mjs";
|
|
4
|
-
import { validateDrizzleStorage } from "./storage-validation.mjs";
|
|
5
|
-
import { Database } from "./d1-database.mjs";
|
|
6
|
-
import { D1BatchStatements } from "./D1BatchStatements.mjs";
|
|
7
|
-
import { CurrentD1PlanningDatabase, makeD1Owner } from "./d1-planning.mjs";
|
|
8
|
-
import { nativeDatabase } from "./native-database.mjs";
|
|
9
|
-
import { compileD1ProofCompletionPlan } from "./d1-proofs.mjs";
|
|
10
|
-
import { NativeDatabase, requireStandalone, samePasswordCredentialSnapshot } from "@yielded/auth-persistence/Adapter";
|
|
11
|
-
import { and, eq, getTableColumns, inArray, sql } from "drizzle-orm";
|
|
12
|
-
import { Cause, Context, DateTime, Effect, Option, Predicate, Redacted, Schema } from "effect";
|
|
13
|
-
import { CurrentCommitJournal, HookConfigurationError, LifecycleHooks, coordinateCommit, hasCommitScope } from "@yielded/auth/Hooks";
|
|
14
|
-
import { AuthenticationEvidence, AuthenticationRequirement, snapshotAuthenticationEvidence } from "@yielded/auth/Sessions";
|
|
15
|
-
import { reportPersistenceFailure } from "@yielded/auth/Persistence";
|
|
16
|
-
import { ProofUnavailable } from "@yielded/auth/Proofs";
|
|
17
|
-
import { EncodedPasswordHash, PasswordPersistence, PasswordUnavailable, snapshotPasswordCredential, snapshotPasswordRequirement, snapshotPasswordRevision } from "@yielded/auth/Password";
|
|
18
|
-
//#region src/drizzle/d1-passwords.ts
|
|
19
|
-
const unavailable = () => PasswordUnavailable.make({});
|
|
20
|
-
const everyFailureMatches = (cause, classify) => classify !== void 0 && cause.reasons.length > 0 && cause.reasons.every((reason) => Cause.isFailReason(reason) && classify(Cause.fail(reason.error)));
|
|
21
|
-
const validConstraints = (mapping) => Object.entries(requiredPasswordConstraints).every(([key, value]) => mapping.constraints[key] === value);
|
|
22
|
-
const validRegistrationConstraints = (mapping) => Object.entries(requiredPasswordRegistrationConstraints).every(([key, value]) => mapping.constraints[key] === value);
|
|
23
|
-
const containsFailure = (failure, predicate) => {
|
|
24
|
-
const seen = /* @__PURE__ */ new Set();
|
|
25
|
-
const pending = [failure];
|
|
26
|
-
for (let inspected = 0; inspected < 32 && pending.length > 0; inspected++) {
|
|
27
|
-
const current = pending.shift();
|
|
28
|
-
if (current === void 0 || current === null || seen.has(current)) continue;
|
|
29
|
-
seen.add(current);
|
|
30
|
-
if (predicate(current)) return true;
|
|
31
|
-
if (Cause.isCause(current)) {
|
|
32
|
-
for (const reason of current.reasons) if (Cause.isFailReason(reason)) pending.push(reason.error);
|
|
33
|
-
else if (Cause.isDieReason(reason)) pending.push(reason.defect);
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
if (typeof current !== "object") continue;
|
|
37
|
-
const wrapped = current;
|
|
38
|
-
if (wrapped.cause !== void 0) pending.push(wrapped.cause);
|
|
39
|
-
if (wrapped.reason !== void 0) pending.push(wrapped.reason);
|
|
40
|
-
if (wrapped.message !== void 0) pending.push(wrapped.message);
|
|
41
|
-
}
|
|
42
|
-
return false;
|
|
43
|
-
};
|
|
44
|
-
const isGuardFailure = (cause, marker) => {
|
|
45
|
-
const native = `bad JSON path: '${`$[${marker.replaceAll("'", "''")}]`}': SQLITE_ERROR`;
|
|
46
|
-
return containsFailure(cause, (value) => value === native || value === `D1_ERROR: ${native}`);
|
|
47
|
-
};
|
|
48
|
-
const statement = Effect.fn(function* (query) {
|
|
49
|
-
const database = yield* CurrentD1PlanningDatabase;
|
|
50
|
-
const rendered = query.toSQL();
|
|
51
|
-
return database.$client.unsafe(rendered.sql, rendered.params);
|
|
52
|
-
});
|
|
53
|
-
const assertion = Effect.fn(function* (condition, marker) {
|
|
54
|
-
const database = yield* CurrentD1PlanningDatabase;
|
|
55
|
-
return yield* statement(database.select({ ok: sql`case when ${condition} then 1 else json_extract('[]', ${`$[${marker}]`}) end`.as("ok") }).from(sql`(select 1)`));
|
|
56
|
-
});
|
|
57
|
-
const readEngineNowMillis = Effect.fn("Drizzle.readEngineNowMillis")(function* (mapping) {
|
|
58
|
-
return yield* (yield* CurrentD1PlanningDatabase).select({ value: mapping.d1.engineNowMillis.as("engine_now_millis") }).from(sql`(select 1)`).pipe(Effect.flatMap((rows) => {
|
|
59
|
-
const value = Number(rows[0]?.value);
|
|
60
|
-
return Number.isFinite(value) ? Effect.succeed(value) : Effect.fail(unavailable());
|
|
61
|
-
}));
|
|
62
|
-
});
|
|
63
|
-
const allocate = (asyncValue, syncValue) => asyncValue !== void 0 ? asyncValue : syncValue === void 0 ? Effect.fail(unavailable()) : Effect.try({
|
|
64
|
-
try: syncValue,
|
|
65
|
-
catch: (cause) => new PersistenceMappingError$1({
|
|
66
|
-
operation: "mapping",
|
|
67
|
-
cause
|
|
68
|
-
})
|
|
69
|
-
});
|
|
70
|
-
const allocateNextSecurityRevision = (mapping, current) => allocate(mapping.subject.nextSecurityRevision?.(current) ?? mapping.allocateRevision, mapping.subject.nextSecurityRevisionSync === void 0 ? mapping.allocateRevisionSync : () => mapping.subject.nextSecurityRevisionSync(current));
|
|
71
|
-
const subjectColumns = (mapping) => ({
|
|
72
|
-
id: column(mapping.subject.table, mapping.subject.id),
|
|
73
|
-
status: column(mapping.subject.table, mapping.subject.status),
|
|
74
|
-
securityRevision: column(mapping.subject.table, mapping.subject.securityRevision)
|
|
75
|
-
});
|
|
76
|
-
const identifierColumns = (mapping) => ({
|
|
77
|
-
namespace: column(mapping.identifier.table, mapping.identifier.namespace),
|
|
78
|
-
value: column(mapping.identifier.table, mapping.identifier.value),
|
|
79
|
-
subjectId: column(mapping.identifier.table, mapping.identifier.subjectId),
|
|
80
|
-
verifiedAt: column(mapping.identifier.table, mapping.identifier.verifiedAt),
|
|
81
|
-
bindingRevision: column(mapping.identifier.table, mapping.identifier.bindingRevision)
|
|
82
|
-
});
|
|
83
|
-
const credentialColumns = (mapping) => ({
|
|
84
|
-
moduleId: column(mapping.credential.table, mapping.credential.moduleId),
|
|
85
|
-
subjectId: column(mapping.credential.table, mapping.credential.subjectId),
|
|
86
|
-
credentialId: column(mapping.credential.table, mapping.credential.credentialId),
|
|
87
|
-
credentialRevision: column(mapping.credential.table, mapping.credential.credentialRevision),
|
|
88
|
-
verifierVersion: column(mapping.credential.table, mapping.credential.verifierVersion),
|
|
89
|
-
verifier: column(mapping.credential.table, mapping.credential.verifier),
|
|
90
|
-
normalization: column(mapping.credential.table, mapping.credential.normalization)
|
|
91
|
-
});
|
|
92
|
-
const authorityColumns = (mapping) => ({
|
|
93
|
-
subjectId: column(mapping.authorityCredential.table, mapping.authorityCredential.subjectId),
|
|
94
|
-
credentialId: column(mapping.authorityCredential.table, mapping.authorityCredential.credentialId),
|
|
95
|
-
revision: column(mapping.authorityCredential.table, mapping.authorityCredential.revision),
|
|
96
|
-
status: mapping.authorityCredential.status === void 0 ? void 0 : column(mapping.authorityCredential.table, mapping.authorityCredential.status)
|
|
97
|
-
});
|
|
98
|
-
const commandColumns = (mapping) => ({
|
|
99
|
-
moduleId: column(mapping.command.table, mapping.command.moduleId),
|
|
100
|
-
commandId: column(mapping.command.table, mapping.command.commandId),
|
|
101
|
-
action: column(mapping.command.table, mapping.command.action),
|
|
102
|
-
bindingDigest: column(mapping.command.table, mapping.command.bindingDigest),
|
|
103
|
-
decision: column(mapping.command.table, mapping.command.decision),
|
|
104
|
-
retentionUntil: column(mapping.command.table, mapping.command.retentionUntil)
|
|
105
|
-
});
|
|
106
|
-
const readIdentifier = Effect.fn("Drizzle.readIdentifier")(function* (mapping, identifier) {
|
|
107
|
-
const database = yield* CurrentD1PlanningDatabase;
|
|
108
|
-
const c = identifierColumns(mapping);
|
|
109
|
-
return yield* database.select().from(mapping.identifier.table).where(and(eq(c.namespace, identifier.namespace), eq(c.value, identifier.value))).limit(1);
|
|
110
|
-
});
|
|
111
|
-
const readSubjectNative = Effect.fn("Drizzle.readSubjectNative")(function* (mapping, nativeSubjectId) {
|
|
112
|
-
return yield* (yield* CurrentD1PlanningDatabase).select().from(mapping.subject.table).where(eq(subjectColumns(mapping).id, nativeSubjectId)).limit(1);
|
|
113
|
-
});
|
|
114
|
-
const readCredentialNative = Effect.fn("Drizzle.readCredentialNative")(function* (mapping, moduleId, nativeSubjectId) {
|
|
115
|
-
const database = yield* CurrentD1PlanningDatabase;
|
|
116
|
-
const c = credentialColumns(mapping);
|
|
117
|
-
return yield* database.select().from(mapping.credential.table).where(and(eq(c.moduleId, moduleId), eq(c.subjectId, nativeSubjectId))).limit(1);
|
|
118
|
-
});
|
|
119
|
-
const resolveCredential = Effect.fn("DrizzleD1Password.resolveCredential")(function* (mapping, moduleId, identifier, requestedSubjectId) {
|
|
120
|
-
const identifierRow = (yield* readIdentifier(mapping, identifier))[0];
|
|
121
|
-
if (identifierRow === void 0 || !mapping.identifier.isCurrent(identifierRow)) return void 0;
|
|
122
|
-
const nativeSubjectId = identifierRow[mapping.identifier.subjectId];
|
|
123
|
-
const subject = (yield* readSubjectNative(mapping, nativeSubjectId))[0];
|
|
124
|
-
if (subject === void 0 || !mapping.subject.isActiveStatus(subject[mapping.subject.status])) return void 0;
|
|
125
|
-
const subjectId = yield* mapping.subjectId.toSubject(nativeSubjectId);
|
|
126
|
-
if (requestedSubjectId !== void 0 && subjectId !== requestedSubjectId) return void 0;
|
|
127
|
-
const credential = (yield* readCredentialNative(mapping, moduleId, nativeSubjectId))[0];
|
|
128
|
-
if (credential === void 0) return {
|
|
129
|
-
nativeSubjectId,
|
|
130
|
-
subject,
|
|
131
|
-
identifier: identifierRow
|
|
132
|
-
};
|
|
133
|
-
return {
|
|
134
|
-
nativeSubjectId,
|
|
135
|
-
subject,
|
|
136
|
-
identifier: identifierRow,
|
|
137
|
-
credential,
|
|
138
|
-
snapshot: yield* mapping.credential.decode({
|
|
139
|
-
moduleId,
|
|
140
|
-
subject,
|
|
141
|
-
identifier: identifierRow,
|
|
142
|
-
credential
|
|
143
|
-
}).pipe(Effect.flatMap(snapshotPasswordCredential))
|
|
144
|
-
};
|
|
145
|
-
});
|
|
146
|
-
const evidenceProofsJson = Schema.encodeSync(Schema.fromJsonString(AuthenticationEvidence.fields.proofs));
|
|
147
|
-
const alternativesJson = Schema.encodeSync(Schema.fromJsonString(AuthenticationRequirement.fields.alternatives));
|
|
148
|
-
const assuranceCondition = (mapping, evidence, requirement) => {
|
|
149
|
-
const proofs = evidenceProofsJson(evidence.proofs);
|
|
150
|
-
const fresh = sql`json_extract(proof.value, '$.verifiedAt') <= ${mapping.d1.engineNowMillis} and ${mapping.d1.engineNowMillis} - json_extract(proof.value, '$.verifiedAt') < ${requirement.maximumAgeMillis}`;
|
|
151
|
-
return sql`exists(
|
|
152
|
-
select 1 from json_each(${alternativesJson(requirement.alternatives)}) as alternative
|
|
153
|
-
where not exists(select 1 from json_each(${proofs}) as proof where json_extract(proof.value, '$.verifiedAt') > ${mapping.d1.engineNowMillis})
|
|
154
|
-
and not exists(select 1 from json_each(alternative.value, '$.factors') as factor where not exists(select 1 from json_each(${proofs}) as proof, json_each(proof.value, '$.factors') as held where ${fresh} and held.value = factor.value))
|
|
155
|
-
and (select count(distinct json_extract(proof.value, '$.credentialId')) from json_each(${proofs}) as proof where ${fresh}) >= json_extract(alternative.value, '$.minimumCredentials')
|
|
156
|
-
and exists(select 1 from json_each(${proofs}) as proof where ${fresh} and (json_extract(alternative.value, '$.userVerified') = 0 or json_extract(proof.value, '$.userVerified') = 1) and (json_extract(alternative.value, '$.phishingResistant') = 0 or json_extract(proof.value, '$.phishingResistant') = 1))
|
|
157
|
-
)`;
|
|
158
|
-
};
|
|
159
|
-
const sameIdentifier = (left, right) => left.namespace === right.namespace && left.value === right.value;
|
|
160
|
-
const evidenceSatisfiedAt = (evidence, requirement, now) => {
|
|
161
|
-
if (evidence.proofs.length > 64 || evidence.revision.credentials.length > 64) return false;
|
|
162
|
-
const revisions = /* @__PURE__ */ new Map();
|
|
163
|
-
for (const revision of evidence.revision.credentials) {
|
|
164
|
-
if (revisions.has(revision.credentialId)) return false;
|
|
165
|
-
revisions.set(revision.credentialId, revision.revision);
|
|
166
|
-
}
|
|
167
|
-
if (evidence.proofs.some((proof) => !revisions.has(proof.credentialId))) return false;
|
|
168
|
-
if (evidence.proofs.some((proof) => now < DateTime.toEpochMillis(proof.verifiedAt))) return false;
|
|
169
|
-
const fresh = evidence.proofs.filter((proof) => now - DateTime.toEpochMillis(proof.verifiedAt) < requirement.maximumAgeMillis);
|
|
170
|
-
const factors = new Set(fresh.flatMap((proof) => proof.factors));
|
|
171
|
-
const credentials = new Set(fresh.map((proof) => proof.credentialId));
|
|
172
|
-
return requirement.alternatives.some((alternative) => alternative.factors.every((factor) => factors.has(factor)) && credentials.size >= alternative.minimumCredentials && fresh.some((proof) => (!alternative.userVerified || proof.userVerified) && (!alternative.phishingResistant || proof.phishingResistant)));
|
|
173
|
-
};
|
|
174
|
-
const snapshotMutationInput = Effect.fn("DrizzleD1Password.snapshotMutationInput")(function* (input) {
|
|
175
|
-
const expectedRevision = snapshotPasswordRevision(input.expectedRevision);
|
|
176
|
-
const evidence = yield* snapshotAuthenticationEvidence(input.authorization.evidence).pipe(Effect.mapError(unavailable));
|
|
177
|
-
const requirement = yield* snapshotPasswordRequirement(input.authorization.requirement);
|
|
178
|
-
const credential = input.credential === void 0 ? void 0 : yield* snapshotPasswordCredential(input.credential);
|
|
179
|
-
return Object.freeze({
|
|
180
|
-
...input,
|
|
181
|
-
expectedRevision,
|
|
182
|
-
replacement: Object.freeze({
|
|
183
|
-
verifier: Redacted.make(Redacted.value(input.replacement.verifier)),
|
|
184
|
-
normalization: input.replacement.normalization
|
|
185
|
-
}),
|
|
186
|
-
invalidation: Object.freeze({ ...input.invalidation }),
|
|
187
|
-
...credential === void 0 ? {} : { credential },
|
|
188
|
-
authorization: Object.freeze({
|
|
189
|
-
challenge: Object.freeze({
|
|
190
|
-
...input.authorization.challenge,
|
|
191
|
-
revision: snapshotPasswordRevision(input.authorization.challenge.revision)
|
|
192
|
-
}),
|
|
193
|
-
evidence,
|
|
194
|
-
requirement
|
|
195
|
-
})
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
const completionMatchesPassword = (input) => {
|
|
199
|
-
const completion = input.completion.input;
|
|
200
|
-
const binding = completion.binding;
|
|
201
|
-
if (completion.moduleId !== `${input.moduleId}/reset` || completion.purpose !== "password-reset" || binding._tag !== "Subject" || input.credential === void 0 || binding.revision.subjectId !== input.expectedRevision.subjectId || binding.revision.securityRevision !== input.expectedRevision.securityRevision || !sameIdentifier(binding.identifier, input.credential.identifier)) return false;
|
|
202
|
-
const expected = [...input.expectedRevision.credentials].sort((left, right) => left.credentialId.localeCompare(right.credentialId));
|
|
203
|
-
const actual = [...binding.revision.credentials].sort((left, right) => left.credentialId.localeCompare(right.credentialId));
|
|
204
|
-
return expected.length === actual.length && expected.every((item, index) => item.credentialId === actual[index].credentialId && item.revision === actual[index].revision);
|
|
205
|
-
};
|
|
206
|
-
const probeProofCompletion = Effect.fn("DrizzleD1.probeProofCompletion")(function* (mapping, input) {
|
|
207
|
-
const database = yield* CurrentD1PlanningDatabase;
|
|
208
|
-
const plan = {
|
|
209
|
-
input,
|
|
210
|
-
prepare: (decision, journal, project) => journal.prepare(project(decision))
|
|
211
|
-
};
|
|
212
|
-
const marker = `effect-auth-proof-guard:protected:${input.continuationId}`;
|
|
213
|
-
return yield* coordinateCommit(() => Effect.gen(function* () {
|
|
214
|
-
const compiled = yield* compileD1ProofCompletionPlan(mapping, plan, {
|
|
215
|
-
statements: [],
|
|
216
|
-
appliedCondition: sql`false`
|
|
217
|
-
}, () => false);
|
|
218
|
-
if (compiled.statements.length === 0) return false;
|
|
219
|
-
yield* database.$client.batch(compiled.statements);
|
|
220
|
-
return false;
|
|
221
|
-
}), { mode: "batch" }).pipe(Effect.as(false), Effect.catchCause((cause) => isGuardFailure(cause, marker) ? Effect.succeed(true) : Effect.failCause(cause)));
|
|
222
|
-
});
|
|
223
|
-
const identifierCurrentCondition = (mapping, input, nativeSubjectId, nativeVerifiedAt) => {
|
|
224
|
-
if (input.credential === void 0) return sql`true`;
|
|
225
|
-
const ic = identifierColumns(mapping), snapshot = input.credential;
|
|
226
|
-
return and(mapping.identifier.d1CurrentCondition({
|
|
227
|
-
identifier: snapshot.identifier,
|
|
228
|
-
nativeSubjectId
|
|
229
|
-
}), sql`exists(select 1 from ${mapping.identifier.table} where ${ic.namespace} = ${sql.param(snapshot.identifier.namespace, ic.namespace)} and ${ic.value} = ${sql.param(snapshot.identifier.value, ic.value)} and ${ic.subjectId} = ${sql.param(nativeSubjectId, ic.subjectId)} and ${ic.bindingRevision} = ${sql.param(snapshot.identifierBindingRevision, ic.bindingRevision)} and ${Predicate.isNullish(nativeVerifiedAt) ? sql`${ic.verifiedAt} is null` : sql`${ic.verifiedAt} = ${sql.param(nativeVerifiedAt, ic.verifiedAt)}`})`);
|
|
230
|
-
};
|
|
231
|
-
const readAuthority = Effect.fn("DrizzleD1Password.readAuthority")(function* (mapping, input, action) {
|
|
232
|
-
const database = yield* CurrentD1PlanningDatabase;
|
|
233
|
-
if (input.authorization.evidence.proofs.length > 64 || input.authorization.evidence.revision.credentials.length > 64) return void 0;
|
|
234
|
-
const revisionIds = new Set(input.authorization.evidence.revision.credentials.map((item) => item.credentialId));
|
|
235
|
-
if (revisionIds.size !== input.authorization.evidence.revision.credentials.length || input.authorization.evidence.proofs.some((proof) => !revisionIds.has(proof.credentialId))) return void 0;
|
|
236
|
-
const nativeSubjectId = yield* mapping.subjectId.toNative(input.expectedRevision.subjectId);
|
|
237
|
-
const subject = (yield* readSubjectNative(mapping, nativeSubjectId))[0];
|
|
238
|
-
if (subject === void 0 || !mapping.subject.isActiveStatus(subject[mapping.subject.status]) || subject[mapping.subject.securityRevision] !== input.expectedRevision.securityRevision || input.authorization.challenge.moduleId !== input.moduleId || input.authorization.challenge.action !== action || input.authorization.challenge.commandId !== input.commandId || input.authorization.challenge.revision.subjectId !== input.expectedRevision.subjectId || input.authorization.challenge.revision.securityRevision !== input.expectedRevision.securityRevision || input.authorization.evidence.revision.subjectId !== input.expectedRevision.subjectId || input.authorization.evidence.revision.securityRevision !== input.expectedRevision.securityRevision || input.authorization.evidence.flowId !== input.commandId || input.authorization.evidence.bindingDigest !== input.authorization.challenge.bindingDigest || action === "add-password" && (input.credential !== void 0 || input.authorization.challenge.targetCredentialId !== void 0) || input.expectedRevision.credentials.some((expected) => !input.authorization.evidence.revision.credentials.some((actual) => actual.credentialId === expected.credentialId && actual.revision === expected.revision))) return void 0;
|
|
239
|
-
let identifierCondition = sql`true`;
|
|
240
|
-
if (input.credential !== void 0) {
|
|
241
|
-
const identifier = (yield* readIdentifier(mapping, input.credential.identifier))[0];
|
|
242
|
-
if (identifier === void 0 || input.authorization.challenge.targetCredentialId !== input.credential.credentialId || !mapping.identifier.isCurrent(identifier) || !mapping.subjectId.equals(identifier[mapping.identifier.subjectId], nativeSubjectId) || identifier[mapping.identifier.bindingRevision] !== input.credential.identifierBindingRevision) return void 0;
|
|
243
|
-
const credential = (yield* readCredentialNative(mapping, input.moduleId, nativeSubjectId))[0];
|
|
244
|
-
if (credential === void 0) return void 0;
|
|
245
|
-
const snapshot = yield* mapping.credential.decode({
|
|
246
|
-
moduleId: input.moduleId,
|
|
247
|
-
subject,
|
|
248
|
-
identifier,
|
|
249
|
-
credential
|
|
250
|
-
});
|
|
251
|
-
if (!samePasswordCredentialSnapshot(snapshot, input.credential)) return void 0;
|
|
252
|
-
identifierCondition = identifierCurrentCondition(mapping, input, nativeSubjectId, identifier[mapping.identifier.verifiedAt]);
|
|
253
|
-
const ic = identifierColumns(mapping);
|
|
254
|
-
identifierCondition = and(identifierCondition, sql`exists(select 1 from ${mapping.identifier.table} where ${ic.namespace} = ${sql.param(input.credential.identifier.namespace, ic.namespace)} and ${ic.value} = ${sql.param(input.credential.identifier.value, ic.value)} and ${ic.subjectId} = ${sql.param(nativeSubjectId, ic.subjectId)} and ${ic.bindingRevision} = ${sql.param(input.credential.identifierBindingRevision, ic.bindingRevision)})`);
|
|
255
|
-
}
|
|
256
|
-
const expected = [...new Map([...input.expectedRevision.credentials, ...input.authorization.evidence.revision.credentials].map((item) => [item.credentialId, item])).values()].sort((left, right) => left.credentialId.localeCompare(right.credentialId));
|
|
257
|
-
const ac = authorityColumns(mapping);
|
|
258
|
-
const sortedRows = [...expected.length === 0 ? [] : yield* database.select().from(mapping.authorityCredential.table).where(and(eq(ac.subjectId, nativeSubjectId), inArray(ac.credentialId, expected.map((item) => item.credentialId))))].sort((left, right) => String(left[mapping.authorityCredential.credentialId]).localeCompare(String(right[mapping.authorityCredential.credentialId])));
|
|
259
|
-
if (sortedRows.length !== expected.length || sortedRows.some((row, index) => row[mapping.authorityCredential.credentialId] !== expected[index].credentialId || row[mapping.authorityCredential.revision] !== expected[index].revision || mapping.authorityCredential.status !== void 0 && mapping.authorityCredential.isActiveStatus?.(row[mapping.authorityCredential.status]) !== true)) return void 0;
|
|
260
|
-
const requirement = yield* mapping.subject.decodeActionRequirement(subject, action);
|
|
261
|
-
const engineNow = yield* readEngineNowMillis(mapping);
|
|
262
|
-
if (!evidenceSatisfiedAt(input.authorization.evidence, input.authorization.requirement, engineNow) || !evidenceSatisfiedAt(input.authorization.evidence, requirement, engineNow)) return void 0;
|
|
263
|
-
if (input.invalidation.existingSessions === "immediate" && mapping.sessionInvalidation !== "same-authority-immediate") return void 0;
|
|
264
|
-
const s = subjectColumns(mapping);
|
|
265
|
-
const credentialConditions = expected.map((item) => sql`exists(select 1 from ${mapping.authorityCredential.table} where ${ac.subjectId} = ${sql.param(nativeSubjectId, ac.subjectId)} and ${ac.credentialId} = ${sql.param(item.credentialId, ac.credentialId)} and ${ac.revision} = ${sql.param(item.revision, ac.revision)}${ac.status === void 0 ? sql`` : sql` and ${ac.status} = ${sql.param(mapping.authorityCredential.d1ActiveStatusValue, ac.status)}`})`);
|
|
266
|
-
return {
|
|
267
|
-
nativeSubjectId,
|
|
268
|
-
subject,
|
|
269
|
-
requirement,
|
|
270
|
-
identifierCondition,
|
|
271
|
-
condition: balancedD1And(sql`exists(select 1 from ${mapping.subject.table} where ${s.id} = ${sql.param(nativeSubjectId, s.id)} and ${s.status} = ${sql.param(mapping.subject.d1ActiveStatusValue, s.status)} and ${s.securityRevision} = ${sql.param(input.expectedRevision.securityRevision, s.securityRevision)})`, identifierCondition, ...credentialConditions, assuranceCondition(mapping, input.authorization.evidence, input.authorization.requirement), assuranceCondition(mapping, input.authorization.evidence, requirement))
|
|
272
|
-
};
|
|
273
|
-
});
|
|
274
|
-
const commandAbsentCondition = (mapping, moduleId, commandId) => {
|
|
275
|
-
const c = commandColumns(mapping);
|
|
276
|
-
return sql`not exists(select 1 from ${mapping.command.table} where ${c.moduleId} = ${sql.param(moduleId, c.moduleId)} and ${c.commandId} = ${sql.param(commandId, c.commandId)})`;
|
|
277
|
-
};
|
|
278
|
-
const credentialCurrentCondition = (mapping, input, nativeSubjectId) => {
|
|
279
|
-
const c = credentialColumns(mapping);
|
|
280
|
-
return input.credential === void 0 ? sql`false` : sql`exists(select 1 from ${mapping.credential.table} where ${c.moduleId} = ${sql.param(input.moduleId, c.moduleId)} and ${c.subjectId} = ${sql.param(nativeSubjectId, c.subjectId)} and ${c.credentialId} = ${sql.param(input.credential.credentialId, c.credentialId)} and ${c.credentialRevision} = ${sql.param(input.credential.credentialRevision, c.credentialRevision)} and ${c.verifierVersion} = ${sql.param(input.credential.verifierVersion, c.verifierVersion)} and ${c.verifier} = ${sql.param(Redacted.value(input.credential.verifier), c.verifier)} and ${c.normalization} = ${sql.param(input.credential.normalization, c.normalization)})`;
|
|
281
|
-
};
|
|
282
|
-
const mutationStatements = Effect.fn(function* (mapping, input, nativeSubjectId, revisions, now) {
|
|
283
|
-
const database = yield* CurrentD1PlanningDatabase;
|
|
284
|
-
const c = credentialColumns(mapping);
|
|
285
|
-
const s = subjectColumns(mapping);
|
|
286
|
-
const ac = authorityColumns(mapping);
|
|
287
|
-
return [
|
|
288
|
-
yield* statement(database.update(mapping.credential.table).set(mapping.credential.encodeReplacement({
|
|
289
|
-
replacement: input.replacement,
|
|
290
|
-
credentialRevision: revisions.credentialRevision,
|
|
291
|
-
verifierVersion: revisions.verifierVersion
|
|
292
|
-
})).where(and(eq(c.moduleId, input.moduleId), eq(c.subjectId, nativeSubjectId), eq(c.credentialId, input.credential.credentialId), eq(c.credentialRevision, input.credential.credentialRevision), eq(c.verifierVersion, input.credential.verifierVersion), eq(c.verifier, Redacted.value(input.credential.verifier)), eq(c.normalization, input.credential.normalization)))),
|
|
293
|
-
yield* statement(database.update(mapping.subject.table).set(updateValues([[mapping.subject.securityRevision, revisions.nextSecurityRevision]])).where(and(eq(s.id, nativeSubjectId), eq(s.securityRevision, input.expectedRevision.securityRevision)))),
|
|
294
|
-
yield* statement(database.update(mapping.authorityCredential.table).set(mapping.authorityCredential.encodeRevision(revisions.credentialRevision)).where(and(eq(ac.subjectId, nativeSubjectId), eq(ac.credentialId, input.credential.credentialId), eq(ac.revision, input.credential.credentialRevision)))),
|
|
295
|
-
yield* statement(database.insert(mapping.command.table).values(mapping.command.encodeInsert({
|
|
296
|
-
moduleId: input.moduleId,
|
|
297
|
-
commandId: input.commandId,
|
|
298
|
-
action: input.authorization.challenge.action,
|
|
299
|
-
bindingDigest: input.authorization.challenge.bindingDigest,
|
|
300
|
-
decision: "changed",
|
|
301
|
-
retentionUntilMillis: now + mapping.commandRetentionMillis
|
|
302
|
-
})))
|
|
303
|
-
];
|
|
304
|
-
});
|
|
305
|
-
const replacementApplied = (mapping, input, nativeSubjectId, revisions, now, identifierCondition) => {
|
|
306
|
-
const c = credentialColumns(mapping);
|
|
307
|
-
const s = subjectColumns(mapping);
|
|
308
|
-
const ac = authorityColumns(mapping);
|
|
309
|
-
const mc = commandColumns(mapping);
|
|
310
|
-
return and(sql`exists(select 1 from ${mapping.credential.table} where ${c.moduleId} = ${sql.param(input.moduleId, c.moduleId)} and ${c.subjectId} = ${sql.param(nativeSubjectId, c.subjectId)} and ${c.credentialId} = ${sql.param(input.credential.credentialId, c.credentialId)} and ${c.credentialRevision} = ${sql.param(revisions.credentialRevision, c.credentialRevision)} and ${c.verifierVersion} = ${sql.param(revisions.verifierVersion, c.verifierVersion)} and ${c.verifier} = ${sql.param(Redacted.value(input.replacement.verifier), c.verifier)} and ${c.normalization} = ${sql.param(input.replacement.normalization, c.normalization)})`, sql`exists(select 1 from ${mapping.subject.table} where ${s.id} = ${sql.param(nativeSubjectId, s.id)} and ${s.securityRevision} = ${sql.param(revisions.nextSecurityRevision, s.securityRevision)} and ${s.status} = ${sql.param(mapping.subject.d1ActiveStatusValue, s.status)})`, sql`exists(select 1 from ${mapping.authorityCredential.table} where ${ac.subjectId} = ${sql.param(nativeSubjectId, ac.subjectId)} and ${ac.credentialId} = ${sql.param(input.credential.credentialId, ac.credentialId)} and ${ac.revision} = ${sql.param(revisions.credentialRevision, ac.revision)}${ac.status === void 0 ? sql`` : sql` and ${ac.status} = ${sql.param(mapping.authorityCredential.d1ActiveStatusValue, ac.status)}`})`, sql`exists(select 1 from ${mapping.command.table} where ${mc.moduleId} = ${sql.param(input.moduleId, mc.moduleId)} and ${mc.commandId} = ${sql.param(input.commandId, mc.commandId)} and ${mc.bindingDigest} = ${sql.param(input.authorization.challenge.bindingDigest, mc.bindingDigest)} and ${mc.action} = ${sql.param(input.authorization.challenge.action, mc.action)} and ${mc.decision} = ${sql.param("changed", mc.decision)} and ${mc.retentionUntil} = ${sql.param(mapping.encodeInstant(now + mapping.commandRetentionMillis), mc.retentionUntil)})`, identifierCondition, sql`true`);
|
|
311
|
-
};
|
|
312
|
-
const compileAddMutation = Effect.fn("DrizzleD1Password.compileAddMutation")(function* (mapping, input, revisions) {
|
|
313
|
-
const database = yield* CurrentD1PlanningDatabase;
|
|
314
|
-
const { credentialId, credentialRevision, verifierVersion, nextSecurityRevision } = revisions;
|
|
315
|
-
const authority = yield* readAuthority(mapping, input, "add-password");
|
|
316
|
-
if (authority === void 0) return void 0;
|
|
317
|
-
const now = yield* readEngineNowMillis(mapping);
|
|
318
|
-
const c = credentialColumns(mapping);
|
|
319
|
-
const s = subjectColumns(mapping);
|
|
320
|
-
const ac = authorityColumns(mapping);
|
|
321
|
-
const mc = commandColumns(mapping);
|
|
322
|
-
const marker = `effect-auth-password-guard:add:${input.commandId}`;
|
|
323
|
-
const absent = sql`not exists(select 1 from ${mapping.credential.table} where ${c.moduleId} = ${sql.param(input.moduleId, c.moduleId)} and ${c.subjectId} = ${sql.param(authority.nativeSubjectId, c.subjectId)})`;
|
|
324
|
-
const guard = and(authority.condition, absent, commandAbsentCondition(mapping, input.moduleId, input.commandId));
|
|
325
|
-
const appliedCondition = and(sql`exists(select 1 from ${mapping.credential.table} where ${c.moduleId} = ${sql.param(input.moduleId, c.moduleId)} and ${c.subjectId} = ${sql.param(authority.nativeSubjectId, c.subjectId)} and ${c.credentialId} = ${sql.param(credentialId, c.credentialId)} and ${c.credentialRevision} = ${sql.param(credentialRevision, c.credentialRevision)} and ${c.verifierVersion} = ${sql.param(verifierVersion, c.verifierVersion)} and ${c.verifier} = ${sql.param(Redacted.value(input.replacement.verifier), c.verifier)} and ${c.normalization} = ${sql.param(input.replacement.normalization, c.normalization)})`, sql`exists(select 1 from ${mapping.authorityCredential.table} where ${ac.subjectId} = ${sql.param(authority.nativeSubjectId, ac.subjectId)} and ${ac.credentialId} = ${sql.param(credentialId, ac.credentialId)} and ${ac.revision} = ${sql.param(credentialRevision, ac.revision)}${ac.status === void 0 ? sql`` : sql` and ${ac.status} = ${sql.param(mapping.authorityCredential.d1ActiveStatusValue, ac.status)}`})`, sql`exists(select 1 from ${mapping.subject.table} where ${s.id} = ${sql.param(authority.nativeSubjectId, s.id)} and ${s.securityRevision} = ${sql.param(nextSecurityRevision, s.securityRevision)} and ${s.status} = ${sql.param(mapping.subject.d1ActiveStatusValue, s.status)})`, sql`exists(select 1 from ${mapping.command.table} where ${mc.moduleId} = ${sql.param(input.moduleId, mc.moduleId)} and ${mc.commandId} = ${sql.param(input.commandId, mc.commandId)} and ${mc.bindingDigest} = ${sql.param(input.authorization.challenge.bindingDigest, mc.bindingDigest)} and ${mc.action} = ${sql.param("add-password", mc.action)} and ${mc.decision} = ${sql.param("changed", mc.decision)} and ${mc.retentionUntil} = ${sql.param(mapping.encodeInstant(now + mapping.commandRetentionMillis), mc.retentionUntil)})`);
|
|
326
|
-
return {
|
|
327
|
-
statements: [
|
|
328
|
-
yield* assertion(guard, marker),
|
|
329
|
-
yield* statement(database.insert(mapping.credential.table).values(mapping.credential.encodeInsert({
|
|
330
|
-
moduleId: input.moduleId,
|
|
331
|
-
subjectId: authority.nativeSubjectId,
|
|
332
|
-
credentialId,
|
|
333
|
-
credentialRevision,
|
|
334
|
-
verifierVersion,
|
|
335
|
-
replacement: input.replacement
|
|
336
|
-
}))),
|
|
337
|
-
yield* statement(database.insert(mapping.authorityCredential.table).values(mapping.authorityCredential.encodeInsert({
|
|
338
|
-
subjectId: authority.nativeSubjectId,
|
|
339
|
-
credentialId,
|
|
340
|
-
revision: credentialRevision
|
|
341
|
-
}))),
|
|
342
|
-
yield* statement(database.update(mapping.subject.table).set(updateValues([[mapping.subject.securityRevision, nextSecurityRevision]])).where(and(eq(s.id, authority.nativeSubjectId), eq(s.securityRevision, input.expectedRevision.securityRevision)))),
|
|
343
|
-
yield* statement(database.insert(mapping.command.table).values(mapping.command.encodeInsert({
|
|
344
|
-
moduleId: input.moduleId,
|
|
345
|
-
commandId: input.commandId,
|
|
346
|
-
action: "add-password",
|
|
347
|
-
bindingDigest: input.authorization.challenge.bindingDigest,
|
|
348
|
-
decision: "changed",
|
|
349
|
-
retentionUntilMillis: now + mapping.commandRetentionMillis
|
|
350
|
-
}))),
|
|
351
|
-
yield* assertion(appliedCondition, marker)
|
|
352
|
-
],
|
|
353
|
-
appliedCondition,
|
|
354
|
-
marker,
|
|
355
|
-
retryable: (cause) => isGuardFailure(cause, marker)
|
|
356
|
-
};
|
|
357
|
-
});
|
|
358
|
-
const makePasswordPlans = (mapping, proofMapping) => {
|
|
359
|
-
const run = (plan) => Effect.gen(function* () {
|
|
360
|
-
if (!validConstraints(mapping)) return yield* unavailable();
|
|
361
|
-
return yield* plan;
|
|
362
|
-
});
|
|
363
|
-
return {
|
|
364
|
-
findCredential: (uncaptured) => Effect.gen(function* () {
|
|
365
|
-
if (!validConstraints(mapping)) return yield* unavailable();
|
|
366
|
-
const input = {
|
|
367
|
-
...uncaptured,
|
|
368
|
-
identifier: { ...uncaptured.identifier }
|
|
369
|
-
};
|
|
370
|
-
const database = yield* CurrentD1PlanningDatabase;
|
|
371
|
-
const identifierRow = (yield* readIdentifier(mapping, input.identifier))[0];
|
|
372
|
-
if (identifierRow === void 0 || !mapping.identifier.isCurrent(identifierRow)) return Option.none();
|
|
373
|
-
const nativeId = identifierRow[mapping.identifier.subjectId];
|
|
374
|
-
const sc = subjectColumns(mapping), ic = identifierColumns(mapping), cc = credentialColumns(mapping);
|
|
375
|
-
const rows = yield* database.select({
|
|
376
|
-
subject: getTableColumns(mapping.subject.table),
|
|
377
|
-
identifier: getTableColumns(mapping.identifier.table),
|
|
378
|
-
credential: getTableColumns(mapping.credential.table)
|
|
379
|
-
}).from(mapping.subject.table).innerJoin(mapping.identifier.table, and(eq(ic.namespace, input.identifier.namespace), eq(ic.value, input.identifier.value), eq(ic.subjectId, nativeId))).innerJoin(mapping.credential.table, and(eq(cc.moduleId, input.moduleId), eq(cc.subjectId, nativeId))).where(eq(sc.id, nativeId));
|
|
380
|
-
if (rows.length !== 1) return Option.none();
|
|
381
|
-
const row = rows[0];
|
|
382
|
-
if (!mapping.subject.isActiveStatus(row.subject[mapping.subject.status]) || !mapping.identifier.isCurrent(row.identifier) || !mapping.subjectId.equals(nativeId, row.subject[mapping.subject.id]) || !mapping.subjectId.equals(nativeId, row.identifier[mapping.identifier.subjectId]) || !mapping.subjectId.equals(nativeId, row.credential[mapping.credential.subjectId])) return Option.none();
|
|
383
|
-
const credential = yield* mapping.credential.decode({
|
|
384
|
-
moduleId: input.moduleId,
|
|
385
|
-
...row
|
|
386
|
-
}).pipe(Effect.flatMap(snapshotPasswordCredential));
|
|
387
|
-
return input.subjectId !== void 0 && credential.revision.subjectId !== input.subjectId ? Option.none() : Option.some(credential);
|
|
388
|
-
}),
|
|
389
|
-
rehashIfCurrent: (input) => run(Effect.gen(function* () {
|
|
390
|
-
const nextVerifier = Redacted.make(yield* Schema.decodeEffect(EncodedPasswordHash)(Redacted.value(input.nextVerifier)));
|
|
391
|
-
const credential = yield* snapshotPasswordCredential(input.credential);
|
|
392
|
-
const database = yield* CurrentD1PlanningDatabase;
|
|
393
|
-
const nativeId = yield* mapping.subjectId.toNative(credential.revision.subjectId);
|
|
394
|
-
const version = yield* allocate(mapping.allocateRevision, mapping.allocateRevisionSync);
|
|
395
|
-
if (version === credential.verifierVersion) return yield* unavailable();
|
|
396
|
-
const encoded = mapping.credential.encodeVerifier(nextVerifier, version);
|
|
397
|
-
const values = {
|
|
398
|
-
[mapping.credential.verifier]: encoded[mapping.credential.verifier],
|
|
399
|
-
[mapping.credential.verifierVersion]: encoded[mapping.credential.verifierVersion]
|
|
400
|
-
};
|
|
401
|
-
if (Object.values(values).some((value) => value === void 0)) return yield* unavailable();
|
|
402
|
-
const c = credentialColumns(mapping);
|
|
403
|
-
return {
|
|
404
|
-
receipt: void 0,
|
|
405
|
-
statements: [yield* statement(database.update(mapping.credential.table).set(values).where(and(eq(c.moduleId, credential.moduleId), eq(c.subjectId, nativeId), eq(c.credentialId, credential.credentialId), ...[
|
|
406
|
-
[c.moduleId, credential.moduleId],
|
|
407
|
-
[c.subjectId, nativeId],
|
|
408
|
-
[c.credentialId, credential.credentialId],
|
|
409
|
-
[c.credentialRevision, credential.credentialRevision],
|
|
410
|
-
[c.verifierVersion, credential.verifierVersion],
|
|
411
|
-
[c.verifier, Redacted.value(credential.verifier)],
|
|
412
|
-
[c.normalization, credential.normalization]
|
|
413
|
-
].map(([column, value]) => typeof value === "string" ? sql`cast(${column} as blob) = cast(${sql.param(value, column)} as blob)` : eq(column, value)))))]
|
|
414
|
-
};
|
|
415
|
-
})),
|
|
416
|
-
readForSubject: (input) => Effect.gen(function* () {
|
|
417
|
-
const database = yield* CurrentD1PlanningDatabase;
|
|
418
|
-
if (yield* hasCommitScope) return yield* unavailable();
|
|
419
|
-
const nativeSubjectId = yield* mapping.subjectId.toNative(input.subjectId);
|
|
420
|
-
const subject = (yield* readSubjectNative(mapping, nativeSubjectId))[0];
|
|
421
|
-
if (subject === void 0 || !mapping.subject.isActiveStatus(subject[mapping.subject.status])) return Option.none();
|
|
422
|
-
const credential = (yield* readCredentialNative(mapping, input.moduleId, nativeSubjectId))[0];
|
|
423
|
-
if (credential === void 0) return Option.none();
|
|
424
|
-
const ic = identifierColumns(mapping);
|
|
425
|
-
const identifier = (yield* database.select().from(mapping.identifier.table).where(eq(ic.subjectId, nativeSubjectId))).find((row) => mapping.identifier.isCurrent(row));
|
|
426
|
-
if (identifier === void 0) return Option.none();
|
|
427
|
-
return Option.some(yield* mapping.credential.decode({
|
|
428
|
-
moduleId: input.moduleId,
|
|
429
|
-
subject,
|
|
430
|
-
identifier,
|
|
431
|
-
credential
|
|
432
|
-
}).pipe(Effect.flatMap(snapshotPasswordCredential)));
|
|
433
|
-
}),
|
|
434
|
-
recoveryTarget: (input) => Effect.gen(function* () {
|
|
435
|
-
if (yield* hasCommitScope) return yield* unavailable();
|
|
436
|
-
const resolved = yield* resolveCredential(mapping, input.moduleId, input.identifier);
|
|
437
|
-
return resolved?.snapshot === void 0 || resolved.snapshot.identifierVerifiedAtMillis === void 0 ? Option.none() : Option.some(resolved.snapshot);
|
|
438
|
-
}),
|
|
439
|
-
addIfAbsent: (uncaptured, prepare) => Effect.gen(function* () {
|
|
440
|
-
const input = yield* snapshotMutationInput(uncaptured);
|
|
441
|
-
const credentialId = yield* allocate(mapping.allocateCredentialId, mapping.allocateCredentialIdSync);
|
|
442
|
-
const credentialRevision = yield* allocate(mapping.allocateRevision, mapping.allocateRevisionSync);
|
|
443
|
-
const verifierVersion = yield* allocate(mapping.allocateRevision, mapping.allocateRevisionSync);
|
|
444
|
-
const nextSecurityRevision = yield* allocateNextSecurityRevision(mapping, input.expectedRevision.securityRevision);
|
|
445
|
-
if (nextSecurityRevision === input.expectedRevision.securityRevision) return yield* unavailable();
|
|
446
|
-
return yield* run(Effect.gen(function* () {
|
|
447
|
-
const journal = yield* CurrentCommitJournal;
|
|
448
|
-
const compiled = yield* compileAddMutation(mapping, input, {
|
|
449
|
-
credentialId,
|
|
450
|
-
credentialRevision,
|
|
451
|
-
verifierVersion,
|
|
452
|
-
nextSecurityRevision
|
|
453
|
-
});
|
|
454
|
-
if (compiled === void 0) return {
|
|
455
|
-
receipt: prepare("rejected", journal),
|
|
456
|
-
statements: []
|
|
457
|
-
};
|
|
458
|
-
return {
|
|
459
|
-
receipt: prepare("changed", journal),
|
|
460
|
-
statements: compiled.statements,
|
|
461
|
-
postconditions: [yield* assertion(compiled.appliedCondition, compiled.marker)],
|
|
462
|
-
retryable: compiled.retryable
|
|
463
|
-
};
|
|
464
|
-
}));
|
|
465
|
-
}),
|
|
466
|
-
replaceIfCurrent: (uncaptured, prepare) => Effect.flatMap(snapshotMutationInput(uncaptured), (input) => replacementPlan(mapping, proofMapping, input, prepare, "change-password")),
|
|
467
|
-
checkReset: (input) => proofMapping === void 0 ? Effect.fail(unavailable()) : Effect.gen(function* () {
|
|
468
|
-
if (yield* hasCommitScope) return yield* unavailable();
|
|
469
|
-
if (input.moduleId.length <= 6 || !input.moduleId.endsWith("/reset") || input.purpose !== "password-reset" || input.binding._tag !== "Subject") return false;
|
|
470
|
-
const binding = input.binding;
|
|
471
|
-
const resolved = yield* resolveCredential(mapping, input.moduleId.slice(0, -6), binding.identifier, binding.revision.subjectId);
|
|
472
|
-
return resolved?.snapshot !== void 0 && resolved.snapshot.revision.securityRevision === binding.revision.securityRevision && binding.revision.credentials.every((item) => resolved.snapshot.revision.credentials.some((current) => current.credentialId === item.credentialId && current.revision === item.revision)) ? yield* probeProofCompletion(proofMapping, input) : false;
|
|
473
|
-
}),
|
|
474
|
-
resetWithProof: (uncaptured, prepare) => proofMapping === void 0 ? Effect.fail(unavailable()) : Effect.flatMap(snapshotMutationInput(uncaptured), (captured) => replacementPlan(mapping, proofMapping, Object.freeze({
|
|
475
|
-
...captured,
|
|
476
|
-
completion: uncaptured.completion
|
|
477
|
-
}), prepare, "reset-password"))
|
|
478
|
-
};
|
|
479
|
-
};
|
|
480
|
-
const compileReplacementMutation = Effect.fn("DrizzleD1Password.compileReplacementMutation")(function* (mapping, input, action, revisions) {
|
|
481
|
-
const { credentialRevision, verifierVersion, nextSecurityRevision } = revisions;
|
|
482
|
-
const authority = yield* readAuthority(mapping, input, action);
|
|
483
|
-
const current = authority === void 0 || input.credential === void 0 ? void 0 : (yield* readCredentialNative(mapping, input.moduleId, authority.nativeSubjectId))[0];
|
|
484
|
-
const currentMatches = current !== void 0 && current[mapping.credential.credentialId] === input.credential.credentialId && current[mapping.credential.credentialRevision] === input.credential.credentialRevision && current[mapping.credential.verifierVersion] === input.credential.verifierVersion && current[mapping.credential.verifier] === Redacted.value(input.credential.verifier) && current[mapping.credential.normalization] === input.credential.normalization;
|
|
485
|
-
if (authority === void 0 || !currentMatches) return void 0;
|
|
486
|
-
const now = yield* readEngineNowMillis(mapping);
|
|
487
|
-
const guard = and(authority.condition, credentialCurrentCondition(mapping, input, authority.nativeSubjectId), commandAbsentCondition(mapping, input.moduleId, input.commandId));
|
|
488
|
-
const marker = `effect-auth-password-guard:${action}:${input.commandId}`;
|
|
489
|
-
return {
|
|
490
|
-
protectedMutation: {
|
|
491
|
-
statements: [yield* assertion(guard, marker), ...yield* mutationStatements(mapping, input, authority.nativeSubjectId, {
|
|
492
|
-
credentialRevision,
|
|
493
|
-
verifierVersion,
|
|
494
|
-
nextSecurityRevision
|
|
495
|
-
}, now)],
|
|
496
|
-
appliedCondition: replacementApplied(mapping, input, authority.nativeSubjectId, {
|
|
497
|
-
credentialRevision,
|
|
498
|
-
verifierVersion,
|
|
499
|
-
nextSecurityRevision
|
|
500
|
-
}, now, authority.identifierCondition)
|
|
501
|
-
},
|
|
502
|
-
marker
|
|
503
|
-
};
|
|
504
|
-
});
|
|
505
|
-
const replacementPlan = Effect.fn("Drizzle.replacementPlan")(function* (mapping, proofMapping, input, prepare, action) {
|
|
506
|
-
const credentialRevision = yield* allocate(mapping.allocateRevision, mapping.allocateRevisionSync);
|
|
507
|
-
const verifierVersion = yield* allocate(mapping.allocateRevision, mapping.allocateRevisionSync);
|
|
508
|
-
const nextSecurityRevision = yield* allocateNextSecurityRevision(mapping, input.expectedRevision.securityRevision);
|
|
509
|
-
if (nextSecurityRevision === input.expectedRevision.securityRevision || input.credential !== void 0 && credentialRevision === input.credential.credentialRevision) return yield* unavailable();
|
|
510
|
-
const journal = yield* CurrentCommitJournal;
|
|
511
|
-
const compiledMutation = yield* compileReplacementMutation(mapping, input, action, {
|
|
512
|
-
credentialRevision,
|
|
513
|
-
verifierVersion,
|
|
514
|
-
nextSecurityRevision
|
|
515
|
-
});
|
|
516
|
-
if (compiledMutation === void 0) return {
|
|
517
|
-
receipt: prepare("rejected", journal),
|
|
518
|
-
statements: []
|
|
519
|
-
};
|
|
520
|
-
const { protectedMutation, marker } = compiledMutation;
|
|
521
|
-
if (action === "reset-password") {
|
|
522
|
-
if (proofMapping === void 0 || input.completion === void 0 || !completionMatchesPassword(input)) return {
|
|
523
|
-
receipt: prepare("rejected", journal),
|
|
524
|
-
statements: []
|
|
525
|
-
};
|
|
526
|
-
let passwordReceipt;
|
|
527
|
-
const compiled = yield* compileD1ProofCompletionPlan(proofMapping, input.completion, protectedMutation, (decision) => {
|
|
528
|
-
passwordReceipt = prepare(decision === "completed" ? "changed" : "rejected", journal);
|
|
529
|
-
return decision;
|
|
530
|
-
});
|
|
531
|
-
return {
|
|
532
|
-
receipt: passwordReceipt ?? prepare("rejected", journal),
|
|
533
|
-
statements: compiled.statements,
|
|
534
|
-
...compiled.postconditions === void 0 ? {} : { postconditions: compiled.postconditions },
|
|
535
|
-
retryable: (cause) => isGuardFailure(cause, marker) || isGuardFailure(cause, `effect-auth-proof-guard:complete:${input.completion.input.continuationId}`) || isGuardFailure(cause, `effect-auth-proof-guard:protected:${input.completion.input.continuationId}`)
|
|
536
|
-
};
|
|
537
|
-
}
|
|
538
|
-
const applied = yield* assertion(protectedMutation.appliedCondition, marker);
|
|
539
|
-
return {
|
|
540
|
-
receipt: prepare("changed", journal),
|
|
541
|
-
statements: [...protectedMutation.statements, applied],
|
|
542
|
-
postconditions: [applied],
|
|
543
|
-
retryable: (cause) => isGuardFailure(cause, marker)
|
|
544
|
-
};
|
|
545
|
-
});
|
|
546
|
-
const makeD1PasswordPersistenceServices = Effect.fnUntraced(function* (mapping, proofMapping) {
|
|
547
|
-
const database = yield* Database;
|
|
548
|
-
yield* validateDrizzleStorage({
|
|
549
|
-
...mapping,
|
|
550
|
-
proof: proofMapping
|
|
551
|
-
}).pipe(Effect.provideServiceEffect(NativeDatabase, nativeDatabase(Database)), Effect.mapError(unavailable));
|
|
552
|
-
const hooks = yield* LifecycleHooks;
|
|
553
|
-
const plans = makePasswordPlans(mapping, proofMapping);
|
|
554
|
-
const standalone = Effect.gen(function* () {
|
|
555
|
-
if (yield* hasCommitScope) return yield* unavailable();
|
|
556
|
-
yield* requireStandalone(unavailable, database.$client.transactionService);
|
|
557
|
-
});
|
|
558
|
-
const run = (plan) => Effect.gen(function* () {
|
|
559
|
-
yield* standalone;
|
|
560
|
-
return yield* executeStandalone(plan, 2);
|
|
561
|
-
}).pipe(Effect.provideService(CurrentD1PlanningDatabase, database), Effect.provideService(LifecycleHooks, hooks));
|
|
562
|
-
return { passwordPersistence: {
|
|
563
|
-
findCredential: (input) => standalone.pipe(Effect.andThen(plans.findCredential(input)), Effect.provideService(CurrentD1PlanningDatabase, database), translateFailure),
|
|
564
|
-
rehashIfCurrent: (input) => run(plans.rehashIfCurrent(input)).pipe(translateFailure),
|
|
565
|
-
readForSubject: (input) => plans.readForSubject(input).pipe(Effect.provideService(CurrentD1PlanningDatabase, database), Effect.provideService(LifecycleHooks, hooks), translateFailure),
|
|
566
|
-
recoveryTarget: (input) => plans.recoveryTarget(input).pipe(Effect.provideService(CurrentD1PlanningDatabase, database), Effect.provideService(LifecycleHooks, hooks), translateFailure),
|
|
567
|
-
addIfAbsent: (input, prepare) => run(plans.addIfAbsent(input, prepare)).pipe(translateFailure),
|
|
568
|
-
replaceIfCurrent: (input, prepare) => run(plans.replaceIfCurrent(input, prepare)).pipe(translateFailure),
|
|
569
|
-
checkReset: (input) => plans.checkReset(input).pipe(Effect.provideService(CurrentD1PlanningDatabase, database), Effect.provideService(LifecycleHooks, hooks), translateFailure),
|
|
570
|
-
resetWithProof: (input, prepare) => run(plans.resetWithProof(input, prepare)).pipe(translateFailure)
|
|
571
|
-
} };
|
|
572
|
-
});
|
|
573
|
-
/**
|
|
574
|
-
* Owns one password transition plus application statements in one D1 batch.
|
|
575
|
-
* The owner Effect is invoked once and is never replayed after an ambiguous or
|
|
576
|
-
* guarded batch failure. Standalone adapter-owned commands may replan boundedly.
|
|
577
|
-
*/
|
|
578
|
-
function coordinateD1PasswordPersistence(acquire, options, body) {
|
|
579
|
-
return Effect.flatMap(nativeDatabase(acquire), (database) => Effect.gen(function* () {
|
|
580
|
-
yield* validateDrizzleStorage({
|
|
581
|
-
...options.mapping,
|
|
582
|
-
proof: options.proofMapping
|
|
583
|
-
}).pipe(Effect.mapError(unavailable));
|
|
584
|
-
const hooks = yield* LifecycleHooks;
|
|
585
|
-
if (yield* hasCommitScope) return yield* unavailable();
|
|
586
|
-
return (yield* coordinateCommit(() => Effect.gen(function* () {
|
|
587
|
-
const statements = [];
|
|
588
|
-
let mutation;
|
|
589
|
-
const nativeCollector = D1BatchStatements.of({ append: (statement) => Effect.sync(() => statements.push(statement)) });
|
|
590
|
-
const owner = yield* makeD1Owner(unavailable()).pipe(Effect.provideService(D1BatchStatements, nativeCollector));
|
|
591
|
-
const plans = makePasswordPlans(options.mapping, options.proofMapping);
|
|
592
|
-
const run = (plan) => coordinateCommit(() => Effect.gen(function* () {
|
|
593
|
-
const journal = yield* CurrentCommitJournal;
|
|
594
|
-
const planned = yield* plan;
|
|
595
|
-
yield* owner.check;
|
|
596
|
-
if (mutation !== void 0) return yield* unavailable();
|
|
597
|
-
const guarded = {
|
|
598
|
-
...planned,
|
|
599
|
-
journalGuard: journal.prepare(void 0)
|
|
600
|
-
};
|
|
601
|
-
mutation = guarded;
|
|
602
|
-
statements.push(...guarded.statements);
|
|
603
|
-
return guarded.receipt;
|
|
604
|
-
}), { mode: "batch" }).pipe(Effect.map((result) => result.value), Effect.provideService(CurrentD1PlanningDatabase, database), Effect.provideService(LifecycleHooks, hooks));
|
|
605
|
-
const provided = Context.make(PasswordPersistence, {
|
|
606
|
-
findCredential: (input) => owner.run(plans.findCredential(input).pipe(Effect.provideService(CurrentD1PlanningDatabase, database), translateFailure)),
|
|
607
|
-
rehashIfCurrent: (input) => owner.run(run(plans.rehashIfCurrent(input)).pipe(translateFailure)),
|
|
608
|
-
readForSubject: (input) => owner.run(plans.readForSubject(input).pipe(Effect.provideService(CurrentD1PlanningDatabase, database), Effect.provideService(LifecycleHooks, hooks), translateFailure)),
|
|
609
|
-
recoveryTarget: (input) => owner.run(plans.recoveryTarget(input).pipe(Effect.provideService(CurrentD1PlanningDatabase, database), Effect.provideService(LifecycleHooks, hooks), translateFailure)),
|
|
610
|
-
addIfAbsent: (input, prepare) => owner.run(run(plans.addIfAbsent(input, prepare)).pipe(translateFailure)),
|
|
611
|
-
replaceIfCurrent: (input, prepare) => owner.run(run(plans.replaceIfCurrent(input, prepare)).pipe(translateFailure)),
|
|
612
|
-
checkReset: (input) => owner.run(plans.checkReset(input).pipe(Effect.provideService(CurrentD1PlanningDatabase, database), Effect.provideService(LifecycleHooks, hooks), translateFailure)),
|
|
613
|
-
resetWithProof: (input, prepare) => owner.run(run(plans.resetWithProof(input, prepare)).pipe(translateFailure))
|
|
614
|
-
}).pipe(Context.add(D1BatchStatements, owner.collector));
|
|
615
|
-
const value = yield* owner.close(Effect.provideContext(body, provided));
|
|
616
|
-
if (mutation?.journalGuard !== void 0) {
|
|
617
|
-
const status = yield* Effect.result(mutation.journalGuard.read);
|
|
618
|
-
if (status._tag === "Success" || status.failure._tag !== "CommitPending") return yield* unavailable();
|
|
619
|
-
}
|
|
620
|
-
yield* database.$client.batch([...statements, ...mutation?.postconditions ?? []]).pipe(Effect.catchCause((cause) => Effect.failCause(Cause.map(cause, (error) => everyFailureMatches(cause, mutation?.retryable) ? unavailable() : error))), translateFailure);
|
|
621
|
-
return value;
|
|
622
|
-
}), { mode: "batch" }).pipe(Effect.provideService(LifecycleHooks, hooks))).value;
|
|
623
|
-
}).pipe(Effect.provideService(NativeDatabase, database)));
|
|
624
|
-
}
|
|
625
|
-
const registrationRows = Effect.fn("Drizzle.registrationRows")(function* (mapping, moduleId, requestId) {
|
|
626
|
-
const database = yield* CurrentD1PlanningDatabase;
|
|
627
|
-
const module = column(mapping.registration.table, mapping.registration.moduleId);
|
|
628
|
-
const request = column(mapping.registration.table, mapping.registration.requestId);
|
|
629
|
-
return yield* database.select().from(mapping.registration.table).where(and(eq(module, moduleId), eq(request, requestId))).limit(1);
|
|
630
|
-
});
|
|
631
|
-
const registrationIdentifierRows = Effect.fn("Drizzle.registrationIdentifierRows")(function* (mapping, identifier) {
|
|
632
|
-
const database = yield* CurrentD1PlanningDatabase;
|
|
633
|
-
const namespace = column(mapping.identifier.table, mapping.identifier.namespace);
|
|
634
|
-
const value = column(mapping.identifier.table, mapping.identifier.value);
|
|
635
|
-
return yield* database.select().from(mapping.identifier.table).where(and(eq(namespace, identifier.namespace), eq(value, identifier.value))).limit(1);
|
|
636
|
-
});
|
|
637
|
-
const planRegistration = Effect.fn("Drizzle.planRegistration")(function* (mapping, input, allocated, prepare) {
|
|
638
|
-
const database = yield* CurrentD1PlanningDatabase;
|
|
639
|
-
const journal = yield* CurrentCommitJournal;
|
|
640
|
-
const existing = (yield* registrationRows(mapping, input.moduleId, input.requestId))[0];
|
|
641
|
-
if (existing !== void 0) return {
|
|
642
|
-
receipt: prepare(yield* mapping.registration.decodeReplay(existing), journal),
|
|
643
|
-
statements: []
|
|
644
|
-
};
|
|
645
|
-
const intent = {
|
|
646
|
-
moduleId: input.moduleId,
|
|
647
|
-
requestId: input.requestId,
|
|
648
|
-
identifier: input.identifier,
|
|
649
|
-
registration: input.registration,
|
|
650
|
-
replacement: input.replacement
|
|
651
|
-
};
|
|
652
|
-
if (mapping.mode === "pending") {
|
|
653
|
-
if (allocated.recoveryReference === void 0) return yield* unavailable();
|
|
654
|
-
return {
|
|
655
|
-
receipt: prepare({
|
|
656
|
-
_tag: "Pending",
|
|
657
|
-
reference: allocated.recoveryReference
|
|
658
|
-
}, journal),
|
|
659
|
-
statements: [yield* statement(database.insert(mapping.registration.table).values(mapping.registration.encodeInsert(intent, {
|
|
660
|
-
state: "pending",
|
|
661
|
-
recoveryReference: allocated.recoveryReference
|
|
662
|
-
})))],
|
|
663
|
-
retryable: (cause) => isMappedConstraintConflict(mapping.isRequestConflict, cause)
|
|
664
|
-
};
|
|
665
|
-
}
|
|
666
|
-
if (mapping.provisioning.idMode === "generated" || allocated.nativeSubjectId === void 0) return yield* unavailable();
|
|
667
|
-
if ((yield* registrationIdentifierRows(mapping, input.identifier)).length > 0) return {
|
|
668
|
-
receipt: prepare({ _tag: "Suppressed" }, journal),
|
|
669
|
-
statements: []
|
|
670
|
-
};
|
|
671
|
-
const nativeSubjectId = allocated.nativeSubjectId;
|
|
672
|
-
return {
|
|
673
|
-
receipt: prepare({
|
|
674
|
-
_tag: "Created",
|
|
675
|
-
subjectId: yield* mapping.subjectId.toSubject(nativeSubjectId)
|
|
676
|
-
}, journal),
|
|
677
|
-
statements: [
|
|
678
|
-
yield* statement(database.insert(mapping.subject.table).values(mapping.provisioning.encodeSubjectInsert(intent, {
|
|
679
|
-
nativeSubjectId,
|
|
680
|
-
securityRevision: allocated.securityRevision
|
|
681
|
-
}))),
|
|
682
|
-
yield* statement(database.insert(mapping.identifier.table).values(mapping.identifier.encodeInitialInsert(input.identifier, nativeSubjectId, allocated.identifierRevision))),
|
|
683
|
-
yield* statement(database.insert(mapping.credential.table).values(mapping.credential.encodeInsert({
|
|
684
|
-
moduleId: input.moduleId,
|
|
685
|
-
subjectId: nativeSubjectId,
|
|
686
|
-
credentialId: allocated.credentialId,
|
|
687
|
-
credentialRevision: allocated.credentialRevision,
|
|
688
|
-
verifierVersion: allocated.verifierVersion,
|
|
689
|
-
replacement: input.replacement
|
|
690
|
-
}))),
|
|
691
|
-
yield* statement(database.insert(mapping.authorityCredential.table).values(mapping.authorityCredential.encodeInsert({
|
|
692
|
-
subjectId: nativeSubjectId,
|
|
693
|
-
credentialId: allocated.credentialId,
|
|
694
|
-
revision: allocated.credentialRevision
|
|
695
|
-
}))),
|
|
696
|
-
yield* statement(database.insert(mapping.registration.table).values(mapping.registration.encodeInsert(intent, {
|
|
697
|
-
state: "created",
|
|
698
|
-
nativeSubjectId
|
|
699
|
-
})))
|
|
700
|
-
],
|
|
701
|
-
retryable: (cause) => isMappedConstraintConflict(mapping.isRequestConflict, cause) || isMappedConstraintConflict(mapping.isIdentifierConflict, cause)
|
|
702
|
-
};
|
|
703
|
-
});
|
|
704
|
-
const allocateRegistration = (mapping) => Effect.gen(function* () {
|
|
705
|
-
const credentialId = yield* allocate(mapping.allocateCredentialId, mapping.allocateCredentialIdSync);
|
|
706
|
-
const securityRevision = yield* allocate(mapping.allocateRevision, mapping.allocateRevisionSync);
|
|
707
|
-
const identifierRevision = yield* allocate(mapping.allocateRevision, mapping.allocateRevisionSync);
|
|
708
|
-
const credentialRevision = yield* allocate(mapping.allocateRevision, mapping.allocateRevisionSync);
|
|
709
|
-
const verifierVersion = yield* allocate(mapping.allocateRevision, mapping.allocateRevisionSync);
|
|
710
|
-
const nativeSubjectId = mapping.mode !== "atomic" || mapping.provisioning.idMode === "generated" ? void 0 : yield* allocate(mapping.provisioning.allocateSubjectId, mapping.provisioning.allocateSubjectIdSync);
|
|
711
|
-
const recoveryReference = mapping.mode === "pending" ? yield* allocate(mapping.allocateRecoveryReference, mapping.allocateRecoveryReferenceSync) : void 0;
|
|
712
|
-
return {
|
|
713
|
-
credentialId,
|
|
714
|
-
securityRevision,
|
|
715
|
-
identifierRevision,
|
|
716
|
-
credentialRevision,
|
|
717
|
-
verifierVersion,
|
|
718
|
-
...nativeSubjectId === void 0 ? {} : { nativeSubjectId },
|
|
719
|
-
...recoveryReference === void 0 ? {} : { recoveryReference }
|
|
720
|
-
};
|
|
721
|
-
});
|
|
722
|
-
const makeRegistrationPlans = (mapping) => ({ register: (input, prepare) => Effect.gen(function* () {
|
|
723
|
-
if (!validRegistrationConstraints(mapping)) return yield* unavailable();
|
|
724
|
-
if (mapping.mode === "atomic" && mapping.provisioning.idMode === "generated") return yield* unavailable();
|
|
725
|
-
const allocated = yield* allocateRegistration(mapping);
|
|
726
|
-
return yield* planRegistration(mapping, input, allocated, prepare);
|
|
727
|
-
}) });
|
|
728
|
-
const makeD1PasswordRegistrationServices = Effect.fnUntraced(function* (mapping) {
|
|
729
|
-
const database = yield* Database;
|
|
730
|
-
yield* validateDrizzleStorage(mapping).pipe(Effect.provideServiceEffect(NativeDatabase, nativeDatabase(Database)), Effect.mapError(unavailable));
|
|
731
|
-
const hooks = yield* LifecycleHooks;
|
|
732
|
-
const plans = makeRegistrationPlans(mapping);
|
|
733
|
-
const run = (plan) => Effect.gen(function* () {
|
|
734
|
-
if (yield* hasCommitScope) return yield* unavailable();
|
|
735
|
-
return yield* executeStandalone(plan, 2);
|
|
736
|
-
}).pipe(Effect.provideService(CurrentD1PlanningDatabase, database), Effect.provideService(LifecycleHooks, hooks));
|
|
737
|
-
return { registrationAuthority: { register: (input, prepare) => run(plans.register(input, prepare)).pipe(translateFailure) } };
|
|
738
|
-
});
|
|
739
|
-
function coordinateD1PasswordRegistration(acquire, options, body) {
|
|
740
|
-
return Effect.flatMap(nativeDatabase(acquire), (database) => Effect.gen(function* () {
|
|
741
|
-
yield* validateDrizzleStorage(options.mapping).pipe(Effect.mapError(unavailable));
|
|
742
|
-
const hooks = yield* LifecycleHooks;
|
|
743
|
-
if (yield* hasCommitScope) return yield* unavailable();
|
|
744
|
-
return (yield* coordinateCommit(() => Effect.gen(function* () {
|
|
745
|
-
const statements = [];
|
|
746
|
-
let mutation;
|
|
747
|
-
const nativeCollector = D1BatchStatements.of({ append: (statement) => Effect.sync(() => statements.push(statement)) });
|
|
748
|
-
const owner = yield* makeD1Owner(unavailable()).pipe(Effect.provideService(D1BatchStatements, nativeCollector));
|
|
749
|
-
const plans = makeRegistrationPlans(options.mapping);
|
|
750
|
-
const run = (plan) => coordinateCommit(() => Effect.gen(function* () {
|
|
751
|
-
const journal = yield* CurrentCommitJournal;
|
|
752
|
-
const planned = yield* plan;
|
|
753
|
-
yield* owner.check;
|
|
754
|
-
if (mutation !== void 0) return yield* unavailable();
|
|
755
|
-
const guarded = {
|
|
756
|
-
...planned,
|
|
757
|
-
journalGuard: journal.prepare(void 0)
|
|
758
|
-
};
|
|
759
|
-
mutation = guarded;
|
|
760
|
-
statements.push(...guarded.statements);
|
|
761
|
-
return guarded.receipt;
|
|
762
|
-
}), { mode: "batch" }).pipe(Effect.map((result) => result.value), Effect.provideService(CurrentD1PlanningDatabase, database), Effect.provideService(LifecycleHooks, hooks));
|
|
763
|
-
const provided = Context.make(options.target, { register: (input, prepare) => owner.run(run(plans.register(input, prepare)).pipe(translateFailure)) }).pipe(Context.add(D1BatchStatements, owner.collector));
|
|
764
|
-
const value = yield* owner.close(Effect.provideContext(body, provided));
|
|
765
|
-
if (mutation?.journalGuard !== void 0) {
|
|
766
|
-
const status = yield* Effect.result(mutation.journalGuard.read);
|
|
767
|
-
if (status._tag === "Success" || status.failure._tag !== "CommitPending") return yield* unavailable();
|
|
768
|
-
}
|
|
769
|
-
yield* database.$client.batch(statements).pipe(Effect.catchCause((cause) => Effect.failCause(Cause.map(cause, (error) => everyFailureMatches(cause, mutation?.retryable) ? unavailable() : error))), translateFailure);
|
|
770
|
-
return value;
|
|
771
|
-
}), { mode: "batch" }).pipe(Effect.provideService(LifecycleHooks, hooks))).value;
|
|
772
|
-
}).pipe(Effect.provideService(NativeDatabase, database)));
|
|
773
|
-
}
|
|
774
|
-
/** Private prepared compiler seam: it never replays a caller or prepared callback. */
|
|
775
|
-
const passwordD1Kernel = {
|
|
776
|
-
statement,
|
|
777
|
-
assertion,
|
|
778
|
-
readEngineNowMillis,
|
|
779
|
-
allocate,
|
|
780
|
-
allocateNextSecurityRevision,
|
|
781
|
-
subjectColumns,
|
|
782
|
-
identifierColumns,
|
|
783
|
-
credentialColumns,
|
|
784
|
-
authorityColumns,
|
|
785
|
-
readAuthority,
|
|
786
|
-
assuranceCondition,
|
|
787
|
-
credentialCurrentCondition,
|
|
788
|
-
commandAbsentCondition,
|
|
789
|
-
compileAddMutation,
|
|
790
|
-
compileReplacementMutation,
|
|
791
|
-
completionMatchesPassword,
|
|
792
|
-
isGuardFailure
|
|
793
|
-
};
|
|
794
|
-
const translateFailure = (effect) => reportPersistenceFailure(effect, (error) => Schema.is(PasswordUnavailable)(error) || Schema.is(ProofUnavailable)(error) || Schema.is(HookConfigurationError)(error)).pipe(Effect.catchCause((cause) => Effect.failCause(Cause.map(cause, () => unavailable()))));
|
|
795
|
-
const executeStandalone = (plan, retries = 2) => Effect.suspend(() => {
|
|
796
|
-
let retryable;
|
|
797
|
-
return coordinateCommit(() => Effect.gen(function* () {
|
|
798
|
-
const database = yield* CurrentD1PlanningDatabase;
|
|
799
|
-
const planned = yield* plan;
|
|
800
|
-
retryable = planned.retryable;
|
|
801
|
-
yield* database.$client.batch(planned.statements);
|
|
802
|
-
return planned.receipt;
|
|
803
|
-
}), { mode: "batch" }).pipe(Effect.map((result) => result.value)).pipe(Effect.catchCause((cause) => retries > 0 && everyFailureMatches(cause, retryable) ? executeStandalone(plan, retries - 1) : Effect.failCause(cause)));
|
|
804
|
-
});
|
|
805
|
-
//#endregion
|
|
806
|
-
export { coordinateD1PasswordPersistence, coordinateD1PasswordRegistration, makeD1PasswordPersistenceServices, makeD1PasswordRegistrationServices, passwordD1Kernel };
|
|
807
|
-
|
|
808
|
-
//# sourceMappingURL=d1-passwords.mjs.map
|