AuthSchema.ts overview

AuthSchema: an Alchemy Action that applies @thomasfosterau/effect-auth/sql’s schemaStatements to a Cloudflare.D1.Database on deploy, idempotently and beside the application’s own migrations. An Action has no delete, so the tables go only with the database.

Example

const db = yield * Cloudflare.D1.Database("auth-db")
yield * AuthSchema("auth-schema", db).pipe(Effect.provide(Cloudflare.D1.QueryDatabaseLocal))

Exports Grouped by Category


utils

AUTH_SCHEMA_TYPE

The Action’s Alchemy type tag.

Signature

declare const AUTH_SCHEMA_TYPE: "effect-auth::D1AuthSchema"

Source

AuthSchema

Apply the effect-auth schema to database on deploy, as an Alchemy Action with logical id id. Yield it in an Alchemy program with a Cloudflare.D1.QueryDatabase provided (Cloudflare.D1.QueryDatabaseLocal on deploy); it outputs the AuthSchemaAttributes of the run.

Each call declares its own Action, so one stack can apply the schema to several databases under distinct ids. Its type (effect-auth::D1AuthSchema) differs from the Postgres package’s resource.

Signature

declare const AuthSchema: (
  id: string,
  database: Database
) => Effect.Effect<
  ObjectExpr<{ tables: ReadonlyArray<string>; statements: number; appliedAt: number }, never>,
  never,
  QueryDatabase | Stack
>

Source

AuthSchemaAttributes (interface)

What a run of the AuthSchema Action outputs.

Signature

export interface AuthSchemaAttributes {
  /** The auth tables observed in the database after applying, sorted. */
  readonly tables: readonly string[]
  /** Number of DDL statements in the applied schema. */
  readonly statements: number
  /** Epoch milliseconds at which the schema was last applied. */
  readonly appliedAt: number
}

Source

AuthSchemaInput (interface)

The input the engine hashes: a change to either re-runs the Action.

Signature

export interface AuthSchemaInput {
  /** The target database's id, so a replaced database is migrated again. */
  readonly databaseId: string
  /** `@thomasfosterau/effect-auth/sql`'s DDL, so a schema change is applied. */
  readonly statements: readonly string[]
}

Source

authTableNames

Every table the effect-auth schema creates (@thomasfosterau/effect-auth/sql’s list).

Signature

declare const authTableNames: ReadonlyArray<string>

Source


This site uses Just the Docs, a documentation theme for Jekyll.