@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,509 +1,67 @@
|
|
|
1
|
-
import { NativeDatabase } from "@yielded/auth-persistence/Adapter";
|
|
2
|
-
import { LifecycleHooks } from "@yielded/auth/Hooks";
|
|
3
1
|
import {
|
|
4
|
-
|
|
2
|
+
makeNativePhoneServices,
|
|
3
|
+
type AnyPhoneMapping as SharedMapping,
|
|
4
|
+
} from "@yielded/auth-persistence/Adapter";
|
|
5
|
+
import {
|
|
6
|
+
PhoneOtpUnavailable,
|
|
5
7
|
PhoneLifecyclePolicy,
|
|
6
|
-
|
|
7
|
-
PhoneLifecycleTarget,
|
|
8
|
-
PhoneActionAuthorization,
|
|
9
|
-
PhoneAdmission,
|
|
10
|
-
type PhoneMutation,
|
|
11
|
-
PhonePersistence,
|
|
12
|
-
PhoneSignInTargets,
|
|
13
|
-
type PhoneOtpUnavailable as PhoneUnavailable,
|
|
8
|
+
PhoneConfigurationError,
|
|
14
9
|
} from "@yielded/auth/PhoneOtp";
|
|
15
|
-
import {
|
|
16
|
-
import { sql, type Table } from "drizzle-orm";
|
|
17
|
-
/* oxlint-disable no-explicit-any -- shared native implementation; driver entrypoints retain exact database and table types. */
|
|
18
|
-
import { type Crypto, Context, Effect, Schema } from "effect";
|
|
19
|
-
import type { Statement } from "effect/sql/Statement";
|
|
10
|
+
import { Effect, Schema } from "effect";
|
|
20
11
|
|
|
21
|
-
import {
|
|
22
|
-
import { CurrentD1PlanningDatabase } from "./d1-planning";
|
|
23
|
-
import { compileD1ProofCompletionPlan } from "./d1-proofs";
|
|
24
|
-
import type { PersistenceMappingError } from "./model";
|
|
25
|
-
import { nativeDatabase } from "./native-database";
|
|
12
|
+
import { NativeDatabase, type NativeDatabaseHandle } from "./native-database";
|
|
26
13
|
import {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
type
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
} from "./phone-model";
|
|
34
|
-
import {
|
|
35
|
-
capturePhone,
|
|
36
|
-
lookupPhone,
|
|
37
|
-
admitPhone,
|
|
38
|
-
cleanupPhoneAdmission,
|
|
39
|
-
CurrentPhoneTransaction,
|
|
40
|
-
invariant,
|
|
41
|
-
equal,
|
|
42
|
-
preparePhoneMutation,
|
|
43
|
-
unavailable,
|
|
44
|
-
} from "./phone-state";
|
|
45
|
-
import { requiredProofConstraints } from "./proof-model";
|
|
46
|
-
import { completeProofPlanIn, CurrentProofSql } from "./proof-sql";
|
|
14
|
+
coordinateNativeTarget,
|
|
15
|
+
nativeTarget,
|
|
16
|
+
type NativeTargetConfiguration,
|
|
17
|
+
} from "./native-target";
|
|
18
|
+
import { type AnyPhoneMapping, type PhonePersistenceServices } from "./phone-model";
|
|
19
|
+
import { nativeProofMapping } from "./proof-target";
|
|
47
20
|
import { validateDrizzleStorage } from "./storage-validation";
|
|
48
|
-
import type { SuppliedService } from "./SuppliedService";
|
|
49
|
-
import {
|
|
50
|
-
coordinateTransactionOwner,
|
|
51
|
-
makeTransactionExecution,
|
|
52
|
-
sqlClientTransactionStandaloneGuard,
|
|
53
|
-
type TransactionExecution,
|
|
54
|
-
type TransactionTargetConfiguration,
|
|
55
|
-
type TransactionCoordinatorError,
|
|
56
|
-
} from "./transaction-execution";
|
|
57
|
-
import type { TransactionNativeDatabase } from "./transaction-owner";
|
|
58
|
-
export type PhoneTargetConfiguration = TransactionTargetConfiguration<PhoneUnavailable>;
|
|
59
|
-
|
|
60
|
-
export type PhoneCoordinatorError<E> =
|
|
61
|
-
| TransactionCoordinatorError<E, PhoneUnavailable>
|
|
62
|
-
| PhoneConfigurationError
|
|
63
|
-
| PersistenceMappingError;
|
|
64
21
|
|
|
65
|
-
|
|
66
|
-
service: Parameters<typeof sqlClientTransactionStandaloneGuard>[1],
|
|
67
|
-
) => sqlClientTransactionStandaloneGuard(unavailable, service);
|
|
22
|
+
const unavailable = () => PhoneOtpUnavailable.make({});
|
|
68
23
|
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
for (const [key, value] of Object.entries(requiredProofConstraints))
|
|
80
|
-
invariant((proofs.constraints as any)?.[key] === value);
|
|
81
|
-
if (configuration.mode === "synchronous") invariant(proofs.allocateVersionSync !== undefined);
|
|
82
|
-
if (configuration.mode === "batch")
|
|
83
|
-
invariant(
|
|
84
|
-
proofs.d1 !== undefined && proofs.authority.identifier.d1CurrentCondition !== undefined,
|
|
85
|
-
);
|
|
86
|
-
for (const [key, value] of Object.entries(requiredPhoneConstraints))
|
|
87
|
-
invariant(mapping.constraints?.[key] === value);
|
|
88
|
-
if (configuration.mode === "batch") invariant(mapping.d1?.primary === true);
|
|
89
|
-
|
|
90
|
-
return Object.freeze({
|
|
91
|
-
...mapping,
|
|
92
|
-
policy: Object.freeze({ ...mapping.policy }),
|
|
93
|
-
subject: Object.freeze({ ...mapping.subject }),
|
|
94
|
-
state: Object.freeze({ ...mapping.state }),
|
|
95
|
-
identifier: Object.freeze({ ...mapping.identifier }),
|
|
96
|
-
admission: Object.freeze({ ...mapping.admission }),
|
|
97
|
-
credential: Object.freeze({ ...mapping.credential }),
|
|
98
|
-
subjectIds: Object.freeze({ ...mapping.subjectIds }),
|
|
99
|
-
});
|
|
100
|
-
};
|
|
24
|
+
const validate = Effect.fnUntraced(
|
|
25
|
+
function* (source: AnyPhoneMapping, configuration: NativeTargetConfiguration) {
|
|
26
|
+
yield* validateDrizzleStorage(source);
|
|
27
|
+
yield* validateDrizzleStorage(source.proofs);
|
|
28
|
+
yield* Schema.decodeEffect(PhoneLifecyclePolicy)(source.policy);
|
|
29
|
+
if (configuration.mode === "batch" && source.proofs.d1?.primary !== true)
|
|
30
|
+
return yield* PhoneConfigurationError.make({});
|
|
31
|
+
},
|
|
32
|
+
Effect.mapError(() => PhoneConfigurationError.make({})),
|
|
33
|
+
);
|
|
101
34
|
|
|
102
35
|
const services = Effect.fnUntraced(function* (
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
const run = <A, E, R>(effect: Effect.Effect<A, E, R>, mutation = true) =>
|
|
110
|
-
execution.admit.pipe(
|
|
111
|
-
Effect.andThen(execution.run(effect, mutation)),
|
|
112
|
-
Effect.provideService(LifecycleHooks, hooks),
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
return {
|
|
116
|
-
phoneAdmission: PhoneAdmission.of({
|
|
117
|
-
admit: (input) => run(admitPhone(mapping, { ...input })),
|
|
118
|
-
cleanup: (input) => run(cleanupPhoneAdmission(mapping, { ...input })),
|
|
119
|
-
}),
|
|
120
|
-
phoneSignInTargets: PhoneSignInTargets.of({
|
|
121
|
-
lookup: (input) => run(lookupPhone(mapping, { ...input }), false),
|
|
122
|
-
}),
|
|
123
|
-
phonePersistence: PhonePersistence.of({
|
|
124
|
-
target: (input) =>
|
|
125
|
-
run(
|
|
126
|
-
Effect.gen(function* () {
|
|
127
|
-
invariant(input.moduleId === mapping.moduleId);
|
|
128
|
-
|
|
129
|
-
return (yield* capturePhone(mapping, { ...input })).target;
|
|
130
|
-
}),
|
|
131
|
-
false,
|
|
132
|
-
),
|
|
133
|
-
mutate: (original, prepare) =>
|
|
134
|
-
Effect.suspend(() => {
|
|
135
|
-
const input: PhoneMutation = {
|
|
136
|
-
...original,
|
|
137
|
-
target: Schema.decodeSync(Schema.toCodecIso(PhoneLifecycleTarget))(
|
|
138
|
-
Schema.encodeSync(Schema.toCodecIso(PhoneLifecycleTarget))(original.target),
|
|
139
|
-
),
|
|
140
|
-
policy: { ...original.policy },
|
|
141
|
-
...(original.authorization === undefined
|
|
142
|
-
? {}
|
|
143
|
-
: {
|
|
144
|
-
authorization: Schema.decodeSync(Schema.toCodecIso(PhoneActionAuthorization))(
|
|
145
|
-
Schema.encodeSync(Schema.toCodecIso(PhoneActionAuthorization))(
|
|
146
|
-
original.authorization,
|
|
147
|
-
),
|
|
148
|
-
),
|
|
149
|
-
}),
|
|
150
|
-
completion: {
|
|
151
|
-
input: {
|
|
152
|
-
...original.completion.input,
|
|
153
|
-
binding: Schema.decodeSync(Schema.toCodecIso(ProofBinding))(
|
|
154
|
-
Schema.encodeSync(Schema.toCodecIso(ProofBinding))(
|
|
155
|
-
original.completion.input.binding,
|
|
156
|
-
),
|
|
157
|
-
),
|
|
158
|
-
},
|
|
159
|
-
prepare: original.completion.prepare,
|
|
160
|
-
},
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
return run(
|
|
164
|
-
Effect.gen(function* () {
|
|
165
|
-
const owner = yield* CurrentPhoneTransaction,
|
|
166
|
-
candidate = yield* preparePhoneMutation(mapping, input);
|
|
167
|
-
|
|
168
|
-
if (candidate.mutate === undefined) {
|
|
169
|
-
const receipt = prepare(candidate.decision, owner.journal);
|
|
170
|
-
|
|
171
|
-
owner.guards.push(receipt as any);
|
|
172
|
-
|
|
173
|
-
return receipt;
|
|
174
|
-
}
|
|
175
|
-
const cn = phoneProofs(mapping.proofs).continuation;
|
|
176
|
-
|
|
177
|
-
const observed = yield* owner.read(
|
|
178
|
-
cn.table,
|
|
179
|
-
equal(cn.table, {
|
|
180
|
-
[cn.moduleId]: input.completion.input.moduleId,
|
|
181
|
-
[cn.continuationId]: input.completion.input.continuationId,
|
|
182
|
-
}),
|
|
183
|
-
{ limit: 1 },
|
|
184
|
-
);
|
|
185
|
-
|
|
186
|
-
let completed = false;
|
|
187
|
-
|
|
188
|
-
const plan = {
|
|
189
|
-
...input.completion,
|
|
190
|
-
prepare: (decision: any, journal: any) => {
|
|
191
|
-
completed = decision === "completed";
|
|
192
|
-
const proofReceipt = input.completion.prepare(decision, journal, () => undefined);
|
|
193
|
-
|
|
194
|
-
owner.guards.push(proofReceipt);
|
|
195
|
-
|
|
196
|
-
return prepare(
|
|
197
|
-
decision === "completed" ? candidate.decision : { _tag: "Rejected" },
|
|
198
|
-
journal,
|
|
199
|
-
);
|
|
200
|
-
},
|
|
201
|
-
};
|
|
36
|
+
source: AnyPhoneMapping,
|
|
37
|
+
configuration: NativeTargetConfiguration,
|
|
38
|
+
) {
|
|
39
|
+
const target = yield* nativeTarget(configuration);
|
|
40
|
+
const mapping: SharedMapping = { ...source, proofs: nativeProofMapping(source.proofs) };
|
|
202
41
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (owner.batch) {
|
|
206
|
-
const offset = owner.statements.length;
|
|
207
|
-
|
|
208
|
-
yield* candidate.mutate;
|
|
209
|
-
const statements = owner.statements.splice(offset);
|
|
210
|
-
|
|
211
|
-
const compiled = yield* compileD1ProofCompletionPlan(
|
|
212
|
-
phoneProofs(mapping.proofs) as any,
|
|
213
|
-
plan as any,
|
|
214
|
-
{ statements, appliedCondition: candidate.appliedCondition! },
|
|
215
|
-
(x) => x,
|
|
216
|
-
).pipe(Effect.provideService(CurrentD1PlanningDatabase, owner.database));
|
|
217
|
-
|
|
218
|
-
// Mutation observations describe an accepted plan. A stale proof aborts this owner.
|
|
219
|
-
invariant(compiled.statements.length !== 0);
|
|
220
|
-
owner.statements.push(...compiled.statements, ...(compiled.postconditions ?? []));
|
|
221
|
-
receipt = compiled.receipt;
|
|
222
|
-
} else {
|
|
223
|
-
receipt = yield* completeProofPlanIn(
|
|
224
|
-
phoneProofs(mapping.proofs),
|
|
225
|
-
{
|
|
226
|
-
mode: configuration.mode === "synchronous" ? "synchronous" : "interactive",
|
|
227
|
-
locking: configuration.locking,
|
|
228
|
-
standaloneGuard: Effect.void,
|
|
229
|
-
coordinated: true,
|
|
230
|
-
insertIfAbsent: (query: any, key, value) =>
|
|
231
|
-
configuration.dialect === "mysql"
|
|
232
|
-
? query.onDuplicateKeyUpdate({ set: { [key]: value } })
|
|
233
|
-
: query.onConflictDoNothing(),
|
|
234
|
-
},
|
|
235
|
-
plan as any,
|
|
236
|
-
candidate.mutate,
|
|
237
|
-
(x) => x,
|
|
238
|
-
).pipe(Effect.provideService(CurrentProofSql, owner.database));
|
|
239
|
-
}
|
|
240
|
-
if (completed) {
|
|
241
|
-
invariant(observed.rows.length === 1);
|
|
242
|
-
const record = yield* cn.decode(observed.rows[0]!);
|
|
243
|
-
|
|
244
|
-
observed.rows = observed.rows.map((row) => ({ ...row, [cn.consumed]: true }));
|
|
245
|
-
const command = phoneProofs(mapping.proofs).command;
|
|
246
|
-
|
|
247
|
-
owner.postconditions.push(
|
|
248
|
-
sql`${mapping.engineNowMillis} < ${record.expiresAtMillis}`,
|
|
249
|
-
sql`exists(select 1 from ${command.table} where ${equal(command.table, { [command.moduleId]: input.completion.input.moduleId, [command.commandId]: input.completion.input.continuationDigest, [command.kind]: "complete", [command.decision]: "completed", [command.retentionUntil]: phoneProofs(mapping.proofs).encodeInstant(record.expiresAtMillis) })})`,
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
invariant(receipt?._tag === "PreparedCommit");
|
|
253
|
-
owner.guards.push(receipt as any);
|
|
254
|
-
|
|
255
|
-
return receipt as ReturnType<typeof prepare>;
|
|
256
|
-
}),
|
|
257
|
-
);
|
|
258
|
-
}).pipe(Effect.catchDefect(() => Effect.fail(unavailable()))),
|
|
259
|
-
}),
|
|
260
|
-
};
|
|
42
|
+
return yield* target.provide(makeNativePhoneServices(target.tables, mapping));
|
|
261
43
|
});
|
|
262
44
|
|
|
263
|
-
export const
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
C extends Table,
|
|
268
|
-
N,
|
|
269
|
-
RSetup = never,
|
|
270
|
-
>(
|
|
271
|
-
source: PhoneMappingSource<PhoneMapping<S, I, C, F, N>, RSetup>,
|
|
272
|
-
configuration: PhoneTargetConfiguration,
|
|
273
|
-
) =>
|
|
274
|
-
Effect.gen(function* () {
|
|
275
|
-
const original = yield* Effect.isEffect(source) ? source : Effect.succeed(source);
|
|
276
|
-
|
|
277
|
-
const mapping = yield* Effect.try({
|
|
278
|
-
try: () => validateMapping(original, configuration),
|
|
279
|
-
catch: () => PhoneConfigurationError.make({}),
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
yield* validateDrizzleStorage({
|
|
283
|
-
...mapping,
|
|
284
|
-
proofs: phoneProofs(mapping.proofs),
|
|
285
|
-
}).pipe(Effect.mapError(() => PhoneConfigurationError.make({})));
|
|
286
|
-
|
|
287
|
-
const execution = yield* makeTransactionExecution(
|
|
288
|
-
CurrentPhoneTransaction,
|
|
289
|
-
configuration,
|
|
290
|
-
unavailable,
|
|
291
|
-
randomId,
|
|
292
|
-
);
|
|
45
|
+
export const makeTargetPhonePersistenceServices = (
|
|
46
|
+
source: AnyPhoneMapping,
|
|
47
|
+
configuration: NativeTargetConfiguration,
|
|
48
|
+
) => validate(source, configuration).pipe(Effect.andThen(services(source, configuration)));
|
|
293
49
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
configuration: PhoneTargetConfiguration,
|
|
307
|
-
body: (
|
|
308
|
-
transaction: any,
|
|
309
|
-
services: PhonePersistenceServices,
|
|
310
|
-
append: (statement: Statement<any>) => void,
|
|
311
|
-
) => Effect.Effect<A, E, R>,
|
|
312
|
-
): Effect.Effect<
|
|
313
|
-
A,
|
|
314
|
-
PhoneCoordinatorError<E>,
|
|
315
|
-
R | RSetup | Crypto.Crypto | LifecycleHooks | NativeDatabase
|
|
316
|
-
> =>
|
|
317
|
-
Effect.gen(function* () {
|
|
318
|
-
const original = yield* Effect.isEffect(source) ? source : Effect.succeed(source);
|
|
319
|
-
|
|
320
|
-
const mapping = yield* Effect.try({
|
|
321
|
-
try: () => validateMapping(original, configuration),
|
|
322
|
-
catch: () => PhoneConfigurationError.make({}),
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
yield* validateDrizzleStorage({
|
|
326
|
-
...mapping,
|
|
327
|
-
proofs: phoneProofs(mapping.proofs),
|
|
328
|
-
}).pipe(Effect.mapError(() => PhoneConfigurationError.make({})));
|
|
329
|
-
|
|
330
|
-
return yield* coordinateTransactionOwner(
|
|
331
|
-
database,
|
|
332
|
-
CurrentPhoneTransaction,
|
|
333
|
-
configuration,
|
|
334
|
-
Effect.void,
|
|
335
|
-
unavailable,
|
|
336
|
-
randomId,
|
|
337
|
-
(execution) => services(mapping, execution, configuration),
|
|
338
|
-
(transaction, acquireServices, append) =>
|
|
339
|
-
Effect.flatMap(acquireServices, (boundServices) =>
|
|
340
|
-
body(transaction, boundServices, append),
|
|
341
|
-
),
|
|
342
|
-
);
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
type TransactionOf<D> = D extends { readonly transaction: (...args: any[]) => any }
|
|
346
|
-
? Parameters<Parameters<D["transaction"]>[0]>[0]
|
|
347
|
-
: never;
|
|
348
|
-
|
|
349
|
-
/** Concrete driver wrappers select transaction mode. */
|
|
350
|
-
export const makePhoneTarget = <
|
|
351
|
-
DatabaseId,
|
|
352
|
-
D extends { readonly transaction: any },
|
|
353
|
-
T extends Table,
|
|
354
|
-
Extra = unknown,
|
|
355
|
-
Synchronous extends boolean = false,
|
|
356
|
-
>(
|
|
357
|
-
databaseService: Context.Service<DatabaseId, D>,
|
|
358
|
-
configuration: PhoneTargetConfiguration,
|
|
359
|
-
) => {
|
|
360
|
-
function coordinatePhonePersistence<
|
|
361
|
-
Database extends D,
|
|
362
|
-
S extends T,
|
|
363
|
-
I extends T,
|
|
364
|
-
F extends T,
|
|
365
|
-
C extends T,
|
|
366
|
-
N,
|
|
367
|
-
A,
|
|
368
|
-
E,
|
|
369
|
-
R,
|
|
370
|
-
RSetup = never,
|
|
371
|
-
DatabaseError = never,
|
|
372
|
-
DatabaseRequirements = never,
|
|
373
|
-
>(
|
|
374
|
-
acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,
|
|
375
|
-
options: {
|
|
376
|
-
readonly mapping: PhoneMappingSource<PhoneMapping<S, I, C, F, N> & Extra, RSetup>;
|
|
377
|
-
readonly transaction?: never;
|
|
378
|
-
},
|
|
379
|
-
body: Effect.Effect<
|
|
380
|
-
A,
|
|
381
|
-
E,
|
|
382
|
-
Synchronous extends true ? NoInfer<PhonePersistence | PhoneAdmission | PhoneSignInTargets> : R
|
|
383
|
-
>,
|
|
384
|
-
): Effect.Effect<
|
|
385
|
-
A,
|
|
386
|
-
PhoneCoordinatorError<E> | DatabaseError,
|
|
387
|
-
| (Synchronous extends true
|
|
388
|
-
? never
|
|
389
|
-
: Exclude<R, PhonePersistence | PhoneAdmission | PhoneSignInTargets>)
|
|
390
|
-
| Crypto.Crypto
|
|
391
|
-
| LifecycleHooks
|
|
392
|
-
| RSetup
|
|
393
|
-
| DatabaseRequirements
|
|
394
|
-
>;
|
|
395
|
-
function coordinatePhonePersistence<
|
|
396
|
-
Database extends D,
|
|
397
|
-
S extends T,
|
|
398
|
-
I extends T,
|
|
399
|
-
F extends T,
|
|
400
|
-
C extends T,
|
|
401
|
-
N,
|
|
402
|
-
A,
|
|
403
|
-
E,
|
|
404
|
-
R,
|
|
405
|
-
TxId,
|
|
406
|
-
TxShape,
|
|
407
|
-
RSetup = never,
|
|
408
|
-
DatabaseError = never,
|
|
409
|
-
DatabaseRequirements = never,
|
|
410
|
-
>(
|
|
411
|
-
acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,
|
|
412
|
-
options: {
|
|
413
|
-
readonly mapping: PhoneMappingSource<PhoneMapping<S, I, C, F, N> & Extra, RSetup>;
|
|
414
|
-
readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<Database>>, TxShape>;
|
|
415
|
-
},
|
|
416
|
-
body: Effect.Effect<
|
|
417
|
-
A,
|
|
418
|
-
E,
|
|
419
|
-
Synchronous extends true
|
|
420
|
-
? NoInfer<PhonePersistence | PhoneAdmission | PhoneSignInTargets | TxId>
|
|
421
|
-
: R
|
|
422
|
-
>,
|
|
423
|
-
): Effect.Effect<
|
|
424
|
-
A,
|
|
425
|
-
PhoneCoordinatorError<E> | DatabaseError,
|
|
426
|
-
| (Synchronous extends true
|
|
427
|
-
? never
|
|
428
|
-
: Exclude<R, PhonePersistence | PhoneAdmission | PhoneSignInTargets | TxId>)
|
|
429
|
-
| Crypto.Crypto
|
|
430
|
-
| LifecycleHooks
|
|
431
|
-
| RSetup
|
|
432
|
-
| DatabaseRequirements
|
|
433
|
-
>;
|
|
434
|
-
function coordinatePhonePersistence<
|
|
435
|
-
Database extends D,
|
|
436
|
-
S extends T,
|
|
437
|
-
I extends T,
|
|
438
|
-
F extends T,
|
|
439
|
-
C extends T,
|
|
440
|
-
N,
|
|
441
|
-
A,
|
|
442
|
-
E,
|
|
443
|
-
R,
|
|
444
|
-
TxId,
|
|
445
|
-
TxShape,
|
|
446
|
-
RSetup = never,
|
|
447
|
-
DatabaseError = never,
|
|
448
|
-
DatabaseRequirements = never,
|
|
449
|
-
>(
|
|
450
|
-
acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,
|
|
451
|
-
options: {
|
|
452
|
-
readonly mapping: PhoneMappingSource<PhoneMapping<S, I, C, F, N> & Extra, RSetup>;
|
|
453
|
-
readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<Database>>, TxShape>;
|
|
454
|
-
},
|
|
455
|
-
body: Effect.Effect<A, E, R>,
|
|
456
|
-
): Effect.Effect<
|
|
457
|
-
A,
|
|
458
|
-
PhoneCoordinatorError<E> | DatabaseError,
|
|
459
|
-
| Exclude<R, PhonePersistence | PhoneAdmission | PhoneSignInTargets>
|
|
460
|
-
| Crypto.Crypto
|
|
461
|
-
| LifecycleHooks
|
|
462
|
-
| RSetup
|
|
463
|
-
| DatabaseRequirements
|
|
464
|
-
> {
|
|
465
|
-
return Effect.flatMap(nativeDatabase(acquire), (database) =>
|
|
466
|
-
coordinateTargetPhone(
|
|
467
|
-
database as any,
|
|
468
|
-
options.mapping,
|
|
50
|
+
export const coordinateTargetPhonePersistence = <Transaction, A, E, R>(
|
|
51
|
+
database: NativeDatabaseHandle,
|
|
52
|
+
source: AnyPhoneMapping,
|
|
53
|
+
configuration: NativeTargetConfiguration,
|
|
54
|
+
body: (transaction: Transaction, services: PhonePersistenceServices) => Effect.Effect<A, E, R>,
|
|
55
|
+
) =>
|
|
56
|
+
validate(source, configuration).pipe(
|
|
57
|
+
Effect.provideService(NativeDatabase, database),
|
|
58
|
+
Effect.andThen(
|
|
59
|
+
coordinateNativeTarget(
|
|
60
|
+
unavailable,
|
|
61
|
+
database,
|
|
469
62
|
configuration,
|
|
470
|
-
(
|
|
471
|
-
|
|
472
|
-
services,
|
|
473
|
-
): Effect.Effect<
|
|
474
|
-
A,
|
|
475
|
-
E,
|
|
476
|
-
Exclude<R, PhonePersistence | PhoneAdmission | PhoneSignInTargets>
|
|
477
|
-
> => {
|
|
478
|
-
const provided = Context.make(PhonePersistence, services.phonePersistence).pipe(
|
|
479
|
-
Context.add(PhoneAdmission, services.phoneAdmission),
|
|
480
|
-
Context.add(PhoneSignInTargets, services.phoneSignInTargets),
|
|
481
|
-
);
|
|
482
|
-
|
|
483
|
-
const work = Effect.provideContext(body, provided);
|
|
484
|
-
|
|
485
|
-
return options.transaction === undefined
|
|
486
|
-
? work
|
|
487
|
-
: Effect.provideService(work, options.transaction, options.transaction.of(transaction));
|
|
488
|
-
},
|
|
489
|
-
).pipe(Effect.provideService(NativeDatabase, database)),
|
|
490
|
-
);
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
return {
|
|
494
|
-
makePhonePersistenceServices: <
|
|
495
|
-
S extends T,
|
|
496
|
-
I extends T,
|
|
497
|
-
F extends T,
|
|
498
|
-
C extends T,
|
|
499
|
-
N,
|
|
500
|
-
RSetup = never,
|
|
501
|
-
>(
|
|
502
|
-
mapping: PhoneMappingSource<PhoneMapping<S, I, C, F, N> & Extra, RSetup>,
|
|
503
|
-
) =>
|
|
504
|
-
makeTargetPhonePersistence(mapping, configuration).pipe(
|
|
505
|
-
Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),
|
|
63
|
+
services(source, configuration),
|
|
64
|
+
body,
|
|
506
65
|
),
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
};
|
|
66
|
+
),
|
|
67
|
+
);
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { LifecycleHooks } from "@yielded/auth/Hooks";
|
|
2
|
+
import { ProofPersistence, type ProofUnavailable } from "@yielded/auth/Proofs";
|
|
3
|
+
import type { Table } from "drizzle-orm";
|
|
4
|
+
import { type Context, Effect, type Crypto } from "effect";
|
|
5
|
+
|
|
6
|
+
import type { NativeDriverDatabase, NativeDriverTransaction } from "./driver-types";
|
|
7
|
+
import { NativeDatabase, nativeDatabase } from "./native-database";
|
|
8
|
+
import type { NativeTargetConfiguration } from "./native-target";
|
|
9
|
+
import type { AnyProofPersistenceMapping, ProofPersistenceMapping } from "./proof-model";
|
|
10
|
+
import {
|
|
11
|
+
coordinateTargetProofPersistence,
|
|
12
|
+
makeTargetProofPersistenceServices,
|
|
13
|
+
} from "./proof-target";
|
|
14
|
+
import type { SuppliedService } from "./SuppliedService";
|
|
15
|
+
|
|
16
|
+
/** Physical driver selection; the proof workflow has one implementation.
|
|
17
|
+
* Erase only foreign table/ID callback variance at the validated mapping boundary;
|
|
18
|
+
* decoded proof and subject values still pass through their owning codecs. */
|
|
19
|
+
export const makeProofTarget = <DatabaseId, D extends NativeDriverDatabase>(
|
|
20
|
+
databaseService: Context.Service<DatabaseId, D>,
|
|
21
|
+
configuration: NativeTargetConfiguration,
|
|
22
|
+
) => {
|
|
23
|
+
function coordinateProofPersistence<
|
|
24
|
+
Database extends D,
|
|
25
|
+
Proof extends Table,
|
|
26
|
+
Subject extends Table,
|
|
27
|
+
NativeId,
|
|
28
|
+
A,
|
|
29
|
+
E,
|
|
30
|
+
R,
|
|
31
|
+
DE,
|
|
32
|
+
DR,
|
|
33
|
+
>(
|
|
34
|
+
acquire: Effect.Effect<Database, DE, DR>,
|
|
35
|
+
options: {
|
|
36
|
+
readonly mapping: ProofPersistenceMapping<Proof, Subject, NativeId>;
|
|
37
|
+
readonly transaction?: never;
|
|
38
|
+
},
|
|
39
|
+
body: Effect.Effect<A, E, R>,
|
|
40
|
+
): Effect.Effect<
|
|
41
|
+
A,
|
|
42
|
+
E | DE | ProofUnavailable,
|
|
43
|
+
Exclude<R, ProofPersistence> | DR | LifecycleHooks | Crypto.Crypto
|
|
44
|
+
>;
|
|
45
|
+
function coordinateProofPersistence<
|
|
46
|
+
Database extends D,
|
|
47
|
+
Proof extends Table,
|
|
48
|
+
Subject extends Table,
|
|
49
|
+
NativeId,
|
|
50
|
+
A,
|
|
51
|
+
E,
|
|
52
|
+
R,
|
|
53
|
+
DE,
|
|
54
|
+
DR,
|
|
55
|
+
TxId,
|
|
56
|
+
TxShape,
|
|
57
|
+
>(
|
|
58
|
+
acquire: Effect.Effect<Database, DE, DR>,
|
|
59
|
+
options: {
|
|
60
|
+
readonly mapping: ProofPersistenceMapping<Proof, Subject, NativeId>;
|
|
61
|
+
readonly transaction: SuppliedService<
|
|
62
|
+
TxId,
|
|
63
|
+
NoInfer<NativeDriverTransaction<Database>>,
|
|
64
|
+
TxShape
|
|
65
|
+
>;
|
|
66
|
+
},
|
|
67
|
+
body: Effect.Effect<A, E, R>,
|
|
68
|
+
): Effect.Effect<
|
|
69
|
+
A,
|
|
70
|
+
E | DE | ProofUnavailable,
|
|
71
|
+
Exclude<R, ProofPersistence | TxId> | DR | LifecycleHooks | Crypto.Crypto
|
|
72
|
+
>;
|
|
73
|
+
function coordinateProofPersistence<
|
|
74
|
+
Database extends D,
|
|
75
|
+
Proof extends Table,
|
|
76
|
+
Subject extends Table,
|
|
77
|
+
NativeId,
|
|
78
|
+
A,
|
|
79
|
+
E,
|
|
80
|
+
R,
|
|
81
|
+
DE,
|
|
82
|
+
DR,
|
|
83
|
+
TxId,
|
|
84
|
+
TxShape,
|
|
85
|
+
>(
|
|
86
|
+
acquire: Effect.Effect<Database, DE, DR>,
|
|
87
|
+
options: {
|
|
88
|
+
readonly mapping: ProofPersistenceMapping<Proof, Subject, NativeId>;
|
|
89
|
+
readonly transaction?: SuppliedService<
|
|
90
|
+
TxId,
|
|
91
|
+
NoInfer<NativeDriverTransaction<Database>>,
|
|
92
|
+
TxShape
|
|
93
|
+
>;
|
|
94
|
+
},
|
|
95
|
+
body: Effect.Effect<A, E, R>,
|
|
96
|
+
) {
|
|
97
|
+
return Effect.flatMap(nativeDatabase(acquire), (database) =>
|
|
98
|
+
coordinateTargetProofPersistence(
|
|
99
|
+
database,
|
|
100
|
+
options.mapping as unknown as AnyProofPersistenceMapping,
|
|
101
|
+
configuration,
|
|
102
|
+
(transaction: NativeDriverTransaction<Database>, services) => {
|
|
103
|
+
const work = Effect.provideService(body, ProofPersistence, services.proofPersistence);
|
|
104
|
+
|
|
105
|
+
return options.transaction === undefined
|
|
106
|
+
? work
|
|
107
|
+
: Effect.provideService(work, options.transaction, options.transaction.of(transaction));
|
|
108
|
+
},
|
|
109
|
+
),
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
makeProofPersistenceServices: <Proof extends Table, Subject extends Table, NativeId>(
|
|
115
|
+
mapping: ProofPersistenceMapping<Proof, Subject, NativeId>,
|
|
116
|
+
) =>
|
|
117
|
+
makeTargetProofPersistenceServices(
|
|
118
|
+
mapping as unknown as AnyProofPersistenceMapping,
|
|
119
|
+
configuration,
|
|
120
|
+
).pipe(Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService))),
|
|
121
|
+
coordinateProofPersistence,
|
|
122
|
+
};
|
|
123
|
+
};
|