@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,387 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
//#region src/internal/storage-tables.ts
|
|
3
|
+
const StorageColumn = Schema.Struct({
|
|
4
|
+
name: Schema.NonEmptyString,
|
|
5
|
+
type: Schema.Literals([
|
|
6
|
+
"text",
|
|
7
|
+
"integer",
|
|
8
|
+
"boolean"
|
|
9
|
+
]),
|
|
10
|
+
nullable: Schema.optionalKey(Schema.Boolean)
|
|
11
|
+
});
|
|
12
|
+
const StorageTable = Schema.Struct({
|
|
13
|
+
name: Schema.NonEmptyString,
|
|
14
|
+
schema: Schema.optionalKey(Schema.NonEmptyString),
|
|
15
|
+
columns: Schema.Record(Schema.String, StorageColumn),
|
|
16
|
+
unique: Schema.Array(Schema.Array(Schema.String))
|
|
17
|
+
});
|
|
18
|
+
const text = { type: "text" };
|
|
19
|
+
const integer = { type: "integer" };
|
|
20
|
+
const boolean = { type: "boolean" };
|
|
21
|
+
const optionalText = {
|
|
22
|
+
...text,
|
|
23
|
+
nullable: true
|
|
24
|
+
};
|
|
25
|
+
const optionalInteger = {
|
|
26
|
+
...integer,
|
|
27
|
+
nullable: true
|
|
28
|
+
};
|
|
29
|
+
const spec = (columns, unique) => ({
|
|
30
|
+
columns,
|
|
31
|
+
unique
|
|
32
|
+
});
|
|
33
|
+
/** Logical roles are independent of table names and migration ownership. */
|
|
34
|
+
const storageTables = {
|
|
35
|
+
subjects: spec({
|
|
36
|
+
id: text,
|
|
37
|
+
active: boolean,
|
|
38
|
+
securityRevision: text
|
|
39
|
+
}, [["id"]]),
|
|
40
|
+
identifiers: spec({
|
|
41
|
+
namespace: text,
|
|
42
|
+
value: text,
|
|
43
|
+
subjectId: text,
|
|
44
|
+
revision: text,
|
|
45
|
+
verifiedAt: optionalInteger,
|
|
46
|
+
active: boolean
|
|
47
|
+
}, [["namespace", "value"]]),
|
|
48
|
+
credentials: spec({
|
|
49
|
+
credentialId: text,
|
|
50
|
+
subjectId: text,
|
|
51
|
+
revision: text,
|
|
52
|
+
active: boolean
|
|
53
|
+
}, [["credentialId"]]),
|
|
54
|
+
passwords: spec({
|
|
55
|
+
moduleId: text,
|
|
56
|
+
subjectId: text,
|
|
57
|
+
credentialId: text,
|
|
58
|
+
credentialRevision: text,
|
|
59
|
+
verifierVersion: text,
|
|
60
|
+
verifier: text,
|
|
61
|
+
normalization: text
|
|
62
|
+
}, [["moduleId", "subjectId"], ["moduleId", "credentialId"]]),
|
|
63
|
+
passwordAttempts: spec({
|
|
64
|
+
moduleId: text,
|
|
65
|
+
action: text,
|
|
66
|
+
attemptId: text,
|
|
67
|
+
identifierNamespace: text,
|
|
68
|
+
identifierValue: text,
|
|
69
|
+
subjectId: optionalText,
|
|
70
|
+
credentialId: optionalText,
|
|
71
|
+
securityRevision: optionalText,
|
|
72
|
+
credentialRevision: optionalText,
|
|
73
|
+
verifierVersion: optionalText,
|
|
74
|
+
identifierBindingRevision: optionalText,
|
|
75
|
+
admittedAt: integer,
|
|
76
|
+
deadline: integer,
|
|
77
|
+
retentionUntil: integer,
|
|
78
|
+
state: text
|
|
79
|
+
}, [["moduleId", "attemptId"]]),
|
|
80
|
+
passwordScopes: spec({
|
|
81
|
+
moduleId: text,
|
|
82
|
+
action: text,
|
|
83
|
+
scopeKind: text,
|
|
84
|
+
scopeKey: text
|
|
85
|
+
}, [[
|
|
86
|
+
"moduleId",
|
|
87
|
+
"action",
|
|
88
|
+
"scopeKind",
|
|
89
|
+
"scopeKey"
|
|
90
|
+
]]),
|
|
91
|
+
passwordCharges: spec({
|
|
92
|
+
moduleId: text,
|
|
93
|
+
action: text,
|
|
94
|
+
scopeKind: text,
|
|
95
|
+
scopeKey: text,
|
|
96
|
+
attemptId: text,
|
|
97
|
+
occurredAt: integer,
|
|
98
|
+
retentionUntil: integer
|
|
99
|
+
}, [[
|
|
100
|
+
"moduleId",
|
|
101
|
+
"action",
|
|
102
|
+
"scopeKind",
|
|
103
|
+
"scopeKey",
|
|
104
|
+
"attemptId"
|
|
105
|
+
]]),
|
|
106
|
+
passwordCommands: spec({
|
|
107
|
+
moduleId: text,
|
|
108
|
+
commandId: text,
|
|
109
|
+
action: text,
|
|
110
|
+
bindingDigest: text,
|
|
111
|
+
decision: text,
|
|
112
|
+
retentionUntil: integer
|
|
113
|
+
}, [["moduleId", "commandId"]]),
|
|
114
|
+
passwordRegistrations: spec({
|
|
115
|
+
moduleId: text,
|
|
116
|
+
requestId: text
|
|
117
|
+
}, [["moduleId", "requestId"]]),
|
|
118
|
+
emailCredentials: spec({
|
|
119
|
+
moduleId: text,
|
|
120
|
+
subjectId: text,
|
|
121
|
+
credentialId: text,
|
|
122
|
+
identifierNamespace: text,
|
|
123
|
+
identifierValue: text,
|
|
124
|
+
credentialRevision: text,
|
|
125
|
+
active: boolean
|
|
126
|
+
}, [["moduleId", "credentialId"], [
|
|
127
|
+
"moduleId",
|
|
128
|
+
"identifierNamespace",
|
|
129
|
+
"identifierValue"
|
|
130
|
+
]]),
|
|
131
|
+
emailCommands: spec({
|
|
132
|
+
moduleId: text,
|
|
133
|
+
commandId: text,
|
|
134
|
+
action: text,
|
|
135
|
+
bindingDigest: text,
|
|
136
|
+
retentionUntil: integer
|
|
137
|
+
}, [["moduleId", "commandId"]]),
|
|
138
|
+
phoneState: spec({
|
|
139
|
+
scope: text,
|
|
140
|
+
state: text,
|
|
141
|
+
version: text
|
|
142
|
+
}, [["scope"]]),
|
|
143
|
+
passkeyCredentials: spec({
|
|
144
|
+
credentialId: text,
|
|
145
|
+
subjectId: text,
|
|
146
|
+
rpId: text,
|
|
147
|
+
protocolCredentialId: text,
|
|
148
|
+
credentialKey: text,
|
|
149
|
+
handleKey: text,
|
|
150
|
+
userHandle: text,
|
|
151
|
+
publicKey: text,
|
|
152
|
+
algorithm: integer,
|
|
153
|
+
profile: text,
|
|
154
|
+
credentialRevision: text,
|
|
155
|
+
active: boolean,
|
|
156
|
+
primarySignIn: boolean,
|
|
157
|
+
enrollmentUserVerified: boolean,
|
|
158
|
+
backupEligible: boolean,
|
|
159
|
+
backupState: boolean,
|
|
160
|
+
counter: integer,
|
|
161
|
+
maximumCounter: integer,
|
|
162
|
+
name: text,
|
|
163
|
+
createdAt: integer,
|
|
164
|
+
lastUsedAt: optionalInteger
|
|
165
|
+
}, [["credentialId"], ["credentialKey"]]),
|
|
166
|
+
passkeyOwnership: spec({
|
|
167
|
+
credentialKey: text,
|
|
168
|
+
rpId: text,
|
|
169
|
+
protocolCredentialId: text,
|
|
170
|
+
subjectId: optionalText,
|
|
171
|
+
credentialId: optionalText,
|
|
172
|
+
state: text,
|
|
173
|
+
version: text,
|
|
174
|
+
reservationId: optionalText
|
|
175
|
+
}, [["credentialKey"]]),
|
|
176
|
+
passkeyHandles: spec({
|
|
177
|
+
handleKey: text,
|
|
178
|
+
rpId: text,
|
|
179
|
+
userHandle: text,
|
|
180
|
+
subjectId: optionalText,
|
|
181
|
+
state: text,
|
|
182
|
+
version: text,
|
|
183
|
+
reservationId: optionalText
|
|
184
|
+
}, [["handleKey"], ["rpId", "subjectId"]]),
|
|
185
|
+
passkeyModules: spec({
|
|
186
|
+
moduleId: text,
|
|
187
|
+
active: boolean,
|
|
188
|
+
policyRevision: text,
|
|
189
|
+
policy: text
|
|
190
|
+
}, [["moduleId"]]),
|
|
191
|
+
passkeyFlows: spec({
|
|
192
|
+
moduleId: text,
|
|
193
|
+
flowId: text,
|
|
194
|
+
commandId: text,
|
|
195
|
+
purpose: text,
|
|
196
|
+
state: text,
|
|
197
|
+
version: text,
|
|
198
|
+
generation: integer,
|
|
199
|
+
snapshot: text,
|
|
200
|
+
policySnapshot: text,
|
|
201
|
+
requestBindingVerifier: text,
|
|
202
|
+
requestBindingExpiresAt: integer,
|
|
203
|
+
issuedAt: integer,
|
|
204
|
+
expiresAt: integer,
|
|
205
|
+
retentionUntil: integer,
|
|
206
|
+
claimId: optionalText,
|
|
207
|
+
claimedAt: optionalInteger,
|
|
208
|
+
claimExpiresAt: optionalInteger,
|
|
209
|
+
credentialSnapshot: optionalText,
|
|
210
|
+
subjectScope: optionalText,
|
|
211
|
+
targetScope: optionalText
|
|
212
|
+
}, [["moduleId", "flowId"], ["moduleId", "commandId"]]),
|
|
213
|
+
passkeyAdmissions: spec({
|
|
214
|
+
authorityScope: text,
|
|
215
|
+
moduleId: text,
|
|
216
|
+
version: text,
|
|
217
|
+
ownerMarker: text,
|
|
218
|
+
admittedAt: optionalInteger
|
|
219
|
+
}, [["authorityScope", "moduleId"]]),
|
|
220
|
+
passkeyCharges: spec({
|
|
221
|
+
moduleId: text,
|
|
222
|
+
flowId: text,
|
|
223
|
+
purpose: text,
|
|
224
|
+
kind: text,
|
|
225
|
+
scope: text,
|
|
226
|
+
originalWindowMillis: integer,
|
|
227
|
+
admittedAt: optionalInteger,
|
|
228
|
+
retainUntil: optionalInteger,
|
|
229
|
+
version: text,
|
|
230
|
+
ownerMarker: text
|
|
231
|
+
}, [[
|
|
232
|
+
"moduleId",
|
|
233
|
+
"flowId",
|
|
234
|
+
"kind"
|
|
235
|
+
]]),
|
|
236
|
+
passkeyCommands: spec({
|
|
237
|
+
moduleId: text,
|
|
238
|
+
commandId: text,
|
|
239
|
+
subjectId: text,
|
|
240
|
+
credentialId: text,
|
|
241
|
+
intent: text,
|
|
242
|
+
decision: text,
|
|
243
|
+
retentionUntil: integer,
|
|
244
|
+
version: text
|
|
245
|
+
}, [["moduleId", "commandId"]]),
|
|
246
|
+
proofRequests: spec({
|
|
247
|
+
moduleId: text,
|
|
248
|
+
requestId: text,
|
|
249
|
+
fingerprint: text,
|
|
250
|
+
proofId: text,
|
|
251
|
+
purpose: text,
|
|
252
|
+
keyId: text,
|
|
253
|
+
createdAt: integer,
|
|
254
|
+
retentionUntil: integer,
|
|
255
|
+
receipt: text
|
|
256
|
+
}, [["moduleId", "requestId"]]),
|
|
257
|
+
proofSeries: spec({
|
|
258
|
+
moduleId: text,
|
|
259
|
+
purpose: text,
|
|
260
|
+
scopeKey: text,
|
|
261
|
+
activeProofId: optionalText,
|
|
262
|
+
lastIssueAt: optionalInteger,
|
|
263
|
+
version: text
|
|
264
|
+
}, [[
|
|
265
|
+
"moduleId",
|
|
266
|
+
"purpose",
|
|
267
|
+
"scopeKey"
|
|
268
|
+
]]),
|
|
269
|
+
proofGenerations: spec({
|
|
270
|
+
moduleId: text,
|
|
271
|
+
purpose: text,
|
|
272
|
+
proofId: text,
|
|
273
|
+
requestId: text,
|
|
274
|
+
seriesKey: text,
|
|
275
|
+
deliveryId: text,
|
|
276
|
+
binding: text,
|
|
277
|
+
verifierKeyId: text,
|
|
278
|
+
verifierDigest: text,
|
|
279
|
+
issuedAt: integer,
|
|
280
|
+
expiresAt: integer,
|
|
281
|
+
version: text,
|
|
282
|
+
state: text,
|
|
283
|
+
sendCount: integer,
|
|
284
|
+
deliveryState: text,
|
|
285
|
+
claimVersion: optionalText,
|
|
286
|
+
claimDeadline: optionalInteger,
|
|
287
|
+
retryAt: optionalInteger,
|
|
288
|
+
deliveryRetryMillis: integer,
|
|
289
|
+
retentionUntil: integer,
|
|
290
|
+
fingerprint: text
|
|
291
|
+
}, [["moduleId", "proofId"], ["moduleId", "deliveryId"]]),
|
|
292
|
+
proofContinuations: spec({
|
|
293
|
+
moduleId: text,
|
|
294
|
+
purpose: text,
|
|
295
|
+
continuationId: text,
|
|
296
|
+
digest: text,
|
|
297
|
+
proofId: text,
|
|
298
|
+
seriesKey: text,
|
|
299
|
+
binding: text,
|
|
300
|
+
expiresAt: integer,
|
|
301
|
+
consumed: boolean,
|
|
302
|
+
version: text,
|
|
303
|
+
retentionUntil: integer
|
|
304
|
+
}, [["moduleId", "continuationId"], ["moduleId", "digest"]]),
|
|
305
|
+
proofScopes: spec({
|
|
306
|
+
moduleId: text,
|
|
307
|
+
purpose: text,
|
|
308
|
+
action: text,
|
|
309
|
+
scopeKind: text,
|
|
310
|
+
scopeKey: text
|
|
311
|
+
}, [[
|
|
312
|
+
"moduleId",
|
|
313
|
+
"purpose",
|
|
314
|
+
"action",
|
|
315
|
+
"scopeKind",
|
|
316
|
+
"scopeKey"
|
|
317
|
+
]]),
|
|
318
|
+
proofAbuse: spec({
|
|
319
|
+
moduleId: text,
|
|
320
|
+
purpose: text,
|
|
321
|
+
action: text,
|
|
322
|
+
scopeKind: text,
|
|
323
|
+
scopeKey: text,
|
|
324
|
+
commandId: text,
|
|
325
|
+
occurredAt: integer,
|
|
326
|
+
retentionUntil: integer
|
|
327
|
+
}, [[
|
|
328
|
+
"moduleId",
|
|
329
|
+
"action",
|
|
330
|
+
"scopeKind",
|
|
331
|
+
"scopeKey",
|
|
332
|
+
"commandId"
|
|
333
|
+
]]),
|
|
334
|
+
proofFailures: spec({
|
|
335
|
+
moduleId: text,
|
|
336
|
+
purpose: text,
|
|
337
|
+
seriesKey: text,
|
|
338
|
+
commandId: text,
|
|
339
|
+
occurredAt: integer,
|
|
340
|
+
retentionUntil: integer
|
|
341
|
+
}, [[
|
|
342
|
+
"moduleId",
|
|
343
|
+
"seriesKey",
|
|
344
|
+
"commandId"
|
|
345
|
+
]]),
|
|
346
|
+
proofCommands: spec({
|
|
347
|
+
moduleId: text,
|
|
348
|
+
commandId: text,
|
|
349
|
+
kind: text,
|
|
350
|
+
decision: text,
|
|
351
|
+
retentionUntil: integer
|
|
352
|
+
}, [["moduleId", "commandId"]]),
|
|
353
|
+
sessions: spec({
|
|
354
|
+
sessionId: text,
|
|
355
|
+
subjectId: text,
|
|
356
|
+
digest: text,
|
|
357
|
+
version: text,
|
|
358
|
+
securityRevision: text,
|
|
359
|
+
issuedAt: integer,
|
|
360
|
+
expiresAt: integer,
|
|
361
|
+
absoluteExpiresAt: integer,
|
|
362
|
+
record: text
|
|
363
|
+
}, [["sessionId"], ["digest"]]),
|
|
364
|
+
sessionFlows: spec({
|
|
365
|
+
flowId: text,
|
|
366
|
+
subjectId: text,
|
|
367
|
+
state: text,
|
|
368
|
+
pendingDigest: optionalText,
|
|
369
|
+
dedupUntil: integer
|
|
370
|
+
}, [["flowId"]])
|
|
371
|
+
};
|
|
372
|
+
const tableDefinition = (role, name, subjectType = "text") => {
|
|
373
|
+
const table = storageTables[role];
|
|
374
|
+
return {
|
|
375
|
+
name,
|
|
376
|
+
columns: Object.fromEntries(Object.entries(table.columns).map(([key, column]) => [key, {
|
|
377
|
+
...column,
|
|
378
|
+
name: key.replace(/[A-Z]/g, (letter) => "_" + letter.toLowerCase()),
|
|
379
|
+
...key === "subjectId" ? { type: subjectType } : {}
|
|
380
|
+
}])),
|
|
381
|
+
unique: table.unique
|
|
382
|
+
};
|
|
383
|
+
};
|
|
384
|
+
//#endregion
|
|
385
|
+
export { StorageColumn, StorageTable, storageTables, tableDefinition };
|
|
386
|
+
|
|
387
|
+
//# sourceMappingURL=storage-tables.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-tables.mjs","names":[],"sources":["../../src/internal/storage-tables.ts"],"sourcesContent":["import { Schema } from \"effect\";\n\nexport const StorageColumn = Schema.Struct({\n name: Schema.NonEmptyString,\n type: Schema.Literals([\"text\", \"integer\", \"boolean\"]),\n nullable: Schema.optionalKey(Schema.Boolean),\n});\n\nexport const StorageTable = Schema.Struct({\n name: Schema.NonEmptyString,\n schema: Schema.optionalKey(Schema.NonEmptyString),\n columns: Schema.Record(Schema.String, StorageColumn),\n unique: Schema.Array(Schema.Array(Schema.String)),\n});\n\nexport type StorageTable = typeof StorageTable.Type;\n\nconst text = { type: \"text\" as const };\nconst integer = { type: \"integer\" as const };\nconst boolean = { type: \"boolean\" as const };\nconst optionalText = { ...text, nullable: true };\nconst optionalInteger = { ...integer, nullable: true };\n\nconst spec = <C extends Readonly<Record<string, Omit<typeof StorageColumn.Type, \"name\">>>>(\n columns: C,\n unique: ReadonlyArray<ReadonlyArray<Extract<keyof C, string>>>,\n) => ({ columns, unique });\n\n/** Logical roles are independent of table names and migration ownership. */\nexport const storageTables = {\n subjects: spec({ id: text, active: boolean, securityRevision: text }, [[\"id\"]]),\n identifiers: spec(\n {\n namespace: text,\n value: text,\n subjectId: text,\n revision: text,\n verifiedAt: optionalInteger,\n active: boolean,\n },\n [[\"namespace\", \"value\"]],\n ),\n credentials: spec({ credentialId: text, subjectId: text, revision: text, active: boolean }, [\n [\"credentialId\"],\n ]),\n passwords: spec(\n {\n moduleId: text,\n subjectId: text,\n credentialId: text,\n credentialRevision: text,\n verifierVersion: text,\n verifier: text,\n normalization: text,\n },\n [\n [\"moduleId\", \"subjectId\"],\n [\"moduleId\", \"credentialId\"],\n ],\n ),\n passwordAttempts: spec(\n {\n moduleId: text,\n action: text,\n attemptId: text,\n identifierNamespace: text,\n identifierValue: text,\n subjectId: optionalText,\n credentialId: optionalText,\n securityRevision: optionalText,\n credentialRevision: optionalText,\n verifierVersion: optionalText,\n identifierBindingRevision: optionalText,\n admittedAt: integer,\n deadline: integer,\n retentionUntil: integer,\n state: text,\n },\n [[\"moduleId\", \"attemptId\"]],\n ),\n passwordScopes: spec({ moduleId: text, action: text, scopeKind: text, scopeKey: text }, [\n [\"moduleId\", \"action\", \"scopeKind\", \"scopeKey\"],\n ]),\n passwordCharges: spec(\n {\n moduleId: text,\n action: text,\n scopeKind: text,\n scopeKey: text,\n attemptId: text,\n occurredAt: integer,\n retentionUntil: integer,\n },\n [[\"moduleId\", \"action\", \"scopeKind\", \"scopeKey\", \"attemptId\"]],\n ),\n passwordCommands: spec(\n {\n moduleId: text,\n commandId: text,\n action: text,\n bindingDigest: text,\n decision: text,\n retentionUntil: integer,\n },\n [[\"moduleId\", \"commandId\"]],\n ),\n passwordRegistrations: spec({ moduleId: text, requestId: text }, [[\"moduleId\", \"requestId\"]]),\n emailCredentials: spec(\n {\n moduleId: text,\n subjectId: text,\n credentialId: text,\n identifierNamespace: text,\n identifierValue: text,\n credentialRevision: text,\n active: boolean,\n },\n [\n [\"moduleId\", \"credentialId\"],\n [\"moduleId\", \"identifierNamespace\", \"identifierValue\"],\n ],\n ),\n emailCommands: spec(\n { moduleId: text, commandId: text, action: text, bindingDigest: text, retentionUntil: integer },\n [[\"moduleId\", \"commandId\"]],\n ),\n phoneState: spec({ scope: text, state: text, version: text }, [[\"scope\"]]),\n passkeyCredentials: spec(\n {\n credentialId: text,\n subjectId: text,\n rpId: text,\n protocolCredentialId: text,\n credentialKey: text,\n handleKey: text,\n userHandle: text,\n publicKey: text,\n algorithm: integer,\n profile: text,\n credentialRevision: text,\n active: boolean,\n primarySignIn: boolean,\n enrollmentUserVerified: boolean,\n backupEligible: boolean,\n backupState: boolean,\n counter: integer,\n maximumCounter: integer,\n name: text,\n createdAt: integer,\n lastUsedAt: optionalInteger,\n },\n [[\"credentialId\"], [\"credentialKey\"]],\n ),\n passkeyOwnership: spec(\n {\n credentialKey: text,\n rpId: text,\n protocolCredentialId: text,\n subjectId: optionalText,\n credentialId: optionalText,\n state: text,\n version: text,\n reservationId: optionalText,\n },\n [[\"credentialKey\"]],\n ),\n passkeyHandles: spec(\n {\n handleKey: text,\n rpId: text,\n userHandle: text,\n subjectId: optionalText,\n state: text,\n version: text,\n reservationId: optionalText,\n },\n [[\"handleKey\"], [\"rpId\", \"subjectId\"]],\n ),\n passkeyModules: spec(\n {\n moduleId: text,\n active: boolean,\n policyRevision: text,\n policy: text,\n },\n [[\"moduleId\"]],\n ),\n passkeyFlows: spec(\n {\n moduleId: text,\n flowId: text,\n commandId: text,\n purpose: text,\n state: text,\n version: text,\n generation: integer,\n snapshot: text,\n policySnapshot: text,\n requestBindingVerifier: text,\n requestBindingExpiresAt: integer,\n issuedAt: integer,\n expiresAt: integer,\n retentionUntil: integer,\n claimId: optionalText,\n claimedAt: optionalInteger,\n claimExpiresAt: optionalInteger,\n credentialSnapshot: optionalText,\n subjectScope: optionalText,\n targetScope: optionalText,\n },\n [\n [\"moduleId\", \"flowId\"],\n [\"moduleId\", \"commandId\"],\n ],\n ),\n passkeyAdmissions: spec(\n {\n authorityScope: text,\n moduleId: text,\n version: text,\n ownerMarker: text,\n admittedAt: optionalInteger,\n },\n [[\"authorityScope\", \"moduleId\"]],\n ),\n passkeyCharges: spec(\n {\n moduleId: text,\n flowId: text,\n purpose: text,\n kind: text,\n scope: text,\n originalWindowMillis: integer,\n admittedAt: optionalInteger,\n retainUntil: optionalInteger,\n version: text,\n ownerMarker: text,\n },\n [[\"moduleId\", \"flowId\", \"kind\"]],\n ),\n passkeyCommands: spec(\n {\n moduleId: text,\n commandId: text,\n subjectId: text,\n credentialId: text,\n intent: text,\n decision: text,\n retentionUntil: integer,\n version: text,\n },\n [[\"moduleId\", \"commandId\"]],\n ),\n proofRequests: spec(\n {\n moduleId: text,\n requestId: text,\n fingerprint: text,\n proofId: text,\n purpose: text,\n keyId: text,\n createdAt: integer,\n retentionUntil: integer,\n receipt: text,\n },\n [[\"moduleId\", \"requestId\"]],\n ),\n proofSeries: spec(\n {\n moduleId: text,\n purpose: text,\n scopeKey: text,\n activeProofId: optionalText,\n lastIssueAt: optionalInteger,\n version: text,\n },\n [[\"moduleId\", \"purpose\", \"scopeKey\"]],\n ),\n proofGenerations: spec(\n {\n moduleId: text,\n purpose: text,\n proofId: text,\n requestId: text,\n seriesKey: text,\n deliveryId: text,\n binding: text,\n verifierKeyId: text,\n verifierDigest: text,\n issuedAt: integer,\n expiresAt: integer,\n version: text,\n state: text,\n sendCount: integer,\n deliveryState: text,\n claimVersion: optionalText,\n claimDeadline: optionalInteger,\n retryAt: optionalInteger,\n deliveryRetryMillis: integer,\n retentionUntil: integer,\n fingerprint: text,\n },\n [\n [\"moduleId\", \"proofId\"],\n [\"moduleId\", \"deliveryId\"],\n ],\n ),\n proofContinuations: spec(\n {\n moduleId: text,\n purpose: text,\n continuationId: text,\n digest: text,\n proofId: text,\n seriesKey: text,\n binding: text,\n expiresAt: integer,\n consumed: boolean,\n version: text,\n retentionUntil: integer,\n },\n [\n [\"moduleId\", \"continuationId\"],\n [\"moduleId\", \"digest\"],\n ],\n ),\n proofScopes: spec(\n { moduleId: text, purpose: text, action: text, scopeKind: text, scopeKey: text },\n [[\"moduleId\", \"purpose\", \"action\", \"scopeKind\", \"scopeKey\"]],\n ),\n proofAbuse: spec(\n {\n moduleId: text,\n purpose: text,\n action: text,\n scopeKind: text,\n scopeKey: text,\n commandId: text,\n occurredAt: integer,\n retentionUntil: integer,\n },\n [[\"moduleId\", \"action\", \"scopeKind\", \"scopeKey\", \"commandId\"]],\n ),\n proofFailures: spec(\n {\n moduleId: text,\n purpose: text,\n seriesKey: text,\n commandId: text,\n occurredAt: integer,\n retentionUntil: integer,\n },\n [[\"moduleId\", \"seriesKey\", \"commandId\"]],\n ),\n proofCommands: spec(\n { moduleId: text, commandId: text, kind: text, decision: text, retentionUntil: integer },\n [[\"moduleId\", \"commandId\"]],\n ),\n sessions: spec(\n {\n sessionId: text,\n subjectId: text,\n digest: text,\n version: text,\n securityRevision: text,\n issuedAt: integer,\n expiresAt: integer,\n absoluteExpiresAt: integer,\n record: text,\n },\n [[\"sessionId\"], [\"digest\"]],\n ),\n sessionFlows: spec(\n {\n flowId: text,\n subjectId: text,\n state: text,\n pendingDigest: optionalText,\n dedupUntil: integer,\n },\n [[\"flowId\"]],\n ),\n} as const;\n\nexport type StorageRole = keyof typeof storageTables;\n\nexport const tableDefinition = (\n role: StorageRole,\n name: string,\n subjectType: \"text\" | \"integer\" = \"text\",\n): StorageTable => {\n const table = storageTables[role];\n\n return {\n name,\n columns: Object.fromEntries(\n Object.entries(table.columns).map(([key, column]) => [\n key,\n {\n ...column,\n name: key.replace(/[A-Z]/g, (letter) => \"_\" + letter.toLowerCase()),\n ...(key === \"subjectId\" ? { type: subjectType } : {}),\n },\n ]),\n ),\n unique: table.unique,\n };\n};\n"],"mappings":";;AAEA,MAAa,gBAAgB,OAAO,OAAO;CACzC,MAAM,OAAO;CACb,MAAM,OAAO,SAAS;EAAC;EAAQ;EAAW;CAAS,CAAC;CACpD,UAAU,OAAO,YAAY,OAAO,OAAO;AAC7C,CAAC;AAED,MAAa,eAAe,OAAO,OAAO;CACxC,MAAM,OAAO;CACb,QAAQ,OAAO,YAAY,OAAO,cAAc;CAChD,SAAS,OAAO,OAAO,OAAO,QAAQ,aAAa;CACnD,QAAQ,OAAO,MAAM,OAAO,MAAM,OAAO,MAAM,CAAC;AAClD,CAAC;AAID,MAAM,OAAO,EAAE,MAAM,OAAgB;AACrC,MAAM,UAAU,EAAE,MAAM,UAAmB;AAC3C,MAAM,UAAU,EAAE,MAAM,UAAmB;AAC3C,MAAM,eAAe;CAAE,GAAG;CAAM,UAAU;AAAK;AAC/C,MAAM,kBAAkB;CAAE,GAAG;CAAS,UAAU;AAAK;AAErD,MAAM,QACJ,S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ACR,WAAW;EACX,OAAO;EACP,eAAe;EACf,YAAY;CACd,GACA,CAAC,CAAC,QAAQ,CAAC,CACb;AACF;AAIA,MAAa,mBACX,MACA,MACA,cAAkC,WACjB;CACjB,MAAM,QAAQ,cAAc;CAE5B,OAAO;EACL;EACA,SAAS,OAAO,YACd,OAAO,QAAQ,MAAM,OAAO,CAAC,CAAC,KAAK,CAAC,KAAK,YAAY,CACnD,KACA;GACE,GAAG;GACH,MAAM,IAAI,QAAQ,WAAW,WAAW,MAAM,OAAO,YAAY,CAAC;GAClE,GAAI,QAAQ,cAAc,EAAE,MAAM,YAAY,IAAI,CAAC;EACrD,CACF,CAAC,CACH;EACA,QAAQ,MAAM;CAChB;AACF"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { PersistenceConfigurationError } from "./configuration.mjs";
|
|
2
|
+
import { Effect, Schema } from "effect";
|
|
3
|
+
//#region src/internal/storage-validation.ts
|
|
4
|
+
const Column = Schema.Struct({
|
|
5
|
+
name: Schema.String,
|
|
6
|
+
pk: Schema.Int
|
|
7
|
+
});
|
|
8
|
+
const Index = Schema.Struct({
|
|
9
|
+
name: Schema.String,
|
|
10
|
+
unique: Schema.Int,
|
|
11
|
+
partial: Schema.Int
|
|
12
|
+
});
|
|
13
|
+
const IndexColumn = Schema.Struct({ name: Schema.NullOr(Schema.String) });
|
|
14
|
+
const PgColumns = Schema.Array(Schema.Struct({ name: Schema.String }));
|
|
15
|
+
const PgKeys = Schema.Array(Schema.Struct({ columns: Schema.Array(Schema.String) }));
|
|
16
|
+
const quote = (value) => "\"" + value.replaceAll("\"", "\"\"") + "\"";
|
|
17
|
+
const qualifiedTableName = (table) => (table.schema === void 0 ? "" : quote(table.schema) + ".") + quote(table.name);
|
|
18
|
+
/** Validate physical uniqueness before the first authentication operation. A
|
|
19
|
+
* partial or expression index cannot establish these unconditional guarantees. */
|
|
20
|
+
const validateStorage = (client, dialect, table, required) => Effect.gen(function* () {
|
|
21
|
+
const physicalKeys = yield* dialect === "sqlite" ? Effect.gen(function* () {
|
|
22
|
+
if (table.schema !== void 0 && table.schema !== "main") return yield* PersistenceConfigurationError.make({ reason: "SQLite storage must belong to the main database" });
|
|
23
|
+
const columns = yield* client`select name, pk from pragma_table_info(${table.name})`.pipe(Effect.flatMap(Schema.decodeUnknownEffect(Schema.Array(Column))));
|
|
24
|
+
for (const column of Object.values(table.columns)) if (!columns.some((actual) => actual.name === column.name)) return yield* PersistenceConfigurationError.make({ reason: `Missing SQL column ${table.name}.${column.name}` });
|
|
25
|
+
const keys = [];
|
|
26
|
+
const primary = columns.filter((column) => column.pk > 0).sort((a, b) => a.pk - b.pk);
|
|
27
|
+
if (primary.length > 0) keys.push(primary.map((column) => column.name));
|
|
28
|
+
const indexes = yield* client`select name, "unique", partial from pragma_index_list(${table.name})`.pipe(Effect.flatMap(Schema.decodeUnknownEffect(Schema.Array(Index))));
|
|
29
|
+
for (const index of indexes) {
|
|
30
|
+
if (index.unique !== 1 || index.partial !== 0) continue;
|
|
31
|
+
const columns = yield* client`select name from pragma_index_info(${index.name})`.pipe(Effect.flatMap(Schema.decodeUnknownEffect(Schema.Array(IndexColumn))));
|
|
32
|
+
if (columns.every((column) => column.name !== null)) keys.push(columns.flatMap((column) => column.name === null ? [] : [column.name]));
|
|
33
|
+
}
|
|
34
|
+
return keys;
|
|
35
|
+
}) : Effect.gen(function* () {
|
|
36
|
+
const relation = qualifiedTableName(table);
|
|
37
|
+
const columns = yield* client`select attname as name from pg_attribute where attrelid = to_regclass(${relation}) and attnum > 0 and not attisdropped`.pipe(Effect.flatMap(Schema.decodeUnknownEffect(PgColumns)));
|
|
38
|
+
for (const column of Object.values(table.columns)) if (!columns.some((actual) => actual.name === column.name)) return yield* PersistenceConfigurationError.make({ reason: `Missing SQL column ${relation}.${column.name}` });
|
|
39
|
+
return (yield* client`
|
|
40
|
+
select array_agg(a.attname order by k.ordinality) as columns
|
|
41
|
+
from pg_index i
|
|
42
|
+
cross join lateral unnest(i.indkey) with ordinality as k(attnum, ordinality)
|
|
43
|
+
join pg_attribute a on a.attrelid = i.indrelid and a.attnum = k.attnum
|
|
44
|
+
where i.indrelid = to_regclass(${relation}) and i.indisunique and i.indisvalid
|
|
45
|
+
and i.indimmediate and i.indpred is null and i.indexprs is null
|
|
46
|
+
and k.ordinality <= i.indnkeyatts
|
|
47
|
+
group by i.indexrelid
|
|
48
|
+
`.pipe(Effect.flatMap(Schema.decodeUnknownEffect(PgKeys)))).map((index) => index.columns);
|
|
49
|
+
});
|
|
50
|
+
for (const keys of required) {
|
|
51
|
+
const columns = keys.map((key) => table.columns[key]?.name);
|
|
52
|
+
if (columns.some((column) => column === void 0) || !physicalKeys.some((actual) => actual.length === columns.length && actual.every((column) => columns.includes(column)))) return yield* PersistenceConfigurationError.make({ reason: `Missing unique key on ${table.name} (${keys.join(", ")})` });
|
|
53
|
+
}
|
|
54
|
+
}).pipe(Effect.mapError((error) => Schema.is(PersistenceConfigurationError)(error) ? error : PersistenceConfigurationError.make({ reason: `Cannot validate SQL storage for ${table.name}` })));
|
|
55
|
+
//#endregion
|
|
56
|
+
export { qualifiedTableName, validateStorage };
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=storage-validation.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-validation.mjs","names":[],"sources":["../../src/internal/storage-validation.ts"],"sourcesContent":["import { Effect, Schema } from \"effect\";\nimport type { SqlClient } from \"effect/unstable/sql/SqlClient\";\n\nimport { PersistenceConfigurationError } from \"./configuration\";\nimport type { StorageTable } from \"./storage-tables\";\n\nconst Column = Schema.Struct({ name: Schema.String, pk: Schema.Int });\nconst Index = Schema.Struct({ name: Schema.String, unique: Schema.Int, partial: Schema.Int });\nconst IndexColumn = Schema.Struct({ name: Schema.NullOr(Schema.String) });\nconst PgColumns = Schema.Array(Schema.Struct({ name: Schema.String }));\nconst PgKeys = Schema.Array(Schema.Struct({ columns: Schema.Array(Schema.String) }));\nconst quote = (value: string) => '\"' + value.replaceAll('\"', '\"\"') + '\"';\n\nexport const qualifiedTableName = (table: Pick<StorageTable, \"name\" | \"schema\">) =>\n (table.schema === undefined ? \"\" : quote(table.schema) + \".\") + quote(table.name);\n\n/** Validate physical uniqueness before the first authentication operation. A\n * partial or expression index cannot establish these unconditional guarantees. */\nexport const validateStorage = (\n client: SqlClient,\n dialect: \"pg\" | \"sqlite\",\n table: StorageTable,\n required: ReadonlyArray<ReadonlyArray<string>>,\n) =>\n Effect.gen(function* () {\n const physicalKeys: ReadonlyArray<ReadonlyArray<string>> = yield* dialect === \"sqlite\"\n ? Effect.gen(function* () {\n if (table.schema !== undefined && table.schema !== \"main\")\n return yield* PersistenceConfigurationError.make({\n reason: \"SQLite storage must belong to the main database\",\n });\n\n const columns = yield* client`select name, pk from pragma_table_info(${table.name})`.pipe(\n Effect.flatMap(Schema.decodeUnknownEffect(Schema.Array(Column))),\n );\n\n for (const column of Object.values(table.columns)) {\n if (!columns.some((actual) => actual.name === column.name))\n return yield* PersistenceConfigurationError.make({\n reason: `Missing SQL column ${table.name}.${column.name}`,\n });\n }\n const keys: string[][] = [];\n const primary = columns.filter((column) => column.pk > 0).sort((a, b) => a.pk - b.pk);\n\n if (primary.length > 0) keys.push(primary.map((column) => column.name));\n\n const indexes =\n yield* client`select name, \"unique\", partial from pragma_index_list(${table.name})`.pipe(\n Effect.flatMap(Schema.decodeUnknownEffect(Schema.Array(Index))),\n );\n\n for (const index of indexes) {\n if (index.unique !== 1 || index.partial !== 0) continue;\n\n const columns = yield* client`select name from pragma_index_info(${index.name})`.pipe(\n Effect.flatMap(Schema.decodeUnknownEffect(Schema.Array(IndexColumn))),\n );\n\n if (columns.every((column) => column.name !== null))\n keys.push(columns.flatMap((column) => (column.name === null ? [] : [column.name])));\n }\n\n return keys;\n })\n : Effect.gen(function* () {\n const relation = qualifiedTableName(table);\n\n const columns =\n yield* client`select attname as name from pg_attribute where attrelid = to_regclass(${relation}) and attnum > 0 and not attisdropped`.pipe(\n Effect.flatMap(Schema.decodeUnknownEffect(PgColumns)),\n );\n\n for (const column of Object.values(table.columns)) {\n if (!columns.some((actual) => actual.name === column.name))\n return yield* PersistenceConfigurationError.make({\n reason: `Missing SQL column ${relation}.${column.name}`,\n });\n }\n\n const indexes = yield* client`\n select array_agg(a.attname order by k.ordinality) as columns\n from pg_index i\n cross join lateral unnest(i.indkey) with ordinality as k(attnum, ordinality)\n join pg_attribute a on a.attrelid = i.indrelid and a.attnum = k.attnum\n where i.indrelid = to_regclass(${relation}) and i.indisunique and i.indisvalid\n and i.indimmediate and i.indpred is null and i.indexprs is null\n and k.ordinality <= i.indnkeyatts\n group by i.indexrelid\n `.pipe(Effect.flatMap(Schema.decodeUnknownEffect(PgKeys)));\n\n return indexes.map((index) => index.columns);\n });\n\n for (const keys of required) {\n const columns = keys.map((key) => table.columns[key]?.name);\n\n if (\n columns.some((column) => column === undefined) ||\n !physicalKeys.some(\n (actual) =>\n actual.length === columns.length && actual.every((column) => columns.includes(column)),\n )\n )\n return yield* PersistenceConfigurationError.make({\n reason: `Missing unique key on ${table.name} (${keys.join(\", \")})`,\n });\n }\n }).pipe(\n Effect.mapError((error) =>\n Schema.is(PersistenceConfigurationError)(error)\n ? error\n : PersistenceConfigurationError.make({\n reason: `Cannot validate SQL storage for ${table.name}`,\n }),\n ),\n );\n"],"mappings":";;;AAMA,MAAM,SAAS,OAAO,OAAO;CAAE,MAAM,OAAO;CAAQ,IAAI,OAAO;AAAI,CAAC;AACpE,MAAM,QAAQ,OAAO,OAAO;CAAE,MAAM,OAAO;CAAQ,QAAQ,OAAO;CAAK,SAAS,OAAO;AAAI,CAAC;AAC5F,MAAM,cAAc,OAAO,OAAO,EAAE,MAAM,OAAO,OAAO,OAAO,MAAM,EAAE,CAAC;AACxE,MAAM,YAAY,OAAO,MAAM,OAAO,OAAO,EAAE,MAAM,OAAO,OAAO,CAAC,CAAC;AACrE,MAAM,SAAS,OAAO,MAAM,OAAO,OAAO,EAAE,SAAS,OAAO,MA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B,KAAK,EACjC,QAAQ,mCAAmC,MAAM,OACnD,CAAC,CACP,CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import "./transaction-kernel.mjs";
|
|
2
|
+
import { Context, Effect } from "effect";
|
|
3
|
+
import { CurrentCommitJournal, HookConfigurationError, LifecycleHooks } from "@yielded/auth/Hooks";
|
|
4
|
+
import "effect/unstable/sql/SqlClient";
|
|
5
|
+
import * as SqlError$1 from "effect/unstable/sql/SqlError";
|
|
6
|
+
import { Statement } from "effect/unstable/sql/Statement";
|
|
7
|
+
//#region src/internal/transaction-execution-kernel.d.ts
|
|
8
|
+
interface TransactionTargetConfiguration<Failure> {
|
|
9
|
+
readonly mode: "interactive" | "synchronous" | "batch";
|
|
10
|
+
readonly dialect: "pg" | "mysql" | "sqlite";
|
|
11
|
+
readonly locking: boolean;
|
|
12
|
+
readonly standaloneGuard: (database: any) => Effect.Effect<void, Failure>;
|
|
13
|
+
readonly transaction?: <A, E, R>(database: any, body: (transaction: any) => Effect.Effect<A, E, R>) => Effect.Effect<A, E | SqlError$1.SqlError | Failure, R>;
|
|
14
|
+
}
|
|
15
|
+
type TransactionCoordinatorError<E, Failure> = E | Failure | HookConfigurationError | SqlError$1.SqlError;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { TransactionCoordinatorError, TransactionTargetConfiguration };
|
|
18
|
+
//# sourceMappingURL=transaction-execution-kernel.d.mts.map
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Context, Effect, Option } from "effect";
|
|
2
|
+
import { CurrentCommitJournal, coordinateCommit, hasCommitScope } from "@yielded/auth/Hooks";
|
|
3
|
+
//#region src/internal/transaction-execution-kernel.ts
|
|
4
|
+
const makeTransactionExecutionKernel = (transactions) => {
|
|
5
|
+
const { makeTransactionOwner, reportTransactionFailure } = transactions;
|
|
6
|
+
const sqlClientTransactionStandaloneGuard = (unavailable, database) => Effect.serviceOption(database.$client.transactionService).pipe(Effect.flatMap(Option.match({
|
|
7
|
+
onNone: () => Effect.void,
|
|
8
|
+
onSome: () => Effect.fail(unavailable())
|
|
9
|
+
})));
|
|
10
|
+
const makeTransactionExecution = (ownerTag, database, configuration, unavailable, nonce, bound) => {
|
|
11
|
+
const invariant = (value) => {
|
|
12
|
+
if (!value) throw unavailable();
|
|
13
|
+
};
|
|
14
|
+
return {
|
|
15
|
+
bound: bound !== void 0,
|
|
16
|
+
active: () => bound === void 0 || bound.active,
|
|
17
|
+
admit: bound !== void 0 ? Effect.suspend(() => bound.active ? Effect.void : Effect.fail(unavailable())) : Effect.gen(function* () {
|
|
18
|
+
if (yield* hasCommitScope) return yield* Effect.fail(unavailable());
|
|
19
|
+
yield* configuration.standaloneGuard(database);
|
|
20
|
+
}),
|
|
21
|
+
poison: () => {
|
|
22
|
+
if (bound !== void 0) bound.poisoned = true;
|
|
23
|
+
},
|
|
24
|
+
run: (body, mutation = true) => {
|
|
25
|
+
return Effect.suspend(() => {
|
|
26
|
+
let entered = false;
|
|
27
|
+
return (bound !== void 0 ? Effect.gen(function* () {
|
|
28
|
+
if (!bound.active) return yield* Effect.fail(unavailable());
|
|
29
|
+
entered = true;
|
|
30
|
+
bound.inFlight++;
|
|
31
|
+
if (!mutation) return yield* Effect.provideContext(body, Context.make(ownerTag, bound.owner).pipe(Context.add(CurrentCommitJournal, bound.owner.journal)));
|
|
32
|
+
invariant(!bound.used && !bound.poisoned);
|
|
33
|
+
bound.used = true;
|
|
34
|
+
return (yield* coordinateCommit((journal) => Effect.gen(function* () {
|
|
35
|
+
bound.owner.guards.push(journal.prepare(void 0));
|
|
36
|
+
return yield* Effect.provideContext(body, Context.make(ownerTag, {
|
|
37
|
+
...bound.owner,
|
|
38
|
+
journal
|
|
39
|
+
}).pipe(Context.add(CurrentCommitJournal, journal)));
|
|
40
|
+
}), { mode: configuration.mode })).value;
|
|
41
|
+
}).pipe(Effect.onExit((exit) => Effect.sync(() => {
|
|
42
|
+
if (entered) bound.inFlight--;
|
|
43
|
+
if (exit._tag === "Failure") bound.poisoned = true;
|
|
44
|
+
}))) : Effect.gen(function* () {
|
|
45
|
+
if (yield* hasCommitScope) return yield* Effect.fail(unavailable());
|
|
46
|
+
yield* configuration.standaloneGuard(database);
|
|
47
|
+
const marker = nonce();
|
|
48
|
+
return (yield* coordinateCommit((journal) => {
|
|
49
|
+
const run = (tx) => Effect.gen(function* () {
|
|
50
|
+
const owner = makeTransactionOwner(tx, journal, marker, unavailable, {
|
|
51
|
+
client: database.$client,
|
|
52
|
+
batch: configuration.mode === "batch",
|
|
53
|
+
locking: configuration.locking,
|
|
54
|
+
mysql: configuration.dialect === "mysql",
|
|
55
|
+
dialect: configuration.dialect
|
|
56
|
+
});
|
|
57
|
+
const value = yield* Effect.provideContext(body, Context.make(ownerTag, owner).pipe(Context.add(CurrentCommitJournal, journal)));
|
|
58
|
+
yield* owner.finish();
|
|
59
|
+
if (configuration.mode === "batch") yield* tx.$client.batch(owner.statements);
|
|
60
|
+
return value;
|
|
61
|
+
});
|
|
62
|
+
return configuration.mode === "batch" ? run(database) : configuration.transaction !== void 0 ? configuration.transaction(database, run) : database.transaction(run);
|
|
63
|
+
}, { mode: configuration.mode })).value;
|
|
64
|
+
})).pipe((operation) => reportTransactionFailure(operation, unavailable), Effect.mapError(unavailable), Effect.catchDefect(() => Effect.fail(unavailable())));
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
const coordinateTransactionOwner = (database, ownerTag, configuration, allocate, unavailable, nonce, services, owner) => {
|
|
70
|
+
return Effect.gen(function* () {
|
|
71
|
+
if (yield* hasCommitScope) return yield* Effect.fail(unavailable());
|
|
72
|
+
yield* configuration.standaloneGuard(database);
|
|
73
|
+
const resources = yield* allocate.pipe((operation) => reportTransactionFailure(operation, unavailable), Effect.mapError(unavailable), Effect.catchDefect(() => Effect.fail(unavailable())));
|
|
74
|
+
const marker = nonce();
|
|
75
|
+
return (yield* coordinateCommit((journal) => {
|
|
76
|
+
const run = (tx) => Effect.gen(function* () {
|
|
77
|
+
const state = makeTransactionOwner(tx, journal, marker, unavailable, {
|
|
78
|
+
client: database.$client,
|
|
79
|
+
batch: configuration.mode === "batch",
|
|
80
|
+
dialect: configuration.dialect,
|
|
81
|
+
mysql: configuration.dialect === "mysql",
|
|
82
|
+
locking: configuration.locking
|
|
83
|
+
});
|
|
84
|
+
const bound = {
|
|
85
|
+
owner: state,
|
|
86
|
+
used: false,
|
|
87
|
+
poisoned: false,
|
|
88
|
+
active: true,
|
|
89
|
+
inFlight: 0
|
|
90
|
+
};
|
|
91
|
+
return yield* Effect.gen(function* () {
|
|
92
|
+
const value = yield* owner(tx, services(makeTransactionExecution(ownerTag, tx, configuration, unavailable, nonce, bound), resources), (statement) => {
|
|
93
|
+
if (!bound.active) throw unavailable();
|
|
94
|
+
state.statements.push(statement);
|
|
95
|
+
});
|
|
96
|
+
bound.active = false;
|
|
97
|
+
if (bound.poisoned || bound.inFlight !== 0) return yield* Effect.fail(unavailable());
|
|
98
|
+
yield* state.finish();
|
|
99
|
+
if (configuration.mode === "batch") yield* tx.$client.batch(state.statements);
|
|
100
|
+
return value;
|
|
101
|
+
}).pipe(Effect.ensuring(Effect.sync(() => {
|
|
102
|
+
bound.active = false;
|
|
103
|
+
})));
|
|
104
|
+
});
|
|
105
|
+
return configuration.mode === "batch" ? run(database) : configuration.transaction !== void 0 ? configuration.transaction(database, run) : database.transaction(run);
|
|
106
|
+
}, { mode: configuration.mode })).value;
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
return {
|
|
110
|
+
sqlClientTransactionStandaloneGuard,
|
|
111
|
+
makeTransactionExecution,
|
|
112
|
+
coordinateTransactionOwner
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
//#endregion
|
|
116
|
+
export { makeTransactionExecutionKernel };
|
|
117
|
+
|
|
118
|
+
//# sourceMappingURL=transaction-execution-kernel.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction-execution-kernel.mjs","names":[],"sources":["../../src/internal/transaction-execution-kernel.ts"],"sourcesContent":["import {\n coordinateCommit,\n hasCommitScope,\n CurrentCommitJournal,\n type LifecycleHooks,\n type HookConfigurationError,\n} from \"@yielded/auth/Hooks\";\n/* oxlint-disable no-explicit-any -- existing storage kernels erase foreign table shapes; domain errors remain typed. */\n/* oxlint-disable no-explicit-any -- private execution bridge retains exact public driver wrappers. */\nimport { Context, Effect, Option } from \"effect\";\nimport type * as SqlClient from \"effect/unstable/sql/SqlClient\";\nimport type * as SqlError from \"effect/unstable/sql/SqlError\";\nimport type { Statement } from \"effect/unstable/sql/Statement\";\n\nimport {\n type TransactionNativeDatabase,\n type TransactionOwner,\n type makeTransactionKernel,\n} from \"./transaction-kernel\";\n\nexport interface TransactionTargetConfiguration<Failure> {\n readonly mode: \"interactive\" | \"synchronous\" | \"batch\";\n readonly dialect: \"pg\" | \"mysql\" | \"sqlite\";\n readonly locking: boolean;\n readonly standaloneGuard: (database: any) => Effect.Effect<void, Failure>;\n readonly transaction?: <A, E, R>(\n database: any,\n body: (transaction: any) => Effect.Effect<A, E, R>,\n ) => Effect.Effect<A, E | SqlError.SqlError | Failure, R>;\n}\n\nexport type TransactionCoordinatorError<E, Failure> =\n | E\n | Failure\n | HookConfigurationError\n | SqlError.SqlError;\n\nexport interface TransactionBound<Failure> {\n readonly owner: TransactionOwner<Failure>;\n used: boolean;\n poisoned: boolean;\n active: boolean;\n inFlight: number;\n}\n\nexport interface TransactionExecution<Failure, OwnerId, Requirements = LifecycleHooks> {\n readonly bound: boolean;\n readonly active: () => boolean;\n readonly admit: Effect.Effect<void, Failure>;\n readonly poison: () => void;\n readonly run: <A, E, R>(\n body: Effect.Effect<A, E, R>,\n mutation?: boolean,\n ) => Effect.Effect<A, Failure, Exclude<R, OwnerId | CurrentCommitJournal> | Requirements>;\n}\n\nexport const makeTransactionExecutionKernel = (\n transactions: Pick<\n ReturnType<typeof makeTransactionKernel>,\n \"makeTransactionOwner\" | \"reportTransactionFailure\"\n >,\n) => {\n const { makeTransactionOwner, reportTransactionFailure } = transactions;\n\n const sqlClientTransactionStandaloneGuard = <Failure>(\n unavailable: () => Failure,\n database: {\n readonly $client: Pick<SqlClient.SqlClient, \"transactionService\">;\n },\n ) =>\n Effect.serviceOption(database.$client.transactionService).pipe(\n Effect.flatMap(\n Option.match({ onNone: () => Effect.void, onSome: () => Effect.fail(unavailable()) }),\n ),\n );\n\n const makeTransactionExecution = <Failure, OwnerId>(\n ownerTag: Context.Key<OwnerId, TransactionOwner<Failure>>,\n database: TransactionNativeDatabase,\n configuration: TransactionTargetConfiguration<Failure>,\n unavailable: () => Failure,\n nonce: () => string,\n bound?: TransactionBound<Failure>,\n ): TransactionExecution<Failure, OwnerId> => {\n const invariant: (value: unknown) => asserts value = (value) => {\n if (!value) throw unavailable();\n };\n\n return {\n bound: bound !== undefined,\n active: () => bound === undefined || bound.active,\n admit:\n bound !== undefined\n ? Effect.suspend(() => (bound.active ? Effect.void : Effect.fail(unavailable())))\n : Effect.gen(function* () {\n if (yield* hasCommitScope) return yield* Effect.fail(unavailable());\n yield* configuration.standaloneGuard(database);\n }),\n poison: () => {\n if (bound !== undefined) bound.poisoned = true;\n },\n run: <A, E, R>(\n body: Effect.Effect<A, E, R>,\n mutation = true,\n ): Effect.Effect<A, Failure, Exclude<R, OwnerId | CurrentCommitJournal> | LifecycleHooks> => {\n return Effect.suspend(() => {\n let entered = false;\n\n const work =\n bound !== undefined\n ? Effect.gen(function* () {\n if (!bound.active) return yield* Effect.fail(unavailable());\n entered = true;\n bound.inFlight++;\n if (!mutation)\n return yield* Effect.provideContext(\n body,\n Context.make(ownerTag, bound.owner).pipe(\n Context.add(CurrentCommitJournal, bound.owner.journal),\n ),\n );\n invariant(!bound.used && !bound.poisoned);\n bound.used = true;\n\n const result = yield* coordinateCommit(\n (journal) =>\n Effect.gen(function* () {\n bound.owner.guards.push(journal.prepare(undefined));\n\n return yield* Effect.provideContext(\n body,\n Context.make(ownerTag, { ...bound.owner, journal }).pipe(\n Context.add(CurrentCommitJournal, journal),\n ),\n );\n }),\n { mode: configuration.mode },\n );\n\n return result.value;\n }).pipe(\n Effect.onExit((exit) =>\n Effect.sync(() => {\n if (entered) bound.inFlight--;\n if (exit._tag === \"Failure\") bound.poisoned = true;\n }),\n ),\n )\n : Effect.gen(function* () {\n if (yield* hasCommitScope) return yield* Effect.fail(unavailable());\n yield* configuration.standaloneGuard(database);\n const marker = nonce();\n\n const result = yield* coordinateCommit(\n (journal) => {\n const run = (tx: TransactionNativeDatabase) =>\n Effect.gen(function* () {\n const owner = makeTransactionOwner(tx, journal, marker, unavailable, {\n client: database.$client,\n batch: configuration.mode === \"batch\",\n locking: configuration.locking,\n mysql: configuration.dialect === \"mysql\",\n dialect: configuration.dialect,\n });\n\n const value = yield* Effect.provideContext(\n body,\n Context.make(ownerTag, owner).pipe(\n Context.add(CurrentCommitJournal, journal),\n ),\n );\n\n yield* owner.finish();\n if (configuration.mode === \"batch\")\n yield* tx.$client.batch(owner.statements);\n\n return value;\n });\n\n return configuration.mode === \"batch\"\n ? run(database)\n : configuration.transaction !== undefined\n ? configuration.transaction(database, run)\n : database.transaction(run);\n },\n { mode: configuration.mode },\n );\n\n return result.value;\n });\n\n return work.pipe(\n (operation) => reportTransactionFailure(operation, unavailable),\n Effect.mapError(unavailable),\n Effect.catchDefect(() => Effect.fail(unavailable())),\n );\n });\n },\n };\n };\n\n const coordinateTransactionOwner = <\n Failure,\n OwnerId,\n Resources,\n AllocationError,\n Services,\n Transaction,\n A,\n E,\n R,\n >(\n database: TransactionNativeDatabase,\n ownerTag: Context.Key<OwnerId, TransactionOwner<Failure>>,\n configuration: TransactionTargetConfiguration<Failure>,\n allocate: Effect.Effect<Resources, AllocationError>,\n unavailable: () => Failure,\n nonce: () => string,\n services: (execution: TransactionExecution<Failure, OwnerId>, resources: Resources) => Services,\n owner: (\n transaction: Transaction,\n services: Services,\n append: (statement: Statement<any>) => void,\n ) => Effect.Effect<A, E, R>,\n ): Effect.Effect<\n A,\n TransactionCoordinatorError<E, Failure>,\n Exclude<R, CurrentCommitJournal> | LifecycleHooks\n > => {\n return Effect.gen(function* () {\n if (yield* hasCommitScope) return yield* Effect.fail(unavailable());\n yield* configuration.standaloneGuard(database);\n\n // Allocation is independent of registration data and always precedes the physical owner.\n const resources = yield* allocate.pipe(\n (operation) => reportTransactionFailure(operation, unavailable),\n Effect.mapError(unavailable),\n Effect.catchDefect(() => Effect.fail(unavailable())),\n );\n\n const marker = nonce();\n\n const result = yield* coordinateCommit(\n (journal) => {\n const run = (tx: TransactionNativeDatabase) =>\n Effect.gen(function* () {\n const state = makeTransactionOwner(tx, journal, marker, unavailable, {\n client: database.$client,\n batch: configuration.mode === \"batch\",\n dialect: configuration.dialect,\n mysql: configuration.dialect === \"mysql\",\n locking: configuration.locking,\n });\n\n const bound: TransactionBound<Failure> = {\n owner: state,\n used: false,\n poisoned: false,\n active: true,\n inFlight: 0,\n };\n\n return yield* Effect.gen(function* () {\n const value = yield* owner(\n tx as Transaction,\n services(\n makeTransactionExecution(\n ownerTag,\n tx,\n configuration,\n unavailable,\n nonce,\n bound,\n ),\n resources,\n ),\n (statement) => {\n if (!bound.active) throw unavailable();\n state.statements.push(statement);\n },\n );\n\n bound.active = false;\n if (bound.poisoned || bound.inFlight !== 0)\n return yield* Effect.fail(unavailable());\n yield* state.finish();\n if (configuration.mode === \"batch\") yield* tx.$client.batch(state.statements);\n\n return value;\n }).pipe(\n Effect.ensuring(\n Effect.sync(() => {\n bound.active = false;\n }),\n ),\n );\n });\n\n return configuration.mode === \"batch\"\n ? run(database)\n : configuration.transaction !== undefined\n ? configuration.transaction(database, run)\n : database.transaction(run);\n },\n { mode: configuration.mode },\n );\n\n return result.value as A;\n });\n };\n\n return {\n sqlClientTransactionStandaloneGuard,\n makeTransactionExecution,\n coordinateTransactionOwner,\n };\n};\n"],"mappings":";;;AAwDA,MAAa,kCACX,iBAIG;CACH,MAAM,EAAE,sBAAsB,6BAA6B;CAE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