@yielded/auth-persistence 0.1.0-beta.25 → 0.1.0-beta.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -8
- package/dist/Adapter.d.mts +47 -33
- package/dist/Adapter.mjs +36 -23
- package/dist/OAuthPersistence.d.mts +35 -51
- package/dist/OAuthPersistence.mjs +60 -68
- package/dist/OAuthPersistence.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/internal/browser-login.d.mts +1 -1
- package/dist/internal/browser-login.mjs +29 -9
- package/dist/internal/browser-login.mjs.map +1 -1
- package/dist/internal/configuration.d.mts +13 -8
- package/dist/internal/configuration.mjs.map +1 -1
- package/dist/internal/crypto.d.mts +1 -0
- package/dist/internal/crypto.mjs +1 -1
- package/dist/internal/d1-planning.mjs +8 -0
- package/dist/internal/d1-planning.mjs.map +1 -0
- package/dist/internal/email-native-state.mjs +135 -0
- package/dist/internal/email-native-state.mjs.map +1 -0
- package/dist/internal/email-native.d.mts +17 -0
- package/dist/internal/email-native.mjs +245 -0
- package/dist/internal/email-native.mjs.map +1 -0
- package/dist/internal/email-policy.mjs +92 -0
- package/dist/internal/email-policy.mjs.map +1 -0
- package/dist/internal/email-registration-native.d.mts +38 -0
- package/dist/internal/email-registration-native.mjs +171 -0
- package/dist/internal/email-registration-native.mjs.map +1 -0
- package/dist/internal/models/email-model.d.mts +40 -104
- package/dist/internal/models/email-model.mjs +3 -5
- package/dist/internal/models/email-model.mjs.map +1 -1
- package/dist/internal/models/oauth-connected-model.d.mts +44 -213
- package/dist/internal/models/oauth-connected-model.mjs +6 -14
- package/dist/internal/models/oauth-connected-model.mjs.map +1 -1
- package/dist/internal/models/oauth-model.d.mts +95 -244
- package/dist/internal/models/oauth-model.mjs +28 -22
- package/dist/internal/models/oauth-model.mjs.map +1 -1
- package/dist/internal/models/passkey-model.d.mts +11 -147
- package/dist/internal/models/passkey-model.mjs +5 -24
- package/dist/internal/models/passkey-model.mjs.map +1 -1
- package/dist/internal/models/passkey-registration-ceremony-model.d.mts +5 -39
- package/dist/internal/models/passkey-write-model.d.mts +17 -75
- package/dist/internal/models/passkey-write-model.mjs +1 -7
- package/dist/internal/models/passkey-write-model.mjs.map +1 -1
- package/dist/internal/models/password-model.d.mts +14 -81
- package/dist/internal/models/password-model.mjs +1 -4
- package/dist/internal/models/password-model.mjs.map +1 -1
- package/dist/internal/models/phone-model.d.mts +86 -0
- package/dist/internal/models/phone-model.mjs +10 -0
- package/dist/internal/models/phone-model.mjs.map +1 -0
- package/dist/internal/models/proof-model.d.mts +43 -272
- package/dist/internal/models/proof-model.mjs +2 -10
- package/dist/internal/models/proof-model.mjs.map +1 -1
- package/dist/internal/models/session-model.d.mts +74 -93
- package/dist/internal/models/session-model.mjs +3 -11
- package/dist/internal/models/session-model.mjs.map +1 -1
- package/dist/internal/models/step-up-model.d.mts +12 -50
- package/dist/internal/models/step-up-model.mjs +2 -4
- package/dist/internal/models/step-up-model.mjs.map +1 -1
- package/dist/internal/models/totp-model.d.mts +76 -0
- package/dist/internal/models/totp-model.mjs +10 -0
- package/dist/internal/models/totp-model.mjs.map +1 -0
- package/dist/internal/native-sql-table.d.mts +21 -4
- package/dist/internal/native-sql-table.mjs +9 -5
- package/dist/internal/native-sql-table.mjs.map +1 -1
- package/dist/internal/oauth/native-accounts.d.mts +17 -0
- package/dist/internal/oauth/native-accounts.mjs +290 -0
- package/dist/internal/oauth/native-accounts.mjs.map +1 -0
- package/dist/internal/oauth/native-connected-state.d.mts +11 -0
- package/dist/internal/oauth/native-connected-state.mjs +146 -0
- package/dist/internal/oauth/native-connected-state.mjs.map +1 -0
- package/dist/internal/oauth/native-connected.d.mts +15 -0
- package/dist/internal/oauth/native-connected.mjs +462 -0
- package/dist/internal/oauth/native-connected.mjs.map +1 -0
- package/dist/internal/oauth/native-flow.mjs +138 -0
- package/dist/internal/oauth/native-flow.mjs.map +1 -0
- package/dist/internal/oauth/native-layers.d.mts +24 -0
- package/dist/internal/oauth/native-layers.mjs +13 -0
- package/dist/internal/oauth/native-layers.mjs.map +1 -0
- package/dist/internal/oauth/native-mutation.mjs +122 -0
- package/dist/internal/oauth/native-mutation.mjs.map +1 -0
- package/dist/internal/oauth/native-registration.d.mts +24 -0
- package/dist/internal/oauth/native-registration.mjs +328 -0
- package/dist/internal/oauth/native-registration.mjs.map +1 -0
- package/dist/internal/oauth/native-revocations.d.mts +17 -0
- package/dist/internal/oauth/native-revocations.mjs +106 -0
- package/dist/internal/oauth/native-revocations.mjs.map +1 -0
- package/dist/internal/oauth/native-sign-in.d.mts +17 -0
- package/dist/internal/oauth/native-sign-in.mjs +50 -0
- package/dist/internal/oauth/native-sign-in.mjs.map +1 -0
- package/dist/internal/oauth/native-state.d.mts +10 -0
- package/dist/internal/oauth/native-state.mjs +214 -0
- package/dist/internal/oauth/native-state.mjs.map +1 -0
- package/dist/internal/oauth/state.d.mts +10 -0
- package/dist/internal/oauth/state.mjs +3 -27
- package/dist/internal/oauth/state.mjs.map +1 -1
- package/dist/internal/passkey-actions.mjs +55 -0
- package/dist/internal/passkey-actions.mjs.map +1 -0
- package/dist/internal/passkey-inputs.mjs +73 -0
- package/dist/internal/passkey-inputs.mjs.map +1 -0
- package/dist/internal/passkey-managed.mjs +224 -0
- package/dist/internal/passkey-managed.mjs.map +1 -0
- package/dist/internal/passkey-native-ceremony.d.mts +35 -0
- package/dist/internal/passkey-native-ceremony.mjs +38 -0
- package/dist/internal/passkey-native-ceremony.mjs.map +1 -0
- package/dist/internal/passkey-native-flow.mjs +91 -0
- package/dist/internal/passkey-native-flow.mjs.map +1 -0
- package/dist/internal/passkey-native-registration.d.mts +10 -0
- package/dist/internal/passkey-native-registration.mjs +114 -0
- package/dist/internal/passkey-native-registration.mjs.map +1 -0
- package/dist/internal/passkey-native-state.d.mts +15 -0
- package/dist/internal/passkey-native-state.mjs +186 -0
- package/dist/internal/passkey-native-state.mjs.map +1 -0
- package/dist/internal/passkey-native-write.d.mts +82 -0
- package/dist/internal/passkey-native-write.mjs +330 -0
- package/dist/internal/passkey-native-write.mjs.map +1 -0
- package/dist/internal/passkey-native.d.mts +835 -0
- package/dist/internal/passkey-native.mjs +175 -0
- package/dist/internal/passkey-native.mjs.map +1 -0
- package/dist/internal/passkey-policy.mjs +115 -0
- package/dist/internal/passkey-policy.mjs.map +1 -0
- package/dist/internal/password-credentials.mjs +38 -9
- package/dist/internal/password-credentials.mjs.map +1 -1
- package/dist/internal/password-native.d.mts +14 -0
- package/dist/internal/password-native.mjs +292 -0
- package/dist/internal/password-native.mjs.map +1 -0
- package/dist/internal/password-policy.mjs +93 -0
- package/dist/internal/password-policy.mjs.map +1 -0
- package/dist/internal/password-registration-native.d.mts +22 -0
- package/dist/internal/password-registration-native.mjs +142 -0
- package/dist/internal/password-registration-native.mjs.map +1 -0
- package/dist/internal/persistence.d.mts +6 -19
- package/dist/internal/persistence.mjs +199 -166
- package/dist/internal/persistence.mjs.map +1 -1
- package/dist/internal/phone-composed.mjs +79 -0
- package/dist/internal/phone-composed.mjs.map +1 -0
- package/dist/internal/phone-native.d.mts +15 -0
- package/dist/internal/phone-native.mjs +354 -0
- package/dist/internal/phone-native.mjs.map +1 -0
- package/dist/internal/proof-native.d.mts +15 -0
- package/dist/internal/proof-native.mjs +289 -0
- package/dist/internal/proof-native.mjs.map +1 -0
- package/dist/internal/registration.mjs +50 -60
- package/dist/internal/registration.mjs.map +1 -1
- package/dist/internal/session-native-authority.d.mts +15 -0
- package/dist/internal/session-native-authority.mjs +91 -0
- package/dist/internal/session-native-authority.mjs.map +1 -0
- package/dist/internal/session-native-cleanup.d.mts +14 -0
- package/dist/internal/session-native-cleanup.mjs +48 -0
- package/dist/internal/session-native-cleanup.mjs.map +1 -0
- package/dist/internal/session-native-login.d.mts +15 -0
- package/dist/internal/session-native-login.mjs +87 -0
- package/dist/internal/session-native-login.mjs.map +1 -0
- package/dist/internal/session-native-pending-read.mjs +42 -0
- package/dist/internal/session-native-pending-read.mjs.map +1 -0
- package/dist/internal/session-native-pending.mjs +134 -0
- package/dist/internal/session-native-pending.mjs.map +1 -0
- package/dist/internal/session-native-record.mjs +79 -0
- package/dist/internal/session-native-record.mjs.map +1 -0
- package/dist/internal/session-native-state.mjs +130 -0
- package/dist/internal/session-native-state.mjs.map +1 -0
- package/dist/internal/session-native-stateful.d.mts +16 -0
- package/dist/internal/session-native-stateful.mjs +225 -0
- package/dist/internal/session-native-stateful.mjs.map +1 -0
- package/dist/internal/session-native-step-up.d.mts +15 -0
- package/dist/internal/session-native-step-up.mjs +212 -0
- package/dist/internal/session-native-step-up.mjs.map +1 -0
- package/dist/internal/session-native-validity.d.mts +15 -0
- package/dist/internal/session-native-validity.mjs +97 -0
- package/dist/internal/session-native-validity.mjs.map +1 -0
- package/dist/internal/session-policy.mjs +29 -0
- package/dist/internal/session-policy.mjs.map +1 -0
- package/dist/internal/sql-authority.d.mts +16 -0
- package/dist/internal/sql-authority.mjs +32 -0
- package/dist/internal/sql-authority.mjs.map +1 -0
- package/dist/internal/sql-change.mjs +21 -0
- package/dist/internal/sql-change.mjs.map +1 -0
- package/dist/internal/sql-cleanup.mjs +35 -0
- package/dist/internal/sql-cleanup.mjs.map +1 -0
- package/dist/internal/sql-commit.d.mts +72 -0
- package/dist/internal/sql-commit.mjs +176 -0
- package/dist/internal/sql-commit.mjs.map +1 -0
- package/dist/internal/sql-expression.d.mts +17 -0
- package/dist/internal/sql-expression.mjs +49 -0
- package/dist/internal/sql-expression.mjs.map +1 -0
- package/dist/internal/sql-oauth-connected-model.d.mts +7 -23
- package/dist/internal/sql-oauth-model.d.mts +27 -52
- package/dist/internal/sql-oauth-model.mjs +3 -4
- package/dist/internal/sql-oauth-model.mjs.map +1 -1
- package/dist/internal/sql-persistence.mjs +5 -9
- package/dist/internal/sql-persistence.mjs.map +1 -1
- package/dist/internal/sql-storage-validation.mjs +1 -2
- package/dist/internal/sql-storage-validation.mjs.map +1 -1
- package/dist/internal/sql-table.d.mts +3 -16
- package/dist/internal/sql-table.mjs +21 -42
- package/dist/internal/sql-table.mjs.map +1 -1
- package/dist/internal/standalone.mjs +2 -3
- package/dist/internal/standalone.mjs.map +1 -1
- package/dist/internal/step-up-state.mjs +5 -8
- package/dist/internal/step-up-state.mjs.map +1 -1
- package/dist/internal/storage-clock.mjs +44 -0
- package/dist/internal/storage-clock.mjs.map +1 -0
- package/dist/internal/storage-mapping.d.mts +11 -8
- package/dist/internal/storage-mapping.mjs +88 -302
- package/dist/internal/storage-mapping.mjs.map +1 -1
- package/dist/internal/storage-plans.mjs +15 -73
- package/dist/internal/storage-plans.mjs.map +1 -1
- package/dist/internal/storage-tables.d.mts +37 -520
- package/dist/internal/storage-tables.mjs +31 -211
- package/dist/internal/storage-tables.mjs.map +1 -1
- package/dist/internal/storage-validation.d.mts +1 -6
- package/dist/internal/storage-validation.mjs +1 -42
- package/dist/internal/storage-validation.mjs.map +1 -1
- package/dist/internal/table-model.d.mts +21 -0
- package/dist/internal/totp-native.d.mts +15 -0
- package/dist/internal/totp-native.mjs +401 -0
- package/dist/internal/totp-native.mjs.map +1 -0
- package/package.json +1 -1
- package/src/Adapter.ts +143 -199
- package/src/OAuthPersistence.ts +128 -271
- package/src/index.ts +1 -1
- package/src/internal/browser-login.ts +54 -24
- package/src/internal/configuration.ts +16 -31
- package/src/internal/d1-planning.ts +7 -0
- package/src/internal/email-native-state.ts +247 -0
- package/src/internal/email-native.ts +514 -0
- package/src/internal/email-policy.ts +235 -0
- package/src/internal/email-registration-native.ts +386 -0
- package/src/internal/models/email-model.ts +76 -214
- package/src/internal/models/oauth-connected-model.ts +50 -288
- package/src/internal/models/oauth-model.ts +147 -368
- package/src/internal/models/passkey-model.ts +11 -208
- package/src/internal/models/passkey-registration-ceremony-model.ts +6 -60
- package/src/internal/models/passkey-write-model.ts +14 -95
- package/src/internal/models/password-model.ts +26 -147
- package/src/internal/models/phone-model.ts +110 -0
- package/src/internal/models/proof-model.ts +48 -404
- package/src/internal/models/session-model.ts +102 -200
- package/src/internal/models/step-up-model.ts +17 -96
- package/src/internal/models/totp-model.ts +82 -0
- package/src/internal/native-sql-table.ts +32 -11
- package/src/internal/oauth/native-accounts.ts +576 -0
- package/src/internal/oauth/native-connected-state.ts +288 -0
- package/src/internal/oauth/native-connected.ts +888 -0
- package/src/internal/oauth/native-flow.ts +253 -0
- package/src/internal/oauth/native-layers.ts +83 -0
- package/src/internal/oauth/native-mutation.ts +222 -0
- package/src/internal/oauth/native-registration.ts +545 -0
- package/src/internal/oauth/native-revocations.ts +190 -0
- package/src/internal/oauth/native-sign-in.ts +111 -0
- package/src/internal/oauth/native-state.ts +346 -0
- package/src/internal/oauth/state.ts +2 -70
- package/src/internal/passkey-actions.ts +70 -0
- package/src/internal/passkey-inputs.ts +56 -0
- package/src/internal/passkey-managed.ts +360 -0
- package/src/internal/passkey-native-ceremony.ts +66 -0
- package/src/internal/passkey-native-flow.ts +140 -0
- package/src/internal/passkey-native-registration.ts +221 -0
- package/src/internal/passkey-native-state.ts +335 -0
- package/src/internal/passkey-native-write.ts +611 -0
- package/src/internal/passkey-native.ts +372 -0
- package/src/internal/passkey-policy.ts +246 -0
- package/src/internal/password-credentials.ts +52 -10
- package/src/internal/password-native.ts +571 -0
- package/src/internal/password-policy.ts +307 -0
- package/src/internal/password-registration-native.ts +322 -0
- package/src/internal/persistence.ts +336 -290
- package/src/internal/phone-composed.ts +86 -0
- package/src/internal/phone-native.ts +659 -0
- package/src/internal/proof-native.ts +448 -0
- package/src/internal/registration.ts +96 -143
- package/src/internal/session-native-authority.ts +247 -0
- package/src/internal/session-native-cleanup.ts +65 -0
- package/src/internal/session-native-login.ts +205 -0
- package/src/internal/session-native-pending-read.ts +68 -0
- package/src/internal/session-native-pending.ts +223 -0
- package/src/internal/session-native-record.ts +141 -0
- package/src/internal/session-native-state.ts +259 -0
- package/src/internal/session-native-stateful.ts +512 -0
- package/src/internal/session-native-step-up.ts +450 -0
- package/src/internal/session-native-validity.ts +208 -0
- package/src/internal/session-policy.ts +59 -0
- package/src/internal/sql-authority.ts +56 -0
- package/src/internal/sql-change.ts +38 -0
- package/src/internal/sql-cleanup.ts +56 -0
- package/src/internal/sql-commit.ts +435 -0
- package/src/internal/sql-expression.ts +94 -0
- package/src/internal/sql-metadata.ts +100 -0
- package/src/internal/sql-oauth-connected-model.ts +6 -95
- package/src/internal/sql-oauth-model.ts +31 -134
- package/src/internal/sql-persistence.ts +2 -6
- package/src/internal/sql-storage-validation.ts +1 -2
- package/src/internal/sql-table.ts +19 -52
- package/src/internal/standalone.ts +2 -11
- package/src/internal/step-up-state.ts +4 -17
- package/src/internal/storage-clock.ts +58 -0
- package/src/internal/storage-mapping.ts +125 -340
- package/src/internal/storage-plans.ts +14 -80
- package/src/internal/storage-tables.ts +28 -212
- package/src/internal/storage-validation.ts +0 -58
- package/src/internal/table-model.ts +24 -0
- package/src/internal/totp-native.ts +701 -0
- package/dist/internal/PasswordPreparedPostconditions.d.mts +0 -22
- package/dist/internal/PasswordPreparedPostconditions.mjs +0 -12
- package/dist/internal/PasswordPreparedPostconditions.mjs.map +0 -1
- package/dist/internal/authority-snapshot.mjs +0 -53
- package/dist/internal/authority-snapshot.mjs.map +0 -1
- package/dist/internal/email-kernel.d.mts +0 -276
- package/dist/internal/email-kernel.mjs +0 -497
- package/dist/internal/email-kernel.mjs.map +0 -1
- package/dist/internal/models/passkey-registration-ceremony-model.mjs +0 -18
- package/dist/internal/models/passkey-registration-ceremony-model.mjs.map +0 -1
- package/dist/internal/oauth/accounts.d.mts +0 -8
- package/dist/internal/oauth/accounts.mjs +0 -379
- package/dist/internal/oauth/accounts.mjs.map +0 -1
- package/dist/internal/oauth/connected-access.d.mts +0 -9
- package/dist/internal/oauth/connected-access.mjs +0 -229
- package/dist/internal/oauth/connected-access.mjs.map +0 -1
- package/dist/internal/oauth/connected-collection.d.mts +0 -7
- package/dist/internal/oauth/connected-collection.mjs +0 -214
- package/dist/internal/oauth/connected-collection.mjs.map +0 -1
- package/dist/internal/oauth/connected-custody.d.mts +0 -6
- package/dist/internal/oauth/connected-custody.mjs +0 -165
- package/dist/internal/oauth/connected-custody.mjs.map +0 -1
- package/dist/internal/oauth/connected-flow.d.mts +0 -7
- package/dist/internal/oauth/connected-flow.mjs +0 -324
- package/dist/internal/oauth/connected-flow.mjs.map +0 -1
- package/dist/internal/oauth/connected-input.mjs +0 -122
- package/dist/internal/oauth/connected-input.mjs.map +0 -1
- package/dist/internal/oauth/connected-keys.d.mts +0 -2
- package/dist/internal/oauth/connected-keys.mjs +0 -22
- package/dist/internal/oauth/connected-keys.mjs.map +0 -1
- package/dist/internal/oauth/connected-maintenance.d.mts +0 -9
- package/dist/internal/oauth/connected-maintenance.mjs +0 -226
- package/dist/internal/oauth/connected-maintenance.mjs.map +0 -1
- package/dist/internal/oauth/connected-management.d.mts +0 -9
- package/dist/internal/oauth/connected-management.mjs +0 -243
- package/dist/internal/oauth/connected-management.mjs.map +0 -1
- package/dist/internal/oauth/connected-reference.mjs +0 -63
- package/dist/internal/oauth/connected-reference.mjs.map +0 -1
- package/dist/internal/oauth/connected-settlement.d.mts +0 -8
- package/dist/internal/oauth/connected-settlement.mjs +0 -141
- package/dist/internal/oauth/connected-settlement.mjs.map +0 -1
- package/dist/internal/oauth/connected-sign-in.d.mts +0 -10
- package/dist/internal/oauth/connected-sign-in.mjs +0 -281
- package/dist/internal/oauth/connected-sign-in.mjs.map +0 -1
- package/dist/internal/oauth/connected-state.d.mts +0 -14
- package/dist/internal/oauth/connected-state.mjs +0 -469
- package/dist/internal/oauth/connected-state.mjs.map +0 -1
- package/dist/internal/oauth/connected-target.d.mts +0 -21
- package/dist/internal/oauth/connected-target.mjs +0 -117
- package/dist/internal/oauth/connected-target.mjs.map +0 -1
- package/dist/internal/oauth/flow.d.mts +0 -5
- package/dist/internal/oauth/flow.mjs +0 -279
- package/dist/internal/oauth/flow.mjs.map +0 -1
- package/dist/internal/oauth/input.mjs +0 -127
- package/dist/internal/oauth/input.mjs.map +0 -1
- package/dist/internal/oauth/owner.d.mts +0 -10
- package/dist/internal/oauth/owner.mjs +0 -10
- package/dist/internal/oauth/owner.mjs.map +0 -1
- package/dist/internal/oauth/query-compiler.d.mts +0 -7
- package/dist/internal/oauth/query-compiler.mjs +0 -9
- package/dist/internal/oauth/query-compiler.mjs.map +0 -1
- package/dist/internal/oauth/registration.d.mts +0 -7
- package/dist/internal/oauth/registration.mjs +0 -393
- package/dist/internal/oauth/registration.mjs.map +0 -1
- package/dist/internal/oauth/target.d.mts +0 -31
- package/dist/internal/oauth/target.mjs +0 -273
- package/dist/internal/oauth/target.mjs.map +0 -1
- package/dist/internal/oauth-kernel.d.mts +0 -1423
- package/dist/internal/oauth-kernel.mjs +0 -187
- package/dist/internal/oauth-kernel.mjs.map +0 -1
- package/dist/internal/passkey/admission.d.mts +0 -6
- package/dist/internal/passkey/admission.mjs +0 -220
- package/dist/internal/passkey/admission.mjs.map +0 -1
- package/dist/internal/passkey/credentials.d.mts +0 -14
- package/dist/internal/passkey/credentials.mjs +0 -249
- package/dist/internal/passkey/credentials.mjs.map +0 -1
- package/dist/internal/passkey/enrollment.mjs +0 -138
- package/dist/internal/passkey/enrollment.mjs.map +0 -1
- package/dist/internal/passkey/flow.d.mts +0 -21
- package/dist/internal/passkey/flow.mjs +0 -452
- package/dist/internal/passkey/flow.mjs.map +0 -1
- package/dist/internal/passkey/management.mjs +0 -231
- package/dist/internal/passkey/management.mjs.map +0 -1
- package/dist/internal/passkey/registration-ceremony.d.mts +0 -9
- package/dist/internal/passkey/registration-ceremony.mjs +0 -129
- package/dist/internal/passkey/registration-ceremony.mjs.map +0 -1
- package/dist/internal/passkey/registration-custody.d.mts +0 -2
- package/dist/internal/passkey/registration-custody.mjs +0 -52
- package/dist/internal/passkey/registration-custody.mjs.map +0 -1
- package/dist/internal/passkey/registration-write.mjs +0 -211
- package/dist/internal/passkey/registration-write.mjs.map +0 -1
- package/dist/internal/passkey/state.d.mts +0 -10
- package/dist/internal/passkey/state.mjs +0 -234
- package/dist/internal/passkey/state.mjs.map +0 -1
- package/dist/internal/passkey/target.d.mts +0 -20
- package/dist/internal/passkey/target.mjs +0 -200
- package/dist/internal/passkey/target.mjs.map +0 -1
- package/dist/internal/passkey/write-state.d.mts +0 -17
- package/dist/internal/passkey/write-state.mjs +0 -354
- package/dist/internal/passkey/write-state.mjs.map +0 -1
- package/dist/internal/passkey/write-target.mjs +0 -192
- package/dist/internal/passkey/write-target.mjs.map +0 -1
- package/dist/internal/passkey-kernel.d.mts +0 -6045
- package/dist/internal/passkey-kernel.mjs +0 -49
- package/dist/internal/passkey-kernel.mjs.map +0 -1
- package/dist/internal/passkeys.d.mts +0 -7
- package/dist/internal/passkeys.mjs +0 -387
- package/dist/internal/passkeys.mjs.map +0 -1
- package/dist/internal/password-credentials.d.mts +0 -11
- package/dist/internal/password-kernel.d.mts +0 -278
- package/dist/internal/password-kernel.mjs +0 -508
- package/dist/internal/password-kernel.mjs.map +0 -1
- package/dist/internal/phone-kernel.d.mts +0 -162
- package/dist/internal/phone-kernel.mjs +0 -437
- package/dist/internal/phone-kernel.mjs.map +0 -1
- package/dist/internal/proof-kernel.d.mts +0 -94
- package/dist/internal/proof-kernel.mjs +0 -624
- package/dist/internal/proof-kernel.mjs.map +0 -1
- package/dist/internal/query-operations.d.mts +0 -68
- package/dist/internal/session-kernel.d.mts +0 -62
- package/dist/internal/session-kernel.mjs +0 -820
- package/dist/internal/session-kernel.mjs.map +0 -1
- package/dist/internal/sql-oauth-connected-model.mjs +0 -7
- package/dist/internal/sql-oauth-connected-model.mjs.map +0 -1
- package/dist/internal/sql-query.d.mts +0 -12
- package/dist/internal/sql-query.mjs +0 -206
- package/dist/internal/sql-query.mjs.map +0 -1
- package/dist/internal/step-up-state.d.mts +0 -49
- package/dist/internal/transaction-execution-kernel.d.mts +0 -37
- package/dist/internal/transaction-execution-kernel.mjs +0 -120
- package/dist/internal/transaction-execution-kernel.mjs.map +0 -1
- package/dist/internal/transaction-kernel.d.mts +0 -81
- package/dist/internal/transaction-kernel.mjs +0 -264
- package/dist/internal/transaction-kernel.mjs.map +0 -1
- package/src/internal/PasswordPreparedPostconditions.ts +0 -30
- package/src/internal/authority-snapshot.ts +0 -91
- package/src/internal/email-kernel.ts +0 -1556
- package/src/internal/oauth/accounts.ts +0 -839
- package/src/internal/oauth/connected-access.ts +0 -388
- package/src/internal/oauth/connected-collection.ts +0 -345
- package/src/internal/oauth/connected-custody.ts +0 -308
- package/src/internal/oauth/connected-flow.ts +0 -562
- package/src/internal/oauth/connected-input.ts +0 -147
- package/src/internal/oauth/connected-keys.ts +0 -31
- package/src/internal/oauth/connected-maintenance.ts +0 -379
- package/src/internal/oauth/connected-management.ts +0 -391
- package/src/internal/oauth/connected-reference.ts +0 -135
- package/src/internal/oauth/connected-settlement.ts +0 -278
- package/src/internal/oauth/connected-sign-in.ts +0 -472
- package/src/internal/oauth/connected-state.ts +0 -924
- package/src/internal/oauth/connected-target.ts +0 -307
- package/src/internal/oauth/flow.ts +0 -505
- package/src/internal/oauth/input.ts +0 -201
- package/src/internal/oauth/owner.ts +0 -22
- package/src/internal/oauth/query-compiler.ts +0 -15
- package/src/internal/oauth/registration.ts +0 -676
- package/src/internal/oauth/target.ts +0 -803
- package/src/internal/oauth-kernel.ts +0 -294
- package/src/internal/passkey/admission.ts +0 -368
- package/src/internal/passkey/credentials.ts +0 -511
- package/src/internal/passkey/enrollment.ts +0 -326
- package/src/internal/passkey/flow.ts +0 -1062
- package/src/internal/passkey/management.ts +0 -426
- package/src/internal/passkey/registration-ceremony.ts +0 -283
- package/src/internal/passkey/registration-custody.ts +0 -91
- package/src/internal/passkey/registration-write.ts +0 -426
- package/src/internal/passkey/state.ts +0 -351
- package/src/internal/passkey/target.ts +0 -598
- package/src/internal/passkey/write-state.ts +0 -692
- package/src/internal/passkey/write-target.ts +0 -450
- package/src/internal/passkey-kernel.ts +0 -112
- package/src/internal/passkeys.ts +0 -652
- package/src/internal/password-kernel.ts +0 -1523
- package/src/internal/phone-kernel.ts +0 -872
- package/src/internal/proof-kernel.ts +0 -1992
- package/src/internal/query-operations.ts +0 -91
- package/src/internal/session-kernel.ts +0 -2406
- package/src/internal/sql-query.ts +0 -304
- package/src/internal/transaction-execution-kernel.ts +0 -335
- package/src/internal/transaction-kernel.ts +0 -603
|
@@ -1,624 +0,0 @@
|
|
|
1
|
-
import { PersistenceMappingError } from "./mapping-error.mjs";
|
|
2
|
-
import { requiredProofConstraints } from "./models/proof-model.mjs";
|
|
3
|
-
import { CurrentPasswordPreparedTransaction, PasswordPreparedPostconditions } from "./PasswordPreparedPostconditions.mjs";
|
|
4
|
-
import { Cause, Context, DateTime, Effect, Option, Schema } from "effect";
|
|
5
|
-
import { CurrentCommitJournal, HookConfigurationError, LifecycleHooks, coordinateCommit, hasCommitScope } from "@yielded/auth/Hooks";
|
|
6
|
-
import { reportPersistenceFailure } from "@yielded/auth/Persistence";
|
|
7
|
-
import { ProofBinding, ProofPersistence, ProofRequestConflict, ProofUnavailable } from "@yielded/auth/Proofs";
|
|
8
|
-
//#region src/internal/proof-kernel.ts
|
|
9
|
-
var CurrentProofSql = class extends Context.Service()("effect-auth/CurrentProofSql") {};
|
|
10
|
-
const makeProofKernel = (operations) => {
|
|
11
|
-
const { and, eq, gte, inArray, isNull, lte, notExists, sql, column, updateValues } = operations;
|
|
12
|
-
const unavailable = () => ProofUnavailable.make({});
|
|
13
|
-
const translateFailure = (effect) => reportPersistenceFailure(effect, (error) => Schema.is(ProofUnavailable)(error) || Schema.is(HookConfigurationError)(error)).pipe(Effect.catchCause((cause) => Effect.failCause(Cause.map(cause, () => unavailable()))));
|
|
14
|
-
const translateIssueFailure = (effect) => reportPersistenceFailure(effect, (error) => Schema.is(ProofUnavailable)(error) || Schema.is(ProofRequestConflict)(error) || Schema.is(HookConfigurationError)(error)).pipe(Effect.catchCause((cause) => Effect.failCause(Cause.map(cause, (error) => Schema.is(ProofRequestConflict)(error) ? error : unavailable()))));
|
|
15
|
-
const conflict = () => ProofRequestConflict.make({});
|
|
16
|
-
const validConstraints = (mapping) => Object.entries(requiredProofConstraints).every(([key, value]) => mapping.constraints[key] === value);
|
|
17
|
-
const selectRows = (query, locking) => locking && typeof query.for === "function" ? query.for("update") : query;
|
|
18
|
-
const allocateVersion = (mapping, mode) => {
|
|
19
|
-
if (mode === "synchronous") return mapping.allocateVersionSync === void 0 ? Effect.fail(unavailable()) : Effect.try({
|
|
20
|
-
try: mapping.allocateVersionSync,
|
|
21
|
-
catch: (cause) => new PersistenceMappingError({
|
|
22
|
-
operation: "mapping",
|
|
23
|
-
cause
|
|
24
|
-
})
|
|
25
|
-
});
|
|
26
|
-
if (mapping.allocateVersion !== void 0) return mapping.allocateVersion;
|
|
27
|
-
return mapping.allocateVersionSync === void 0 ? Effect.fail(unavailable()) : Effect.try({
|
|
28
|
-
try: mapping.allocateVersionSync,
|
|
29
|
-
catch: (cause) => new PersistenceMappingError({
|
|
30
|
-
operation: "mapping",
|
|
31
|
-
cause
|
|
32
|
-
})
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
const canonicalBinding = Schema.encodeSync(Schema.fromJsonString(ProofBinding));
|
|
36
|
-
const sameBinding = (left, right) => canonicalBinding(left) === canonicalBinding(right);
|
|
37
|
-
const requestColumns = (mapping) => ({
|
|
38
|
-
moduleId: column(mapping.request.table, mapping.request.moduleId),
|
|
39
|
-
requestId: column(mapping.request.table, mapping.request.requestId),
|
|
40
|
-
fingerprint: column(mapping.request.table, mapping.request.fingerprint),
|
|
41
|
-
proofId: column(mapping.request.table, mapping.request.proofId),
|
|
42
|
-
retentionUntil: column(mapping.request.table, mapping.request.retentionUntil)
|
|
43
|
-
});
|
|
44
|
-
const seriesColumns = (mapping) => ({
|
|
45
|
-
moduleId: column(mapping.series.table, mapping.series.moduleId),
|
|
46
|
-
purpose: column(mapping.series.table, mapping.series.purpose),
|
|
47
|
-
scopeKey: column(mapping.series.table, mapping.series.scopeKey),
|
|
48
|
-
activeProofId: column(mapping.series.table, mapping.series.activeProofId),
|
|
49
|
-
lastIssueAt: column(mapping.series.table, mapping.series.lastIssueAt),
|
|
50
|
-
version: column(mapping.series.table, mapping.series.version)
|
|
51
|
-
});
|
|
52
|
-
const generationColumns = (mapping) => ({
|
|
53
|
-
moduleId: column(mapping.generation.table, mapping.generation.moduleId),
|
|
54
|
-
purpose: column(mapping.generation.table, mapping.generation.purpose),
|
|
55
|
-
proofId: column(mapping.generation.table, mapping.generation.proofId),
|
|
56
|
-
requestId: column(mapping.generation.table, mapping.generation.requestId),
|
|
57
|
-
seriesKey: column(mapping.generation.table, mapping.generation.seriesKey),
|
|
58
|
-
deliveryId: column(mapping.generation.table, mapping.generation.deliveryId),
|
|
59
|
-
verifierKeyId: column(mapping.generation.table, mapping.generation.verifierKeyId),
|
|
60
|
-
verifierDigest: column(mapping.generation.table, mapping.generation.verifierDigest),
|
|
61
|
-
issuedAt: column(mapping.generation.table, mapping.generation.issuedAt),
|
|
62
|
-
expiresAt: column(mapping.generation.table, mapping.generation.expiresAt),
|
|
63
|
-
version: column(mapping.generation.table, mapping.generation.version),
|
|
64
|
-
state: column(mapping.generation.table, mapping.generation.state),
|
|
65
|
-
sendCount: column(mapping.generation.table, mapping.generation.sendCount),
|
|
66
|
-
deliveryState: column(mapping.generation.table, mapping.generation.deliveryState),
|
|
67
|
-
claimVersion: column(mapping.generation.table, mapping.generation.claimVersion),
|
|
68
|
-
claimDeadline: column(mapping.generation.table, mapping.generation.claimDeadline),
|
|
69
|
-
retryAt: column(mapping.generation.table, mapping.generation.retryAt),
|
|
70
|
-
deliveryRetryMillis: column(mapping.generation.table, mapping.generation.deliveryRetryMillis),
|
|
71
|
-
retentionUntil: column(mapping.generation.table, mapping.generation.retentionUntil)
|
|
72
|
-
});
|
|
73
|
-
const continuationColumns = (mapping) => ({
|
|
74
|
-
moduleId: column(mapping.continuation.table, mapping.continuation.moduleId),
|
|
75
|
-
purpose: column(mapping.continuation.table, mapping.continuation.purpose),
|
|
76
|
-
continuationId: column(mapping.continuation.table, mapping.continuation.continuationId),
|
|
77
|
-
digest: column(mapping.continuation.table, mapping.continuation.digest),
|
|
78
|
-
proofId: column(mapping.continuation.table, mapping.continuation.proofId),
|
|
79
|
-
seriesKey: column(mapping.continuation.table, mapping.continuation.seriesKey),
|
|
80
|
-
expiresAt: column(mapping.continuation.table, mapping.continuation.expiresAt),
|
|
81
|
-
consumed: column(mapping.continuation.table, mapping.continuation.consumed),
|
|
82
|
-
version: column(mapping.continuation.table, mapping.continuation.version),
|
|
83
|
-
retentionUntil: column(mapping.continuation.table, mapping.continuation.retentionUntil)
|
|
84
|
-
});
|
|
85
|
-
const scopeColumns = (mapping) => ({
|
|
86
|
-
moduleId: column(mapping.rateScope.table, mapping.rateScope.moduleId),
|
|
87
|
-
purpose: column(mapping.rateScope.table, mapping.rateScope.purpose),
|
|
88
|
-
action: column(mapping.rateScope.table, mapping.rateScope.action),
|
|
89
|
-
scopeKind: column(mapping.rateScope.table, mapping.rateScope.scopeKind),
|
|
90
|
-
scopeKey: column(mapping.rateScope.table, mapping.rateScope.scopeKey)
|
|
91
|
-
});
|
|
92
|
-
const abuseColumns = (mapping) => ({
|
|
93
|
-
moduleId: column(mapping.abuseEvent.table, mapping.abuseEvent.moduleId),
|
|
94
|
-
purpose: column(mapping.abuseEvent.table, mapping.abuseEvent.purpose),
|
|
95
|
-
action: column(mapping.abuseEvent.table, mapping.abuseEvent.action),
|
|
96
|
-
scopeKind: column(mapping.abuseEvent.table, mapping.abuseEvent.scopeKind),
|
|
97
|
-
scopeKey: column(mapping.abuseEvent.table, mapping.abuseEvent.scopeKey),
|
|
98
|
-
commandId: column(mapping.abuseEvent.table, mapping.abuseEvent.commandId),
|
|
99
|
-
occurredAt: column(mapping.abuseEvent.table, mapping.abuseEvent.occurredAt),
|
|
100
|
-
retentionUntil: column(mapping.abuseEvent.table, mapping.abuseEvent.retentionUntil)
|
|
101
|
-
});
|
|
102
|
-
const failureColumns = (mapping) => ({
|
|
103
|
-
moduleId: column(mapping.failureEvent.table, mapping.failureEvent.moduleId),
|
|
104
|
-
purpose: column(mapping.failureEvent.table, mapping.failureEvent.purpose),
|
|
105
|
-
seriesKey: column(mapping.failureEvent.table, mapping.failureEvent.seriesKey),
|
|
106
|
-
commandId: column(mapping.failureEvent.table, mapping.failureEvent.commandId),
|
|
107
|
-
occurredAt: column(mapping.failureEvent.table, mapping.failureEvent.occurredAt),
|
|
108
|
-
retentionUntil: column(mapping.failureEvent.table, mapping.failureEvent.retentionUntil)
|
|
109
|
-
});
|
|
110
|
-
const commandColumns = (mapping) => ({
|
|
111
|
-
moduleId: column(mapping.command.table, mapping.command.moduleId),
|
|
112
|
-
commandId: column(mapping.command.table, mapping.command.commandId),
|
|
113
|
-
kind: column(mapping.command.table, mapping.command.kind),
|
|
114
|
-
decision: column(mapping.command.table, mapping.command.decision),
|
|
115
|
-
retentionUntil: column(mapping.command.table, mapping.command.retentionUntil)
|
|
116
|
-
});
|
|
117
|
-
const nowMillis = DateTime.now.pipe(Effect.map(DateTime.toEpochMillis));
|
|
118
|
-
const lockAuthority = Effect.fn("DrizzleProof.lockAuthority")(function* (mapping, moduleId, purpose, binding, locking) {
|
|
119
|
-
const database = yield* CurrentProofSql;
|
|
120
|
-
const authority = mapping.authority;
|
|
121
|
-
let nativeSubjectId;
|
|
122
|
-
if (binding._tag !== "Identifier") {
|
|
123
|
-
if (authority.subject === void 0 || authority.credential === void 0 || authority.subjectId === void 0) return yield* unavailable();
|
|
124
|
-
nativeSubjectId = yield* authority.subjectId.toNative(binding.revision.subjectId);
|
|
125
|
-
const subject = authority.subject;
|
|
126
|
-
const row = (yield* selectRows(database.select().from(subject.table).where(eq(column(subject.table, subject.id), nativeSubjectId)).limit(1), locking))[0];
|
|
127
|
-
if (row === void 0 || !subject.isActiveStatus(row[subject.status]) || row[subject.securityRevision] !== binding.revision.securityRevision) return false;
|
|
128
|
-
}
|
|
129
|
-
const identifier = authority.identifier;
|
|
130
|
-
const identifierRows = yield* selectRows(database.select().from(identifier.table).where(and(eq(column(identifier.table, identifier.namespace), binding.identifier.namespace), eq(column(identifier.table, identifier.value), binding.identifier.value))), locking);
|
|
131
|
-
if (!identifier.isCurrent({
|
|
132
|
-
moduleId,
|
|
133
|
-
purpose,
|
|
134
|
-
binding,
|
|
135
|
-
...nativeSubjectId === void 0 ? {} : { nativeSubjectId }
|
|
136
|
-
}, identifierRows)) return false;
|
|
137
|
-
if (binding._tag === "Identifier") return true;
|
|
138
|
-
const credential = authority.credential;
|
|
139
|
-
const expected = [...binding.revision.credentials].sort((a, b) => a.credentialId.localeCompare(b.credentialId));
|
|
140
|
-
const rows = expected.length === 0 ? [] : yield* selectRows(database.select().from(credential.table).where(and(eq(column(credential.table, credential.subjectId), nativeSubjectId), inArray(column(credential.table, credential.credentialId), expected.map((item) => item.credentialId)))), locking);
|
|
141
|
-
if (rows.length !== expected.length) return false;
|
|
142
|
-
return rows.map((row) => ({
|
|
143
|
-
credentialId: row[credential.credentialId],
|
|
144
|
-
revision: row[credential.revision],
|
|
145
|
-
active: credential.status === void 0 || credential.isActiveStatus?.(row[credential.status]) === true
|
|
146
|
-
})).sort((a, b) => a.credentialId.localeCompare(b.credentialId)).every((item, index) => item.active && item.credentialId === expected[index]?.credentialId && item.revision === expected[index]?.revision);
|
|
147
|
-
});
|
|
148
|
-
const scopeEntries = (keys, binding, action, policy) => {
|
|
149
|
-
const suffix = action === "issue" ? "Issues" : "Attempts";
|
|
150
|
-
const simple = action === "issue" ? "issues" : "attempts";
|
|
151
|
-
const entries = [{
|
|
152
|
-
kind: "action",
|
|
153
|
-
key: "*",
|
|
154
|
-
budget: policy.abuse[`action${suffix}`]
|
|
155
|
-
}, {
|
|
156
|
-
kind: "identifier",
|
|
157
|
-
key: keys.identifier,
|
|
158
|
-
budget: policy.abuse[simple]
|
|
159
|
-
}];
|
|
160
|
-
if (binding._tag !== "Identifier") entries.push({
|
|
161
|
-
kind: "subject",
|
|
162
|
-
key: keys.subject,
|
|
163
|
-
budget: policy.abuse[`subject${suffix}`]
|
|
164
|
-
});
|
|
165
|
-
return entries;
|
|
166
|
-
};
|
|
167
|
-
const lockScopes = Effect.fn("DrizzleProof.lockScopes")(function* (mapping, configuration, moduleId, purpose, action, entries) {
|
|
168
|
-
const database = yield* CurrentProofSql;
|
|
169
|
-
const c = scopeColumns(mapping);
|
|
170
|
-
for (const entry of entries) {
|
|
171
|
-
const values = mapping.rateScope.encodeInsert({
|
|
172
|
-
moduleId,
|
|
173
|
-
purpose,
|
|
174
|
-
action,
|
|
175
|
-
scopeKind: entry.kind,
|
|
176
|
-
scopeKey: entry.key
|
|
177
|
-
});
|
|
178
|
-
const query = database.insert(mapping.rateScope.table).values(values);
|
|
179
|
-
yield* configuration.insertIfAbsent(query, mapping.rateScope.scopeKey, entry.key);
|
|
180
|
-
yield* selectRows(database.select().from(mapping.rateScope.table).where(and(eq(c.moduleId, moduleId), eq(c.purpose, purpose), eq(c.action, action), eq(c.scopeKind, entry.kind), eq(c.scopeKey, entry.key))).limit(1), configuration.locking);
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
const admittedScopes = Effect.fn("DrizzleProof.admittedScopes")(function* (mapping, moduleId, purpose, action, entries, now) {
|
|
184
|
-
const database = yield* CurrentProofSql;
|
|
185
|
-
const c = abuseColumns(mapping);
|
|
186
|
-
const admitted = [];
|
|
187
|
-
for (const entry of entries) if ((yield* selectRows(database.select({ commandId: c.commandId }).from(mapping.abuseEvent.table).where(and(eq(c.moduleId, moduleId), eq(c.purpose, purpose), eq(c.action, action), eq(c.scopeKind, entry.kind), eq(c.scopeKey, entry.key), gte(c.occurredAt, mapping.encodeInstant(now - entry.budget.windowMillis)))).limit(entry.budget.limit), true)).length < entry.budget.limit) admitted.push(entry);
|
|
188
|
-
return admitted;
|
|
189
|
-
});
|
|
190
|
-
const insertScopeEvents = Effect.fn("Drizzle.insertScopeEvents")(function* (mapping, moduleId, purpose, action, commandId, entries, now, retentionUntil) {
|
|
191
|
-
const database = yield* CurrentProofSql;
|
|
192
|
-
return yield* Effect.forEach(entries, (entry) => database.insert(mapping.abuseEvent.table).values(mapping.abuseEvent.encodeInsert({
|
|
193
|
-
moduleId,
|
|
194
|
-
purpose,
|
|
195
|
-
action,
|
|
196
|
-
scopeKind: entry.kind,
|
|
197
|
-
scopeKey: entry.key,
|
|
198
|
-
commandId,
|
|
199
|
-
occurredAtMillis: now,
|
|
200
|
-
retentionUntilMillis: retentionUntil
|
|
201
|
-
})), { discard: true });
|
|
202
|
-
});
|
|
203
|
-
const ensureSeries = Effect.fn("DrizzleProof.ensureSeries")(function* (mapping, configuration, moduleId, purpose, scopeKey) {
|
|
204
|
-
const database = yield* CurrentProofSql;
|
|
205
|
-
const c = seriesColumns(mapping);
|
|
206
|
-
const initialVersion = yield* allocateVersion(mapping, configuration.mode);
|
|
207
|
-
const query = database.insert(mapping.series.table).values(mapping.series.encodeInsert({
|
|
208
|
-
moduleId,
|
|
209
|
-
purpose,
|
|
210
|
-
scopeKey,
|
|
211
|
-
version: initialVersion
|
|
212
|
-
}));
|
|
213
|
-
yield* configuration.insertIfAbsent(query, mapping.series.scopeKey, scopeKey);
|
|
214
|
-
return (yield* selectRows(database.select().from(mapping.series.table).where(and(eq(c.moduleId, moduleId), eq(c.purpose, purpose), eq(c.scopeKey, scopeKey))).limit(1), configuration.locking))[0] ?? (yield* unavailable());
|
|
215
|
-
});
|
|
216
|
-
const readGeneration = Effect.fn("Drizzle.readGeneration")(function* (mapping, moduleId, proofId, locking) {
|
|
217
|
-
const database = yield* CurrentProofSql;
|
|
218
|
-
const c = generationColumns(mapping);
|
|
219
|
-
return yield* selectRows(database.select().from(mapping.generation.table).where(and(eq(c.moduleId, moduleId), eq(c.proofId, proofId))).limit(1), locking);
|
|
220
|
-
});
|
|
221
|
-
const failureCount = Effect.fn("DrizzleProof.failureCount")(function* (mapping, moduleId, purpose, seriesKey, now, policy) {
|
|
222
|
-
const database = yield* CurrentProofSql;
|
|
223
|
-
const c = failureColumns(mapping);
|
|
224
|
-
return (yield* selectRows(database.select({ commandId: c.commandId }).from(mapping.failureEvent.table).where(and(eq(c.moduleId, moduleId), eq(c.purpose, purpose), eq(c.seriesKey, seriesKey), gte(c.occurredAt, mapping.encodeInstant(now - policy.abuse.attempts.windowMillis)))).limit(policy.maximumFailedAttempts), true)).length;
|
|
225
|
-
});
|
|
226
|
-
const commandRow = Effect.fn("Drizzle.commandRow")(function* (mapping, moduleId, commandId, locking) {
|
|
227
|
-
const database = yield* CurrentProofSql;
|
|
228
|
-
const c = commandColumns(mapping);
|
|
229
|
-
return yield* selectRows(database.select().from(mapping.command.table).where(and(eq(c.moduleId, moduleId), eq(c.commandId, commandId))).limit(1), locking);
|
|
230
|
-
});
|
|
231
|
-
const insertCommand = Effect.fn("Drizzle.insertCommand")(function* (mapping, moduleId, commandId, kind, decision, retentionUntil) {
|
|
232
|
-
return yield* (yield* CurrentProofSql).insert(mapping.command.table).values(mapping.command.encodeInsert({
|
|
233
|
-
moduleId,
|
|
234
|
-
commandId,
|
|
235
|
-
kind,
|
|
236
|
-
decision,
|
|
237
|
-
retentionUntilMillis: retentionUntil
|
|
238
|
-
}));
|
|
239
|
-
});
|
|
240
|
-
const owned = (database, mapping, configuration, body) => {
|
|
241
|
-
if (!validConstraints(mapping)) return Effect.fail(unavailable());
|
|
242
|
-
const run = coordinateCommit(() => database.transaction((transaction) => body.pipe(Effect.provideService(CurrentProofSql, transaction))), { mode: configuration.mode }).pipe(Effect.map((result) => result.value));
|
|
243
|
-
return configuration.coordinated !== true ? Effect.gen(function* () {
|
|
244
|
-
if (yield* hasCommitScope) return yield* unavailable();
|
|
245
|
-
yield* configuration.standaloneGuard;
|
|
246
|
-
return yield* run;
|
|
247
|
-
}) : run;
|
|
248
|
-
};
|
|
249
|
-
const makeSqlProofPersistence = Effect.fn("makeSqlProofPersistence")(function* (mapping, configuration) {
|
|
250
|
-
const database = yield* CurrentProofSql;
|
|
251
|
-
if (!configuration.coordinated) yield* (operations.validateStorage?.(mapping) ?? Effect.void).pipe(Effect.mapError(unavailable));
|
|
252
|
-
const hooks = yield* LifecycleHooks;
|
|
253
|
-
return ProofPersistence.of({
|
|
254
|
-
issue: (input, prepare) => owned(database, mapping, configuration, Effect.gen(function* () {
|
|
255
|
-
const transaction = yield* CurrentProofSql;
|
|
256
|
-
const journal = yield* CurrentCommitJournal;
|
|
257
|
-
const keys = mapping.scopeKeys({
|
|
258
|
-
moduleId: input.record.moduleId,
|
|
259
|
-
purpose: input.record.purpose,
|
|
260
|
-
binding: input.record.binding
|
|
261
|
-
});
|
|
262
|
-
const authorityCurrent = yield* lockAuthority(mapping, input.record.moduleId, input.record.purpose, input.record.binding, configuration.locking);
|
|
263
|
-
const scopes = scopeEntries(keys, input.record.binding, "issue", input.policy);
|
|
264
|
-
yield* lockScopes(mapping, configuration, input.record.moduleId, input.record.purpose, "issue", scopes.slice(0, 1));
|
|
265
|
-
const actionNow = yield* nowMillis;
|
|
266
|
-
const actionOpen = (yield* admittedScopes(mapping, input.record.moduleId, input.record.purpose, "issue", scopes.slice(0, 1), actionNow)).length === 1;
|
|
267
|
-
if (actionOpen) yield* lockScopes(mapping, configuration, input.record.moduleId, input.record.purpose, "issue", scopes.slice(1));
|
|
268
|
-
const series = actionOpen ? yield* ensureSeries(mapping, configuration, input.record.moduleId, input.record.purpose, keys.series) : void 0;
|
|
269
|
-
const now = yield* nowMillis;
|
|
270
|
-
const retentionUntil = now + input.policy.requestRetentionMillis;
|
|
271
|
-
const rc = requestColumns(mapping);
|
|
272
|
-
let requestRows = yield* selectRows(transaction.select().from(mapping.request.table).where(and(eq(rc.moduleId, input.record.moduleId), eq(rc.requestId, input.record.requestId))).limit(1), configuration.locking);
|
|
273
|
-
let request = requestRows[0];
|
|
274
|
-
if (request !== void 0) {
|
|
275
|
-
if ((yield* mapping.decodeInstant(request[mapping.request.retentionUntil])) > now) {
|
|
276
|
-
if (request[mapping.request.fingerprint] !== input.record.fingerprint) return yield* conflict();
|
|
277
|
-
return prepare({
|
|
278
|
-
_tag: "Existing",
|
|
279
|
-
receipt: yield* mapping.request.decodeReceipt(request)
|
|
280
|
-
}, journal);
|
|
281
|
-
}
|
|
282
|
-
yield* transaction.delete(mapping.request.table).where(and(eq(rc.moduleId, input.record.moduleId), eq(rc.requestId, input.record.requestId), lte(rc.retentionUntil, mapping.encodeInstant(now))));
|
|
283
|
-
}
|
|
284
|
-
const requestInsert = mapping.request.encodeInsert({
|
|
285
|
-
record: input.record,
|
|
286
|
-
createdAtMillis: now,
|
|
287
|
-
retentionUntilMillis: retentionUntil
|
|
288
|
-
});
|
|
289
|
-
const requestQuery = transaction.insert(mapping.request.table).values(requestInsert);
|
|
290
|
-
yield* configuration.insertIfAbsent(requestQuery, mapping.request.requestId, input.record.requestId);
|
|
291
|
-
requestRows = yield* selectRows(transaction.select().from(mapping.request.table).where(and(eq(rc.moduleId, input.record.moduleId), eq(rc.requestId, input.record.requestId))).limit(1), configuration.locking);
|
|
292
|
-
request = requestRows[0];
|
|
293
|
-
if (request === void 0) return yield* unavailable();
|
|
294
|
-
if (request[mapping.request.fingerprint] !== input.record.fingerprint) return yield* conflict();
|
|
295
|
-
if (request[mapping.request.proofId] !== input.record.proofId) return prepare({
|
|
296
|
-
_tag: "Existing",
|
|
297
|
-
receipt: yield* mapping.request.decodeReceipt(request)
|
|
298
|
-
}, journal);
|
|
299
|
-
const admitted = actionOpen ? yield* admittedScopes(mapping, input.record.moduleId, input.record.purpose, "issue", scopes, now) : [];
|
|
300
|
-
const sc = seriesColumns(mapping);
|
|
301
|
-
const lastIssueAt = series?.[mapping.series.lastIssueAt] === null || series?.[mapping.series.lastIssueAt] === void 0 ? void 0 : yield* mapping.decodeInstant(series[mapping.series.lastIssueAt]);
|
|
302
|
-
const activeProofId = series?.[mapping.series.activeProofId];
|
|
303
|
-
const activeGeneration = activeProofId === null || activeProofId === void 0 ? void 0 : (yield* readGeneration(mapping, input.record.moduleId, activeProofId, configuration.locking))[0];
|
|
304
|
-
if (activeProofId !== null && activeProofId !== void 0 && (activeGeneration === void 0 || activeGeneration[mapping.generation.purpose] !== input.record.purpose)) return yield* unavailable();
|
|
305
|
-
const replacementAuthorized = activeGeneration === void 0 || activeGeneration[mapping.generation.state] !== "active" || (yield* mapping.decodeInstant(activeGeneration[mapping.generation.expiresAt])) <= now || sameBinding(yield* mapping.generation.decodeBinding(activeGeneration), input.record.binding);
|
|
306
|
-
const supersedesCurrent = input.supersedes === void 0 || input.supersedes === activeProofId;
|
|
307
|
-
const allowed = authorityCurrent && input.eligible && admitted.length === scopes.length && input.record.issuedAtMillis <= now && input.record.expiresAtMillis > now && replacementAuthorized && supersedesCurrent && (lastIssueAt === void 0 || now - lastIssueAt >= input.policy.abuse.resendCooldownMillis);
|
|
308
|
-
const receipt = {
|
|
309
|
-
requestId: input.record.requestId,
|
|
310
|
-
reference: {
|
|
311
|
-
proofId: input.record.proofId,
|
|
312
|
-
purpose: input.record.purpose,
|
|
313
|
-
keyId: input.record.verifier.keyId
|
|
314
|
-
}
|
|
315
|
-
};
|
|
316
|
-
const prepared = prepare(allowed ? {
|
|
317
|
-
_tag: "Issued",
|
|
318
|
-
record: input.record
|
|
319
|
-
} : {
|
|
320
|
-
_tag: "Suppressed",
|
|
321
|
-
receipt
|
|
322
|
-
}, journal);
|
|
323
|
-
if (!allowed) return prepared;
|
|
324
|
-
yield* insertScopeEvents(mapping, input.record.moduleId, input.record.purpose, "issue", input.record.requestId, scopes, now, retentionUntil);
|
|
325
|
-
if (activeProofId !== null && activeProofId !== void 0) yield* transaction.update(mapping.generation.table).set(updateValues([[mapping.generation.state, "superseded"]])).where(and(eq(generationColumns(mapping).moduleId, input.record.moduleId), eq(generationColumns(mapping).proofId, activeProofId), eq(generationColumns(mapping).state, "active")));
|
|
326
|
-
yield* transaction.insert(mapping.generation.table).values(mapping.generation.encodeInsert({
|
|
327
|
-
record: input.record,
|
|
328
|
-
seriesKey: keys.series,
|
|
329
|
-
retentionUntilMillis: retentionUntil,
|
|
330
|
-
state: "active",
|
|
331
|
-
deliveryState: "new",
|
|
332
|
-
policy: input.policy
|
|
333
|
-
}));
|
|
334
|
-
const nextVersion = yield* allocateVersion(mapping, configuration.mode);
|
|
335
|
-
yield* transaction.update(mapping.series.table).set(updateValues([
|
|
336
|
-
[mapping.series.activeProofId, input.record.proofId],
|
|
337
|
-
[mapping.series.lastIssueAt, mapping.encodeInstant(now)],
|
|
338
|
-
[mapping.series.version, nextVersion]
|
|
339
|
-
])).where(and(eq(sc.moduleId, input.record.moduleId), eq(sc.purpose, input.record.purpose), eq(sc.scopeKey, keys.series)));
|
|
340
|
-
return prepared;
|
|
341
|
-
})).pipe(Effect.provideService(CurrentProofSql, database), Effect.provideService(LifecycleHooks, hooks), translateIssueFailure),
|
|
342
|
-
attempt: (input, prepare) => owned(database, mapping, configuration, Effect.gen(function* () {
|
|
343
|
-
const transaction = yield* CurrentProofSql;
|
|
344
|
-
const journal = yield* CurrentCommitJournal;
|
|
345
|
-
const keys = mapping.scopeKeys({
|
|
346
|
-
moduleId: input.moduleId,
|
|
347
|
-
purpose: input.purpose,
|
|
348
|
-
binding: input.binding
|
|
349
|
-
});
|
|
350
|
-
const authorityCurrent = yield* lockAuthority(mapping, input.moduleId, input.purpose, input.binding, configuration.locking);
|
|
351
|
-
const scopes = scopeEntries(keys, input.binding, "attempt", input.policy);
|
|
352
|
-
yield* lockScopes(mapping, configuration, input.moduleId, input.purpose, "attempt", scopes.slice(0, 1));
|
|
353
|
-
const actionNow = yield* nowMillis;
|
|
354
|
-
const actionOpen = (yield* admittedScopes(mapping, input.moduleId, input.purpose, "attempt", scopes.slice(0, 1), actionNow)).length === 1;
|
|
355
|
-
if (actionOpen) yield* lockScopes(mapping, configuration, input.moduleId, input.purpose, "attempt", scopes.slice(1));
|
|
356
|
-
const series = actionOpen ? yield* ensureSeries(mapping, configuration, input.moduleId, input.purpose, keys.series) : void 0;
|
|
357
|
-
const generation = (yield* readGeneration(mapping, input.moduleId, input.proofId, configuration.locking))[0];
|
|
358
|
-
const existingCommand = (yield* commandRow(mapping, input.moduleId, input.continuationId, configuration.locking))[0];
|
|
359
|
-
if (existingCommand !== void 0) {
|
|
360
|
-
if (existingCommand[mapping.command.decision] === "rejected") return prepare({ _tag: "Rejected" }, journal);
|
|
361
|
-
return yield* unavailable();
|
|
362
|
-
}
|
|
363
|
-
const now = yield* nowMillis;
|
|
364
|
-
const admitted = actionOpen ? yield* admittedScopes(mapping, input.moduleId, input.purpose, "attempt", scopes, now) : [];
|
|
365
|
-
const failures = yield* failureCount(mapping, input.moduleId, input.purpose, keys.series, now, input.policy);
|
|
366
|
-
const gc = generationColumns(mapping);
|
|
367
|
-
const activeProofId = series?.[mapping.series.activeProofId];
|
|
368
|
-
const storedBinding = generation === void 0 ? void 0 : yield* mapping.generation.decodeBinding(generation);
|
|
369
|
-
const candidateMatches = generation !== void 0 && input.candidate !== void 0 && generation[mapping.generation.verifierKeyId] === input.candidate.keyId && generation[mapping.generation.verifierDigest] === input.candidate.digest;
|
|
370
|
-
const currentGeneration = generation !== void 0 && generation[mapping.generation.purpose] === input.purpose && generation[mapping.generation.state] === "active" && activeProofId === input.proofId && storedBinding !== void 0 && sameBinding(storedBinding, input.binding) && Number(yield* mapping.decodeInstant(generation[mapping.generation.expiresAt])) > now;
|
|
371
|
-
const accepted = authorityCurrent && currentGeneration && candidateMatches && admitted.length === scopes.length && failures < input.policy.maximumFailedAttempts;
|
|
372
|
-
const retentionUntil = now + input.policy.requestRetentionMillis;
|
|
373
|
-
if (!accepted) {
|
|
374
|
-
const prepared = prepare({ _tag: "Rejected" }, journal);
|
|
375
|
-
yield* insertCommand(mapping, input.moduleId, input.continuationId, "attempt", "rejected", retentionUntil);
|
|
376
|
-
yield* insertScopeEvents(mapping, input.moduleId, input.purpose, "attempt", input.continuationId, admitted, now, retentionUntil);
|
|
377
|
-
if (admitted.length === scopes.length && currentGeneration && !candidateMatches && failures < input.policy.maximumFailedAttempts) yield* transaction.insert(mapping.failureEvent.table).values(mapping.failureEvent.encodeInsert({
|
|
378
|
-
moduleId: input.moduleId,
|
|
379
|
-
purpose: input.purpose,
|
|
380
|
-
seriesKey: keys.series,
|
|
381
|
-
commandId: input.continuationId,
|
|
382
|
-
occurredAtMillis: now,
|
|
383
|
-
retentionUntilMillis: retentionUntil
|
|
384
|
-
}));
|
|
385
|
-
return prepared;
|
|
386
|
-
}
|
|
387
|
-
const version = yield* allocateVersion(mapping, configuration.mode);
|
|
388
|
-
const expiresAt = Math.min(Number(yield* mapping.decodeInstant(generation[mapping.generation.expiresAt])), now + input.policy.continuationLifetimeMillis);
|
|
389
|
-
const continuation = {
|
|
390
|
-
moduleId: input.moduleId,
|
|
391
|
-
purpose: input.purpose,
|
|
392
|
-
continuationId: input.continuationId,
|
|
393
|
-
digest: input.continuationDigest,
|
|
394
|
-
proofId: input.proofId,
|
|
395
|
-
seriesKey: keys.series,
|
|
396
|
-
binding: input.binding,
|
|
397
|
-
expiresAtMillis: expiresAt,
|
|
398
|
-
version
|
|
399
|
-
};
|
|
400
|
-
const prepared = prepare({
|
|
401
|
-
_tag: "Accepted",
|
|
402
|
-
continuation: {
|
|
403
|
-
continuationId: input.continuationId,
|
|
404
|
-
purpose: input.purpose,
|
|
405
|
-
expiresAtMillis: expiresAt
|
|
406
|
-
}
|
|
407
|
-
}, journal);
|
|
408
|
-
yield* insertCommand(mapping, input.moduleId, input.continuationId, "attempt", "accepted", retentionUntil);
|
|
409
|
-
yield* insertScopeEvents(mapping, input.moduleId, input.purpose, "attempt", input.continuationId, scopes, now, retentionUntil);
|
|
410
|
-
yield* transaction.update(mapping.generation.table).set(updateValues([[mapping.generation.state, "consumed"]])).where(and(eq(gc.moduleId, input.moduleId), eq(gc.proofId, input.proofId), eq(gc.state, "active")));
|
|
411
|
-
yield* transaction.insert(mapping.continuation.table).values(mapping.continuation.encodeInsert({
|
|
412
|
-
...continuation,
|
|
413
|
-
retentionUntilMillis: retentionUntil
|
|
414
|
-
}));
|
|
415
|
-
return prepared;
|
|
416
|
-
})).pipe(Effect.provideService(CurrentProofSql, database), Effect.provideService(LifecycleHooks, hooks), translateFailure),
|
|
417
|
-
complete: (input, prepare) => owned(database, mapping, configuration, Effect.gen(function* () {
|
|
418
|
-
const journal = yield* CurrentCommitJournal;
|
|
419
|
-
return yield* completeIn(mapping, configuration, input, (decision) => prepare(decision, journal));
|
|
420
|
-
})).pipe(Effect.provideService(CurrentProofSql, database), Effect.provideService(LifecycleHooks, hooks), translateFailure),
|
|
421
|
-
claimDelivery: (input, prepare) => owned(database, mapping, configuration, Effect.gen(function* () {
|
|
422
|
-
const transaction = yield* CurrentProofSql;
|
|
423
|
-
const journal = yield* CurrentCommitJournal;
|
|
424
|
-
const row = (yield* readGeneration(mapping, input.moduleId, input.proofId, configuration.locking))[0];
|
|
425
|
-
const now = yield* nowMillis;
|
|
426
|
-
if (row === void 0) return prepare({ _tag: "Declined" }, journal);
|
|
427
|
-
const c = generationColumns(mapping);
|
|
428
|
-
const expiresAt = yield* mapping.decodeInstant(row[mapping.generation.expiresAt]);
|
|
429
|
-
const claimDeadline = row[mapping.generation.claimDeadline] === null || row[mapping.generation.claimDeadline] === void 0 ? void 0 : yield* mapping.decodeInstant(row[mapping.generation.claimDeadline]);
|
|
430
|
-
const retryAt = row[mapping.generation.retryAt] === null || row[mapping.generation.retryAt] === void 0 ? void 0 : yield* mapping.decodeInstant(row[mapping.generation.retryAt]);
|
|
431
|
-
let state = row[mapping.generation.deliveryState];
|
|
432
|
-
if (state === "claimed" && claimDeadline !== void 0 && claimDeadline <= now) {
|
|
433
|
-
state = "ambiguous";
|
|
434
|
-
yield* transaction.update(mapping.generation.table).set(updateValues([[mapping.generation.deliveryState, "ambiguous"]])).where(and(eq(c.moduleId, input.moduleId), eq(c.proofId, input.proofId)));
|
|
435
|
-
}
|
|
436
|
-
if (!(row[mapping.generation.version] === input.version && row[mapping.generation.deliveryId] === input.deliveryId && row[mapping.generation.state] === "active" && expiresAt > now && Number(row[mapping.generation.sendCount]) < input.policy.maximumDeliveryAttempts && (state === "new" || state === "ambiguous" && input.allowAmbiguousRetry && (retryAt === void 0 || retryAt <= now)))) return prepare({ _tag: "Declined" }, journal);
|
|
437
|
-
const claimVersion = yield* allocateVersion(mapping, configuration.mode);
|
|
438
|
-
const prepared = prepare({
|
|
439
|
-
_tag: "Claimed",
|
|
440
|
-
claimVersion
|
|
441
|
-
}, journal);
|
|
442
|
-
yield* transaction.update(mapping.generation.table).set(updateValues([
|
|
443
|
-
[mapping.generation.sendCount, Number(row[mapping.generation.sendCount]) + 1],
|
|
444
|
-
[mapping.generation.deliveryState, "claimed"],
|
|
445
|
-
[mapping.generation.claimVersion, claimVersion],
|
|
446
|
-
[mapping.generation.claimDeadline, mapping.encodeInstant(now + input.policy.deliveryClaimMillis)],
|
|
447
|
-
[mapping.generation.retryAt, mapping.encodeInstant(now + input.policy.deliveryRetryMillis)]
|
|
448
|
-
])).where(and(eq(c.moduleId, input.moduleId), eq(c.proofId, input.proofId)));
|
|
449
|
-
return prepared;
|
|
450
|
-
})).pipe(Effect.provideService(CurrentProofSql, database), Effect.provideService(LifecycleHooks, hooks), translateFailure),
|
|
451
|
-
settleDelivery: (input, prepare) => owned(database, mapping, configuration, Effect.gen(function* () {
|
|
452
|
-
const transaction = yield* CurrentProofSql;
|
|
453
|
-
const journal = yield* CurrentCommitJournal;
|
|
454
|
-
const initial = (yield* readGeneration(mapping, input.moduleId, input.proofId, false))[0];
|
|
455
|
-
if (initial === void 0) return prepare(void 0, journal);
|
|
456
|
-
const keys = initial[mapping.generation.seriesKey];
|
|
457
|
-
yield* ensureSeries(mapping, configuration, input.moduleId, initial[mapping.generation.purpose], keys);
|
|
458
|
-
const row = (yield* readGeneration(mapping, input.moduleId, input.proofId, configuration.locking))[0];
|
|
459
|
-
const prepared = prepare(void 0, journal);
|
|
460
|
-
if (row === void 0 || row[mapping.generation.version] !== input.version || row[mapping.generation.deliveryId] !== input.deliveryId || row[mapping.generation.claimVersion] !== input.claimVersion || row[mapping.generation.deliveryState] !== "claimed") return prepared;
|
|
461
|
-
const c = generationColumns(mapping);
|
|
462
|
-
const outcome = input.outcome;
|
|
463
|
-
const state = outcome._tag === "Accepted" ? "accepted" : outcome._tag === "DefiniteFailure" ? "failed" : "ambiguous";
|
|
464
|
-
const values = [[mapping.generation.deliveryState, state], [mapping.generation.claimDeadline, null]];
|
|
465
|
-
if (outcome._tag === "Ambiguous") values.push([mapping.generation.retryAt, mapping.encodeInstant((yield* nowMillis) + Number(row[mapping.generation.deliveryRetryMillis]))]);
|
|
466
|
-
if (outcome._tag === "DefiniteFailure") values.push([mapping.generation.state, "cancelled"]);
|
|
467
|
-
yield* transaction.update(mapping.generation.table).set(updateValues(values)).where(and(eq(c.moduleId, input.moduleId), eq(c.proofId, input.proofId)));
|
|
468
|
-
if (outcome._tag === "DefiniteFailure") {
|
|
469
|
-
const sc = seriesColumns(mapping);
|
|
470
|
-
yield* transaction.update(mapping.series.table).set(updateValues([[mapping.series.activeProofId, null]])).where(and(eq(sc.moduleId, input.moduleId), eq(sc.purpose, row[mapping.generation.purpose]), eq(sc.scopeKey, keys), eq(sc.activeProofId, input.proofId)));
|
|
471
|
-
}
|
|
472
|
-
return prepared;
|
|
473
|
-
})).pipe(Effect.provideService(CurrentProofSql, database), Effect.provideService(LifecycleHooks, hooks), translateFailure),
|
|
474
|
-
cancel: (input, prepare) => owned(database, mapping, configuration, Effect.gen(function* () {
|
|
475
|
-
const transaction = yield* CurrentProofSql;
|
|
476
|
-
const journal = yield* CurrentCommitJournal;
|
|
477
|
-
const authorityCurrent = yield* lockAuthority(mapping, input.moduleId, input.purpose, input.binding, configuration.locking);
|
|
478
|
-
const keys = mapping.scopeKeys({
|
|
479
|
-
moduleId: input.moduleId,
|
|
480
|
-
purpose: input.purpose,
|
|
481
|
-
binding: input.binding
|
|
482
|
-
});
|
|
483
|
-
const active = (yield* ensureSeries(mapping, configuration, input.moduleId, input.purpose, keys.series))[mapping.series.activeProofId];
|
|
484
|
-
const prepared = prepare(void 0, journal);
|
|
485
|
-
if (authorityCurrent && active !== void 0 && active !== null) {
|
|
486
|
-
const gc = generationColumns(mapping);
|
|
487
|
-
const sc = seriesColumns(mapping);
|
|
488
|
-
const row = (yield* readGeneration(mapping, input.moduleId, active, configuration.locking))[0];
|
|
489
|
-
const storedBinding = row === void 0 ? void 0 : yield* mapping.generation.decodeBinding(row);
|
|
490
|
-
if (storedBinding === void 0 || !sameBinding(storedBinding, input.binding)) return prepared;
|
|
491
|
-
yield* transaction.update(mapping.generation.table).set(updateValues([[mapping.generation.state, "cancelled"]])).where(and(eq(gc.moduleId, input.moduleId), eq(gc.proofId, active)));
|
|
492
|
-
yield* transaction.update(mapping.series.table).set(updateValues([[mapping.series.activeProofId, null]])).where(and(eq(sc.moduleId, input.moduleId), eq(sc.purpose, input.purpose), eq(sc.scopeKey, keys.series), eq(sc.activeProofId, active)));
|
|
493
|
-
}
|
|
494
|
-
return prepared;
|
|
495
|
-
})).pipe(Effect.provideService(CurrentProofSql, database), Effect.provideService(LifecycleHooks, hooks), translateFailure),
|
|
496
|
-
cleanup: (input, prepare) => owned(database, mapping, configuration, Effect.gen(function* () {
|
|
497
|
-
const transaction = yield* CurrentProofSql;
|
|
498
|
-
const journal = yield* CurrentCommitJournal;
|
|
499
|
-
const now = yield* nowMillis;
|
|
500
|
-
const nativeNow = mapping.encodeInstant(now);
|
|
501
|
-
const gc = generationColumns(mapping);
|
|
502
|
-
const cc = continuationColumns(mapping);
|
|
503
|
-
const rc = requestColumns(mapping);
|
|
504
|
-
const ac = abuseColumns(mapping);
|
|
505
|
-
const fc = failureColumns(mapping);
|
|
506
|
-
const mc = commandColumns(mapping);
|
|
507
|
-
const sc = seriesColumns(mapping);
|
|
508
|
-
const rsc = scopeColumns(mapping);
|
|
509
|
-
let remaining = input.limit;
|
|
510
|
-
let hasMore = false;
|
|
511
|
-
const take = (query) => selectRows(query.limit(remaining + 1), configuration.locking).pipe(Effect.map((rows) => {
|
|
512
|
-
if (rows.length > remaining) hasMore = true;
|
|
513
|
-
const selected = rows.slice(0, remaining);
|
|
514
|
-
remaining -= selected.length;
|
|
515
|
-
return selected;
|
|
516
|
-
}));
|
|
517
|
-
const continuations = yield* take(transaction.select({ continuationId: cc.continuationId }).from(mapping.continuation.table).where(and(eq(cc.moduleId, input.moduleId), lte(cc.retentionUntil, nativeNow))).orderBy(cc.retentionUntil));
|
|
518
|
-
const generations = yield* take(transaction.select({ proofId: gc.proofId }).from(mapping.generation.table).where(and(eq(gc.moduleId, input.moduleId), lte(gc.retentionUntil, nativeNow))).orderBy(gc.retentionUntil));
|
|
519
|
-
const requests = yield* take(transaction.select({ requestId: rc.requestId }).from(mapping.request.table).where(and(eq(rc.moduleId, input.moduleId), lte(rc.retentionUntil, nativeNow))).orderBy(rc.retentionUntil));
|
|
520
|
-
const abuse = yield* take(transaction.select({
|
|
521
|
-
action: ac.action,
|
|
522
|
-
scopeKind: ac.scopeKind,
|
|
523
|
-
scopeKey: ac.scopeKey,
|
|
524
|
-
commandId: ac.commandId
|
|
525
|
-
}).from(mapping.abuseEvent.table).where(and(eq(ac.moduleId, input.moduleId), lte(ac.retentionUntil, nativeNow))).orderBy(ac.retentionUntil));
|
|
526
|
-
const failures = yield* take(transaction.select({
|
|
527
|
-
seriesKey: fc.seriesKey,
|
|
528
|
-
commandId: fc.commandId
|
|
529
|
-
}).from(mapping.failureEvent.table).where(and(eq(fc.moduleId, input.moduleId), lte(fc.retentionUntil, nativeNow))).orderBy(fc.retentionUntil));
|
|
530
|
-
const commands = yield* take(transaction.select({ commandId: mc.commandId }).from(mapping.command.table).where(and(eq(mc.moduleId, input.moduleId), lte(mc.retentionUntil, nativeNow))).orderBy(mc.retentionUntil));
|
|
531
|
-
const series = yield* take(transaction.select({
|
|
532
|
-
purpose: sc.purpose,
|
|
533
|
-
scopeKey: sc.scopeKey
|
|
534
|
-
}).from(mapping.series.table).where(and(eq(sc.moduleId, input.moduleId), isNull(sc.activeProofId), notExists(transaction.select({ one: sql`1` }).from(mapping.generation.table).where(and(eq(gc.moduleId, sc.moduleId), eq(gc.purpose, sc.purpose), eq(gc.seriesKey, sc.scopeKey)))), notExists(transaction.select({ one: sql`1` }).from(mapping.failureEvent.table).where(and(eq(fc.moduleId, sc.moduleId), eq(fc.purpose, sc.purpose), eq(fc.seriesKey, sc.scopeKey)))))));
|
|
535
|
-
const rateScopes = yield* take(transaction.select({
|
|
536
|
-
purpose: rsc.purpose,
|
|
537
|
-
action: rsc.action,
|
|
538
|
-
scopeKind: rsc.scopeKind,
|
|
539
|
-
scopeKey: rsc.scopeKey
|
|
540
|
-
}).from(mapping.rateScope.table).where(and(eq(rsc.moduleId, input.moduleId), notExists(transaction.select({ one: sql`1` }).from(mapping.abuseEvent.table).where(and(eq(ac.moduleId, rsc.moduleId), eq(ac.purpose, rsc.purpose), eq(ac.action, rsc.action), eq(ac.scopeKind, rsc.scopeKind), eq(ac.scopeKey, rsc.scopeKey)))))));
|
|
541
|
-
hasMore ||= generations.length > 0 || failures.length > 0 || abuse.length > 0;
|
|
542
|
-
const prepared = prepare({
|
|
543
|
-
removed: input.limit - remaining,
|
|
544
|
-
hasMore
|
|
545
|
-
}, journal);
|
|
546
|
-
if (continuations.length > 0) yield* transaction.delete(mapping.continuation.table).where(and(eq(cc.moduleId, input.moduleId), inArray(cc.continuationId, continuations.map((row) => row.continuationId)), lte(cc.retentionUntil, nativeNow)));
|
|
547
|
-
if (generations.length > 0) yield* transaction.update(mapping.series.table).set(updateValues([[mapping.series.activeProofId, null]])).where(and(eq(sc.moduleId, input.moduleId), inArray(sc.activeProofId, generations.map((row) => row.proofId))));
|
|
548
|
-
if (generations.length > 0) yield* transaction.delete(mapping.generation.table).where(and(eq(gc.moduleId, input.moduleId), inArray(gc.proofId, generations.map((row) => row.proofId)), lte(gc.retentionUntil, nativeNow)));
|
|
549
|
-
if (requests.length > 0) yield* transaction.delete(mapping.request.table).where(and(eq(rc.moduleId, input.moduleId), inArray(rc.requestId, requests.map((row) => row.requestId)), lte(rc.retentionUntil, nativeNow)));
|
|
550
|
-
for (const row of abuse) yield* transaction.delete(mapping.abuseEvent.table).where(and(eq(ac.moduleId, input.moduleId), eq(ac.action, row.action), eq(ac.scopeKind, row.scopeKind), eq(ac.scopeKey, row.scopeKey), eq(ac.commandId, row.commandId), lte(ac.retentionUntil, nativeNow)));
|
|
551
|
-
for (const row of failures) yield* transaction.delete(mapping.failureEvent.table).where(and(eq(fc.moduleId, input.moduleId), eq(fc.seriesKey, row.seriesKey), eq(fc.commandId, row.commandId), lte(fc.retentionUntil, nativeNow)));
|
|
552
|
-
if (commands.length > 0) yield* transaction.delete(mapping.command.table).where(and(eq(mc.moduleId, input.moduleId), inArray(mc.commandId, commands.map((row) => row.commandId)), lte(mc.retentionUntil, nativeNow)));
|
|
553
|
-
for (const row of series) yield* transaction.delete(mapping.series.table).where(and(eq(sc.moduleId, input.moduleId), eq(sc.purpose, row.purpose), eq(sc.scopeKey, row.scopeKey), isNull(sc.activeProofId), notExists(transaction.select({ one: sql`1` }).from(mapping.generation.table).where(and(eq(gc.moduleId, sc.moduleId), eq(gc.purpose, sc.purpose), eq(gc.seriesKey, sc.scopeKey))))));
|
|
554
|
-
for (const row of rateScopes) yield* transaction.delete(mapping.rateScope.table).where(and(eq(rsc.moduleId, input.moduleId), eq(rsc.purpose, row.purpose), eq(rsc.action, row.action), eq(rsc.scopeKind, row.scopeKind), eq(rsc.scopeKey, row.scopeKey), notExists(transaction.select({ one: sql`1` }).from(mapping.abuseEvent.table).where(and(eq(ac.moduleId, rsc.moduleId), eq(ac.purpose, rsc.purpose), eq(ac.action, rsc.action), eq(ac.scopeKind, rsc.scopeKind), eq(ac.scopeKey, rsc.scopeKey))))));
|
|
555
|
-
return prepared;
|
|
556
|
-
})).pipe(Effect.provideService(CurrentProofSql, database), Effect.provideService(LifecycleHooks, hooks), translateFailure)
|
|
557
|
-
});
|
|
558
|
-
});
|
|
559
|
-
const inspectCompletionIn = Effect.fn("DrizzleProof.inspectCompletionIn")(function* (mapping, configuration, input, ensure) {
|
|
560
|
-
const database = yield* CurrentProofSql;
|
|
561
|
-
const authorityCurrent = yield* lockAuthority(mapping, input.moduleId, input.purpose, input.binding, configuration.locking);
|
|
562
|
-
const keys = mapping.scopeKeys({
|
|
563
|
-
moduleId: input.moduleId,
|
|
564
|
-
purpose: input.purpose,
|
|
565
|
-
binding: input.binding
|
|
566
|
-
});
|
|
567
|
-
if (ensure) yield* ensureSeries(mapping, configuration, input.moduleId, input.purpose, keys.series);
|
|
568
|
-
const c = continuationColumns(mapping);
|
|
569
|
-
const row = (yield* selectRows(database.select().from(mapping.continuation.table).where(and(eq(c.moduleId, input.moduleId), eq(c.continuationId, input.continuationId))).limit(1), configuration.locking))[0];
|
|
570
|
-
const now = yield* nowMillis;
|
|
571
|
-
const record = row === void 0 ? void 0 : yield* mapping.continuation.decode(row);
|
|
572
|
-
return authorityCurrent && row !== void 0 && record !== void 0 && record.moduleId === input.moduleId && record.continuationId === input.continuationId && record.purpose === input.purpose && record.digest === input.continuationDigest && record.seriesKey === keys.series && sameBinding(record.binding, input.binding) && row[mapping.continuation.consumed] === false && record.expiresAtMillis > now ? {
|
|
573
|
-
record,
|
|
574
|
-
row,
|
|
575
|
-
columns: c
|
|
576
|
-
} : void 0;
|
|
577
|
-
});
|
|
578
|
-
/** Nonconsuming same-owner preflight; it never inserts a series or changes expiry. */
|
|
579
|
-
const checkProofCompletionIn = Effect.fn("Drizzle.checkProofCompletionIn")(function* (mapping, configuration, input) {
|
|
580
|
-
return yield* inspectCompletionIn(mapping, configuration, input, false).pipe(Effect.map((value) => value !== void 0));
|
|
581
|
-
});
|
|
582
|
-
const completeIn = Effect.fn("DrizzleProof.completeIn")(function* (mapping, configuration, input, prepare, protectedMutation) {
|
|
583
|
-
const database = yield* CurrentProofSql;
|
|
584
|
-
const accepted = yield* inspectCompletionIn(mapping, configuration, input, true);
|
|
585
|
-
if (accepted === void 0) return prepare("rejected");
|
|
586
|
-
const { record, row: original, columns: c } = accepted;
|
|
587
|
-
if (protectedMutation !== void 0 && !(yield* protectedMutation)) return yield* unavailable();
|
|
588
|
-
const value = prepare("completed");
|
|
589
|
-
yield* database.update(mapping.continuation.table).set(updateValues([[mapping.continuation.consumed, true]])).where(and(eq(c.moduleId, input.moduleId), eq(c.continuationId, input.continuationId), eq(c.digest, input.continuationDigest), eq(c.consumed, false)));
|
|
590
|
-
yield* insertCommand(mapping, input.moduleId, input.continuationDigest, "complete", "completed", record.expiresAtMillis);
|
|
591
|
-
const assertApplied = Effect.flatMap(CurrentPasswordPreparedTransaction, (currentTransaction) => Effect.gen(function* () {
|
|
592
|
-
const persisted = (yield* selectRows(currentTransaction.select().from(mapping.continuation.table).where(and(eq(c.moduleId, input.moduleId), eq(c.continuationId, input.continuationId))).limit(1), false))[0];
|
|
593
|
-
const command = (yield* commandRow(mapping, input.moduleId, input.continuationDigest, false))[0];
|
|
594
|
-
const decoded = persisted === void 0 ? void 0 : yield* mapping.continuation.decode(persisted);
|
|
595
|
-
const immutable = [
|
|
596
|
-
mapping.continuation.moduleId,
|
|
597
|
-
mapping.continuation.purpose,
|
|
598
|
-
mapping.continuation.continuationId,
|
|
599
|
-
mapping.continuation.digest,
|
|
600
|
-
mapping.continuation.proofId,
|
|
601
|
-
mapping.continuation.seriesKey,
|
|
602
|
-
mapping.continuation.version
|
|
603
|
-
];
|
|
604
|
-
if (persisted === void 0 || decoded === void 0 || !sameBinding(decoded.binding, record.binding) || persisted[mapping.continuation.consumed] !== true || immutable.some((key) => persisted[key] !== original[key]) || (yield* mapping.decodeInstant(persisted[mapping.continuation.expiresAt])) !== record.expiresAtMillis || (yield* mapping.decodeInstant(persisted[mapping.continuation.retentionUntil])) !== (yield* mapping.decodeInstant(original[mapping.continuation.retentionUntil])) || command === void 0 || command[mapping.command.kind] !== "complete" || command[mapping.command.decision] !== "completed" || (yield* mapping.decodeInstant(command[mapping.command.retentionUntil])) !== record.expiresAtMillis) return yield* unavailable();
|
|
605
|
-
if (record.expiresAtMillis <= (yield* nowMillis)) return yield* unavailable();
|
|
606
|
-
}).pipe(Effect.provideService(CurrentProofSql, currentTransaction)));
|
|
607
|
-
yield* assertApplied.pipe(Effect.provideService(CurrentPasswordPreparedTransaction, database));
|
|
608
|
-
const postconditions = yield* Effect.serviceOption(PasswordPreparedPostconditions);
|
|
609
|
-
if (Option.isSome(postconditions) && !postconditions.value.register(assertApplied.pipe(translateFailure))) return yield* unavailable();
|
|
610
|
-
return value;
|
|
611
|
-
});
|
|
612
|
-
return {
|
|
613
|
-
makeSqlProofPersistence,
|
|
614
|
-
checkProofCompletionIn,
|
|
615
|
-
completeProofPlanIn: Effect.fn("Drizzle.completeProofPlanIn")(function* (mapping, configuration, plan, protectedMutation, project) {
|
|
616
|
-
const journal = yield* CurrentCommitJournal;
|
|
617
|
-
return yield* completeIn(mapping, configuration, plan.input, (decision) => plan.prepare(decision, journal, project), protectedMutation);
|
|
618
|
-
})
|
|
619
|
-
};
|
|
620
|
-
};
|
|
621
|
-
//#endregion
|
|
622
|
-
export { CurrentProofSql, makeProofKernel };
|
|
623
|
-
|
|
624
|
-
//# sourceMappingURL=proof-kernel.mjs.map
|