@yielded/auth-persistence-drizzle 0.1.0-beta.16 → 0.1.0-beta.18
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/dist/D1.d.mts +116 -116
- package/dist/Libsql.d.mts +125 -125
- package/dist/Mysql2.d.mts +123 -123
- package/dist/Pglite.d.mts +123 -123
- package/dist/Postgres.d.mts +123 -123
- package/dist/SqliteBun.d.mts +125 -125
- package/dist/SqliteDo.d.mts +125 -125
- package/dist/SqliteNode.d.mts +122 -122
- package/dist/SqliteWasm.d.mts +125 -125
- package/dist/drizzle/d1-oauth.d.mts +7 -7
- package/dist/drizzle/d1-password-prepared.mjs +3 -3
- package/dist/drizzle/d1-password-prepared.mjs.map +1 -1
- package/dist/drizzle/d1-passwords.mjs +1 -1
- package/dist/drizzle/d1-passwords.mjs.map +1 -1
- package/dist/drizzle/d1-sessions.mjs +4 -3
- package/dist/drizzle/d1-sessions.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-state.d.mts +252 -252
- package/dist/drizzle/oauth-connected-target.d.mts +102 -102
- package/dist/drizzle/password-prepared-sql.mjs +1 -1
- package/dist/drizzle/password-prepared-sql.mjs.map +1 -1
- package/package.json +1 -1
- package/src/drizzle/d1-password-prepared.ts +11 -5
- package/src/drizzle/d1-passwords.ts +1 -1
- package/src/drizzle/d1-sessions.ts +8 -2
- package/src/drizzle/password-prepared-sql.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"password-prepared-sql.mjs","names":["kernel"],"sources":["../../src/drizzle/password-prepared-sql.ts"],"sourcesContent":["import {\n type NativeDatabase,\n CurrentPasswordPreparedTransaction,\n PasswordPreparedPostconditions,\n PasswordPreparedJournalGuards,\n} from \"@yielded/auth-persistence/Adapter\";\nimport { CurrentCommitJournal, LifecycleHooks, HookConfigurationError } from \"@yielded/auth/Hooks\";\nimport {\n PasswordUnavailable,\n PasswordRejected,\n PasswordPreparedVersion,\n decodePasswordPreparedReady,\n encodePasswordPreparedReady,\n snapshotPasswordPreparedReady,\n snapshotPasswordPreparedReservation,\n type PasswordPreparedReady,\n type PasswordPreparedReservation,\n snapshotPasswordCredential,\n snapshotPasswordRequirement,\n type PasswordMutationDecision,\n type PreparePasswordCommit,\n type PasswordPreparedPersistence,\n type PasswordPreparedMutation,\n} from \"@yielded/auth/Password\";\nimport { reportPersistenceFailure } from \"@yielded/auth/Persistence\";\nimport { type ProofCompletionPlan, ProofUnavailable, ProofBinding } from \"@yielded/auth/Proofs\";\nimport { AuthenticationRevision } from \"@yielded/auth/Sessions\";\n/* oxlint-disable no-explicit-any -- concrete driver makers retain consumer table types. */\nimport { and, count, eq, gt, isNotNull, isNull, lte, or, type SQL } from \"drizzle-orm\";\nimport { Cause, DateTime, Effect, Option, Predicate, Redacted, Schema } from \"effect\";\n\nimport { column } from \"./model\";\nimport {\n requiredPasswordPreparedConstraints,\n type AnyPasswordPreparedPersistenceMapping,\n type PasswordPreparedState,\n} from \"./password-prepared-model\";\nimport {\n ContextInput,\n CompletionInput,\n encodeReservation,\n evidenceCurrent,\n identifierScope,\n reservationOf,\n sameRevision,\n snapshotMutation,\n snapshotReserve,\n unavailable,\n} from \"./password-prepared-state\";\nimport {\n CurrentPasswordSql,\n passwordSqlKernel as kernel,\n type PasswordSqlConfiguration,\n type PasswordSqlQuery,\n} from \"./password-sql\";\nimport { checkProofCompletionIn, completeProofPlanIn } from \"./proof-sql\";\nimport { validateDrizzleStorage } from \"./storage-validation\";\n\nconst translateFailure = <A, E, R>(\n effect: Effect.Effect<A, E, R>,\n): Effect.Effect<A, PasswordUnavailable, R> =>\n reportPersistenceFailure(\n effect,\n (error) =>\n Schema.is(PasswordUnavailable)(error) ||\n Schema.is(ProofUnavailable)(error) ||\n Schema.is(HookConfigurationError)(error),\n ).pipe(Effect.catchCause((cause) => Effect.failCause(Cause.map(cause, () => unavailable()))));\n\nconst translateContextFailure = <A, E, R>(\n effect: Effect.Effect<A, E, R>,\n): Effect.Effect<A, PasswordUnavailable | PasswordRejected, R> =>\n reportPersistenceFailure(\n effect,\n (error) =>\n Schema.is(PasswordUnavailable)(error) ||\n Schema.is(PasswordRejected)(error) ||\n Schema.is(ProofUnavailable)(error) ||\n Schema.is(HookConfigurationError)(error),\n ).pipe(\n Effect.catchCause((cause) =>\n Effect.failCause(\n Cause.map(cause, (error) => (Schema.is(PasswordRejected)(error) ? error : unavailable())),\n ),\n ),\n );\n\ntype Mapping = AnyPasswordPreparedPersistenceMapping;\nconst nowMillis = DateTime.now.pipe(Effect.map(DateTime.toEpochMillis));\n\nconst read = (query: PasswordSqlQuery, locking: boolean) =>\n locking && typeof query.for === \"function\" ? query.for(\"update\") : query;\n\nconst columns = (mapping: Mapping) => {\n const table = mapping.intent;\n\n return {\n moduleId: column(table.table, table.moduleId),\n intentId: column(table.table, table.intentId),\n commandId: column(table.table, table.commandId),\n subjectId: column(table.table, table.subjectId),\n action: column(table.table, table.action),\n generation: column(table.table, table.generation),\n version: column(table.table, table.version),\n state: column(table.table, table.state),\n digest: column(table.table, table.digest),\n snapshot: column(table.table, table.snapshot),\n identifierScope: column(table.table, table.identifierScope),\n createdAt: column(table.table, table.createdAt),\n admittedAt: column(table.table, table.admittedAt),\n admissionRetainUntil: column(table.table, table.admissionRetainUntil),\n preparationExpiresAt: column(table.table, table.preparationExpiresAt),\n expiresAt: column(table.table, table.expiresAt),\n retainUntil: column(table.table, table.retainUntil),\n };\n};\n\nconst valid = (mapping: Mapping) =>\n Object.entries(requiredPasswordPreparedConstraints).every(\n ([key, value]) =>\n mapping.constraints[key as keyof typeof requiredPasswordPreparedConstraints] === value,\n );\n\nconst lockAnchor = Effect.fn(\"DrizzlePasswordPrepared.lockAnchor\")(function* (\n mapping: Mapping,\n configuration: PasswordSqlConfiguration,\n moduleId: string,\n create = true,\n) {\n const database = yield* CurrentPasswordSql;\n\n const a = mapping.admission,\n key = column(a.table, a.moduleId);\n\n if (create)\n yield* configuration.insertIfAbsent(\n database.insert(a.table).values(a.encodeInsert(moduleId)),\n a.moduleId,\n moduleId,\n );\n\n const rows = yield* read(\n database.select().from(a.table).where(eq(key, moduleId)).limit(2),\n configuration.locking,\n );\n\n if (rows.length > 1 || (create && rows.length !== 1)) return yield* unavailable();\n\n return rows.length === 1;\n});\n\nconst bindingJson = Schema.encodeSync(Schema.fromJsonString(ProofBinding));\n\nconst captureAuthority = Effect.fn(\"DrizzlePasswordPrepared.captureAuthority\")(function* (\n mapping: Mapping,\n configuration: Pick<PasswordSqlConfiguration, \"locking\">,\n input: {\n readonly moduleId: string;\n readonly action: PasswordPreparedReservation[\"action\"];\n readonly subjectId: string;\n readonly reset?: PasswordPreparedReservation[\"reset\"];\n },\n) {\n const database = yield* CurrentPasswordSql;\n\n const p = mapping.password;\n const locked = yield* kernel.lockSubject(p, input.subjectId, configuration.locking);\n\n if (locked.row === undefined || !p.subject.isActiveStatus(locked.row[p.subject.status]))\n return undefined;\n\n const ic = kernel.identifierColumns(p),\n ac = kernel.authorityCredentialColumns(p);\n\n let identifier: any;\n\n if (input.action !== \"add-password\") {\n if (input.reset !== undefined)\n identifier = (yield* kernel.lockIdentifier(\n p,\n input.reset.binding.identifier,\n configuration.locking,\n ))[0];\n else {\n const discovered = (yield* read(\n database\n .select()\n .from(p.identifier.table)\n .where(eq(ic.subjectId, locked.nativeSubjectId))\n .orderBy(ic.namespace, ic.value),\n false,\n )).find((row: any) => p.identifier.isCurrent(row));\n\n if (discovered !== undefined)\n identifier = (yield* kernel.lockIdentifier(\n p,\n {\n namespace: discovered[p.identifier.namespace],\n value: discovered[p.identifier.value],\n } as any,\n configuration.locking,\n ))[0];\n }\n if (\n identifier === undefined ||\n !p.identifier.isCurrent(identifier) ||\n !p.subjectId.equals(identifier[p.identifier.subjectId], locked.nativeSubjectId)\n )\n return undefined;\n }\n\n const credential = (yield* kernel.readPasswordCredential(\n p,\n input.moduleId,\n locked.nativeSubjectId,\n configuration.locking,\n ))[0];\n\n if ((input.action === \"add-password\") !== (credential === undefined)) return undefined;\n\n const snapshot =\n credential === undefined\n ? undefined\n : yield* p.credential\n .decode({ moduleId: input.moduleId, subject: locked.row, identifier, credential })\n .pipe(Effect.flatMap(snapshotPasswordCredential));\n\n if (\n snapshot !== undefined &&\n (snapshot.moduleId !== input.moduleId ||\n snapshot.revision.subjectId !== input.subjectId ||\n snapshot.revision.securityRevision !== locked.row[p.subject.securityRevision] ||\n snapshot.credentialId !== credential[p.credential.credentialId] ||\n snapshot.credentialRevision !== credential[p.credential.credentialRevision] ||\n snapshot.verifierVersion !== credential[p.credential.verifierVersion] ||\n Redacted.value(snapshot.verifier) !== credential[p.credential.verifier] ||\n snapshot.normalization !== credential[p.credential.normalization] ||\n snapshot.identifier.namespace !== identifier[p.identifier.namespace] ||\n snapshot.identifier.value !== identifier[p.identifier.value] ||\n snapshot.identifierBindingRevision !== identifier[p.identifier.bindingRevision])\n )\n return undefined;\n\n const factors = yield* read(\n database\n .select()\n .from(p.authorityCredential.table)\n .where(eq(ac.subjectId, locked.nativeSubjectId))\n .orderBy(ac.credentialId),\n configuration.locking,\n );\n\n const active = factors.filter(\n (row: any) =>\n p.authorityCredential.status === undefined ||\n p.authorityCredential.isActiveStatus?.(row[p.authorityCredential.status]) === true,\n );\n\n if (active.length > 64) return yield* unavailable();\n\n const revision =\n snapshot?.revision ??\n AuthenticationRevision.make({\n subjectId: input.subjectId as any,\n securityRevision: locked.row[p.subject.securityRevision],\n credentials: active.map((row: any) => ({\n credentialId: row[p.authorityCredential.credentialId],\n revision: row[p.authorityCredential.revision],\n })),\n });\n\n if (\n revision.credentials.some(\n (expected) =>\n !active.some(\n (row: any) =>\n row[p.authorityCredential.credentialId] === expected.credentialId &&\n row[p.authorityCredential.revision] === expected.revision,\n ),\n )\n )\n return undefined;\n\n const requirement = yield* p.subject\n .decodeActionRequirement(locked.row, input.action)\n .pipe(Effect.flatMap(snapshotPasswordRequirement));\n\n return { ...locked, identifier, snapshot, revision, requirement };\n});\n\nconst currentAuthority = Effect.fn(\"DrizzlePasswordPrepared.currentAuthority\")(function* (\n mapping: Mapping,\n configuration: Pick<PasswordSqlConfiguration, \"locking\">,\n record: PasswordPreparedReservation | PasswordPreparedReady,\n) {\n const current = yield* captureAuthority(mapping, configuration, {\n moduleId: record.moduleId,\n action: record.action,\n subjectId: record.revision.subjectId,\n ...(record.reset === undefined ? {} : { reset: record.reset }),\n });\n\n if (\n current === undefined ||\n !sameRevision(current.revision, record.revision) ||\n (current.snapshot === undefined\n ? record.credential !== undefined\n : record.credential === undefined ||\n !kernel.sameCredentialSnapshot(current.snapshot, record.credential))\n )\n return undefined;\n\n return current;\n});\n\nconst rowCondition = (mapping: Mapping, row: any) => {\n const c = columns(mapping);\n\n return and(\n ...Object.entries(c).map(([key, value]) => {\n const field = mapping.intent[key as keyof typeof c],\n item = row[field];\n\n return Predicate.isNullish(item) ? isNull(value) : eq(value, item);\n }),\n )!;\n};\n\nconst readIntent = Effect.fn(\"Drizzle.readIntent\")(function* (\n mapping: Mapping,\n condition: SQL,\n locking: boolean,\n) {\n const database = yield* CurrentPasswordSql;\n\n return yield* read(\n database.select().from(mapping.intent.table).where(condition).limit(2),\n locking,\n );\n});\n\nconst recordMatches = Effect.fn(\"DrizzlePasswordPrepared.recordMatches\")(function* (\n mapping: Mapping,\n row: any,\n record: PasswordPreparedReservation | PasswordPreparedReady,\n nativeSubjectId: unknown,\n snapshot: string,\n) {\n const t = mapping.intent,\n p = mapping.password;\n\n if (\n row === undefined ||\n row[t.moduleId] !== record.moduleId ||\n row[t.intentId] !== record.intentId ||\n row[t.commandId] !== record.commandId ||\n !p.subjectId.equals(row[t.subjectId], nativeSubjectId) ||\n row[t.action] !== record.action ||\n row[t.generation] !== record.generation ||\n row[t.version] !== record.version ||\n row[t.state] !== t.states[record._tag] ||\n row[t.snapshot] !== snapshot ||\n row[t.identifierScope] !== identifierScope(record) ||\n (record._tag === \"Ready\"\n ? row[t.digest] !== record.digest\n : !Predicate.isNullish(row[t.digest]))\n )\n return false;\n for (const [key, instant] of [\n [t.createdAt, record.createdAtMillis],\n [t.preparationExpiresAt, record.preparationExpiresAtMillis],\n [t.retainUntil, record.retainUntilMillis],\n ] as const)\n if ((yield* p.decodeInstant(row[key])) !== instant) return false;\n\n return record._tag === \"Ready\"\n ? (yield* p.decodeInstant(row[t.expiresAt])) === record.expiresAtMillis\n : Predicate.isNullish(row[t.expiresAt]);\n});\n\nconst terminal = Effect.fn(\"DrizzlePasswordPrepared.terminal\")(function* (\n mapping: Mapping,\n row: any,\n state: Exclude<PasswordPreparedState, \"Preparing\" | \"Ready\">,\n) {\n const database = yield* CurrentPasswordSql;\n\n yield* database\n .update(mapping.intent.table)\n .set(mapping.intent.encodeTerminal(state))\n .where(rowCondition(mapping, row));\n\n const c = columns(mapping),\n t = mapping.intent;\n\n const rows = yield* readIntent(\n mapping,\n and(eq(c.moduleId, row[t.moduleId]), eq(c.intentId, row[t.intentId]))!,\n false,\n );\n\n const expected = { ...row, [t.state]: t.states[state], [t.snapshot]: null, [t.digest]: null };\n\n if (\n rows.length !== 1 ||\n (yield* readIntent(mapping, rowCondition(mapping, expected), false)).length !== 1\n )\n return yield* unavailable();\n});\n\nexport const makeSqlPasswordPreparedPersistence = Effect.fn(\"makeSqlPasswordPreparedPersistence\")(\n function* (\n mapping: Mapping,\n configuration: PasswordSqlConfiguration,\n ): Effect.fn.Return<\n PasswordPreparedPersistence,\n PasswordUnavailable,\n LifecycleHooks | CurrentPasswordSql | NativeDatabase\n > {\n const database = yield* CurrentPasswordSql;\n\n if (!configuration.coordinated)\n yield* validateDrizzleStorage({\n ...mapping,\n proof: configuration.proof?.mapping,\n }).pipe(Effect.mapError(unavailable));\n const hooks = yield* LifecycleHooks;\n\n const p = mapping.password,\n c = columns(mapping),\n t = mapping.intent;\n\n const owned = <A, E, R>(body: Effect.Effect<A, E, R>) =>\n valid(mapping)\n ? kernel.owned(\n database,\n p,\n configuration,\n Effect.gen(function* () {\n const journal = yield* CurrentCommitJournal;\n const guards = yield* Effect.serviceOption(PasswordPreparedJournalGuards);\n\n if (Option.isSome(guards) && !guards.value.register(journal.prepare(undefined)))\n return yield* unavailable();\n\n return yield* body;\n }),\n )\n : Effect.fail(unavailable());\n\n const complete = <A>(\n uncaptured: PasswordPreparedMutation & { readonly completion?: ProofCompletionPlan },\n prepare: PreparePasswordCommit<PasswordMutationDecision, A>,\n ) =>\n Effect.gen(function* () {\n const input = yield* snapshotMutation(uncaptured);\n\n const completion =\n uncaptured.completion === undefined\n ? undefined\n : {\n prepare: uncaptured.completion.prepare,\n input: yield* Schema.encodeEffect(Schema.fromJsonString(CompletionInput))(\n uncaptured.completion.input,\n ).pipe(\n Effect.flatMap(Schema.decodeEffect(Schema.fromJsonString(CompletionInput))),\n Effect.mapError(unavailable),\n ),\n };\n\n if (\n (input.intent.action === \"reset-password\") !== (completion !== undefined) ||\n (completion !== undefined && configuration.proof === undefined)\n )\n return yield* unavailable();\n\n return yield* owned(\n Effect.gen(function* () {\n const transaction = yield* CurrentPasswordSql;\n const journal = yield* CurrentCommitJournal;\n\n yield* lockAnchor(mapping, configuration, input.intent.moduleId);\n\n const authority = yield* kernel.validateMutationAuthority(\n p,\n configuration,\n input.mutation,\n input.intent.action,\n );\n\n if (authority === undefined) return prepare(\"rejected\", journal);\n const current = yield* currentAuthority(mapping, configuration, input.intent);\n\n if (current === undefined) return prepare(\"rejected\", journal);\n\n const rows = yield* readIntent(\n mapping,\n and(eq(c.moduleId, input.intent.moduleId), eq(c.intentId, input.intent.intentId))!,\n configuration.locking,\n );\n\n const row = rows[0],\n encoded = yield* encodePasswordPreparedReady(input.intent);\n\n if (\n rows.length !== 1 ||\n !(yield* recordMatches(\n mapping,\n row,\n input.intent,\n current.nativeSubjectId,\n encoded,\n )) ||\n !evidenceCurrent(input, current.requirement, yield* nowMillis) ||\n (yield* kernel.commandExists(\n p,\n input.intent.moduleId,\n input.intent.commandId,\n configuration.locking,\n )).length !== 0\n )\n return prepare(\"rejected\", journal);\n if (\n completion !== undefined &&\n (input.intent.reset === undefined ||\n completion.input.continuationId !== input.intent.reset.continuationId ||\n bindingJson(completion.input.binding) !== bindingJson(input.intent.reset.binding) ||\n !kernel.proofCompletionMatchesPassword({ ...input.mutation, completion }))\n )\n return prepare(\"rejected\", journal);\n\n const credentialRevision = yield* kernel.allocate(\n configuration.mode,\n p.allocateRevision,\n p.allocateRevisionSync,\n );\n\n const verifierVersion = yield* kernel.allocate(\n configuration.mode,\n p.allocateRevision,\n p.allocateRevisionSync,\n );\n\n const nextSecurityRevision = yield* kernel.allocateNextSecurityRevision(\n p,\n configuration.mode,\n input.intent.revision.securityRevision,\n );\n\n if (\n nextSecurityRevision === input.intent.revision.securityRevision ||\n credentialRevision === input.intent.credential?.credentialRevision ||\n verifierVersion === input.intent.credential?.verifierVersion\n )\n return yield* unavailable();\n\n const credentialId =\n input.intent.action === \"add-password\"\n ? yield* kernel.allocate(\n configuration.mode,\n p.allocateCredentialId,\n p.allocateCredentialIdSync,\n )\n : undefined;\n\n let appliedAt: number | undefined;\n\n const assertApplied = Effect.fn(\"DrizzlePasswordPrepared.assertApplied\")(() =>\n Effect.flatMap(CurrentPasswordPreparedTransaction, (currentTransaction) =>\n Effect.gen(function* () {\n if (appliedAt === undefined) return;\n\n if (\n !(yield* kernel.checkMutationApplied(\n p,\n input.mutation,\n current.nativeSubjectId,\n {\n credentialId: credentialId ?? input.intent.credential!.credentialId,\n credentialRevision,\n verifierVersion,\n nextSecurityRevision,\n },\n appliedAt,\n )) ||\n (yield* readIntent(\n mapping,\n rowCondition(mapping, {\n ...row,\n [t.state]: t.states.Consumed,\n [t.snapshot]: null,\n [t.digest]: null,\n }),\n false,\n )).length !== 1 ||\n !evidenceCurrent(input, current.requirement, yield* nowMillis)\n )\n return yield* unavailable();\n }).pipe(Effect.provideService(CurrentPasswordSql, currentTransaction)),\n ),\n );\n\n const validateApplied = Effect.gen(function* () {\n yield* assertApplied().pipe(\n Effect.provideService(CurrentPasswordPreparedTransaction, transaction),\n );\n if (appliedAt === undefined) return;\n const postconditions = yield* Effect.serviceOption(PasswordPreparedPostconditions);\n\n if (\n Option.isSome(postconditions) &&\n !postconditions.value.register(assertApplied().pipe(translateFailure))\n )\n return yield* unavailable();\n });\n\n const apply = Effect.fn(\"DrizzlePasswordPrepared.apply\")(function* () {\n const finalNow = yield* nowMillis;\n\n if (!evidenceCurrent(input, current.requirement, finalNow)) return false;\n\n const changed =\n input.intent.action === \"add-password\"\n ? yield* kernel.addPasswordIn(\n p,\n configuration,\n input.mutation,\n {\n credentialId: credentialId!,\n credentialRevision,\n verifierVersion,\n nextSecurityRevision,\n },\n finalNow,\n )\n : yield* kernel.writeReplacement(\n p,\n input.mutation,\n current.nativeSubjectId,\n { credentialRevision, verifierVersion, nextSecurityRevision },\n finalNow,\n );\n\n if (!changed) return yield* unavailable();\n appliedAt = finalNow;\n yield* terminal(mapping, row, \"Consumed\");\n if (!evidenceCurrent(input, current.requirement, yield* nowMillis))\n return yield* unavailable();\n\n return true;\n });\n\n if (completion !== undefined) {\n let receipt: ReturnType<typeof prepare> | undefined;\n\n yield* completeProofPlanIn(\n configuration.proof!.mapping,\n configuration.proof!.configuration,\n completion,\n Effect.gen(function* () {\n return yield* apply();\n }),\n (decision) => {\n receipt = prepare(decision === \"completed\" ? \"changed\" : \"rejected\", journal);\n\n return decision;\n },\n );\n\n yield* validateApplied;\n\n return receipt ?? prepare(\"rejected\", journal);\n }\n\n const changed = yield* apply();\n\n yield* validateApplied;\n\n return prepare(changed ? \"changed\" : \"rejected\", journal);\n }),\n );\n });\n\n const services: PasswordPreparedPersistence = {\n reserve: (uncaptured, prepare) =>\n Effect.gen(function* () {\n const input = yield* snapshotReserve(uncaptured);\n\n if (\n (input.action === \"reset-password\") !==\n (input.reset !== undefined && input.completion !== undefined) ||\n (input.action === \"reset-password\" && configuration.proof === undefined) ||\n input.generation !== input.policy.generation ||\n input.policy.retentionMillis <\n Math.max(\n input.policy.preparationLifetimeMillis + input.policy.lifetimeMillis,\n input.policy.admission.action.windowMillis,\n input.policy.admission.identifier.windowMillis,\n input.policy.admission.subject.windowMillis,\n ) ||\n (input.invalidation.existingSessions === \"immediate\" &&\n p.sessionInvalidation !== \"same-authority-immediate\")\n )\n return yield* unavailable();\n\n return yield* owned(\n Effect.gen(function* () {\n const transaction = yield* CurrentPasswordSql;\n const journal = yield* CurrentCommitJournal;\n\n yield* lockAnchor(mapping, configuration, input.moduleId);\n\n const version = PasswordPreparedVersion.make(\n yield* kernel.allocate(\n configuration.mode,\n mapping.allocateVersion,\n mapping.allocateVersionSync,\n ),\n );\n\n const authority = yield* captureAuthority(mapping, configuration, input);\n\n if (authority === undefined) return yield* unavailable();\n if (input.reset !== undefined) {\n if (\n input.completion === undefined ||\n input.completion.moduleId !== `${input.moduleId}/reset` ||\n input.completion.purpose !== \"password-reset\" ||\n input.reset.continuationId !== input.completion.continuationId ||\n bindingJson(input.reset.binding) !== bindingJson(input.completion.binding) ||\n input.reset.binding._tag !== \"Subject\" ||\n !sameRevision(input.reset.binding.revision, authority.revision) ||\n authority.snapshot?.identifierVerifiedAtMillis === undefined ||\n !(yield* checkProofCompletionIn(\n configuration.proof!.mapping,\n configuration.proof!.configuration,\n input.completion,\n ))\n )\n return yield* unavailable();\n }\n if (\n (yield* readIntent(\n mapping,\n and(eq(c.moduleId, input.moduleId), eq(c.commandId, input.commandId))!,\n configuration.locking,\n )).length\n )\n return prepare({ _tag: \"Existing\" }, journal);\n\n const now = yield* nowMillis,\n nativeNow = p.encodeInstant(now);\n\n const scope = identifierScope({\n credential: authority.snapshot,\n revision: authority.revision,\n });\n\n const active =\n (yield* read(\n transaction\n .select({ total: count() })\n .from(t.table)\n .where(\n and(\n eq(c.moduleId, input.moduleId),\n eq(c.subjectId, authority.nativeSubjectId),\n or(\n and(\n eq(c.state, t.states.Preparing),\n gt(c.preparationExpiresAt, nativeNow),\n ),\n and(eq(c.state, t.states.Ready), gt(c.expiresAt, nativeNow)),\n ),\n ),\n ),\n false,\n ))[0]?.total ?? 0;\n\n if (active >= input.policy.maximumPendingPerSubject) return yield* unavailable();\n for (const [condition, budget] of [\n [eq(c.action, input.action), input.policy.admission.action],\n [eq(c.identifierScope, scope), input.policy.admission.identifier],\n [eq(c.subjectId, authority.nativeSubjectId), input.policy.admission.subject],\n ] as const) {\n const total =\n (yield* read(\n transaction\n .select({ total: count() })\n .from(t.table)\n .where(\n and(\n eq(c.moduleId, input.moduleId),\n condition,\n gt(c.admittedAt, p.encodeInstant(now - budget.windowMillis)),\n ),\n ),\n false,\n ))[0]?.total ?? 0;\n\n if (total >= budget.limit) return yield* unavailable();\n }\n\n const reservation = yield* snapshotPasswordPreparedReservation({\n _tag: \"Preparing\",\n moduleId: input.moduleId,\n generation: input.generation,\n intentId: input.intentId,\n version,\n commandId: input.commandId,\n action: input.action,\n revision: authority.revision,\n ...(authority.snapshot === undefined ? {} : { credential: authority.snapshot }),\n capturedRequirement: authority.requirement,\n ...(input.reset === undefined ? {} : { reset: input.reset }),\n invalidation: input.invalidation,\n createdAtMillis: now,\n preparationExpiresAtMillis: now + input.policy.preparationLifetimeMillis,\n retainUntilMillis: now + input.policy.retentionMillis,\n });\n\n const snapshot = yield* encodeReservation(reservation);\n\n yield* transaction.insert(t.table).values(\n t.encodeInsert({\n reservation,\n nativeSubjectId: authority.nativeSubjectId,\n identifierScope: scope,\n snapshot,\n admittedAtMillis: now,\n admissionRetainUntilMillis:\n now +\n Math.max(\n input.policy.admission.action.windowMillis,\n input.policy.admission.identifier.windowMillis,\n input.policy.admission.subject.windowMillis,\n ),\n }),\n );\n\n const rows = yield* readIntent(\n mapping,\n and(eq(c.moduleId, input.moduleId), eq(c.intentId, input.intentId))!,\n false,\n );\n\n if (\n rows.length !== 1 ||\n !(yield* recordMatches(\n mapping,\n rows[0],\n reservation,\n authority.nativeSubjectId,\n snapshot,\n ))\n )\n return yield* unavailable();\n\n const admittedUntil =\n now +\n Math.max(\n input.policy.admission.action.windowMillis,\n input.policy.admission.identifier.windowMillis,\n input.policy.admission.subject.windowMillis,\n );\n\n if (\n (yield* p.decodeInstant(rows[0][t.admittedAt])) !== now ||\n (yield* p.decodeInstant(rows[0][t.admissionRetainUntil])) !== admittedUntil ||\n (yield* nowMillis) >= reservation.preparationExpiresAtMillis ||\n (input.completion !== undefined &&\n !(yield* checkProofCompletionIn(\n configuration.proof!.mapping,\n configuration.proof!.configuration,\n input.completion,\n )))\n )\n return yield* unavailable();\n\n return prepare({ _tag: \"Reserved\", reservation }, journal);\n }),\n );\n }).pipe(\n Effect.provideService(CurrentPasswordSql, database),\n Effect.provideService(LifecycleHooks, hooks),\n translateFailure,\n ),\n publishReady: (uncaptured, prepare) =>\n Effect.gen(function* () {\n const reservation = yield* snapshotPasswordPreparedReservation(uncaptured.reservation),\n ready = yield* snapshotPasswordPreparedReady(uncaptured.ready);\n\n const snapshot = yield* encodeReservation(reservation),\n readySnapshot = yield* encodePasswordPreparedReady(ready);\n\n if ((yield* encodeReservation(reservationOf(ready))) !== snapshot)\n return yield* unavailable();\n\n return yield* owned(\n Effect.gen(function* () {\n const transaction = yield* CurrentPasswordSql;\n const journal = yield* CurrentCommitJournal;\n\n yield* lockAnchor(mapping, configuration, reservation.moduleId);\n const authority = yield* currentAuthority(mapping, configuration, reservation);\n\n if (authority === undefined) return prepare(\"rejected\", journal);\n\n const rows = yield* readIntent(\n mapping,\n and(eq(c.moduleId, reservation.moduleId), eq(c.intentId, reservation.intentId))!,\n configuration.locking,\n ),\n row = rows[0];\n\n const now = yield* nowMillis;\n\n if (\n rows.length !== 1 ||\n !(yield* recordMatches(\n mapping,\n row,\n reservation,\n authority.nativeSubjectId,\n snapshot,\n )) ||\n now < ready.issuedAtMillis ||\n now >= reservation.preparationExpiresAtMillis ||\n now >= ready.expiresAtMillis\n )\n return prepare(\"rejected\", journal);\n yield* transaction\n .update(t.table)\n .set(t.encodeReady({ ready, snapshot: readySnapshot }))\n .where(rowCondition(mapping, row));\n\n const saved = yield* readIntent(\n mapping,\n and(eq(c.moduleId, ready.moduleId), eq(c.intentId, ready.intentId))!,\n false,\n );\n\n if (\n saved.length !== 1 ||\n !(yield* recordMatches(\n mapping,\n saved[0],\n ready,\n authority.nativeSubjectId,\n readySnapshot,\n )) ||\n (yield* readIntent(\n mapping,\n and(\n eq(c.moduleId, ready.moduleId),\n eq(c.intentId, ready.intentId),\n eq(c.admittedAt, row[t.admittedAt]),\n eq(c.admissionRetainUntil, row[t.admissionRetainUntil]),\n )!,\n false,\n )).length !== 1\n )\n return yield* unavailable();\n if (\n (yield* nowMillis) >= reservation.preparationExpiresAtMillis ||\n (yield* nowMillis) >= ready.expiresAtMillis\n )\n return yield* unavailable();\n\n return prepare(\"published\", journal);\n }),\n );\n }).pipe(\n Effect.provideService(CurrentPasswordSql, database),\n Effect.provideService(LifecycleHooks, hooks),\n translateFailure,\n ),\n context: (uncaptured) =>\n Effect.gen(function* () {\n const input = yield* Schema.decodeEffect(ContextInput)({ ...uncaptured }).pipe(\n Effect.mapError(unavailable),\n );\n\n const record = yield* kernel.safeRead(\n database,\n configuration,\n Effect.gen(function* () {\n if (\n !valid(mapping) ||\n !(yield* lockAnchor(mapping, configuration, input.moduleId, false))\n )\n return undefined;\n\n const rows = yield* readIntent(\n mapping,\n and(\n eq(c.moduleId, input.moduleId),\n eq(c.generation, input.generation),\n eq(c.digest, input.digest),\n eq(c.state, t.states.Ready),\n )!,\n false,\n );\n\n if (rows.length !== 1) return undefined;\n const selected = yield* decodePasswordPreparedReady(rows[0][t.snapshot]);\n const authority = yield* currentAuthority(mapping, configuration, selected);\n\n if (authority === undefined) return undefined;\n\n const locked = yield* readIntent(\n mapping,\n rowCondition(mapping, rows[0]),\n configuration.locking,\n );\n\n const now = yield* nowMillis;\n\n if (\n locked.length !== 1 ||\n now < selected.issuedAtMillis ||\n now >= selected.expiresAtMillis ||\n selected.moduleId !== input.moduleId ||\n selected.generation !== input.generation ||\n selected.digest !== input.digest ||\n !(yield* recordMatches(\n mapping,\n locked[0],\n selected,\n authority.nativeSubjectId,\n yield* encodePasswordPreparedReady(selected),\n ))\n )\n return undefined;\n\n return { record: selected, currentRequirement: authority.requirement };\n }),\n );\n\n return record ?? (yield* PasswordRejected.make({}));\n }).pipe(\n Effect.provideService(CurrentPasswordSql, database),\n Effect.provideService(LifecycleHooks, hooks),\n translateContextFailure,\n ),\n complete: (input, prepare) =>\n complete(input, prepare).pipe(\n Effect.provideService(CurrentPasswordSql, database),\n Effect.provideService(LifecycleHooks, hooks),\n translateFailure,\n ),\n resetWithProof: (input, prepare) =>\n complete(input, prepare).pipe(\n Effect.provideService(CurrentPasswordSql, database),\n Effect.provideService(LifecycleHooks, hooks),\n translateFailure,\n ),\n cancel: (uncaptured, prepare) =>\n Effect.gen(function* () {\n const record = yield* snapshotPasswordPreparedReady(uncaptured.record),\n snapshot = yield* encodePasswordPreparedReady(record);\n\n return yield* owned(\n Effect.gen(function* () {\n const journal = yield* CurrentCommitJournal;\n\n yield* lockAnchor(mapping, configuration, record.moduleId);\n const authority = yield* currentAuthority(mapping, configuration, record);\n\n if (authority === undefined) return prepare(false, journal);\n\n const rows = yield* readIntent(\n mapping,\n and(eq(c.moduleId, record.moduleId), eq(c.intentId, record.intentId))!,\n configuration.locking,\n );\n\n const now = yield* nowMillis;\n\n if (\n rows.length !== 1 ||\n now < record.issuedAtMillis ||\n now >= record.expiresAtMillis ||\n !(yield* recordMatches(\n mapping,\n rows[0],\n record,\n authority.nativeSubjectId,\n snapshot,\n ))\n )\n return prepare(false, journal);\n yield* terminal(mapping, rows[0], \"Cancelled\");\n\n return prepare(true, journal);\n }),\n );\n }).pipe(\n Effect.provideService(CurrentPasswordSql, database),\n Effect.provideService(LifecycleHooks, hooks),\n translateFailure,\n ),\n cleanup: (uncaptured, prepare) =>\n Effect.gen(function* () {\n const input = { ...uncaptured };\n\n if (!Number.isSafeInteger(input.limit) || input.limit < 1 || input.limit > 1000)\n return yield* unavailable();\n\n return yield* owned(\n Effect.gen(function* () {\n const transaction = yield* CurrentPasswordSql;\n const journal = yield* CurrentCommitJournal;\n\n if (!(yield* lockAnchor(mapping, configuration, input.moduleId, false)))\n return prepare({ removed: 0, hasMore: false }, journal);\n const now = p.encodeInstant(yield* nowMillis);\n\n const due = and(\n eq(c.moduleId, input.moduleId),\n or(\n and(lte(c.retainUntil, now), lte(c.admissionRetainUntil, now)),\n and(\n isNotNull(c.snapshot),\n or(\n and(eq(c.state, t.states.Preparing), lte(c.preparationExpiresAt, now)),\n and(eq(c.state, t.states.Ready), lte(c.expiresAt, now)),\n ),\n ),\n ),\n )!;\n\n const rows = yield* read(\n transaction\n .select()\n .from(t.table)\n .where(due)\n .orderBy(c.createdAt, c.intentId)\n .limit(input.limit + 1),\n configuration.locking,\n );\n\n let removed = 0;\n\n for (const row of rows.slice(0, input.limit)) {\n const expired =\n (yield* readIntent(\n mapping,\n and(\n rowCondition(mapping, row),\n lte(c.retainUntil, now),\n lte(c.admissionRetainUntil, now),\n )!,\n false,\n )).length === 1;\n\n if (expired) {\n yield* transaction.delete(t.table).where(rowCondition(mapping, row));\n if (\n (yield* readIntent(\n mapping,\n and(eq(c.moduleId, input.moduleId), eq(c.intentId, row[t.intentId]))!,\n false,\n )).length\n )\n return yield* unavailable();\n removed++;\n } else yield* terminal(mapping, row, \"Expired\");\n }\n\n return prepare(\n {\n removed,\n hasMore:\n (yield* read(transaction.select().from(t.table).where(due).limit(1), false))\n .length > 0,\n },\n journal,\n );\n }),\n );\n }).pipe(\n Effect.provideService(CurrentPasswordSql, database),\n Effect.provideService(LifecycleHooks, hooks),\n translateFailure,\n ),\n };\n\n return services;\n },\n);\n\nexport const passwordPreparedSqlKernel = {\n columns,\n recordMatches,\n captureAuthority,\n currentAuthority,\n rowCondition,\n valid,\n identifierScope,\n};\n"],"mappings":";;;;;;;;;;;;;;;AA0DA,MAAM,oBACJ,WAEA,yBACE,SACC,UACC,OAAO,GAAG,mBAAmB,CAAC,CAAC,KAAK,KACpC,OAAO,GAAG,gBAAgB,CAAC,CAAC,KAAK,KACjC,OAAO,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;EACF,CAAC,CAAC,CAAC,KACD,OAAO,eAAe,oBAAoB,QAAQ,GAClD,OAAO,eAAe,gBAAgB,KAAK,GAC3C,gBACF;CAGU;AAChB,CACF;AAEA,MAAa,4BAA4B;CACvC;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
|
|
1
|
+
{"version":3,"file":"password-prepared-sql.mjs","names":["kernel"],"sources":["../../src/drizzle/password-prepared-sql.ts"],"sourcesContent":["import {\n type NativeDatabase,\n CurrentPasswordPreparedTransaction,\n PasswordPreparedPostconditions,\n PasswordPreparedJournalGuards,\n} from \"@yielded/auth-persistence/Adapter\";\nimport { CurrentCommitJournal, LifecycleHooks, HookConfigurationError } from \"@yielded/auth/Hooks\";\nimport {\n PasswordUnavailable,\n PasswordRejected,\n PasswordPreparedVersion,\n decodePasswordPreparedReady,\n encodePasswordPreparedReady,\n snapshotPasswordPreparedReady,\n snapshotPasswordPreparedReservation,\n type PasswordPreparedReady,\n type PasswordPreparedReservation,\n snapshotPasswordCredential,\n snapshotPasswordRequirement,\n type PasswordMutationDecision,\n type PreparePasswordCommit,\n type PasswordPreparedPersistence,\n type PasswordPreparedMutation,\n} from \"@yielded/auth/Password\";\nimport { reportPersistenceFailure } from \"@yielded/auth/Persistence\";\nimport { type ProofCompletionPlan, ProofUnavailable, ProofBinding } from \"@yielded/auth/Proofs\";\nimport { AuthenticationRevision } from \"@yielded/auth/Sessions\";\n/* oxlint-disable no-explicit-any -- concrete driver makers retain consumer table types. */\nimport { and, count, eq, gt, isNotNull, isNull, lte, or, type SQL } from \"drizzle-orm\";\nimport { Cause, DateTime, Effect, Option, Predicate, Redacted, Schema } from \"effect\";\n\nimport { column } from \"./model\";\nimport {\n requiredPasswordPreparedConstraints,\n type AnyPasswordPreparedPersistenceMapping,\n type PasswordPreparedState,\n} from \"./password-prepared-model\";\nimport {\n ContextInput,\n CompletionInput,\n encodeReservation,\n evidenceCurrent,\n identifierScope,\n reservationOf,\n sameRevision,\n snapshotMutation,\n snapshotReserve,\n unavailable,\n} from \"./password-prepared-state\";\nimport {\n CurrentPasswordSql,\n passwordSqlKernel as kernel,\n type PasswordSqlConfiguration,\n type PasswordSqlQuery,\n} from \"./password-sql\";\nimport { checkProofCompletionIn, completeProofPlanIn } from \"./proof-sql\";\nimport { validateDrizzleStorage } from \"./storage-validation\";\n\nconst translateFailure = <A, E, R>(\n effect: Effect.Effect<A, E, R>,\n): Effect.Effect<A, PasswordUnavailable, R> =>\n reportPersistenceFailure(\n effect,\n (error) =>\n Schema.is(PasswordUnavailable)(error) ||\n Schema.is(ProofUnavailable)(error) ||\n Schema.is(HookConfigurationError)(error),\n ).pipe(Effect.catchCause((cause) => Effect.failCause(Cause.map(cause, () => unavailable()))));\n\nconst translateContextFailure = <A, E, R>(\n effect: Effect.Effect<A, E, R>,\n): Effect.Effect<A, PasswordUnavailable | PasswordRejected, R> =>\n reportPersistenceFailure(\n effect,\n (error) =>\n Schema.is(PasswordUnavailable)(error) ||\n Schema.is(PasswordRejected)(error) ||\n Schema.is(ProofUnavailable)(error) ||\n Schema.is(HookConfigurationError)(error),\n ).pipe(\n Effect.catchCause((cause) =>\n Effect.failCause(\n Cause.map(cause, (error) => (Schema.is(PasswordRejected)(error) ? error : unavailable())),\n ),\n ),\n );\n\ntype Mapping = AnyPasswordPreparedPersistenceMapping;\nconst nowMillis = DateTime.now.pipe(Effect.map(DateTime.toEpochMillis));\n\nconst read = (query: PasswordSqlQuery, locking: boolean) =>\n locking && typeof query.for === \"function\" ? query.for(\"update\") : query;\n\nconst columns = (mapping: Mapping) => {\n const table = mapping.intent;\n\n return {\n moduleId: column(table.table, table.moduleId),\n intentId: column(table.table, table.intentId),\n commandId: column(table.table, table.commandId),\n subjectId: column(table.table, table.subjectId),\n action: column(table.table, table.action),\n generation: column(table.table, table.generation),\n version: column(table.table, table.version),\n state: column(table.table, table.state),\n digest: column(table.table, table.digest),\n snapshot: column(table.table, table.snapshot),\n identifierScope: column(table.table, table.identifierScope),\n createdAt: column(table.table, table.createdAt),\n admittedAt: column(table.table, table.admittedAt),\n admissionRetainUntil: column(table.table, table.admissionRetainUntil),\n preparationExpiresAt: column(table.table, table.preparationExpiresAt),\n expiresAt: column(table.table, table.expiresAt),\n retainUntil: column(table.table, table.retainUntil),\n };\n};\n\nconst valid = (mapping: Mapping) =>\n Object.entries(requiredPasswordPreparedConstraints).every(\n ([key, value]) =>\n mapping.constraints[key as keyof typeof requiredPasswordPreparedConstraints] === value,\n );\n\nconst lockAnchor = Effect.fn(\"DrizzlePasswordPrepared.lockAnchor\")(function* (\n mapping: Mapping,\n configuration: PasswordSqlConfiguration,\n moduleId: string,\n create = true,\n) {\n const database = yield* CurrentPasswordSql;\n\n const a = mapping.admission,\n key = column(a.table, a.moduleId);\n\n if (create)\n yield* configuration.insertIfAbsent(\n database.insert(a.table).values(a.encodeInsert(moduleId)),\n a.moduleId,\n moduleId,\n );\n\n const rows = yield* read(\n database.select().from(a.table).where(eq(key, moduleId)).limit(2),\n configuration.locking,\n );\n\n if (rows.length > 1 || (create && rows.length !== 1)) return yield* unavailable();\n\n return rows.length === 1;\n});\n\nconst bindingJson = Schema.encodeSync(Schema.fromJsonString(ProofBinding));\n\nconst captureAuthority = Effect.fn(\"DrizzlePasswordPrepared.captureAuthority\")(function* (\n mapping: Mapping,\n configuration: Pick<PasswordSqlConfiguration, \"locking\">,\n input: {\n readonly moduleId: string;\n readonly action: PasswordPreparedReservation[\"action\"];\n readonly subjectId: string;\n readonly reset?: PasswordPreparedReservation[\"reset\"];\n },\n) {\n const database = yield* CurrentPasswordSql;\n\n const p = mapping.password;\n const locked = yield* kernel.lockSubject(p, input.subjectId, configuration.locking);\n\n if (locked.row === undefined || !p.subject.isActiveStatus(locked.row[p.subject.status]))\n return undefined;\n\n const ic = kernel.identifierColumns(p),\n ac = kernel.authorityCredentialColumns(p);\n\n let identifier: any;\n\n if (input.action !== \"add-password\") {\n if (input.reset !== undefined)\n identifier = (yield* kernel.lockIdentifier(\n p,\n input.reset.binding.identifier,\n configuration.locking,\n ))[0];\n else {\n const discovered = (yield* read(\n database\n .select()\n .from(p.identifier.table)\n .where(eq(ic.subjectId, locked.nativeSubjectId))\n .orderBy(ic.namespace, ic.value),\n false,\n )).find((row: any) => p.identifier.isCurrent(row));\n\n if (discovered !== undefined)\n identifier = (yield* kernel.lockIdentifier(\n p,\n {\n namespace: discovered[p.identifier.namespace],\n value: discovered[p.identifier.value],\n } as any,\n configuration.locking,\n ))[0];\n }\n if (\n identifier === undefined ||\n !p.identifier.isCurrent(identifier) ||\n !p.subjectId.equals(identifier[p.identifier.subjectId], locked.nativeSubjectId)\n )\n return undefined;\n }\n\n const credential = (yield* kernel.readPasswordCredential(\n p,\n input.moduleId,\n locked.nativeSubjectId,\n configuration.locking,\n ))[0];\n\n if ((input.action === \"add-password\") !== (credential === undefined)) return undefined;\n\n const snapshot =\n credential === undefined\n ? undefined\n : yield* p.credential\n .decode({ moduleId: input.moduleId, subject: locked.row, identifier, credential })\n .pipe(Effect.flatMap(snapshotPasswordCredential));\n\n if (\n snapshot !== undefined &&\n (snapshot.moduleId !== input.moduleId ||\n snapshot.revision.subjectId !== input.subjectId ||\n snapshot.revision.securityRevision !== locked.row[p.subject.securityRevision] ||\n snapshot.credentialId !== credential[p.credential.credentialId] ||\n snapshot.credentialRevision !== credential[p.credential.credentialRevision] ||\n snapshot.verifierVersion !== credential[p.credential.verifierVersion] ||\n Redacted.value(snapshot.verifier) !== credential[p.credential.verifier] ||\n snapshot.normalization !== credential[p.credential.normalization] ||\n snapshot.identifier.namespace !== identifier[p.identifier.namespace] ||\n snapshot.identifier.value !== identifier[p.identifier.value] ||\n snapshot.identifierBindingRevision !== identifier[p.identifier.bindingRevision])\n )\n return undefined;\n\n const factors = yield* read(\n database\n .select()\n .from(p.authorityCredential.table)\n .where(eq(ac.subjectId, locked.nativeSubjectId))\n .orderBy(ac.credentialId),\n configuration.locking,\n );\n\n const active = factors.filter(\n (row: any) =>\n p.authorityCredential.status === undefined ||\n p.authorityCredential.isActiveStatus?.(row[p.authorityCredential.status]) === true,\n );\n\n if (active.length > 64) return yield* unavailable();\n\n const revision =\n snapshot?.revision ??\n AuthenticationRevision.make({\n subjectId: input.subjectId as any,\n securityRevision: locked.row[p.subject.securityRevision],\n credentials: active.map((row: any) => ({\n credentialId: row[p.authorityCredential.credentialId],\n revision: row[p.authorityCredential.revision],\n })),\n });\n\n if (\n revision.credentials.some(\n (expected) =>\n !active.some(\n (row: any) =>\n row[p.authorityCredential.credentialId] === expected.credentialId &&\n row[p.authorityCredential.revision] === expected.revision,\n ),\n )\n )\n return undefined;\n\n const requirement = yield* p.subject\n .decodeActionRequirement(locked.row, input.action)\n .pipe(Effect.flatMap(snapshotPasswordRequirement));\n\n return { ...locked, identifier, snapshot, revision, requirement };\n});\n\nconst currentAuthority = Effect.fn(\"DrizzlePasswordPrepared.currentAuthority\")(function* (\n mapping: Mapping,\n configuration: Pick<PasswordSqlConfiguration, \"locking\">,\n record: PasswordPreparedReservation | PasswordPreparedReady,\n) {\n const current = yield* captureAuthority(mapping, configuration, {\n moduleId: record.moduleId,\n action: record.action,\n subjectId: record.revision.subjectId,\n ...(record.reset === undefined ? {} : { reset: record.reset }),\n });\n\n if (\n current === undefined ||\n !sameRevision(current.revision, record.revision) ||\n (current.snapshot === undefined\n ? record.credential !== undefined\n : record.credential === undefined ||\n !kernel.sameCredentialSnapshot(current.snapshot, record.credential))\n )\n return undefined;\n\n return current;\n});\n\nconst rowCondition = (mapping: Mapping, row: any) => {\n const c = columns(mapping);\n\n return and(\n ...Object.entries(c).map(([key, value]) => {\n const field = mapping.intent[key as keyof typeof c],\n item = row[field];\n\n return Predicate.isNullish(item) ? isNull(value) : eq(value, item);\n }),\n )!;\n};\n\nconst readIntent = Effect.fn(\"Drizzle.readIntent\")(function* (\n mapping: Mapping,\n condition: SQL,\n locking: boolean,\n) {\n const database = yield* CurrentPasswordSql;\n\n return yield* read(\n database.select().from(mapping.intent.table).where(condition).limit(2),\n locking,\n );\n});\n\nconst recordMatches = Effect.fn(\"DrizzlePasswordPrepared.recordMatches\")(function* (\n mapping: Mapping,\n row: any,\n record: PasswordPreparedReservation | PasswordPreparedReady,\n nativeSubjectId: unknown,\n snapshot: string,\n) {\n const t = mapping.intent,\n p = mapping.password;\n\n if (\n row === undefined ||\n row[t.moduleId] !== record.moduleId ||\n row[t.intentId] !== record.intentId ||\n row[t.commandId] !== record.commandId ||\n !p.subjectId.equals(row[t.subjectId], nativeSubjectId) ||\n row[t.action] !== record.action ||\n row[t.generation] !== record.generation ||\n row[t.version] !== record.version ||\n row[t.state] !== t.states[record._tag] ||\n row[t.snapshot] !== snapshot ||\n row[t.identifierScope] !== identifierScope(record) ||\n (record._tag === \"Ready\"\n ? row[t.digest] !== record.digest\n : !Predicate.isNullish(row[t.digest]))\n )\n return false;\n for (const [key, instant] of [\n [t.createdAt, record.createdAtMillis],\n [t.preparationExpiresAt, record.preparationExpiresAtMillis],\n [t.retainUntil, record.retainUntilMillis],\n ] as const)\n if ((yield* p.decodeInstant(row[key])) !== instant) return false;\n\n return record._tag === \"Ready\"\n ? (yield* p.decodeInstant(row[t.expiresAt])) === record.expiresAtMillis\n : Predicate.isNullish(row[t.expiresAt]);\n});\n\nconst terminal = Effect.fn(\"DrizzlePasswordPrepared.terminal\")(function* (\n mapping: Mapping,\n row: any,\n state: Exclude<PasswordPreparedState, \"Preparing\" | \"Ready\">,\n) {\n const database = yield* CurrentPasswordSql;\n\n yield* database\n .update(mapping.intent.table)\n .set(mapping.intent.encodeTerminal(state))\n .where(rowCondition(mapping, row));\n\n const c = columns(mapping),\n t = mapping.intent;\n\n const rows = yield* readIntent(\n mapping,\n and(eq(c.moduleId, row[t.moduleId]), eq(c.intentId, row[t.intentId]))!,\n false,\n );\n\n const expected = { ...row, [t.state]: t.states[state], [t.snapshot]: null, [t.digest]: null };\n\n if (\n rows.length !== 1 ||\n (yield* readIntent(mapping, rowCondition(mapping, expected), false)).length !== 1\n )\n return yield* unavailable();\n});\n\nexport const makeSqlPasswordPreparedPersistence = Effect.fn(\"makeSqlPasswordPreparedPersistence\")(\n function* (\n mapping: Mapping,\n configuration: PasswordSqlConfiguration,\n ): Effect.fn.Return<\n PasswordPreparedPersistence,\n PasswordUnavailable,\n LifecycleHooks | CurrentPasswordSql | NativeDatabase\n > {\n const database = yield* CurrentPasswordSql;\n\n if (!configuration.coordinated)\n yield* validateDrizzleStorage({\n ...mapping,\n proof: configuration.proof?.mapping,\n }).pipe(Effect.mapError(unavailable));\n const hooks = yield* LifecycleHooks;\n\n const p = mapping.password,\n c = columns(mapping),\n t = mapping.intent;\n\n const owned = <A, E, R>(body: Effect.Effect<A, E, R>) =>\n valid(mapping)\n ? kernel.owned(\n database,\n p,\n configuration,\n Effect.gen(function* () {\n const journal = yield* CurrentCommitJournal;\n const guards = yield* Effect.serviceOption(PasswordPreparedJournalGuards);\n\n if (Option.isSome(guards) && !guards.value.register(journal.prepare(undefined)))\n return yield* unavailable();\n\n return yield* body;\n }),\n )\n : Effect.fail(unavailable());\n\n const complete = <A>(\n uncaptured: PasswordPreparedMutation & { readonly completion?: ProofCompletionPlan },\n prepare: PreparePasswordCommit<PasswordMutationDecision, A>,\n ) =>\n Effect.gen(function* () {\n const input = yield* snapshotMutation(uncaptured);\n\n const completion =\n uncaptured.completion === undefined\n ? undefined\n : {\n prepare: uncaptured.completion.prepare,\n input: yield* Schema.encodeEffect(Schema.fromJsonString(CompletionInput))(\n uncaptured.completion.input,\n ).pipe(\n Effect.flatMap(Schema.decodeEffect(Schema.fromJsonString(CompletionInput))),\n Effect.mapError(unavailable),\n ),\n };\n\n if (\n (input.intent.action === \"reset-password\") !== (completion !== undefined) ||\n (completion !== undefined && configuration.proof === undefined)\n )\n return yield* unavailable();\n\n return yield* owned(\n Effect.gen(function* () {\n const transaction = yield* CurrentPasswordSql;\n const journal = yield* CurrentCommitJournal;\n\n yield* lockAnchor(mapping, configuration, input.intent.moduleId);\n\n const authority = yield* kernel.validateMutationAuthority(\n p,\n configuration,\n input.mutation,\n input.intent.action,\n );\n\n if (authority === undefined) return prepare(\"rejected\", journal);\n const current = yield* currentAuthority(mapping, configuration, input.intent);\n\n if (current === undefined) return prepare(\"rejected\", journal);\n\n const rows = yield* readIntent(\n mapping,\n and(eq(c.moduleId, input.intent.moduleId), eq(c.intentId, input.intent.intentId))!,\n configuration.locking,\n );\n\n const row = rows[0],\n encoded = yield* encodePasswordPreparedReady(input.intent);\n\n if (\n rows.length !== 1 ||\n !(yield* recordMatches(\n mapping,\n row,\n input.intent,\n current.nativeSubjectId,\n encoded,\n )) ||\n !evidenceCurrent(input, current.requirement, yield* nowMillis) ||\n (yield* kernel.commandExists(\n p,\n input.intent.moduleId,\n input.intent.commandId,\n configuration.locking,\n )).length !== 0\n )\n return prepare(\"rejected\", journal);\n if (\n completion !== undefined &&\n (input.intent.reset === undefined ||\n completion.input.continuationId !== input.intent.reset.continuationId ||\n bindingJson(completion.input.binding) !== bindingJson(input.intent.reset.binding) ||\n !kernel.proofCompletionMatchesPassword({ ...input.mutation, completion }))\n )\n return prepare(\"rejected\", journal);\n\n const credentialRevision = yield* kernel.allocate(\n configuration.mode,\n p.allocateRevision,\n p.allocateRevisionSync,\n );\n\n const verifierVersion = yield* kernel.allocate(\n configuration.mode,\n p.allocateRevision,\n p.allocateRevisionSync,\n );\n\n const nextSecurityRevision = yield* kernel.allocateNextSecurityRevision(\n p,\n configuration.mode,\n input.intent.revision.securityRevision,\n );\n\n if (\n nextSecurityRevision === input.intent.revision.securityRevision ||\n credentialRevision === input.intent.credential?.credentialRevision ||\n verifierVersion === input.intent.credential?.verifierVersion\n )\n return yield* unavailable();\n\n const credentialId =\n input.intent.action === \"add-password\"\n ? yield* kernel.allocate(\n configuration.mode,\n p.allocateCredentialId,\n p.allocateCredentialIdSync,\n )\n : undefined;\n\n let appliedAt: number | undefined;\n\n const assertApplied = Effect.fn(\"DrizzlePasswordPrepared.assertApplied\")(() =>\n Effect.flatMap(CurrentPasswordPreparedTransaction, (currentTransaction) =>\n Effect.gen(function* () {\n if (appliedAt === undefined) return;\n\n if (\n !(yield* kernel.checkMutationApplied(\n p,\n input.mutation,\n current.nativeSubjectId,\n {\n credentialId: credentialId ?? input.intent.credential!.credentialId,\n credentialRevision,\n verifierVersion,\n nextSecurityRevision,\n },\n appliedAt,\n )) ||\n (yield* readIntent(\n mapping,\n rowCondition(mapping, {\n ...row,\n [t.state]: t.states.Consumed,\n [t.snapshot]: null,\n [t.digest]: null,\n }),\n false,\n )).length !== 1 ||\n !evidenceCurrent(input, current.requirement, yield* nowMillis)\n )\n return yield* unavailable();\n }).pipe(Effect.provideService(CurrentPasswordSql, currentTransaction)),\n ),\n );\n\n const validateApplied = Effect.gen(function* () {\n yield* assertApplied().pipe(\n Effect.provideService(CurrentPasswordPreparedTransaction, transaction),\n );\n if (appliedAt === undefined) return;\n const postconditions = yield* Effect.serviceOption(PasswordPreparedPostconditions);\n\n if (\n Option.isSome(postconditions) &&\n !postconditions.value.register(assertApplied().pipe(translateFailure))\n )\n return yield* unavailable();\n });\n\n const apply = Effect.fn(\"DrizzlePasswordPrepared.apply\")(function* () {\n const finalNow = yield* nowMillis;\n\n if (!evidenceCurrent(input, current.requirement, finalNow)) return false;\n\n const changed =\n input.intent.action === \"add-password\"\n ? yield* kernel.addPasswordIn(\n p,\n configuration,\n input.mutation,\n {\n credentialId: credentialId!,\n credentialRevision,\n verifierVersion,\n nextSecurityRevision,\n },\n finalNow,\n )\n : yield* kernel.writeReplacement(\n p,\n input.mutation,\n current.nativeSubjectId,\n { credentialRevision, verifierVersion, nextSecurityRevision },\n finalNow,\n );\n\n if (!changed) return yield* unavailable();\n appliedAt = finalNow;\n yield* terminal(mapping, row, \"Consumed\");\n if (!evidenceCurrent(input, current.requirement, yield* nowMillis))\n return yield* unavailable();\n\n return true;\n });\n\n if (completion !== undefined) {\n let receipt: ReturnType<typeof prepare> | undefined;\n\n yield* completeProofPlanIn(\n configuration.proof!.mapping,\n configuration.proof!.configuration,\n completion,\n Effect.gen(function* () {\n return yield* apply();\n }),\n (decision) => {\n receipt = prepare(decision === \"completed\" ? \"changed\" : \"rejected\", journal);\n\n return decision;\n },\n );\n\n yield* validateApplied;\n\n return receipt ?? prepare(\"rejected\", journal);\n }\n\n const changed = yield* apply();\n\n yield* validateApplied;\n\n return prepare(changed ? \"changed\" : \"rejected\", journal);\n }),\n );\n });\n\n const services: PasswordPreparedPersistence = {\n reserve: (uncaptured, prepare) =>\n Effect.gen(function* () {\n const input = yield* snapshotReserve(uncaptured);\n\n if (\n (input.action === \"reset-password\") !==\n (input.reset !== undefined && input.completion !== undefined) ||\n (input.action === \"reset-password\" && configuration.proof === undefined) ||\n input.generation !== input.policy.generation ||\n input.policy.retentionMillis <\n Math.max(\n input.policy.preparationLifetimeMillis + input.policy.lifetimeMillis,\n input.policy.admission.action.windowMillis,\n input.policy.admission.identifier.windowMillis,\n input.policy.admission.subject.windowMillis,\n ) ||\n (input.invalidation.existingSessions === \"immediate\" &&\n p.sessionInvalidation !== \"same-authority-immediate\")\n )\n return yield* unavailable();\n\n return yield* owned(\n Effect.gen(function* () {\n const transaction = yield* CurrentPasswordSql;\n const journal = yield* CurrentCommitJournal;\n\n yield* lockAnchor(mapping, configuration, input.moduleId);\n\n const version = PasswordPreparedVersion.make(\n yield* kernel.allocate(\n configuration.mode,\n mapping.allocateVersion,\n mapping.allocateVersionSync,\n ),\n );\n\n const authority = yield* captureAuthority(mapping, configuration, input);\n\n if (authority === undefined) return yield* unavailable();\n if (input.reset !== undefined) {\n if (\n input.completion === undefined ||\n input.completion.moduleId !== `${input.moduleId}/reset` ||\n input.completion.purpose !== \"password-reset\" ||\n input.reset.continuationId !== input.completion.continuationId ||\n bindingJson(input.reset.binding) !== bindingJson(input.completion.binding) ||\n input.reset.binding._tag !== \"Subject\" ||\n !sameRevision(input.reset.binding.revision, authority.revision) ||\n authority.snapshot?.identifierVerifiedAtMillis === undefined ||\n !(yield* checkProofCompletionIn(\n configuration.proof!.mapping,\n configuration.proof!.configuration,\n input.completion,\n ))\n )\n return yield* unavailable();\n }\n if (\n (yield* readIntent(\n mapping,\n and(eq(c.moduleId, input.moduleId), eq(c.commandId, input.commandId))!,\n configuration.locking,\n )).length\n )\n return prepare({ _tag: \"Existing\" }, journal);\n\n const now = yield* nowMillis,\n nativeNow = p.encodeInstant(now);\n\n const scope = identifierScope({\n ...(authority.snapshot === undefined ? {} : { credential: authority.snapshot }),\n revision: authority.revision,\n });\n\n const active =\n (yield* read(\n transaction\n .select({ total: count() })\n .from(t.table)\n .where(\n and(\n eq(c.moduleId, input.moduleId),\n eq(c.subjectId, authority.nativeSubjectId),\n or(\n and(\n eq(c.state, t.states.Preparing),\n gt(c.preparationExpiresAt, nativeNow),\n ),\n and(eq(c.state, t.states.Ready), gt(c.expiresAt, nativeNow)),\n ),\n ),\n ),\n false,\n ))[0]?.total ?? 0;\n\n if (active >= input.policy.maximumPendingPerSubject) return yield* unavailable();\n for (const [condition, budget] of [\n [eq(c.action, input.action), input.policy.admission.action],\n [eq(c.identifierScope, scope), input.policy.admission.identifier],\n [eq(c.subjectId, authority.nativeSubjectId), input.policy.admission.subject],\n ] as const) {\n const total =\n (yield* read(\n transaction\n .select({ total: count() })\n .from(t.table)\n .where(\n and(\n eq(c.moduleId, input.moduleId),\n condition,\n gt(c.admittedAt, p.encodeInstant(now - budget.windowMillis)),\n ),\n ),\n false,\n ))[0]?.total ?? 0;\n\n if (total >= budget.limit) return yield* unavailable();\n }\n\n const reservation = yield* snapshotPasswordPreparedReservation({\n _tag: \"Preparing\",\n moduleId: input.moduleId,\n generation: input.generation,\n intentId: input.intentId,\n version,\n commandId: input.commandId,\n action: input.action,\n revision: authority.revision,\n ...(authority.snapshot === undefined ? {} : { credential: authority.snapshot }),\n capturedRequirement: authority.requirement,\n ...(input.reset === undefined ? {} : { reset: input.reset }),\n invalidation: input.invalidation,\n createdAtMillis: now,\n preparationExpiresAtMillis: now + input.policy.preparationLifetimeMillis,\n retainUntilMillis: now + input.policy.retentionMillis,\n });\n\n const snapshot = yield* encodeReservation(reservation);\n\n yield* transaction.insert(t.table).values(\n t.encodeInsert({\n reservation,\n nativeSubjectId: authority.nativeSubjectId,\n identifierScope: scope,\n snapshot,\n admittedAtMillis: now,\n admissionRetainUntilMillis:\n now +\n Math.max(\n input.policy.admission.action.windowMillis,\n input.policy.admission.identifier.windowMillis,\n input.policy.admission.subject.windowMillis,\n ),\n }),\n );\n\n const rows = yield* readIntent(\n mapping,\n and(eq(c.moduleId, input.moduleId), eq(c.intentId, input.intentId))!,\n false,\n );\n\n if (\n rows.length !== 1 ||\n !(yield* recordMatches(\n mapping,\n rows[0],\n reservation,\n authority.nativeSubjectId,\n snapshot,\n ))\n )\n return yield* unavailable();\n\n const admittedUntil =\n now +\n Math.max(\n input.policy.admission.action.windowMillis,\n input.policy.admission.identifier.windowMillis,\n input.policy.admission.subject.windowMillis,\n );\n\n if (\n (yield* p.decodeInstant(rows[0][t.admittedAt])) !== now ||\n (yield* p.decodeInstant(rows[0][t.admissionRetainUntil])) !== admittedUntil ||\n (yield* nowMillis) >= reservation.preparationExpiresAtMillis ||\n (input.completion !== undefined &&\n !(yield* checkProofCompletionIn(\n configuration.proof!.mapping,\n configuration.proof!.configuration,\n input.completion,\n )))\n )\n return yield* unavailable();\n\n return prepare({ _tag: \"Reserved\", reservation }, journal);\n }),\n );\n }).pipe(\n Effect.provideService(CurrentPasswordSql, database),\n Effect.provideService(LifecycleHooks, hooks),\n translateFailure,\n ),\n publishReady: (uncaptured, prepare) =>\n Effect.gen(function* () {\n const reservation = yield* snapshotPasswordPreparedReservation(uncaptured.reservation),\n ready = yield* snapshotPasswordPreparedReady(uncaptured.ready);\n\n const snapshot = yield* encodeReservation(reservation),\n readySnapshot = yield* encodePasswordPreparedReady(ready);\n\n if ((yield* encodeReservation(reservationOf(ready))) !== snapshot)\n return yield* unavailable();\n\n return yield* owned(\n Effect.gen(function* () {\n const transaction = yield* CurrentPasswordSql;\n const journal = yield* CurrentCommitJournal;\n\n yield* lockAnchor(mapping, configuration, reservation.moduleId);\n const authority = yield* currentAuthority(mapping, configuration, reservation);\n\n if (authority === undefined) return prepare(\"rejected\", journal);\n\n const rows = yield* readIntent(\n mapping,\n and(eq(c.moduleId, reservation.moduleId), eq(c.intentId, reservation.intentId))!,\n configuration.locking,\n ),\n row = rows[0];\n\n const now = yield* nowMillis;\n\n if (\n rows.length !== 1 ||\n !(yield* recordMatches(\n mapping,\n row,\n reservation,\n authority.nativeSubjectId,\n snapshot,\n )) ||\n now < ready.issuedAtMillis ||\n now >= reservation.preparationExpiresAtMillis ||\n now >= ready.expiresAtMillis\n )\n return prepare(\"rejected\", journal);\n yield* transaction\n .update(t.table)\n .set(t.encodeReady({ ready, snapshot: readySnapshot }))\n .where(rowCondition(mapping, row));\n\n const saved = yield* readIntent(\n mapping,\n and(eq(c.moduleId, ready.moduleId), eq(c.intentId, ready.intentId))!,\n false,\n );\n\n if (\n saved.length !== 1 ||\n !(yield* recordMatches(\n mapping,\n saved[0],\n ready,\n authority.nativeSubjectId,\n readySnapshot,\n )) ||\n (yield* readIntent(\n mapping,\n and(\n eq(c.moduleId, ready.moduleId),\n eq(c.intentId, ready.intentId),\n eq(c.admittedAt, row[t.admittedAt]),\n eq(c.admissionRetainUntil, row[t.admissionRetainUntil]),\n )!,\n false,\n )).length !== 1\n )\n return yield* unavailable();\n if (\n (yield* nowMillis) >= reservation.preparationExpiresAtMillis ||\n (yield* nowMillis) >= ready.expiresAtMillis\n )\n return yield* unavailable();\n\n return prepare(\"published\", journal);\n }),\n );\n }).pipe(\n Effect.provideService(CurrentPasswordSql, database),\n Effect.provideService(LifecycleHooks, hooks),\n translateFailure,\n ),\n context: (uncaptured) =>\n Effect.gen(function* () {\n const input = yield* Schema.decodeEffect(ContextInput)({ ...uncaptured }).pipe(\n Effect.mapError(unavailable),\n );\n\n const record = yield* kernel.safeRead(\n database,\n configuration,\n Effect.gen(function* () {\n if (\n !valid(mapping) ||\n !(yield* lockAnchor(mapping, configuration, input.moduleId, false))\n )\n return undefined;\n\n const rows = yield* readIntent(\n mapping,\n and(\n eq(c.moduleId, input.moduleId),\n eq(c.generation, input.generation),\n eq(c.digest, input.digest),\n eq(c.state, t.states.Ready),\n )!,\n false,\n );\n\n if (rows.length !== 1) return undefined;\n const selected = yield* decodePasswordPreparedReady(rows[0][t.snapshot]);\n const authority = yield* currentAuthority(mapping, configuration, selected);\n\n if (authority === undefined) return undefined;\n\n const locked = yield* readIntent(\n mapping,\n rowCondition(mapping, rows[0]),\n configuration.locking,\n );\n\n const now = yield* nowMillis;\n\n if (\n locked.length !== 1 ||\n now < selected.issuedAtMillis ||\n now >= selected.expiresAtMillis ||\n selected.moduleId !== input.moduleId ||\n selected.generation !== input.generation ||\n selected.digest !== input.digest ||\n !(yield* recordMatches(\n mapping,\n locked[0],\n selected,\n authority.nativeSubjectId,\n yield* encodePasswordPreparedReady(selected),\n ))\n )\n return undefined;\n\n return { record: selected, currentRequirement: authority.requirement };\n }),\n );\n\n return record ?? (yield* PasswordRejected.make({}));\n }).pipe(\n Effect.provideService(CurrentPasswordSql, database),\n Effect.provideService(LifecycleHooks, hooks),\n translateContextFailure,\n ),\n complete: (input, prepare) =>\n complete(input, prepare).pipe(\n Effect.provideService(CurrentPasswordSql, database),\n Effect.provideService(LifecycleHooks, hooks),\n translateFailure,\n ),\n resetWithProof: (input, prepare) =>\n complete(input, prepare).pipe(\n Effect.provideService(CurrentPasswordSql, database),\n Effect.provideService(LifecycleHooks, hooks),\n translateFailure,\n ),\n cancel: (uncaptured, prepare) =>\n Effect.gen(function* () {\n const record = yield* snapshotPasswordPreparedReady(uncaptured.record),\n snapshot = yield* encodePasswordPreparedReady(record);\n\n return yield* owned(\n Effect.gen(function* () {\n const journal = yield* CurrentCommitJournal;\n\n yield* lockAnchor(mapping, configuration, record.moduleId);\n const authority = yield* currentAuthority(mapping, configuration, record);\n\n if (authority === undefined) return prepare(false, journal);\n\n const rows = yield* readIntent(\n mapping,\n and(eq(c.moduleId, record.moduleId), eq(c.intentId, record.intentId))!,\n configuration.locking,\n );\n\n const now = yield* nowMillis;\n\n if (\n rows.length !== 1 ||\n now < record.issuedAtMillis ||\n now >= record.expiresAtMillis ||\n !(yield* recordMatches(\n mapping,\n rows[0],\n record,\n authority.nativeSubjectId,\n snapshot,\n ))\n )\n return prepare(false, journal);\n yield* terminal(mapping, rows[0], \"Cancelled\");\n\n return prepare(true, journal);\n }),\n );\n }).pipe(\n Effect.provideService(CurrentPasswordSql, database),\n Effect.provideService(LifecycleHooks, hooks),\n translateFailure,\n ),\n cleanup: (uncaptured, prepare) =>\n Effect.gen(function* () {\n const input = { ...uncaptured };\n\n if (!Number.isSafeInteger(input.limit) || input.limit < 1 || input.limit > 1000)\n return yield* unavailable();\n\n return yield* owned(\n Effect.gen(function* () {\n const transaction = yield* CurrentPasswordSql;\n const journal = yield* CurrentCommitJournal;\n\n if (!(yield* lockAnchor(mapping, configuration, input.moduleId, false)))\n return prepare({ removed: 0, hasMore: false }, journal);\n const now = p.encodeInstant(yield* nowMillis);\n\n const due = and(\n eq(c.moduleId, input.moduleId),\n or(\n and(lte(c.retainUntil, now), lte(c.admissionRetainUntil, now)),\n and(\n isNotNull(c.snapshot),\n or(\n and(eq(c.state, t.states.Preparing), lte(c.preparationExpiresAt, now)),\n and(eq(c.state, t.states.Ready), lte(c.expiresAt, now)),\n ),\n ),\n ),\n )!;\n\n const rows = yield* read(\n transaction\n .select()\n .from(t.table)\n .where(due)\n .orderBy(c.createdAt, c.intentId)\n .limit(input.limit + 1),\n configuration.locking,\n );\n\n let removed = 0;\n\n for (const row of rows.slice(0, input.limit)) {\n const expired =\n (yield* readIntent(\n mapping,\n and(\n rowCondition(mapping, row),\n lte(c.retainUntil, now),\n lte(c.admissionRetainUntil, now),\n )!,\n false,\n )).length === 1;\n\n if (expired) {\n yield* transaction.delete(t.table).where(rowCondition(mapping, row));\n if (\n (yield* readIntent(\n mapping,\n and(eq(c.moduleId, input.moduleId), eq(c.intentId, row[t.intentId]))!,\n false,\n )).length\n )\n return yield* unavailable();\n removed++;\n } else yield* terminal(mapping, row, \"Expired\");\n }\n\n return prepare(\n {\n removed,\n hasMore:\n (yield* read(transaction.select().from(t.table).where(due).limit(1), false))\n .length > 0,\n },\n journal,\n );\n }),\n );\n }).pipe(\n Effect.provideService(CurrentPasswordSql, database),\n Effect.provideService(LifecycleHooks, hooks),\n translateFailure,\n ),\n };\n\n return services;\n },\n);\n\nexport const passwordPreparedSqlKernel = {\n columns,\n recordMatches,\n captureAuthority,\n currentAuthority,\n rowCondition,\n valid,\n identifierScope,\n};\n"],"mappings":";;;;;;;;;;;;;;;AA0DA,MAAM,oBACJ,WAEA,yBACE,SACC,UACC,OAAO,GAAG,mBAAmB,CAAC,CAAC,KAAK,KACpC,OAAO,GAAG,gBAAgB,CAAC,CAAC,KAAK,KACjC,OAAO,GAAG,sBAAsB,CAAC,CAAC,KAAK,CAC3C,CAAC,CAAC,KAAK,OAAO,YAAY,UAAU,OAAO,UAAU,MAAM,IAAI,aAAa,YAAY,CAAC,CAAC,CAAC,CAAC;AAE9F,MAAM,2BACJ,WAEA,yBACE,SACC,UACC,OAAO,GAAG,mBAAmB,CAAC,CAAC,KAAK,KACpC,OAAO,GAAG,gBAAgB,CAAC,CAAC,KAAK,KACjC,OAAO,GAAG,gBAAgB,CAAC,CAAC,KAAK,KACjC,OAAO,GAAG,sBAAsB,CAAC,CAAC,KAAK,CAC3C,CAAC,CAAC,KACA,OAAO,YAAY,UACjB,OAAO,UACL,MAAM,IAAI,QAAQ,UAAW,OAAO,GAAG,gBAAgB,CAAC,CAAC,KAAK,IAAI,QAAQ,YAAY,CAAE,CAC1F,CACF,CACF;AAGF,MAAM,YAAY,SAAS,IAAI,KAAK,OAAO,IAAI,SAAS,aAAa,CAAC;AAEtE,MAAM,QAAQ,OAAyB,YACrC,WAAW,OAAO,MAAM,QAAQ,aAAa,MAAM,IAAI,QAAQ,IAAI;AAErE,MAAM,WAAW,YAAqB;CACpC,MAAM,QAA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GACzB,IAAI,EAAE,aAAa,GAAG,GACtB,IAAI,EAAE,sBAAsB,GAAG,CACjC,GACA,KACF,EAAA,CAAG,WAAW,GAEH;KACX,OAAO,YAAY,OAAO,EAAE,KAAK,CAAC,CAAC,MAAM,aAAa,SAAS,GAAG,CAAC;KACnE,KACG,OAAO,WACN,SACA,IAAI,GAAG,EAAE,UAAU,MAAM,QAAQ,GAAG,GAAG,EAAE,UAAU,IAAI,EAAE,SAAS,CAAC,GACnE,KACF,EAAA,CAAG,QAEH,OAAO,OAAO,YAAY;KAC5B;IACF,OAAO,OAAO,SAAS,SAAS,KAAK,SAAS;IAGhD,OAAO,QACL;KACE;KACA,UACG,OAAO,KAAK,YAAY,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,KAAK,EAAA,CACvE,SAAS;IAChB,GACA,OACF;GACF,CAAC,CACH;EACF,CAAC,CAAC,CAAC,KACD,OAAO,eAAe,oBAAoB,QAAQ,GAClD,OAAO,eAAe,gBAAgB,KAAK,GAC3C,gBACF;CAGU;AAChB,CACF;AAEA,MAAa,4BAA4B;CACvC;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@yielded/auth-persistence-drizzle","version":"0.1.0-beta.
|
|
1
|
+
{"name":"@yielded/auth-persistence-drizzle","version":"0.1.0-beta.18","dependencies":{"@noble/hashes":"2.3.0","@yielded/auth":"0.1.0-beta.18","@yielded/auth-crypto":"0.1.0-beta.18","@yielded/auth-persistence":"0.1.0-beta.18"},"devDependencies":{"@effect/platform-bun":"4.0.0","@effect/platform-node":"4.0.0","@effect/sql-d1":"4.0.0","@effect/sql-libsql":"4.0.0","@effect/sql-mysql2":"4.0.0","@effect/sql-pg":"4.0.0","@effect/sql-pglite":"4.0.0","@effect/sql-sqlite-bun":"4.0.0","@effect/sql-sqlite-do":"4.0.0","@effect/sql-sqlite-node":"4.0.0","@effect/sql-sqlite-wasm":"4.0.0","@effect/vitest":"4.0.0","drizzle-orm":"1.0.0-rc.4","effect":"4.0.0","typescript":"7.0.2","vite-plus":"0.3.3"},"peerDependencies":{"@effect/sql-d1":">=4.0.0","@effect/sql-libsql":">=4.0.0","@effect/sql-mysql2":">=4.0.0","@effect/sql-pg":">=4.0.0","@effect/sql-pglite":">=4.0.0","@effect/sql-sqlite-bun":">=4.0.0","@effect/sql-sqlite-do":">=4.0.0","@effect/sql-sqlite-node":">=4.0.0","@effect/sql-sqlite-wasm":">=4.0.0","drizzle-orm":">=1.0.0-rc.4","effect":"^4.0.0"},"exports":{".":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"./D1":{"types":"./dist/D1.d.mts","default":"./dist/D1.mjs"},"./Libsql":{"types":"./dist/Libsql.d.mts","default":"./dist/Libsql.mjs"},"./Mysql2":{"types":"./dist/Mysql2.d.mts","default":"./dist/Mysql2.mjs"},"./Pglite":{"types":"./dist/Pglite.d.mts","default":"./dist/Pglite.mjs"},"./Postgres":{"types":"./dist/Postgres.d.mts","default":"./dist/Postgres.mjs"},"./SqliteBun":{"types":"./dist/SqliteBun.d.mts","default":"./dist/SqliteBun.mjs"},"./SqliteDo":{"types":"./dist/SqliteDo.d.mts","default":"./dist/SqliteDo.mjs"},"./SqliteNode":{"types":"./dist/SqliteNode.d.mts","default":"./dist/SqliteNode.mjs"},"./SqliteWasm":{"types":"./dist/SqliteWasm.d.mts","default":"./dist/SqliteWasm.mjs"}},"description":"Drizzle persistence, table mappings, and migration adapters for Yielded Auth.","homepage":"https://yielded.dev/auth/","bugs":{"url":"https://github.com/yielded-dev/auth/issues"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/yielded-dev/auth.git","directory":"packages/auth-persistence-drizzle"},"files":["dist","src"],"type":"module","sideEffects":[],"publishConfig":{"access":"public"},"scripts":{"build":"vp pack","check":"tsc --noEmit -p tsconfig.json","test":"vp test --passWithNoTests","example:totp":"bun test/fixtures/totp-sqlite-bun.ts"},"peerDependenciesMeta":{"@effect/sql-d1":{"optional":true},"@effect/sql-libsql":{"optional":true},"@effect/sql-mysql2":{"optional":true},"@effect/sql-pg":{"optional":true},"@effect/sql-pglite":{"optional":true},"@effect/sql-sqlite-bun":{"optional":true},"@effect/sql-sqlite-do":{"optional":true},"@effect/sql-sqlite-node":{"optional":true},"@effect/sql-sqlite-wasm":{"optional":true}}}
|
|
@@ -209,9 +209,13 @@ const makePreparedPlans = (mapping: Mapping, proofMapping?: any) => {
|
|
|
209
209
|
statements: planned.statements.map((statement) =>
|
|
210
210
|
compactD1GeneratedStatement(database.$client, statement, unavailable),
|
|
211
211
|
),
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
212
|
+
...(planned.postconditions === undefined
|
|
213
|
+
? {}
|
|
214
|
+
: {
|
|
215
|
+
postconditions: planned.postconditions.map((statement) =>
|
|
216
|
+
compactD1GeneratedStatement(database.$client, statement, unavailable),
|
|
217
|
+
),
|
|
218
|
+
}),
|
|
215
219
|
}),
|
|
216
220
|
catch: (cause) =>
|
|
217
221
|
Schema.is(PasswordUnavailable)(cause)
|
|
@@ -418,7 +422,9 @@ const makePreparedPlans = (mapping: Mapping, proofMapping?: any) => {
|
|
|
418
422
|
))),
|
|
419
423
|
receipt: receipt ?? prepare("rejected", journal),
|
|
420
424
|
statements: compiled.statements,
|
|
421
|
-
|
|
425
|
+
...(compiled.postconditions === undefined
|
|
426
|
+
? {}
|
|
427
|
+
: { postconditions: compiled.postconditions }),
|
|
422
428
|
};
|
|
423
429
|
}
|
|
424
430
|
|
|
@@ -520,7 +526,7 @@ const makePreparedPlans = (mapping: Mapping, proofMapping?: any) => {
|
|
|
520
526
|
|
|
521
527
|
const now = yield* kernel.readEngineNowMillis(p),
|
|
522
528
|
scope = identifierScope({
|
|
523
|
-
credential: authority.snapshot,
|
|
529
|
+
...(authority.snapshot === undefined ? {} : { credential: authority.snapshot }),
|
|
524
530
|
revision: authority.revision,
|
|
525
531
|
});
|
|
526
532
|
|
|
@@ -1622,7 +1622,7 @@ const makePasswordPlans = (
|
|
|
1622
1622
|
return {
|
|
1623
1623
|
receipt: prepare(compiled === undefined ? "rejected" : "changed", journal),
|
|
1624
1624
|
statements: compiled?.statements ?? [],
|
|
1625
|
-
retryable: compiled
|
|
1625
|
+
...(compiled?.retryable === undefined ? {} : { retryable: compiled.retryable }),
|
|
1626
1626
|
};
|
|
1627
1627
|
}),
|
|
1628
1628
|
);
|
|
@@ -341,7 +341,11 @@ function runPlanned<A, E, GuardE extends D1PlanError = never>(
|
|
|
341
341
|
recoverGuard?: Effect.Effect<never, GuardE, CurrentD1PlanningDatabase>,
|
|
342
342
|
) {
|
|
343
343
|
const planned = plan.pipe(
|
|
344
|
-
Effect.map((value) => ({
|
|
344
|
+
Effect.map((value) => ({
|
|
345
|
+
...value,
|
|
346
|
+
...(isConstraintConflict === undefined ? {} : { isConstraintConflict }),
|
|
347
|
+
...(recoverGuard === undefined ? {} : { recoverGuard }),
|
|
348
|
+
})),
|
|
345
349
|
);
|
|
346
350
|
|
|
347
351
|
const execution = Effect.gen(function* () {
|
|
@@ -1498,9 +1502,11 @@ export const makeD1StatefulSessions = <Claims>(
|
|
|
1498
1502
|
Schema.encodeEffect(codec)(record).pipe(Effect.flatMap(Schema.decodeEffect(codec))),
|
|
1499
1503
|
);
|
|
1500
1504
|
|
|
1505
|
+
const nextCursor = decoded.length <= input.limit ? undefined : sessions.at(-1)?.sessionId;
|
|
1506
|
+
|
|
1501
1507
|
return {
|
|
1502
1508
|
sessions,
|
|
1503
|
-
...(
|
|
1509
|
+
...(nextCursor === undefined ? {} : { nextCursor }),
|
|
1504
1510
|
};
|
|
1505
1511
|
}).pipe(terminalD1),
|
|
1506
1512
|
};
|
|
@@ -752,7 +752,7 @@ export const makeSqlPasswordPreparedPersistence = Effect.fn("makeSqlPasswordPrep
|
|
|
752
752
|
nativeNow = p.encodeInstant(now);
|
|
753
753
|
|
|
754
754
|
const scope = identifierScope({
|
|
755
|
-
credential: authority.snapshot,
|
|
755
|
+
...(authority.snapshot === undefined ? {} : { credential: authority.snapshot }),
|
|
756
756
|
revision: authority.revision,
|
|
757
757
|
});
|
|
758
758
|
|