@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,170 @@
|
|
|
1
|
+
import { requiredProofConstraints } from "./proof-model.mjs";
|
|
2
|
+
import { CurrentProofSql } from "../internal/proof-kernel.mjs";
|
|
3
|
+
import { CurrentPhoneTransaction } from "../internal/phone-kernel.mjs";
|
|
4
|
+
import { completeProofPlanIn } from "./proof-sql.mjs";
|
|
5
|
+
import { coordinateTransactionOwner, makeTransactionExecution, sqlClientTransactionStandaloneGuard } from "./transaction-execution.mjs";
|
|
6
|
+
import { phoneProofs, requiredPhoneConstraints } from "./phone-model.mjs";
|
|
7
|
+
import { CurrentD1PlanningDatabase } from "./d1-planning.mjs";
|
|
8
|
+
import { compileD1ProofCompletionPlan } from "./d1-proofs.mjs";
|
|
9
|
+
import { admitPhone, capturePhone, cleanupPhoneAdmission, equal, invariant, lookupPhone, preparePhoneMutation, unavailable } from "./phone-state.mjs";
|
|
10
|
+
import { Context, Effect, Schema } from "effect";
|
|
11
|
+
import { randomId } from "@yielded/auth/Persistence";
|
|
12
|
+
import { LifecycleHooks } from "@yielded/auth/Hooks";
|
|
13
|
+
import { PhoneActionAuthorization, PhoneAdmission, PhoneAdmissionPolicy, PhoneConfigurationError, PhoneLifecyclePolicy, PhoneLifecycleTarget, PhonePersistence, PhoneSignInTargets } from "@yielded/auth/PhoneOtp";
|
|
14
|
+
import { ProofBinding } from "@yielded/auth/Proofs";
|
|
15
|
+
import { sql } from "drizzle-orm";
|
|
16
|
+
//#region src/drizzle/phone-target.ts
|
|
17
|
+
const sqlClientPhoneStandaloneGuard = (database) => sqlClientTransactionStandaloneGuard(unavailable, database);
|
|
18
|
+
const validateMapping = (original, configuration) => {
|
|
19
|
+
const mapping = original;
|
|
20
|
+
invariant(mapping.moduleId.length > 0);
|
|
21
|
+
Schema.decodeSync(PhoneLifecyclePolicy)(mapping.policy);
|
|
22
|
+
Schema.decodeSync(PhoneAdmissionPolicy)(mapping.admission);
|
|
23
|
+
invariant(mapping.admission.requestRetentionMillis >= mapping.admission.windowMillis);
|
|
24
|
+
const proofs = phoneProofs(mapping.proofs);
|
|
25
|
+
invariant(proofs !== void 0);
|
|
26
|
+
for (const [key, value] of Object.entries(requiredProofConstraints)) invariant(proofs.constraints?.[key] === value);
|
|
27
|
+
if (configuration.mode === "synchronous") invariant(proofs.allocateVersionSync !== void 0);
|
|
28
|
+
if (configuration.mode === "batch") invariant(proofs.d1 !== void 0 && proofs.authority.identifier.d1CurrentCondition !== void 0);
|
|
29
|
+
for (const [key, value] of Object.entries(requiredPhoneConstraints)) invariant(mapping.constraints?.[key] === value);
|
|
30
|
+
if (configuration.mode === "batch") invariant(mapping.d1?.primary === true);
|
|
31
|
+
return Object.freeze({
|
|
32
|
+
...mapping,
|
|
33
|
+
policy: Object.freeze({ ...mapping.policy }),
|
|
34
|
+
subject: Object.freeze({ ...mapping.subject }),
|
|
35
|
+
state: Object.freeze({ ...mapping.state }),
|
|
36
|
+
identifier: Object.freeze({ ...mapping.identifier }),
|
|
37
|
+
admission: Object.freeze({ ...mapping.admission }),
|
|
38
|
+
credential: Object.freeze({ ...mapping.credential }),
|
|
39
|
+
subjectIds: Object.freeze({ ...mapping.subjectIds })
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
const services = (mapping, execution, hooks, configuration) => {
|
|
43
|
+
const run = (effect, mutation = true) => execution.admit.pipe(Effect.andThen(execution.run(effect, mutation)), Effect.provideService(LifecycleHooks, hooks));
|
|
44
|
+
return {
|
|
45
|
+
phoneAdmission: PhoneAdmission.of({
|
|
46
|
+
admit: (input) => run(admitPhone(mapping, { ...input })),
|
|
47
|
+
cleanup: (input) => run(cleanupPhoneAdmission(mapping, { ...input }))
|
|
48
|
+
}),
|
|
49
|
+
phoneSignInTargets: PhoneSignInTargets.of({ lookup: (input) => run(lookupPhone(mapping, { ...input }), false) }),
|
|
50
|
+
phonePersistence: PhonePersistence.of({
|
|
51
|
+
target: (input) => run(Effect.gen(function* () {
|
|
52
|
+
invariant(input.moduleId === mapping.moduleId);
|
|
53
|
+
return (yield* capturePhone(mapping, { ...input })).target;
|
|
54
|
+
}), false),
|
|
55
|
+
mutate: (original, prepare) => Effect.suspend(() => {
|
|
56
|
+
const input = {
|
|
57
|
+
...original,
|
|
58
|
+
target: Schema.decodeSync(Schema.toCodecIso(PhoneLifecycleTarget))(Schema.encodeSync(Schema.toCodecIso(PhoneLifecycleTarget))(original.target)),
|
|
59
|
+
policy: { ...original.policy },
|
|
60
|
+
...original.authorization === void 0 ? {} : { authorization: Schema.decodeSync(Schema.toCodecIso(PhoneActionAuthorization))(Schema.encodeSync(Schema.toCodecIso(PhoneActionAuthorization))(original.authorization)) },
|
|
61
|
+
completion: {
|
|
62
|
+
input: {
|
|
63
|
+
...original.completion.input,
|
|
64
|
+
binding: Schema.decodeSync(Schema.toCodecIso(ProofBinding))(Schema.encodeSync(Schema.toCodecIso(ProofBinding))(original.completion.input.binding))
|
|
65
|
+
},
|
|
66
|
+
prepare: original.completion.prepare
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
return run(Effect.gen(function* () {
|
|
70
|
+
const owner = yield* CurrentPhoneTransaction, candidate = yield* preparePhoneMutation(mapping, input);
|
|
71
|
+
if (candidate.mutate === void 0) {
|
|
72
|
+
const receipt = prepare(candidate.decision, owner.journal);
|
|
73
|
+
owner.guards.push(receipt);
|
|
74
|
+
return receipt;
|
|
75
|
+
}
|
|
76
|
+
const cn = phoneProofs(mapping.proofs).continuation;
|
|
77
|
+
const observed = yield* owner.read(cn.table, equal(cn.table, {
|
|
78
|
+
[cn.moduleId]: input.completion.input.moduleId,
|
|
79
|
+
[cn.continuationId]: input.completion.input.continuationId
|
|
80
|
+
}), { limit: 1 });
|
|
81
|
+
let completed = false;
|
|
82
|
+
const plan = {
|
|
83
|
+
...input.completion,
|
|
84
|
+
prepare: (decision, journal) => {
|
|
85
|
+
completed = decision === "completed";
|
|
86
|
+
const proofReceipt = input.completion.prepare(decision, journal, () => void 0);
|
|
87
|
+
owner.guards.push(proofReceipt);
|
|
88
|
+
return prepare(decision === "completed" ? candidate.decision : { _tag: "Rejected" }, journal);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
let receipt;
|
|
92
|
+
if (owner.batch) {
|
|
93
|
+
const offset = owner.statements.length;
|
|
94
|
+
yield* candidate.mutate;
|
|
95
|
+
const statements = owner.statements.splice(offset);
|
|
96
|
+
const compiled = yield* compileD1ProofCompletionPlan(phoneProofs(mapping.proofs), plan, {
|
|
97
|
+
statements,
|
|
98
|
+
appliedCondition: candidate.appliedCondition
|
|
99
|
+
}, (x) => x).pipe(Effect.provideService(CurrentD1PlanningDatabase, owner.database));
|
|
100
|
+
invariant(compiled.statements.length !== 0);
|
|
101
|
+
owner.statements.push(...compiled.statements, ...compiled.postconditions ?? []);
|
|
102
|
+
receipt = compiled.receipt;
|
|
103
|
+
} else receipt = yield* completeProofPlanIn(phoneProofs(mapping.proofs), {
|
|
104
|
+
mode: configuration.mode === "synchronous" ? "synchronous" : "interactive",
|
|
105
|
+
locking: configuration.locking,
|
|
106
|
+
standaloneGuard: Effect.void,
|
|
107
|
+
coordinated: true,
|
|
108
|
+
insertIfAbsent: (query, key, value) => configuration.dialect === "mysql" ? query.onDuplicateKeyUpdate({ set: { [key]: value } }) : query.onConflictDoNothing()
|
|
109
|
+
}, plan, candidate.mutate, (x) => x).pipe(Effect.provideService(CurrentProofSql, owner.database));
|
|
110
|
+
if (completed) {
|
|
111
|
+
invariant(observed.rows.length === 1);
|
|
112
|
+
const record = yield* cn.decode(observed.rows[0]);
|
|
113
|
+
observed.rows = observed.rows.map((row) => ({
|
|
114
|
+
...row,
|
|
115
|
+
[cn.consumed]: true
|
|
116
|
+
}));
|
|
117
|
+
const command = phoneProofs(mapping.proofs).command;
|
|
118
|
+
owner.postconditions.push(sql`${mapping.engineNowMillis} < ${record.expiresAtMillis}`, sql`exists(select 1 from ${command.table} where ${equal(command.table, {
|
|
119
|
+
[command.moduleId]: input.completion.input.moduleId,
|
|
120
|
+
[command.commandId]: input.completion.input.continuationDigest,
|
|
121
|
+
[command.kind]: "complete",
|
|
122
|
+
[command.decision]: "completed",
|
|
123
|
+
[command.retentionUntil]: phoneProofs(mapping.proofs).encodeInstant(record.expiresAtMillis)
|
|
124
|
+
})})`);
|
|
125
|
+
}
|
|
126
|
+
invariant(receipt?._tag === "PreparedCommit");
|
|
127
|
+
owner.guards.push(receipt);
|
|
128
|
+
return receipt;
|
|
129
|
+
}));
|
|
130
|
+
}).pipe(Effect.catchDefect(() => Effect.fail(unavailable())))
|
|
131
|
+
})
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
const makeTargetPhonePersistence = (database, source, configuration) => Effect.gen(function* () {
|
|
135
|
+
const hooks = yield* LifecycleHooks;
|
|
136
|
+
const original = yield* Effect.isEffect(source) ? source : Effect.succeed(source);
|
|
137
|
+
const mapping = yield* Effect.try({
|
|
138
|
+
try: () => validateMapping(original, configuration),
|
|
139
|
+
catch: () => PhoneConfigurationError.make({})
|
|
140
|
+
});
|
|
141
|
+
const execution = makeTransactionExecution(CurrentPhoneTransaction, database, configuration, unavailable, randomId);
|
|
142
|
+
return services(mapping, execution, hooks, configuration);
|
|
143
|
+
});
|
|
144
|
+
const coordinateTargetPhone = (database, source, configuration, body) => Effect.gen(function* () {
|
|
145
|
+
const hooks = yield* LifecycleHooks;
|
|
146
|
+
const original = yield* Effect.isEffect(source) ? source : Effect.succeed(source);
|
|
147
|
+
const mapping = yield* Effect.try({
|
|
148
|
+
try: () => validateMapping(original, configuration),
|
|
149
|
+
catch: () => PhoneConfigurationError.make({})
|
|
150
|
+
});
|
|
151
|
+
return yield* coordinateTransactionOwner(database, CurrentPhoneTransaction, configuration, Effect.void, unavailable, randomId, (execution) => services(mapping, execution, hooks, configuration), body);
|
|
152
|
+
});
|
|
153
|
+
/** Concrete driver wrappers select transaction mode; cryptography always precedes these owners. */
|
|
154
|
+
const makePhoneTarget = (configuration) => {
|
|
155
|
+
function coordinatePhonePersistence(acquire, options, body) {
|
|
156
|
+
return Effect.flatMap(acquire, (database) => coordinateTargetPhone(database, options.mapping, configuration, (transaction, services) => {
|
|
157
|
+
const provided = Context.make(PhonePersistence, services.phonePersistence).pipe(Context.add(PhoneAdmission, services.phoneAdmission), Context.add(PhoneSignInTargets, services.phoneSignInTargets));
|
|
158
|
+
const work = Effect.provideContext(body, provided);
|
|
159
|
+
return options.transaction === void 0 ? work : Effect.provideService(work, options.transaction, options.transaction.of(transaction));
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
makePhonePersistenceServices: (database, mapping) => makeTargetPhonePersistence(database, mapping, configuration),
|
|
164
|
+
coordinatePhonePersistence
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
//#endregion
|
|
168
|
+
export { coordinateTargetPhone, makePhoneTarget, makeTargetPhonePersistence, sqlClientPhoneStandaloneGuard };
|
|
169
|
+
|
|
170
|
+
//# sourceMappingURL=phone-target.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phone-target.mjs","names":[],"sources":["../../src/drizzle/phone-target.ts"],"sourcesContent":["import { LifecycleHooks } from \"@yielded/auth/Hooks\";\nimport { randomId } from \"@yielded/auth/Persistence\";\nimport {\n PhoneConfigurationError,\n PhoneLifecyclePolicy,\n PhoneAdmissionPolicy,\n PhoneLifecycleTarget,\n PhoneActionAuthorization,\n PhoneAdmission,\n type PhoneMutation,\n PhonePersistence,\n PhoneSignInTargets,\n type PhoneOtpUnavailable as PhoneUnavailable,\n} from \"@yielded/auth/PhoneOtp\";\nimport { ProofBinding } from \"@yielded/auth/Proofs\";\nimport { sql, type Table } from \"drizzle-orm\";\n/* oxlint-disable no-explicit-any -- shared native implementation; driver entrypoints retain exact database and table types. */\nimport { Context, Effect, Schema } from \"effect\";\nimport type { Statement } from \"effect/unstable/sql/Statement\";\n\nimport { CurrentD1PlanningDatabase } from \"./d1-planning\";\nimport { compileD1ProofCompletionPlan } from \"./d1-proofs\";\nimport type { PersistenceMappingError } from \"./model\";\nimport {\n phoneProofs,\n type PhoneMapping,\n type PhoneMappingSource,\n type PhonePersistenceServices,\n requiredPhoneConstraints,\n} from \"./phone-model\";\nimport {\n capturePhone,\n lookupPhone,\n admitPhone,\n cleanupPhoneAdmission,\n CurrentPhoneTransaction,\n invariant,\n equal,\n preparePhoneMutation,\n unavailable,\n} from \"./phone-state\";\nimport { requiredProofConstraints } from \"./proof-model\";\nimport { completeProofPlanIn, CurrentProofSql } from \"./proof-sql\";\nimport type { SuppliedService } from \"./SuppliedService\";\nimport {\n coordinateTransactionOwner,\n makeTransactionExecution,\n sqlClientTransactionStandaloneGuard,\n type TransactionExecution,\n type TransactionTargetConfiguration,\n type TransactionCoordinatorError,\n} from \"./transaction-execution\";\nimport type { TransactionNativeDatabase } from \"./transaction-owner\";\nexport type PhoneTargetConfiguration = TransactionTargetConfiguration<PhoneUnavailable>;\n\nexport type PhoneCoordinatorError<E> =\n | TransactionCoordinatorError<E, PhoneUnavailable>\n | PhoneConfigurationError\n | PersistenceMappingError;\n\nexport const sqlClientPhoneStandaloneGuard = (\n database: Parameters<typeof sqlClientTransactionStandaloneGuard>[1],\n) => sqlClientTransactionStandaloneGuard(unavailable, database);\n\nconst validateMapping = <M>(original: M, configuration: PhoneTargetConfiguration): M => {\n const mapping = original as any;\n\n invariant(mapping.moduleId.length > 0);\n Schema.decodeSync(PhoneLifecyclePolicy)(mapping.policy);\n Schema.decodeSync(PhoneAdmissionPolicy)(mapping.admission);\n invariant(mapping.admission.requestRetentionMillis >= mapping.admission.windowMillis);\n const proofs = phoneProofs(mapping.proofs);\n\n invariant(proofs !== undefined);\n for (const [key, value] of Object.entries(requiredProofConstraints))\n invariant((proofs.constraints as any)?.[key] === value);\n if (configuration.mode === \"synchronous\") invariant(proofs.allocateVersionSync !== undefined);\n if (configuration.mode === \"batch\")\n invariant(\n proofs.d1 !== undefined && proofs.authority.identifier.d1CurrentCondition !== undefined,\n );\n for (const [key, value] of Object.entries(requiredPhoneConstraints))\n invariant(mapping.constraints?.[key] === value);\n if (configuration.mode === \"batch\") invariant(mapping.d1?.primary === true);\n\n return Object.freeze({\n ...mapping,\n policy: Object.freeze({ ...mapping.policy }),\n subject: Object.freeze({ ...mapping.subject }),\n state: Object.freeze({ ...mapping.state }),\n identifier: Object.freeze({ ...mapping.identifier }),\n admission: Object.freeze({ ...mapping.admission }),\n credential: Object.freeze({ ...mapping.credential }),\n subjectIds: Object.freeze({ ...mapping.subjectIds }),\n });\n};\n\nconst services = (\n mapping: any,\n execution: TransactionExecution<PhoneUnavailable, CurrentPhoneTransaction>,\n hooks: LifecycleHooks[\"Service\"],\n configuration: PhoneTargetConfiguration,\n): PhonePersistenceServices => {\n const run = <A, E, R>(effect: Effect.Effect<A, E, R>, mutation = true) =>\n execution.admit.pipe(\n Effect.andThen(execution.run(effect, mutation)),\n Effect.provideService(LifecycleHooks, hooks),\n );\n\n return {\n phoneAdmission: PhoneAdmission.of({\n admit: (input) => run(admitPhone(mapping, { ...input })),\n cleanup: (input) => run(cleanupPhoneAdmission(mapping, { ...input })),\n }),\n phoneSignInTargets: PhoneSignInTargets.of({\n lookup: (input) => run(lookupPhone(mapping, { ...input }), false),\n }),\n phonePersistence: PhonePersistence.of({\n target: (input) =>\n run(\n Effect.gen(function* () {\n invariant(input.moduleId === mapping.moduleId);\n\n return (yield* capturePhone(mapping, { ...input })).target;\n }),\n false,\n ),\n mutate: (original, prepare) =>\n Effect.suspend(() => {\n const input: PhoneMutation = {\n ...original,\n target: Schema.decodeSync(Schema.toCodecIso(PhoneLifecycleTarget))(\n Schema.encodeSync(Schema.toCodecIso(PhoneLifecycleTarget))(original.target),\n ),\n policy: { ...original.policy },\n ...(original.authorization === undefined\n ? {}\n : {\n authorization: Schema.decodeSync(Schema.toCodecIso(PhoneActionAuthorization))(\n Schema.encodeSync(Schema.toCodecIso(PhoneActionAuthorization))(\n original.authorization,\n ),\n ),\n }),\n completion: {\n input: {\n ...original.completion.input,\n binding: Schema.decodeSync(Schema.toCodecIso(ProofBinding))(\n Schema.encodeSync(Schema.toCodecIso(ProofBinding))(\n original.completion.input.binding,\n ),\n ),\n },\n prepare: original.completion.prepare,\n },\n };\n\n return run(\n Effect.gen(function* () {\n const owner = yield* CurrentPhoneTransaction,\n candidate = yield* preparePhoneMutation(mapping, input);\n\n if (candidate.mutate === undefined) {\n const receipt = prepare(candidate.decision, owner.journal);\n\n owner.guards.push(receipt as any);\n\n return receipt;\n }\n const cn = phoneProofs(mapping.proofs).continuation;\n\n const observed = yield* owner.read(\n cn.table,\n equal(cn.table, {\n [cn.moduleId]: input.completion.input.moduleId,\n [cn.continuationId]: input.completion.input.continuationId,\n }),\n { limit: 1 },\n );\n\n let completed = false;\n\n const plan = {\n ...input.completion,\n prepare: (decision: any, journal: any) => {\n completed = decision === \"completed\";\n const proofReceipt = input.completion.prepare(decision, journal, () => undefined);\n\n owner.guards.push(proofReceipt);\n\n return prepare(\n decision === \"completed\" ? candidate.decision : { _tag: \"Rejected\" },\n journal,\n );\n },\n };\n\n let receipt;\n\n if (owner.batch) {\n const offset = owner.statements.length;\n\n yield* candidate.mutate;\n const statements = owner.statements.splice(offset);\n\n const compiled = yield* compileD1ProofCompletionPlan(\n phoneProofs(mapping.proofs) as any,\n plan as any,\n { statements, appliedCondition: candidate.appliedCondition! },\n (x) => x,\n ).pipe(Effect.provideService(CurrentD1PlanningDatabase, owner.database));\n\n // Mutation observations describe an accepted plan. A stale proof aborts this owner.\n invariant(compiled.statements.length !== 0);\n owner.statements.push(...compiled.statements, ...(compiled.postconditions ?? []));\n receipt = compiled.receipt;\n } else {\n receipt = yield* completeProofPlanIn(\n phoneProofs(mapping.proofs),\n {\n mode: configuration.mode === \"synchronous\" ? \"synchronous\" : \"interactive\",\n locking: configuration.locking,\n standaloneGuard: Effect.void,\n coordinated: true,\n insertIfAbsent: (query: any, key, value) =>\n configuration.dialect === \"mysql\"\n ? query.onDuplicateKeyUpdate({ set: { [key]: value } })\n : query.onConflictDoNothing(),\n },\n plan as any,\n candidate.mutate,\n (x) => x,\n ).pipe(Effect.provideService(CurrentProofSql, owner.database));\n }\n if (completed) {\n invariant(observed.rows.length === 1);\n const record = yield* cn.decode(observed.rows[0]!);\n\n observed.rows = observed.rows.map((row) => ({ ...row, [cn.consumed]: true }));\n const command = phoneProofs(mapping.proofs).command;\n\n owner.postconditions.push(\n sql`${mapping.engineNowMillis} < ${record.expiresAtMillis}`,\n sql`exists(select 1 from ${command.table} where ${equal(command.table, { [command.moduleId]: input.completion.input.moduleId, [command.commandId]: input.completion.input.continuationDigest, [command.kind]: \"complete\", [command.decision]: \"completed\", [command.retentionUntil]: phoneProofs(mapping.proofs).encodeInstant(record.expiresAtMillis) })})`,\n );\n }\n invariant(receipt?._tag === \"PreparedCommit\");\n owner.guards.push(receipt as any);\n\n return receipt as ReturnType<typeof prepare>;\n }),\n );\n }).pipe(Effect.catchDefect(() => Effect.fail(unavailable()))),\n }),\n };\n};\n\nexport const makeTargetPhonePersistence = <\n S extends Table,\n I extends Table,\n F extends Table,\n C extends Table,\n N,\n RSetup = never,\n>(\n database: TransactionNativeDatabase,\n source: PhoneMappingSource<PhoneMapping<S, I, C, F, N>, RSetup>,\n configuration: PhoneTargetConfiguration,\n) =>\n Effect.gen(function* () {\n const hooks = yield* LifecycleHooks;\n const original = yield* Effect.isEffect(source) ? source : Effect.succeed(source);\n\n const mapping = yield* Effect.try({\n try: () => validateMapping(original, configuration),\n catch: () => PhoneConfigurationError.make({}),\n });\n\n const execution = makeTransactionExecution(\n CurrentPhoneTransaction,\n database,\n configuration,\n unavailable,\n randomId,\n );\n\n return services(mapping, execution, hooks, configuration);\n });\n\nexport const coordinateTargetPhone = <M, A, E, R, RSetup = never>(\n database: TransactionNativeDatabase,\n source: PhoneMappingSource<M, RSetup>,\n configuration: PhoneTargetConfiguration,\n body: (\n transaction: any,\n services: PhonePersistenceServices,\n append: (statement: Statement<any>) => void,\n ) => Effect.Effect<A, E, R>,\n): Effect.Effect<A, PhoneCoordinatorError<E>, R | RSetup | LifecycleHooks> =>\n Effect.gen(function* () {\n const hooks = yield* LifecycleHooks;\n const original = yield* Effect.isEffect(source) ? source : Effect.succeed(source);\n\n const mapping = yield* Effect.try({\n try: () => validateMapping(original, configuration),\n catch: () => PhoneConfigurationError.make({}),\n });\n\n return yield* coordinateTransactionOwner(\n database,\n CurrentPhoneTransaction,\n configuration,\n Effect.void,\n unavailable,\n randomId,\n (execution) => services(mapping, execution, hooks, configuration),\n body,\n );\n });\n\ntype TransactionOf<D> = D extends { readonly transaction: (...args: any[]) => any }\n ? Parameters<Parameters<D[\"transaction\"]>[0]>[0]\n : never;\n\n/** Concrete driver wrappers select transaction mode; cryptography always precedes these owners. */\nexport const makePhoneTarget = <\n D extends { readonly transaction: any },\n T extends Table,\n Extra = unknown,\n Synchronous extends boolean = false,\n>(\n configuration: PhoneTargetConfiguration,\n) => {\n function coordinatePhonePersistence<\n Database extends D,\n S extends T,\n I extends T,\n F extends T,\n C extends T,\n N,\n A,\n E,\n R,\n RSetup = never,\n DatabaseError = never,\n DatabaseRequirements = never,\n >(\n acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PhoneMappingSource<PhoneMapping<S, I, C, F, N> & Extra, RSetup>;\n readonly transaction?: never;\n },\n body: Effect.Effect<\n A,\n E,\n Synchronous extends true ? NoInfer<PhonePersistence | PhoneAdmission | PhoneSignInTargets> : R\n >,\n ): Effect.Effect<\n A,\n PhoneCoordinatorError<E> | DatabaseError,\n | (Synchronous extends true\n ? never\n : Exclude<R, PhonePersistence | PhoneAdmission | PhoneSignInTargets>)\n | LifecycleHooks\n | RSetup\n | DatabaseRequirements\n >;\n function coordinatePhonePersistence<\n Database extends D,\n S extends T,\n I extends T,\n F extends T,\n C extends T,\n N,\n A,\n E,\n R,\n TxId,\n TxShape,\n RSetup = never,\n DatabaseError = never,\n DatabaseRequirements = never,\n >(\n acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PhoneMappingSource<PhoneMapping<S, I, C, F, N> & Extra, RSetup>;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<Database>>, TxShape>;\n },\n body: Effect.Effect<\n A,\n E,\n Synchronous extends true\n ? NoInfer<PhonePersistence | PhoneAdmission | PhoneSignInTargets | TxId>\n : R\n >,\n ): Effect.Effect<\n A,\n PhoneCoordinatorError<E> | DatabaseError,\n | (Synchronous extends true\n ? never\n : Exclude<R, PhonePersistence | PhoneAdmission | PhoneSignInTargets | TxId>)\n | LifecycleHooks\n | RSetup\n | DatabaseRequirements\n >;\n function coordinatePhonePersistence<\n Database extends D,\n S extends T,\n I extends T,\n F extends T,\n C extends T,\n N,\n A,\n E,\n R,\n TxId,\n TxShape,\n RSetup = never,\n DatabaseError = never,\n DatabaseRequirements = never,\n >(\n acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PhoneMappingSource<PhoneMapping<S, I, C, F, N> & Extra, RSetup>;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<Database>>, TxShape>;\n },\n body: Effect.Effect<A, E, R>,\n ): Effect.Effect<\n A,\n PhoneCoordinatorError<E> | DatabaseError,\n | Exclude<R, PhonePersistence | PhoneAdmission | PhoneSignInTargets>\n | LifecycleHooks\n | RSetup\n | DatabaseRequirements\n > {\n return Effect.flatMap(acquire, (database) =>\n coordinateTargetPhone(\n database as any,\n options.mapping,\n configuration,\n (transaction: TransactionOf<Database>, services) => {\n const provided = Context.make(PhonePersistence, services.phonePersistence).pipe(\n Context.add(PhoneAdmission, services.phoneAdmission),\n Context.add(PhoneSignInTargets, services.phoneSignInTargets),\n );\n\n const work = Effect.provideContext(body, provided);\n\n return options.transaction === undefined\n ? work\n : Effect.provideService(work, options.transaction, options.transaction.of(transaction));\n },\n ),\n );\n }\n\n return {\n makePhonePersistenceServices: <\n Database extends D,\n S extends T,\n I extends T,\n F extends T,\n C extends T,\n N,\n RSetup = never,\n >(\n database: Database,\n mapping: PhoneMappingSource<PhoneMapping<S, I, C, F, N> & Extra, RSetup>,\n ) => makeTargetPhonePersistence(database as any, mapping, configuration),\n coordinatePhonePersistence,\n };\n};\n"],"mappings":"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"}
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { PersistenceMappingError } from "../internal/mapping-error.mjs";
|
|
2
|
+
import { SubjectIdCodec } from "./model.mjs";
|
|
3
|
+
import { Effect } from "effect";
|
|
4
|
+
import { TokenDigest } from "@yielded/auth/Schema";
|
|
5
|
+
import { ProofBinding, ProofContinuationId, ProofId, ProofPolicy, ProofPurpose, ProofRecord, ProofRequestReceipt, ProofVersion } from "@yielded/auth/Proofs";
|
|
6
|
+
import { InferInsertModel, InferSelectModel, SQL, Table } from "drizzle-orm";
|
|
7
|
+
//#region src/drizzle/proof-model.d.ts
|
|
8
|
+
type ColumnKey<T extends Table> = Extract<keyof T["_"]["columns"], string>;
|
|
9
|
+
type ProofAction = "issue" | "attempt";
|
|
10
|
+
type ProofScopeKind = "action" | "identifier" | "subject";
|
|
11
|
+
type ProofGenerationState = "active" | "consumed" | "cancelled" | "superseded";
|
|
12
|
+
type ProofDeliveryState = "new" | "claimed" | "accepted" | "failed" | "ambiguous";
|
|
13
|
+
type ProofCommandKind = "attempt" | "complete";
|
|
14
|
+
type ProofCommandDecision = "accepted" | "rejected" | "completed";
|
|
15
|
+
interface ProofScopeKeys {
|
|
16
|
+
/** Stable across flow/context/request changes and bounded by the consumer codec. */
|
|
17
|
+
readonly series: string;
|
|
18
|
+
readonly identifier: string;
|
|
19
|
+
/** A tagged non-null value; use a stable sentinel when the binding has no subject. */
|
|
20
|
+
readonly subject: string;
|
|
21
|
+
}
|
|
22
|
+
interface ProofAuthorityInput<NativeSubjectId> {
|
|
23
|
+
readonly moduleId: string;
|
|
24
|
+
readonly purpose: ProofPurpose;
|
|
25
|
+
readonly binding: ProofBinding;
|
|
26
|
+
/** Resolved by Effect preplanning before an interactive check or D1 predicate compile. */
|
|
27
|
+
readonly nativeSubjectId?: NativeSubjectId;
|
|
28
|
+
}
|
|
29
|
+
interface ProofAuthorityTables<Subject extends Table, Identifier extends Table, Credential extends Table, NativeSubjectId> {
|
|
30
|
+
readonly identifier: {
|
|
31
|
+
readonly table: Identifier;
|
|
32
|
+
readonly namespace: ColumnKey<Identifier>;
|
|
33
|
+
readonly value: ColumnKey<Identifier>;
|
|
34
|
+
/** Evaluate the consumer's explicit current-ownership/availability semantics. */
|
|
35
|
+
readonly isCurrent: (input: ProofAuthorityInput<NativeSubjectId>, rows: ReadonlyArray<InferSelectModel<Identifier>>) => boolean;
|
|
36
|
+
/** Optional outside D1. Never infer this semantic predicate from eligibility. */
|
|
37
|
+
readonly d1CurrentCondition?: (input: ProofAuthorityInput<NativeSubjectId>) => SQL;
|
|
38
|
+
};
|
|
39
|
+
readonly subject?: {
|
|
40
|
+
readonly table: Subject;
|
|
41
|
+
readonly id: ColumnKey<Subject>;
|
|
42
|
+
readonly status: ColumnKey<Subject>;
|
|
43
|
+
readonly securityRevision: ColumnKey<Subject>;
|
|
44
|
+
readonly isActiveStatus: (value: unknown) => boolean;
|
|
45
|
+
readonly d1ActiveStatusValue: unknown;
|
|
46
|
+
};
|
|
47
|
+
readonly credential?: {
|
|
48
|
+
readonly table: Credential;
|
|
49
|
+
readonly subjectId: ColumnKey<Credential>;
|
|
50
|
+
readonly credentialId: ColumnKey<Credential>;
|
|
51
|
+
readonly revision: ColumnKey<Credential>;
|
|
52
|
+
readonly status?: ColumnKey<Credential>;
|
|
53
|
+
readonly isActiveStatus?: (value: unknown) => boolean;
|
|
54
|
+
readonly d1ActiveStatusValue?: unknown;
|
|
55
|
+
};
|
|
56
|
+
readonly subjectId?: SubjectIdCodec<NativeSubjectId>;
|
|
57
|
+
}
|
|
58
|
+
interface ProofRequestTable<Request extends Table> {
|
|
59
|
+
readonly table: Request;
|
|
60
|
+
readonly moduleId: ColumnKey<Request>;
|
|
61
|
+
readonly requestId: ColumnKey<Request>;
|
|
62
|
+
readonly fingerprint: ColumnKey<Request>;
|
|
63
|
+
readonly proofId: ColumnKey<Request>;
|
|
64
|
+
readonly purpose: ColumnKey<Request>;
|
|
65
|
+
readonly keyId: ColumnKey<Request>;
|
|
66
|
+
readonly createdAt: ColumnKey<Request>;
|
|
67
|
+
readonly retentionUntil: ColumnKey<Request>;
|
|
68
|
+
readonly encodeInsert: (input: {
|
|
69
|
+
readonly record: ProofRecord;
|
|
70
|
+
readonly createdAtMillis: number;
|
|
71
|
+
readonly retentionUntilMillis: number;
|
|
72
|
+
}) => InferInsertModel<Request>;
|
|
73
|
+
readonly decodeReceipt: (row: InferSelectModel<Request>) => Effect.Effect<ProofRequestReceipt, PersistenceMappingError>;
|
|
74
|
+
}
|
|
75
|
+
interface ProofSeriesTable<Series extends Table> {
|
|
76
|
+
readonly table: Series;
|
|
77
|
+
readonly moduleId: ColumnKey<Series>;
|
|
78
|
+
readonly purpose: ColumnKey<Series>;
|
|
79
|
+
readonly scopeKey: ColumnKey<Series>;
|
|
80
|
+
readonly activeProofId: ColumnKey<Series>;
|
|
81
|
+
readonly lastIssueAt: ColumnKey<Series>;
|
|
82
|
+
readonly version: ColumnKey<Series>;
|
|
83
|
+
readonly encodeInsert: (input: {
|
|
84
|
+
readonly moduleId: string;
|
|
85
|
+
readonly purpose: ProofPurpose;
|
|
86
|
+
readonly scopeKey: string;
|
|
87
|
+
readonly version: ProofVersion;
|
|
88
|
+
}) => InferInsertModel<Series>;
|
|
89
|
+
}
|
|
90
|
+
interface ProofGenerationTable<Generation extends Table> {
|
|
91
|
+
readonly table: Generation;
|
|
92
|
+
readonly moduleId: ColumnKey<Generation>;
|
|
93
|
+
readonly purpose: ColumnKey<Generation>;
|
|
94
|
+
readonly proofId: ColumnKey<Generation>;
|
|
95
|
+
readonly requestId: ColumnKey<Generation>;
|
|
96
|
+
readonly seriesKey: ColumnKey<Generation>;
|
|
97
|
+
readonly deliveryId: ColumnKey<Generation>;
|
|
98
|
+
readonly binding: ColumnKey<Generation>;
|
|
99
|
+
readonly verifierKeyId: ColumnKey<Generation>;
|
|
100
|
+
readonly verifierDigest: ColumnKey<Generation>;
|
|
101
|
+
readonly issuedAt: ColumnKey<Generation>;
|
|
102
|
+
readonly expiresAt: ColumnKey<Generation>;
|
|
103
|
+
readonly version: ColumnKey<Generation>;
|
|
104
|
+
readonly state: ColumnKey<Generation>;
|
|
105
|
+
readonly sendCount: ColumnKey<Generation>;
|
|
106
|
+
readonly deliveryState: ColumnKey<Generation>;
|
|
107
|
+
readonly claimVersion: ColumnKey<Generation>;
|
|
108
|
+
readonly claimDeadline: ColumnKey<Generation>;
|
|
109
|
+
readonly retryAt: ColumnKey<Generation>;
|
|
110
|
+
readonly deliveryRetryMillis: ColumnKey<Generation>;
|
|
111
|
+
readonly retentionUntil: ColumnKey<Generation>;
|
|
112
|
+
readonly encodeInsert: (input: {
|
|
113
|
+
readonly record: ProofRecord;
|
|
114
|
+
readonly seriesKey: string;
|
|
115
|
+
readonly retentionUntilMillis: number;
|
|
116
|
+
readonly state: ProofGenerationState;
|
|
117
|
+
readonly deliveryState: ProofDeliveryState;
|
|
118
|
+
readonly policy: ProofPolicy;
|
|
119
|
+
}) => InferInsertModel<Generation>;
|
|
120
|
+
readonly decodeRecord: (row: InferSelectModel<Generation>) => Effect.Effect<ProofRecord, PersistenceMappingError>;
|
|
121
|
+
readonly decodeBinding: (row: InferSelectModel<Generation>) => Effect.Effect<ProofBinding, PersistenceMappingError>;
|
|
122
|
+
}
|
|
123
|
+
interface ProofContinuationRecord {
|
|
124
|
+
readonly moduleId: string;
|
|
125
|
+
readonly purpose: ProofPurpose;
|
|
126
|
+
readonly continuationId: ProofContinuationId;
|
|
127
|
+
readonly digest: TokenDigest;
|
|
128
|
+
readonly proofId: ProofId;
|
|
129
|
+
readonly seriesKey: string;
|
|
130
|
+
readonly binding: ProofBinding;
|
|
131
|
+
readonly expiresAtMillis: number;
|
|
132
|
+
readonly version: ProofVersion;
|
|
133
|
+
}
|
|
134
|
+
interface ProofContinuationTable<Continuation extends Table> {
|
|
135
|
+
readonly table: Continuation;
|
|
136
|
+
readonly moduleId: ColumnKey<Continuation>;
|
|
137
|
+
readonly purpose: ColumnKey<Continuation>;
|
|
138
|
+
readonly continuationId: ColumnKey<Continuation>;
|
|
139
|
+
readonly digest: ColumnKey<Continuation>;
|
|
140
|
+
readonly proofId: ColumnKey<Continuation>;
|
|
141
|
+
readonly seriesKey: ColumnKey<Continuation>;
|
|
142
|
+
readonly binding: ColumnKey<Continuation>;
|
|
143
|
+
readonly expiresAt: ColumnKey<Continuation>;
|
|
144
|
+
readonly consumed: ColumnKey<Continuation>;
|
|
145
|
+
readonly version: ColumnKey<Continuation>;
|
|
146
|
+
readonly retentionUntil: ColumnKey<Continuation>;
|
|
147
|
+
readonly encodeInsert: (record: ProofContinuationRecord & {
|
|
148
|
+
readonly retentionUntilMillis: number;
|
|
149
|
+
}) => InferInsertModel<Continuation>;
|
|
150
|
+
readonly decode: (row: InferSelectModel<Continuation>) => Effect.Effect<ProofContinuationRecord, PersistenceMappingError>;
|
|
151
|
+
}
|
|
152
|
+
interface ProofRateScopeTable<RateScope extends Table> {
|
|
153
|
+
readonly table: RateScope;
|
|
154
|
+
readonly moduleId: ColumnKey<RateScope>;
|
|
155
|
+
readonly purpose: ColumnKey<RateScope>;
|
|
156
|
+
readonly action: ColumnKey<RateScope>;
|
|
157
|
+
readonly scopeKind: ColumnKey<RateScope>;
|
|
158
|
+
readonly scopeKey: ColumnKey<RateScope>;
|
|
159
|
+
readonly encodeInsert: (input: {
|
|
160
|
+
readonly moduleId: string;
|
|
161
|
+
readonly purpose: ProofPurpose;
|
|
162
|
+
readonly action: ProofAction;
|
|
163
|
+
readonly scopeKind: ProofScopeKind;
|
|
164
|
+
readonly scopeKey: string;
|
|
165
|
+
}) => InferInsertModel<RateScope>;
|
|
166
|
+
}
|
|
167
|
+
interface ProofAbuseEventTable<AbuseEvent extends Table> {
|
|
168
|
+
readonly table: AbuseEvent;
|
|
169
|
+
readonly moduleId: ColumnKey<AbuseEvent>;
|
|
170
|
+
readonly purpose: ColumnKey<AbuseEvent>;
|
|
171
|
+
readonly action: ColumnKey<AbuseEvent>;
|
|
172
|
+
readonly scopeKind: ColumnKey<AbuseEvent>;
|
|
173
|
+
readonly scopeKey: ColumnKey<AbuseEvent>;
|
|
174
|
+
readonly commandId: ColumnKey<AbuseEvent>;
|
|
175
|
+
readonly occurredAt: ColumnKey<AbuseEvent>;
|
|
176
|
+
readonly retentionUntil: ColumnKey<AbuseEvent>;
|
|
177
|
+
readonly encodeInsert: (input: {
|
|
178
|
+
readonly moduleId: string;
|
|
179
|
+
readonly purpose: ProofPurpose;
|
|
180
|
+
readonly action: ProofAction;
|
|
181
|
+
readonly scopeKind: ProofScopeKind;
|
|
182
|
+
readonly scopeKey: string;
|
|
183
|
+
readonly commandId: string;
|
|
184
|
+
readonly occurredAtMillis: number;
|
|
185
|
+
readonly retentionUntilMillis: number;
|
|
186
|
+
}) => InferInsertModel<AbuseEvent>;
|
|
187
|
+
}
|
|
188
|
+
interface ProofFailureEventTable<FailureEvent extends Table> {
|
|
189
|
+
readonly table: FailureEvent;
|
|
190
|
+
readonly moduleId: ColumnKey<FailureEvent>;
|
|
191
|
+
readonly purpose: ColumnKey<FailureEvent>;
|
|
192
|
+
readonly seriesKey: ColumnKey<FailureEvent>;
|
|
193
|
+
readonly commandId: ColumnKey<FailureEvent>;
|
|
194
|
+
readonly occurredAt: ColumnKey<FailureEvent>;
|
|
195
|
+
readonly retentionUntil: ColumnKey<FailureEvent>;
|
|
196
|
+
readonly encodeInsert: (input: {
|
|
197
|
+
readonly moduleId: string;
|
|
198
|
+
readonly purpose: ProofPurpose;
|
|
199
|
+
readonly seriesKey: string;
|
|
200
|
+
readonly commandId: string;
|
|
201
|
+
readonly occurredAtMillis: number;
|
|
202
|
+
readonly retentionUntilMillis: number;
|
|
203
|
+
}) => InferInsertModel<FailureEvent>;
|
|
204
|
+
}
|
|
205
|
+
interface ProofCommandTable<Command extends Table> {
|
|
206
|
+
readonly table: Command;
|
|
207
|
+
readonly moduleId: ColumnKey<Command>;
|
|
208
|
+
readonly commandId: ColumnKey<Command>;
|
|
209
|
+
readonly kind: ColumnKey<Command>;
|
|
210
|
+
readonly decision: ColumnKey<Command>;
|
|
211
|
+
readonly retentionUntil: ColumnKey<Command>;
|
|
212
|
+
readonly encodeInsert: (input: {
|
|
213
|
+
readonly moduleId: string;
|
|
214
|
+
readonly commandId: string;
|
|
215
|
+
readonly kind: ProofCommandKind;
|
|
216
|
+
readonly decision: ProofCommandDecision;
|
|
217
|
+
readonly retentionUntilMillis: number;
|
|
218
|
+
}) => InferInsertModel<Command>;
|
|
219
|
+
}
|
|
220
|
+
interface RequiredProofConstraints {
|
|
221
|
+
readonly request: "unique(request.moduleId,request.requestId)";
|
|
222
|
+
readonly series: "unique(series.moduleId,series.purpose,series.scopeKey)";
|
|
223
|
+
readonly proof: "unique(generation.moduleId,generation.proofId)";
|
|
224
|
+
readonly delivery: "unique(generation.moduleId,generation.deliveryId)";
|
|
225
|
+
readonly continuationId: "unique(continuation.moduleId,continuation.continuationId)";
|
|
226
|
+
readonly continuationDigest: "unique(continuation.moduleId,continuation.digest)";
|
|
227
|
+
readonly rateScope: "unique(rateScope.moduleId,rateScope.purpose,rateScope.action,rateScope.scopeKind,rateScope.scopeKey)";
|
|
228
|
+
readonly abuseEvent: "unique(abuseEvent.moduleId,abuseEvent.action,abuseEvent.scopeKind,abuseEvent.scopeKey,abuseEvent.commandId)";
|
|
229
|
+
readonly failureEvent: "unique(failureEvent.moduleId,failureEvent.seriesKey,failureEvent.commandId)";
|
|
230
|
+
readonly command: "unique(command.moduleId,command.commandId)";
|
|
231
|
+
}
|
|
232
|
+
declare const requiredProofConstraints: RequiredProofConstraints;
|
|
233
|
+
interface ProofConstraintClassifier {
|
|
234
|
+
/** Match only the declared request uniqueness constraint, including wrapped driver errors. */
|
|
235
|
+
readonly isRequestConflict: (cause: unknown) => boolean;
|
|
236
|
+
/** Match only the declared series uniqueness constraint, including wrapped driver errors. */
|
|
237
|
+
readonly isSeriesConflict: (cause: unknown) => boolean;
|
|
238
|
+
/** Match only the declared command uniqueness constraint, including wrapped driver errors. */
|
|
239
|
+
readonly isCommandConflict: (cause: unknown) => boolean;
|
|
240
|
+
}
|
|
241
|
+
interface ProofD1Clock {
|
|
242
|
+
/** Native instant expression evaluated by SQLite inside the submitted batch. */
|
|
243
|
+
readonly engineNow: SQL;
|
|
244
|
+
/** Integer Unix milliseconds expression evaluated inside the submitted batch. */
|
|
245
|
+
readonly engineNowMillis: SQL;
|
|
246
|
+
/** Native instant expression for an engine-time rolling-window cutoff. */
|
|
247
|
+
readonly engineInstantMinus: (millis: number) => SQL;
|
|
248
|
+
/** Native instant expression for a retention/lease deadline from engine time. */
|
|
249
|
+
readonly engineInstantPlus: (millis: number) => SQL;
|
|
250
|
+
}
|
|
251
|
+
interface ProofPersistenceMapping<Request extends Table, Series extends Table, Generation extends Table, Continuation extends Table, RateScope extends Table, AbuseEvent extends Table, FailureEvent extends Table, Command extends Table, Subject extends Table, Identifier extends Table, Credential extends Table, NativeSubjectId> extends ProofConstraintClassifier {
|
|
252
|
+
readonly request: ProofRequestTable<Request>;
|
|
253
|
+
readonly series: ProofSeriesTable<Series>;
|
|
254
|
+
readonly generation: ProofGenerationTable<Generation>;
|
|
255
|
+
readonly continuation: ProofContinuationTable<Continuation>;
|
|
256
|
+
readonly rateScope: ProofRateScopeTable<RateScope>;
|
|
257
|
+
readonly abuseEvent: ProofAbuseEventTable<AbuseEvent>;
|
|
258
|
+
readonly failureEvent: ProofFailureEventTable<FailureEvent>;
|
|
259
|
+
readonly command: ProofCommandTable<Command>;
|
|
260
|
+
readonly authority: ProofAuthorityTables<Subject, Identifier, Credential, NativeSubjectId>;
|
|
261
|
+
readonly constraints: RequiredProofConstraints;
|
|
262
|
+
readonly scopeKeys: (input: {
|
|
263
|
+
readonly moduleId: string;
|
|
264
|
+
readonly purpose: ProofPurpose;
|
|
265
|
+
readonly binding: ProofBinding;
|
|
266
|
+
}) => ProofScopeKeys;
|
|
267
|
+
readonly encodeInstant: (epochMillis: number) => unknown;
|
|
268
|
+
readonly decodeInstant: (native: unknown) => Effect.Effect<number, PersistenceMappingError>;
|
|
269
|
+
readonly allocateVersion?: Effect.Effect<ProofVersion, PersistenceMappingError>;
|
|
270
|
+
readonly allocateVersionSync?: () => ProofVersion;
|
|
271
|
+
/** Required by D1 mappings and ignored by interactive targets. */
|
|
272
|
+
readonly d1?: ProofD1Clock;
|
|
273
|
+
}
|
|
274
|
+
type D1ProofPersistenceMapping<Request extends Table, Series extends Table, Generation extends Table, Continuation extends Table, RateScope extends Table, AbuseEvent extends Table, FailureEvent extends Table, Command extends Table, Subject extends Table, Identifier extends Table, Credential extends Table, NativeSubjectId> = ProofPersistenceMapping<Request, Series, Generation, Continuation, RateScope, AbuseEvent, FailureEvent, Command, Subject, Identifier, Credential, NativeSubjectId> & {
|
|
275
|
+
readonly d1: ProofD1Clock;
|
|
276
|
+
readonly authority: ProofAuthorityTables<Subject, Identifier, Credential, NativeSubjectId> & {
|
|
277
|
+
readonly identifier: ProofAuthorityTables<Subject, Identifier, Credential, NativeSubjectId>["identifier"] & {
|
|
278
|
+
/** Synchronous SQL compiler; Effect-based ID conversion has already completed. */
|
|
279
|
+
readonly d1CurrentCondition: (input: ProofAuthorityInput<NativeSubjectId>) => SQL;
|
|
280
|
+
};
|
|
281
|
+
};
|
|
282
|
+
};
|
|
283
|
+
type AnyProofPersistenceMapping = ProofPersistenceMapping<Table, Table, Table, Table, Table, Table, Table, Table, Table, Table, Table, unknown>;
|
|
284
|
+
//#endregion
|
|
285
|
+
export { AnyProofPersistenceMapping, D1ProofPersistenceMapping, ProofAbuseEventTable, ProofAction, ProofAuthorityInput, ProofAuthorityTables, ProofCommandDecision, ProofCommandKind, ProofCommandTable, ProofConstraintClassifier, ProofContinuationRecord, ProofContinuationTable, ProofD1Clock, ProofDeliveryState, ProofFailureEventTable, ProofGenerationState, ProofGenerationTable, ProofPersistenceMapping, ProofRateScopeTable, ProofRequestTable, ProofScopeKeys, ProofScopeKind, ProofSeriesTable, RequiredProofConstraints, requiredProofConstraints };
|
|
286
|
+
//# sourceMappingURL=proof-model.d.mts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/drizzle/proof-model.ts
|
|
2
|
+
const requiredProofConstraints = {
|
|
3
|
+
request: "unique(request.moduleId,request.requestId)",
|
|
4
|
+
series: "unique(series.moduleId,series.purpose,series.scopeKey)",
|
|
5
|
+
proof: "unique(generation.moduleId,generation.proofId)",
|
|
6
|
+
delivery: "unique(generation.moduleId,generation.deliveryId)",
|
|
7
|
+
continuationId: "unique(continuation.moduleId,continuation.continuationId)",
|
|
8
|
+
continuationDigest: "unique(continuation.moduleId,continuation.digest)",
|
|
9
|
+
rateScope: "unique(rateScope.moduleId,rateScope.purpose,rateScope.action,rateScope.scopeKind,rateScope.scopeKey)",
|
|
10
|
+
abuseEvent: "unique(abuseEvent.moduleId,abuseEvent.action,abuseEvent.scopeKind,abuseEvent.scopeKey,abuseEvent.commandId)",
|
|
11
|
+
failureEvent: "unique(failureEvent.moduleId,failureEvent.seriesKey,failureEvent.commandId)",
|
|
12
|
+
command: "unique(command.moduleId,command.commandId)"
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { requiredProofConstraints };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=proof-model.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proof-model.mjs","names":[],"sources":["../../src/drizzle/proof-model.ts"],"sourcesContent":["import type {\n ProofBinding,\n ProofContinuationId,\n ProofId,\n ProofPurpose,\n ProofRequestReceipt,\n ProofVersion,\n ProofPolicy,\n ProofRecord,\n} from \"@yielded/auth/Proofs\";\nimport type { TokenDigest } from \"@yielded/auth/Schema\";\nimport type { InferInsertModel, InferSelectModel, SQL, Table } from \"drizzle-orm\";\nimport type { Effect } from \"effect\";\n\nimport type { PersistenceMappingError, SubjectIdCodec } from \"./model\";\n\ntype ColumnKey<T extends Table> = Extract<keyof T[\"_\"][\"columns\"], string>;\n\nexport type ProofAction = \"issue\" | \"attempt\";\nexport type ProofScopeKind = \"action\" | \"identifier\" | \"subject\";\nexport type ProofGenerationState = \"active\" | \"consumed\" | \"cancelled\" | \"superseded\";\nexport type ProofDeliveryState = \"new\" | \"claimed\" | \"accepted\" | \"failed\" | \"ambiguous\";\nexport type ProofCommandKind = \"attempt\" | \"complete\";\nexport type ProofCommandDecision = \"accepted\" | \"rejected\" | \"completed\";\n\nexport interface ProofScopeKeys {\n /** Stable across flow/context/request changes and bounded by the consumer codec. */\n readonly series: string;\n readonly identifier: string;\n /** A tagged non-null value; use a stable sentinel when the binding has no subject. */\n readonly subject: string;\n}\n\nexport interface ProofAuthorityInput<NativeSubjectId> {\n readonly moduleId: string;\n readonly purpose: ProofPurpose;\n readonly binding: ProofBinding;\n /** Resolved by Effect preplanning before an interactive check or D1 predicate compile. */\n readonly nativeSubjectId?: NativeSubjectId;\n}\n\nexport interface ProofAuthorityTables<\n Subject extends Table,\n Identifier extends Table,\n Credential extends Table,\n NativeSubjectId,\n> {\n readonly identifier: {\n readonly table: Identifier;\n readonly namespace: ColumnKey<Identifier>;\n readonly value: ColumnKey<Identifier>;\n /** Evaluate the consumer's explicit current-ownership/availability semantics. */\n readonly isCurrent: (\n input: ProofAuthorityInput<NativeSubjectId>,\n rows: ReadonlyArray<InferSelectModel<Identifier>>,\n ) => boolean;\n /** Optional outside D1. Never infer this semantic predicate from eligibility. */\n readonly d1CurrentCondition?: (input: ProofAuthorityInput<NativeSubjectId>) => SQL;\n };\n readonly subject?: {\n readonly table: Subject;\n readonly id: ColumnKey<Subject>;\n readonly status: ColumnKey<Subject>;\n readonly securityRevision: ColumnKey<Subject>;\n readonly isActiveStatus: (value: unknown) => boolean;\n readonly d1ActiveStatusValue: unknown;\n };\n readonly credential?: {\n readonly table: Credential;\n readonly subjectId: ColumnKey<Credential>;\n readonly credentialId: ColumnKey<Credential>;\n readonly revision: ColumnKey<Credential>;\n readonly status?: ColumnKey<Credential>;\n readonly isActiveStatus?: (value: unknown) => boolean;\n readonly d1ActiveStatusValue?: unknown;\n };\n readonly subjectId?: SubjectIdCodec<NativeSubjectId>;\n}\n\nexport interface ProofRequestTable<Request extends Table> {\n readonly table: Request;\n readonly moduleId: ColumnKey<Request>;\n readonly requestId: ColumnKey<Request>;\n readonly fingerprint: ColumnKey<Request>;\n readonly proofId: ColumnKey<Request>;\n readonly purpose: ColumnKey<Request>;\n readonly keyId: ColumnKey<Request>;\n readonly createdAt: ColumnKey<Request>;\n readonly retentionUntil: ColumnKey<Request>;\n readonly encodeInsert: (input: {\n readonly record: ProofRecord;\n readonly createdAtMillis: number;\n readonly retentionUntilMillis: number;\n }) => InferInsertModel<Request>;\n readonly decodeReceipt: (\n row: InferSelectModel<Request>,\n ) => Effect.Effect<ProofRequestReceipt, PersistenceMappingError>;\n}\n\nexport interface ProofSeriesTable<Series extends Table> {\n readonly table: Series;\n readonly moduleId: ColumnKey<Series>;\n readonly purpose: ColumnKey<Series>;\n readonly scopeKey: ColumnKey<Series>;\n readonly activeProofId: ColumnKey<Series>;\n readonly lastIssueAt: ColumnKey<Series>;\n readonly version: ColumnKey<Series>;\n readonly encodeInsert: (input: {\n readonly moduleId: string;\n readonly purpose: ProofPurpose;\n readonly scopeKey: string;\n readonly version: ProofVersion;\n }) => InferInsertModel<Series>;\n}\n\nexport interface ProofGenerationTable<Generation extends Table> {\n readonly table: Generation;\n readonly moduleId: ColumnKey<Generation>;\n readonly purpose: ColumnKey<Generation>;\n readonly proofId: ColumnKey<Generation>;\n readonly requestId: ColumnKey<Generation>;\n readonly seriesKey: ColumnKey<Generation>;\n readonly deliveryId: ColumnKey<Generation>;\n readonly binding: ColumnKey<Generation>;\n readonly verifierKeyId: ColumnKey<Generation>;\n readonly verifierDigest: ColumnKey<Generation>;\n readonly issuedAt: ColumnKey<Generation>;\n readonly expiresAt: ColumnKey<Generation>;\n readonly version: ColumnKey<Generation>;\n readonly state: ColumnKey<Generation>;\n readonly sendCount: ColumnKey<Generation>;\n readonly deliveryState: ColumnKey<Generation>;\n readonly claimVersion: ColumnKey<Generation>;\n readonly claimDeadline: ColumnKey<Generation>;\n readonly retryAt: ColumnKey<Generation>;\n readonly deliveryRetryMillis: ColumnKey<Generation>;\n readonly retentionUntil: ColumnKey<Generation>;\n readonly encodeInsert: (input: {\n readonly record: ProofRecord;\n readonly seriesKey: string;\n readonly retentionUntilMillis: number;\n readonly state: ProofGenerationState;\n readonly deliveryState: ProofDeliveryState;\n readonly policy: ProofPolicy;\n }) => InferInsertModel<Generation>;\n readonly decodeRecord: (\n row: InferSelectModel<Generation>,\n ) => Effect.Effect<ProofRecord, PersistenceMappingError>;\n readonly decodeBinding: (\n row: InferSelectModel<Generation>,\n ) => Effect.Effect<ProofBinding, PersistenceMappingError>;\n}\n\nexport interface ProofContinuationRecord {\n readonly moduleId: string;\n readonly purpose: ProofPurpose;\n readonly continuationId: ProofContinuationId;\n readonly digest: TokenDigest;\n readonly proofId: ProofId;\n readonly seriesKey: string;\n readonly binding: ProofBinding;\n readonly expiresAtMillis: number;\n readonly version: ProofVersion;\n}\n\nexport interface ProofContinuationTable<Continuation extends Table> {\n readonly table: Continuation;\n readonly moduleId: ColumnKey<Continuation>;\n readonly purpose: ColumnKey<Continuation>;\n readonly continuationId: ColumnKey<Continuation>;\n readonly digest: ColumnKey<Continuation>;\n readonly proofId: ColumnKey<Continuation>;\n readonly seriesKey: ColumnKey<Continuation>;\n readonly binding: ColumnKey<Continuation>;\n readonly expiresAt: ColumnKey<Continuation>;\n readonly consumed: ColumnKey<Continuation>;\n readonly version: ColumnKey<Continuation>;\n readonly retentionUntil: ColumnKey<Continuation>;\n readonly encodeInsert: (\n record: ProofContinuationRecord & { readonly retentionUntilMillis: number },\n ) => InferInsertModel<Continuation>;\n readonly decode: (\n row: InferSelectModel<Continuation>,\n ) => Effect.Effect<ProofContinuationRecord, PersistenceMappingError>;\n}\n\nexport interface ProofRateScopeTable<RateScope extends Table> {\n readonly table: RateScope;\n readonly moduleId: ColumnKey<RateScope>;\n readonly purpose: ColumnKey<RateScope>;\n readonly action: ColumnKey<RateScope>;\n readonly scopeKind: ColumnKey<RateScope>;\n readonly scopeKey: ColumnKey<RateScope>;\n readonly encodeInsert: (input: {\n readonly moduleId: string;\n readonly purpose: ProofPurpose;\n readonly action: ProofAction;\n readonly scopeKind: ProofScopeKind;\n readonly scopeKey: string;\n }) => InferInsertModel<RateScope>;\n}\n\nexport interface ProofAbuseEventTable<AbuseEvent extends Table> {\n readonly table: AbuseEvent;\n readonly moduleId: ColumnKey<AbuseEvent>;\n readonly purpose: ColumnKey<AbuseEvent>;\n readonly action: ColumnKey<AbuseEvent>;\n readonly scopeKind: ColumnKey<AbuseEvent>;\n readonly scopeKey: ColumnKey<AbuseEvent>;\n readonly commandId: ColumnKey<AbuseEvent>;\n readonly occurredAt: ColumnKey<AbuseEvent>;\n readonly retentionUntil: ColumnKey<AbuseEvent>;\n readonly encodeInsert: (input: {\n readonly moduleId: string;\n readonly purpose: ProofPurpose;\n readonly action: ProofAction;\n readonly scopeKind: ProofScopeKind;\n readonly scopeKey: string;\n readonly commandId: string;\n readonly occurredAtMillis: number;\n readonly retentionUntilMillis: number;\n }) => InferInsertModel<AbuseEvent>;\n}\n\nexport interface ProofFailureEventTable<FailureEvent extends Table> {\n readonly table: FailureEvent;\n readonly moduleId: ColumnKey<FailureEvent>;\n readonly purpose: ColumnKey<FailureEvent>;\n readonly seriesKey: ColumnKey<FailureEvent>;\n readonly commandId: ColumnKey<FailureEvent>;\n readonly occurredAt: ColumnKey<FailureEvent>;\n readonly retentionUntil: ColumnKey<FailureEvent>;\n readonly encodeInsert: (input: {\n readonly moduleId: string;\n readonly purpose: ProofPurpose;\n readonly seriesKey: string;\n readonly commandId: string;\n readonly occurredAtMillis: number;\n readonly retentionUntilMillis: number;\n }) => InferInsertModel<FailureEvent>;\n}\n\nexport interface ProofCommandTable<Command extends Table> {\n readonly table: Command;\n readonly moduleId: ColumnKey<Command>;\n readonly commandId: ColumnKey<Command>;\n readonly kind: ColumnKey<Command>;\n readonly decision: ColumnKey<Command>;\n readonly retentionUntil: ColumnKey<Command>;\n readonly encodeInsert: (input: {\n readonly moduleId: string;\n readonly commandId: string;\n readonly kind: ProofCommandKind;\n readonly decision: ProofCommandDecision;\n readonly retentionUntilMillis: number;\n }) => InferInsertModel<Command>;\n}\n\nexport interface RequiredProofConstraints {\n readonly request: \"unique(request.moduleId,request.requestId)\";\n readonly series: \"unique(series.moduleId,series.purpose,series.scopeKey)\";\n readonly proof: \"unique(generation.moduleId,generation.proofId)\";\n readonly delivery: \"unique(generation.moduleId,generation.deliveryId)\";\n readonly continuationId: \"unique(continuation.moduleId,continuation.continuationId)\";\n readonly continuationDigest: \"unique(continuation.moduleId,continuation.digest)\";\n readonly rateScope: \"unique(rateScope.moduleId,rateScope.purpose,rateScope.action,rateScope.scopeKind,rateScope.scopeKey)\";\n readonly abuseEvent: \"unique(abuseEvent.moduleId,abuseEvent.action,abuseEvent.scopeKind,abuseEvent.scopeKey,abuseEvent.commandId)\";\n readonly failureEvent: \"unique(failureEvent.moduleId,failureEvent.seriesKey,failureEvent.commandId)\";\n readonly command: \"unique(command.moduleId,command.commandId)\";\n}\n\nexport const requiredProofConstraints: RequiredProofConstraints = {\n request: \"unique(request.moduleId,request.requestId)\",\n series: \"unique(series.moduleId,series.purpose,series.scopeKey)\",\n proof: \"unique(generation.moduleId,generation.proofId)\",\n delivery: \"unique(generation.moduleId,generation.deliveryId)\",\n continuationId: \"unique(continuation.moduleId,continuation.continuationId)\",\n continuationDigest: \"unique(continuation.moduleId,continuation.digest)\",\n rateScope:\n \"unique(rateScope.moduleId,rateScope.purpose,rateScope.action,rateScope.scopeKind,rateScope.scopeKey)\",\n abuseEvent:\n \"unique(abuseEvent.moduleId,abuseEvent.action,abuseEvent.scopeKind,abuseEvent.scopeKey,abuseEvent.commandId)\",\n failureEvent: \"unique(failureEvent.moduleId,failureEvent.seriesKey,failureEvent.commandId)\",\n command: \"unique(command.moduleId,command.commandId)\",\n};\n\nexport interface ProofConstraintClassifier {\n /** Match only the declared request uniqueness constraint, including wrapped driver errors. */\n readonly isRequestConflict: (cause: unknown) => boolean;\n /** Match only the declared series uniqueness constraint, including wrapped driver errors. */\n readonly isSeriesConflict: (cause: unknown) => boolean;\n /** Match only the declared command uniqueness constraint, including wrapped driver errors. */\n readonly isCommandConflict: (cause: unknown) => boolean;\n}\n\nexport interface ProofD1Clock {\n /** Native instant expression evaluated by SQLite inside the submitted batch. */\n readonly engineNow: SQL;\n /** Integer Unix milliseconds expression evaluated inside the submitted batch. */\n readonly engineNowMillis: SQL;\n /** Native instant expression for an engine-time rolling-window cutoff. */\n readonly engineInstantMinus: (millis: number) => SQL;\n /** Native instant expression for a retention/lease deadline from engine time. */\n readonly engineInstantPlus: (millis: number) => SQL;\n}\n\nexport interface ProofPersistenceMapping<\n Request extends Table,\n Series extends Table,\n Generation extends Table,\n Continuation extends Table,\n RateScope extends Table,\n AbuseEvent extends Table,\n FailureEvent extends Table,\n Command extends Table,\n Subject extends Table,\n Identifier extends Table,\n Credential extends Table,\n NativeSubjectId,\n> extends ProofConstraintClassifier {\n readonly request: ProofRequestTable<Request>;\n readonly series: ProofSeriesTable<Series>;\n readonly generation: ProofGenerationTable<Generation>;\n readonly continuation: ProofContinuationTable<Continuation>;\n readonly rateScope: ProofRateScopeTable<RateScope>;\n readonly abuseEvent: ProofAbuseEventTable<AbuseEvent>;\n readonly failureEvent: ProofFailureEventTable<FailureEvent>;\n readonly command: ProofCommandTable<Command>;\n readonly authority: ProofAuthorityTables<Subject, Identifier, Credential, NativeSubjectId>;\n readonly constraints: RequiredProofConstraints;\n readonly scopeKeys: (input: {\n readonly moduleId: string;\n readonly purpose: ProofPurpose;\n readonly binding: ProofBinding;\n }) => ProofScopeKeys;\n readonly encodeInstant: (epochMillis: number) => unknown;\n readonly decodeInstant: (native: unknown) => Effect.Effect<number, PersistenceMappingError>;\n readonly allocateVersion?: Effect.Effect<ProofVersion, PersistenceMappingError>;\n readonly allocateVersionSync?: () => ProofVersion;\n /** Required by D1 mappings and ignored by interactive targets. */\n readonly d1?: ProofD1Clock;\n}\n\nexport type D1ProofPersistenceMapping<\n Request extends Table,\n Series extends Table,\n Generation extends Table,\n Continuation extends Table,\n RateScope extends Table,\n AbuseEvent extends Table,\n FailureEvent extends Table,\n Command extends Table,\n Subject extends Table,\n Identifier extends Table,\n Credential extends Table,\n NativeSubjectId,\n> = ProofPersistenceMapping<\n Request,\n Series,\n Generation,\n Continuation,\n RateScope,\n AbuseEvent,\n FailureEvent,\n Command,\n Subject,\n Identifier,\n Credential,\n NativeSubjectId\n> & {\n readonly d1: ProofD1Clock;\n readonly authority: ProofAuthorityTables<Subject, Identifier, Credential, NativeSubjectId> & {\n readonly identifier: ProofAuthorityTables<\n Subject,\n Identifier,\n Credential,\n NativeSubjectId\n >[\"identifier\"] & {\n /** Synchronous SQL compiler; Effect-based ID conversion has already completed. */\n readonly d1CurrentCondition: (input: ProofAuthorityInput<NativeSubjectId>) => SQL;\n };\n };\n};\n\nexport type AnyProofPersistenceMapping = ProofPersistenceMapping<\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n unknown\n>;\n"],"mappings":";AA+QA,MAAa,2BAAqD;CAChE,SAAS;CACT,QAAQ;CACR,OAAO;CACP,UAAU;CACV,gBAAgB;CAChB,oBAAoB;CACpB,WACE;CACF,YACE;CACF,cAAc;CACd,SAAS;AACX"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CurrentProofSql, makeProofKernel } from "../internal/proof-kernel.mjs";
|
|
2
|
+
import { drizzleQueryOperations } from "./query-operations.mjs";
|
|
3
|
+
//#region src/drizzle/proof-sql.ts
|
|
4
|
+
const { makeSqlProofPersistence, checkProofCompletionIn, completeProofPlanIn } = makeProofKernel(drizzleQueryOperations);
|
|
5
|
+
//#endregion
|
|
6
|
+
export { CurrentProofSql, checkProofCompletionIn, completeProofPlanIn, makeSqlProofPersistence };
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=proof-sql.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proof-sql.mjs","names":[],"sources":["../../src/drizzle/proof-sql.ts"],"sourcesContent":["import { makeProofKernel } from \"../internal/proof-kernel\";\nimport { drizzleQueryOperations } from \"./query-operations\";\nexport type { ProofSqlQuery } from \"../internal/proof-kernel\";\nexport type { ProofSqlDatabase } from \"../internal/proof-kernel\";\nexport { CurrentProofSql } from \"../internal/proof-kernel\";\nexport type { ProofSqlConfiguration } from \"../internal/proof-kernel\";\n\nexport const { makeSqlProofPersistence, checkProofCompletionIn, completeProofPlanIn } =\n makeProofKernel(drizzleQueryOperations);\n"],"mappings":";;;AAOA,MAAa,EAAE,yBAAyB,wBAAwB,wBAC9D,gBAAgB,sBAAsB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import "./proof-sql.mjs";
|
|
2
|
+
import { Effect, Layer } from "effect";
|
|
3
|
+
import { HookConfigurationError, LifecycleHooks } from "@yielded/auth/Hooks";
|
|
4
|
+
import { ProofPersistence, ProofUnavailable } from "@yielded/auth/Proofs";
|
|
5
|
+
import "effect/unstable/sql/SqlError";
|
|
6
|
+
//#region src/drizzle/proof-target.d.ts
|
|
7
|
+
declare const proofPersistenceLayer: (services: Effect.Effect<{
|
|
8
|
+
readonly proofPersistence: ProofPersistence["Service"];
|
|
9
|
+
}, never, LifecycleHooks>) => Layer.Layer<ProofPersistence, never, LifecycleHooks>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { proofPersistenceLayer };
|
|
12
|
+
//# sourceMappingURL=proof-target.d.mts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { sqlClientStandaloneGuard } from "./standalone-guard.mjs";
|
|
2
|
+
import { makeSqlProofPersistence } from "./proof-sql.mjs";
|
|
3
|
+
import { Effect, Layer } from "effect";
|
|
4
|
+
import { LifecycleHooks, coordinateCommit, hasCommitScope } from "@yielded/auth/Hooks";
|
|
5
|
+
import { ProofPersistence, ProofUnavailable } from "@yielded/auth/Proofs";
|
|
6
|
+
//#region src/drizzle/proof-target.ts
|
|
7
|
+
const sqlClientProofStandaloneGuard = (database) => sqlClientStandaloneGuard(database, () => ProofUnavailable.make({}));
|
|
8
|
+
const options = (configuration, coordinated = false) => ({
|
|
9
|
+
mode: configuration.mode,
|
|
10
|
+
locking: configuration.locking,
|
|
11
|
+
standaloneGuard: !coordinated ? configuration.standaloneGuard : Effect.void,
|
|
12
|
+
insertIfAbsent: configuration.insertIfAbsent,
|
|
13
|
+
coordinated
|
|
14
|
+
});
|
|
15
|
+
const makeTargetProofPersistenceServices = (database, mapping, configuration) => Effect.gen(function* () {
|
|
16
|
+
return { proofPersistence: yield* makeSqlProofPersistence(database, mapping, options(configuration)) };
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* The native transaction is the root commit owner. Interruption or owner failure
|
|
20
|
+
* rolls it back and discards the journal. No owner effect is retried. Native
|
|
21
|
+
* transaction-acquisition `SqlError`s are exposed; caller errors, including
|
|
22
|
+
* Drizzle query wrappers, propagate unchanged.
|
|
23
|
+
*/
|
|
24
|
+
const coordinateTargetProofPersistence = (database, mapping, configuration, owner) => Effect.gen(function* () {
|
|
25
|
+
const hooks = yield* LifecycleHooks;
|
|
26
|
+
if (yield* hasCommitScope) return yield* ProofUnavailable.make({});
|
|
27
|
+
yield* configuration.coordinatorGuard ?? configuration.standaloneGuard;
|
|
28
|
+
return (yield* coordinateCommit(() => database.transaction((transaction) => Effect.gen(function* () {
|
|
29
|
+
return yield* owner(transaction, { proofPersistence: yield* makeSqlProofPersistence(transaction, mapping, options(configuration, true)) });
|
|
30
|
+
})), { mode: configuration.mode }).pipe(Effect.provideService(LifecycleHooks, hooks))).value;
|
|
31
|
+
});
|
|
32
|
+
const proofPersistenceLayer = (services) => Layer.effect(ProofPersistence, Effect.map(services, (value) => value.proofPersistence));
|
|
33
|
+
//#endregion
|
|
34
|
+
export { coordinateTargetProofPersistence, makeTargetProofPersistenceServices, proofPersistenceLayer, sqlClientProofStandaloneGuard };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=proof-target.mjs.map
|