// Authors with their books eager-loaded — demonstrates `.with({ books: true })`. // // DESCRIPTOR (browser-safe). The `output` shape includes the nested `books` // array the eager spec attaches to each author row (the relation registered // in authors.relations.ts). // // `source: ['authors', 'books']` makes the reactive subscription re-run when // EITHER table changes — a new book under an author pushes a fresh snapshot. // No `cache` here: this is a join-shaped result; we let the live dispatcher // keep it fresh rather than cache a snapshot. import { defineQuery } from '@voltro/protocol' import { Schema } from 'effect' const Book = Schema.Struct({ id: Schema.String, authorId: Schema.String, title: Schema.String, summary: Schema.String, genre: Schema.String, tags: Schema.Array(Schema.String), slug: Schema.String, tenantId: Schema.String, }) export const authorsWithBooks = defineQuery({ name: 'authors.withBooks', source: ['authors', 'books'], // Open: the rows are this template's own seeded catalogue // (`seeds/catalog.seed.ts` — a public book list, no personal data), and // `tenant()` on both tables scopes every delivery to the request's tenant. // // `bio` is the `.encrypted()` column and it IS in this output — deliberately, // because the lesson is that `.encrypted()` is about bytes AT REST and says // nothing about the wire. If a column must not leave the server, that is a // different marker (`.serverOnly()`), not this one. openAccess: 'streams the seeded demo catalogue (authors + their books) for the request\'s tenant; the ' + 'seed holds no personal data. `bio` is `.encrypted()` and still crosses the wire on ' + 'purpose — encryption at rest is not an exposure marker; `.serverOnly()` is.', input: Schema.Struct({}), output: Schema.Struct({ id: Schema.String, name: Schema.String, // `bio` is the `.encrypted()` column — handlers (and the wire) see // plaintext; it's ciphertext only on disk. Nullable in the seed/data. bio: Schema.NullOr(Schema.String), tenantId: Schema.String, // Eager-loaded relation: each author carries an array of their books. books: Schema.Array(Book), }), })