OwnedListFilter.ts overview
Auth.OwnedAccess.readScope rendered as a drizzle WHERE over an owned table’s columns. Missing draft, unapproved or group columns only narrow it, and the follow and group sets stay subqueries (isFollowerLayer, isMemberLayer). It agrees row for row with canView and ReadScope.compile.
Example
import { Effect } from "effect"
import { eq, sql } from "drizzle-orm"
import * as Drizzle from "@thomasfosterau/effect-auth-drizzle"
const listPosts = Effect.gen(function* () {
const scope = yield* owned.readScope
const where = Drizzle.OwnedListFilter.ownedListFilter({
owner: posts.ownerId,
visibility: posts.visibility,
draft: posts.draft,
unapproved: sql`${posts.moderation} <> 'approved'`,
group: posts.groupId,
})(scope)
return yield* Effect.promise(() => db.select().from(posts).where(where).limit(50))
})
// The follower seam, over the application's own follow table:
const followers = Drizzle.OwnedListFilter.isFollowerLayer({
isFollower: (followerId, ownerId) => … ,
followingQuery: (followerId) =>
db.select({ id: follows.ownerId }).from(follows).where(eq(follows.followerId, followerId)),
})
// The member seam, over the application's own membership table:
const members = Drizzle.OwnedListFilter.isMemberLayer({
isMember: (accountId, groupId) => … ,
groupsQuery: (accountId) =>
db.select({ id: memberships.groupId }).from(memberships).where(eq(memberships.accountId, accountId)),
})
Exports Grouped by Category
layers
isFollowerLayer
Provide Auth.OwnedAccess.IsFollower over an application’s own follow relation: the row check, and the viewer’s follow set as a drizzle query nested into ownedListFilter’s owner IN (…).
Signature
declare const isFollowerLayer: (options: {
readonly isFollower: (followerId: string, ownerId: string) => Effect.Effect<boolean>
readonly followingQuery: (followerId: string) => SQLWrapper
}) => Layer.Layer<Auth.OwnedAccess.IsFollower>
Since v0.1.0
isMemberLayer
Provide Auth.OwnedAccess.IsMember over an application’s own membership relation: the row check, and the viewer’s group set as a drizzle query nested into ownedListFilter’s group IN (…). A pending invitation is not membership, so neither should count one.
Signature
declare const isMemberLayer: (options: {
readonly isMember: (accountId: string, groupId: string) => Effect.Effect<boolean>
readonly groupsQuery: (accountId: string) => SQLWrapper
}) => Layer.Layer<Auth.OwnedAccess.IsMember>
Since v0.6.0
models
OwnedColumns (interface)
The columns an owned-material list is filtered on. Any column or SQL expression works — a table’s columns, a view’s, an alias.
Signature
export interface OwnedColumns {
/** The owner's id. */
readonly owner: SQLWrapper
/** The four-state visibility (`public | followers | group | private`). */
readonly visibility: SQLWrapper
/** The draft flag, for a table that has one. Omit it for a table that does not. */
readonly draft?: SQLWrapper
/**
* Whether the row awaits (or failed) moderation: `true` for anything but the
* approved state. Omit it for a table with no moderation axis.
*/
readonly unapproved?: SQLWrapper
/**
* The group a `group` row is shared with, read against the scope's group
* set. Omit it and `group` rows list only for their owner.
*/
readonly group?: SQLWrapper
}
Since v0.1.0
rendering
ownedListFilter
Render an owned-material read scope as a WHERE over columns. undefined means no filter (the all scope), which is what drizzle’s .where(undefined) reads it as.
Signature
declare const ownedListFilter: (columns: OwnedColumns) => (scope: Auth.OwnedAccess.OwnedReadScope) => SQL | undefined
Since v0.1.0