@yielded/auth-persistence 0.1.0-beta.7
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 +21 -0
- package/dist/Drizzle.d.mts +28 -0
- package/dist/Drizzle.mjs +28 -0
- package/dist/DrizzleD1.d.mts +963 -0
- package/dist/DrizzleD1.mjs +29 -0
- package/dist/DrizzleD1.mjs.map +1 -0
- package/dist/DrizzleLibsql.d.mts +2284 -0
- package/dist/DrizzleLibsql.mjs +92 -0
- package/dist/DrizzleLibsql.mjs.map +1 -0
- package/dist/DrizzleMysql2.d.mts +1820 -0
- package/dist/DrizzleMysql2.mjs +55 -0
- package/dist/DrizzleMysql2.mjs.map +1 -0
- package/dist/DrizzlePglite.d.mts +1826 -0
- package/dist/DrizzlePglite.mjs +53 -0
- package/dist/DrizzlePglite.mjs.map +1 -0
- package/dist/DrizzlePostgres.d.mts +1826 -0
- package/dist/DrizzlePostgres.mjs +53 -0
- package/dist/DrizzlePostgres.mjs.map +1 -0
- package/dist/DrizzleSqliteBun.d.mts +2279 -0
- package/dist/DrizzleSqliteBun.mjs +70 -0
- package/dist/DrizzleSqliteBun.mjs.map +1 -0
- package/dist/DrizzleSqliteDo.d.mts +2329 -0
- package/dist/DrizzleSqliteDo.mjs +105 -0
- package/dist/DrizzleSqliteDo.mjs.map +1 -0
- package/dist/DrizzleSqliteNode.d.mts +2279 -0
- package/dist/DrizzleSqliteNode.mjs +70 -0
- package/dist/DrizzleSqliteNode.mjs.map +1 -0
- package/dist/DrizzleSqliteWasm.d.mts +2282 -0
- package/dist/DrizzleSqliteWasm.mjs +70 -0
- package/dist/DrizzleSqliteWasm.mjs.map +1 -0
- package/dist/drizzle/D1BatchStatements.d.mts +11 -0
- package/dist/drizzle/D1BatchStatements.mjs +8 -0
- package/dist/drizzle/D1BatchStatements.mjs.map +1 -0
- package/dist/drizzle/PasswordPreparedPostconditions.mjs +12 -0
- package/dist/drizzle/PasswordPreparedPostconditions.mjs.map +1 -0
- package/dist/drizzle/SuppliedService.d.mts +10 -0
- package/dist/drizzle/d1-emails.d.mts +62 -0
- package/dist/drizzle/d1-emails.mjs +580 -0
- package/dist/drizzle/d1-emails.mjs.map +1 -0
- package/dist/drizzle/d1-generated-statement.d.mts +2 -0
- package/dist/drizzle/d1-generated-statement.mjs +79 -0
- package/dist/drizzle/d1-generated-statement.mjs.map +1 -0
- package/dist/drizzle/d1-identity.d.mts +31 -0
- package/dist/drizzle/d1-identity.mjs +119 -0
- package/dist/drizzle/d1-identity.mjs.map +1 -0
- package/dist/drizzle/d1-oauth.d.mts +301 -0
- package/dist/drizzle/d1-oauth.mjs +76 -0
- package/dist/drizzle/d1-oauth.mjs.map +1 -0
- package/dist/drizzle/d1-passkey.d.mts +51 -0
- package/dist/drizzle/d1-passkey.mjs +95 -0
- package/dist/drizzle/d1-passkey.mjs.map +1 -0
- package/dist/drizzle/d1-password-prepared.d.mts +25 -0
- package/dist/drizzle/d1-password-prepared.mjs +461 -0
- package/dist/drizzle/d1-password-prepared.mjs.map +1 -0
- package/dist/drizzle/d1-passwords.d.mts +87 -0
- package/dist/drizzle/d1-passwords.mjs +1004 -0
- package/dist/drizzle/d1-passwords.mjs.map +1 -0
- package/dist/drizzle/d1-phone.d.mts +26 -0
- package/dist/drizzle/d1-phone.mjs +30 -0
- package/dist/drizzle/d1-phone.mjs.map +1 -0
- package/dist/drizzle/d1-planning.d.mts +12 -0
- package/dist/drizzle/d1-planning.mjs +43 -0
- package/dist/drizzle/d1-planning.mjs.map +1 -0
- package/dist/drizzle/d1-proofs.d.mts +80 -0
- package/dist/drizzle/d1-proofs.mjs +830 -0
- package/dist/drizzle/d1-proofs.mjs.map +1 -0
- package/dist/drizzle/d1-sessions.d.mts +67 -0
- package/dist/drizzle/d1-sessions.mjs +966 -0
- package/dist/drizzle/d1-sessions.mjs.map +1 -0
- package/dist/drizzle/d1-totp.d.mts +26 -0
- package/dist/drizzle/d1-totp.mjs +27 -0
- package/dist/drizzle/d1-totp.mjs.map +1 -0
- package/dist/drizzle/email-model.d.mts +354 -0
- package/dist/drizzle/email-model.mjs +21 -0
- package/dist/drizzle/email-model.mjs.map +1 -0
- package/dist/drizzle/email-registration.d.mts +30 -0
- package/dist/drizzle/email-registration.mjs +238 -0
- package/dist/drizzle/email-registration.mjs.map +1 -0
- package/dist/drizzle/email-sql.d.mts +4 -0
- package/dist/drizzle/email-sql.mjs +9 -0
- package/dist/drizzle/email-sql.mjs.map +1 -0
- package/dist/drizzle/email-target.d.mts +20 -0
- package/dist/drizzle/email-target.mjs +72 -0
- package/dist/drizzle/email-target.mjs.map +1 -0
- package/dist/drizzle/model.d.mts +250 -0
- package/dist/drizzle/model.mjs +58 -0
- package/dist/drizzle/model.mjs.map +1 -0
- package/dist/drizzle/mysql-emails.d.mts +71 -0
- package/dist/drizzle/mysql-emails.mjs +38 -0
- package/dist/drizzle/mysql-emails.mjs.map +1 -0
- package/dist/drizzle/mysql-identity.d.mts +22 -0
- package/dist/drizzle/mysql-identity.mjs +94 -0
- package/dist/drizzle/mysql-identity.mjs.map +1 -0
- package/dist/drizzle/mysql-password-prepared.d.mts +30 -0
- package/dist/drizzle/mysql-password-prepared.mjs +16 -0
- package/dist/drizzle/mysql-password-prepared.mjs.map +1 -0
- package/dist/drizzle/mysql-passwords.d.mts +86 -0
- package/dist/drizzle/mysql-passwords.mjs +38 -0
- package/dist/drizzle/mysql-passwords.mjs.map +1 -0
- package/dist/drizzle/mysql-proofs.d.mts +75 -0
- package/dist/drizzle/mysql-proofs.mjs +23 -0
- package/dist/drizzle/mysql-proofs.mjs.map +1 -0
- package/dist/drizzle/mysql-sessions.d.mts +237 -0
- package/dist/drizzle/mysql-sessions.mjs +53 -0
- package/dist/drizzle/mysql-sessions.mjs.map +1 -0
- package/dist/drizzle/mysql.d.mts +70 -0
- package/dist/drizzle/mysql.mjs +218 -0
- package/dist/drizzle/mysql.mjs.map +1 -0
- package/dist/drizzle/oauth-accounts.mjs +358 -0
- package/dist/drizzle/oauth-accounts.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-access.mjs +210 -0
- package/dist/drizzle/oauth-connected-access.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-collection.mjs +202 -0
- package/dist/drizzle/oauth-connected-collection.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-custody.mjs +146 -0
- package/dist/drizzle/oauth-connected-custody.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-drivers.mjs +76 -0
- package/dist/drizzle/oauth-connected-drivers.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-flow.mjs +247 -0
- package/dist/drizzle/oauth-connected-flow.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-input.mjs +103 -0
- package/dist/drizzle/oauth-connected-input.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-maintenance.mjs +214 -0
- package/dist/drizzle/oauth-connected-maintenance.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-management.mjs +228 -0
- package/dist/drizzle/oauth-connected-management.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-model.d.mts +278 -0
- package/dist/drizzle/oauth-connected-model.mjs +22 -0
- package/dist/drizzle/oauth-connected-model.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-reference.d.mts +17 -0
- package/dist/drizzle/oauth-connected-reference.mjs +53 -0
- package/dist/drizzle/oauth-connected-reference.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-settlement.mjs +117 -0
- package/dist/drizzle/oauth-connected-settlement.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-state.d.mts +14 -0
- package/dist/drizzle/oauth-connected-state.mjs +422 -0
- package/dist/drizzle/oauth-connected-state.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-target.d.mts +753 -0
- package/dist/drizzle/oauth-connected-target.mjs +91 -0
- package/dist/drizzle/oauth-connected-target.mjs.map +1 -0
- package/dist/drizzle/oauth-drivers.mjs +51 -0
- package/dist/drizzle/oauth-drivers.mjs.map +1 -0
- package/dist/drizzle/oauth-flow.d.mts +5 -0
- package/dist/drizzle/oauth-flow.mjs +253 -0
- package/dist/drizzle/oauth-flow.mjs.map +1 -0
- package/dist/drizzle/oauth-input.mjs +127 -0
- package/dist/drizzle/oauth-input.mjs.map +1 -0
- package/dist/drizzle/oauth-model.d.mts +463 -0
- package/dist/drizzle/oauth-model.mjs +49 -0
- package/dist/drizzle/oauth-model.mjs.map +1 -0
- package/dist/drizzle/oauth-mysql.mjs +8 -0
- package/dist/drizzle/oauth-mysql.mjs.map +1 -0
- package/dist/drizzle/oauth-owner.d.mts +4 -0
- package/dist/drizzle/oauth-owner.mjs +10 -0
- package/dist/drizzle/oauth-owner.mjs.map +1 -0
- package/dist/drizzle/oauth-registration.d.mts +6 -0
- package/dist/drizzle/oauth-registration.mjs +374 -0
- package/dist/drizzle/oauth-registration.mjs.map +1 -0
- package/dist/drizzle/oauth-state.mjs +107 -0
- package/dist/drizzle/oauth-state.mjs.map +1 -0
- package/dist/drizzle/oauth-target.d.mts +111 -0
- package/dist/drizzle/oauth-target.mjs +246 -0
- package/dist/drizzle/oauth-target.mjs.map +1 -0
- package/dist/drizzle/passkey-drivers.mjs +34 -0
- package/dist/drizzle/passkey-drivers.mjs.map +1 -0
- package/dist/drizzle/passkey-kernel.mjs +8 -0
- package/dist/drizzle/passkey-kernel.mjs.map +1 -0
- package/dist/drizzle/passkey-model.d.mts +272 -0
- package/dist/drizzle/passkey-model.mjs +34 -0
- package/dist/drizzle/passkey-model.mjs.map +1 -0
- package/dist/drizzle/passkey-registration-ceremony-model.d.mts +50 -0
- package/dist/drizzle/passkey-registration-ceremony-model.mjs +18 -0
- package/dist/drizzle/passkey-registration-ceremony-model.mjs.map +1 -0
- package/dist/drizzle/passkey-state.mjs +7 -0
- package/dist/drizzle/passkey-state.mjs.map +1 -0
- package/dist/drizzle/passkey-target.d.mts +9 -0
- package/dist/drizzle/passkey-target.mjs +7 -0
- package/dist/drizzle/passkey-target.mjs.map +1 -0
- package/dist/drizzle/passkey-write-drivers.mjs +32 -0
- package/dist/drizzle/passkey-write-drivers.mjs.map +1 -0
- package/dist/drizzle/passkey-write-model.d.mts +190 -0
- package/dist/drizzle/passkey-write-model.mjs +13 -0
- package/dist/drizzle/passkey-write-model.mjs.map +1 -0
- package/dist/drizzle/passkey-write-target.d.mts +11 -0
- package/dist/drizzle/passkey-write-target.mjs +7 -0
- package/dist/drizzle/passkey-write-target.mjs.map +1 -0
- package/dist/drizzle/password-model.d.mts +329 -0
- package/dist/drizzle/password-model.mjs +23 -0
- package/dist/drizzle/password-model.mjs.map +1 -0
- package/dist/drizzle/password-prepared-model.d.mts +94 -0
- package/dist/drizzle/password-prepared-model.mjs +11 -0
- package/dist/drizzle/password-prepared-model.mjs.map +1 -0
- package/dist/drizzle/password-prepared-sql.mjs +390 -0
- package/dist/drizzle/password-prepared-sql.mjs.map +1 -0
- package/dist/drizzle/password-prepared-state.mjs +104 -0
- package/dist/drizzle/password-prepared-state.mjs.map +1 -0
- package/dist/drizzle/password-prepared-target.d.mts +12 -0
- package/dist/drizzle/password-prepared-target.mjs +56 -0
- package/dist/drizzle/password-prepared-target.mjs.map +1 -0
- package/dist/drizzle/password-registration.d.mts +19 -0
- package/dist/drizzle/password-registration.mjs +135 -0
- package/dist/drizzle/password-registration.mjs.map +1 -0
- package/dist/drizzle/password-sql.d.mts +5 -0
- package/dist/drizzle/password-sql.mjs +9 -0
- package/dist/drizzle/password-sql.mjs.map +1 -0
- package/dist/drizzle/password-target.d.mts +17 -0
- package/dist/drizzle/password-target.mjs +61 -0
- package/dist/drizzle/password-target.mjs.map +1 -0
- package/dist/drizzle/pg-emails.d.mts +72 -0
- package/dist/drizzle/pg-emails.mjs +38 -0
- package/dist/drizzle/pg-emails.mjs.map +1 -0
- package/dist/drizzle/pg-password-prepared.d.mts +31 -0
- package/dist/drizzle/pg-password-prepared.mjs +16 -0
- package/dist/drizzle/pg-password-prepared.mjs.map +1 -0
- package/dist/drizzle/pg-passwords.d.mts +87 -0
- package/dist/drizzle/pg-passwords.mjs +38 -0
- package/dist/drizzle/pg-passwords.mjs.map +1 -0
- package/dist/drizzle/pg-proofs.d.mts +76 -0
- package/dist/drizzle/pg-proofs.mjs +22 -0
- package/dist/drizzle/pg-proofs.mjs.map +1 -0
- package/dist/drizzle/pg-sessions.d.mts +238 -0
- package/dist/drizzle/pg-sessions.mjs +53 -0
- package/dist/drizzle/pg-sessions.mjs.map +1 -0
- package/dist/drizzle/pg.d.mts +81 -0
- package/dist/drizzle/pg.mjs +290 -0
- package/dist/drizzle/pg.mjs.map +1 -0
- package/dist/drizzle/phone-model.d.mts +115 -0
- package/dist/drizzle/phone-model.mjs +39 -0
- package/dist/drizzle/phone-model.mjs.map +1 -0
- package/dist/drizzle/phone-state.mjs +16 -0
- package/dist/drizzle/phone-state.mjs.map +1 -0
- package/dist/drizzle/phone-target.d.mts +17 -0
- package/dist/drizzle/phone-target.mjs +170 -0
- package/dist/drizzle/phone-target.mjs.map +1 -0
- package/dist/drizzle/proof-model.d.mts +286 -0
- package/dist/drizzle/proof-model.mjs +17 -0
- package/dist/drizzle/proof-model.mjs.map +1 -0
- package/dist/drizzle/proof-sql.d.mts +4 -0
- package/dist/drizzle/proof-sql.mjs +8 -0
- package/dist/drizzle/proof-sql.mjs.map +1 -0
- package/dist/drizzle/proof-target.d.mts +12 -0
- package/dist/drizzle/proof-target.mjs +36 -0
- package/dist/drizzle/proof-target.mjs.map +1 -0
- package/dist/drizzle/query-operations.mjs +26 -0
- package/dist/drizzle/query-operations.mjs.map +1 -0
- package/dist/drizzle/session-model.d.mts +200 -0
- package/dist/drizzle/session-model.mjs +20 -0
- package/dist/drizzle/session-model.mjs.map +1 -0
- package/dist/drizzle/session-sql.mjs +8 -0
- package/dist/drizzle/session-sql.mjs.map +1 -0
- package/dist/drizzle/session-target.d.mts +28 -0
- package/dist/drizzle/session-target.mjs +47 -0
- package/dist/drizzle/session-target.mjs.map +1 -0
- package/dist/drizzle/sqlite-emails.mjs +45 -0
- package/dist/drizzle/sqlite-emails.mjs.map +1 -0
- package/dist/drizzle/sqlite-identity.mjs +91 -0
- package/dist/drizzle/sqlite-identity.mjs.map +1 -0
- package/dist/drizzle/sqlite-password-prepared.mjs +21 -0
- package/dist/drizzle/sqlite-password-prepared.mjs.map +1 -0
- package/dist/drizzle/sqlite-passwords.mjs +49 -0
- package/dist/drizzle/sqlite-passwords.mjs.map +1 -0
- package/dist/drizzle/sqlite-proofs.mjs +29 -0
- package/dist/drizzle/sqlite-proofs.mjs.map +1 -0
- package/dist/drizzle/sqlite-sessions.mjs +74 -0
- package/dist/drizzle/sqlite-sessions.mjs.map +1 -0
- package/dist/drizzle/sqlite.d.mts +78 -0
- package/dist/drizzle/sqlite.mjs +217 -0
- package/dist/drizzle/sqlite.mjs.map +1 -0
- package/dist/drizzle/standalone-guard.mjs +19 -0
- package/dist/drizzle/standalone-guard.mjs.map +1 -0
- package/dist/drizzle/step-up-model.d.mts +65 -0
- package/dist/drizzle/step-up-model.mjs +9 -0
- package/dist/drizzle/step-up-model.mjs.map +1 -0
- package/dist/drizzle/step-up-state.mjs +32 -0
- package/dist/drizzle/step-up-state.mjs.map +1 -0
- package/dist/drizzle/totp-model.d.mts +84 -0
- package/dist/drizzle/totp-model.mjs +13 -0
- package/dist/drizzle/totp-model.mjs.map +1 -0
- package/dist/drizzle/totp-state.d.mts +38 -0
- package/dist/drizzle/totp-state.mjs +287 -0
- package/dist/drizzle/totp-state.mjs.map +1 -0
- package/dist/drizzle/totp-target.d.mts +17 -0
- package/dist/drizzle/totp-target.mjs +81 -0
- package/dist/drizzle/totp-target.mjs.map +1 -0
- package/dist/drizzle/transaction-execution.d.mts +4 -0
- package/dist/drizzle/transaction-execution.mjs +11 -0
- package/dist/drizzle/transaction-execution.mjs.map +1 -0
- package/dist/drizzle/transaction-mysql.mjs +46 -0
- package/dist/drizzle/transaction-mysql.mjs.map +1 -0
- package/dist/drizzle/transaction-owner.d.mts +2 -0
- package/dist/drizzle/transaction-owner.mjs +8 -0
- package/dist/drizzle/transaction-owner.mjs.map +1 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +5 -0
- package/dist/internal/configuration.d.mts +174 -0
- package/dist/internal/configuration.mjs +7 -0
- package/dist/internal/configuration.mjs.map +1 -0
- package/dist/internal/drizzle-migrations.mjs +19 -0
- package/dist/internal/drizzle-migrations.mjs.map +1 -0
- package/dist/internal/drizzle-postgres.mjs +39 -0
- package/dist/internal/drizzle-postgres.mjs.map +1 -0
- package/dist/internal/drizzle-sqlite.mjs +37 -0
- package/dist/internal/drizzle-sqlite.mjs.map +1 -0
- package/dist/internal/email-kernel.d.mts +13 -0
- package/dist/internal/email-kernel.mjs +487 -0
- package/dist/internal/email-kernel.mjs.map +1 -0
- package/dist/internal/mapping-error.d.mts +11 -0
- package/dist/internal/mapping-error.mjs +30 -0
- package/dist/internal/mapping-error.mjs.map +1 -0
- package/dist/internal/passkey/admission.d.mts +7 -0
- package/dist/internal/passkey/admission.mjs +216 -0
- package/dist/internal/passkey/admission.mjs.map +1 -0
- package/dist/internal/passkey/credentials.d.mts +6 -0
- package/dist/internal/passkey/credentials.mjs +249 -0
- package/dist/internal/passkey/credentials.mjs.map +1 -0
- package/dist/internal/passkey/enrollment.mjs +138 -0
- package/dist/internal/passkey/enrollment.mjs.map +1 -0
- package/dist/internal/passkey/flow.d.mts +10 -0
- package/dist/internal/passkey/flow.mjs +452 -0
- package/dist/internal/passkey/flow.mjs.map +1 -0
- package/dist/internal/passkey/management.mjs +231 -0
- package/dist/internal/passkey/management.mjs.map +1 -0
- package/dist/internal/passkey/registration-ceremony.d.mts +9 -0
- package/dist/internal/passkey/registration-ceremony.mjs +129 -0
- package/dist/internal/passkey/registration-ceremony.mjs.map +1 -0
- package/dist/internal/passkey/registration-custody.d.mts +2 -0
- package/dist/internal/passkey/registration-custody.mjs +52 -0
- package/dist/internal/passkey/registration-custody.mjs.map +1 -0
- package/dist/internal/passkey/registration-write.mjs +211 -0
- package/dist/internal/passkey/registration-write.mjs.map +1 -0
- package/dist/internal/passkey/state.d.mts +5 -0
- package/dist/internal/passkey/state.mjs +234 -0
- package/dist/internal/passkey/state.mjs.map +1 -0
- package/dist/internal/passkey/target.d.mts +19 -0
- package/dist/internal/passkey/target.mjs +190 -0
- package/dist/internal/passkey/target.mjs.map +1 -0
- package/dist/internal/passkey/write-state.mjs +345 -0
- package/dist/internal/passkey/write-state.mjs.map +1 -0
- package/dist/internal/passkey/write-target.mjs +192 -0
- package/dist/internal/passkey/write-target.mjs.map +1 -0
- package/dist/internal/passkey-kernel.mjs +49 -0
- package/dist/internal/passkey-kernel.mjs.map +1 -0
- package/dist/internal/passkeys.mjs +367 -0
- package/dist/internal/passkeys.mjs.map +1 -0
- package/dist/internal/password-kernel.d.mts +13 -0
- package/dist/internal/password-kernel.mjs +704 -0
- package/dist/internal/password-kernel.mjs.map +1 -0
- package/dist/internal/persistence.mjs +289 -0
- package/dist/internal/persistence.mjs.map +1 -0
- package/dist/internal/phone-kernel.mjs +434 -0
- package/dist/internal/phone-kernel.mjs.map +1 -0
- package/dist/internal/proof-kernel.d.mts +9 -0
- package/dist/internal/proof-kernel.mjs +619 -0
- package/dist/internal/proof-kernel.mjs.map +1 -0
- package/dist/internal/query-operations.d.mts +3 -0
- package/dist/internal/registration.mjs +65 -0
- package/dist/internal/registration.mjs.map +1 -0
- package/dist/internal/session-kernel.mjs +737 -0
- package/dist/internal/session-kernel.mjs.map +1 -0
- package/dist/internal/sql-persistence.d.mts +11 -0
- package/dist/internal/sql-persistence.mjs +37 -0
- package/dist/internal/sql-persistence.mjs.map +1 -0
- package/dist/internal/sql-query.mjs +207 -0
- package/dist/internal/sql-query.mjs.map +1 -0
- package/dist/internal/sql-table.d.mts +37 -0
- package/dist/internal/sql-table.mjs +71 -0
- package/dist/internal/sql-table.mjs.map +1 -0
- package/dist/internal/storage-mapping.mjs +687 -0
- package/dist/internal/storage-mapping.mjs.map +1 -0
- package/dist/internal/storage-tables.d.mts +914 -0
- package/dist/internal/storage-tables.mjs +387 -0
- package/dist/internal/storage-tables.mjs.map +1 -0
- package/dist/internal/storage-validation.mjs +58 -0
- package/dist/internal/storage-validation.mjs.map +1 -0
- package/dist/internal/transaction-execution-kernel.d.mts +18 -0
- package/dist/internal/transaction-execution-kernel.mjs +118 -0
- package/dist/internal/transaction-execution-kernel.mjs.map +1 -0
- package/dist/internal/transaction-kernel.d.mts +7 -0
- package/dist/internal/transaction-kernel.mjs +260 -0
- package/dist/internal/transaction-kernel.mjs.map +1 -0
- package/package.json +1 -0
- package/src/Drizzle.ts +378 -0
- package/src/DrizzleD1.ts +136 -0
- package/src/DrizzleLibsql.ts +301 -0
- package/src/DrizzleMysql2.ts +184 -0
- package/src/DrizzlePglite.ts +174 -0
- package/src/DrizzlePostgres.ts +174 -0
- package/src/DrizzleSqliteBun.ts +258 -0
- package/src/DrizzleSqliteDo.ts +473 -0
- package/src/DrizzleSqliteNode.ts +259 -0
- package/src/DrizzleSqliteWasm.ts +263 -0
- package/src/drizzle/D1BatchStatements.ts +10 -0
- package/src/drizzle/PasswordPreparedPostconditions.ts +30 -0
- package/src/drizzle/SuppliedService.ts +10 -0
- package/src/drizzle/d1-emails.ts +1829 -0
- package/src/drizzle/d1-generated-statement.ts +129 -0
- package/src/drizzle/d1-identity.ts +375 -0
- package/src/drizzle/d1-oauth.ts +340 -0
- package/src/drizzle/d1-passkey.ts +373 -0
- package/src/drizzle/d1-password-prepared.ts +1270 -0
- package/src/drizzle/d1-passwords.ts +2656 -0
- package/src/drizzle/d1-phone.ts +96 -0
- package/src/drizzle/d1-planning.ts +104 -0
- package/src/drizzle/d1-proofs.ts +2305 -0
- package/src/drizzle/d1-sessions.ts +2857 -0
- package/src/drizzle/d1-totp.ts +78 -0
- package/src/drizzle/email-model.ts +516 -0
- package/src/drizzle/email-registration.ts +698 -0
- package/src/drizzle/email-sql.ts +24 -0
- package/src/drizzle/email-target.ts +243 -0
- package/src/drizzle/model.ts +463 -0
- package/src/drizzle/mysql-emails.ts +321 -0
- package/src/drizzle/mysql-identity.ts +324 -0
- package/src/drizzle/mysql-password-prepared.ts +204 -0
- package/src/drizzle/mysql-passwords.ts +339 -0
- package/src/drizzle/mysql-proofs.ts +181 -0
- package/src/drizzle/mysql-sessions.ts +741 -0
- package/src/drizzle/mysql.ts +687 -0
- package/src/drizzle/oauth-accounts.ts +804 -0
- package/src/drizzle/oauth-connected-access.ts +354 -0
- package/src/drizzle/oauth-connected-collection.ts +324 -0
- package/src/drizzle/oauth-connected-custody.ts +277 -0
- package/src/drizzle/oauth-connected-drivers.ts +465 -0
- package/src/drizzle/oauth-connected-flow.ts +441 -0
- package/src/drizzle/oauth-connected-input.ts +127 -0
- package/src/drizzle/oauth-connected-maintenance.ts +345 -0
- package/src/drizzle/oauth-connected-management.ts +365 -0
- package/src/drizzle/oauth-connected-model.ts +347 -0
- package/src/drizzle/oauth-connected-reference.ts +112 -0
- package/src/drizzle/oauth-connected-settlement.ts +226 -0
- package/src/drizzle/oauth-connected-state.ts +845 -0
- package/src/drizzle/oauth-connected-target.ts +264 -0
- package/src/drizzle/oauth-drivers.ts +569 -0
- package/src/drizzle/oauth-flow.ts +462 -0
- package/src/drizzle/oauth-input.ts +201 -0
- package/src/drizzle/oauth-model.ts +617 -0
- package/src/drizzle/oauth-mysql.ts +10 -0
- package/src/drizzle/oauth-owner.ts +29 -0
- package/src/drizzle/oauth-registration.ts +640 -0
- package/src/drizzle/oauth-state.ts +215 -0
- package/src/drizzle/oauth-target.ts +750 -0
- package/src/drizzle/passkey-drivers.ts +385 -0
- package/src/drizzle/passkey-kernel.ts +3 -0
- package/src/drizzle/passkey-model.ts +353 -0
- package/src/drizzle/passkey-registration-ceremony-model.ts +69 -0
- package/src/drizzle/passkey-state.ts +3 -0
- package/src/drizzle/passkey-target.ts +23 -0
- package/src/drizzle/passkey-write-drivers.ts +395 -0
- package/src/drizzle/passkey-write-model.ts +271 -0
- package/src/drizzle/passkey-write-target.ts +9 -0
- package/src/drizzle/password-model.ts +491 -0
- package/src/drizzle/password-prepared-model.ts +259 -0
- package/src/drizzle/password-prepared-sql.ts +1191 -0
- package/src/drizzle/password-prepared-state.ts +231 -0
- package/src/drizzle/password-prepared-target.ts +160 -0
- package/src/drizzle/password-registration.ts +374 -0
- package/src/drizzle/password-sql.ts +12 -0
- package/src/drizzle/password-target.ts +224 -0
- package/src/drizzle/pg-emails.ts +321 -0
- package/src/drizzle/pg-password-prepared.ts +205 -0
- package/src/drizzle/pg-passwords.ts +338 -0
- package/src/drizzle/pg-proofs.ts +191 -0
- package/src/drizzle/pg-sessions.ts +750 -0
- package/src/drizzle/pg.ts +984 -0
- package/src/drizzle/phone-model.ts +190 -0
- package/src/drizzle/phone-state.ts +21 -0
- package/src/drizzle/phone-target.ts +472 -0
- package/src/drizzle/proof-model.ts +398 -0
- package/src/drizzle/proof-sql.ts +9 -0
- package/src/drizzle/proof-target.ts +122 -0
- package/src/drizzle/query-operations.ts +37 -0
- package/src/drizzle/session-model.ts +370 -0
- package/src/drizzle/session-sql.ts +13 -0
- package/src/drizzle/session-target.ts +338 -0
- package/src/drizzle/sqlite-emails.ts +366 -0
- package/src/drizzle/sqlite-identity.ts +344 -0
- package/src/drizzle/sqlite-password-prepared.ts +260 -0
- package/src/drizzle/sqlite-passwords.ts +497 -0
- package/src/drizzle/sqlite-proofs.ts +202 -0
- package/src/drizzle/sqlite-sessions.ts +971 -0
- package/src/drizzle/sqlite.ts +705 -0
- package/src/drizzle/standalone-guard.ts +38 -0
- package/src/drizzle/step-up-model.ts +128 -0
- package/src/drizzle/step-up-state.ts +139 -0
- package/src/drizzle/totp-model.ts +92 -0
- package/src/drizzle/totp-state.ts +525 -0
- package/src/drizzle/totp-target.ts +308 -0
- package/src/drizzle/transaction-execution.ts +12 -0
- package/src/drizzle/transaction-mysql.ts +104 -0
- package/src/drizzle/transaction-owner.ts +10 -0
- package/src/index.ts +4 -0
- package/src/internal/configuration.ts +282 -0
- package/src/internal/drizzle-migrations.ts +30 -0
- package/src/internal/drizzle-postgres.ts +81 -0
- package/src/internal/drizzle-sqlite.ts +79 -0
- package/src/internal/email-kernel.ts +1532 -0
- package/src/internal/mapping-error.ts +36 -0
- package/src/internal/passkey/admission.ts +362 -0
- package/src/internal/passkey/credentials.ts +511 -0
- package/src/internal/passkey/enrollment.ts +326 -0
- package/src/internal/passkey/flow.ts +1062 -0
- package/src/internal/passkey/management.ts +422 -0
- package/src/internal/passkey/registration-ceremony.ts +283 -0
- package/src/internal/passkey/registration-custody.ts +91 -0
- package/src/internal/passkey/registration-write.ts +426 -0
- package/src/internal/passkey/state.ts +354 -0
- package/src/internal/passkey/target.ts +586 -0
- package/src/internal/passkey/write-state.ts +681 -0
- package/src/internal/passkey/write-target.ts +452 -0
- package/src/internal/passkey-kernel.ts +102 -0
- package/src/internal/passkeys.ts +597 -0
- package/src/internal/password-kernel.ts +2122 -0
- package/src/internal/persistence.ts +590 -0
- package/src/internal/phone-kernel.ts +843 -0
- package/src/internal/proof-kernel.ts +1949 -0
- package/src/internal/query-operations.ts +26 -0
- package/src/internal/registration.ts +160 -0
- package/src/internal/session-kernel.ts +2210 -0
- package/src/internal/sql-persistence.ts +45 -0
- package/src/internal/sql-query.ts +298 -0
- package/src/internal/sql-table.ts +89 -0
- package/src/internal/storage-mapping.ts +706 -0
- package/src/internal/storage-tables.ts +408 -0
- package/src/internal/storage-validation.ts +117 -0
- package/src/internal/transaction-execution-kernel.ts +317 -0
- package/src/internal/transaction-kernel.ts +582 -0
|
@@ -0,0 +1,582 @@
|
|
|
1
|
+
import { type CommitJournal, type PreparedCommit } from "@yielded/auth/Hooks";
|
|
2
|
+
import { reportAuthFailure } from "@yielded/auth/Persistence";
|
|
3
|
+
/* oxlint-disable no-explicit-any -- existing storage kernels erase foreign table shapes; domain errors remain typed. */
|
|
4
|
+
import type { SQL, Table } from "drizzle-orm";
|
|
5
|
+
import type { EffectDrizzleQueryError } from "drizzle-orm/effect-core";
|
|
6
|
+
import { Cause, Effect } from "effect";
|
|
7
|
+
import type * as SqlClient from "effect/unstable/sql/SqlClient";
|
|
8
|
+
import type { SqlError } from "effect/unstable/sql/SqlError";
|
|
9
|
+
import type { Statement } from "effect/unstable/sql/Statement";
|
|
10
|
+
|
|
11
|
+
import type { QueryOperations } from "./query-operations";
|
|
12
|
+
|
|
13
|
+
export type Row = Record<string, any>;
|
|
14
|
+
|
|
15
|
+
/** Only query-builder/table shapes are erased here. Installed Effect Drizzle
|
|
16
|
+
* queries have captured clients, and their error channel remains explicit. */
|
|
17
|
+
type NativeQuery<A> = Effect.Effect<A, EffectDrizzleQueryError | SqlError>;
|
|
18
|
+
|
|
19
|
+
export interface TransactionNativeDatabase {
|
|
20
|
+
readonly $client: SqlClient.SqlClient & {
|
|
21
|
+
readonly batch: (statements: ReadonlyArray<Statement<any>>) => Effect.Effect<any, SqlError>;
|
|
22
|
+
};
|
|
23
|
+
readonly transaction: <A, E, R>(
|
|
24
|
+
body: (transaction: any) => Effect.Effect<A, E, R>,
|
|
25
|
+
) => Effect.Effect<A, E | SqlError, R>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface Observation {
|
|
29
|
+
readonly table: Table;
|
|
30
|
+
readonly where: SQL;
|
|
31
|
+
rows: ReadonlyArray<Row>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Expressions deliberately do not replace observed values. Read only semantic
|
|
35
|
+
* columns when telemetry changes atomically, and state the physical result. */
|
|
36
|
+
export interface GuardedUpdate {
|
|
37
|
+
readonly rows: number;
|
|
38
|
+
readonly postcondition: SQL;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface TransactionOwner<Failure> {
|
|
42
|
+
readonly database: any;
|
|
43
|
+
readonly journal: CommitJournal;
|
|
44
|
+
readonly marker: string;
|
|
45
|
+
readonly batch: boolean;
|
|
46
|
+
readonly observations: Observation[];
|
|
47
|
+
readonly postconditions: Array<SQL | (() => SQL)>;
|
|
48
|
+
readonly statements: Statement<any>[];
|
|
49
|
+
readonly guards: PreparedCommit<void>[];
|
|
50
|
+
exact(table: Table, row: Row): SQL;
|
|
51
|
+
read(
|
|
52
|
+
table: Table,
|
|
53
|
+
where: SQL,
|
|
54
|
+
options?: {
|
|
55
|
+
readonly lock?: boolean;
|
|
56
|
+
readonly limit?: number;
|
|
57
|
+
readonly observe?: boolean;
|
|
58
|
+
readonly admissionOnly?: boolean;
|
|
59
|
+
readonly takeOnly?: boolean;
|
|
60
|
+
readonly orderBy?: any;
|
|
61
|
+
readonly columns?: ReadonlyArray<string>;
|
|
62
|
+
},
|
|
63
|
+
): Effect.Effect<Observation, Failure>;
|
|
64
|
+
write(query: any): Effect.Effect<void, Failure>;
|
|
65
|
+
insert(
|
|
66
|
+
table: Table,
|
|
67
|
+
values: Row,
|
|
68
|
+
key: Row,
|
|
69
|
+
absent?: boolean,
|
|
70
|
+
): Effect.Effect<Observation, Failure>;
|
|
71
|
+
update(table: Table, key: Row, values: Row): Effect.Effect<void, Failure>;
|
|
72
|
+
updateGuarded(
|
|
73
|
+
table: Table,
|
|
74
|
+
where: SQL,
|
|
75
|
+
values: Row,
|
|
76
|
+
guard: GuardedUpdate,
|
|
77
|
+
): Effect.Effect<void, Failure>;
|
|
78
|
+
/** Internal SQL only, run once after application work and before final guards. */
|
|
79
|
+
finalUpdate(
|
|
80
|
+
table: Table,
|
|
81
|
+
where: SQL,
|
|
82
|
+
values: Row,
|
|
83
|
+
guard: GuardedUpdate,
|
|
84
|
+
): Effect.Effect<void, Failure>;
|
|
85
|
+
remove(table: Table, key: Row): Effect.Effect<void, Failure>;
|
|
86
|
+
check(condition: SQL): Effect.Effect<boolean, Failure>;
|
|
87
|
+
now(clock: { readonly engineNowMillis: SQL }): Effect.Effect<number, Failure>;
|
|
88
|
+
finish(): Effect.Effect<void, Failure>;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export const makeTransactionKernel = (operations: QueryOperations) => {
|
|
92
|
+
const { eq, getTableColumns, isNull, sql, balancedD1And, compactD1GeneratedStatement } =
|
|
93
|
+
operations;
|
|
94
|
+
|
|
95
|
+
const isUnavailableCause = <Failure>(cause: Cause.Cause<unknown>, unavailable: () => Failure) => {
|
|
96
|
+
const expected = unavailable();
|
|
97
|
+
|
|
98
|
+
const tag =
|
|
99
|
+
typeof expected === "object" && expected !== null && "_tag" in expected
|
|
100
|
+
? expected._tag
|
|
101
|
+
: undefined;
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
tag !== undefined &&
|
|
105
|
+
cause.reasons.length > 0 &&
|
|
106
|
+
cause.reasons.every(
|
|
107
|
+
(reason) =>
|
|
108
|
+
Cause.isFailReason(reason) &&
|
|
109
|
+
typeof reason.error === "object" &&
|
|
110
|
+
reason.error !== null &&
|
|
111
|
+
"_tag" in reason.error &&
|
|
112
|
+
reason.error._tag === tag,
|
|
113
|
+
)
|
|
114
|
+
);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/** Report once, before an adapter replaces the raw cause with its public
|
|
118
|
+
* unavailable error. Already translated failures stay quiet at outer owners. */
|
|
119
|
+
const reportTransactionFailure = <A, E, R, Failure>(
|
|
120
|
+
effect: Effect.Effect<A, E, R>,
|
|
121
|
+
unavailable: () => Failure,
|
|
122
|
+
): Effect.Effect<A, E, R> =>
|
|
123
|
+
Effect.catchCause(effect, (cause) =>
|
|
124
|
+
isUnavailableCause(cause, unavailable)
|
|
125
|
+
? Effect.failCause(cause)
|
|
126
|
+
: reportAuthFailure("auth-persistence", cause).pipe(
|
|
127
|
+
Effect.andThen(Effect.failCause(cause)),
|
|
128
|
+
),
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
const both = (...parts: ReadonlyArray<SQL | undefined>) => balancedD1And(...parts) ?? sql`1 = 1`;
|
|
132
|
+
|
|
133
|
+
const makeTransactionRows = <Failure>(unavailable: () => Failure) => {
|
|
134
|
+
const invariant: (value: unknown) => asserts value = (value) => {
|
|
135
|
+
if (!value) throw unavailable();
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const col = (table: Table, key: string) => {
|
|
139
|
+
const value = getTableColumns(table)[key];
|
|
140
|
+
|
|
141
|
+
invariant(value !== undefined);
|
|
142
|
+
|
|
143
|
+
return value;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const equal = (table: Table, values: Row) =>
|
|
147
|
+
both(
|
|
148
|
+
...Object.entries(values).map(([key, value]) =>
|
|
149
|
+
value === null ? isNull(col(table, key)) : eq(col(table, key), value),
|
|
150
|
+
),
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
/** Mapped driver values use plain data, Dates and binary views. Application
|
|
154
|
+
* identity classes are reconstructed by the mapped codecs, never cloned here. */
|
|
155
|
+
const copiedRow = (row: Row) => {
|
|
156
|
+
const seen = new WeakSet<object>();
|
|
157
|
+
|
|
158
|
+
const supported = (value: unknown): void => {
|
|
159
|
+
if (value === null || typeof value !== "object" || seen.has(value)) return;
|
|
160
|
+
seen.add(value);
|
|
161
|
+
if (value instanceof Date || value instanceof ArrayBuffer || ArrayBuffer.isView(value))
|
|
162
|
+
return;
|
|
163
|
+
invariant(
|
|
164
|
+
Array.isArray(value) ||
|
|
165
|
+
Object.getPrototypeOf(value) === Object.prototype ||
|
|
166
|
+
Object.getPrototypeOf(value) === null,
|
|
167
|
+
);
|
|
168
|
+
for (const item of Object.values(value)) supported(item);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
supported(row);
|
|
172
|
+
|
|
173
|
+
return structuredClone(row);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const nativeKey = (value: unknown): string => {
|
|
177
|
+
const packed = (tag: string, text: string) => tag + text.length + ":" + text;
|
|
178
|
+
|
|
179
|
+
if (value instanceof Date) return packed("date", value.toISOString());
|
|
180
|
+
if (typeof value === "bigint") return packed("bigint", value.toString());
|
|
181
|
+
|
|
182
|
+
const bytes =
|
|
183
|
+
value instanceof ArrayBuffer
|
|
184
|
+
? new Uint8Array(value)
|
|
185
|
+
: ArrayBuffer.isView(value)
|
|
186
|
+
? new Uint8Array(value.buffer, value.byteOffset, value.byteLength)
|
|
187
|
+
: undefined;
|
|
188
|
+
|
|
189
|
+
if (bytes !== undefined) return packed("bytes", Array.from(bytes).join(","));
|
|
190
|
+
if (value === null || typeof value !== "object") return packed(typeof value, String(value));
|
|
191
|
+
if (Array.isArray(value)) return packed("array", value.map(nativeKey).join(""));
|
|
192
|
+
invariant(
|
|
193
|
+
Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null,
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
return packed(
|
|
197
|
+
"object",
|
|
198
|
+
Object.entries(value)
|
|
199
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
200
|
+
.map(([name, item]) => nativeKey(name) + nativeKey(item))
|
|
201
|
+
.join(""),
|
|
202
|
+
);
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const matchesNativeRow = (table: Table, row: Row, key: Row) =>
|
|
206
|
+
Object.entries(key).every(([name, value]) => {
|
|
207
|
+
if (value === null || row[name] === null) return value === row[name];
|
|
208
|
+
const column = col(table, name);
|
|
209
|
+
|
|
210
|
+
return (
|
|
211
|
+
nativeKey(column.mapToDriverValue(row[name])) ===
|
|
212
|
+
nativeKey(column.mapToDriverValue(value))
|
|
213
|
+
);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
return { col, equal, copiedRow, matchesNativeRow };
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const makeTransactionOwner = <Failure>(
|
|
220
|
+
database: any,
|
|
221
|
+
journal: CommitJournal,
|
|
222
|
+
marker: string,
|
|
223
|
+
unavailable: () => Failure,
|
|
224
|
+
configuration: {
|
|
225
|
+
readonly client?: any;
|
|
226
|
+
readonly batch: boolean;
|
|
227
|
+
readonly locking: boolean;
|
|
228
|
+
readonly mysql: boolean;
|
|
229
|
+
readonly dialect: "pg" | "mysql" | "sqlite";
|
|
230
|
+
},
|
|
231
|
+
): TransactionOwner<Failure> => {
|
|
232
|
+
const invariant: (value: unknown) => asserts value = (value) => {
|
|
233
|
+
if (!value) throw unavailable();
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
const { col, equal, matchesNativeRow } = makeTransactionRows(unavailable);
|
|
237
|
+
let phase: "open" | "finishing" | "finished" = "open";
|
|
238
|
+
let poisoned = false;
|
|
239
|
+
const open = () => invariant(phase === "open" && !poisoned);
|
|
240
|
+
|
|
241
|
+
const result = <A, E>(effect: Effect.Effect<A, E>) =>
|
|
242
|
+
effect.pipe(
|
|
243
|
+
(operation) => reportTransactionFailure(operation, unavailable),
|
|
244
|
+
Effect.mapError(unavailable),
|
|
245
|
+
Effect.catchDefect(() => Effect.fail(unavailable())),
|
|
246
|
+
Effect.onExit((exit) =>
|
|
247
|
+
Effect.sync(() => {
|
|
248
|
+
if (exit._tag === "Failure") poisoned = true;
|
|
249
|
+
}),
|
|
250
|
+
),
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
const observations: Observation[] = [];
|
|
254
|
+
const statements: Statement<any>[] = [];
|
|
255
|
+
const postconditions: Array<SQL | (() => SQL)> = [];
|
|
256
|
+
const guards: PreparedCommit<void>[] = [];
|
|
257
|
+
const finalUpdates: Array<{ readonly query: any; readonly guard: GuardedUpdate }> = [];
|
|
258
|
+
|
|
259
|
+
const exactRow = (table: Table, row: Row) =>
|
|
260
|
+
both(
|
|
261
|
+
...Object.entries(row).map(([key, value]) => {
|
|
262
|
+
if (typeof value !== "string") return equal(table, { [key]: value });
|
|
263
|
+
|
|
264
|
+
const column = col(table, key),
|
|
265
|
+
bound = sql.param(value, column);
|
|
266
|
+
|
|
267
|
+
return configuration.dialect === "mysql"
|
|
268
|
+
? sql`binary ${column} = binary ${bound}`
|
|
269
|
+
: configuration.dialect === "pg"
|
|
270
|
+
? sql`convert_to(cast(${column} as text), 'UTF8') = convert_to(cast(${bound} as text), 'UTF8')`
|
|
271
|
+
: sql`cast(${column} as blob) = cast(${bound} as blob)`;
|
|
272
|
+
}),
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
const toStatement = (query: any): Statement<any> => {
|
|
276
|
+
const rendered = query.toSQL();
|
|
277
|
+
const client = configuration.client ?? database.$client;
|
|
278
|
+
|
|
279
|
+
return compactD1GeneratedStatement(
|
|
280
|
+
client,
|
|
281
|
+
client.unsafe(rendered.sql, rendered.params),
|
|
282
|
+
unavailable,
|
|
283
|
+
);
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
const assertion = (condition: SQL) =>
|
|
287
|
+
database
|
|
288
|
+
.select({
|
|
289
|
+
value: sql`case when ${condition} then 1 else json_extract('[]', ${"$[oauth-owner-" + marker + "]"}) end`,
|
|
290
|
+
})
|
|
291
|
+
.from(sql`(select 1) as oauth_assertion`);
|
|
292
|
+
|
|
293
|
+
const observedConditions = (table: Table, where: SQL, rows: ReadonlyArray<Row>) => [
|
|
294
|
+
sql`(select count(*) from ${table} where ${where}) = ${rows.length}`,
|
|
295
|
+
...rows.map(
|
|
296
|
+
(row) => sql`exists(select 1 from ${table} where ${both(where, exactRow(table, row))})`,
|
|
297
|
+
),
|
|
298
|
+
];
|
|
299
|
+
|
|
300
|
+
// All chunks remain inside the same native owner or atomic D1 batch. A single
|
|
301
|
+
// wide row is compacted; separate observations cannot accumulate unbounded
|
|
302
|
+
// bind parameters or expression depth in one final SELECT.
|
|
303
|
+
const chunks = (conditions: ReadonlyArray<SQL>) => {
|
|
304
|
+
const output: SQL[] = [];
|
|
305
|
+
let pending: SQL[] = [];
|
|
306
|
+
|
|
307
|
+
for (const condition of conditions) {
|
|
308
|
+
const candidate = [...pending, condition];
|
|
309
|
+
const rendered = assertion(both(...candidate)).toSQL();
|
|
310
|
+
|
|
311
|
+
if (
|
|
312
|
+
pending.length > 0 &&
|
|
313
|
+
(rendered.params.length > 96 || new TextEncoder().encode(rendered.sql).length > 48_000)
|
|
314
|
+
) {
|
|
315
|
+
output.push(both(...pending));
|
|
316
|
+
pending = [condition];
|
|
317
|
+
} else pending = candidate;
|
|
318
|
+
}
|
|
319
|
+
if (pending.length > 0) output.push(both(...pending));
|
|
320
|
+
|
|
321
|
+
return output;
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
const appendAssertions = (conditions: ReadonlyArray<SQL>) => {
|
|
325
|
+
for (const condition of chunks(conditions))
|
|
326
|
+
statements.push(toStatement(assertion(condition)));
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
const observed = (table: Table, where: SQL, rows: ReadonlyArray<Row>) => {
|
|
330
|
+
const observation = { table, where, rows };
|
|
331
|
+
|
|
332
|
+
observations.push(observation);
|
|
333
|
+
|
|
334
|
+
return observation;
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
const queryCondition = (condition: SQL) =>
|
|
338
|
+
database
|
|
339
|
+
.select({
|
|
340
|
+
value: sql<number>`case when ${condition} then 1 else 0 end`.mapWith(Number).as("value"),
|
|
341
|
+
})
|
|
342
|
+
.from(sql`(select 1) as oauth_guard`);
|
|
343
|
+
|
|
344
|
+
const conditionHolds = (condition: SQL) =>
|
|
345
|
+
Effect.gen(function* () {
|
|
346
|
+
const query = queryCondition(condition);
|
|
347
|
+
|
|
348
|
+
const rows: ReadonlyArray<Row> = yield* configuration.dialect === "sqlite"
|
|
349
|
+
? toStatement(query)
|
|
350
|
+
: (query as NativeQuery<Row[]>);
|
|
351
|
+
|
|
352
|
+
invariant(rows.length === 1);
|
|
353
|
+
|
|
354
|
+
return rows[0]!.value === 1;
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
const guardedQuery = (table: Table, where: SQL, values: Row, guard: GuardedUpdate) => {
|
|
358
|
+
invariant(Number.isSafeInteger(guard.rows) && guard.rows > 0 && guard.rows <= 128);
|
|
359
|
+
|
|
360
|
+
return { query: database.update(table).set(values).where(where), guard: { ...guard } };
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
const applyGuarded = (entry: { readonly query: any; readonly guard: GuardedUpdate }) =>
|
|
364
|
+
Effect.gen(function* () {
|
|
365
|
+
if (configuration.batch) {
|
|
366
|
+
statements.push(toStatement(entry.query));
|
|
367
|
+
statements.push(toStatement(assertion(sql`changes() = ${entry.guard.rows}`)));
|
|
368
|
+
appendAssertions([entry.guard.postcondition]);
|
|
369
|
+
} else {
|
|
370
|
+
if (configuration.mysql) {
|
|
371
|
+
// mysql2 reports matched rows (FOUND_ROWS), including a telemetry no-op.
|
|
372
|
+
const changed = yield* entry.query as NativeQuery<{ readonly affectedRows: number }>;
|
|
373
|
+
|
|
374
|
+
invariant(changed.affectedRows === entry.guard.rows);
|
|
375
|
+
} else {
|
|
376
|
+
const changed = yield* entry.query.returning({ value: sql`1` }) as NativeQuery<
|
|
377
|
+
ReadonlyArray<Row>
|
|
378
|
+
>;
|
|
379
|
+
|
|
380
|
+
invariant(changed.length === entry.guard.rows);
|
|
381
|
+
}
|
|
382
|
+
invariant(yield* conditionHolds(entry.guard.postcondition));
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
const owner: TransactionOwner<Failure> = {
|
|
387
|
+
database,
|
|
388
|
+
journal,
|
|
389
|
+
marker,
|
|
390
|
+
batch: configuration.batch,
|
|
391
|
+
observations,
|
|
392
|
+
statements,
|
|
393
|
+
postconditions,
|
|
394
|
+
guards,
|
|
395
|
+
exact: exactRow,
|
|
396
|
+
read: (table, where, options = {}) =>
|
|
397
|
+
result(
|
|
398
|
+
Effect.gen(function* () {
|
|
399
|
+
open();
|
|
400
|
+
const limit = options.limit ?? 64;
|
|
401
|
+
|
|
402
|
+
let query = database
|
|
403
|
+
.select(
|
|
404
|
+
options.columns === undefined
|
|
405
|
+
? undefined
|
|
406
|
+
: Object.fromEntries(options.columns.map((key) => [key, col(table, key)])),
|
|
407
|
+
)
|
|
408
|
+
.from(table)
|
|
409
|
+
.where(where)
|
|
410
|
+
.limit(options.takeOnly ? limit : limit + 1);
|
|
411
|
+
|
|
412
|
+
if (options.orderBy !== undefined) query = query.orderBy(options.orderBy);
|
|
413
|
+
if (options.lock !== false && configuration.locking) query = query.for("update");
|
|
414
|
+
const rows: Row[] = yield* query as NativeQuery<Row[]>;
|
|
415
|
+
|
|
416
|
+
invariant(rows.length <= limit);
|
|
417
|
+
if (configuration.batch && (options.observe !== false || options.admissionOnly))
|
|
418
|
+
appendAssertions(observedConditions(table, where, rows));
|
|
419
|
+
|
|
420
|
+
return options.observe === false || options.admissionOnly
|
|
421
|
+
? { table, where, rows }
|
|
422
|
+
: observed(table, where, rows);
|
|
423
|
+
}),
|
|
424
|
+
),
|
|
425
|
+
write: (query) =>
|
|
426
|
+
result(
|
|
427
|
+
Effect.gen(function* () {
|
|
428
|
+
open();
|
|
429
|
+
if (configuration.batch) statements.push(toStatement(query));
|
|
430
|
+
else yield* query as NativeQuery<unknown>;
|
|
431
|
+
}),
|
|
432
|
+
),
|
|
433
|
+
insert: (table, values, key, absent = false) =>
|
|
434
|
+
result(
|
|
435
|
+
Effect.gen(function* () {
|
|
436
|
+
open();
|
|
437
|
+
let query = database.insert(table).values(values);
|
|
438
|
+
|
|
439
|
+
if (absent)
|
|
440
|
+
query = configuration.mysql
|
|
441
|
+
? query.onDuplicateKeyUpdate({
|
|
442
|
+
set: { [Object.keys(key)[0]!]: col(table, Object.keys(key)[0]!) },
|
|
443
|
+
})
|
|
444
|
+
: query.onConflictDoNothing();
|
|
445
|
+
yield* owner.write(query);
|
|
446
|
+
const where = equal(table, key);
|
|
447
|
+
|
|
448
|
+
if (configuration.batch) return observed(table, where, [values]);
|
|
449
|
+
const found = yield* owner.read(table, where, { limit: 1 });
|
|
450
|
+
const markerColumn = Object.keys(values).find((key) => values[key] === marker);
|
|
451
|
+
|
|
452
|
+
if (!absent || (markerColumn !== undefined && found.rows[0]?.[markerColumn] === marker))
|
|
453
|
+
invariant(
|
|
454
|
+
yield* owner.check(
|
|
455
|
+
sql`exists(select 1 from ${table} where ${both(where, exactRow(table, values))})`,
|
|
456
|
+
),
|
|
457
|
+
);
|
|
458
|
+
|
|
459
|
+
return found;
|
|
460
|
+
}),
|
|
461
|
+
),
|
|
462
|
+
update: (table, key, values) =>
|
|
463
|
+
result(
|
|
464
|
+
Effect.gen(function* () {
|
|
465
|
+
open();
|
|
466
|
+
yield* owner.write(database.update(table).set(values).where(equal(table, key)));
|
|
467
|
+
for (const observation of observations)
|
|
468
|
+
if (observation.table === table)
|
|
469
|
+
observation.rows = observation.rows.map((row) =>
|
|
470
|
+
matchesNativeRow(table, row, key) ? { ...row, ...values } : row,
|
|
471
|
+
);
|
|
472
|
+
}),
|
|
473
|
+
),
|
|
474
|
+
updateGuarded: (table, where, values, guard) =>
|
|
475
|
+
result(
|
|
476
|
+
Effect.gen(function* () {
|
|
477
|
+
open();
|
|
478
|
+
const entry = guardedQuery(table, where, values, guard);
|
|
479
|
+
|
|
480
|
+
yield* applyGuarded(entry);
|
|
481
|
+
postconditions.push(entry.guard.postcondition);
|
|
482
|
+
}),
|
|
483
|
+
),
|
|
484
|
+
finalUpdate: (table, where, values, guard) =>
|
|
485
|
+
result(
|
|
486
|
+
Effect.sync(() => {
|
|
487
|
+
open();
|
|
488
|
+
invariant(finalUpdates.length < 128);
|
|
489
|
+
finalUpdates.push(guardedQuery(table, where, values, guard));
|
|
490
|
+
}),
|
|
491
|
+
),
|
|
492
|
+
remove: (table, key) =>
|
|
493
|
+
result(
|
|
494
|
+
Effect.gen(function* () {
|
|
495
|
+
open();
|
|
496
|
+
yield* owner.write(database.delete(table).where(equal(table, key)));
|
|
497
|
+
for (const observation of observations)
|
|
498
|
+
if (observation.table === table)
|
|
499
|
+
observation.rows = observation.rows.filter(
|
|
500
|
+
(row) => !matchesNativeRow(table, row, key),
|
|
501
|
+
);
|
|
502
|
+
}),
|
|
503
|
+
),
|
|
504
|
+
check: (condition) =>
|
|
505
|
+
result(
|
|
506
|
+
Effect.gen(function* () {
|
|
507
|
+
open();
|
|
508
|
+
const holds = yield* conditionHolds(condition);
|
|
509
|
+
|
|
510
|
+
if (configuration.batch)
|
|
511
|
+
statements.push(toStatement(assertion(holds ? condition : sql`not (${condition})`)));
|
|
512
|
+
|
|
513
|
+
return holds;
|
|
514
|
+
}),
|
|
515
|
+
),
|
|
516
|
+
now: (clock) =>
|
|
517
|
+
result(
|
|
518
|
+
Effect.gen(function* () {
|
|
519
|
+
open();
|
|
520
|
+
|
|
521
|
+
const rows: Row[] = yield* database
|
|
522
|
+
.select({
|
|
523
|
+
value: sql<number>`${clock.engineNowMillis}`.mapWith(Number),
|
|
524
|
+
})
|
|
525
|
+
.from(sql`(select 1) as oauth_clock`) as NativeQuery<Row[]>;
|
|
526
|
+
|
|
527
|
+
const value = rows[0]?.value;
|
|
528
|
+
|
|
529
|
+
invariant(Number.isSafeInteger(value) && value >= 0);
|
|
530
|
+
|
|
531
|
+
return value as number;
|
|
532
|
+
}),
|
|
533
|
+
),
|
|
534
|
+
finish: () =>
|
|
535
|
+
result(
|
|
536
|
+
Effect.gen(function* () {
|
|
537
|
+
open();
|
|
538
|
+
phase = "finishing";
|
|
539
|
+
Object.freeze(observations);
|
|
540
|
+
Object.freeze(postconditions);
|
|
541
|
+
Object.freeze(guards);
|
|
542
|
+
Object.freeze(finalUpdates);
|
|
543
|
+
|
|
544
|
+
// Close registration before any late-bound SQL predicate is materialized.
|
|
545
|
+
// No callback is invoked after the first final write.
|
|
546
|
+
const conditions = observations.flatMap((observation) =>
|
|
547
|
+
observedConditions(observation.table, observation.where, observation.rows),
|
|
548
|
+
);
|
|
549
|
+
|
|
550
|
+
conditions.push(
|
|
551
|
+
...postconditions.map((condition) =>
|
|
552
|
+
typeof condition === "function" ? condition() : condition,
|
|
553
|
+
),
|
|
554
|
+
);
|
|
555
|
+
conditions.push(...finalUpdates.map((entry) => entry.guard.postcondition));
|
|
556
|
+
for (const guard of guards) {
|
|
557
|
+
const status = yield* Effect.result(guard.read);
|
|
558
|
+
|
|
559
|
+
invariant(status._tag === "Failure" && status.failure._tag === "CommitPending");
|
|
560
|
+
}
|
|
561
|
+
invariant(!poisoned);
|
|
562
|
+
for (const entry of finalUpdates) yield* applyGuarded(entry);
|
|
563
|
+
if (configuration.batch) appendAssertions(conditions);
|
|
564
|
+
else
|
|
565
|
+
for (const condition of chunks(conditions))
|
|
566
|
+
invariant(yield* conditionHolds(condition));
|
|
567
|
+
invariant(!poisoned);
|
|
568
|
+
}).pipe(
|
|
569
|
+
Effect.ensuring(
|
|
570
|
+
Effect.sync(() => {
|
|
571
|
+
phase = "finished";
|
|
572
|
+
}),
|
|
573
|
+
),
|
|
574
|
+
),
|
|
575
|
+
),
|
|
576
|
+
};
|
|
577
|
+
|
|
578
|
+
return owner;
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
return { reportTransactionFailure, both, makeTransactionRows, makeTransactionOwner };
|
|
582
|
+
};
|