@yielded/auth-persistence-drizzle 0.1.0-beta.21 → 0.1.0-beta.23
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/Libsql.d.mts +19 -19
- package/dist/Mysql2.d.mts +14 -14
- package/dist/Pglite.d.mts +14 -14
- package/dist/Postgres.d.mts +6 -6
- package/dist/SqliteBun.d.mts +27 -27
- package/dist/SqliteDo.d.mts +13 -13
- package/dist/SqliteNode.d.mts +23 -23
- package/dist/SqliteWasm.d.mts +13 -13
- package/dist/drizzle/d1-password-prepared.d.mts +3 -3
- package/dist/drizzle/d1-password-prepared.mjs.map +1 -1
- package/dist/drizzle/d1-passwords.d.mts +8 -9
- package/dist/drizzle/d1-passwords.mjs +103 -173
- package/dist/drizzle/d1-passwords.mjs.map +1 -1
- package/dist/drizzle/d1-proofs.d.mts +1 -1
- package/dist/drizzle/d1-sessions.d.mts +1 -1
- package/dist/drizzle/mysql-password-prepared.d.mts +5 -5
- package/dist/drizzle/mysql-password-prepared.mjs.map +1 -1
- package/dist/drizzle/mysql-passwords.d.mts +9 -9
- package/dist/drizzle/mysql-passwords.mjs.map +1 -1
- package/dist/drizzle/native-sql-table.mjs +110 -0
- package/dist/drizzle/native-sql-table.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-target.d.mts +5 -5
- package/dist/drizzle/oauth-target.d.mts +1 -1
- package/dist/drizzle/password-model.d.mts +5 -7
- package/dist/drizzle/password-prepared-model.d.mts +5 -5
- package/dist/drizzle/password-prepared-model.mjs.map +1 -1
- package/dist/drizzle/password-sql.mjs +2 -1
- package/dist/drizzle/password-sql.mjs.map +1 -1
- package/dist/drizzle/password-target.mjs +13 -2
- package/dist/drizzle/password-target.mjs.map +1 -1
- package/dist/drizzle/pg-password-prepared.d.mts +5 -5
- package/dist/drizzle/pg-password-prepared.mjs.map +1 -1
- package/dist/drizzle/pg-passwords.d.mts +9 -9
- package/dist/drizzle/pg-passwords.mjs.map +1 -1
- package/dist/drizzle/phone-target.d.mts +1 -1
- package/dist/drizzle/session-sql.mjs +2 -1
- package/dist/drizzle/session-sql.mjs.map +1 -1
- package/dist/drizzle/sqlite-password-prepared.mjs.map +1 -1
- package/dist/drizzle/sqlite-passwords.mjs.map +1 -1
- package/dist/drizzle/storage-validation.mjs +0 -13
- package/dist/drizzle/storage-validation.mjs.map +1 -1
- package/dist/drizzle/totp-target.d.mts +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/internal/drizzle-postgres.mjs +2 -0
- package/dist/internal/drizzle-postgres.mjs.map +1 -1
- package/dist/internal/drizzle-sqlite.mjs +2 -0
- package/dist/internal/drizzle-sqlite.mjs.map +1 -1
- package/package.json +1 -1
- package/src/drizzle/d1-password-prepared.ts +2 -20
- package/src/drizzle/d1-passwords.ts +232 -519
- package/src/drizzle/mysql-password-prepared.ts +4 -12
- package/src/drizzle/mysql-passwords.ts +5 -15
- package/src/drizzle/native-sql-table.ts +229 -0
- package/src/drizzle/password-model.ts +0 -20
- package/src/drizzle/password-prepared-model.ts +0 -12
- package/src/drizzle/password-sql.ts +3 -0
- package/src/drizzle/password-target.ts +41 -4
- package/src/drizzle/pg-password-prepared.ts +4 -12
- package/src/drizzle/pg-passwords.ts +5 -15
- package/src/drizzle/session-sql.ts +2 -1
- package/src/drizzle/sqlite-password-prepared.ts +4 -48
- package/src/drizzle/sqlite-passwords.ts +7 -21
- package/src/drizzle/storage-validation.ts +0 -8
- package/src/index.ts +0 -4
- package/src/internal/drizzle-postgres.ts +2 -0
- package/src/internal/drizzle-sqlite.ts +2 -0
|
@@ -6,11 +6,11 @@ import "./d1-planning.mjs";
|
|
|
6
6
|
import { AnyRelations, SQL, Table } from "drizzle-orm";
|
|
7
7
|
import { Effect } from "effect";
|
|
8
8
|
import { CurrentCommitJournal, HookConfigurationError, LifecycleHooks, PreparedCommit } from "@yielded/auth/Hooks";
|
|
9
|
+
import { Statement } from "effect/sql/Statement";
|
|
9
10
|
import { PrepareProofCommit, ProofAttemptDecision, ProofBinding, ProofCleanupResult, ProofCompletionDecision, ProofCompletionPlan, ProofDeliveryClaim, ProofDeliveryOutcome, ProofPersistence, ProofPolicy, ProofRequestConflict, ProofUnavailable, ProofVersion } from "@yielded/auth/Proofs";
|
|
10
11
|
import { EffectSQLiteD1Database } from "drizzle-orm/effect-d1";
|
|
11
12
|
import { AnySQLiteTable } from "drizzle-orm/sqlite-core";
|
|
12
13
|
import "drizzle-orm/effect-core";
|
|
13
|
-
import { Statement } from "effect/sql/Statement";
|
|
14
14
|
import { D1Client } from "@effect/sql-d1/D1Client";
|
|
15
15
|
//#region src/drizzle/d1-proofs.d.ts
|
|
16
16
|
type Database = EffectSQLiteD1Database<AnyRelations> & {
|
|
@@ -9,11 +9,11 @@ import { NativeDatabase } from "@yielded/auth-persistence/Adapter";
|
|
|
9
9
|
import { Context, DateTime, Effect, Schema } from "effect";
|
|
10
10
|
import { HookConfigurationError, LifecycleHooks, PreparedCommit } from "@yielded/auth/Hooks";
|
|
11
11
|
import { AuthenticationAuthority, AuthenticationEvidence, AuthenticationRequirement, AuthenticationRevision, PendingAuthentication, PendingAuthenticationInvalid, PendingConsumption, PrepareSessionCommit, SessionConflict, SessionInvalid, SessionRepository, SessionStepUpInvalid, SessionStepUpPersistence, SessionUnavailable, SignedSessionValidity, StaleAuthentication, StatefulSessionPersistence } from "@yielded/auth/Sessions";
|
|
12
|
+
import { Statement } from "effect/sql/Statement";
|
|
12
13
|
import { SubjectId } from "@yielded/auth/Schema";
|
|
13
14
|
import { AnySQLiteTable } from "drizzle-orm/sqlite-core";
|
|
14
15
|
import "drizzle-orm/effect-core";
|
|
15
16
|
import "effect/sql/SqlError";
|
|
16
|
-
import { Statement } from "effect/sql/Statement";
|
|
17
17
|
//#region src/drizzle/d1-sessions.d.ts
|
|
18
18
|
type Database = D1PlanningDatabase;
|
|
19
19
|
type D1DomainError = SessionStepUpInvalid | PendingAuthenticationInvalid | SessionConflict | SessionInvalid | SessionUnavailable | StaleAuthentication;
|
|
@@ -11,17 +11,17 @@ import { SqlError } from "effect/sql/SqlError";
|
|
|
11
11
|
//#region src/drizzle/mysql-password-prepared.d.ts
|
|
12
12
|
type Database = EffectMysql2Database<AnyRelations>;
|
|
13
13
|
type TransactionOf<D extends Database> = Parameters<Parameters<D["transaction"]>[0]>[0];
|
|
14
|
-
export declare const makeMySqlPasswordPreparedPersistenceServices: <S extends AnyMySqlTable, I extends AnyMySqlTable, C extends AnyMySqlTable, AC extends AnyMySqlTable, A extends AnyMySqlTable,
|
|
14
|
+
export declare const makeMySqlPasswordPreparedPersistenceServices: <S extends AnyMySqlTable, I extends AnyMySqlTable, C extends AnyMySqlTable, AC extends AnyMySqlTable, A extends AnyMySqlTable, M extends AnyMySqlTable, T extends AnyMySqlTable, B extends AnyMySqlTable, NativeId, PS extends AnyMySqlTable = AnyMySqlTable, PC extends AnyMySqlTable = AnyMySqlTable, PM extends AnyMySqlTable = AnyMySqlTable, PSub extends AnyMySqlTable = AnyMySqlTable, PI extends AnyMySqlTable = AnyMySqlTable, PCr extends AnyMySqlTable = AnyMySqlTable, PNativeId = unknown>(mapping: PasswordPreparedPersistenceMapping<S, I, C, AC, A, M, T, B, NativeId>, proofMapping?: PasswordPreparedProofMapping<PS, PC, PM, PSub, PI, PCr, PNativeId>) => Effect.Effect<{
|
|
15
15
|
passwordPreparedPersistence: PasswordPreparedPersistence;
|
|
16
16
|
}, PasswordUnavailable, Database$1 | LifecycleHooks>;
|
|
17
|
-
export declare function coordinateMySqlPasswordPreparedPersistence<TargetId, D extends Database, S extends AnyMySqlTable, I extends AnyMySqlTable, C extends AnyMySqlTable, AC extends AnyMySqlTable, A extends AnyMySqlTable,
|
|
18
|
-
readonly mapping: PasswordPreparedPersistenceMapping<S, I, C, AC, A,
|
|
17
|
+
export declare function coordinateMySqlPasswordPreparedPersistence<TargetId, D extends Database, S extends AnyMySqlTable, I extends AnyMySqlTable, C extends AnyMySqlTable, AC extends AnyMySqlTable, A extends AnyMySqlTable, M extends AnyMySqlTable, T extends AnyMySqlTable, B extends AnyMySqlTable, NativeId, PS extends AnyMySqlTable, PC extends AnyMySqlTable, PM extends AnyMySqlTable, PSub extends AnyMySqlTable, PI extends AnyMySqlTable, PCr extends AnyMySqlTable, PNativeId, Out, E, R, DatabaseError, DatabaseRequirements>(acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>, options: {
|
|
18
|
+
readonly mapping: PasswordPreparedPersistenceMapping<S, I, C, AC, A, M, T, B, NativeId>;
|
|
19
19
|
readonly proofMapping?: PasswordPreparedProofMapping<PS, PC, PM, PSub, PI, PCr, PNativeId> | undefined;
|
|
20
20
|
readonly target: SuppliedService<TargetId, PasswordPreparedPersistence>;
|
|
21
21
|
readonly transaction?: never;
|
|
22
22
|
}, body: Effect.Effect<Out, E, R>): Effect.Effect<Out, E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError, Exclude<R, TargetId> | LifecycleHooks | DatabaseRequirements>;
|
|
23
|
-
export declare function coordinateMySqlPasswordPreparedPersistence<TargetId, D extends Database, S extends AnyMySqlTable, I extends AnyMySqlTable, C extends AnyMySqlTable, AC extends AnyMySqlTable, A extends AnyMySqlTable,
|
|
24
|
-
readonly mapping: PasswordPreparedPersistenceMapping<S, I, C, AC, A,
|
|
23
|
+
export declare function coordinateMySqlPasswordPreparedPersistence<TargetId, D extends Database, S extends AnyMySqlTable, I extends AnyMySqlTable, C extends AnyMySqlTable, AC extends AnyMySqlTable, A extends AnyMySqlTable, M extends AnyMySqlTable, T extends AnyMySqlTable, B extends AnyMySqlTable, NativeId, PS extends AnyMySqlTable, PC extends AnyMySqlTable, PM extends AnyMySqlTable, PSub extends AnyMySqlTable, PI extends AnyMySqlTable, PCr extends AnyMySqlTable, PNativeId, Out, E, R, DatabaseError, DatabaseRequirements, TxId, TxShape>(acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>, options: {
|
|
24
|
+
readonly mapping: PasswordPreparedPersistenceMapping<S, I, C, AC, A, M, T, B, NativeId>;
|
|
25
25
|
readonly proofMapping?: PasswordPreparedProofMapping<PS, PC, PM, PSub, PI, PCr, PNativeId> | undefined;
|
|
26
26
|
readonly target: SuppliedService<TargetId, PasswordPreparedPersistence>;
|
|
27
27
|
readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mysql-password-prepared.mjs","names":["DatabaseService"],"sources":["../../src/drizzle/mysql-password-prepared.ts"],"sourcesContent":["import { NativeDatabase } from \"@yielded/auth-persistence/Adapter\";\nimport type { LifecycleHooks, HookConfigurationError } from \"@yielded/auth/Hooks\";\nimport type { PasswordUnavailable, PasswordPreparedPersistence } from \"@yielded/auth/Password\";\nimport type { AnyRelations } from \"drizzle-orm\";\nimport type { EffectMysql2Database } from \"drizzle-orm/effect-mysql2\";\nimport type { AnyMySqlTable } from \"drizzle-orm/mysql-core\";\nimport { Effect, Context } from \"effect\";\nimport type { SqlError } from \"effect/sql/SqlError\";\n\nimport { Database as DatabaseService } from \"./mysql-database\";\nimport { mysqlPasswordConfiguration as configuration } from \"./mysql-passwords\";\nimport { nativeDatabase } from \"./native-database\";\nimport type {\n PasswordPreparedPersistenceMapping,\n PasswordPreparedProofMapping,\n} from \"./password-prepared-model\";\nimport {\n makeTargetPasswordPreparedPersistenceServices,\n coordinateTargetPasswordPreparedPersistence,\n} from \"./password-prepared-target\";\nimport { CurrentPasswordSql } from \"./password-sql\";\nimport { acquireTransactionService, transactionService } from \"./standalone-guard\";\nimport type { SuppliedService } from \"./SuppliedService\";\ntype Database = EffectMysql2Database<AnyRelations>;\ntype TransactionOf<D extends Database> = Parameters<Parameters<D[\"transaction\"]>[0]>[0];\n\nexport const makeMySqlPasswordPreparedPersistenceServices = <\n S extends AnyMySqlTable,\n I extends AnyMySqlTable,\n C extends AnyMySqlTable,\n AC extends AnyMySqlTable,\n A extends AnyMySqlTable,\n
|
|
1
|
+
{"version":3,"file":"mysql-password-prepared.mjs","names":["DatabaseService"],"sources":["../../src/drizzle/mysql-password-prepared.ts"],"sourcesContent":["import { NativeDatabase } from \"@yielded/auth-persistence/Adapter\";\nimport type { LifecycleHooks, HookConfigurationError } from \"@yielded/auth/Hooks\";\nimport type { PasswordUnavailable, PasswordPreparedPersistence } from \"@yielded/auth/Password\";\nimport type { AnyRelations } from \"drizzle-orm\";\nimport type { EffectMysql2Database } from \"drizzle-orm/effect-mysql2\";\nimport type { AnyMySqlTable } from \"drizzle-orm/mysql-core\";\nimport { Effect, Context } from \"effect\";\nimport type { SqlError } from \"effect/sql/SqlError\";\n\nimport { Database as DatabaseService } from \"./mysql-database\";\nimport { mysqlPasswordConfiguration as configuration } from \"./mysql-passwords\";\nimport { nativeDatabase } from \"./native-database\";\nimport type {\n PasswordPreparedPersistenceMapping,\n PasswordPreparedProofMapping,\n} from \"./password-prepared-model\";\nimport {\n makeTargetPasswordPreparedPersistenceServices,\n coordinateTargetPasswordPreparedPersistence,\n} from \"./password-prepared-target\";\nimport { CurrentPasswordSql } from \"./password-sql\";\nimport { acquireTransactionService, transactionService } from \"./standalone-guard\";\nimport type { SuppliedService } from \"./SuppliedService\";\ntype Database = EffectMysql2Database<AnyRelations>;\ntype TransactionOf<D extends Database> = Parameters<Parameters<D[\"transaction\"]>[0]>[0];\n\nexport const makeMySqlPasswordPreparedPersistenceServices = <\n S extends AnyMySqlTable,\n I extends AnyMySqlTable,\n C extends AnyMySqlTable,\n AC extends AnyMySqlTable,\n A extends AnyMySqlTable,\n M extends AnyMySqlTable,\n T extends AnyMySqlTable,\n B extends AnyMySqlTable,\n NativeId,\n PS extends AnyMySqlTable = AnyMySqlTable,\n PC extends AnyMySqlTable = AnyMySqlTable,\n PM extends AnyMySqlTable = AnyMySqlTable,\n PSub extends AnyMySqlTable = AnyMySqlTable,\n PI extends AnyMySqlTable = AnyMySqlTable,\n PCr extends AnyMySqlTable = AnyMySqlTable,\n PNativeId = unknown,\n>(\n mapping: PasswordPreparedPersistenceMapping<S, I, C, AC, A, M, T, B, NativeId>,\n proofMapping?: PasswordPreparedProofMapping<PS, PC, PM, PSub, PI, PCr, PNativeId>,\n) =>\n Effect.flatMap(\n Effect.map(acquireTransactionService(DatabaseService), configuration),\n (configuration) =>\n makeTargetPasswordPreparedPersistenceServices(mapping, configuration, proofMapping),\n ).pipe(\n Effect.provideServiceEffect(CurrentPasswordSql, nativeDatabase(DatabaseService)),\n Effect.provideServiceEffect(NativeDatabase, nativeDatabase(DatabaseService)),\n );\n\nexport function coordinateMySqlPasswordPreparedPersistence<\n TargetId,\n D extends Database,\n S extends AnyMySqlTable,\n I extends AnyMySqlTable,\n C extends AnyMySqlTable,\n AC extends AnyMySqlTable,\n A extends AnyMySqlTable,\n M extends AnyMySqlTable,\n T extends AnyMySqlTable,\n B extends AnyMySqlTable,\n NativeId,\n PS extends AnyMySqlTable,\n PC extends AnyMySqlTable,\n PM extends AnyMySqlTable,\n PSub extends AnyMySqlTable,\n PI extends AnyMySqlTable,\n PCr extends AnyMySqlTable,\n PNativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PasswordPreparedPersistenceMapping<S, I, C, AC, A, M, T, B, NativeId>;\n readonly proofMapping?:\n | PasswordPreparedProofMapping<PS, PC, PM, PSub, PI, PCr, PNativeId>\n | undefined;\n readonly target: SuppliedService<TargetId, PasswordPreparedPersistence>;\n readonly transaction?: never;\n },\n body: Effect.Effect<Out, E, R>,\n): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinateMySqlPasswordPreparedPersistence<\n TargetId,\n D extends Database,\n S extends AnyMySqlTable,\n I extends AnyMySqlTable,\n C extends AnyMySqlTable,\n AC extends AnyMySqlTable,\n A extends AnyMySqlTable,\n M extends AnyMySqlTable,\n T extends AnyMySqlTable,\n B extends AnyMySqlTable,\n NativeId,\n PS extends AnyMySqlTable,\n PC extends AnyMySqlTable,\n PM extends AnyMySqlTable,\n PSub extends AnyMySqlTable,\n PI extends AnyMySqlTable,\n PCr extends AnyMySqlTable,\n PNativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PasswordPreparedPersistenceMapping<S, I, C, AC, A, M, T, B, NativeId>;\n readonly proofMapping?:\n | PasswordPreparedProofMapping<PS, PC, PM, PSub, PI, PCr, PNativeId>\n | undefined;\n readonly target: SuppliedService<TargetId, PasswordPreparedPersistence>;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<Out, E, R>,\n): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId | TxId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinateMySqlPasswordPreparedPersistence<\n TargetId,\n D extends Database,\n S extends AnyMySqlTable,\n I extends AnyMySqlTable,\n C extends AnyMySqlTable,\n AC extends AnyMySqlTable,\n A extends AnyMySqlTable,\n M extends AnyMySqlTable,\n T extends AnyMySqlTable,\n B extends AnyMySqlTable,\n NativeId,\n PS extends AnyMySqlTable,\n PC extends AnyMySqlTable,\n PM extends AnyMySqlTable,\n PSub extends AnyMySqlTable,\n PI extends AnyMySqlTable,\n PCr extends AnyMySqlTable,\n PNativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PasswordPreparedPersistenceMapping<S, I, C, AC, A, M, T, B, NativeId>;\n readonly proofMapping?:\n | PasswordPreparedProofMapping<PS, PC, PM, PSub, PI, PCr, PNativeId>\n | undefined;\n readonly target: SuppliedService<TargetId, PasswordPreparedPersistence>;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<Out, E, R>,\n): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId> | LifecycleHooks | DatabaseRequirements\n> {\n return Effect.flatMap(nativeDatabase(acquire), (database) =>\n coordinateTargetPasswordPreparedPersistence<TransactionOf<D>, Out, E, Exclude<R, TargetId>>(\n database,\n options.mapping,\n configuration(transactionService(database)),\n options.proofMapping,\n (\n transaction: TransactionOf<D>,\n services: { readonly passwordPreparedPersistence: PasswordPreparedPersistence },\n ) => {\n const provided = Context.make(options.target, services.passwordPreparedPersistence);\n const work = Effect.provideContext(body, provided);\n\n return options.transaction === undefined\n ? work\n : Effect.provideService(work, options.transaction, options.transaction.of(transaction));\n },\n ).pipe(Effect.provideService(NativeDatabase, database)),\n );\n}\n"],"mappings":";;;;;;;;;AA0BA,MAAa,gDAkBX,SACA,iBAEA,OAAO,QACL,OAAO,IAAI,0BAA0BA,QAAe,GAAG,aAAa,IACnE,kBACC,8CAA8C,SAAS,eAAe,YAAY,CACtF,CAAC,CAAC,KACA,OAAO,qBAAqB,oBAAoB,eAAeA,QAAe,CAAC,GAC/E,OAAO,qBAAqB,gBAAgB,eAAeA,QAAe,CAAC,CAC7E;AAsFF,SAAgB,2CA2Bd,SACA,SAQA,MAKA;CACA,OAAO,OAAO,QAAQ,eAAe,OAAO,IAAI,aAC9C,4CACE,UACA,QAAQ,SACR,cAAc,mBAAmB,QAAQ,CAAC,GAC1C,QAAQ,eAEN,aACA,aACG;EACH,MAAM,WAAW,QAAQ,KAAK,QAAQ,QAAQ,SAAS,2BAA2B;EAClF,MAAM,OAAO,OAAO,eAAe,MAAM,QAAQ;EAEjD,OAAO,QAAQ,gBAAgB,KAAA,IAC3B,OACA,OAAO,eAAe,MAAM,QAAQ,aAAa,QAAQ,YAAY,GAAG,WAAW,CAAC;CAC1F,CACF,CAAC,CAAC,KAAK,OAAO,eAAe,gBAAgB,QAAQ,CAAC,CACxD;AACF"}
|
|
@@ -16,16 +16,16 @@ import { SqlError } from "effect/sql/SqlError";
|
|
|
16
16
|
//#region src/drizzle/mysql-passwords.d.ts
|
|
17
17
|
type Database = EffectMysql2Database<AnyRelations>;
|
|
18
18
|
type TransactionOf<D extends Database> = Parameters<Parameters<D["transaction"]>[0]>[0];
|
|
19
|
-
type Mapping<S extends AnyMySqlTable, I extends AnyMySqlTable, C extends AnyMySqlTable, AC extends AnyMySqlTable, A extends AnyMySqlTable,
|
|
20
|
-
export declare const makeMysqlPasswordPersistenceServices: <S extends AnyMySqlTable, I extends AnyMySqlTable, C extends AnyMySqlTable, AC extends AnyMySqlTable, A extends AnyMySqlTable,
|
|
19
|
+
type Mapping<S extends AnyMySqlTable, I extends AnyMySqlTable, C extends AnyMySqlTable, AC extends AnyMySqlTable, A extends AnyMySqlTable, M extends AnyMySqlTable, NativeId> = PasswordPersistenceMapping<S, I, C, AC, A, M, NativeId>;
|
|
20
|
+
export declare const makeMysqlPasswordPersistenceServices: <S extends AnyMySqlTable, I extends AnyMySqlTable, C extends AnyMySqlTable, AC extends AnyMySqlTable, A extends AnyMySqlTable, M extends AnyMySqlTable, NativeId>(mapping: Mapping<S, I, C, AC, A, M, NativeId>, proofMapping?: ProofPersistenceMapping<any, any, any, any, any, any, any, any, any, any, any, any>) => Effect.Effect<{
|
|
21
21
|
passwordPersistence: {
|
|
22
|
-
readonly
|
|
22
|
+
readonly prepareAttempt: (input: {
|
|
23
23
|
readonly moduleId: string;
|
|
24
24
|
readonly action: "sign-in" | "change";
|
|
25
25
|
readonly identifier: import("@yielded/auth/Identity").LoginIdentifier;
|
|
26
26
|
readonly subjectId?: import("@yielded/auth/Schema").SubjectId;
|
|
27
|
-
readonly
|
|
28
|
-
}
|
|
27
|
+
readonly attemptLifetimeMillis: number;
|
|
28
|
+
}) => Effect.Effect<import("@yielded/auth/Password").PasswordAttemptPreparation, PasswordUnavailable>;
|
|
29
29
|
readonly settleAttempt: <A_1>(input: {
|
|
30
30
|
readonly moduleId: string;
|
|
31
31
|
readonly attemptId: import("@yielded/auth/Password").PasswordAttemptId;
|
|
@@ -60,13 +60,13 @@ export declare const makeMysqlPasswordPersistenceServices: <S extends AnyMySqlTa
|
|
|
60
60
|
}, A_1>) => Effect.Effect<import("@yielded/auth/Hooks").PreparedCommit<A_1>, PasswordUnavailable>;
|
|
61
61
|
};
|
|
62
62
|
}, PasswordUnavailable, Database$1 | LifecycleHooks>;
|
|
63
|
-
export declare function coordinateMysqlPasswordPersistence<D extends Database, S extends AnyMySqlTable, I extends AnyMySqlTable, C extends AnyMySqlTable, AC extends AnyMySqlTable, A extends AnyMySqlTable,
|
|
64
|
-
readonly mapping: Mapping<S, I, C, AC, A,
|
|
63
|
+
export declare function coordinateMysqlPasswordPersistence<D extends Database, S extends AnyMySqlTable, I extends AnyMySqlTable, C extends AnyMySqlTable, AC extends AnyMySqlTable, A extends AnyMySqlTable, M extends AnyMySqlTable, NativeId, PM extends ProofPersistenceMapping<any, any, any, any, any, any, any, any, any, any, any, any> | undefined, Out, E, R, DatabaseError, DatabaseRequirements>(acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>, options: {
|
|
64
|
+
readonly mapping: Mapping<S, I, C, AC, A, M, NativeId>;
|
|
65
65
|
readonly proofMapping?: PM;
|
|
66
66
|
readonly transaction?: never;
|
|
67
67
|
}, body: Effect.Effect<Out, E, R>): Effect.Effect<Out, E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError, Exclude<R, PasswordPersistence> | LifecycleHooks | DatabaseRequirements>;
|
|
68
|
-
export declare function coordinateMysqlPasswordPersistence<D extends Database, S extends AnyMySqlTable, I extends AnyMySqlTable, C extends AnyMySqlTable, AC extends AnyMySqlTable, A extends AnyMySqlTable,
|
|
69
|
-
readonly mapping: Mapping<S, I, C, AC, A,
|
|
68
|
+
export declare function coordinateMysqlPasswordPersistence<D extends Database, S extends AnyMySqlTable, I extends AnyMySqlTable, C extends AnyMySqlTable, AC extends AnyMySqlTable, A extends AnyMySqlTable, M extends AnyMySqlTable, NativeId, PM extends ProofPersistenceMapping<any, any, any, any, any, any, any, any, any, any, any, any> | undefined, Out, E, R, DatabaseError, DatabaseRequirements, TxId, TxShape>(acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>, options: {
|
|
69
|
+
readonly mapping: Mapping<S, I, C, AC, A, M, NativeId>;
|
|
70
70
|
readonly proofMapping?: PM;
|
|
71
71
|
readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;
|
|
72
72
|
}, body: Effect.Effect<Out, E, R>): Effect.Effect<Out, E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError, Exclude<R, PasswordPersistence | TxId> | LifecycleHooks | DatabaseRequirements>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mysql-passwords.mjs","names":["DatabaseService"],"sources":["../../src/drizzle/mysql-passwords.ts"],"sourcesContent":["import { NativeDatabase } from \"@yielded/auth-persistence/Adapter\";\nimport type { LifecycleHooks, HookConfigurationError } from \"@yielded/auth/Hooks\";\nimport { type PasswordUnavailable, PasswordPersistence } from \"@yielded/auth/Password\";\n/* oxlint-disable no-explicit-any -- proof mapping tables are independently typed by the proof owner; this driver forwards them unchanged to the shared target. */\nimport type { AnyRelations } from \"drizzle-orm\";\nimport type { EffectMysql2Database } from \"drizzle-orm/effect-mysql2\";\nimport type { AnyMySqlTable } from \"drizzle-orm/mysql-core\";\nimport { Effect, Context } from \"effect\";\nimport type { SqlError } from \"effect/sql/SqlError\";\n\nimport { Database as DatabaseService } from \"./mysql-database\";\nimport { nativeDatabase } from \"./native-database\";\nimport type { PasswordPersistenceMapping, PasswordRegistrationMapping } from \"./password-model\";\nimport type { PasswordRegistrationAuthority } from \"./password-registration\";\nimport { CurrentPasswordSql } from \"./password-sql\";\nimport type { PasswordSqlQuery } from \"./password-sql\";\nimport {\n coordinateTargetPasswordPersistence,\n coordinateTargetPasswordRegistration,\n makeTargetPasswordPersistenceServices,\n makeTargetPasswordRegistrationServices,\n sqlClientPasswordStandaloneGuard,\n} from \"./password-target\";\nimport type { ProofPersistenceMapping } from \"./proof-model\";\nimport type { ProofSqlQuery } from \"./proof-sql\";\nimport { sqlClientProofStandaloneGuard } from \"./proof-target\";\nimport {\n type TransactionService,\n acquireTransactionService,\n transactionService,\n} from \"./standalone-guard\";\nimport type { SuppliedService } from \"./SuppliedService\";\n\ntype Database = EffectMysql2Database<AnyRelations>;\ntype TransactionOf<D extends Database> = Parameters<Parameters<D[\"transaction\"]>[0]>[0];\n\nconst configuration = (service: TransactionService | undefined) => ({\n mode: \"interactive\" as const,\n locking: true,\n standaloneGuard: sqlClientPasswordStandaloneGuard(service),\n insertIfAbsent: (query: PasswordSqlQuery, selfKey: string, selfValue: unknown) =>\n query.onDuplicateKeyUpdate({ set: { [selfKey]: selfValue } }),\n generatedSubjectRows: (query: PasswordSqlQuery) => query.$returningId(),\n proof: {\n mode: \"interactive\" as const,\n locking: true,\n standaloneGuard: sqlClientProofStandaloneGuard(service),\n insertIfAbsent: (query: ProofSqlQuery, selfKey: string, selfValue: unknown) =>\n query.onDuplicateKeyUpdate({ set: { [selfKey]: selfValue } }),\n },\n});\n\ntype Mapping<\n S extends AnyMySqlTable,\n I extends AnyMySqlTable,\n C extends AnyMySqlTable,\n AC extends AnyMySqlTable,\n A extends AnyMySqlTable,\n RS extends AnyMySqlTable,\n CE extends AnyMySqlTable,\n M extends AnyMySqlTable,\n NativeId,\n> = PasswordPersistenceMapping<S, I, C, AC, A, RS, CE, M, NativeId>;\n\nexport const makeMysqlPasswordPersistenceServices = <\n S extends AnyMySqlTable,\n I extends AnyMySqlTable,\n C extends AnyMySqlTable,\n AC extends AnyMySqlTable,\n A extends AnyMySqlTable,\n RS extends AnyMySqlTable,\n CE extends AnyMySqlTable,\n M extends AnyMySqlTable,\n NativeId,\n>(\n mapping: Mapping<S, I, C, AC, A, RS, CE, M, NativeId>,\n proofMapping?: ProofPersistenceMapping<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >,\n) =>\n Effect.flatMap(\n Effect.map(acquireTransactionService(DatabaseService), configuration),\n (configuration) => makeTargetPasswordPersistenceServices(mapping, configuration, proofMapping),\n ).pipe(\n Effect.provideServiceEffect(CurrentPasswordSql, nativeDatabase(DatabaseService)),\n Effect.provideServiceEffect(NativeDatabase, nativeDatabase(DatabaseService)),\n );\n\nexport function coordinateMysqlPasswordPersistence<\n D extends Database,\n S extends AnyMySqlTable,\n I extends AnyMySqlTable,\n C extends AnyMySqlTable,\n AC extends AnyMySqlTable,\n A extends AnyMySqlTable,\n RS extends AnyMySqlTable,\n CE extends AnyMySqlTable,\n M extends AnyMySqlTable,\n NativeId,\n PM extends\n | ProofPersistenceMapping<any, any, any, any, any, any, any, any, any, any, any, any>\n | undefined,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: Mapping<S, I, C, AC, A, RS, CE, M, NativeId>;\n readonly proofMapping?: PM;\n readonly transaction?: never;\n },\n body: Effect.Effect<Out, E, R>,\n): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, PasswordPersistence> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinateMysqlPasswordPersistence<\n D extends Database,\n S extends AnyMySqlTable,\n I extends AnyMySqlTable,\n C extends AnyMySqlTable,\n AC extends AnyMySqlTable,\n A extends AnyMySqlTable,\n RS extends AnyMySqlTable,\n CE extends AnyMySqlTable,\n M extends AnyMySqlTable,\n NativeId,\n PM extends\n | ProofPersistenceMapping<any, any, any, any, any, any, any, any, any, any, any, any>\n | undefined,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: Mapping<S, I, C, AC, A, RS, CE, M, NativeId>;\n readonly proofMapping?: PM;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<Out, E, R>,\n): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, PasswordPersistence | TxId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinateMysqlPasswordPersistence<\n D extends Database,\n S extends AnyMySqlTable,\n I extends AnyMySqlTable,\n C extends AnyMySqlTable,\n AC extends AnyMySqlTable,\n A extends AnyMySqlTable,\n RS extends AnyMySqlTable,\n CE extends AnyMySqlTable,\n M extends AnyMySqlTable,\n NativeId,\n PM extends\n | ProofPersistenceMapping<any, any, any, any, any, any, any, any, any, any, any, any>\n | undefined,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: Mapping<S, I, C, AC, A, RS, CE, M, NativeId>;\n readonly proofMapping?: PM;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<Out, E, R>,\n): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, PasswordPersistence> | LifecycleHooks | DatabaseRequirements\n> {\n return Effect.flatMap(nativeDatabase(acquire), (database) =>\n coordinateTargetPasswordPersistence<TransactionOf<D>, Out, E, Exclude<R, PasswordPersistence>>(\n database,\n options.mapping,\n configuration(transactionService(database)),\n options.proofMapping,\n (\n transaction: TransactionOf<D>,\n services: { readonly passwordPersistence: PasswordPersistence[\"Service\"] },\n ) => {\n const provided = Context.make(PasswordPersistence, services.passwordPersistence);\n const work = Effect.provideContext(body, provided);\n\n return options.transaction === undefined\n ? work\n : Effect.provideService(work, options.transaction, options.transaction.of(transaction));\n },\n ).pipe(Effect.provideService(NativeDatabase, database)),\n );\n}\n\nexport const makeMysqlPasswordRegistrationServices = <\n Registration,\n S extends AnyMySqlTable,\n I extends AnyMySqlTable,\n C extends AnyMySqlTable,\n AC extends AnyMySqlTable,\n Rq extends AnyMySqlTable,\n NativeId,\n>(\n mapping: PasswordRegistrationMapping<Registration, S, I, C, AC, Rq, NativeId>,\n) =>\n Effect.flatMap(\n Effect.map(acquireTransactionService(DatabaseService), configuration),\n (configuration) => makeTargetPasswordRegistrationServices<Registration>(mapping, configuration),\n ).pipe(\n Effect.provideServiceEffect(CurrentPasswordSql, nativeDatabase(DatabaseService)),\n Effect.provideServiceEffect(NativeDatabase, nativeDatabase(DatabaseService)),\n );\n\nexport function coordinateMysqlPasswordRegistration<\n TargetId,\n Registration,\n D extends Database,\n S extends AnyMySqlTable,\n I extends AnyMySqlTable,\n C extends AnyMySqlTable,\n AC extends AnyMySqlTable,\n Rq extends AnyMySqlTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PasswordRegistrationMapping<NoInfer<Registration>, S, I, C, AC, Rq, NativeId>;\n readonly target: SuppliedService<TargetId, PasswordRegistrationAuthority<Registration>>;\n readonly transaction?: never;\n },\n body: Effect.Effect<Out, E, R>,\n): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinateMysqlPasswordRegistration<\n TargetId,\n Registration,\n D extends Database,\n S extends AnyMySqlTable,\n I extends AnyMySqlTable,\n C extends AnyMySqlTable,\n AC extends AnyMySqlTable,\n Rq extends AnyMySqlTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PasswordRegistrationMapping<NoInfer<Registration>, S, I, C, AC, Rq, NativeId>;\n readonly target: SuppliedService<TargetId, PasswordRegistrationAuthority<Registration>>;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<Out, E, R>,\n): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId | TxId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinateMysqlPasswordRegistration<\n TargetId,\n Registration,\n D extends Database,\n S extends AnyMySqlTable,\n I extends AnyMySqlTable,\n C extends AnyMySqlTable,\n AC extends AnyMySqlTable,\n Rq extends AnyMySqlTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PasswordRegistrationMapping<NoInfer<Registration>, S, I, C, AC, Rq, NativeId>;\n readonly target: SuppliedService<TargetId, PasswordRegistrationAuthority<Registration>>;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<Out, E, R>,\n): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId> | LifecycleHooks | DatabaseRequirements\n> {\n return Effect.flatMap(nativeDatabase(acquire), (database) =>\n coordinateTargetPasswordRegistration<\n Registration,\n TransactionOf<D>,\n Out,\n E,\n Exclude<R, TargetId>\n >(\n database,\n options.mapping,\n configuration(transactionService(database)),\n (\n transaction: TransactionOf<D>,\n services: { readonly registrationAuthority: PasswordRegistrationAuthority<Registration> },\n ) => {\n const provided = Context.make(options.target, services.registrationAuthority);\n const work = Effect.provideContext(body, provided);\n\n return options.transaction === undefined\n ? work\n : Effect.provideService(work, options.transaction, options.transaction.of(transaction));\n },\n ).pipe(Effect.provideService(NativeDatabase, database)),\n );\n}\n\nexport { configuration as mysqlPasswordConfiguration };\n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,oBAAoB,eAAeA,QAAe,CAAC,GAC/E,OAAO,qBAAqB,gBAAgB,eAAeA,QAAe,CAAC,CAC7E;AA8DF,SAAgB,oCAkBd,SACA,SAKA,MAKA;CACA,OAAO,OAAO,QAAQ,eAAe,OAAO,IAAI,aAC9C,qCAOE,UACA,QAAQ,SACR,cAAc,mBAAmB,QAAQ,CAAC,IAExC,aACA,aACG;EACH,MAAM,WAAW,QAAQ,KAAK,QAAQ,QAAQ,SAAS,qBAAqB;EAC5E,MAAM,OAAO,OAAO,eAAe,MAAM,QAAQ;EAEjD,OAAO,QAAQ,gBAAgB,KAAA,IAC3B,OACA,OAAO,eAAe,MAAM,QAAQ,aAAa,QAAQ,YAAY,GAAG,WAAW,CAAC;CAC1F,CACF,CAAC,CAAC,KAAK,OAAO,eAAe,gBAAgB,QAAQ,CAAC,CACxD;AACF"}
|
|
1
|
+
{"version":3,"file":"mysql-passwords.mjs","names":["DatabaseService"],"sources":["../../src/drizzle/mysql-passwords.ts"],"sourcesContent":["import { NativeDatabase } from \"@yielded/auth-persistence/Adapter\";\nimport type { LifecycleHooks, HookConfigurationError } from \"@yielded/auth/Hooks\";\nimport { type PasswordUnavailable, PasswordPersistence } from \"@yielded/auth/Password\";\n/* oxlint-disable no-explicit-any -- proof mapping tables are independently typed by the proof owner; this driver forwards them unchanged to the shared target. */\nimport type { AnyRelations } from \"drizzle-orm\";\nimport type { EffectMysql2Database } from \"drizzle-orm/effect-mysql2\";\nimport type { AnyMySqlTable } from \"drizzle-orm/mysql-core\";\nimport { Effect, Context } from \"effect\";\nimport type { SqlError } from \"effect/sql/SqlError\";\n\nimport { Database as DatabaseService } from \"./mysql-database\";\nimport { nativeDatabase } from \"./native-database\";\nimport type { PasswordPersistenceMapping, PasswordRegistrationMapping } from \"./password-model\";\nimport type { PasswordRegistrationAuthority } from \"./password-registration\";\nimport { CurrentPasswordSql } from \"./password-sql\";\nimport type { PasswordSqlQuery } from \"./password-sql\";\nimport {\n coordinateTargetPasswordPersistence,\n coordinateTargetPasswordRegistration,\n makeTargetPasswordPersistenceServices,\n makeTargetPasswordRegistrationServices,\n sqlClientPasswordStandaloneGuard,\n} from \"./password-target\";\nimport type { ProofPersistenceMapping } from \"./proof-model\";\nimport type { ProofSqlQuery } from \"./proof-sql\";\nimport { sqlClientProofStandaloneGuard } from \"./proof-target\";\nimport {\n type TransactionService,\n acquireTransactionService,\n transactionService,\n} from \"./standalone-guard\";\nimport type { SuppliedService } from \"./SuppliedService\";\n\ntype Database = EffectMysql2Database<AnyRelations>;\ntype TransactionOf<D extends Database> = Parameters<Parameters<D[\"transaction\"]>[0]>[0];\n\nconst configuration = (service: TransactionService | undefined) => ({\n mode: \"interactive\" as const,\n locking: true,\n standaloneGuard: sqlClientPasswordStandaloneGuard(service),\n insertIfAbsent: (query: PasswordSqlQuery, selfKey: string, selfValue: unknown) =>\n query.onDuplicateKeyUpdate({ set: { [selfKey]: selfValue } }),\n generatedSubjectRows: (query: PasswordSqlQuery) => query.$returningId(),\n proof: {\n mode: \"interactive\" as const,\n locking: true,\n standaloneGuard: sqlClientProofStandaloneGuard(service),\n insertIfAbsent: (query: ProofSqlQuery, selfKey: string, selfValue: unknown) =>\n query.onDuplicateKeyUpdate({ set: { [selfKey]: selfValue } }),\n },\n});\n\ntype Mapping<\n S extends AnyMySqlTable,\n I extends AnyMySqlTable,\n C extends AnyMySqlTable,\n AC extends AnyMySqlTable,\n A extends AnyMySqlTable,\n M extends AnyMySqlTable,\n NativeId,\n> = PasswordPersistenceMapping<S, I, C, AC, A, M, NativeId>;\n\nexport const makeMysqlPasswordPersistenceServices = <\n S extends AnyMySqlTable,\n I extends AnyMySqlTable,\n C extends AnyMySqlTable,\n AC extends AnyMySqlTable,\n A extends AnyMySqlTable,\n M extends AnyMySqlTable,\n NativeId,\n>(\n mapping: Mapping<S, I, C, AC, A, M, NativeId>,\n proofMapping?: ProofPersistenceMapping<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >,\n) =>\n Effect.flatMap(\n Effect.map(acquireTransactionService(DatabaseService), configuration),\n (configuration) => makeTargetPasswordPersistenceServices(mapping, configuration, proofMapping),\n ).pipe(\n Effect.provideServiceEffect(CurrentPasswordSql, nativeDatabase(DatabaseService)),\n Effect.provideServiceEffect(NativeDatabase, nativeDatabase(DatabaseService)),\n );\n\nexport function coordinateMysqlPasswordPersistence<\n D extends Database,\n S extends AnyMySqlTable,\n I extends AnyMySqlTable,\n C extends AnyMySqlTable,\n AC extends AnyMySqlTable,\n A extends AnyMySqlTable,\n M extends AnyMySqlTable,\n NativeId,\n PM extends\n | ProofPersistenceMapping<any, any, any, any, any, any, any, any, any, any, any, any>\n | undefined,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: Mapping<S, I, C, AC, A, M, NativeId>;\n readonly proofMapping?: PM;\n readonly transaction?: never;\n },\n body: Effect.Effect<Out, E, R>,\n): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, PasswordPersistence> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinateMysqlPasswordPersistence<\n D extends Database,\n S extends AnyMySqlTable,\n I extends AnyMySqlTable,\n C extends AnyMySqlTable,\n AC extends AnyMySqlTable,\n A extends AnyMySqlTable,\n M extends AnyMySqlTable,\n NativeId,\n PM extends\n | ProofPersistenceMapping<any, any, any, any, any, any, any, any, any, any, any, any>\n | undefined,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: Mapping<S, I, C, AC, A, M, NativeId>;\n readonly proofMapping?: PM;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<Out, E, R>,\n): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, PasswordPersistence | TxId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinateMysqlPasswordPersistence<\n D extends Database,\n S extends AnyMySqlTable,\n I extends AnyMySqlTable,\n C extends AnyMySqlTable,\n AC extends AnyMySqlTable,\n A extends AnyMySqlTable,\n M extends AnyMySqlTable,\n NativeId,\n PM extends\n | ProofPersistenceMapping<any, any, any, any, any, any, any, any, any, any, any, any>\n | undefined,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: Mapping<S, I, C, AC, A, M, NativeId>;\n readonly proofMapping?: PM;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<Out, E, R>,\n): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, PasswordPersistence> | LifecycleHooks | DatabaseRequirements\n> {\n return Effect.flatMap(nativeDatabase(acquire), (database) =>\n coordinateTargetPasswordPersistence<TransactionOf<D>, Out, E, Exclude<R, PasswordPersistence>>(\n database,\n options.mapping,\n configuration(transactionService(database)),\n options.proofMapping,\n (\n transaction: TransactionOf<D>,\n services: { readonly passwordPersistence: PasswordPersistence[\"Service\"] },\n ) => {\n const provided = Context.make(PasswordPersistence, services.passwordPersistence);\n const work = Effect.provideContext(body, provided);\n\n return options.transaction === undefined\n ? work\n : Effect.provideService(work, options.transaction, options.transaction.of(transaction));\n },\n ).pipe(Effect.provideService(NativeDatabase, database)),\n );\n}\n\nexport const makeMysqlPasswordRegistrationServices = <\n Registration,\n S extends AnyMySqlTable,\n I extends AnyMySqlTable,\n C extends AnyMySqlTable,\n AC extends AnyMySqlTable,\n Rq extends AnyMySqlTable,\n NativeId,\n>(\n mapping: PasswordRegistrationMapping<Registration, S, I, C, AC, Rq, NativeId>,\n) =>\n Effect.flatMap(\n Effect.map(acquireTransactionService(DatabaseService), configuration),\n (configuration) => makeTargetPasswordRegistrationServices<Registration>(mapping, configuration),\n ).pipe(\n Effect.provideServiceEffect(CurrentPasswordSql, nativeDatabase(DatabaseService)),\n Effect.provideServiceEffect(NativeDatabase, nativeDatabase(DatabaseService)),\n );\n\nexport function coordinateMysqlPasswordRegistration<\n TargetId,\n Registration,\n D extends Database,\n S extends AnyMySqlTable,\n I extends AnyMySqlTable,\n C extends AnyMySqlTable,\n AC extends AnyMySqlTable,\n Rq extends AnyMySqlTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PasswordRegistrationMapping<NoInfer<Registration>, S, I, C, AC, Rq, NativeId>;\n readonly target: SuppliedService<TargetId, PasswordRegistrationAuthority<Registration>>;\n readonly transaction?: never;\n },\n body: Effect.Effect<Out, E, R>,\n): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinateMysqlPasswordRegistration<\n TargetId,\n Registration,\n D extends Database,\n S extends AnyMySqlTable,\n I extends AnyMySqlTable,\n C extends AnyMySqlTable,\n AC extends AnyMySqlTable,\n Rq extends AnyMySqlTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PasswordRegistrationMapping<NoInfer<Registration>, S, I, C, AC, Rq, NativeId>;\n readonly target: SuppliedService<TargetId, PasswordRegistrationAuthority<Registration>>;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<Out, E, R>,\n): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId | TxId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinateMysqlPasswordRegistration<\n TargetId,\n Registration,\n D extends Database,\n S extends AnyMySqlTable,\n I extends AnyMySqlTable,\n C extends AnyMySqlTable,\n AC extends AnyMySqlTable,\n Rq extends AnyMySqlTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PasswordRegistrationMapping<NoInfer<Registration>, S, I, C, AC, Rq, NativeId>;\n readonly target: SuppliedService<TargetId, PasswordRegistrationAuthority<Registration>>;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<Out, E, R>,\n): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId> | LifecycleHooks | DatabaseRequirements\n> {\n return Effect.flatMap(nativeDatabase(acquire), (database) =>\n coordinateTargetPasswordRegistration<\n Registration,\n TransactionOf<D>,\n Out,\n E,\n Exclude<R, TargetId>\n >(\n database,\n options.mapping,\n configuration(transactionService(database)),\n (\n transaction: TransactionOf<D>,\n services: { readonly registrationAuthority: PasswordRegistrationAuthority<Registration> },\n ) => {\n const provided = Context.make(options.target, services.registrationAuthority);\n const work = Effect.provideContext(body, provided);\n\n return options.transaction === undefined\n ? work\n : Effect.provideService(work, options.transaction, options.transaction.of(transaction));\n },\n ).pipe(Effect.provideService(NativeDatabase, database)),\n );\n}\n\nexport { configuration as mysqlPasswordConfiguration };\n"],"mappings":";;;;;;;;;;AAoCA,MAAM,iBAAiB,aAA6C;CAClE,MAAM;CACN,SAAS;CACT,iBAAiB,iCAAiC,OAAO;CACzD,iBAAiB,OAAyB,SAAiB,cACzD,MAAM,qBAAqB,EAAE,KAAK,GAAG,UAAU,UAAU,EAAE,CAAC;CAC9D,uBAAuB,UAA4B,MAAM,aA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C,IAExC,aACA,aACG;EACH,MAAM,WAAW,QAAQ,KAAK,QAAQ,QAAQ,SAAS,qBAAqB;EAC5E,MAAM,OAAO,OAAO,eAAe,MAAM,QAAQ;EAEjD,OAAO,QAAQ,gBAAgB,KAAA,IAC3B,OACA,OAAO,eAAe,MAAM,QAAQ,aAAa,QAAQ,YAAY,GAAG,WAAW,CAAC;CAC1F,CACF,CAAC,CAAC,KAAK,OAAO,eAAe,gBAAgB,QAAQ,CAAC,CACxD;AACF"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { PersistenceMappingError, makeNativeSqlTables, nativeSqlAlias } from "@yielded/auth-persistence/Adapter";
|
|
2
|
+
import { Param, Placeholder, Table, getTableColumns, is, sql } from "drizzle-orm";
|
|
3
|
+
import { Predicate } from "effect";
|
|
4
|
+
import * as Statement$1 from "effect/sql/Statement";
|
|
5
|
+
//#region src/drizzle/native-sql-table.ts
|
|
6
|
+
const invalid = (cause) => {
|
|
7
|
+
throw PersistenceMappingError.make({
|
|
8
|
+
operation: "mapping",
|
|
9
|
+
cause
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
const capture = (database) => {
|
|
13
|
+
if (!Predicate.hasProperty(database, "select") || typeof database.select !== "function" || !Predicate.hasProperty(database, "insert") || typeof database.insert !== "function" || !Predicate.hasProperty(database, "update") || typeof database.update !== "function") return invalid("Expected a captured Drizzle database");
|
|
14
|
+
const selection = database.select();
|
|
15
|
+
if (!Predicate.hasProperty(selection, "dialect")) return invalid("Expected a captured Drizzle dialect");
|
|
16
|
+
const dialect = selection.dialect;
|
|
17
|
+
if (!Predicate.hasProperty(dialect, "escapeName") || typeof dialect.escapeName !== "function" || !Predicate.hasProperty(dialect, "escapeString") || typeof dialect.escapeString !== "function") return invalid("Expected Drizzle dialect escaping methods");
|
|
18
|
+
if (Predicate.hasProperty(dialect, "codecs") && dialect.codecs !== void 0 && (!Predicate.hasProperty(dialect.codecs, "apply") || typeof dialect.codecs.apply !== "function")) return invalid("Expected Drizzle dialect codecs");
|
|
19
|
+
return {
|
|
20
|
+
database,
|
|
21
|
+
dialect
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
const compileWith = (dialect) => (expression) => {
|
|
25
|
+
const slots = [];
|
|
26
|
+
const query = expression.toQuery({
|
|
27
|
+
escapeName: (name) => {
|
|
28
|
+
if (name.includes("\0")) return invalid("NUL in SQL identifier");
|
|
29
|
+
return dialect.escapeName(name);
|
|
30
|
+
},
|
|
31
|
+
escapeString: (value) => {
|
|
32
|
+
if (value.includes("\0")) return invalid("NUL in SQL literal");
|
|
33
|
+
return dialect.escapeString(value);
|
|
34
|
+
},
|
|
35
|
+
escapeParam: (index) => {
|
|
36
|
+
if (index !== slots.length) return invalid("Invalid Drizzle parameter order");
|
|
37
|
+
const slot = `yielded_parameter_${index}`;
|
|
38
|
+
slots.push(slot);
|
|
39
|
+
return `\0${slot}\0`;
|
|
40
|
+
},
|
|
41
|
+
...dialect.codecs === void 0 ? {} : { codecs: dialect.codecs }
|
|
42
|
+
});
|
|
43
|
+
const parts = query.sql.split("\0");
|
|
44
|
+
if (parts.length !== slots.length * 2 + 1 || query.params.length !== slots.length) return invalid("NUL or parameter marker collision in Drizzle SQL");
|
|
45
|
+
const segments = [];
|
|
46
|
+
const consumed = /* @__PURE__ */ new Set();
|
|
47
|
+
for (let offset = 0; offset < parts.length; offset += 2) {
|
|
48
|
+
segments.push(Statement$1.literal(parts[offset]));
|
|
49
|
+
if (offset + 1 === parts.length) break;
|
|
50
|
+
const index = slots.indexOf(parts[offset + 1]);
|
|
51
|
+
if (index < 0 || consumed.has(index)) return invalid("NUL or parameter marker collision in Drizzle SQL");
|
|
52
|
+
consumed.add(index);
|
|
53
|
+
const value = query.params[index];
|
|
54
|
+
if (is(value, Placeholder) || is(value, Param)) return invalid("Unbound Drizzle placeholder");
|
|
55
|
+
if (Statement$1.isFragment(value)) segments.push(...value.segments);
|
|
56
|
+
else segments.push(Statement$1.parameter(value));
|
|
57
|
+
}
|
|
58
|
+
return Statement$1.fragment(segments);
|
|
59
|
+
};
|
|
60
|
+
/** Preserve native Statement expressions in writes without applying a column
|
|
61
|
+
* codec to them. Ordinary values still pass through Drizzle's own builders. */
|
|
62
|
+
const writeValues = (values) => Object.fromEntries(Object.entries(values).map(([key, value]) => [key, Statement$1.isFragment(value) ? sql`${sql.param(value)}` : value]));
|
|
63
|
+
/** Capture the root database's compiler, not a later transaction object's
|
|
64
|
+
* client. Call insert/update inside the operation to materialize hooks once. */
|
|
65
|
+
const makeDrizzleSqlTables = (client, capturedDatabase) => {
|
|
66
|
+
const { database, dialect } = capture(capturedDatabase);
|
|
67
|
+
const compile = compileWith(dialect);
|
|
68
|
+
return makeNativeSqlTables(client, (_client, physical) => {
|
|
69
|
+
if (!is(physical, Table)) return invalid("Expected a Drizzle table");
|
|
70
|
+
const columns = getTableColumns(physical);
|
|
71
|
+
const entries = Object.entries(columns);
|
|
72
|
+
const getColumn = (key) => {
|
|
73
|
+
const column = Object.hasOwn(columns, key) ? columns[key] : void 0;
|
|
74
|
+
if (column === void 0) return invalid("Missing Drizzle column");
|
|
75
|
+
return column;
|
|
76
|
+
};
|
|
77
|
+
const bind = (alias) => {
|
|
78
|
+
const reference = (key) => {
|
|
79
|
+
const column = getColumn(key);
|
|
80
|
+
return alias === void 0 ? sql`${column}` : sql`${sql.identifier(alias)}.${sql.identifier(column.name)}`;
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
name: compile(alias === void 0 ? sql`${physical}` : sql`${physical} AS ${sql.identifier(alias)}`),
|
|
84
|
+
as: bind,
|
|
85
|
+
column: (key) => compile(reference(key)),
|
|
86
|
+
fields: (prefix) => compile(sql.join(entries.map(([key, column], index) => {
|
|
87
|
+
const selection = dialect.codecs === void 0 ? reference(key) : dialect.codecs.apply(column, "cast", reference(key));
|
|
88
|
+
return sql`${selection} as ${sql.identifier(nativeSqlAlias(prefix, index))}`;
|
|
89
|
+
}), sql`, `)),
|
|
90
|
+
decode: (row, prefix) => Object.fromEntries(entries.map(([key, column], index) => {
|
|
91
|
+
const alias = nativeSqlAlias(prefix, index);
|
|
92
|
+
if (!Object.hasOwn(row, alias)) return invalid("Missing SQL projection field");
|
|
93
|
+
const value = row[alias];
|
|
94
|
+
return [key, value === null ? null : column.mapFromDriverValue(dialect.codecs === void 0 ? value : dialect.codecs.apply(column, "normalize", value))];
|
|
95
|
+
})),
|
|
96
|
+
value: (key, value) => {
|
|
97
|
+
const column = getColumn(key);
|
|
98
|
+
return Statement$1.isFragment(value) ? value : compile(sql`${sql.param(value, column)}`);
|
|
99
|
+
},
|
|
100
|
+
insert: (values) => compile(database.insert(physical).values(writeValues(values)).getSQL()),
|
|
101
|
+
update: (values) => compile(database.update(physical).set(writeValues(values)).getSQL())
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
return bind();
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
//#endregion
|
|
108
|
+
export { makeDrizzleSqlTables };
|
|
109
|
+
|
|
110
|
+
//# sourceMappingURL=native-sql-table.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-sql-table.mjs","names":["Statement"],"sources":["../../src/drizzle/native-sql-table.ts"],"sourcesContent":["import {\n PersistenceMappingError,\n makeNativeSqlTables,\n nativeSqlAlias,\n type NativeSqlTables,\n type SqlTable,\n} from \"@yielded/auth-persistence/Adapter\";\nimport {\n getTableColumns,\n is,\n Param,\n Placeholder,\n type SQL,\n Table,\n sql,\n type BuildQueryConfig,\n type SQLWrapper,\n} from \"drizzle-orm\";\nimport { Predicate } from \"effect\";\nimport type { SqlClient } from \"effect/sql/SqlClient\";\nimport * as Statement from \"effect/sql/Statement\";\n\ntype CapturedDialect = Pick<BuildQueryConfig, \"escapeName\" | \"escapeString\" | \"codecs\">;\n\n/** Foreign compiler boundary only: builders are used to materialize SQL, never\n * executed. The select builder exposes the original dialect even through the\n * Durable Object database projection, which retains bound query methods. */\ninterface CapturedDatabase {\n readonly select: () => { readonly dialect: CapturedDialect };\n readonly insert: (table: Table) => {\n readonly values: (values: Record<string, unknown>) => SQLWrapper;\n };\n readonly update: (table: Table) => {\n readonly set: (values: Record<string, unknown>) => SQLWrapper;\n };\n}\n\nconst invalid = (cause: string): never => {\n throw PersistenceMappingError.make({ operation: \"mapping\", cause });\n};\n\nconst capture = (\n database: object,\n): { readonly database: CapturedDatabase; readonly dialect: CapturedDialect } => {\n if (\n !Predicate.hasProperty(database, \"select\") ||\n typeof database.select !== \"function\" ||\n !Predicate.hasProperty(database, \"insert\") ||\n typeof database.insert !== \"function\" ||\n !Predicate.hasProperty(database, \"update\") ||\n typeof database.update !== \"function\"\n )\n return invalid(\"Expected a captured Drizzle database\");\n\n const selection: unknown = database.select();\n\n if (!Predicate.hasProperty(selection, \"dialect\"))\n return invalid(\"Expected a captured Drizzle dialect\");\n const dialect = selection.dialect;\n\n if (\n !Predicate.hasProperty(dialect, \"escapeName\") ||\n typeof dialect.escapeName !== \"function\" ||\n !Predicate.hasProperty(dialect, \"escapeString\") ||\n typeof dialect.escapeString !== \"function\"\n )\n return invalid(\"Expected Drizzle dialect escaping methods\");\n\n if (\n Predicate.hasProperty(dialect, \"codecs\") &&\n dialect.codecs !== undefined &&\n (!Predicate.hasProperty(dialect.codecs, \"apply\") || typeof dialect.codecs.apply !== \"function\")\n )\n return invalid(\"Expected Drizzle dialect codecs\");\n\n // Drizzle's private dialect and generic query builders are erased only here.\n return { database: database as CapturedDatabase, dialect: dialect as CapturedDialect };\n};\n\nconst compileWith =\n (dialect: CapturedDialect) =>\n (expression: SQL): Statement.Fragment => {\n const slots: string[] = [];\n\n const query = expression.toQuery({\n escapeName: (name) => {\n if (name.includes(\"\\0\")) return invalid(\"NUL in SQL identifier\");\n\n return dialect.escapeName(name);\n },\n escapeString: (value) => {\n if (value.includes(\"\\0\")) return invalid(\"NUL in SQL literal\");\n\n return dialect.escapeString(value);\n },\n escapeParam: (index) => {\n if (index !== slots.length) return invalid(\"Invalid Drizzle parameter order\");\n const slot = `yielded_parameter_${index}`;\n\n slots.push(slot);\n\n return `\\0${slot}\\0`;\n },\n ...(dialect.codecs === undefined ? {} : { codecs: dialect.codecs }),\n });\n\n // Only compiler-emitted slots are translated. Native Statement parameters\n // receive their final positions when composed; SQL literals containing $1 or\n // ? are never inspected or rewritten. NUL is reserved for this compilation.\n const parts = query.sql.split(\"\\0\");\n\n if (parts.length !== slots.length * 2 + 1 || query.params.length !== slots.length)\n return invalid(\"NUL or parameter marker collision in Drizzle SQL\");\n\n const segments: Statement.Segment[] = [];\n const consumed = new Set<number>();\n\n for (let offset = 0; offset < parts.length; offset += 2) {\n segments.push(Statement.literal(parts[offset]));\n if (offset + 1 === parts.length) break;\n const index = slots.indexOf(parts[offset + 1]);\n\n if (index < 0 || consumed.has(index))\n return invalid(\"NUL or parameter marker collision in Drizzle SQL\");\n consumed.add(index);\n const value: unknown = query.params[index];\n\n if (is(value, Placeholder) || is(value, Param)) return invalid(\"Unbound Drizzle placeholder\");\n if (Statement.isFragment(value)) segments.push(...value.segments);\n else segments.push(Statement.parameter(value));\n }\n\n return Statement.fragment(segments);\n };\n\n/** Preserve native Statement expressions in writes without applying a column\n * codec to them. Ordinary values still pass through Drizzle's own builders. */\nconst writeValues = (values: Readonly<Record<string, unknown>>) =>\n Object.fromEntries(\n Object.entries(values).map(([key, value]) => [\n key,\n Statement.isFragment(value) ? sql`${sql.param(value)}` : value,\n ]),\n );\n\n/** Capture the root database's compiler, not a later transaction object's\n * client. Call insert/update inside the operation to materialize hooks once. */\nexport const makeDrizzleSqlTables = (\n client: SqlClient,\n capturedDatabase: object,\n): NativeSqlTables => {\n const { database, dialect } = capture(capturedDatabase);\n const compile = compileWith(dialect);\n\n return makeNativeSqlTables(client, (_client, physical): SqlTable => {\n if (!is(physical, Table)) return invalid(\"Expected a Drizzle table\");\n const columns = getTableColumns(physical);\n const entries = Object.entries(columns);\n\n const getColumn = (key: string) => {\n const column = Object.hasOwn(columns, key) ? columns[key] : undefined;\n\n if (column === undefined) return invalid(\"Missing Drizzle column\");\n\n return column;\n };\n\n const bind = (alias?: string): SqlTable => {\n const reference = (key: string) => {\n const column = getColumn(key);\n\n return alias === undefined\n ? sql`${column}`\n : sql`${sql.identifier(alias)}.${sql.identifier(column.name)}`;\n };\n\n return {\n name: compile(\n alias === undefined ? sql`${physical}` : sql`${physical} AS ${sql.identifier(alias)}`,\n ),\n as: bind,\n column: (key) => compile(reference(key)),\n fields: (prefix) =>\n compile(\n sql.join(\n entries.map(([key, column], index) => {\n const selection =\n dialect.codecs === undefined\n ? reference(key)\n : dialect.codecs.apply(column, \"cast\", reference(key));\n\n return sql`${selection} as ${sql.identifier(nativeSqlAlias(prefix, index))}`;\n }),\n sql`, `,\n ),\n ),\n decode: (row, prefix) =>\n Object.fromEntries(\n entries.map(([key, column], index) => {\n const alias = nativeSqlAlias(prefix, index);\n\n if (!Object.hasOwn(row, alias)) return invalid(\"Missing SQL projection field\");\n const value = row[alias];\n\n return [\n key,\n value === null\n ? null\n : column.mapFromDriverValue(\n dialect.codecs === undefined\n ? value\n : dialect.codecs.apply(column, \"normalize\", value),\n ),\n ];\n }),\n ),\n value: (key, value) => {\n const column = getColumn(key);\n\n return Statement.isFragment(value) ? value : compile(sql`${sql.param(value, column)}`);\n },\n insert: (values) => compile(database.insert(physical).values(writeValues(values)).getSQL()),\n update: (values) => compile(database.update(physical).set(writeValues(values)).getSQL()),\n };\n };\n\n return bind();\n });\n};\n"],"mappings":";;;;;AAqCA,MAAM,WAAW,UAAyB;CACxC,MAAM,wBAAwB,KAAK;EAAE,WAAW;EAAW;CAAM,CAAC;AACpE;AAEA,MAAM,WACJ,aAC+E;CAC/E,IACE,CAAC,UAAU,YAAY,UAAU,QAAQ,KACzC,OAAO,SAAS,WAAW,cAC3B,CAAC,UAAU,YAAY,UAAU,QAAQ,KACzC,OAAO,SAAS,WAAW,cAC3B,CAAC,UAAU,YAAY,UAAU,QAAQ,KACzC,OAAO,SAAS,WAAW,YAE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AC,CAAC,OAAO,YAAY,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IAC1F,SAAS,WAAW,QAAQ,SAAS,OAAO,QAAQ,CAAC,CAAC,IAAI,YAAY,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;GACzF;EACF;EAEA,OAAO,KAAK;CACd,CAAC;AACH"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { OAuthTargetConfiguration } from "./oauth-target.mjs";
|
|
2
2
|
import { Mapping, Revocations, oauth_connected_state_d_exports } from "./oauth-connected-state.mjs";
|
|
3
3
|
import { Crypto, Effect, Layer, Schema } from "effect";
|
|
4
|
+
import { Statement } from "effect/sql/Statement";
|
|
4
5
|
import * as M from "@yielded/auth/OAuth";
|
|
5
6
|
import { OAuthConnectedPersistence, OAuthConnectedRevocationDecision, OAuthConnectedRevocations, OAuthExternalIdentity, PrepareOAuthCommit } from "@yielded/auth/OAuth";
|
|
6
|
-
import { Statement } from "effect/sql/Statement";
|
|
7
7
|
//#region src/drizzle/oauth-connected-target.d.ts
|
|
8
8
|
export declare const makeTargetOAuthConnectedServices: (mapping: Mapping, configuration: OAuthTargetConfiguration) => Effect.Effect<{
|
|
9
9
|
oauthConnectedPersistence: {
|
|
@@ -21,10 +21,10 @@ export declare const makeTargetOAuthConnectedServices: (mapping: Mapping, config
|
|
|
21
21
|
readonly outcome: M.OAuthSignInAccessOutcome;
|
|
22
22
|
}, prepare: PrepareOAuthCommit<{
|
|
23
23
|
readonly _tag: "Rejected";
|
|
24
|
-
} | {
|
|
25
|
-
readonly _tag: "Cancelled";
|
|
26
24
|
} | {
|
|
27
25
|
readonly _tag: "Ambiguous";
|
|
26
|
+
} | {
|
|
27
|
+
readonly _tag: "Cancelled";
|
|
28
28
|
} | {
|
|
29
29
|
readonly _tag: "Connected";
|
|
30
30
|
readonly grant: {
|
|
@@ -477,10 +477,10 @@ export declare const makeTargetOAuthConnectedServices: (mapping: Mapping, config
|
|
|
477
477
|
readonly nowMillis: number;
|
|
478
478
|
}, prepare: PrepareOAuthCommit<{
|
|
479
479
|
readonly _tag: "Rejected";
|
|
480
|
-
} | {
|
|
481
|
-
readonly _tag: "Cancelled";
|
|
482
480
|
} | {
|
|
483
481
|
readonly _tag: "Ambiguous";
|
|
482
|
+
} | {
|
|
483
|
+
readonly _tag: "Cancelled";
|
|
484
484
|
} | {
|
|
485
485
|
readonly _tag: "Connected";
|
|
486
486
|
readonly grant: {
|
|
@@ -6,8 +6,8 @@ import { TransactionCoordinatorError, TransactionTargetConfiguration } from "./t
|
|
|
6
6
|
import { NativeDatabase } from "@yielded/auth-persistence/Adapter";
|
|
7
7
|
import { Context, Crypto, Effect, Layer } from "effect";
|
|
8
8
|
import { LifecycleHooks } from "@yielded/auth/Hooks";
|
|
9
|
-
import { OAuthAccountRevision, OAuthAccountsPersistence, OAuthClaim, OAuthClaimDecision, OAuthCleanupInput, OAuthCredentialSnapshot, OAuthIssueDecision, OAuthLinkClaimDecision, OAuthLinkDecision, OAuthLinkIssueDecision, OAuthLinkPendingFlow, OAuthPendingFlow, OAuthRegistrationIntent, OAuthRegistrationIntents, OAuthSettlementDecision, OAuthSignInPersistence, OAuthUnavailable, OAuthUnlinkDecision, OAuthUnlinkInspection, OAuthVerifiedExternalIdentity, PrepareOAuthCommit } from "@yielded/auth/OAuth";
|
|
10
9
|
import { Statement } from "effect/sql/Statement";
|
|
10
|
+
import { OAuthAccountRevision, OAuthAccountsPersistence, OAuthClaim, OAuthClaimDecision, OAuthCleanupInput, OAuthCredentialSnapshot, OAuthIssueDecision, OAuthLinkClaimDecision, OAuthLinkDecision, OAuthLinkIssueDecision, OAuthLinkPendingFlow, OAuthPendingFlow, OAuthRegistrationIntent, OAuthRegistrationIntents, OAuthSettlementDecision, OAuthSignInPersistence, OAuthUnavailable, OAuthUnlinkDecision, OAuthUnlinkInspection, OAuthVerifiedExternalIdentity, PrepareOAuthCommit } from "@yielded/auth/OAuth";
|
|
11
11
|
//#region src/drizzle/oauth-target.d.ts
|
|
12
12
|
export type OAuthTargetConfiguration = TransactionTargetConfiguration<OAuthUnavailable>;
|
|
13
13
|
export type OAuthCoordinatorError<E> = TransactionCoordinatorError<E, OAuthUnavailable>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DrizzleTableModel } from "./table-model.mjs";
|
|
2
2
|
import * as Shared from "@yielded/auth-persistence/Adapter";
|
|
3
|
-
import { PasswordAttemptAction, PasswordAttemptRecord, PasswordAttemptState, PasswordConstraintClassifier,
|
|
3
|
+
import { PasswordAttemptAction, PasswordAttemptRecord, PasswordAttemptState, PasswordConstraintClassifier, PasswordRegistrationConstraintClassifier, PasswordRegistrationIntent, PasswordRegistrationState, RequiredPasswordConstraints, RequiredPasswordRegistrationConstraints, requiredPasswordConstraints, requiredPasswordRegistrationConstraints } from "@yielded/auth-persistence/Adapter";
|
|
4
4
|
import { SQL, Table } from "drizzle-orm";
|
|
5
5
|
//#region src/drizzle/password-model.d.ts
|
|
6
6
|
export type PasswordSubjectTable<Subject extends Table, _NativeSubjectId> = Shared.PasswordSubjectTable<DrizzleTableModel<Subject>, _NativeSubjectId>;
|
|
@@ -8,17 +8,15 @@ export type PasswordIdentifierTable<Identifier extends Table, NativeSubjectId> =
|
|
|
8
8
|
export type PasswordAuthorityCredentialTable<Credential extends Table, NativeSubjectId> = Shared.PasswordAuthorityCredentialTable<DrizzleTableModel<Credential>, NativeSubjectId>;
|
|
9
9
|
export type PasswordCredentialTable<Subject extends Table, Identifier extends Table, Credential extends Table, NativeSubjectId> = Shared.PasswordCredentialTable<DrizzleTableModel<Subject>, DrizzleTableModel<Identifier>, DrizzleTableModel<Credential>, NativeSubjectId>;
|
|
10
10
|
export type PasswordAttemptTable<Attempt extends Table, NativeSubjectId> = Shared.PasswordAttemptTable<DrizzleTableModel<Attempt>, NativeSubjectId>;
|
|
11
|
-
export type PasswordRateScopeTable<RateScope extends Table> = Shared.PasswordRateScopeTable<DrizzleTableModel<RateScope>>;
|
|
12
|
-
export type PasswordChargeTable<Charge extends Table> = Shared.PasswordChargeTable<DrizzleTableModel<Charge>>;
|
|
13
11
|
export type PasswordCommandTable<Command extends Table> = Shared.PasswordCommandTable<DrizzleTableModel<Command>>;
|
|
14
12
|
export type PasswordD1Clock = Shared.PasswordD1Clock<SQL>;
|
|
15
|
-
export type PasswordPersistenceMapping<Subject extends Table, Identifier extends Table, Credential extends Table, AuthorityCredential extends Table, Attempt extends Table,
|
|
16
|
-
export type D1PasswordPersistenceMapping<Subject extends Table, Identifier extends Table, Credential extends Table, AuthorityCredential extends Table, Attempt extends Table,
|
|
13
|
+
export type PasswordPersistenceMapping<Subject extends Table, Identifier extends Table, Credential extends Table, AuthorityCredential extends Table, Attempt extends Table, Command extends Table, NativeSubjectId> = Shared.PasswordPersistenceMapping<DrizzleTableModel<Subject>, DrizzleTableModel<Identifier>, DrizzleTableModel<Credential>, DrizzleTableModel<AuthorityCredential>, DrizzleTableModel<Attempt>, DrizzleTableModel<Command>, NativeSubjectId, SQL>;
|
|
14
|
+
export type D1PasswordPersistenceMapping<Subject extends Table, Identifier extends Table, Credential extends Table, AuthorityCredential extends Table, Attempt extends Table, Command extends Table, NativeSubjectId> = Shared.D1PasswordPersistenceMapping<DrizzleTableModel<Subject>, DrizzleTableModel<Identifier>, DrizzleTableModel<Credential>, DrizzleTableModel<AuthorityCredential>, DrizzleTableModel<Attempt>, DrizzleTableModel<Command>, NativeSubjectId, SQL>;
|
|
17
15
|
export type PasswordRegistrationTable<Registration, Request extends Table, NativeSubjectId> = Shared.PasswordRegistrationTable<Registration, DrizzleTableModel<Request>, NativeSubjectId>;
|
|
18
16
|
export type PasswordRegistrationProvisioning<Registration, Subject extends Table, NativeSubjectId> = Shared.PasswordRegistrationProvisioning<Registration, DrizzleTableModel<Subject>, NativeSubjectId>;
|
|
19
17
|
export type PasswordRegistrationMapping<Registration, Subject extends Table, Identifier extends Table, Credential extends Table, AuthorityCredential extends Table, Request extends Table, NativeSubjectId> = Shared.PasswordRegistrationMapping<Registration, DrizzleTableModel<Subject>, DrizzleTableModel<Identifier>, DrizzleTableModel<Credential>, DrizzleTableModel<AuthorityCredential>, DrizzleTableModel<Request>, NativeSubjectId, SQL>;
|
|
20
|
-
export type AnyPasswordPersistenceMapping = PasswordPersistenceMapping<Table, Table, Table, Table, Table, Table,
|
|
18
|
+
export type AnyPasswordPersistenceMapping = PasswordPersistenceMapping<Table, Table, Table, Table, Table, Table, unknown>;
|
|
21
19
|
export type AnyPasswordRegistrationMapping<Registration = unknown> = PasswordRegistrationMapping<Registration, Table, Table, Table, Table, Table, unknown>;
|
|
22
20
|
//#endregion
|
|
23
|
-
export { type PasswordAttemptAction, type PasswordAttemptRecord, type PasswordAttemptState, type PasswordConstraintClassifier, type
|
|
21
|
+
export { type PasswordAttemptAction, type PasswordAttemptRecord, type PasswordAttemptState, type PasswordConstraintClassifier, type PasswordRegistrationConstraintClassifier, type PasswordRegistrationIntent, type PasswordRegistrationState, type RequiredPasswordConstraints, type RequiredPasswordRegistrationConstraints, requiredPasswordConstraints, requiredPasswordRegistrationConstraints };
|
|
24
22
|
//# sourceMappingURL=password-model.d.mts.map
|
|
@@ -63,8 +63,8 @@ export declare const requiredPasswordPreparedConstraints: {
|
|
|
63
63
|
readonly digest: "unique(intent.digest)";
|
|
64
64
|
};
|
|
65
65
|
export type RequiredPasswordPreparedConstraints = typeof requiredPasswordPreparedConstraints;
|
|
66
|
-
export interface PasswordPreparedPersistenceMapping<Subject extends Table, Identifier extends Table, Credential extends Table, AuthorityCredential extends Table, Attempt extends Table,
|
|
67
|
-
readonly password: PasswordPersistenceMapping<Subject, Identifier, Credential, AuthorityCredential, Attempt,
|
|
66
|
+
export interface PasswordPreparedPersistenceMapping<Subject extends Table, Identifier extends Table, Credential extends Table, AuthorityCredential extends Table, Attempt extends Table, Command extends Table, Intent extends Table, Admission extends Table, NativeSubjectId> {
|
|
67
|
+
readonly password: PasswordPersistenceMapping<Subject, Identifier, Credential, AuthorityCredential, Attempt, Command, NativeSubjectId>;
|
|
68
68
|
readonly intent: PasswordPreparedIntentTable<Intent, NativeSubjectId>;
|
|
69
69
|
readonly admission: PasswordPreparedAdmissionTable<Admission>;
|
|
70
70
|
readonly constraints: RequiredPasswordPreparedConstraints;
|
|
@@ -72,12 +72,12 @@ export interface PasswordPreparedPersistenceMapping<Subject extends Table, Ident
|
|
|
72
72
|
/** Required by synchronous owners, invoked inside their actual transactionSync. */
|
|
73
73
|
readonly allocateVersionSync?: () => PasswordPreparedVersion;
|
|
74
74
|
}
|
|
75
|
-
export type D1PasswordPreparedPersistenceMapping<Subject extends Table, Identifier extends Table, Credential extends Table, AuthorityCredential extends Table, Attempt extends Table,
|
|
75
|
+
export type D1PasswordPreparedPersistenceMapping<Subject extends Table, Identifier extends Table, Credential extends Table, AuthorityCredential extends Table, Attempt extends Table, Command extends Table, Intent extends Table, Admission extends Table, NativeSubjectId> = PasswordPreparedPersistenceMapping<Subject, Identifier, Credential, AuthorityCredential, Attempt, Command, Intent, Admission, NativeSubjectId> & {
|
|
76
76
|
/** Convert a stored native instant to epoch milliseconds in the same SQL engine. */
|
|
77
77
|
readonly admissionClock: {
|
|
78
78
|
readonly toMillis: (instant: SQL) => SQL;
|
|
79
79
|
};
|
|
80
|
-
readonly password: D1PasswordPersistenceMapping<Subject, Identifier, Credential, AuthorityCredential, Attempt,
|
|
80
|
+
readonly password: D1PasswordPersistenceMapping<Subject, Identifier, Credential, AuthorityCredential, Attempt, Command, NativeSubjectId>;
|
|
81
81
|
};
|
|
82
82
|
/** Optional real proof completion authority. Request/delivery/abuse capabilities
|
|
83
83
|
* are not required to complete the original continuation. */
|
|
@@ -87,6 +87,6 @@ export type PasswordPreparedProofMapping<Series extends Table, Continuation exte
|
|
|
87
87
|
export type D1PasswordPreparedProofMapping<Series extends Table, Continuation extends Table, Command extends Table, Subject extends Table, Identifier extends Table, Credential extends Table, NativeSubjectId> = Pick<D1ProofPersistenceMapping<Table, Series, Table, Continuation, Table, Table, Table, Command, Subject, Identifier, Credential, NativeSubjectId>, Exclude<keyof PasswordPreparedProofMapping<Series, Continuation, Command, Subject, Identifier, Credential, NativeSubjectId>, "constraints">> & {
|
|
88
88
|
readonly constraints: PasswordPreparedProofMapping<Series, Continuation, Command, Subject, Identifier, Credential, NativeSubjectId>["constraints"];
|
|
89
89
|
};
|
|
90
|
-
export type AnyPasswordPreparedPersistenceMapping = PasswordPreparedPersistenceMapping<Table, Table, Table, Table, Table, Table, Table, Table,
|
|
90
|
+
export type AnyPasswordPreparedPersistenceMapping = PasswordPreparedPersistenceMapping<Table, Table, Table, Table, Table, Table, Table, Table, unknown>;
|
|
91
91
|
//#endregion
|
|
92
92
|
//# sourceMappingURL=password-prepared-model.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"password-prepared-model.mjs","names":[],"sources":["../../src/drizzle/password-prepared-model.ts"],"sourcesContent":["import type {\n PasswordPreparedReady,\n PasswordPreparedReservation,\n PasswordPreparedVersion,\n} from \"@yielded/auth/Password\";\nimport type { InferInsertModel, InferSelectModel, SQL, Table } from \"drizzle-orm\";\nimport type { Effect } from \"effect\";\n\nimport type { PersistenceMappingError } from \"./model\";\nimport type { D1PasswordPersistenceMapping, PasswordPersistenceMapping } from \"./password-model\";\nimport type {\n D1ProofPersistenceMapping,\n ProofPersistenceMapping,\n RequiredProofConstraints,\n} from \"./proof-model\";\n\ntype ColumnKey<T extends Table> = Extract<keyof T[\"_\"][\"columns\"], string>;\nexport type PasswordPreparedState = \"Preparing\" | \"Ready\" | \"Consumed\" | \"Cancelled\" | \"Expired\";\n\n/** The retained intent is also its nonrefundable admission charge. Scalar identity,\n * scope and timing columns survive sensitive snapshot/digest erasure. */\nexport interface PasswordPreparedIntentTable<Intent extends Table, NativeSubjectId> {\n readonly table: Intent;\n readonly moduleId: ColumnKey<Intent>;\n readonly intentId: ColumnKey<Intent>;\n readonly commandId: ColumnKey<Intent>;\n readonly subjectId: ColumnKey<Intent>;\n readonly action: ColumnKey<Intent>;\n readonly generation: ColumnKey<Intent>;\n readonly version: ColumnKey<Intent>;\n readonly state: ColumnKey<Intent>;\n readonly digest: ColumnKey<Intent>;\n readonly snapshot: ColumnKey<Intent>;\n readonly identifierScope: ColumnKey<Intent>;\n readonly createdAt: ColumnKey<Intent>;\n readonly admittedAt: ColumnKey<Intent>;\n readonly admissionRetainUntil: ColumnKey<Intent>;\n readonly preparationExpiresAt: ColumnKey<Intent>;\n readonly expiresAt: ColumnKey<Intent>;\n readonly retainUntil: ColumnKey<Intent>;\n readonly states: Readonly<\n Record<PasswordPreparedState, InferSelectModel<Intent>[ColumnKey<Intent>]>\n >;\n readonly encodeInsert: (input: {\n readonly reservation: PasswordPreparedReservation;\n readonly nativeSubjectId: NativeSubjectId;\n readonly identifierScope: string;\n readonly admittedAtMillis: number;\n readonly admissionRetainUntilMillis: number;\n /** Bounded private core codec output; contains a salted verifier for Change/Reset. */\n readonly snapshot: string;\n }) => InferInsertModel<Intent>;\n readonly encodeReady: (input: {\n readonly ready: PasswordPreparedReady;\n readonly snapshot: string;\n }) => Partial<InferInsertModel<Intent>>;\n /** Erase snapshot and digest, preserving every identity/scope/time column. */\n readonly encodeTerminal: (\n state: Exclude<PasswordPreparedState, \"Preparing\" | \"Ready\">,\n ) => Partial<InferInsertModel<Intent>>;\n}\n\n/** One permanent row per configured module; never one row per attacker input.\n * Native owners lock this before subject → identifier → sorted credentials → intent.\n * It serializes admission and maintenance without process-local locks. */\nexport interface PasswordPreparedAdmissionTable<Admission extends Table> {\n readonly table: Admission;\n readonly moduleId: ColumnKey<Admission>;\n readonly intentId: ColumnKey<Admission>;\n readonly admittedAt: ColumnKey<Admission>;\n readonly admissionRetainUntil: ColumnKey<Admission>;\n readonly encodeInsert: (moduleId: string) => InferInsertModel<Admission>;\n}\n\nexport const requiredPasswordPreparedConstraints = {\n admission: \"unique(admission.moduleId)\",\n intent: \"unique(intent.moduleId,intent.intentId)\",\n command: \"unique(intent.moduleId,intent.commandId)\",\n digest: \"unique(intent.digest)\",\n} as const;\n\nexport type RequiredPasswordPreparedConstraints = typeof requiredPasswordPreparedConstraints;\n\nexport interface PasswordPreparedPersistenceMapping<\n Subject extends Table,\n Identifier extends Table,\n Credential extends Table,\n AuthorityCredential extends Table,\n Attempt extends Table,\n
|
|
1
|
+
{"version":3,"file":"password-prepared-model.mjs","names":[],"sources":["../../src/drizzle/password-prepared-model.ts"],"sourcesContent":["import type {\n PasswordPreparedReady,\n PasswordPreparedReservation,\n PasswordPreparedVersion,\n} from \"@yielded/auth/Password\";\nimport type { InferInsertModel, InferSelectModel, SQL, Table } from \"drizzle-orm\";\nimport type { Effect } from \"effect\";\n\nimport type { PersistenceMappingError } from \"./model\";\nimport type { D1PasswordPersistenceMapping, PasswordPersistenceMapping } from \"./password-model\";\nimport type {\n D1ProofPersistenceMapping,\n ProofPersistenceMapping,\n RequiredProofConstraints,\n} from \"./proof-model\";\n\ntype ColumnKey<T extends Table> = Extract<keyof T[\"_\"][\"columns\"], string>;\nexport type PasswordPreparedState = \"Preparing\" | \"Ready\" | \"Consumed\" | \"Cancelled\" | \"Expired\";\n\n/** The retained intent is also its nonrefundable admission charge. Scalar identity,\n * scope and timing columns survive sensitive snapshot/digest erasure. */\nexport interface PasswordPreparedIntentTable<Intent extends Table, NativeSubjectId> {\n readonly table: Intent;\n readonly moduleId: ColumnKey<Intent>;\n readonly intentId: ColumnKey<Intent>;\n readonly commandId: ColumnKey<Intent>;\n readonly subjectId: ColumnKey<Intent>;\n readonly action: ColumnKey<Intent>;\n readonly generation: ColumnKey<Intent>;\n readonly version: ColumnKey<Intent>;\n readonly state: ColumnKey<Intent>;\n readonly digest: ColumnKey<Intent>;\n readonly snapshot: ColumnKey<Intent>;\n readonly identifierScope: ColumnKey<Intent>;\n readonly createdAt: ColumnKey<Intent>;\n readonly admittedAt: ColumnKey<Intent>;\n readonly admissionRetainUntil: ColumnKey<Intent>;\n readonly preparationExpiresAt: ColumnKey<Intent>;\n readonly expiresAt: ColumnKey<Intent>;\n readonly retainUntil: ColumnKey<Intent>;\n readonly states: Readonly<\n Record<PasswordPreparedState, InferSelectModel<Intent>[ColumnKey<Intent>]>\n >;\n readonly encodeInsert: (input: {\n readonly reservation: PasswordPreparedReservation;\n readonly nativeSubjectId: NativeSubjectId;\n readonly identifierScope: string;\n readonly admittedAtMillis: number;\n readonly admissionRetainUntilMillis: number;\n /** Bounded private core codec output; contains a salted verifier for Change/Reset. */\n readonly snapshot: string;\n }) => InferInsertModel<Intent>;\n readonly encodeReady: (input: {\n readonly ready: PasswordPreparedReady;\n readonly snapshot: string;\n }) => Partial<InferInsertModel<Intent>>;\n /** Erase snapshot and digest, preserving every identity/scope/time column. */\n readonly encodeTerminal: (\n state: Exclude<PasswordPreparedState, \"Preparing\" | \"Ready\">,\n ) => Partial<InferInsertModel<Intent>>;\n}\n\n/** One permanent row per configured module; never one row per attacker input.\n * Native owners lock this before subject → identifier → sorted credentials → intent.\n * It serializes admission and maintenance without process-local locks. */\nexport interface PasswordPreparedAdmissionTable<Admission extends Table> {\n readonly table: Admission;\n readonly moduleId: ColumnKey<Admission>;\n readonly intentId: ColumnKey<Admission>;\n readonly admittedAt: ColumnKey<Admission>;\n readonly admissionRetainUntil: ColumnKey<Admission>;\n readonly encodeInsert: (moduleId: string) => InferInsertModel<Admission>;\n}\n\nexport const requiredPasswordPreparedConstraints = {\n admission: \"unique(admission.moduleId)\",\n intent: \"unique(intent.moduleId,intent.intentId)\",\n command: \"unique(intent.moduleId,intent.commandId)\",\n digest: \"unique(intent.digest)\",\n} as const;\n\nexport type RequiredPasswordPreparedConstraints = typeof requiredPasswordPreparedConstraints;\n\nexport interface PasswordPreparedPersistenceMapping<\n Subject extends Table,\n Identifier extends Table,\n Credential extends Table,\n AuthorityCredential extends Table,\n Attempt extends Table,\n Command extends Table,\n Intent extends Table,\n Admission extends Table,\n NativeSubjectId,\n> {\n readonly password: PasswordPersistenceMapping<\n Subject,\n Identifier,\n Credential,\n AuthorityCredential,\n Attempt,\n Command,\n NativeSubjectId\n >;\n readonly intent: PasswordPreparedIntentTable<Intent, NativeSubjectId>;\n readonly admission: PasswordPreparedAdmissionTable<Admission>;\n readonly constraints: RequiredPasswordPreparedConstraints;\n readonly allocateVersion?: Effect.Effect<PasswordPreparedVersion, PersistenceMappingError>;\n /** Required by synchronous owners, invoked inside their actual transactionSync. */\n readonly allocateVersionSync?: () => PasswordPreparedVersion;\n}\n\nexport type D1PasswordPreparedPersistenceMapping<\n Subject extends Table,\n Identifier extends Table,\n Credential extends Table,\n AuthorityCredential extends Table,\n Attempt extends Table,\n Command extends Table,\n Intent extends Table,\n Admission extends Table,\n NativeSubjectId,\n> = PasswordPreparedPersistenceMapping<\n Subject,\n Identifier,\n Credential,\n AuthorityCredential,\n Attempt,\n Command,\n Intent,\n Admission,\n NativeSubjectId\n> & {\n /** Convert a stored native instant to epoch milliseconds in the same SQL engine. */\n readonly admissionClock: { readonly toMillis: (instant: SQL) => SQL };\n readonly password: D1PasswordPersistenceMapping<\n Subject,\n Identifier,\n Credential,\n AuthorityCredential,\n Attempt,\n Command,\n NativeSubjectId\n >;\n};\n\n/** Optional real proof completion authority. Request/delivery/abuse capabilities\n * are not required to complete the original continuation. */\nexport type PasswordPreparedProofMapping<\n Series extends Table,\n Continuation extends Table,\n Command extends Table,\n Subject extends Table,\n Identifier extends Table,\n Credential extends Table,\n NativeSubjectId,\n> = Pick<\n ProofPersistenceMapping<\n Table,\n Series,\n Table,\n Continuation,\n Table,\n Table,\n Table,\n Command,\n Subject,\n Identifier,\n Credential,\n NativeSubjectId\n >,\n | \"series\"\n | \"continuation\"\n | \"command\"\n | \"authority\"\n | \"scopeKeys\"\n | \"encodeInstant\"\n | \"decodeInstant\"\n | \"allocateVersion\"\n | \"allocateVersionSync\"\n | \"isSeriesConflict\"\n | \"isCommandConflict\"\n | \"d1\"\n> & {\n readonly constraints: Pick<\n RequiredProofConstraints,\n \"series\" | \"continuationId\" | \"continuationDigest\" | \"command\"\n >;\n};\n\nexport type D1PasswordPreparedProofMapping<\n Series extends Table,\n Continuation extends Table,\n Command extends Table,\n Subject extends Table,\n Identifier extends Table,\n Credential extends Table,\n NativeSubjectId,\n> = Pick<\n D1ProofPersistenceMapping<\n Table,\n Series,\n Table,\n Continuation,\n Table,\n Table,\n Table,\n Command,\n Subject,\n Identifier,\n Credential,\n NativeSubjectId\n >,\n Exclude<\n keyof PasswordPreparedProofMapping<\n Series,\n Continuation,\n Command,\n Subject,\n Identifier,\n Credential,\n NativeSubjectId\n >,\n \"constraints\"\n >\n> & {\n readonly constraints: PasswordPreparedProofMapping<\n Series,\n Continuation,\n Command,\n Subject,\n Identifier,\n Credential,\n NativeSubjectId\n >[\"constraints\"];\n};\n\nexport type AnyPasswordPreparedPersistenceMapping = PasswordPreparedPersistenceMapping<\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n unknown\n>;\n"],"mappings":";AA0EA,MAAa,sCAAsC;CACjD,WAAW;CACX,QAAQ;CACR,SAAS;CACT,QAAQ;AACV"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { makeDrizzleSqlTables } from "./native-sql-table.mjs";
|
|
1
2
|
import { drizzleQueryOperations } from "./query-operations.mjs";
|
|
2
3
|
import { completeProofPlanIn } from "./proof-sql.mjs";
|
|
3
4
|
import { CurrentPasswordSql, makePasswordKernel } from "@yielded/auth-persistence/Adapter";
|
|
4
5
|
//#region src/drizzle/password-sql.ts
|
|
5
|
-
const { makeSqlPasswordPersistence, passwordSqlKernel } = makePasswordKernel(drizzleQueryOperations, { completeProofPlanIn });
|
|
6
|
+
const { makeSqlPasswordPersistence, passwordSqlKernel } = makePasswordKernel(drizzleQueryOperations, { completeProofPlanIn }, makeDrizzleSqlTables);
|
|
6
7
|
//#endregion
|
|
7
8
|
export { CurrentPasswordSql, makeSqlPasswordPersistence, passwordSqlKernel };
|
|
8
9
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"password-sql.mjs","names":[],"sources":["../../src/drizzle/password-sql.ts"],"sourcesContent":["import { makePasswordKernel } from \"@yielded/auth-persistence/Adapter\";\n\nimport { completeProofPlanIn } from \"./proof-sql\";\nimport { drizzleQueryOperations } from \"./query-operations\";\nexport type { PasswordSqlQuery } from \"@yielded/auth-persistence/Adapter\";\nexport type { PasswordSqlDatabase } from \"@yielded/auth-persistence/Adapter\";\nexport { CurrentPasswordSql } from \"@yielded/auth-persistence/Adapter\";\nexport type { PasswordSqlConfiguration } from \"@yielded/auth-persistence/Adapter\";\n\nexport const { makeSqlPasswordPersistence, passwordSqlKernel } = makePasswordKernel(\n drizzleQueryOperations,\n { completeProofPlanIn },\n);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"password-sql.mjs","names":[],"sources":["../../src/drizzle/password-sql.ts"],"sourcesContent":["import { makePasswordKernel } from \"@yielded/auth-persistence/Adapter\";\n\nimport { makeDrizzleSqlTables } from \"./native-sql-table\";\nimport { completeProofPlanIn } from \"./proof-sql\";\nimport { drizzleQueryOperations } from \"./query-operations\";\nexport type { PasswordSqlQuery } from \"@yielded/auth-persistence/Adapter\";\nexport type { PasswordSqlDatabase } from \"@yielded/auth-persistence/Adapter\";\nexport { CurrentPasswordSql } from \"@yielded/auth-persistence/Adapter\";\n\nexport type { PasswordSqlConfiguration } from \"@yielded/auth-persistence/Adapter\";\n\nexport const { makeSqlPasswordPersistence, passwordSqlKernel } = makePasswordKernel(\n drizzleQueryOperations,\n { completeProofPlanIn },\n makeDrizzleSqlTables,\n);\n"],"mappings":";;;;;AAWA,MAAa,EAAE,4BAA4B,sBAAsB,mBAC/D,wBACA,EAAE,oBAAoB,GACtB,oBACF"}
|
|
@@ -2,7 +2,8 @@ import { validateDrizzleStorage } from "./storage-validation.mjs";
|
|
|
2
2
|
import { sqlClientStandaloneGuard } from "./standalone-guard.mjs";
|
|
3
3
|
import { CurrentPasswordSql, makeSqlPasswordPersistence } from "./password-sql.mjs";
|
|
4
4
|
import { makeSqlPasswordRegistrationAuthority } from "./password-registration.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { CurrentPasswordPreparedTransaction, PasswordPreparedPostconditions } from "@yielded/auth-persistence/Adapter";
|
|
6
|
+
import { Cause, Effect, Layer } from "effect";
|
|
6
7
|
import { LifecycleHooks, coordinateCommit, hasCommitScope } from "@yielded/auth/Hooks";
|
|
7
8
|
import { PasswordPersistence, PasswordUnavailable } from "@yielded/auth/Password";
|
|
8
9
|
//#region src/drizzle/password-target.ts
|
|
@@ -47,7 +48,17 @@ const coordinateTargetPasswordPersistence = (database, mapping, configuration, p
|
|
|
47
48
|
proof: proofMapping
|
|
48
49
|
}).pipe(Effect.mapError(() => PasswordUnavailable.make({})));
|
|
49
50
|
return (yield* coordinateCommit(() => database.transaction((transaction) => Effect.gen(function* () {
|
|
50
|
-
|
|
51
|
+
const postconditions = [];
|
|
52
|
+
let acceptingPostconditions = true;
|
|
53
|
+
const value = yield* owner(transaction, { passwordPersistence: yield* makeSqlPasswordPersistence(mapping, passwordOptions(configuration, proofMapping, true)).pipe(Effect.provideService(CurrentPasswordSql, transaction)) }).pipe(Effect.provideService(PasswordPreparedPostconditions, { register: (check) => {
|
|
54
|
+
if (!acceptingPostconditions) return false;
|
|
55
|
+
postconditions.push(check);
|
|
56
|
+
return true;
|
|
57
|
+
} }), Effect.ensuring(Effect.sync(() => {
|
|
58
|
+
acceptingPostconditions = false;
|
|
59
|
+
})));
|
|
60
|
+
for (const check of postconditions) yield* check.pipe(Effect.provideService(CurrentPasswordPreparedTransaction, transaction), Effect.catchCause((cause) => Effect.failCause(Cause.map(cause, () => PasswordUnavailable.make({})))));
|
|
61
|
+
return value;
|
|
51
62
|
})), { mode: configuration.mode }).pipe(Effect.provideService(LifecycleHooks, hooks))).value;
|
|
52
63
|
});
|
|
53
64
|
const coordinateTargetPasswordRegistration = (database, mapping, configuration, owner) => Effect.gen(function* () {
|